News: 11 March 2016 - Forum Rules

Author Topic: Need some help with Graphics programing on the SNES  (Read 6744 times)

Videogamer555

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Need some help with Graphics programing on the SNES
« on: February 02, 2011, 01:08:53 pm »
Ok first of all I've set the byte that tells where to look for graphics data in VRAM, but there's a problem. Now that I told it where in VRAM to find graphics data, I need to put graphics data there. But there's a catch, this is VRAM now, not SNES ram. How do I store the data into a given VRAM address (not normal SNES memory)? For SNES memory I use

LDA #$01
STA $0005

to store the data hex number 01 into hex memory location 0005. But I'm pretty sure I have to address VRAM differently. None of the online documentation I've read tell how to store data into VRAM. The author's of said documentation seem to just EXPECT the reader to know this somehow. I've read 3 documents on SNES programing and they all say things like "to do bla bla bla with graphics, store such and such a piece of data in VRAM". Now I have NEVER read a passage that says anything like "and this is how you store data in VRAM".

Could someone please enlighten me on this issue?

KaioShin

  • RHDN Supporter
  • Hero Member
  • *****
  • Posts: 5699
    • View Profile
    • The Romhacking Aerie
Re: Need some help with Graphics programing on the SNES
« Reply #1 on: February 02, 2011, 01:14:18 pm »
The answer to your question is DMA tranfers. Can't tell how to do it specifically on the SNES, but now that you know what you are looking for you should be able to find what you need to know?
All my posts are merely personal opinions and not statements of fact, even if they are not explicitly prefixed by "In my opinion", "IMO", "I believe", or similar modifiers. By reading this disclaimer you agree to reply in spirit of these conditions.

KingMike

  • Forum Moderator
  • Hero Member
  • *****
  • Posts: 7412
  • *sigh* A changed avatar. Big deal.
    • View Profile
Re: Need some help with Graphics programing on the SNES
« Reply #2 on: February 02, 2011, 03:05:30 pm »
It is most efficient to use DMA, but you don't have to.
DMA is hardware feature to tell the hardware to automatically copy data from one memory location to another, it much faster than any CPU code you could write to do it manually.

You must be in the Vblank period before accessing VRAM. Usually it is as simple as

Code: [Select]
CHECK_MINUS:
 LDA $4212 : BMI CHECK_MINUS
CHECK_PLUS:
 LDA $4212 : BPL CHECK_PLUS

Then to transfer to VRAM, write the word address (meaning address/2) to $2116-2117.
Then write your data to $2118-2119 (since each VRAM write is 2 bytes).

To use DMA, to transfer the data through channel 0. Write a routine as such below:
First, you'll need to set up the transfer method by writing to $2115.
I write 0x80 to $2115 so it will increment $2116 (VRAM address) automatically after writing $2119.
Write to $4300 to set the data transfer mode. Write 0x01 to initiate a CPU->VRAM transfer.
Write 0x18 to $4301, because we want to do constant writes to $2118, the VRAM data write register.
Write the 24-bit source address to $4302-4204.
Write the size of the data to copy (a 16-bit value) to $4305-4306.
Write 0x01 to $420B to start the transfer.

There are 8 DMA channels. To use a different channel, increase the 10s digit in every $43xx address. ($431x for channel 1 ... up to $437x for channel 7)
Also, change the value written to $420B. It is a binary value, where bit 7 = channel 7 and bit 0 = channel 0, etc.
"My watch says 30 chickens" Google, 2018

Videogamer555

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Need some help with Graphics programing on the SNES
« Reply #3 on: February 02, 2011, 04:11:32 pm »
It is most efficient to use DMA, but you don't have to.
DMA is hardware feature to tell the hardware to automatically copy data from one memory location to another, it much faster than any CPU code you could write to do it manually.

You must be in the Vblank period before accessing VRAM. Usually it is as simple as

Code: [Select]
CHECK_MINUS:
 LDA $4212 : BMI CHECK_MINUS
CHECK_PLUS:
 LDA $4212 : BPL CHECK_PLUS

Then to transfer to VRAM, write the word address (meaning address/2) to $2116-2117.
Then write your data to $2118-2119 (since each VRAM write is 2 bytes).

To use DMA, to transfer the data through channel 0. Write a routine as such below:
First, you'll need to set up the transfer method by writing to $2115.
I write 0x80 to $2115 so it will increment $2116 (VRAM address) automatically after writing $2119.
Write to $4300 to set the data transfer mode. Write 0x01 to initiate a CPU->VRAM transfer.
Write 0x18 to $4301, because we want to do constant writes to $2118, the VRAM data write register.
Write the 24-bit source address to $4302-4204.
Write the size of the data to copy (a 16-bit value) to $4305-4306.
Write 0x01 to $420B to start the transfer.

There are 8 DMA channels. To use a different channel, increase the 10s digit in every $43xx address. ($431x for channel 1 ... up to $437x for channel 7)
Also, change the value written to $420B. It is a binary value, where bit 7 = channel 7 and bit 0 = channel 0, etc.

Thanks for the info. Just a couple more questions for now What is BMI and BPL?
« Last Edit: February 02, 2011, 04:29:18 pm by Videogamer555 »

Ryusui

  • Hero Member
  • *****
  • Posts: 4989
  • It's the greatest day.
    • View Profile
    • Tumblr
Re: Need some help with Graphics programing on the SNES
« Reply #4 on: February 02, 2011, 04:21:16 pm »
Branch Result Minus and Branch Result Plus.

Here.
« Last Edit: February 02, 2011, 05:05:32 pm by Ryusui »
In the event of a firestorm, the salad bar will remain open.

Videogamer555

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Need some help with Graphics programing on the SNES
« Reply #5 on: February 02, 2011, 04:32:26 pm »
Also I'm having this problem. I'm going with mode7 because it has the color bits arranged most similar to how it is in Windows BMP files (not like the other SNES modes which use bitplanes), and thus I am more familiar with the concepts.

So here's my questions though about mode 7.

In mode 7 how do you set the color of a given pixel? I know it lets you specify an exact color in the 256color palette but it's addressed by tile
DD TT (data value, tile number). And that would seem to imply there are 256 tiles (each an 8x8 block) and you can only specify the WHOLE tile's color, and can NOT specify the value of a specific pixel within that tile. Also there's something funny going on with the number of tiles. One byte to specify tile number only gives 256 tiles, but documentation I read says there's 128x128 tiles. That's 16,384 tiles. I need TWO bytes to specify tile number like this (DD TT TT). But in the documentation for mode7 I only see "DD TT" (NOT the DD TT TT that I'll need). This is NOT enough to specify every tile. What's going on here?

Ryusui

  • Hero Member
  • *****
  • Posts: 4989
  • It's the greatest day.
    • View Profile
    • Tumblr
Re: Need some help with Graphics programing on the SNES
« Reply #6 on: February 02, 2011, 05:08:26 pm »
In mode 7 how do you set the color of a given pixel?

Change the value of the byte representing that pixel, or else modify the palette.
In the event of a firestorm, the salad bar will remain open.

Videogamer555

  • Jr. Member
  • **
  • Posts: 25
    • View Profile
Re: Need some help with Graphics programing on the SNES
« Reply #7 on: February 02, 2011, 05:12:03 pm »
In mode 7 how do you set the color of a given pixel?

Change the value of the byte representing that pixel, or else modify the palette.

That answered part of my qustion, but not the whole question. please reread my post and answer more fully. Considering I'm a noob this the explanation will have to be a bit more indepth than your simple explanation. It doesn't help me when someone says "do this" without also in the same paragraph saying "HOW you do this is".

Nightcrawler

  • Hero Member
  • *****
  • Posts: 5795
    • View Profile
    • Nightcrawler's Translation Corporation
Re: Need some help with Graphics programing on the SNES
« Reply #8 on: February 03, 2011, 08:44:18 am »
The answer to most of the questions you've asked so far is to start reading some hardware documentation (or if you have done that, different ones containing the details you need.) Everything that isn't straight 65816 assembly is done via writes or reads to hardware registers. The hardware registers are your interface to the rest of the system.

Read this document. It should answers near everything you've asked so far. Besides all the register information, it has detailed information on the graphics modes and other things in the second half.

http://www.romhacking.net/docs/196/

You can't expect to successfully start programming for a system on a low level without knowing anything about the hardware. Hopefully this document will get you going in the right direction. :)
TransCorp - Over 20 years of community dedication.
Dual Orb 2, Wozz, Emerald Dragon, Tenshi No Uta, Glory of Heracles IV SFC/SNES Translations