Added centering of the image to the GP2X port. Note that I haven't

compiled this code yet, so there's no guarantees :)


git-svn-id: svn://svn.code.sf.net/p/stella/code/trunk@1245 8b62c5a3-ac7e-4cc8-8f21-d9a121418aba
This commit is contained in:
stephena 2006-12-26 23:53:27 +00:00
parent 0724c20181
commit 485f9200a4
2 changed files with 34 additions and 16 deletions

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: FrameBufferGP2X.cxx,v 1.13 2006-12-19 12:40:30 stephena Exp $ // $Id: FrameBufferGP2X.cxx,v 1.14 2006-12-26 23:53:27 stephena Exp $
//============================================================================ //============================================================================
#include <SDL.h> #include <SDL.h>
@ -29,6 +29,7 @@
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
FrameBufferGP2X::FrameBufferGP2X(OSystem* osystem) FrameBufferGP2X::FrameBufferGP2X(OSystem* osystem)
: FrameBuffer(osystem), : FrameBuffer(osystem),
myBasePtr(0),
myDirtyFlag(true) myDirtyFlag(true)
{ {
} }
@ -76,12 +77,23 @@ bool FrameBufferGP2X::createScreen()
SDL_UpdateRect(myScreen, 0, 0, 0, 0); SDL_UpdateRect(myScreen, 0, 0, 0, 0);
} }
// Determine the best screenmode to use; we only use 320x240 or 400x300
if(myBaseDim.w <= 320 && myBaseDim.h <= 240)
{
myScreenDim.w = 320;
myScreenDim.h = 240;
}
else
{
myScreenDim.w = 400;
myScreenDim.h = 300;
}
myScreenDim.x = myScreenDim.y = 0; myScreenDim.x = myScreenDim.y = 0;
myScreenDim.w = myBaseDim.w;
myScreenDim.h = myBaseDim.h;
// In software mode, the image and screen dimensions are always the same // In software mode, the image and base dimensions are always the same
myImageDim = myScreenDim; myImageDim = myBaseDim;
myImageDim.x = (myScreenDim.w - myImageDim.w) / 2;
myImageDim.y = (myScreenDim.h - myImageDim.h) / 2;
// The GP2X always uses a 16-bit hardware buffer // The GP2X always uses a 16-bit hardware buffer
myScreen = SDL_SetVideoMode(myScreenDim.w, myScreenDim.h, 16, mySDLFlags); myScreen = SDL_SetVideoMode(myScreenDim.w, myScreenDim.h, 16, mySDLFlags);
@ -90,6 +102,8 @@ bool FrameBufferGP2X::createScreen()
cerr << "ERROR: Unable to open SDL window: " << SDL_GetError() << endl; cerr << "ERROR: Unable to open SDL window: " << SDL_GetError() << endl;
return false; return false;
} }
myBasePtr = (uInt16*) myScreen->pixels +
myImageDim.y * myScreen->pitch + myImageDim.x;
myPitch = myScreen->pitch/2; myPitch = myScreen->pitch/2;
myDirtyFlag = true; myDirtyFlag = true;
@ -105,7 +119,7 @@ void FrameBufferGP2X::drawMediaSource()
uInt8* previousFrame = mediasrc.previousFrameBuffer(); uInt8* previousFrame = mediasrc.previousFrameBuffer();
uInt32 width = mediasrc.width(); uInt32 width = mediasrc.width();
uInt32 height = mediasrc.height(); uInt32 height = mediasrc.height();
uInt16* buffer = (uInt16*) myScreen->pixels; uInt16* buffer = myBasePtr;
uInt32 bufofsY = 0; uInt32 bufofsY = 0;
uInt32 screenofsY = 0; uInt32 screenofsY = 0;
@ -181,12 +195,12 @@ void FrameBufferGP2X::scanline(uInt32 row, uInt8* data)
SDL_LockSurface(myScreen); SDL_LockSurface(myScreen);
uInt32 bpp = myScreen->format->BytesPerPixel; uInt32 bpp = myScreen->format->BytesPerPixel;
uInt8* start = (uInt8*) myScreen->pixels; uInt8* start = (uInt8*) myBasePtr;
uInt32 yoffset = row * myScreen->pitch; uInt32 yoffset = row * myScreen->pitch;
uInt32 pixel = 0; uInt32 pixel = 0;
uInt8 *p, r, g, b; uInt8 *p, r, g, b;
for(Int32 x = 0; x < myScreen->w; x++) for(Int32 x = 0; x < myImageDim.w; x++)
{ {
p = (Uint8*) (start + // Start at top of RAM p = (Uint8*) (start + // Start at top of RAM
(yoffset) + // Go down 'row' lines (yoffset) + // Go down 'row' lines
@ -228,8 +242,8 @@ void FrameBufferGP2X::vLine(uInt32 x, uInt32 y, uInt32 y2, int color)
SDL_Rect tmp; SDL_Rect tmp;
// Vertical line // Vertical line
tmp.x = x; tmp.x = x + myImageDim.x;
tmp.y = y; tmp.y = y + myImageDim.y;
tmp.w = 1; tmp.w = 1;
tmp.h = (y2 - y + 1); tmp.h = (y2 - y + 1);
SDL_FillRect(myScreen, &tmp, myDefPalette[color]); SDL_FillRect(myScreen, &tmp, myDefPalette[color]);
@ -242,8 +256,8 @@ void FrameBufferGP2X::fillRect(uInt32 x, uInt32 y, uInt32 w, uInt32 h,
SDL_Rect tmp; SDL_Rect tmp;
// Fill the rectangle // Fill the rectangle
tmp.x = x; tmp.x = x + myImageDim.x;
tmp.y = y; tmp.y = y + myImageDim.y;
tmp.w = w; tmp.w = w;
tmp.h = h; tmp.h = h;
SDL_FillRect(myScreen, &tmp, myDefPalette[color]); SDL_FillRect(myScreen, &tmp, myDefPalette[color]);
@ -268,7 +282,7 @@ void FrameBufferGP2X::drawChar(const GUI::Font* font, uInt8 chr,
chr -= desc.firstchar; chr -= desc.firstchar;
const uInt16* tmp = desc.bits + (desc.offset ? desc.offset[chr] : (chr * h)); const uInt16* tmp = desc.bits + (desc.offset ? desc.offset[chr] : (chr * h));
uInt16* buffer = (uInt16*) myScreen->pixels + yorig * myScreen->w + xorig; uInt16* buffer = (uInt16*) myBasePtr + yorig * myScreen->w + xorig;
for(int y = 0; y < h; ++y) for(int y = 0; y < h; ++y)
{ {
const uInt16 ptr = *tmp++; const uInt16 ptr = *tmp++;
@ -285,7 +299,7 @@ void FrameBufferGP2X::drawChar(const GUI::Font* font, uInt8 chr,
void FrameBufferGP2X::drawBitmap(uInt32* bitmap, Int32 xorig, Int32 yorig, void FrameBufferGP2X::drawBitmap(uInt32* bitmap, Int32 xorig, Int32 yorig,
int color, Int32 h) int color, Int32 h)
{ {
uInt16* buffer = (uInt16*) myScreen->pixels + yorig * myScreen->w + xorig; uInt16* buffer = (uInt16*) myBasePtr + yorig * myScreen->w + xorig;
for(int y = 0; y < h; ++y) for(int y = 0; y < h; ++y)
{ {
uInt32 mask = 0xF0000000; uInt32 mask = 0xF0000000;

View File

@ -13,7 +13,7 @@
// See the file "license" for information on usage and redistribution of // See the file "license" for information on usage and redistribution of
// this file, and for a DISCLAIMER OF ALL WARRANTIES. // this file, and for a DISCLAIMER OF ALL WARRANTIES.
// //
// $Id: FrameBufferGP2X.hxx,v 1.8 2006-12-19 12:40:30 stephena Exp $ // $Id: FrameBufferGP2X.hxx,v 1.9 2006-12-26 23:53:27 stephena Exp $
//============================================================================ //============================================================================
#ifndef FRAMEBUFFER_GP2X_HXX #ifndef FRAMEBUFFER_GP2X_HXX
@ -32,7 +32,7 @@ class GUI::Font;
This class implements an SDL hardware framebuffer for the GP2X device. This class implements an SDL hardware framebuffer for the GP2X device.
@author Stephen Anthony @author Stephen Anthony
@version $Id: FrameBufferGP2X.hxx,v 1.8 2006-12-19 12:40:30 stephena Exp $ @version $Id: FrameBufferGP2X.hxx,v 1.9 2006-12-26 23:53:27 stephena Exp $
*/ */
class FrameBufferGP2X : public FrameBuffer class FrameBufferGP2X : public FrameBuffer
{ {
@ -211,6 +211,10 @@ class FrameBufferGP2X : public FrameBuffer
virtual void showCursor(bool show); virtual void showCursor(bool show);
private: private:
// Origin at which to access the FrameBuffer
// This point is treated as (0, 0) wrt the TIA image
uInt16* myBasePtr;
// Indicates that the buffer is dirty, and should be redrawn/flipped // Indicates that the buffer is dirty, and should be redrawn/flipped
bool myDirtyFlag; bool myDirtyFlag;