2013-04-08 66 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位置的图像。