It is currently Wed Jun 26, 2019 3:29 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2, 3  Next
Author Message
 Post subject: question...
PostPosted: Tue Jan 17, 2006 11:30 am 
Offline
User avatar

Joined: Tue Jan 17, 2006 10:39 am
Posts: 143
Location: North Carolina
Hello,

Im VERY new to nes development. I'm decently comfortable with getting
sprites on the screen and positioning them (haven't done any movement of
sprites yet). I'd like to try my hand at backgrounds .... thats where I need
some guidance. At this point I have my background images separate from
my sprites (in two different chr files). So I guess my starting question is if I
have .bank 2's .org at $0000 (for the sprites) then what would I need to do
to include the background as well? Would it be a new bank at $1000? Plus
I'm also assuming (which means I could be wrong) that I need to pass 1 to
bit 4 of $2000 (PPU Control Register 1) and 1 to bit 3 of $2001 (to show the
background). Any help is greatly appreciated.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 12:18 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7717
Location: Chexbres, VD, Switzerland
Quote:
I'm also assuming (which means I could be wrong) that I need to pass 1 to
bit 4 of $2000 (PPU Control Register 1) and 1 to bit 3 of $2001 (to show the
background). Any help is greatly appreciated.

That's pretty much correct. However, you'll have to first clear $2001.3 and $2001.4 to "turn screen off", that means that you can freely write your NameTable data and AttributeTable data to $2006/7 needed to have any background on screen. Once you're done, turn the screen on by setting bits 3 and 4 of $2001. If you need any other $2006/7 update while the screen is on, you have to do it during the VBlank time, right after an NMI. I don't guess you should try that at first, tough.

To include a second CHR file, just insert a second .incbin the second file after the first. I assume you're using NESASM, and I cannot say you that's bad due to the fact you're a newbie, but keep in mind that there are better assemblers out there.

EDIT : Oh yeah, once you have finished to draw your background, you HAVE to set the scrolling registers to get proper image on screen. To do that, wait a frame with $2002.7 or do that in your NMI routine. You should write twice to $2005 to get proper scrolling. If you don't do that (or if you just do that at reset), your scrolling will get altered by $2006 writes.

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 12:51 pm 
Offline
User avatar

Joined: Tue Jan 17, 2006 10:39 am
Posts: 143
Location: North Carolina
Quote:
To include a second CHR file, just insert a second .incbin the second file after the first. I assume you're using NESASM, and I cannot say you that's bad due to the fact you're a newbie, but keep in mind that there are better assemblers out there.


Sorry. Yes I'm using nesasm. I've downloaded WLA-DX but figured I should
get a handle on nesasm before moving to something much bigger....

Quote:
EDIT : Oh yeah, once you have finished to draw your background, you HAVE to set the scrolling registers to get proper image on screen. To do that, wait a frame with $2002.7 or do that in your NMI routine. You should write twice to $2005 to get proper scrolling. If you don't do that (or if you just do that at reset), your scrolling will get altered by $2006 writes.


What I was messing with is a potential side scroller ... but was really just
trying to find my way to get a background just visible ... which brings me
to my next question...

I've been doing something like this for my sprites....
Code:

 .bss

IMG.Y = $700
IMG.T = $701
IMG.S = $702
IMG.X = $703
... later...
clear the memory for sprites..

... later ...
 lda #136
 sta IMG.Y
 sta IMG.x
 lda #1
 sta IMG.T
 lda #0
 sta IMG.S
... later (again) ...

lda #7
sta $4014 ; DMA 100x 7


Would I need to be doing my background tiles the same way? Is this even
the right way to really be doing the sprites? I've seen somethings on
name tables ... I think I understand what they are. (tile index #s in a file)
Just really not sure how to make them or use them. I downloaded the
chr2nam program but couldn't get it to work with my chr.

Also, is it better to use the sprite DMA or should I be using 2003/4?

Thanks so much for your help thus far.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 1:04 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7717
Location: Chexbres, VD, Switzerland
Quote:

Also, is it better to use the sprite DMA or should I be using 2003/4?



Sprite DMA is better, and you HAVE to do it in VBlank, so right after an NMI.

Quote:
Would I need to be doing my background tiles the same way? Is this even
the right way to really be doing the sprites? I've seen somethings on
name tables ... I think I understand what they are. (tile index #s in a file)
Just really not sure how to make them or use them. I downloaded the
chr2nam program but couldn't get it to work with my chr.


Background displaying works totally different than sprites. You'll have to fit your tile data in name tables and color data in attributes tables. (for your first try just put some data in one single nametable with screen off, wait for VBlank or for an NMI, and turn the screen on then write twice zero to $2005, be sure to write to $2000 to setup the good on-screen nametable and do sprite DMA).

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 1:52 pm 
Offline
User avatar

Joined: Mon Sep 27, 2004 8:33 am
Posts: 3715
Location: Central Texas, USA
lynxsolaris wrote:
Sorry. Yes I'm using nesasm. I've downloaded WLA-DX but figured I should
get a handle on nesasm before moving to something much bigger....


That's the thing, nesasm's bank handling gets in the way as much as it helps, so other assemblers are easier to deal with, not harder.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 1:53 pm 
Offline
User avatar

Joined: Tue Jan 17, 2006 10:39 am
Posts: 143
Location: North Carolina
Quote:

Background displaying works totally different than sprites. You'll have to fit your tile data in name tables and color data in attributes tables. (for your first try just put some data in one single nametable with screen off, wait for VBlank or for an NMI, and turn the screen on then write twice zero to $2005, be sure to write to $2000 to setup the good on-screen nametable and do sprite DMA).


wow ... boy I really realize how much I still have to learn.... can you give me a little push on how to "fit your data in a name tables and color data into
attributes tables" .. I'm assuming it has something to do with $2006/7? Load
something into $2006 and then the actual data into $2007???? Or am I
WAY off. Thanks for the patience for a newbie.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 1:55 pm 
Offline
User avatar

Joined: Tue Jan 17, 2006 10:39 am
Posts: 143
Location: North Carolina
blargg wrote:
That's the thing, nesasm's bank handling gets in the way as much as it helps, so other assemblers are easier to deal with, not harder.


Oh I didn't know that. I was told that as someone just starting out that
nesasm would be the best for me.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 2:04 pm 
Offline
User avatar

Joined: Fri Nov 12, 2004 2:49 pm
Posts: 7717
Location: Chexbres, VD, Switzerland
lynxsolaris wrote:
wow ... boy I really realize how much I still have to learn.... can you give me a little push on how to "fit your data in a name tables and color data into
attributes tables" .. I'm assuming it has something to do with $2006/7? Load
something into $2006 and then the actual data into $2007???? Or am I
WAY off. Thanks for the patience for a newbie.


I cannot help you much with the nametable and attribute table format, there is a lot of docs covering that. However, place your adress into $2006 (for example if you want to write at $2100 in PPU RAM to acess the nametable, write #$21, then #$00 to $2006), and then place a data or a string of data to $2007, the adress will automatically increment (be sure to keep $2000.4 clear, else it will increment by 32, usefull only to have column strings).

_________________
Life is complex: it has both real and imaginary components.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 9:45 pm 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11371
Location: Rio de Janeiro - Brazil
Bregalad wrote:
(be sure to keep $2000.4 clear, else it will increment by 32, usefull only to have column strings).


lynxsolaris, if you are planning a side scroller, you'll definately be using this. I don't know if you got what Bregalad said, and before you get confused about the "auto increment" thing, I'd like to say a few things.

As bregalad said, you are right, just write the address where you want to draw the tiles to $2006 and then write the tiles to $2007. The auto increment makes it possible to write long runs of data by setting the address just once, when you begin. And you can choose how much to increment after every write, 1 or 32 bytes.

Increments of 1 are usefull when you draw from the left to the right, and increments of 32 are usefull when you draw from the top down. So, in a side scroller, you'll be using increments of 32, to constantly add new columns of graphics in the direction the player moves.

Well, it may be too soon to be thinking about the actual game, but... Well, play a little with the background and soon you'll begin scrolling stuf. I'd recommend you not to mess with the attribute table until you master the name table, ok? Just wanted to give you something to think about, so you can have an idea of how things work.

I had some trouble with the background at first because back when I programmed games for MS-DOS, I used to redraw the whole screen every frame. The NES is not fast enough for that, and you must draw only what's changed from one frame to the other.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 10:54 pm 
Offline
User avatar

Joined: Tue Jan 17, 2006 10:39 am
Posts: 143
Location: North Carolina
tokumaru wrote:
Well, it may be too soon to be thinking about the actual game, but... Well, play a little with the background and soon you'll begin scrolling stuf. I'd recommend you not to mess with the attribute table until you master the name table, ok? Just wanted to give you something to think about, so you can have an idea of how things work.


I definitely agree with you there. Right now Im just trying to get a background to read from a
chr and display the different tiles. I'd like to make a game some point but need to have a
better understanding of this beginning items first.


Thanks to both you and Bregalad for all your help so far. I started a new little test project
Here is the code I have thus far....
Code:

 .inesprg 1
 .ineschr 1
 .inesmir 0
 .inesmap 0
 
 .code
 .org $8000


main:
 lda #%00001000
 sta $2000
 lda #%00001000
 sta $2001

 jsr wait_vblank
 lda #$3F
 sta $2006
 lda #$00
 sta $2006
 ldx #$00

 lda #$0d
 sta $2007
 lda #$08
 sta $2007
 lda #$28
 sta $2007
 lda #$19
 sta $2007

 lda #$20
 sta $2006
 lda #$00
 sta $2006

 lda #$01
 sta $2007
 lda #$02
 sta $2007
 lda #$03
 sta $2007
end:
 jmp end

wait_vblank:
 bit $2002
 bpl wait_vblank
 rts

nmi:
int:
 rti

 .bank 1
 .org $FFFA
 .dw nmi,main,int

 .bank 2
 .org $0000
 .incbin "test.chr"


My writes to the color palette work fine ($3F00).
For some reason (and maybe this is what its suppose to do) it just displays the first tile tiled
over and over again. I thought if I wrote to $2006 (twice) with $2000 and wrote my tile
numbers to $2007 that it would show them? I believe Im missing something here ....

It does seem that if I just turn on the background bit (2001.3) that it automatically tiles the
first tile across the screen....


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 17, 2006 11:07 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1465
You need to reset the VRAM address after you're done writing to memory. To do this, write once to $2000 (to select which nametable to start rendering at) and then write twice to $2005 (to specify the horizontal and vertical scroll).

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 5:30 am 
Offline
User avatar

Joined: Tue Jan 17, 2006 10:39 am
Posts: 143
Location: North Carolina
Quietust wrote:
You need to reset the VRAM address after you're done writing to memory. To do this, write once to $2000 (to select which nametable to start rendering at) and then write twice to $2005 (to specify the horizontal and vertical scroll).


Thanks. So you have to set $2005 even if Im just trying to get an on screen background
without scrolling at this point?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 8:20 am 
Offline
User avatar

Joined: Sat Feb 12, 2005 9:43 pm
Posts: 11371
Location: Rio de Janeiro - Brazil
lynxsolaris wrote:
So you have to set $2005 even if Im just trying to get an on screen background without scrolling at this point?


Yes. The values you write to $2005 are the top left coordinates of the "camera" over the nametable. If you're not scrolling, just write 0 to $2005 twice and you'll have a full and static view of the name table you selected by writing to $2000.

Scrolling is just the effect produced by successive writes to $2005. If you write 0, 0, you'll see the nametable centered on the screen. Then, in the next frame you write 1, 0, wich means the camera moved a bit to the right. Then you write 2, 0, moving one more pixel to the right, and so on.

So, if you want to have a static screen you still have to write to $2005 so that the PPU knows where exactly to place the nametable on the screen.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 4:54 pm 
Offline
User avatar

Joined: Tue Jan 17, 2006 10:39 am
Posts: 143
Location: North Carolina
Thanks for you help so far. I spent my lunch break thinking
over the advice and knowledge you've given me so far. I :oops: think
:oops: I have a better understanding now but I'm not quite there yet.

If you don't mind ... heres some code ... please let me know anything you
see me doing wrong or if you think theres a "better" way I should be
doing it.

Code:
 .inesprg 1
 .ineschr 1
 .inesmir 0
 .inesmap 0
 
 .code
 .org $8000


main:
 sei
 cld
 ldx #0
 stx $2000
 stx $2001

 jsr wait_vblank
 jsr palette
 jsr nametable
 jsr ppuinit
end:
 jmp end
 
palette:
 lda #$3F
 sta $2006
 lda #$00
 sta $2006
 ldx #$00

 lda #$0d
 sta $2007
 lda #$08
 sta $2007
 lda #$28
 sta $2007
 lda #$19
 sta $2007
 rts

nametable:
 lda #$20
 sta $2006
 lda #$00
 sta $2006 ; name table @ $2000

 lda #$00 ; index #1 in chr file?????
 sta $2007
 lda #$01 ; index # 2......
 sta $2007
 rts

ppuinit:
 lda #%00000000 ; background at $0000
 sta $2000
 lda #%00001000 ; show backgrounds
 sta $2001
 jsr wait_vblank
 lda #$0
 sta $2005
 lda #$0
 sta $2005
 rts

wait_vblank:
 bit $2002
 bpl wait_vblank
 rts

nmi:
int:
 rti

 .bank 1
 .org $FFFA
 .dw nmi,main,int

 .bank 2
 .org $0000
 .incbin "bk.chr"


I'm still doing something wrong (obviously) because I still have blocks
(the first block image in my chr file) that tiles the entire screen. I'm
trying to get these blocks to do two or 3 rows near the bottom of the
screen. Any pointers? Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 18, 2006 5:41 pm 
Offline
User avatar

Joined: Sun Sep 19, 2004 10:59 pm
Posts: 1465
lynxsolaris wrote:
I still have blocks (the first block image in my chr file) that tiles the entire screen.


That's because most emulators initialize RAM to contain all zeros. Be careful, though - on the real hardware, RAM is initialized to mostly random values, so you need to initialize ALL memory you use - for the PPU, this means setting the VRAM address to $2000 and then writing $00/$FF 960 times to $2007 (followed by 64 bytes of $00) and making sure that tile 00/FF is "blank".

_________________
Quietust, QMT Productions
P.S. If you don't get this note, let me know and I'll write you another.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 33 posts ]  Go to page 1, 2, 3  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group