Cool NES Programming DMA tutorial

 26 July 16:06   en:Direct anamnesis admission is a action whereby anamnesis is dynamically affected to addition location, independantly of the CPU. In any avant-garde computer, DMA is an capital requirement. Apropos to the SNES, DMA can be acclimated to bound archetype asphalt and palette data to the video RAM.

    Knowledge of DMA is a claim for creating beyond SNES programs, so this tutorial will awning just that.

    DMA is acclimated for artful cartoon data, such as 8x8 tiles and asphalt maps, to the video RAM(VRAM), and palette data to the CGRAM. These locations can alone be accessed by account or autograph to assertive registers repeatedly. Agenda that while this could added calmly be able after using DMA, it would be several times slower.

    When the DMA action is initialized, the CPU is apoplectic until the DMA is complete. There are in absolute 8 DMA channels, but for the purposes of artlessly loading palette or cartoon data, alone one approach is necessary.

     NOTE: This tutorial is abridged and untested.

    =DMA registers=

    where x is from 0 to 7.

    =some code=

    Here is a en:macro for loading a palette data into the CGRAM(the abode area palettes are stored):

     ;macro for loading palette data into the CGRAM

     ;only use if Admeasurement is beneath than 256 bytes

     ;syntax SetPalette Characterization CGRAM_ADDRESS SIZE

     .macro SetPalette

     pha

     php

     rep #$20 ; 16bit A

     lda #3

     sta $4305 ; # of bytes to be copied

     lda #1 ; account of data into 4302, 4303

     sta $4302

     sep #$20 ; 8bit A

     lda #:1 ; coffer abode of data in memory(ROM)

     sta $4304

     lda #2

     sta $2121 ; abode of CGRAM to alpha artful cartoon to

     stz $4300 ; 0= 1 byte accession (not a word!)

     lda #$22

     sta $4301 ; destination 21xx this is 2122 (CGRAM Gate)

     lda #$01 ; about-face on bit 1 (corresponds to approach 0) of DMA approach reg.

     sta $420b ; to accredit transfer

     plp

     pla

     .endm

    Here is a en:macro for loading a data into the VRAM(the abode area tiles and asphalt maps are stored):

     ;macro for loading cartoon data into the VRAM

     ;only use if Admeasurement is beneath than 256 bytes

     ;syntax LoadVRAM Characterization VRAM_ADDRESS SIZE

     .macro LoadVRAM

     pha

     php

     rep #$20 ; 16bit A

     lda #2

     sta $2116 ; abode for VRAM write(or read)

     lda #3

     sta $4305 ; amount of bytes to be copied

     sep #$20 ; 8bit A

     lda #1

     sta $4302 ; data account in memory

     lda #:1 ; coffer abode of data in memory

     sta $4304

     lda #$80

     sta $2115 ; VRAM abode accession amount designation

     lda #$01

     sta $4300 ; 1= chat increment

     lda #$18

     sta $4301 ; 2118 is the VRAM gate

     lda #$01 ; about-face on bit 1 (channel 0) of DMA

     sta $420b

     plp

     pla

     .endm

    

 


Tags: address, memory, tutorial, macro, channel

 address, macro, cgram, loading, memory, palette, bytes, channel, graphics, tutorial, increment, copied, , data into, macro for, palette data, graphics data, address size macro, 256 bytes syntax, palette data into,

Share Cool NES Programming DMA tutorial:
Digg it!   Google Bookmarks   Del.icio.us   Yahoo! MyWeb   Furl  Binklist   Reddit!   Stumble Upon   Technorati   Windows Live   Bookmark

Text link code :
Hyper link code:

Also see ...

Permalink
Article In : Computers & Technology  -  Programming