Posted by: kevinlin on: 二月 4, 2008
主要資料是在這邊
這張是NDS記憶體的配置圖,後面會有一個表介紹他們實際的位置,因為程式中,會常常需要直接針對某記憶體作
| ARM 9 | ||||
|---|---|---|---|---|
| Name | Start Address | Stop Address | Size | Wait State |
| Main | 0×02000000 | 0×023FFFFF | 4MB | ? |
| BIOS | 0xFFFF0000 | 0xFFFF7FFF | 32KB | ? |
| ITCM | 0×00000000 | 0×00007FFF | 32KB | ? |
| DTCM | 0×0B000000 | 0×0B003FFF | 16KB | ? |
| Shared WRAM Bank 0 | 0×03000000 | 0×03003FFF | 16KB | ? |
| Shared WRAM Bank 1 | 0×03004000 | 0×03007FFF | 16KB | ? |
| ARM 7 | ||||
| Main | 0×02000000 | 0×023FFFFF | 4MB | ? |
| BIOS | 0×00000000 | 0×00003FFF | 16KB | ? |
| IWRAM | 0×03800000 | 0×0380FFFF | 64KB | ? |
| Shared WRAM Bank 0 | 0×03000000 | 0×03003FFF | 16KB | ? |
| Shared WRAM Bank 1 | 0×03004000 | 0×03007FFF | 16KB | ? |
| Video RAM | ||||
| Main OAM | 0×07000000 | 0×070003FF | 1KB | ? |
| Sub OAM | 0×07000400 | 0×070007FF | 1KB | ? |
| Main Palette | 0×05000000 | 0×050003FF | 1KB | ? |
| Sub Palette | 0×05000400 | 0×050007FF | 1KB | ? |
| Bank A | 0×06800000 | 0×0681FFFF | 128KB | ? |
| Bank B | 0×06820000 | 0×0683FFFF | 128KB | ? |
| Bank C | 0×06840000 | 0×0685FFFF | 128KB | ? |
| Bank D | 0×06860000 | 0×0687FFFF | 128KB | ? |
| Bank E | 0×06880000 | 0×0688FFFF | 64KB | ? |
| Bank F | 0×06890000 | 0×06983FFF | 16KB | ? |
| Bank G | 0×06894000 | 0×06897FFF | 16KB | ? |
| Bank H | 0×06898000 | 0×0689FFFF | 32KB | ? |
| Bank I | 0×068A0000 | 0×068A3FFF | 16KB | ? |
| Virtual Video RAM | ||||
| Main Background | 0×06000000 | 0×0607FFFF | 512KB | ? |
| Sub Background | 0×06200000 | 0×0621FFFF | 128KB | |
| Main Sprite | 0×06400000 | 0×0643FFFF | 256KB | ? |
| Sub Sprite | 0×06600000 | 0×0661FFFF | 128KB | ? |
Main Memory
Start Address : 0x0200:0000 End Address : 0x023F:FFFF Mirror : 0x0240:0000
4M的記憶體區塊通常用來放ARM9的可執行程式還有龐大的遊戲資料。
ARM7跟ARM9在任何時候都可以去存取這塊記憶體.ARM7在預設的優先權比較高,但是可以透過Control register去改變。
既使可以同時從這裡面執行ARM7跟ARM9的程式,但是為了效率,devkitPro預設是把ARM7的程式放在ARM7 FAST Ram(IWRAM)裡.官方正版的遊戲通常都是把ARM7跟ARM9放在Main Memory中,然後再把ARM7的程式拷貝到IWRAM裡面。
Start Address : 0x03800000 End Address : 0x0380FFFF
ARM7專用的64KB來放fast 32bit wide memory用的。這個區域包含了ARM7的執行檔跟資料。設計的ARM7代碼時,要注意讓binary小一點。
ARM9包含了一個資料快取跟一個指令快取。 Although the operation of these caches is a bit complex and really out of scope for this document a few things are worth noting.
Main memory is cacheable by default. This means all data and code being accessed from main memory will be stored temporarily in the cache. Because the DMA circuitry and the ARM7 do not have access to the cache often you will get unexpected results if you attempt to DMA from main memory or share data between ARM7 and ARM9 via main memory.
To help utilize the cache effectively the mirror of main memory that begins above 0×02400000 is not cacheable. There are also several functions provided by the library which allow you to flush the data cache and ensure main memory is in sync.
Although the cache adds a certain level of complexity its boost to performance is well worth this small inconvenience.
There are two small 16KB banks of fast 32 bit ram that can be assigned to the ARM7 or ARM9. Access to either block by both CPUs at the same time is prohibited. Commonly, both banks will be mapped to the ARM7 as they form a continuous block with ARM7 IWRAM effectively giving the ARM7 96KB of ram.
The Nintendo DS has nine banks of video memory which may be put to a variety of uses. They can hold the graphics for your sprites, the textures for your 3D space ships, the tiles for your 2D platformer, or a direct map of pixels to render to the screen. Figuring out how to effectively utilize this flexible but limited amount of memory will be one the most challenging endeavors you will face in your first few days of homebrew.
Below is a table of the banks along with a description as to what uses they can be put. You should not worry about understanding this at the moment but it might be handy to bookmark or print out for later use.
In order for the 2D systems to function they need RAM. One of the major differences between the 2D graphics engine on the Gameboy Advanced and those on the DS is the DS has almost no memory dedicated to the 2D system. Instead of setting aside a given amount of video memory for the 2D system it allows you to map the video RAM banks into 2D engine memory space.
This might be a bit difficult to grasp at first. An example might be helpful.
Scenario: You want to render a tile based map to the screen using the main 2D graphics engine.
Because you are an uber Nintendo DS programmer you already know two things:
Solution: Tell the Nintendo DS to map a video RAM bank to the right place…in this case we might map video RAM bank A (VRAM_A) to 0×6000000 for use as 2D background memory but we could have chosen another bank (turns out almost all vram banks can be mapped to main background memory).
videoSetBankA(VRAM_A_MAIN_BG_0x6000000);
We will revisit this topic when we create our first few 2D demos.
最近的回應