Scrollin'

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems. See the NESdev wiki for more information.

Moderator: Moderators

Post Reply
User avatar
cartlemmy
Posts: 193
Joined: Fri Sep 24, 2010 4:41 pm
Location: California, USA
Contact:

Scrollin'

Post by cartlemmy »

I have scrolling implemented now. Though it is a tad buggy I have the core engine in place. Let me know what you think.

Source: http://www.yibbleware.com/nes/cartlemmy-test-0.2.zip
NES: http://www.yibbleware.com/nes/cartlemmy-test-0.2.nes

(use UDLR on controller to scroll)



Also, I want to make it so that the background initialization is done all in one pass... The problem is there is not enough vBlank time for that. Is there a way I can black the screen out and keep rendering without the PPU interfering?
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Post by Dwedit »

PPUMASK register ($2001)

Set to 0 and the screen becomes blank (uses the background color from the palette), and you can draw as much as you want.
Make sure to wait for vblank (NMI) before you turn the screen back on.

By the way, I tend to use stack tricks to do PPU writes, so your draw code can look something like:

PLA
STA $2007
PLA
STA $2007
PLA
STA $2007
PLA
STA $2007
...

It's probably not the "best way" for newcomers to do it though, but it sure is fast. You need to absolutely make sure there is no way for that code to be interrupted.

Here's a snippet of code I was using to draw columns onto the screen in my own scrolling demo. (thread) (File)
It's designed for vertical mirroring, so it assumes that columns will be drawn in two parts, one for the 'top half' and one for the 'bottom half'.

Code: Select all

DrawColumn:
	lda #$04  ;disable NMI, inc by 32
	sta PPUCTRL
	
	tsx
	txa ;save old stack pointer to register A
	ldx #(NameTableBufferColumn-1)&$FF
	txs
	tax ;copy old stack pointer to register X
	
	lda ntColAddress1+1
	sta PPUADDR
	lda ntColAddress1
	sta PPUADDR
	ldy ntColBlocksRemaining1
-
	pla
	sta PPUDATA
	pla
	sta PPUDATA
	dey
	bne -

	ldy ntColBlocksRemaining2
	beq +
	lda ntColAddress2+1
	sta PPUADDR
	lda ntColAddress2
	sta PPUADDR
-
	pla
	sta PPUDATA
	pla
	sta PPUDATA
	dey
	bne -
+
	txs
	rts
Last edited by Dwedit on Fri Oct 15, 2010 10:15 am, edited 1 time in total.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
User avatar
cartlemmy
Posts: 193
Joined: Fri Sep 24, 2010 4:41 pm
Location: California, USA
Contact:

Post by cartlemmy »

Dwedit wrote:PPUMASK register ($2001)...
Awesome, that's exactly what I needed! Thanks for the help!
User avatar
p1xl
Posts: 32
Joined: Sat May 15, 2010 4:13 pm
Location: U.S./Canada
Contact:

Post by p1xl »

@Dwedit That's a really clever trick using the top of the stack like that.
User avatar
cartlemmy
Posts: 193
Joined: Fri Sep 24, 2010 4:41 pm
Location: California, USA
Contact:

Post by cartlemmy »

Also, is that ASM6? Because those + and - labels look really useful
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

Dwedit wrote:By the way, I tend to use stack tricks to do PPU writes, so your draw code can look something like:
Or using the .repeat command (automatic unrolling) in ca65:

Code: Select all

  .repeat 16, I
    pla           ; 4
    sta $2007     ; 4
  .endrepeat
This isn't really any faster than an unrolled LDA/STA loop from a transfer buffer, given all the "internal operation" cycles in PLA:

Code: Select all

  .repeat 16, I
    lda xferBufBase+I,x  ; 4
    sta $2007     ; 4
  .endrepeat
The latter appears considerably more beginner-friendly. And it can overlap unused stack areas too if you put the transfer buffers at $0100-$019F.
cartlemmy wrote:Also, is that ASM6? Because those + and - labels look really useful
The other way to do it, used by ca65, is : labels that can be accessed with :- and :+.
User avatar
cartlemmy
Posts: 193
Joined: Fri Sep 24, 2010 4:41 pm
Location: California, USA
Contact:

Post by cartlemmy »

tepples wrote:
cartlemmy wrote:Also, is that ASM6? Because those + and - labels look really useful
The other way to do it, used by ca65, is : labels that can be accessed with :- and :+.
So that's a 'yes, those + and - labels can be used in ASM6'? Sorry, I'm a n00b to this stuff :oops:
tepples
Posts: 22708
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)
Contact:

Post by tepples »

cartlemmy wrote:So that's a 'yes, those + and - labels can be used in ASM6'?
That's a yes. We recently had a discussion over the merits of these - and + labels.
User avatar
cartlemmy
Posts: 193
Joined: Fri Sep 24, 2010 4:41 pm
Location: California, USA
Contact:

Post by cartlemmy »

tepples wrote:
cartlemmy wrote:So that's a 'yes, those + and - labels can be used in ASM6'?
That's a yes. We recently had a discussion over the merits of these - and + labels.
Ah, ok cool. I remember that thread, I just didn't realize what the + and - were at the time, so I didn't notice :/
Post Reply