Pallete affects scroll value

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

User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Pallete affects scroll value

Post by IMAGICA »

Answer to first question:
This is so that I can double the screen size Ala SMB3 by using adjacent tiles to get a certain effect of doubling the screen size using one hex memory address, effectively filling both "screens" of the PPU. While my arrogance that has shown prominently during this wants to explain how I did it, I want to tell you what it was originally

Code: Select all

DrawColumn:
  LDA #%00100100        ; set to increment +32 mode
  STA $2000
  
  LDA $2002             ; read PPU status to reset the high/low latch
  LDA columnHigh
  STA $2006             ; write the high byte of column address
  LDA columnLow
  STA $2006             ; write the low byte of column address
  LDX #$1E         ; copy 30 bytes
  LDY #$1E
DrawColumnLoop:
  LDA [sourceLow], y
  STA $2007
  INY
  DEX
  BNE DrawColumnLoop

  


  
DrawNewColumn2:
  LDA scroll       ; calculate new column address using scroll register
  LSR A
  LSR A
  LSR A            ; shift right 3 times = divide by 8
  STA columnLow2    ; $00 to $1F, screen is 32 tiles wide

  LDA nametable     ; calculate new column address using current nametable
  EOR #$01          ; invert low bit, A = $00 or $01
  ASL A             ; shift up, A = $00 or $02
  ASL A             ; $00 or $04
  CLC
  ADC #$28          ; add high byte of nametable base address ($2000) can change to lower name table $2000 = ADC #$20 $2800 = ADC #$28 changes what loads the name table in the bottem name table in
  STA columnHigh    ; now address = $20 or $24 for nametable 0 or 1

  LDA columnNumber2  ; column number * 32 = column data offset
  ASL A
  ASL A
  ASL A
  ASL A
  ASL A             
  STA sourceLow2
  LDA columnNumber
  LSR A
  LSR A
  LSR A
  STA sourceHigh2
  
  LDA sourceLow       ; column data start + offset = address to load column data from
  CLC 
  ADC #$04
  STA sourceLow2
  LDA sourceHigh
  ADC #$04
  STA sourceHigh2

DrawColumn2:
  LDA #%00100100        ; set to increment +32 mode
  STA $2000
  
  LDA $2002             ; read PPU status to reset the high/low latch
  LDA columnHigh
  STA $2006             ; write the high byte of column address
  LDA columnLow
  STA $2006             ; write the low byte of column address
  LDX #$1E              ; copy 30 bytes
  LDY #$1E
DrawColumnLoop2:
  LDA [sourceLow2], y
  STA $2007
  INY
  DEX
  BNE DrawColumnLoop2

  
;;;;;;;;;;
scrollCheck:

  
  LDA player
  CLC
  ADC #$08  
  CMP #$80
  BEQ ReadController1
  
  LDA player
  CLC
  ADC #$08  
  CMP #$80
  BCC Rights
  
  
  
  LDA player
  SEC
  SBC #$01
  STA player
   
  LDA #$00
  STA sdir
  
  JMP ReadController1
  

  
  RTS
witch took too much memory from the hex by using the next screen data, halving the game's level data.
The new code like you said
[writes] the value from [sourcelow],y to $2007, then adding 1 that value and writing that to $2007. So for every byte in the address pointed to in sourcelow, you're writing two bytes.
Whitch keeps the level long without compensating the length.

Answer to the second question:
The game isn't finished. When I learn Bank switching and r-a-m- -s-t-o-r-a-g-e(already done) , I'll get working on the other game elements. If there's problem with it, tell me please.
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Pallete affects scroll value

Post by Kasumi »

Yes, there is a problem. Your ROM claims to be 48KB in the header, but it's only 40KB, which makes some emulators reject it outright. Nestopia is one such emulator. VirtuaNES is another. Adding the bank directive as I've instructed will tell NESASM to add another CHR bank (8KB) to your file so that it will be the proper size.

One thing to note is that $2000 isn't written to before (or in) DrawNewAttributes in the NMI, so when $2007 is written to in DrawNewAttributes it is incrementing by whatever was last written to $2000.

Your game crashes when you press A because of this code:

Code: Select all

LDA JumpState;If JumpState is >= 1
  CMP #$01
  BCS ReadADonep1;go to ReadADonep1
  
  LDA #$01;This makes JumpState equal to 1
  STA JumpState
ReadADonep1:  
  
  LDA JumpState;If JumpState is >= 1
  CMP #$01;Go to ReadADonep1
  BCS ReadADonep1;Because ReadADonep1 is directly above, this is an endless loop.
User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Pallete affects scroll value

Post by IMAGICA »

Trying to write to $0700 and every time I do, It resets to $FF

Code: Select all

DrawColumnLoop:
  
  LDA [sourceLow], y
  STA $0700,y
  INY  
  DEX
  BNE DrawColumnLoop
  
  
  RTS
Attachments
Kitsunetales.asm
(19.48 KiB) Downloaded 107 times
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Pallete affects scroll value

Post by Kasumi »

First: There is no ROM, nor a way to build the ROM, so I can't even see the problem you're currently talking about. Can you share the other files one needs to build the game, instead of just the .asm? "KitsuneTaleslevel.bin", "KitsuneTaleslevel2.bin", "KitsuneTalesattrib.bin", "KitsuneTalesattrib2.bin", "Electro_and_Shiro.chr" and "Kitsunetales.chr". This forum allows you to upload .zip files, so you can upload your project file as one file.

Edit:
Second: Please make the changes I suggested in my last post about CHR. I now see that you changed .ineschr to 3 instead of 4, but that... creates a different kind of problem. Potentially the problem you're describing.

The size of your CHR and PRG should be a power of two. If you multiply your .ineschr value by 8192 you'll get 24576 which is not a power of two. What I outlined as a fix was a way to avoid all of this kind of stuff. You want .ineschr 4, you want a .bank 5, and you want .org $0000 under each CHR .bank statement. (so .bank 3, .bank 4, and .bank 5 would want .org $0000 under them, instead of .org $A000 and $E000. .bank 2 is correct.) The last CHR banks can be empty, but they need to be there.

Third: Without building the ROM, that code looks like it'd do exactly what I said it'd do. That is, copy a single column from the address pointed to in sourceLow and sourceLow+1 to RAM (except at $0700+ rather than $0500+). So can you be more specific about the difference between what you are expecting to happen and what is actually happening?

Edit 2: Because it will help replicate exactly what you're seeing, what emulator are you using, and what version of that emulator? If testing on real hardware, what flash card/other type of cartridge? (Though I only own a powerpak and infiniteneslives MMC3 cart, so if it's not those then I can't see it exactly.)
User avatar
Punch
Posts: 365
Joined: Sat Feb 16, 2013 11:52 am

Re: Pallete affects scroll value

Post by Punch »

I want to program a MMC3 demake of smash bros, what's a vblank?
STOP and go read the basics immediately. Go read a decent tutorial (Nerdy Nights at a minimum, I'm sure people here have links to better reading material though) before trying to code complex stuff. You're not going anywhere if all you do is copy/paste code you barely understand even if we try our best to help you. Look at the complexity of a simple breakout game I've coded:

https://github.com/AleffCorrea/BrickBre ... lision.asm

Roughly 500 lines just for background and sprite collision detection... feel free to browse the rest of the files from my game. Don't be overwhelmed by it though, trust me when I say that if you stop what you're trying to do right now and direct your efforts towards learning the underlying concepts first you'll be doing code that is 10 times better than mine in no time.
This is a block of text that can be added to posts you make. There is a 255 character limit.
User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Pallete affects scroll value

Post by IMAGICA »

Here
Attachments
Tanuki.chr
Tanuki Tales spinoff 2d metalgear
(8 KiB) Downloaded 105 times
Kitsunetales.chr
Trash
(8 KiB) Downloaded 107 times
Electro_and_Shiro.chr
Main Graphics
(8 KiB) Downloaded 105 times
KitsuneTales.nes
ROM Game
(40.02 KiB) Downloaded 107 times
KitsuneTales.nes
Main code
(40.02 KiB) Downloaded 108 times
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]
User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Pallete affects scroll value

Post by IMAGICA »

YOU
Attachments
KitsuneTaleslevel2.bin
Level 2
(796 Bytes) Downloaded 106 times
KitsuneTalesattrib2.bin
level2 atribute
(36 Bytes) Downloaded 97 times
KitsuneTaleslevel.bin
Level 1
(48 Bytes) Downloaded 104 times
KitsuneTalesShiroAkai.chr
in case Trash doesn't work
(48.02 KiB) Downloaded 101 times
KitsuneTalesattrib.bin
atributes
(128 Bytes) Downloaded 100 times
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Pallete affects scroll value

Post by Kasumi »

I got rid of the code under anim, and scrollCheck. It wasn't used.
I got rid of readjoy. It wasn't used.
I got rid of Loadp. It wasn't used.
I got rid of LoadPalettes2. It wasn't used.

I recommend getting rid of dead code like that, it makes for way less to sift through while looking for errors.

DrawNewColumn uses columnNumber to decide which column to draw (which address to put into sourceLow and sourceHigh). columnNumber gets incremented every frame, so most of the time it's loading from data totally beyond your level data. Since the byte that's used to pad unused space is $FF in NESASM, this is why mostly $FF gets copied. Why columnNumber gets incremented, I have no idea. It's hard for me to follow the current code. And I know how I'd find out what's wrong, exactly, but I genuinely think the time would be better spent helping you rewrite it. As I, and others, have recommended, I would rewrite this one small step at a time.

1. Write code that copies a single fixed column to RAM.
When that works (check the RAM with FCEUX's hex editor)
2. Write code that copies a single column to RAM, that you can change with the d-pad. (Say... pressing right picks the next column. Pressing left picks the previous column.)
When that works (check the RAM with FCEUX's hex editor)
3. Write code in your NMI that writes the values in the "column RAM" to $2007 fixed to one column's address.
When that works (you can just see it)
4. Write code in that sets an address for $2006 to a specific column, that is also changed with the d-pad.
When that works (check the RAM for the address for $2006 gets stored to)
5. Write code in the NMI that uses the address you set above to write to $2006 so the $2007 writes go to the right place.
When that works (you can just see the columns get written to the right place by using the d-pad)...
6. Write code that writes all columns one frame at a time without the use of the d-pad.
When that works...
7. Move the code in the NMI that writes to $2006 and $2007 to a subroutine and call it from the NMI.
When that works...
8. Disable rendering and use that subroutine in addition to your column to RAM code to write all columns in a single frame.
When that works...
9. When rendering is enabled, make it draw a new column when the screen is scrolled.
When that works...
etc.

I outline these steps to try to teach what making small testable parts is like. If you don't have a good guess of where a problem is when you're coding, you're probably writing too much before testing.

You didn't answer my question: What test setup (emulator/cartridge) are you using?

Edit: For the record I do see you are taking steps to writing small parts like this, but the reason your code is broken right now is actually stuff you wrote before. So I'm saying get rid of that stuff in addition to doing each small part.
User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Pallete affects scroll value

Post by IMAGICA »

Test Setup?:
Fceux first check value, see if my code is working, try to break code. Move on.

wanna see an example? press up and down on the dpad using the kitsune3 code . theres the test of rendering.
Ive Also learmned what vnblabnking is
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Pallete affects scroll value

Post by Kasumi »

I saw an example. I even told you what was wrong, just not specifically how to fix it. You're doing things to columnNumber for reasons I don't understand. If you got rid of all code that modifies columnNumber, it'd probably work. Which you could then build on, which is what I suggest. Assuming you get rid of the columnNumber modifying code, you're on step 1 in my post. Then go to step 2. etc.

Does it at least make sense why you're seeing $FFs with the explanation in the previous post?
User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Pallete affects scroll value

Post by IMAGICA »

Done, check the scrolling by pressing A, Up and down
Attachments
KitsuneTales.nes
(40.02 KiB) Downloaded 113 times
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]
User avatar
Kasumi
Posts: 1293
Joined: Wed Apr 02, 2008 2:09 pm

Re: Pallete affects scroll value

Post by Kasumi »

Fix the CHR! Your file is still 40KB, which probably means you still don't have a .bank 5 and a .org $0000 under that .bank 5.

Glad it mostly works, but there's definitely still something wrong. Every 32 pixels (which I assume is when you update attribute bytes), the scroll position jumps a little vertically.

edit: To be specific: Every 32 horizontal pixels, I mean. Holding A for 32 frames.
User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Pallete affects scroll value

Post by IMAGICA »

Quuuesstion....

Before I dive into the main problem:
"Why does every time I update my 'pallete'[palette] , the scroll gets messed up?" problem,

There is something wrong with the attribute table. I'm using your (Kasumi) method of updating using nmi timing and when I update the screen data, There are background tiles missing and the attribute doesn't update correctly. Answers?
Also, Fancy a bonus?
1.
[*] can you activate an IRQ any where?
2. scroll both the IRQ and the main screen in both directions at the same time? (you know like the Sonic 2 Vs. screen)? example: https://www.youtube.com/watch?v=OgIb5T9HYEc
P.S. This is for a multiplayer option I'm thinking of.[/color]
Attachments
KitsuneTalesattrib.bin
New atributes
(126 Bytes) Downloaded 104 times
Kitsunetales.asm
code
(20.3 KiB) Downloaded 100 times
KitsuneTales.nes
Rom
(48.02 KiB) Downloaded 109 times
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]
User avatar
IMAGICA
Posts: 61
Joined: Thu Jul 13, 2017 5:17 pm
Contact:

Re: Pallete affects scroll value

Post by IMAGICA »

UPDATE.
Bad example: uses parallax scrolling
Attachments
KitsuneTales.nes
(48.02 KiB) Downloaded 105 times
Kitsunetales.asm
(19.05 KiB) Downloaded 96 times
In Progress:
Tengu Tales (MMC3 Test first)[360 degress bullet direction math]
Baseball Brawlers (MMC5 full features, "Yoshi's Island")[Square root table, SPG ]
Smash ("port",MMC5 )[Character Movement]
User avatar
dougeff
Posts: 3078
Joined: Fri May 08, 2015 7:17 pm

Re: Pallete affects scroll value

Post by dougeff »

I didn't look at the code, but after 2 minutes of looking at the last .nes file...I see.


1.You aren't zeroing the attribute table of the PPU. Or setting it at all.

No RAM should be assumed to be zero. On a real NES, the screen (attribute table) might be filled with random palettes for the BG.

2. You are still occasionally writing to the PPU outside of v-blank. Not very far outside, but enough to cause occasional jitter while scrolling.
nesdoug.com -- blog/tutorial on programming for the NES
Post Reply