【问题标题】:Using DMA in mode 4 GBA Linux在模式 4 GBA Linux 中使用 DMA
【发布时间】:2013-04-08 04:16:17
【问题描述】:

我在 GBA 中编写游戏是为了好玩,并且想使用模式 4。我最近创建了一个模式 3 的游戏,它的 dma 非常简单。如果我想在屏幕上绘制图像,dma 结构会相同吗?这是我所拥有的:

/* 
 * 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 下工作。提前谢谢你!

【问题讨论】:

    标签: linux dma game-boy-advance


    【解决方案1】:

    在 GBA 上,模式 3 和模式 4 的主要区别在于,模式 3 每个像素使用 2 个字节,而模式 4 使用调色板表的每个像素使用一个字节。您仍将数据复制到同一位置,但视频硬件对其的解释不同。 (Tonc includes a good demo of this.)

    您需要对代码进行的主要更改是:

    • 将每行复制的字节数减半
    • 调整您的 OFFSET 宏以返回模式 4 的正确值
    • 选择您要将像素数据写入两个页面中的哪一个

    (您还需要将位图转换为 8bpp 格式并为其提供调色板数据。)

    模式 4 引入了另一个问题:图像可能是奇数字节宽。由于 VRAM 不支持单字节写入,您要么需要write some special code to handle this case,要么永远不要绘制具有奇数宽度或 x 位置的图像。

    【讨论】:

      猜你喜欢
      • 2019-11-10
      • 2016-03-15
      • 2021-12-12
      • 2016-09-04
      • 1970-01-01
      • 1970-01-01
      • 2014-07-09
      • 2021-09-29
      • 2014-06-24
      相关资源
      最近更新 更多