我正在做一些有趣的復古編程。我想創建的是使用EGA圖形的DOS遊戲,但我在網絡上找到很好的參考資料時遇到了一些問題。每個談論做DOS編程的人都假定程序員會使用模式13h,雖然有些頁面提到了其他圖形模式,但我還沒有找到一個討論它們的正確用法。DOS EGA圖形編程模式0Dh
這裏就是我想現在就得到工作:如果你改變set_video_mode
//------------------------------------------------------------------------------
// DOS graphics test
//
// Thanks to the following links:
// http://gamebub.com/cpp_graphics.php
//
// Written for Digital Mars C compiler to be compiled as a DOS 16 bit binary.
//------------------------------------------------------------------------------
#include <dos.h>
#include <stdio.h>
#define SCREEN_WIDTH 320;
#define SCREEN_HEIGHT 200;
unsigned char far *vram = (unsigned char far *)0xA0000000L;
//------------------------------------------------------------------------------
void set_video_mode(unsigned char mode)
{
union REGS in, out;
in.h.ah = 0;
in.h.al = mode;
int86(0x10, &in, &out);
}
//------------------------------------------------------------------------------
void plot_pixel(unsigned int x, unsigned int y, unsigned char color)
{
// this is wrong because it's only 4 bpp not 8
vram[y * 320 + x] = color;
//vram[((y<<8)+(y<<6))+x] = color;
}
//------------------------------------------------------------------------------
int main(int argc, char* argv[])
{
// EGA 320 x 200 x 16
set_video_mode(0x0d);
for (unsigned char i = 0; i < 255; i++)
{
vram[i] = i;
}
//plot_pixel(10, 10, 1);
getc(stdin);
return 0;
}
此示例代碼的偉大工程()取0×13,而不是0X0D,但就像我說我想在這裏得到EGA圖形,而不是VGA。 :)我意識到,爲了做到每像素四位,我要麼需要假設plot_pixel同時寫入兩個像素,要麼做一些小事來確保我只寫了四個位,即I其實想要。
我的問題是,我沒有看到我期望的輸出 - 特別是沒有顏色!一切似乎都是單色的,這不是我想要的。在這種圖形模式下使用調色板比在13小時有不同的過程嗎?或者我是否以某種方式調用了一個完全不同的圖形模式?指導將非常感謝。
我不認爲我的編譯器ARGS將是相關的,但以防萬一:
..\dm\bin\dmc test.c -o test -mm
謝謝你的提示!我不知道平面圖形,所以這會有所幫助。我真的想檢查文檔,但我在這裏有一個問題,那就是我還沒有找到關於這個主題的好文檔。 :) – Parappa 2010-01-18 19:32:58
嘗試http://www.phatcode.net/res/224/files/html/index.html。對於VGA和EGA都非常有用,因爲CGA,EGA和VGA上的平面模式理念是相同的。 – Francis 2010-01-19 02:01:05
這也解釋了它:http://www.shikadi.net/moddingwiki/Raw_EGA_data – Aybe 2012-07-26 22:47:53