Read/Write in VRAM

Discussion of hardware and software development for Super NES and Super Famicom.

Moderator: Moderators

Forum rules
  • For making cartridges of your Super NES games, see Reproduction.
Post Reply
gigi5
Posts: 7
Joined: Tue Nov 07, 2017 5:37 pm

Read/Write in VRAM

Post by gigi5 » Fri Mar 26, 2021 2:29 pm

Hello

How to READ or WRITE a word (two bytes) in an address in the VRAM ?

For example:
For READ in VRAM's address $A11C (bytes A11C & A11D) ?
For WRITE 17 35 in VRAM's address $A11C ?


Thank you
Last edited by gigi5 on Fri Mar 26, 2021 4:50 pm, edited 1 time in total.

lidnariq
Posts: 10463
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Read/Write in VRAM

Post by lidnariq » Fri Mar 26, 2021 3:17 pm

The SNES makes reading-then-rewriting VRAM expensive, so it'd be best to not do that.

To literally answer the question:
Set VMADDL,H ($2116,7) to the address you want to read
Possibly set VMAIN ($2115) to the correct mode
Read two bytes via RDVRAML,H ($2139,A)
Re-set VMADDL,H ($2116,7)
Write two different bytes to VMDATAL,H ($2118,9)

93143
Posts: 1344
Joined: Fri Jul 04, 2014 9:31 pm

Re: Read/Write in VRAM

Post by 93143 » Fri Mar 26, 2021 3:45 pm

VRAM uses word addresses. Byte $A11C isn't at $A11C; it's at $508E.

There are only 64 KB of VRAM in the SNES, so $A11C doesn't exist/will wrap to $211C.

gigi5
Posts: 7
Joined: Tue Nov 07, 2017 5:37 pm

Re: Read/Write in VRAM

Post by gigi5 » Fri Mar 26, 2021 4:38 pm

lidnariq wrote:
Fri Mar 26, 2021 3:17 pm
The SNES makes reading-then-rewriting VRAM expensive, so it'd be best to not do that.

To literally answer the question:
Set VMADDL,H ($2116,7) to the address you want to read
Possibly set VMAIN ($2115) to the correct mode
Read two bytes via RDVRAML,H ($2139,A)
Re-set VMADDL,H ($2116,7)
Write two different bytes to VMDATAL,H ($2118,9)
Thank you

But I do not all understand

The easiest (for me) is to look at the hex code (machine language), could you give me this 2 examples in hex code (machine language) ?
93143 wrote:
Fri Mar 26, 2021 3:45 pm
VRAM uses word addresses. Byte $A11C isn't at $A11C; it's at $508E.

There are only 64 KB of VRAM in the SNES, so $A11C doesn't exist/will wrap to $211C.
Ok I take note , thank you

Oziphantom
Posts: 1115
Joined: Tue Feb 07, 2017 2:03 am

Re: Read/Write in VRAM

Post by Oziphantom » Fri Mar 26, 2021 10:07 pm

Code: Select all

;AY 16
LDA #$0080
STA $2115
LDX #$50BE
STX $2116
LDA $2139
; do what ever you want to it, Don't change X
STX $2116
STA $2118

gigi5
Posts: 7
Joined: Tue Nov 07, 2017 5:37 pm

Re: Read/Write in VRAM

Post by gigi5 » Sat Mar 27, 2021 8:27 am

Oziphantom wrote:
Fri Mar 26, 2021 10:07 pm

Code: Select all

;AY 16
LDA #$0080
STA $2115
LDX #$50BE
STX $2116
LDA $2139
; do what ever you want to it, Don't change X
STX $2116
STA $2118

Thank you Oziphantom :wink: , I will see this

gigi5
Posts: 7
Joined: Tue Nov 07, 2017 5:37 pm

Re: Read/Write in VRAM

Post by gigi5 » Sat Mar 27, 2021 9:55 am

LDA #$0080
STA $2115
LDX #$508E
STX $2116
LDA $2139
So if I understood correctly: now index A has the same value as the vram at 508E (A11C/2)

And the method for write "#$1735" in VRAM at 508E if I understood correctly it's :
LDA #$0080
STA $2115
LDX #$508E
LDA #$1735
STX $2116
STA $2118

Oziphantom
Posts: 1115
Joined: Tue Feb 07, 2017 2:03 am

Re: Read/Write in VRAM

Post by Oziphantom » Sat Mar 27, 2021 9:09 pm

yes

Post Reply