Background sprites cutoff too soon

A place for your artistic side. Discuss techniques and tools for pixel art on the NES, GBC, or similar platforms.

Moderator: Moderators

Post Reply
Tompis1995
Posts: 17
Joined: Fri Feb 22, 2019 10:05 am

Background sprites cutoff too soon

Post by Tompis1995 » Mon Mar 16, 2020 8:02 pm

Hello. I'm trying to render a full picture of my favorite internet sensation, the Tourette's guy, but I'm running into significant problems. The titular problem I have is that the background sprites are all not fully displayed on the screen; almost as if the loading of an image on the internet has frozen. I've tried removing all byte values containing $00 in the RODATA for "tourettesguy", which didn't help except show different sprites. Can anyone help? Thanks!
This is the code I'm using (note that any mention of "text" is just a name for rendering the picture not an actual indicator that text exists)

Code: Select all

.segment "RODATA"
palette:
.byte $00,$0f,$10,$30,$00,$01,$21,$31,$00,$06,$16,$26,$00,$09,$19,$29

Tourettesguy:
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $01
.byte $02
.byte $03
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $04
.byte $05
.byte $06
.byte $06
.byte $06
.byte $07
.byte $08
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $09
.byte $0a
.byte $06
.byte $06
.byte $06
.byte $06
.byte $0b
.byte $0c
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $0a
.byte $0e
.byte $06
.byte $06
.byte $06
.byte $06
.byte $0f
.byte $10
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $11
.byte $06
.byte $06
.byte $06
.byte $06
.byte $06
.byte $12
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $13
.byte $06
.byte $06
.byte $06
.byte $06
.byte $06
.byte $14
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $15
.byte $16
.byte $06
.byte $06
.byte $06
.byte $06
.byte $06
.byte $17
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $18
.byte $19
.byte $1a
.byte $06
.byte $06
.byte $1b
.byte $06
.byte $1c
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $1d
.byte $1e
.byte $00
.byte $1f
.byte $20
.byte $06
.byte $21
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $22
.byte $23
.byte $24
.byte $25
.byte $06
.byte $26
.byte $06
.byte $27
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $28
.byte $29
.byte $00
.byte $00
.byte $0a
.byte $2a
.byte $06
.byte $06
.byte $2b
.byte $06
.byte $2c
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $2d
.byte $2e
.byte $2f
.byte $30
.byte $31
.byte $32
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $33
.byte $34
.byte $00
.byte $00
.byte $00
.byte $35
.byte $36
.byte $37
.byte $38
.byte $39
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $06
.byte $06
.byte $3a
.byte $3b
.byte $00
.byte $00
.byte $3c
.byte $3d
.byte $3e
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $3f
.byte $40
.byte $41
.byte $0f
.byte $42
.byte $43
.byte $44
.byte $45
.byte $46
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $47
.byte $48
.byte $49
.byte $4a
.byte $4b
.byte $4c
.byte $4d
.byte $06
.byte $4e
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $4f
.byte $00
.byte $00
.byte $50
.byte $06
.byte $51
.byte $52
.byte $06
.byte $53
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $54
.byte $55
.byte $56
.byte $06
.byte $06
.byte $57
.byte $58
.byte $59
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $5a
.byte $5b
.byte $06
.byte $06
.byte $5c
.byte $5d
.byte $00
.byte $00
.byte $00
.byte $5e
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $5f
.byte $60
.byte $61
.byte $06
.byte $62
.byte $00
.byte $00
.byte $00
.byte $63
.byte $64
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $65
.byte $66
.byte $06
.byte $67
.byte $68
.byte $00
.byte $69
.byte $6a
.byte $6b
.byte $6c
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $6d
.byte $6e
.byte $6e
.byte $6f
.byte $70
.byte $06
.byte $06
.byte $06
.byte $71
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $72
.byte $73
.byte $06
.byte $0f
.byte $74
.byte $06
.byte $06
.byte $06
.byte $75
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $76
.byte $77
.byte $06
.byte $78
.byte $79
.byte $06
.byte $7a
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $7b
.byte $7c
.byte $7d
.byte $7e
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $7f
.byte $e2
.byte $82
.byte $ac
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $c2
.byte $81
.byte $e2
.byte $80
.byte $9a
.byte $c6
.byte $92
.byte $e2
.byte $80
.byte $9e
.byte $e2
.byte $80
.byte $a6
.byte $00


.segment "HEADER"
    .byte "NES"
    .byte $1a
    .byte $02
    .byte $01
    .byte %00000000
    .byte $00
    .byte $00
    .byte $00
    .byte $00
    .byte $00,$00,$00,$00,$00
	
	
.segment "STARTUP"
.segment "ZEROPAGE"

index:
.res 1

.segment "CODE"
WAITVBLANK:
:
    BIT $2002
    BPL :-
    RTS

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

  JSR WAITVBLANK

clrmem:
  LDA #$00
  STA $0000, x
  STA $0100, x
  STA $0200, x
  STA $0400, x
  STA $0500, x
  STA $0600, x
  STA $0700, x
  STA $0300, x
  INX
  BNE clrmem

JSR WAITVBLANK

Main:
NewPalette:
	LDA #$3F	;High byte of the Palette Address
		STA $2006	;Feed the byte to the PPUADDRESS register ($2006)
		LDA #$00	;Low byte of the Palette Address
		STA $2006	;Feed the byte to the PPU ADDRESS register ($2006)
		LDA #$0F	;0F = black = background color
		STA $2007	;Feed the value to the PPUDATA register ($2007)
		LDA #$30	;30 = white = ball color
		STA $2007	;Feed the value to the PPUDATA register ($2007)
		LDA #$10	;10 = gray
		STA $2007	;Feed the value to the PPUDATA register ($2007)
		
loadTextData:
		lda #$20
		sta index
		lda #$20
		sta $2006
		lda #$20
		sta $2006
		ldx index
		textLoop:
			lda Tourettesguy,x
			sta $2007
			ldx index
			cpx #$ff
			beq Return
			inc index
			jmp textLoop
			Return:
			
	LDA #%10000000
STA $2000		;This register controls the PPU in terms of where the Sprite address should be, the background address, etc.
				; From a binary perspective, the value goes something like this: #%vmsbpinn
				; v = Vblank: This bit turns on the NMI, which makes the system jump from whatever it was doing to the VBLANK label
				; 0 = don't 1 = do
				; m = PPU select: This is an unused bit, but by default, it is set to master (0).
				; s = Sprite size: This bit determines the size of an individual sprite, 0 = 8x8, 1 = 8x16
				; b = Background Pattern Table Address (PTA): Where should the background sprites be placed?
				; 0 = $0000, 1 = $1000
				; p = Sprite PTA: Same as b but only applies to non-background sprites
				; i = PPU Address increment
				; n = Name table address
LDA #%00011000
STA $2001		;This register determines whether or not sprites can show on the screen. 
				;From a binary perspective, the value goes something like: #%fffpcsit
				; fff = Full background color: which color(s) ought to be emphasized? 
				; 000 = black, 001 = red, 010 = blue, 100 = green
				; p = Sprite visibility: self explanatory. 0 = off 1 = on
				; c = Background visibility: same as p except it applies to backgrounds
				; s = Sprite clipping: sprites that appear in the left 8 pixel column, 0 = off
				; i = Background clipping: same as s except it applies to backgrounds
				; t = Display type, 0 = color, 1 = monochrome
				; Now, since the value I registered is #%00010000, that '1' is in the 4th bit, which
				; turns on the Sprite visibility bit (s).
				

Loopy:
JMP Loopy

VBLANK:
RTI

.segment "VECTORS"
    .word VBLANK
    .word RESET
    .word 0
	
.segment "CHARS"
   .incbin "tourettes guy.chr"	;CHRS are files containing sprites
Attachments
tourettesguy.asm
(13.37 KiB) Downloaded 61 times
tourettes guy.chr
(4 KiB) Downloaded 67 times
lol.png

User avatar
nesrocks
Posts: 468
Joined: Thu Aug 13, 2015 4:40 pm
Location: Rio de Janeiro - Brazil
Contact:

Re: Background sprites cutoff too soon

Post by nesrocks » Mon Mar 16, 2020 8:27 pm

Code: Select all

			ldx index
			cpx #$ff
			beq Return
It could be that I'm sleepy right now, but doesn't this mean that you've only looped through less than 256 tiles? For an entire screen you need more than that, about 4x that many.
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!

Tompis1995
Posts: 17
Joined: Fri Feb 22, 2019 10:05 am

Re: Background sprites cutoff too soon

Post by Tompis1995 » Mon Mar 23, 2020 4:25 pm

nesrocks wrote:
Mon Mar 16, 2020 8:27 pm

Code: Select all

			ldx index
			cpx #$ff
			beq Return
It could be that I'm sleepy right now, but doesn't this mean that you've only looped through less than 256 tiles? For an entire screen you need more than that, about 4x that many.
How do I do that?

User avatar
nesrocks
Posts: 468
Joined: Thu Aug 13, 2015 4:40 pm
Location: Rio de Janeiro - Brazil
Contact:

Re: Background sprites cutoff too soon

Post by nesrocks » Mon Mar 23, 2020 4:47 pm

Have a secondary counter, add 1 to that every time the first one reaches #ff and keep reading and writing until it reaches 4.

Or... You could do something different. Make sure your data never has a certain value, for example "FF", except at the very end. Whenever you read "FF", that's the end and you branch out.
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!

Tompis1995
Posts: 17
Joined: Fri Feb 22, 2019 10:05 am

Re: Background sprites cutoff too soon

Post by Tompis1995 » Thu Mar 26, 2020 7:50 pm

nesrocks wrote:
Mon Mar 23, 2020 4:47 pm
Have a secondary counter, add 1 to that every time the first one reaches #ff and keep reading and writing until it reaches 4.

Or... You could do something different. Make sure your data never has a certain value, for example "FF", except at the very end. Whenever you read "FF", that's the end and you branch out.
But any register won't store a byte higher than ff and adding a second counter would only repeat the same cut off pattern below.

User avatar
dougeff
Posts: 2739
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Background sprites cutoff too soon

Post by dougeff » Fri Mar 27, 2020 4:35 am

Try using indirect indexed mode.

LDA ($12), y

Example, where addresses $12 and $13 hold a 2 byte address, which can point to anywhere between 0000 and ffff. $12 would hold the low byte and $13 the high byte (little endian).

The pointer address must be in the zero page.

NESASM uses unusual syntax for this mode...

LDA [$52], y

with brackets.
nesdoug.com -- blog/tutorial on programming for the NES

User avatar
nesrocks
Posts: 468
Joined: Thu Aug 13, 2015 4:40 pm
Location: Rio de Janeiro - Brazil
Contact:

Re: Background sprites cutoff too soon

Post by nesrocks » Fri Mar 27, 2020 4:47 am

Yep, that works perfectly and may be best.
The other approach, which is what I meant, is a nested loop. 2 counters, one you count up to #ff. When it reaches that point you inc the second counter and compare it to 4.
https://twitter.com/bitinkstudios <- Follow me on twitter! Thanks!

Tompis1995
Posts: 17
Joined: Fri Feb 22, 2019 10:05 am

Re: Background sprites cutoff too soon

Post by Tompis1995 » Fri Apr 03, 2020 10:47 am

Wait, I found a way to make it work! I split the "Tourettesguy" code in Rodata into 4 separate labels, each one containing no more than 256 bytes, and I repeated the main code 4 times with each having unique labels and pointers. I also added one byte to each label so the picture is perfectly vertically aligned.

Code: Select all

.segment "RODATA"
palette:
.byte $00,$0f,$10,$30,$00,$01,$21,$31,$00,$06,$16,$26,$00,$09,$19,$29

Tourettesguy:
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $01
.byte $02
.byte $03
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $04
.byte $05
.byte $06
.byte $06
.byte $06
.byte $07
.byte $08
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $09
.byte $0a
.byte $06
.byte $06
.byte $06
.byte $06
.byte $0b
.byte $0c
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $0a
.byte $0e
.byte $06
.byte $06
.byte $06
.byte $06
.byte $0f
.byte $10
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $11
.byte $06
.byte $06
.byte $06
.byte $06
.byte $06
.byte $12
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $13
.byte $06
.byte $06
.byte $06
.byte $06
.byte $06
.byte $14
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
Tourettesguy2:
.byte $00
.byte $00
.byte $00
.byte $00
.byte $15
.byte $16
.byte $06
.byte $06
.byte $06
.byte $06
.byte $06
.byte $17
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $18
.byte $19
.byte $1a
.byte $06
.byte $06
.byte $1b
.byte $06
.byte $1c
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $1d
.byte $1e
.byte $00
.byte $1f
.byte $20
.byte $06
.byte $21
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $22
.byte $23
.byte $24
.byte $25
.byte $06
.byte $26
.byte $06
.byte $27
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $28
.byte $29
.byte $00
.byte $00
.byte $0a
.byte $2a
.byte $06
.byte $06
.byte $2b
.byte $06
.byte $2c
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $2d
.byte $2e
.byte $2f
.byte $30
.byte $31
.byte $32
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $33
.byte $34
.byte $00
.byte $00
.byte $00
.byte $35
.byte $36
.byte $37
.byte $38
.byte $39
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $06
.byte $06
.byte $3a
.byte $3b
.byte $00
.byte $00
.byte $3c
.byte $3d
.byte $3e
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
Tourettesguy3:
.byte $00
.byte $3f
.byte $40
.byte $41
.byte $0f
.byte $42
.byte $43
.byte $44
.byte $45
.byte $46
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $47
.byte $48
.byte $49
.byte $4a
.byte $4b
.byte $4c
.byte $4d
.byte $06
.byte $4e
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $4f
.byte $00
.byte $00
.byte $50
.byte $06
.byte $51
.byte $52
.byte $06
.byte $53
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $54
.byte $55
.byte $56
.byte $06
.byte $06
.byte $57
.byte $58
.byte $59
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $5a
.byte $5b
.byte $06
.byte $06
.byte $5c
.byte $5d
.byte $00
.byte $00
.byte $00
.byte $5e
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $5f
.byte $60
.byte $61
.byte $06
.byte $62
.byte $00
.byte $00
.byte $00
.byte $63
.byte $64
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $65
.byte $66
.byte $06
.byte $67
.byte $68
.byte $00
.byte $69
.byte $6a
.byte $6b
.byte $6c
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $6d
.byte $6e
.byte $6e
.byte $6f
.byte $70
.byte $06
.byte $06
.byte $06
.byte $71
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
Tourettesguy4:
.byte $00
.byte $00
.byte $00
.byte $00
.byte $72
.byte $73
.byte $06
.byte $0f
.byte $74
.byte $06
.byte $06
.byte $06
.byte $75
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $76
.byte $77
.byte $06
.byte $78
.byte $79
.byte $06
.byte $7a
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $7b
.byte $7c
.byte $7d
.byte $7e
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $7f
.byte $e2
.byte $82
.byte $ac
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $00
.byte $c2
.byte $81
.byte $e2
.byte $80
.byte $9a
.byte $c6
.byte $92
.byte $e2
.byte $80
.byte $9e
.byte $e2
.byte $80
.byte $a6
.byte $00


.segment "HEADER"
    .byte "NES"
    .byte $1a
    .byte $02
    .byte $01
    .byte %00000000
    .byte $00
    .byte $00
    .byte $00
    .byte $00
    .byte $00,$00,$00,$00,$00
	
	
.segment "STARTUP"
.segment "ZEROPAGE"
screenHighByte:
.res 1
index:
.res 1

.segment "CODE"
WAITVBLANK:
:
    BIT $2002
    BPL :-
    RTS

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

  JSR WAITVBLANK

clrmem:
  LDA #$00
  STA $0000, x
  STA $0100, x
  STA $0200, x
  STA $0400, x
  STA $0500, x
  STA $0600, x
  STA $0700, x
  STA $0300, x
  INX
  BNE clrmem

JSR WAITVBLANK

Main:
NewPalette:
	LDA #$3F	;High byte of the Palette Address
		STA $2006	;Feed the byte to the PPUADDRESS register ($2006)
		LDA #$00	;Low byte of the Palette Address
		STA $2006	;Feed the byte to the PPU ADDRESS register ($2006)
		LDA #$0F	;0F = black = background color
		STA $2007	;Feed the value to the PPUDATA register ($2007)
		LDA #$30	;30 = white = ball color
		STA $2007	;Feed the value to the PPUDATA register ($2007)
		LDA #$10	;10 = gray
		STA $2007	;Feed the value to the PPUDATA register ($2007)
		
loadTextData:
		lda #$20
		sta screenHighByte
		lda #$20
		sta index
		lda screenHighByte
		sta $2006
		lda #$20
		sta $2006
		ldx index
		textLoop:
			lda Tourettesguy,x
			sta $2007
			ldx index
			cpx #$ff
			beq newLine
			inc index
			jmp textLoop
	newLine:
		inc index
		ldx index
			textLoop2:
			lda Tourettesguy2,x
			sta $2007
			ldx index
			cpx #$ff
			beq newLine2
			inc index
			jmp textLoop2
	newLine2:
		inc index
		ldx index
			textLoop3:
			lda Tourettesguy3,x
			sta $2007
			ldx index
			cpx #$ff
			beq newLine3
			inc index
			jmp textLoop3
	newLine3:
		inc index
		ldx index
			textLoop4:
			lda Tourettesguy4,x
			sta $2007
			ldx index
			cpx #$67
			beq Return
			inc index
			jmp textLoop4
			Return:
			
			
	LDA #%10000000
STA $2000		;This register controls the PPU in terms of where the Sprite address should be, the background address, etc.
				; From a binary perspective, the value goes something like this: #%vmsbpinn
				; v = Vblank: This bit turns on the NMI, which makes the system jump from whatever it was doing to the VBLANK label
				; 0 = don't 1 = do
				; m = PPU select: This is an unused bit, but by default, it is set to master (0).
				; s = Sprite size: This bit determines the size of an individual sprite, 0 = 8x8, 1 = 8x16
				; b = Background Pattern Table Address (PTA): Where should the background sprites be placed?
				; 0 = $0000, 1 = $1000
				; p = Sprite PTA: Same as b but only applies to non-background sprites
				; i = PPU Address increment
				; n = Name table address
LDA #%00011000
STA $2001		;This register determines whether or not sprites can show on the screen. 
				;From a binary perspective, the value goes something like: #%fffpcsit
				; fff = Full background color: which color(s) ought to be emphasized? 
				; 000 = black, 001 = red, 010 = blue, 100 = green
				; p = Sprite visibility: self explanatory. 0 = off 1 = on
				; c = Background visibility: same as p except it applies to backgrounds
				; s = Sprite clipping: sprites that appear in the left 8 pixel column, 0 = off
				; i = Background clipping: same as s except it applies to backgrounds
				; t = Display type, 0 = color, 1 = monochrome
				; Now, since the value I registered is #%00010000, that '1' is in the 4th bit, which
				; turns on the Sprite visibility bit (s).
				

Loopy:
JMP Loopy

VBLANK:
RTI

.segment "VECTORS"
    .word VBLANK
    .word RESET
    .word 0
	
.segment "CHARS"
   .incbin "tourettes guy.chr"	;CHRS are files containing sprites

User avatar
dougeff
Posts: 2739
Joined: Fri May 08, 2015 7:17 pm
Location: DIGDUG
Contact:

Re: Background sprites cutoff too soon

Post by dougeff » Fri Apr 03, 2020 12:51 pm

Typically you would increment the X register (inx) and use bne for a loop of 256. When the inx results in x=0 it breaks the loop.

ldx #0

loop:

lda data, x
sta $2007
inx
bne loop

This will copy exactly 256 bytes.
nesdoug.com -- blog/tutorial on programming for the NES

Post Reply