Sprite graphics

Subject: Sprite graphics
From: Kevin Lipe <kevin.lipe@xxxxxxxxx>
Date: Mon, 11 Oct 2004 01:52:55 -0500
OK, So I took the advice given me in the other thread that I started,
"Confused newbie..." and read back through the Stella Programmer's
Guide, Andrew Davie's tutorials, and 2600 101, and I've gotten to the
end of Andrew's tutorials and I don't know what's happening.

I've got the code to display the "Bad Llama" sprite working, and
something appears and moves across the screen like it's supposed to,
but... the graphics are all screwed up and I have no idea why.

 Just so all the labels and stuff in the code make sense to whoever
may be looking at this code, heres my description of this game, "Super
Killer Attack Llamas."

>The new game, tentatively titled Super Killer Attack Llamas, is kinda
like a cross between Space Invaders and Yars Revenge, i guess...
basically the player is Good Llama, at the bottom of the screen, and
they're fighting Bad Llama at the top of the screen. Bad Llama is
shooting down at Good Llama, who has a few playfield objects to hide
behind, and must use the cover to shoot up at Bad Llama... that's
really it. Bad Llama occupies 10 scanlines and Good Llama occupies 10
scanlines, and they both can only move horizontally, so there's no
need to Vertical positioning because they will -always- be on those
scanlines...

I've pored over this code several times, and can't find what's wrong
with it at all.

Thanks!
~ kevin
	LIST OFF 
;============================================================================
; S U P E R   K I L L E R   A T T A C K   L L A M A S
; aka "Killing Me Softly"
; 
; (c)2004 Kevin Lipe
;============================================================================
; COMPILE WITH:
; dasm llama.asm -f3 -v5 -ollama.bin
;============================================================================

	processor 6502
	include vcs.h
	include macro.h


	LIST ON
;===============================================================================
; A S S E M B L E R   S W I T C H E S
;===============================================================================

NTSC                    = 0
PAL                     = 1

COMPILE_VERSION         = NTSC      	; change this to compile for different
    		                        ; regions

FILL_OPT		= 1		; fills the optimized space with NOPs
   
;============================================================================
; T I A   C O N S T A N T S
;============================================================================

HMOVE_L7          =  $70
HMOVE_L6          =  $60
HMOVE_L5          =  $50
HMOVE_L4          =  $40
HMOVE_L3          =  $30
HMOVE_L2          =  $20
HMOVE_L1          =  $10
HMOVE_0           =  $00
HMOVE_R1          =  $F0
HMOVE_R2          =  $E0
HMOVE_R3          =  $D0
HMOVE_R4          =  $C0
HMOVE_R5          =  $B0
HMOVE_R6          =  $A0
HMOVE_R7          =  $90
HMOVE_R8          =  $80

; values for ENAMx and ENABL
DISABLE_BM        = %00
ENABLE_BM         = %10

; values for NUSIZx
ONE_COPY          = %000
DOUBLE_SIZE       = %101
QUAD_SIZE         = %111
MSBL_SIZE1        = %000000
MSBL_SIZE2        = %010000
MSBL_SIZE4        = %100000
MSBL_SIZE8        = %110000

; values for REFPx
NO_REFLECT        = %0000
REFLECT           = %1000

; mask for SWCHB
P1_DIFF_MASK      = %10000000
BW_MASK           = %00001000       ; black and white bit
SELECT_MASK       = %00000010
RESET_MASK        = %00000001

; SWCHA joystick bits
MOVE_RIGHT        = %1000
MOVE_LEFT         = %0100
MOVE_DOWN         = %0010
MOVE_UP           = %0001
NO_MOVE           = %11111111

; general constants
SCREEN_WIDTH	  = 160			; width of screen, in pixels
NUM_DIGITS	  = 4			; number of digits in the score

;============================================================================
; U S E R   C O N S T A N T S
;============================================================================

; frame time values   
VBLANK_TIME          = $2C

; color constants
BLACK          = $00
WHITE          = $0E

GREEN_BLUE     = $A0
RED            = $30
YELLOW         = $1E
GREEN          = $C0
BLUE           = $90
LIGHT_BLUE     = $80
PURPLE         = $60
BROWN          = $E0

; game state values
SYSTEM_POWERUP       = %00001010
GAME_RUNNING         = %11111111 

; illegal opcodes allowed
NO_ILLEGAL_OPCODES = 0

; height of the llama sprites
SpriteHeight	= 10

;============================================================================
; Z P - V A R I A B L E S
;============================================================================

	SEG.U VARS
	ORG $80

CTRLPF_shadow 		ds 1	; CTRLPF shadow copy

GoodLlamaHPos		ds 1    ; Good Llama's horizontal position
BadLlamaHPos		ds 1	; Bad Llama's horizontal position

BadMissleHPos		ds 1	; Bad Llama's bullet's horizontal position
BadMissleVPos		ds 1	; Bad Llama's bullet's vertical position

GoodMissleHPos		ds 1	; Good Llama's bullet's horizontal position
GoodMissleVPos		ds 1	; Good Llama's bullet's vertical position

	echo "----",($100 - *) , "bytes of RAM left" ; DASM tells how many bytes of RAM are left.

;===============================================================================
; M A C R O S
;===============================================================================

  MAC FILL_NOP
    IF FILL_OPT
      REPEAT {1}
         NOP
      REPEND
    ENDIF
  ENDM

;============================================================================
; R O M   C O D E
;============================================================================

	SEG Bank0
	ORG $F000
	
Reset
		CLEAN_START 

;------------------------------------------------
; Once-only initialisation...

		lda #YELLOW		; player 0 color = yellow
		sta COLUP0

		lda #RED		; player 1 color = red
		sta COLUP1
		
		lda #LIGHT_BLUE	; playfield color = light blue
		sta COLUPF		

		lda #%10000001      	; Set both shadow copy and CTRLPF to "mirror" mode,
		sta CTRLPF_shadow		; the playfield and ball have priority.
		sta CTRLPF 				
		
		lda #$00		; clear graphics registers
		sta PF0
		sta PF1
		sta PF2
		sta GRP0
		sta GRP1
		
		ldy #0			; zeroes out Y
;---------------------------------------

StartOfFrame				
; Start of new frame
; Start of vertical blank processing

		lda #0
		sta VBLANK

		lda #2
		sta VSYNC

		sta WSYNC		
		sta WSYNC
		sta WSYNC                ; 3 scanlines of VSYNC signal
		
		lda #0
		sta VSYNC


               
;------------------------------------------------
; 37 scanlines of vertical blank...
          
		ldx #37
VerticalBlank	sta WSYNC
		dex
		bne VerticalBlank

;------------------------------------------------
; The kernel

		lda #%11111111
		sta PF0
		sta PF1
		sta PF2

		sta WSYNC ; top line of playfield
;------------------------
		lda #%00010000
		sta PF0
		lda #0
		sta PF1
		sta PF2

		sta WSYNC
		
; Now adjust the sprite position
		inc BadLlamaHPos
		ldx BadLlamaHPos
		cpx #160
		bcc LT160
		ldx #0
		stx BadLlamaHPos
LT160
		jsr PositionSprite
		
		lda LlamaSprite
		sta GRP1
		
		ldx #9
BadLlama	
		iny
		lda LlamaSprite,y
		sta GRP1
		dex
		sta WSYNC ; 10 lines of resolution for the Bad Llama
		bne BadLlama
;-----------------------
		lda #0
		sta GRP1
		
		ldx #172
MiddleSpace	sta WSYNC ; space for the obstacles and missiles
		dex
		bne MiddleSpace 
;------------------------
		sta WSYNC
		ldx #10
GoodLlama	
		dex
		sta WSYNC ; 10 lines of resolution for the Good Llama
		bne GoodLlama
;------------------------
		lda #%11111111
		sta PF0
		sta PF1
		sta PF2
		sta WSYNC ; bottom of playfield
;------------------------------------------------
		lda #%01000010
		sta VBLANK           ; end of screen - enter blanking

    ; 30 scanlines of overscan...

		ldx #30
Overscan 	sta WSYNC
		dex
		bne Overscan

		jmp StartOfFrame 
;------------------------------------------------
;Other routines

PositionSprite
		sta WSYNC
; Pass X register holding desired X position of sprite!
		lda Divide15,x			; xPosition / 15
		tax
SimpleLoop	dex
		bne SimpleLoop

		sta RESP1			; start drawing the sprite
		rts


;============================================================================
; R O M   D A T A
;============================================================================

LlamaSprite:				; isn't it cute?
		.byte #%00000100 ; .....X.. ;10
		.byte #%00000111 ; .....XXX ;09
		.byte #%00000110 ; .....XX. ;08
		.byte #%00000110 ; .....XX. ;07
		.byte #%00000110 ; .....XX. ;06
		.byte #%01111110 ; .XXXXXX. ;05
		.byte #%01111110 ; .XXXXXX. ;04
		.byte #%01111110 ; .XXXXXX. ;03
		.byte #%01100110 ; .XX..XX. ;02
		.byte #%01100110 ; .XX..XX. ;01
		
Divide15 					;much easier than writing out a table...
.POS	SET 0
	REPEAT 256
	.byte (.POS / 15) + 1
.POS	SET .POS + 1
	REPEND

;===============================================================================
; V E C T O R S
;===============================================================================

        ORG $FFFA

InterruptVectors

	.word Reset           ; NMI
    .word Reset           ; RESET
    .word Reset           ; IRQ
	END   
Current Thread