News:

11 March 2016 - Forum Rules

Main Menu

[SNES] Easy way to clear VRAM?

Started by lytron, March 27, 2014, 05:01:46 AM

Previous topic - Next topic

lytron

Hello, hello,

I take a small peek into the code of Asterix for the SNES. The whole boot/register clear stuff seems to be written quite dilettantish (double-clearing registers, unnecessary lines and stuff).

But all of a sudden, I saw this:

LDA #$C0
STA $211A


If I understand this document right, this clears the whole VRAM at once? Is that right? Does that actually work even if the screen setting was changed to Mode 1 before? I would be astonished if something that nifty would be there, after all this weird stuff I saw...

... does anyone know more about it?

Bregalad

Clearing VRAM is something very very different from showing a blank screen.

mopoz

#2

lda #$0000
ldx #$0000
-
sta $7F8000,x
inx
inx
beq -

  lda #$0000
  sta $2116
  lda #$8000
  sta $4302
  lda #$8000
  sta $4305
  sep #$20
  lda #$80
  sta $2115
  lda #$01
  sta $4300
  lda #$18
  sta $4301
  lda #$7f
  sta $4334
  lda #$01
  sta $420b

  lda #$4000
  sta $2116
  lda #$8000
  sta $4312
  lda #$8000
  sta $4315
  sep #$20
  lda #$80
  sta $2115
  lda #$01
  sta $4300
  lda #$18
  sta $4311
  lda #$7f
  sta $4314
  lda #$02
  sta $420b


Or have an empty space in the ROM.
Skate-punk rulezzzz

lytron

Ah, sorry, my mistake. I misunderstood this:

Quote211a  wb++?-
        rc----yx
c       = Empty space fill, when bit 7 is set:
                   0 = Transparent.
                   1 = Fill with character 0. Note that the fill is matrix transformed like all other Mode 7 tiles.

I misinterpreted "Empty space fill" and "Fill with character 0".

magno

In fact, erasing VRAM is easier and faster than mopoz posted:
  ; set a '0' value in RAM
  lda #$0000
  sta $0000
  ; VRAM destination address $0000
  sta $2116
  ; RAM source address $7E:0000
  sta $4302
  ; bytes to transfer $10000
  sta $4305
  sep #$20
  ; VRAM address increment after writing to $2119
  lda #$80
  sta $2115
  ; DMA transfer writes 2 bytes, 1 to $2118 and 1 to $2119, without incrementing RAM address (fixed transfer)
  lda #$09
  sta $4300
  ; PPU destination register $2118
  lda #$18
  sta $4301
  ; RAM source address bank $7E
  lda #$7E
  sta $4334
  ; run the DMA!
  lda #$01
  sta $420b

jeffythedragonslayer

#5
Quote from: magno on March 27, 2014, 09:31:29 AMIn fact, erasing VRAM is easier and faster than mopoz posted:
  ; set a '0' value in RAM
  lda #$0000
  sta $0000
  ; VRAM destination address $0000
  sta $2116
  ; RAM source address $7E:0000
  sta $4302
  ; bytes to transfer $10000
  sta $4305
  sep #$20
  ; VRAM address increment after writing to $2119
  lda #$80
  sta $2115
  ; DMA transfer writes 2 bytes, 1 to $2118 and 1 to $2119, without incrementing RAM address (fixed transfer)
  lda #$09
  sta $4300
  ; PPU destination register $2118
  lda #$18
  sta $4301
  ; RAM source address bank $7E
  lda #$7E
  sta $4334
  ; run the DMA!
  lda #$01
  sta $420b

I think there is a problem with this code.  It STAs to special open bus according to fullsnes; the range 4300h-437Fh:

http://problemkaputt.de/fullsnes.htm#snesunpredictablethings

When I run this, it fills VRAM with 42h, which is the high byte of 420Bh/MDMAEN, the value pointed to by the current program counter.  I was expecting it to fill VRAM with 00h.

jeffythedragonslayer

Quote from: mopoz on March 27, 2014, 05:57:40 AM lda #$0000
 ldx #$0000
-
 sta $7F8000,x
 inx
 inx
 beq -

  lda #$0000
  sta $2116
  lda #$8000
  sta $4302
  lda #$8000
  sta $4305
  sep #$20
  lda #$80
  sta $2115
  lda #$01
  sta $4300
  lda #$18
  sta $4301
  lda #$7f
  sta $4334
  lda #$01
  sta $420b

  lda #$4000
  sta $2116
  lda #$8000
  sta $4312
  lda #$8000
  sta $4315
  sep #$20
  lda #$80
  sta $2115
  lda #$01
  sta $4300
  lda #$18
  sta $4311
  lda #$7f
  sta $4314
  lda #$02
  sta $420b
 

Or have an empty space in the ROM.

I think the BEQ here should be a BNE so more than one iteration happens.

yugisokubodai

To my understand, there's no other way to clear Vram than Dma a bunch of zeroes. Do it in Nmi or force blank.

pianohombre

This clears the VRAM for every SNES rom?
"Programming in itself is beauty,
whether or not the operating system actually functions." - Linus Torvalds

slidelljohn

#9
I dont use the ram like this to clear vram:
; set a '0' value in RAM
  lda #$0000
  sta $0000
I prefer using the rom.

Quote from: yugisokubodai on July 08, 2022, 07:10:55 PMTo my understand, there's no other way to clear Vram than Dma a bunch of zeroes. Do it in Nmi or force blank.
REP #$20
LDY #$7FFF
LDX #$0000
LDA #$0000
STA $00
SEP #$20
LDA #$80
STA $2115 //Video Port Control Register
STX $2116 //VRAM Address Register (Low)
REP #$20
LDA $00
STA $2118 //VRAM Data Write Register (Low)
DEY
BPL $FA
RTL
This clears it without DMA but it still uses zeros. Dont ever clear the vram like this. Its really really slow.


@pianohombre
Yes, snes registers :beer:

yugisokubodai

Quote from: slidelljohn on July 10, 2022, 12:18:09 AMI dont use the ram like this to clear vram:
; set a '0' value in RAM
  lda #$0000
  sta $0000
I prefer using the rom.
REP #$20
LDY #$7FFF
LDX #$0000
LDA #$0000
STA $00
SEP #$20
LDA #$80
STA $2115 //Video Port Control Register
STX $2116 //VRAM Address Register (Low)
REP #$20
LDA $00
STA $2118 //VRAM Data Write Register (Low)
DEY
BPL $FA
RTL
This clears it without DMA but it still uses zeros. Dont ever clear the vram like this. Its really really slow.


@pianohombre
Yes, snes registers :beer:

Lol, I think DMA is the best way to clear Vram. Basically your medthod does the same as DMA but it wastes more time than DMA.

slidelljohn

That's definitely not my method I would never use that code and I didn't even write it. That's Konami's awful code. I removed all kinds of awful Konami code like this out of gradius 3 and now my fastrom patch for gradius 3 is less than a second away from matching the gradius 3 sa-1 hacks speed. Once I'm done with it I'm pretty sure the sa-1 hack will have more slowdown than my gradius 3 fastrom patch with no enhancement chips once it's finished. I probably should have posted the code I use for clearing vram using dma to make my post look less confusing. Dma is the only method anyone should ever use to clear all of vram.

@Romhacking.net Staff
Why are quotes done like this? It doesn't look right when someone is being quoted. I think this should be changed to actually show what was posted and quotes shouldn't be automatically modified by the website. When my post #9 is quoted it looks like I'm saying I prefer using the rom for the second group of code when that sentence goes with the first group.