Strange artifact

Are you new to 6502, NES, or even programming in general? Post any of your questions here. Remember - the only dumb question is the question that remains unasked.

Moderator: Moderators

Post Reply
casprog
Posts: 70
Joined: Fri Oct 28, 2016 12:37 pm

Strange artifact

Post by casprog » Mon Aug 24, 2020 8:03 pm

Hi all,

After a good break after writing my first game I've come back to work with the NES again and instantly ran into a strange issue (hoping my brain didn't reset here). What you are seeing is bare bones code. I'm just loading a nametable, nothing fancy. As soon as I try adding a subroutine, even if it's not called, I get a black tile. The debugger shows a tile id of 1E, but I'm not using that. If I open the nametable using screen tool everything looks fine.

Now here is the kicker... like I said even if my subroutine isn't being called this is happening, AND this only happens if the subroutine passes a certain size. The instructions within it do not matter. You can see my filler routine called test_routine:. It's just LDAs... If I remove just ONE of those, the black tile goes away :shock:

Example of how it should look
Image

The black tile
Image

Code: Select all

;----------------------------------------------------------------
; constants
;----------------------------------------------------------------

PRG_COUNT = 1 ;1 = 16KB, 2 = 32KB
MIRRORING = %0001 ;%0000 = horizontal, %0001 = vertical, %1000 = four-screen

;----------------------------------------------------------------
; variables
;----------------------------------------------------------------

	.enum $0000
	tempPtr .dsb 2
	.ende

;----------------------------------------------------------------
; iNES header
;----------------------------------------------------------------

	.db "NES", $1a ;identification of the iNES header
	.db PRG_COUNT ;number of 16KB PRG-ROM pages
	.db $01 ;number of 8KB CHR-ROM pages
	.db $00|MIRRORING ;mapper 0 and mirroring
	.dsb 9, $00 ;clear the remaining bytes

;----------------------------------------------------------------
; program bank(s)
;----------------------------------------------------------------

	.base $10000-(PRG_COUNT*$4000)

RESET:
	SEI          ; disable IRQs
	CLD          ; disable decimal mode
	LDX #$40
	STX $4017    ; disable APU frame IRQ
	LDX #$FF
	TXS          ; Set up stack
	INX          ; now X = 0
	STX $2000    ; disable NMI
	STX $2001    ; disable rendering
	STX $4010    ; disable DMC IRQs

vblankwait1:       ; First wait for vblank to make sure PPU is ready
	BIT $2002
	BPL vblankwait1

; clear out 256 bytes at various memory spaces
	LDX #0
clrmem:
	LDA #0
	STA $0000, x
	STA $0100, x
	STA $0300, x
	STA $0400, x
	STA $0500, x
	STA $0600, x
	STA $0700, x
	LDA #$FE
	STA $0200, x
	INX
	BNE clrmem

vblankwait2:      ; Second wait for vblank, PPU is ready after this
	BIT $2002
	BPL vblankwait2

; load palettes
	LDA $2002             ; read PPU status to reset the high/low latch
	LDA #$3F
	STA $2006             ; write the high byte of $3F00 address
	LDA #$00
	STA $2006             ; write the low byte of $3F00 address

	LDY #0
-:	LDA palettes, y
	STA $2007
	INY
	CPY #16
	BNE -

; load nametable
	LDA $2002             ; read PPU status to reset the high/low latch
	LDA #$20
	STA $2006             ; write the high byte of $2000 address
	LDA #$00
	STA $2006             ; write the low byte of $2000 address

	LDA #<nametable
	STA tempPtr
	LDA #>nametable
	STA tempPtr + 1

	LDY #0
	LDX #4
-:	LDA (tempPtr), y
	STA $2007
	INY
	; zero flag set? (y = 0)
	BNE -
	; advance outer loop
	INC tempPtr + 1
	DEX
	; zero flag set? (x = 0)
	BNE -

	; finish off some things before entering main game loop
	LDA #%10010000   ; enable NMI, sprites from Pattern Table 0, background from Pattern Table 1
	STA $2000
	LDA #%00011110   ; enable sprites, enable background, no clipping on left side
	STA $2001

main:
	JMP main

NMI:
	LDA #0
	STA $2003       ; set the low byte (00) of the RAM address
	LDA #2
	STA $4014       ; set the high byte (03) of the RAM address, start the transfer

	LDA #%00011110   ; enable sprites, enable background, no clipping on left side
	STA $2007

	LDA #$00
	STA $2005	; no horizontal scroll
	STA $2005	; no vertical scrolling
	RTI

test_routine:
	LDA #$00
	LDA #$00
	LDA #$00
	LDA #$00
	RTS

IRQ:
	RTI

palettes:
	.incbin "palettes.pal"

nametable:
	.incbin "nametable.nam"

;----------------------------------------------------------------
; interrupt vectors
;----------------------------------------------------------------

	.org $fffa

	.dw NMI
	.dw RESET
	.dw IRQ

;----------------------------------------------------------------
; CHR-ROM bank
;----------------------------------------------------------------
	.incbin "chrdata.chr"


casprog
Posts: 70
Joined: Fri Oct 28, 2016 12:37 pm

Re: Strange artifact

Post by casprog » Mon Aug 24, 2020 8:22 pm

erm... in my NMI....

Code: Select all

LDA #%00011110   ; enable sprites, enable background, no clipping on left side
STA $2007
that should have been $2001

I don't know why this only showed after adding a subroutine

Post Reply