2013-04-08 23 views
2

我在GBA中編寫遊戲以獲得樂趣,並希望使用模式4.我最近在模式3中創建了一個遊戲,其中的dma非常簡單。如果我想在屏幕上繪製圖像,dma結構是否會相同?這裏是我有:在模式4中使用DMA GBA Linux

/* 
* A function that will draw an arbitrary sized image * onto the screen (with DMA). 
* @param r row to draw the image 
* @param c column to draw the image 
* @param width width of the image 
* @param height height of the image 
* @param image Pointer to the first element of the image. */ 
void drawImageInMode4(int r, int c, int width, int height, const u16* image) 
{ 
    for(int i = 0; i < height; i++){ 
    DMA[3].src = image + OFFSET(i,0,width); 
    //offset calculates the offset of pixel to screen 
    DMA[3].dst = VIDEOBUFFER + OFFSET(r+i,c,240); 
    DMA[3].cnt = DMA_ON | width; 
} 

我覺得這是不使用模式4,但使用模式3.我已經看過了關於如何修改我的代碼,以便它可以工作在模式4預先感謝您!

回答

0

在GBA上,模式3和模式4之間的主要區別在於模式3對每個像素使用2個字節,而模式4對於具有調色板表的每個像素使用一個字節。您仍然可以將數據複製到同一個地方,但視頻硬件會以不同的方式進行解釋。 (Tonc includes a good demo of this.

你需要讓你的代碼的主要變化是:

  • 減半字節你每行復制
  • 調整號碼的OFFSET宏返回正確的值方式4
  • 選擇你想要的像素數據寫入到

(你還需要將位圖轉換爲8BP其中兩頁p格式併爲它們提供調色板數據。)

模式4引入了另一個問題:您的圖像可能是奇數個字節寬。由於VRAM不支持單字節寫入,因此您需要write some special code to handle this case,或者從不繪製具有奇數寬度或x位置的圖像。