Does anyone have the files that come with Gbaguy's tutorial

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

sebanonis
Posts: 16
Joined: Fri Dec 28, 2007 7:40 pm

Post by sebanonis »

Thanks.

Will check it out.

BTW, Happy New Year!
sebanonis
Posts: 16
Joined: Fri Dec 28, 2007 7:40 pm

Post by sebanonis »

HI Celius

I reread the tutorials on the 6502 opcodes -

Code: Select all

 lda   #$21
   sta   $2006
   lda   #$00
   sta   $2006       ;Point 8 rows down in Name Table.

   ldx   #$00          ;-
   txa                 ; \

 DefMap0:
   ldy   #$10        ; set Y to 16
   tax		   ; xfer A to X	

DefMap1:
   stx $2007
   inx               ; Increment X
   dey               ; Decrement Y
   bne   DefMap1     ; If Y not 0, go back to DefMap1
   ldy   #$10        ; Else restart Y
   tax

 DefMap2:
   stx $2007
   inx
   dey
   bne   DefMap2

   txa
   cpx   #$00          ; /
   bne   DefMap0      ;-

Is the above code the part that draws the two images? Just wanted to make sure I am on the right track. I am still grappling with how graphics is generated via the PPU, whether the tiles are written sequentially or via nested loops for rows and columns.

Re the palette -

Code: Select all

DrawAtt:
   lda   #$00
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
   lda   #$00       ;Palette #0
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
   dey
   bne   DrawAtt
The second LDA is used for the second image, right? So if I am able to get rid of the second image, I won't need the second LDA. Is this right? TIA.[/code]
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

You are correct about that being the code that displays the two images. What happens is this:

The loop starts off with A being 0, and X being 0. The first loop stores X into $2007 16 times, each time it stores, X increases by 1. After that first loop, A, or 0, is transfered into X. That is the cause of the two contiguous images. The first loop stores tiles until it reaches the middle of the row. The loop on the bottom basically stores whatever was stored in the first half in the second half.

About the attributes, you don't need to load #$00 again if A is already #$00. But you'll still need to store data into $2007 8 times per row, unless you manually reset the pointer.
sebanonis
Posts: 16
Joined: Fri Dec 28, 2007 7:40 pm

Post by sebanonis »

HI Celius,

I commented out the nested loop as shown below:

Code: Select all

   lda   #$21
   sta   $2006
   lda   #$00
   sta   $2006       ;Point 8 rows down in Name Table.

   ldx   #$00          ;-
   txa                 ; \

DefMap0:
   LDY #$10          ; set Y to 16

   TAX		   ; xfer A to X	
DefMap1:
   STX $2007
   INX               ; Increment X
   DEY               ; Decrement Y
   BNE DefMap1       ; If Y not 0, go back to DefMap1
;  LDY #$10          ; Else restart Y

;  TAX
; DefMap2:
;  STX $2007
;  INX
;  DEY
;  BNE DefMap2

   TXA
   CPX #$00          ; /
   BNE DefMap0       ;-
But in doing so, I still get the two images, albeit they are both distorted. What am I doing wrong?

As for the attribute, am I right in concluding I don't need to do the loop?

Code: Select all

;   ldy   #$02	   ; No need to do a loop	
; DrawAtt:           ; No need to do a loop
   lda   #$00
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
  ; dey              ; No need to do a loop  
  ; bne   DrawAtt    ; No need to do a loop
As always, thanks for your patience in helping me.
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

sebanonis wrote: But in doing so, I still get the two images, albeit they are both distorted. What am I doing wrong?.
Okay, I should've asked earlier. What exactly are you wanting on screen? Just one 128x128 display in the center of the screen?
sebanonis wrote: As for the attribute, am I right in concluding I don't need to do the loop?

Code: Select all

;   ldy   #$02	   ; No need to do a loop	
; DrawAtt:           ; No need to do a loop
   lda   #$00
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
   sta   $2007
  ; dey              ; No need to do a loop  
  ; bne   DrawAtt    ; No need to do a loop
Actually, I was trying to say that in general, you don't NEED a loop to store information to the background. I wasn't referring to your code. But you'll want to do the loop in your case.

If I were you, I'd scrap the whole mishmash of code, and right a demo from scratch. That way, you should know what's going on. But explain what you want to happen please.
sebanonis
Posts: 16
Joined: Fri Dec 28, 2007 7:40 pm

Post by sebanonis »

Hi Celius,

Basically I am starting with just a simple program - to put a logo in the background. I have converted the logo into a 128x128 bmp, then converted that to a CHR. That's all.

I discovered the old message board and saw some old threads on backgrounds. I am presently reading these and hopefully should learn something from them.

I agree, writing a simple demo from scratch would be the preferred way and I started out doing that but soon hit a wall with the graphics. At least, using a base demo program, I can experiment by changing the values and studying the result. Admittedly it is not the most scientific way, but I am beginning to learn bits and pieces from doing so.

Thanks.
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

Well, if you want a 128x128 logo on the background, I'm assuming you want it in the center of the screen. How about I just do this. This should copy the whole thing to the background in the center of the screen:

Code: Select all

	lda #$20		;Here we tell the PPU to start putting tiles on the name table
	sta $2006	;At location $20E8.
	sta PPUPointerH	;We save the value of the starting pointer
	lda #$E8
	sta $2006
	sta PPUPointerL
	ldy #0		;Start with $0
-
	sty $2007.w	;Store Y in $2007
	iny		;Increase Y by one to get the next tile value
	tya		;Here we check if Y is a multiple of $10 by seeing if the low
	and #$0F		;4 bits are $0
	bne -		;If Y is not equal to zero after eliminating the upper 4 bits,
			;Do the loop again (It will loop 16 times)
	clc		;We take the previous PPU address, and we tell it to point to
	lda PPUPointerL	;The next row.
	adc #$20		;Add #$20, because that's how many tiles are in a row
	sta PPUPointerL	;If you don't know, this is an example of 16-bit addition. If
	lda PPUPointerH	;PPUPointerL wraps around, the Carry flag will be set. Here
	adc #0		;We tell it to add #0 + the Carry flag to PPUPointerH. If the carry flag
	sta PPUPointerH	;is set, it will add one to PPUPointerH.
	lda PPUPointerH	;Store the new PPU pointer values in $2006
	sta $2006
	lda PPUPointerL
	sta $2006
	cpy #0		;See if Y is #0. If it is, that means we've wrapped around, and thus,
			;reached the end.
	bne -		;If not, go back to do the loop.
You'll need to assign variables in RAM to PPUPointerL and PPUPointerH. I tested it and it works. It should work for you.
sebanonis
Posts: 16
Joined: Fri Dec 28, 2007 7:40 pm

Post by sebanonis »

Hi Celius,

Thanks so much.

Will study it first to make sure I fully understand everything before proceeding to the next phase.

Spent the last few days reading on name tables, pattern tables, and attribute tables.

I have to admit it is really frustrating trying to learn NES programming without a comprehensive structured tutorial.

You don't have any idea how appreciative I am with your patience and willingness to provide guidance.

Thanks again!
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

Oh also, delete the ".w" at the end of "sty $2007" if you're not using WLA-DX. For some reason, there's a bug where you need to put ".w" at the end of $2007 if you're storing X or Y into that register.

I am happy to be of help, because I know how frustrating it can be. I came without any programming experience, and for about 6 months, I didn't really know what I was doing. It just takes time and patience, and not getting frustrated. You should see SNES programming. The only thing you really have to go by is the documentation out there, because not many people program for the SNES anymore. Thankfully, the NESdev scene is really active in comparison.
sebanonis
Posts: 16
Joined: Fri Dec 28, 2007 7:40 pm

Post by sebanonis »

Hi Celius,

It works!

I set the PPUPointer to $2100, labeled the loop and everything came out okay. But I still need to digest everything to make sure I fully understand everything before proceeding. Will also experiment with some of the values.

Thanks so much. Really appreciate it.
sebanonis
Posts: 16
Joined: Fri Dec 28, 2007 7:40 pm

Post by sebanonis »

Hi Celius,

There is a short green horizontal bar right at the upper left corner of the screen. What could be causing it? TIA
Celius
Posts: 2159
Joined: Sun Jun 05, 2005 2:04 pm
Location: Minneapolis, Minnesota, United States
Contact:

Post by Celius »

Most likely you have sprites turned on, and you haven't assigned proper values to them. Are you using sprite DMA? If so, that's probably it if you aren't doing anything with the sprites. If you're not using the sprites, make sure you clear whatever page ($100 byte section in RAM) with any value between $F0-$FF. This will render them off screen, and they will not be visible.

Example:

Code: Select all

    ldx #0        ;pretend you're assigning $300 to sprite DMA
    lda #$FF
-
    sta $300,x   ;This will store $FF in that whole page.
    inx
    bne -

    blah code

nmi:
    lda #3        ;Store #3 (For $[b]3[/b]00) in $4014
    sta $4014     ;To let it know to use that page for sprite data
If sprites are turned on, you want all unused sprites off screen, so you can do this by making the Y coordinate any value between $F0-$FF. That I'm pretty sure will solve your problem.
sebanonis
Posts: 16
Joined: Fri Dec 28, 2007 7:40 pm

Post by sebanonis »

Hi Celius,

Yup, I had sprites turned on. Set D4 to 0 and everything turned out okay. Actually I played around with the palette table and managed to make the bar disappear by matching the background color. Of course I know this is a cheat and is not a feasible solution but I took the opportunity to learn more about the palette table. :)

Again, thanks!
sebanonis
Posts: 16
Joined: Fri Dec 28, 2007 7:40 pm

Post by sebanonis »

Hi Celius,

It works!

I set the PPUPointer to $2100, labeled the loop and everything came out okay. But I still need to digest everything to make sure I fully understand everything before proceeding. Will also experiment with some of the values.

Thanks so much. Really appreciate it.
Post Reply