diff options
author | Paul Gilbert | 2011-06-27 18:57:58 +1000 |
---|---|---|
committer | Paul Gilbert | 2011-06-27 18:57:58 +1000 |
commit | e13317baeab99f4868d49a89e110deda1d5ca5f4 (patch) | |
tree | 38666ccfc1b7819072beac2442ff70c00634daca /engines | |
parent | d5fdd094294becb49ef2adf0af00c4814c6efefe (diff) | |
download | scummvm-rg350-e13317baeab99f4868d49a89e110deda1d5ca5f4.tar.gz scummvm-rg350-e13317baeab99f4868d49a89e110deda1d5ca5f4.tar.bz2 scummvm-rg350-e13317baeab99f4868d49a89e110deda1d5ca5f4.zip |
CGE: Beginnings of work on graphics support
Diffstat (limited to 'engines')
-rw-r--r-- | engines/cge/bitmap.cpp | 20 | ||||
-rw-r--r-- | engines/cge/bitmap.h | 5 | ||||
-rw-r--r-- | engines/cge/cge.cpp | 4 | ||||
-rw-r--r-- | engines/cge/cge_main.cpp | 17 | ||||
-rw-r--r-- | engines/cge/general.cpp | 7 | ||||
-rw-r--r-- | engines/cge/snail.cpp | 9 | ||||
-rw-r--r-- | engines/cge/vga13h.cpp | 395 | ||||
-rw-r--r-- | engines/cge/vga13h.h | 11 |
8 files changed, 179 insertions, 289 deletions
diff --git a/engines/cge/bitmap.cpp b/engines/cge/bitmap.cpp index b528b5578d..4112ccb380 100644 --- a/engines/cge/bitmap.cpp +++ b/engines/cge/bitmap.cpp @@ -30,6 +30,7 @@ #include "cge/jbw.h" #include "cge/vol.h" #include "cge/cfile.h" +#include "cge/vga13h.h" #include "common/system.h" namespace CGE { @@ -37,6 +38,13 @@ namespace CGE { DAC *BITMAP::Pal = NULL; #define MAXPATH 128 +void BITMAP::init() { + Pal = NULL; +} + +void BITMAP::deinit() { +} + #pragma argsused BITMAP::BITMAP(const char *fname, bool rem) : M(NULL), V(NULL) { char pat[MAXPATH]; @@ -369,7 +377,7 @@ bool BITMAP::VBMSave(XFILE *f) { if (f->Error == 0) if (p) - f->Write((uint8 *)Pal, 256 * sizeof(DAC)); + f->Write((uint8 *)Pal, 256 * 3); if (f->Error == 0) f->Write(V, n); @@ -394,10 +402,12 @@ bool BITMAP::VBMLoad(XFILE *f) { if (f->Error == 0) { if (p) { - if (Pal) - f->Read((uint8 *)Pal, 256 * sizeof(DAC)); - else - f->Seek(f->Mark() + 256 * sizeof(DAC)); + if (Pal) { + byte palData[PAL_SIZ]; + f->Read(palData, PAL_SIZ); + VGA::pal2DAC(palData, Pal); + } else + f->Seek(f->Mark() + PAL_SIZ); } } if ((V = farnew(uint8, n)) == NULL) diff --git a/engines/cge/bitmap.h b/engines/cge/bitmap.h index eca3be70e8..13e28f4369 100644 --- a/engines/cge/bitmap.h +++ b/engines/cge/bitmap.h @@ -39,6 +39,7 @@ namespace CGE { #define TRANS 0xFE +#include "common/pack-start.h" typedef struct { uint16 b : 2; @@ -56,6 +57,7 @@ typedef struct { uint16 hide; } HideDesc; +#include "common/pack-end.h" class BITMAP { bool BMPLoad(XFILE *f); @@ -70,6 +72,9 @@ public: BITMAP(uint16 w, uint16 h, uint8 fill); BITMAP(const BITMAP &bmp); ~BITMAP(void); + static void init(); + static void deinit(); + BITMAP *FlipH(void); BITMAP *Code(); BITMAP &operator = (const BITMAP &bmp); diff --git a/engines/cge/cge.cpp b/engines/cge/cge.cpp index d056a6737d..287586e092 100644 --- a/engines/cge/cge.cpp +++ b/engines/cge/cge.cpp @@ -53,7 +53,9 @@ void CGEEngine::setup() { _console = new CGEConsole(this); // Initialise classes that have static members + BITMAP::init(); VFILE::init(); + VGA::init(); // Initialise engine objects Text = new TEXT(ProgName(), 128); @@ -99,7 +101,9 @@ CGEEngine::~CGEEngine() { debug("CGEEngine::~CGEEngine"); // Call classes with static members to clear them up + BITMAP::deinit(); VFILE::deinit(); + VGA::deinit(); // Remove all of our debug levels here DebugMan.clearAllDebugChannels(); diff --git a/engines/cge/cge_main.cpp b/engines/cge/cge_main.cpp index ec8f743fe4..d49f71cd99 100644 --- a/engines/cge/cge_main.cpp +++ b/engines/cge/cge_main.cpp @@ -128,7 +128,6 @@ static int DemoText = DEMO_TEXT; //-------------------------------------------------------------------------- bool JBW = false; -DAC *SysPal = farnew(DAC, PAL_CNT); //------------------------------------------------------------------------- int PocPtr = 0; @@ -652,7 +651,7 @@ static void PostMiniStep(int stp) { void SYSTEM::SetPal(void) { int i; - DAC *p = SysPal + 256 - ArrayCount(StdPal); + DAC *p = VGA::SysPal + 256 - ArrayCount(StdPal); for (i = 0; i < ArrayCount(StdPal); i ++) { p[i].R = StdPal[i].R >> 2; p[i].G = StdPal[i].G >> 2; @@ -671,7 +670,7 @@ void SYSTEM::FunTouch(void) { static void ShowBak(int ref) { SPRITE *spr = Vga->SpareQ->Locate(ref); if (spr) { - BITMAP::Pal = SysPal; + BITMAP::Pal = VGA::SysPal; spr->Expand(); BITMAP::Pal = NULL; spr->Show(2); @@ -727,7 +726,7 @@ static void CaveUp(void) { if (Shadow) { Vga->ShowQ->Remove(Shadow); - Shadow->MakeXlat(Glass(SysPal, 204, 204, 204)); + Shadow->MakeXlat(Glass(VGA::SysPal, 204, 204, 204)); Vga->ShowQ->Insert(Shadow, Hero); Shadow->Z = Hero->Z; } @@ -735,7 +734,7 @@ static void CaveUp(void) { Vga->Show(); Vga->CopyPage(1, 0); Vga->Show(); - Vga->Sunrise(SysPal); + Vga->Sunrise(VGA::SysPal); Dark = false; if (! Startup) Mouse->On(); @@ -1027,7 +1026,7 @@ static void SpkClose(void) { static void SwitchColorMode(void) { SNPOST_(SNSEQ, 121, Vga->Mono = !Vga->Mono, NULL); KeyClick(); - Vga->SetColors(SysPal, 64); + Vga->SetColors(VGA::SysPal, 64); } @@ -1712,7 +1711,7 @@ void Movie(const char *ext) { bool ShowTitle(const char *name) { - BITMAP::Pal = SysPal; + BITMAP::Pal = VGA::SysPal; BMP_PTR LB[] = { new BITMAP(name), NULL }; BITMAP::Pal = NULL; bool usr_ok = false; @@ -1732,7 +1731,7 @@ bool ShowTitle(const char *name) { Vga->CopyPage(1, 2); Vga->CopyPage(0, 1); SelectPocket(-1); - Vga->Sunrise(SysPal); + Vga->Sunrise(VGA::SysPal); if (STARTUP::Mode < 2 && !STARTUP::SoundOk) { Vga->CopyPage(1, 2); @@ -1793,7 +1792,7 @@ bool ShowTitle(const char *name) { if (CFILE::Exist(n)) { CFILE file = CFILE(n, REA, RCrypt); LoadGame(file, true); // only system vars - Vga->SetColors(SysPal, 64); + Vga->SetColors(VGA::SysPal, 64); Vga->Update(); if (FINIS) { ++ STARTUP::Mode; diff --git a/engines/cge/general.cpp b/engines/cge/general.cpp index 9caa864227..a851957b21 100644 --- a/engines/cge/general.cpp +++ b/engines/cge/general.cpp @@ -127,7 +127,12 @@ char *ForceExt(char *buf, const char *nam, const char *ext) { // fnsplit(nam, dr, di, na, ex); // fnmerge(buf, dr, di, na, ext); // return buf; - warning("STUB: ForceExt"); + strcpy(buf, nam); + char *dot = strrchr(buf, '.'); + if (dot) + *dot = '\0'; + strcat(buf, ext); + return buf; } diff --git a/engines/cge/snail.cpp b/engines/cge/snail.cpp index 2b36ca4325..a07cf9d09b 100644 --- a/engines/cge/snail.cpp +++ b/engines/cge/snail.cpp @@ -65,7 +65,6 @@ extern SPRITE *PocLight; //------------------------------------------------------------------------- extern SPRITE *Pocket[]; extern int PocPtr; -extern DAC *SysPal; static void SNGame(SPRITE *spr, int num) { switch (num) { @@ -576,7 +575,7 @@ void SNSend(SPRITE *spr, int val) { spr->Flags.Slav = false; } else { if (spr->Ref % 1000 == 0) - BITMAP::Pal = SysPal; + BITMAP::Pal = VGA::SysPal; if (spr->Flags.Back) spr->BackShow(true); else @@ -849,7 +848,7 @@ void SNFlash(bool on) { if (on) { DAC *pal = farnew(DAC, PAL_CNT); if (pal) { - memcpy(pal, SysPal, PAL_SIZ); + memcpy(pal, VGA::SysPal, PAL_SIZ); for (int i = 0; i < PAL_CNT; i ++) { register int c; c = pal[i].R << 1; @@ -862,14 +861,14 @@ void SNFlash(bool on) { Vga->SetColors(pal, 64); } } else - Vga->SetColors(SysPal, 64); + Vga->SetColors(VGA::SysPal, 64); Dark = false; } static void SNLight(bool in) { if (in) - Vga->Sunrise(SysPal); + Vga->Sunrise(VGA::SysPal); else Vga->Sunset(); Dark = ! in; diff --git a/engines/cge/vga13h.cpp b/engines/cge/vga13h.cpp index 349f412ca0..f5fde14122 100644 --- a/engines/cge/vga13h.cpp +++ b/engines/cge/vga13h.cpp @@ -25,6 +25,8 @@ * Copyright (c) 1994-1995 Janus B. Wisniewski and L.K. Avalon */ +#include "common/rect.h" +#include "graphics/palette.h" #include "cge/general.h" #include "cge/vga13h.h" #include "cge/bitmap.h" @@ -737,7 +739,7 @@ void SPRITE::Show(void) { void SPRITE::Show(uint16 pg) { - uint8 *a = VGA::Page[1]; + Graphics::Surface *a = VGA::Page[1]; VGA::Page[1] = VGA::Page[pg & 3]; Shp()->Show(X, Y); VGA::Page[1] = a; @@ -886,17 +888,25 @@ SPRITE *QUEUE::Locate(int ref) { } -// TODO: Was direct mapping to VGA buffers.. need to create scummvm surfaces for that -uint8 *VGA::Page[4] = { 0, 0, 0, 0 }; +//extern const char Copr[]; +Graphics::Surface *VGA::Page[4]; +DAC *VGA::SysPal; -/* -uint8 * VGA::Page[4] = { (uint8 *) MK_FP(SCR_SEG, 0x0000), - (uint8 *) MK_FP(SCR_SEG, 0x4000), - (uint8 *) MK_FP(SCR_SEG, 0x8000), - (uint8 *) MK_FP(SCR_SEG, 0xC000) }; -*/ +void VGA::init() { + for (int idx = 0; idx < 4; ++idx) { + Page[idx] = new Graphics::Surface(); + Page[idx]->create(320, 200, Graphics::PixelFormat::createFormatCLUT8()); + } -//extern const char Copr[]; + SysPal = new DAC[PAL_CNT]; +} + +void VGA::deinit() { + for (int idx = 0; idx < 4; ++idx) { + delete Page[idx]; + } + delete[] SysPal; +} VGA::VGA(int mode) : FrmCnt(0), OldMode(0), OldScreen(NULL), StatAdr(VGAST1_), @@ -977,21 +987,9 @@ void VGA::SetStatAdr(void) { #pragma argsused void VGA::WaitVR(bool on) { - /* - _DX = StatAdr; - _AH = (on) ? 0x00 : 0x08; - - asm mov cx,2 - // wait for vertical retrace on (off) - wait: - asm in al,dx - asm xor al,ah - asm test al,0x08 - asm jnz wait - asm xor ah,0x08 - asm loop wait - */ - warning("STUB: VGA::WaitVR"); + // Since some of the game parts rely on using vertical sync as a delay mechanism, + // we're introducing a short delay to simulate it + g_system->delayMillis(10); } @@ -1039,102 +1037,54 @@ void VGA::Setup(VgaRegBlk *vrb) { int VGA::SetMode(int mode) { - /* - Clear(); - // get current mode - asm mov ah,0x0F - Video(); // BIOS video service - asm xor ah,ah - asm push ax - - // wait for v-retrace - WaitVR(); - - // set mode - asm xor ah,ah - asm mov al,byte ptr mode - Video(); // BIOS video service - SetStatAdr(); - // return previous mode - asm pop ax - return _AX; - */ - warning("STUB: VGA::SetMode"); + // ScummVM provides it's own vieo services return 0; } void VGA::GetColors(DAC *tab) { - /* - asm cld - asm les di,tab // color table - asm mov dx,0x3C7 // PEL address read mode register - asm xor al,al // start from address 0 - asm out dx,al // put address - asm mov cx,256*3 // # of colors - asm mov dl,0xC9 // PEL data register - - // asm rep insb // very fast! - - gc: // much slower: - asm in al,dx // take 1 color - asm jmp sto // little delay - sto: - asm stosb // store 1 color - asm loop gc // next one? - */ - warning("STUB: VGA::GetColors"); + byte palData[PAL_SIZ]; + g_system->getPaletteManager()->grabPalette(palData, 0, PAL_CNT); + pal2DAC(palData, tab); } +void VGA::pal2DAC(const byte *palData, DAC *tab) { + const byte *colP = palData; + for (int idx = 0; idx < PAL_CNT; ++idx, colP += 3) { + tab[idx].R = *colP; + tab[idx].G = *(colP + 1); + tab[idx].B = *(colP + 2); + } +} + +void VGA::DAC2pal(const DAC *tab, byte *palData) { + for (int idx = 0; idx < PAL_CNT; ++idx, palData += 3) { + *palData = tab[idx].R; + *(palData + 1) = tab[idx].G; + *(palData + 2) = tab[idx].B; + } +} void VGA::SetColors(DAC *tab, int lum) { - /* - DAC * des = NewColors; - asm push ds - - asm les di,des - asm lds si,tab - asm mov cx,256*3 - asm xor bx,bx - asm mov dx,lum - - copcol: - asm mov al,[si+bx] - asm mul dl - asm shr ax,6 - asm mov es:[di+bx],al - asm inc bx - asm cmp bx,cx - asm jb copcol - - asm pop ds - - if (Mono) - { - asm add cx,di - mono: - asm xor dx,dx - asm mov al,77 // 30% R - asm mul byte ptr es:[di].0 - asm add dx,ax - asm mov al,151 // 59% G - asm mul byte ptr es:[di].1 - asm add dx,ax - asm mov al,28 // 11% B - asm mul byte ptr es:[di].2 - asm add dx,ax - - asm mov es:[di].0,dh - asm mov es:[di].1,dh - asm mov es:[di].2,dh - - asm add di,3 - asm cmp di,cx - asm jb mono - } - */ + DAC *palP = tab; + for (int idx = 0; idx < PAL_CNT; ++idx, ++palP) { + palP->R = (palP->R * lum) >> 6; + palP->G = (palP->G * lum) >> 6; + palP->B = (palP->B * lum) >> 6; + } + + if (Mono) { + palP = tab; + for (int idx = 0; idx < PAL_CNT; ++idx, ++palP) { + // Form a greyscalce colour from 30% R, 59% G, 11% B + uint8 intensity = (palP->R * 77) + (palP->G * 151) + (palP->B * 28); + palP->R = intensity; + palP->G = intensity; + palP->B = intensity; + } + } + SetPal = true; - warning("STUB: VGA::SetColors"); } @@ -1178,113 +1128,33 @@ void VGA::Show(void) { void VGA::UpdateColors(void) { - /* - DAC * tab = NewColors; - - asm push ds - asm cld - asm lds si,tab // color table - asm mov dx,0x3C8 // PEL address write mode register - asm xor al,al // start from address 0 - asm out dx,al // put address - asm mov cx,256*3 // # of colors - asm mov dl,0xC9 // PEL data register - - // asm rep outsb // very fast! - - // the slower version of above: - sc: - asm lodsb // take 1/3 color - asm out dx,al // put 1/3 color - asm jmp loop // little delay - loop: - asm loop sc // next one? - - - asm pop ds - */ - warning("STUB: VGA::UpdateColors"); + byte palData[PAL_SIZ]; + DAC2pal(NewColors, palData); + g_system->getPaletteManager()->setPalette(palData, 0, 256); } void VGA::Update(void) { - /* - uint8 * p = Page[1]; - Page[1] = Page[0]; - Page[0] = p; - - asm mov dx,VGACRT_ - asm mov al,0x0D - asm mov ah,byte ptr p - asm out dx,ax - asm dec al - asm mov ah,byte ptr p+1 - asm out dx,ax - */ - if (! SpeedTest) - WaitVR(true); + SWAP(VGA::Page[0], VGA::Page[1]); if (SetPal) { UpdateColors(); SetPal = false; } - warning("STUB: VGA::Update"); + + g_system->copyRectToScreen((const byte *)VGA::Page[0]->getBasePtr(0, 0), SCR_WID, 0, 0, SCR_WID, SCR_HIG); + g_system->updateScreen(); } void VGA::Clear(uint8 color) { - /* - uint8 * a = (uint8 *) MK_FP(SCR_SEG, 0); - - asm mov dx,VGASEQ_ - asm mov ax,0x0F02 // map mask register - enable all planes - asm out dx,ax - asm les di,a - asm cld - - asm mov cx,0xFFFF - asm mov al,color - asm rep stosb - asm stosb - */ - warning("STUB: VGA::Clear"); + for (int paneNum = 0; paneNum < 4; ++paneNum) + Page[paneNum]->fillRect(Common::Rect(0, 0, SCR_WID, SCR_HIG), color); } void VGA::CopyPage(uint16 d, uint16 s) { - /* - uint8 * S = Page[s & 3], * D = Page[d & 3]; - - asm mov dx,VGAGRA_ - asm mov al,0x05 // R/W mode - asm out dx,al - asm inc dx - asm in al,dx - asm and al,0xF4 - asm push ax - asm push dx - asm or al,0x01 - asm out dx,al - - asm mov dx,VGASEQ_ - asm mov ax,0x0F02 // map mask register - enable all planes - asm out dx,ax - - asm push ds - - asm les di,D - asm lds si,S - asm cld - asm mov cx,0x4000 - asm rep movsb - - asm pop ds - - asm pop dx - asm pop ax - asm out dx,al // end of copy mode - */ - warning("STUB: VGA::CopyPage"); + Page[d]->copyFrom(*Page[s]); } //-------------------------------------------------------------------------- @@ -1372,72 +1242,63 @@ void BITMAP::XShow(int x, int y) { void BITMAP::Show(int x, int y) { - /* - uint8 mask = 1 << (x & 3), - * scr = VGA::Page[1] + y * (SCR_WID >> 2) + (x >> 2); - uint8 * v = V; - - asm push ds // preserve DS - - asm cld // normal direction - asm les di,scr // screen address - asm lds si,v // picture address - asm mov dx,VGASEQ_ // VGA reg - asm mov al,0x02 - asm mov ah,mask - - plane: - asm out dx,ax - asm push ax - asm push di - - block: - asm mov cx,[si] // with ADD faster then LODSW - asm add si,2 - asm test ch,0xC0 - asm jns skip // 1 (SKP) or 0 (EOI) - asm jpo repeat // 2 (REP) - - copy: // 3 (CPY) - asm and ch,0x3F - asm shr cx,1 - asm rep movsw - asm jnc block - asm movsb - asm jmp block - - repeat: - asm and ch,0x3F - asm mov al,[si] - asm inc si - asm mov ah,al - asm shr cx,1 - asm rep stosw - asm jnc block - asm mov es:[di],al - asm inc di - asm jmp block - - skip: - asm jz endpl - asm and ch,0x3F - asm add di,cx - asm jmp block - - endpl: - asm pop di - asm pop ax - asm shl ah,1 - asm test ah,0x10 - asm jz x_chk - asm mov ah,0x01 - asm inc di - x_chk: - asm cmp ah,mask - asm jne plane - asm pop ds - */ - warning("STUB: BITMAP::Show"); + const byte *srcP = (const byte *)V; + byte *destP = (byte *)VGA::Page[1]->getBasePtr(x, y); + + int yc = 0, xc = 0; + + for (;;) { + uint16 v = READ_LE_UINT16(srcP); + srcP += 2; + int cmd = v >> 14; + int count = v & 0x3FFF; + + if (cmd == 0) + // End of image + break; + + // Handle a set of pixels + while (count-- > 0) { + // Transfer operation + switch (cmd) { + case 1: + // SKIP + break; + case 2: + // REPEAT + *destP = *srcP; + break; + case 3: + // COPY + *destP = *srcP++; + break; + } + + // Move to next dest position + ++destP; + ++xc; + if (xc == W) { + xc = 0; + ++yc; + if (yc == H) + return; + + destP = (byte *)VGA::Page[1]->getBasePtr(x, y + yc); + } + } + + if (cmd == 2) + ++srcP; + } + + // Temporary + g_system->copyRectToScreen((const byte *)VGA::Page[1]->getBasePtr(0, 0), SCR_WID, 0, 0, SCR_WID, SCR_HIG); + byte palData[PAL_SIZ]; + VGA::DAC2pal(VGA::SysPal, palData); + g_system->getPaletteManager()->setPalette(palData, 0, PAL_CNT); + + g_system->updateScreen(); + g_system->delayMillis(5000); } diff --git a/engines/cge/vga13h.h b/engines/cge/vga13h.h index 63886d9a99..edbeebf727 100644 --- a/engines/cge/vga13h.h +++ b/engines/cge/vga13h.h @@ -28,6 +28,7 @@ #ifndef __VGA13H__ #define __VGA13H__ +#include "graphics/surface.h" #include "cge/general.h" #include <stddef.h> #include "cge/bitmap.h" @@ -111,7 +112,7 @@ extern SEQ Seq2[]; #define PAL_CNT 256 -#define PAL_SIZ (PAL_CNT * sizeof(DAC)) +#define PAL_SIZ (PAL_CNT * 3) #define VGAATR_ 0x3C0 #define VGAMIw_ 0x3C0 #define VGASEQ_ 0x3C4 @@ -265,10 +266,13 @@ public: uint32 FrmCnt; QUEUE *ShowQ, *SpareQ; int Mono; - static uint8 *Page[4]; + static Graphics::Surface *Page[4]; + static DAC *VGA::SysPal; VGA(int mode); ~VGA(void); + static void init(); + static void deinit(); void Setup(VgaRegBlk *vrb); void GetColors(DAC *tab); @@ -279,6 +283,9 @@ public: void Sunset(void); void Show(void); void Update(void); + + static void pal2DAC(const byte *palData, DAC *tab); + static void DAC2pal(const DAC *tab, byte *palData); }; |