Jump to content
IGNORED

Ball positioning, ENABL, RESBL


Recommended Posts

Hi, I've been out of this for a while and I find that I've forgotten a lot. So, I thought I'd start with something simple. I wanted to code a kernel that does nothing but display and position a ball. After about an hour I was finally able to get a straight vertical line to appear. An hour after that I was able to get a ball that is one clock wide and one scanline tall. I've experiemted with ENABLE and RESBL for a few hours now and I wasn't able to reposition the ball horizontally until a few minutes ago. I didn't find any discussions about Ball (lots of player and playfield) so I wanted to share my noob experience.

 

My understanding of RESBL was that I chould set it one time only at the color clock where I wanted the ball to be positioned. What I didn't understand was the I need to set WSYNC after RESBL to get the ball to appear. I misunderstood what was meant by "strobe" register in this case. Writting to RESBL doesn't take affect until the next scanline. Then when I reach the correct scanline I set ENABLE and presto! the ball appears at the color clock where I had positioned it. After another WSYNC I disable the ball so I get the ball for just one scaneline.

 

These are some of the things that confused me in the Stella Programming Guide.

1) RESBL and ENABL can not both be set at the same time for the same scanline. There needs to be at least one WSYNC after RESBL before setting ENABL

2) Page 6 of the Stella's Programming Guide states I need to set a "1" to ENABL. But I think they meant to say write a "1" to bit 1, which is a "2" in decimal (#%00000010)

3) Page 8 of the Stella's Programming Guide states that setting RESBL during Horizontal Blank will position the ball at color clock zero. When I tried this, it positioned the ball around color clock 69 or so (give or take a clock)

4) I am still experimenting with HMBL and HMOVE.

 

   processor 6502
   include vcs.h
   include macro.h
   
  ;set origin to the start RAM
  ;this is where variables are declared
    SEG.U vars;this declares Uninitialized space. i.e. RAM
              ; "vars" is the label. YOU NEED THIS!!
    ORG $80   ;$80 is the beginning of RAM

; vet up variables
YPos          ds 1
XPos          ds 1

      ;set origin to the start of the 4k rom
       SEG;this ends the unitialized space and begins Initialized space
          ; i.e. ROM
       ORG $F000  ;$F000 is the beginning of ROM
                 
Reset

      ;Clear RAM and all TIA registers

       ldx #0
       lda #0
Clear   sta 0,x
       inx
       bne Clear
      ;total 9 bytes!

;//////////////////////////////////////
;             InitializeVariables
;//////////////////////////////////////

       lda #$D6 ; light green
       sta COLUPF;set the playfield and Ball color

;EndInitializeVariables

;////////////////////////////////////////
StartOfFrame; Beginning of the game
;////////////////////////////////////////


;/////////////////////////////////////
; VerticalSync   ;top 3 scanlines
      ;using macro. this also stops vsync
       VERTICAL_SYNC
;/////////////////////////////////////



;/////////////////////////////////////
;VerticalBlank  ;37 scanlines
       ldx #37  ; 37 scanlines of vertical blank...
vblankloop
       sta WSYNC
       dex            ;2
       bne vblankloop ;3

       SLEEP 17 ;end of hblank
       SLEEP 20 ;about the center of the visible scanline
       sta RESBL; enable the ball for color clock 60 (give or take)

       LDX #0
       STX VBLANK
       sta WSYNC 
;EndVerticalBlank
;////////////////////////////////////////



;////////////////////////////////////////
;DrawScreen ;192 scanlines

       ldx #192;set the counter for 192 scanlines


scrloop

;I have 192 scanlines of picture
;remember, that's 228 clocks / 3 = 76 cpu cycles per line


;HBLANK 68 CLOCKS/ about 22 cycles
;VISIBLE 160 CLOCKS / about 53 cycles

       CPX #40 
       BEQ PLAYBALL; if scanline 40 from bottom jump to PLAYBALL
       JMP NOBALL  ; else jump to NOBALL
PLAYBALL

       lda #2    ;Stella's Programming Guide 
                  ;page 6 says to write a "1"
                  ;but doesn't seem to work. 
       sta ENABL  ; enable the ball!
       STA WSYNC  ;ball does not display if I don't set WSYNC here
       DEX        ; decrament the counter after setting WSYNC
NOBALL
       lda #00    ;zero disables the ball
       sta ENABL  ;disable the ball
       sta WSYNC  ;end of scanline
       DEX
       BNE scrloop

;EndDrawScreen
;////////////////////////////////



;////////////////////////////////
OverScan
      ;now you have 30 scanlines of overscan

       LDA $%0001
       STA HMBL
       STA WSYNC
       STA HMOVE
       LDX #29
O1
       STA WSYNC 
       DEX
       BNE O1

;EndOverScan
;//////////////////////////////////

;///////////////////////////////////////
;go back to the beginning: 
;inifinate loop
       JMP StartOfFrame
;//////////////////////////////////////

;*****************************
;Graphics 
;*****************************
;//place graphics here

      ;this is the end. change origin to the end of the 4k rom
       org $FFFA
TheEnd
       .word Reset    ;NMI;used in 7800?
       .word Reset    ;RESET 
       .word Reset    ;IRQ;used in 7800?

      ;end of file
       END

Link to comment
Share on other sites

Positioning of all the objects is the most obscure, ornery thing about the 2600, in my opinion.

 

Here are some references. Some of these are very technical. Basically, though, it sounds like you figured everything out the hard way already.

 

Reference 1: http://www.whimsey.com/atari_docs/TIA_HW_Notes.txt

The graphics output for players contains some extra clocking

logic not present for the Playfield or other screen objects.

It takes 1 additional CLK to latch the player START signal.

The rest of the clocking logic is in common with the other

grahpics objects; therefore we can say that player grahpics

are delayed by 1 CLK (this is why the leftmost possible start

position for a RESP0 is pixel 1, not pixel 0. You can HMOVE

the player further left though, if necessary.)

...

This arrangement means that resetting the player counter on any

visible pixel will cause the main copy of the player to appear

at that same pixel position on the next and subsequent scanlines.

There are 5 CLK worth of clocking/latching to take into account,

so the actual position ends up 5 pixels to the right of the

reset pixel (approx. 9 pixels after the start of STA RESP0).

 

For better or worse, the manual 'reset' signal (RESP0) does not

generate a START signal for graphics output. This means that

you must always do a 'reset' then wait for the counter to

wrap around (160 CLK later) before the main copy of the player

will appear. However, if you have any of the 'close', 'medium'

or 'far' copies of the player enabled in NUSIZ, these will be

drawn on the current and subsequent scanlines as the appropriate

decodes are reached and generate their START signals.

...

There are also two individual Horizontal Position Counters for

missile 0 and missile 1. The counters are independent and identical.

 

These counters use exactly the same counter decodes as the players,

but without the extra 1 CLK delay to start writing out graphics.

...

If you look closely at the START signal for the ball, unlike all

the other position counters - the ball reset RESBL does send a START

signal for graphics output! This makes the ball incredibly useful

since you can trigger it as many times as you like across the same

scanline and it will start drawing immediately each time :)

Reference 2: http://www.atariage.com/forums/index.php?s...ndpost&p=894475

It's just the normal offset for the positions of the objects. A RESP will set the objects position to the pixel at which the write happens. But the TIA needs a couple of cycles from the pixel clock to set up the actual output. Therefore all objects will be delayed by a couple of pixels.

 

The offset is 4 pixels for missiles and the ball, 5 pixels for single-width players, and 6 pixels for double- and quadrouple-width players. You need to take these offsets into account when calculating the position of an object.

 

Hi, I've been out of this for a while and I find that I've forgotten a lot. So, I thought I'd start with something simple. I wanted to code a kernel that does nothing but display and position a ball. After about an hour I was finally able to get a straight vertical line to appear. An hour after that I was able to get a ball that is one clock wide and one scanline tall.  I've experiemted with ENABLE and RESBL for a few hours now and I wasn't able to reposition the ball horizontally until a few minutes ago. I didn't find any discussions about Ball (lots of player and playfield) so I wanted to share my noob experience.

 

My understanding of RESBL was that I chould set it one time only at the color clock where I wanted the ball to be positioned. What I didn't understand was the I need to set WSYNC after RESBL to get the ball to appear. I misunderstood what was meant by "strobe" register in this case. Writting to RESBL doesn't  take affect until the next scanline. Then when I reach the correct scanline I set ENABLE and presto! the ball appears at the color clock where I had positioned it. After another WSYNC I disable the ball so I get the ball for just one scaneline.

 

These are some of the things that confused me in the Stella Programming Guide.

1) RESBL and ENABL can not both be set at the same time for the same scanline. There needs to be at least one WSYNC after RESBL before setting ENABL

2) Page 6 of the Stella's Programming Guide states I need to set a "1" to ENABL. But I think they meant to say write a "1" to bit 1, which is a "2" in decimal (#%00000010)

3) Page 8 of the Stella's Programming Guide states that setting RESBL during Horizontal Blank will position the ball at color clock zero. When I tried this, it positioned the ball around color clock 69 or so (give or take a clock)

4) I am still experimenting with HMBL and HMOVE.

 

   processor 6502
   include vcs.h
   include macro.h
   
 ;set origin to the start RAM
 ;this is where variables are declared
    SEG.U vars;this declares Uninitialized space. i.e. RAM
             ; "vars" is the label. YOU NEED THIS!!
    ORG $80  ;$80 is the beginning of RAM

; vet up variables
YPos          ds 1
XPos          ds 1

     ;set origin to the start of the 4k rom
       SEG;this ends the unitialized space and begins Initialized space
         ; i.e. ROM
       ORG $F000 ;$F000 is the beginning of ROM
                 
Reset

     ;Clear RAM and all TIA registers

       ldx #0
       lda #0
Clear   sta 0,x
       inx
       bne Clear
     ;total 9 bytes!

;//////////////////////////////////////
;             InitializeVariables
;//////////////////////////////////////

       lda #$D6; light green
       sta COLUPF;set the playfield and Ball color

;EndInitializeVariables

;////////////////////////////////////////
StartOfFrame; Beginning of the game
;////////////////////////////////////////


;/////////////////////////////////////
; VerticalSync  ;top 3 scanlines
     ;using macro. this also stops vsync
       VERTICAL_SYNC
;/////////////////////////////////////



;/////////////////////////////////////
;VerticalBlank ;37 scanlines
       ldx #37 ; 37 scanlines of vertical blank...
vblankloop
       sta WSYNC
       dex           ;2
       bne vblankloop;3

       SLEEP 17;end of hblank
       SLEEP 20;about the center of the visible scanline
       sta RESBL; enable the ball for color clock 60 (give or take)

       LDX #0
       STX VBLANK
       sta WSYNC 
;EndVerticalBlank
;////////////////////////////////////////



;////////////////////////////////////////
;DrawScreen;192 scanlines

       ldx #192;set the counter for 192 scanlines


scrloop

;I have 192 scanlines of picture
;remember, that's 228 clocks / 3 = 76 cpu cycles per line


;HBLANK 68 CLOCKS/ about 22 cycles
;VISIBLE 160 CLOCKS / about 53 cycles

       CPX #40 
       BEQ PLAYBALL; if scanline 40 from bottom jump to PLAYBALL
       JMP NOBALL ; else jump to NOBALL
PLAYBALL

       lda #2   ;Stella's Programming Guide 
                 ;page 6 says to write a "1"
                 ;but doesn't seem to work. 
       sta ENABL ; enable the ball!
       STA WSYNC ;ball does not display if I don't set WSYNC here
       DEX       ; decrament the counter after setting WSYNC
NOBALL
       lda #00   ;zero disables the ball
       sta ENABL ;disable the ball
       sta WSYNC ;end of scanline
       DEX
       BNE scrloop

;EndDrawScreen
;////////////////////////////////



;////////////////////////////////
OverScan
     ;now you have 30 scanlines of overscan

       LDA $%0001
       STA HMBL
       STA WSYNC
       STA HMOVE
       LDX #29
O1
       STA WSYNC 
       DEX
       BNE O1

;EndOverScan
;//////////////////////////////////

;///////////////////////////////////////
;go back to the beginning: 
;inifinate loop
       JMP StartOfFrame
;//////////////////////////////////////

;*****************************
;Graphics 
;*****************************
;//place graphics here

     ;this is the end. change origin to the end of the 4k rom
       org $FFFA
TheEnd
       .word Reset   ;NMI;used in 7800?
       .word Reset   ;RESET 
       .word Reset   ;IRQ;used in 7800?

     ;end of file
       END

906016[/snapback]

  • Like 1
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...