I am currently working on a program which is trying to refresh the screen at a rate of ~60hz.
Unfortunately, this is painfully *slow* :(
The screen size I am working on is 160x144 magnified 4x (that is really 640x576).
This is my current code:
Code: Select all
LcdModifiedFirstY = 255
LcdModifiedFirstX = 255
LcdModifiedLastX = 0
FOR y = 0 TO 143
LcdModifiedScanline(y) = 0
FOR x = 0 TO 159
IF ScreenBuffer(x, y) <> ScreenOldBuffer(x, y) THEN
ScreenOldBuffer(x, y) = ScreenBuffer(x, y)
IF LcdModifiedScanline(y) = 0 THEN
LcdModifiedScanline(y) = 1
IF (LcdModifiedFirstY > y) THEN LcdModifiedFirstY = y
LcdModifiedLastY = y
IF (LcdModifiedFirstX > x) THEN LcdModifiedFirstX = x
IF (LcdModifiedLastX < x) THEN LcdModifiedLastX = x
DIM AS UINTEGER x, y
IF (LcdModifiedFirstY < 255) THEN
DIM AS UINTEGER a, b, c, d
DIM AS UBYTE ScaleStepX, ScaleStepY
DIM AS UINTEGER PTR sPtr32 = Screenptr
FOR ScaleStepY = 0 TO (GraphicScaleFactor - 1) STEP FastScale
a = (GraphicWidth * ScaleStepY) + ScreenBorderRight + (ScreenBorderTop * GraphicWidth)
FOR y = LcdModifiedFirstY TO LcdModifiedLastY
IF (LcdModifiedScanline(y) = 1) THEN
b = y * GraphicWidth * GraphicScaleFactor
FOR x = LcdModifiedFirstX TO LcdModifiedLastX
c = (x * GraphicScaleFactor) + b + a
FOR ScaleStepX = 0 TO (GraphicScaleFactor - 1)
sPtr32[c + ScaleStepX] = ScreenPalette32(ScreenBuffer(x, y))
I am rendering my screen's content in an array called "ScreenBuffer(x,y)", and then I call this sub (refreshscreen) to draw it on screen. The ScreenBuffer() array is an array of UBYTES, and each value points to a palette entry (palette colors are stored in the array called ScreenPalette32()).
Variables ScaleStepX and ScaleStepY are both equal to 4 (but could be anything, to scale the screen more or less), and the variable "FastScale" is always equal to "1".
There is also a routine called "DetectScrenChanges()", which is detecting if the screen changed or not, and feeding variables LcdModifiedFirstX, LcdModifiedFirstY, LcdModifiedLastX, LcdModifiedLastY. (this way I don't have to redraw the screen if its content hasn't changed).
I am also keeping track of modifications on every line, to avoid redrawing lines of screen which weren't changed since last refresh (that's what the LcdModifiedScanline() array is about).
Is there any chance for me to speed up this code? I wonder if using SDL would improve the refresh rate speed?