EarthBound/ASM/VRAM DMA Transfer Routines: Difference between revisions

From Data Crystal
Jump to navigation Jump to search
(→‎$C085B7-$C08615: Transfer memory to VRAM in batches: Document batched transfer routine)
m (Xkeeper moved page EarthBound:ASM:VRAM DMA Transfer Routines to EarthBound/ASM/VRAM DMA Transfer Routines: normalize subpages and titles)
 
(8 intermediate revisions by one other user not shown)
Line 2: Line 2:


==<tt>$C085B7-$C08615</tt>: Batched memory/VRAM transfer==
==<tt>$C085B7-$C08615</tt>: Batched memory/VRAM transfer==
Batched transfers between main memory (ROM/WRAM) and VRAM. Makes the transfers using multiple calls to [[#$C08643|<tt>$C08643</tt>]] for batches of 0x1200 bytes, with a final transfer of the remainder up to 0x1201 bytes. Before each batch, spins on [[EarthBound:$7E0099|<tt>$7E0099</tt>]], waiting for the value to become <code>#$0000</code>.
Batched transfers between main memory (ROM/WRAM) and VRAM. Sets up [[EarthBound:VRAM_DMA_memory|VRAM DMA memory]] and makes the transfers using multiple calls to [[#$C08643|<tt>$C08643</tt>]] for batches of 0x1200 bytes, with a final transfer of the remainder up to 0x1201 bytes. Before each batch, spins on [[EarthBound:$7E0099|<tt>$7E0099</tt>]], waiting for the value to become <code>#$0000</code>.


===Inputs===
===Inputs===
* <tt>a</tt>: Transfer style. Pointer into [[EarthBound:VRAM_DMA_Transfer_Style_Table|VRAM DMA Transfer Style Table]]
* <tt>accumulator</tt>: Transfer style. Byte index into [[EarthBound:VRAM_DMA_Transfer_Style_Table|VRAM DMA Transfer Style Table]]
* <tt>x</tt>: Transfer size (bytes)
* <tt>x</tt>: Transfer size (bytes)
* <tt>y</tt>: VRAM address (word)
* <tt>y</tt>: VRAM address (word)
* <tt>$0e..$10</tt>: Memory address long pointer
* <tt>$0e..$10</tt>: Memory address long pointer


==<tt>$C08616-$C0865A</tt>: Transfer memory to VRAM==
==<tt>$C08616-$C0865A</tt>: Memory/VRAM transfer==
Prepares memory (see [[EarthBound:VRAM_DMA_memory|VRAM DMA memory]]) and sets Data Bank and Data Page to zero. Then calls [[#$C0865F|<tt>$C0865F</tt>]] to perform the DMA transfer.
 
Subroutine has multiple entry points.
 
===Entry point <tt>$C08616</tt>===
Setup including long pointer for memory address
 
====Inputs====
* <tt>accumulator</tt>: Transfer style. Byte index into [[EarthBound:VRAM_DMA_Transfer_Style_Table|VRAM DMA Transfer Style Table]]
* <tt>x</tt>: Transfer size (bytes)
* <tt>y</tt>: VRAM address (word)
* <tt>$0e..$10</tt>: Memory address long pointer
 
===Entry point <tt>$C0862E</tt>===
Setup including separated address/bank for memory address
 
====Inputs====
* <tt>accumulator</tt>: Transfer style. Byte index into [[EarthBound:VRAM_DMA_Transfer_Style_Table|VRAM DMA Transfer Style Table]]
* <tt>x</tt>: Transfer size (bytes)
* <tt>y</tt>: Memory address
* <tt>$0e</tt>: Memory address bank
* <tt>$10</tt>: VRAM address (word)
 
===Entry point <tt>$C08643</tt><span class="anchor" id="$C08643"></span>===
Set up only Data Bank and Data Page registers. Used when [[EarthBound:VRAM_DMA_memory|VRAM DMA memory]] has already been prepared separately.


==<tt>$C0865B-$C0865E</tt>: Perform DMA transfer (<tt>JSL</tt>)==
==<tt>$C0865B-$C0865E</tt>: Perform DMA transfer (<tt>JSL</tt>)==
Trivial <code>JSL</code> wrapper around a call to [[#$C0865F|<tt>$C0865F</tt>]].
Trivial <code>JSL</code> wrapper around a call to [[#$C0865F|<tt>$C0865F</tt>]].
''Note: Subroutine expects to always be called with Data Bank set to <code>#$00</code> and Data Page set to <code>#$0000</code>. This is normally done via the subroutine at [[#$C08643|<tt>$C08643</tt>]].''


==<tt>$C0865F-$C086DD</tt>: Perform DMA transfer (<tt>JSR</tt>)<span class="anchor" id="$C0865F"></span>==
==<tt>$C0865F-$C086DD</tt>: Perform DMA transfer (<tt>JSR</tt>)<span class="anchor" id="$C0865F"></span>==
Primary memory/VRAM DMA transfer subroutine. Performs a DMA transfer using the parameters saved in [[EarthBound:VRAM_DMA_memory|VRAM DMA memory]].
Depending on the value stored in [[EarthBound:$7E000D|<tt>$7E000D</tt>]], either directly prepares and initiates DMA using the [https://snes.nesdev.org/wiki/DMA_registers SNES DMA registers], or saves the transfer parameters to the [[EarthBound:VRAM_DMA_Circular_Queue|VRAM DMA Circular Queue]] to allow the transfer to be performed upon the next vblank period by the [[EarthBound:ASM:VBLANK_Interrupt_Routine|VBLANK Interrupt Routine]].
''Note: Subroutine expects to always be called with Data Bank set to <code>#$00</code> and Data Page set to <code>#$0000</code>. This is normally done via the subroutine at [[#$C08643|<tt>$C08643</tt>]].''
==<tt>$C086DE-$C08704</tt>: Allocate temporary WRAM for VRAM DMA<span class="anchor" id="$C086DE"></span>==
Allocates a block of memory (from the [[EarthBound:Temp_VRAM_DMA_Data_Block|Temp VRAM DMA Data Block]]) to store temporary data for use in the next VRAM DMA transfer. All allocated memory is always deallocated after each transfer.
===Inputs===
* <tt>accumulator</tt>: Num bytes to allocate. ''Note: Total allocatable memory is typically 512 bytes, so this routine may deadlock if more than 512 bytes are requested.''
===Outputs===
* <tt>accumulator</tt>: Pointer (in <tt>$7E</tt> bank) to allocated memory.


[[Category:EarthBound:ASM|VRAM DMA Transfer Routines]]
[[Category:EarthBound:ASM|VRAM DMA Transfer Routines]]
{{Internal Data|game=EarthBound}}
{{Internal Data|game=EarthBound}}
{{stub}}

Latest revision as of 02:41, 24 January 2024

This is a sub-page of EarthBound/ASM.

$C085B7-$C08615: Batched memory/VRAM transfer

Batched transfers between main memory (ROM/WRAM) and VRAM. Sets up VRAM DMA memory and makes the transfers using multiple calls to $C08643 for batches of 0x1200 bytes, with a final transfer of the remainder up to 0x1201 bytes. Before each batch, spins on $7E0099, waiting for the value to become #$0000.

Inputs

  • accumulator: Transfer style. Byte index into VRAM DMA Transfer Style Table
  • x: Transfer size (bytes)
  • y: VRAM address (word)
  • $0e..$10: Memory address long pointer

$C08616-$C0865A: Memory/VRAM transfer

Prepares memory (see VRAM DMA memory) and sets Data Bank and Data Page to zero. Then calls $C0865F to perform the DMA transfer.

Subroutine has multiple entry points.

Entry point $C08616

Setup including long pointer for memory address

Inputs

  • accumulator: Transfer style. Byte index into VRAM DMA Transfer Style Table
  • x: Transfer size (bytes)
  • y: VRAM address (word)
  • $0e..$10: Memory address long pointer

Entry point $C0862E

Setup including separated address/bank for memory address

Inputs

  • accumulator: Transfer style. Byte index into VRAM DMA Transfer Style Table
  • x: Transfer size (bytes)
  • y: Memory address
  • $0e: Memory address bank
  • $10: VRAM address (word)

Entry point $C08643

Set up only Data Bank and Data Page registers. Used when VRAM DMA memory has already been prepared separately.

$C0865B-$C0865E: Perform DMA transfer (JSL)

Trivial JSL wrapper around a call to $C0865F.

Note: Subroutine expects to always be called with Data Bank set to #$00 and Data Page set to #$0000. This is normally done via the subroutine at $C08643.

$C0865F-$C086DD: Perform DMA transfer (JSR)

Primary memory/VRAM DMA transfer subroutine. Performs a DMA transfer using the parameters saved in VRAM DMA memory.

Depending on the value stored in $7E000D, either directly prepares and initiates DMA using the SNES DMA registers, or saves the transfer parameters to the VRAM DMA Circular Queue to allow the transfer to be performed upon the next vblank period by the VBLANK Interrupt Routine.

Note: Subroutine expects to always be called with Data Bank set to #$00 and Data Page set to #$0000. This is normally done via the subroutine at $C08643.

$C086DE-$C08704: Allocate temporary WRAM for VRAM DMA

Allocates a block of memory (from the Temp VRAM DMA Data Block) to store temporary data for use in the next VRAM DMA transfer. All allocated memory is always deallocated after each transfer.

Inputs

  • accumulator: Num bytes to allocate. Note: Total allocatable memory is typically 512 bytes, so this routine may deadlock if more than 512 bytes are requested.

Outputs

  • accumulator: Pointer (in $7E bank) to allocated memory.