Jump to content
IGNORED

Understanding Sprites


Recommended Posts

Here's a quick look at something else I don't quite get:

 

ScanLoop:
   sta WSYNC

; graphics updates go here

   lda SpriteLine
   cmp #5
   beq .skip
   lda #%01010101
   sta GRP0
   inc SpriteLine
.skip

   dey
   bne ScanLoop

   lda #%00000010
   sta WSYNC
   sta VBLANK
   ldx #30 ; setup 30 scan lines for overscan

 

So, what I'm trying to do, is load 5 lines of sprite data so that I can make a block.

 

SpriteLine is my variable and is initalized as 0. Every iteration I am comparing this to 5, if the zero flag is set, then I know it has reached 5 so i skip that drawing.

 

For some reason, the state of ScanLoop doesn't seem to matter because this is the output:

 

I can see that it is "working" when it comes to drawing to the screen, but it isn't working as it should.

post-36643-0-51709800-1377024057_thumb.png

Edited by johnnystarr
Link to comment
Share on other sites

TIA is a scanline based video chip. If you set a register, such as GRP0, on one line and don't change it then that value will continue to be displayed on all following scanlines.

 

You're setting GRP0 to %01010101, but never setting it to any other value, so the strips are drawn down the screen.

 

You need to load GRP0 with 0 to make it stop displaying.

        lda SpriteLine
       cmp #5
       beq .skip
       lda #%01010101
       .byte $2c
.skip
       lda #0
       sta GRP0
       inc SpriteLine

 

$2c is the opcode for BIT $ABSOLUTE, so it "hides" the lda #0 by treating it as the $ABSOLUTE address. It doesn't affect the registers, but it does change the N, V and Z flags.

 

There's undocumented opcodes that can also be used. NOP $ABSOLUTE can be done using .byte $0c. Like the $2c, it'll "hide" the lda #0, but it won't change any registers OR flags.

  • Like 1
Link to comment
Share on other sites

Hmm, I applied this code and I'm just getting a scan up and down. I must be doing something wrong here:

 

Maybe you could look at my source?

 

   processor 6502
   include "macro.h"
   include "vcs.h"
   
   ORG $F000
   
; constants
; variables
SpriteLine = $80

Start:
   sei
   cld
   ldx #$FF
   txs
   lda #0
.clearmem
   sta 0,x
   dex
   bne .clearmem
   
   lda #$23
   sta COLUBK
   
   ;setup sprite
   
   lda #$20
   sta COLUP0
   
; Main gameloop
Main:
   lda #%00000010
   sta VSYNC
   sta    WSYNC
   sta WSYNC
   sta WSYNC
   
   ; set timer to handle the rest of VBLANK draw
   lda #41
   sta TIM64T
   lda #0
   sta VSYNC
   
   ; main logic goes here
   ; this is where you put all your controller logic and score, etc.
   
   
   
   
   ; -----
   
WaitForVBlank:
   lda INTIM
   bne WaitForVBlank
   ldy #191
   sta WSYNC
   sta VBLANK
   sta WSYNC

   
ScanLoop:
   sta WSYNC
   
   ; graphics updates go here
   
   lda SpriteLine
   cmp #5
   beq .skip
   lda #%01010101
   .byte $2c
.skip
   lda #0
   sta GRP0
   inc SpriteLine

   dey
   bne ScanLoop
   
   lda #%00000010
   sta WSYNC
   sta VBLANK
   ldx #30 ; setup 30 scan lines for overscan
   
Overscan:
   sta    WSYNC
   dex
   bne Overscan
   jmp Main
   
   
Sprite:
   .byte #%00011000
   .byte #%00111100
   .byte #%00011000
   
   .org $FFFC
   .word Start
   .word Start

Link to comment
Share on other sites

Will do.

 

I have scanned over those chapters, but I was hoping to try to figure this out so I can get what I'm doing wrong.

 

I've tried a second attempt to no avail.

 


; in above code
   lda #5
   sta SpriteLine ; initialize to 5

ScanLoop:
   sta WSYNC

; --- begin graphics

   lda SpriteLine    ; load current state
   beq .skip		 ; if is 0, branch to skip
   lda #%01010101    ; line pattern
   sta GRP0		  ; store
   dec SpriteLine    ; decrement the counter
   jmp .done		 ; jump past the skip portion

.skip
   lda #0		    ; load 0
   sta GRP0		  ; store in sprite register
.done

 

The output is just my background. When i change "beq .skip" to "bne .skip" I get the strip down the screen again.

Edited by johnnystarr
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...