-
Notifications
You must be signed in to change notification settings - Fork 0
Cleanup debug #90
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Cleanup debug #90
Changes from all commits
331013b
aed5f68
ea5c293
4fd6a55
661af3a
ad7554a
cf459ee
842617a
afd47d6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,19 @@ | |
#define MARGIN 25 | ||
#define MARGINS 50 // MARGIN*2 | ||
|
||
int SCREEN_WIDTH = 640; | ||
int SCREEN_HEIGHT = 480; | ||
int SCREEN_BPP = 32; | ||
#define WHITE_32BPP 0x00FFFFFF | ||
#define BLACK_32BPP 0x00000000 | ||
|
||
#define WHITE_16BPP 0xFFFF | ||
#define BLACK_16BPP 0x0000 | ||
|
||
#define WHITE_15BPP 0x7FFF | ||
#define BLACK_15BPP 0x0000 | ||
|
||
static unsigned char *SCREEN_FB = NULL; | ||
static int SCREEN_WIDTH = 0; | ||
static int SCREEN_HEIGHT = 0; | ||
static int SCREEN_BPP = 0; | ||
|
||
int nextRow = MARGIN; | ||
int nextCol = MARGIN; | ||
|
@@ -27,9 +37,23 @@ static const unsigned char systemFont[] = | |
#include "font_unscii_16.h" | ||
}; | ||
|
||
static void synchronizeVideoMode() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is already upstream as static void synchronizeFramebuffer(void)
{
VIDEO_MODE vm = XVideoGetMode();
SCREEN_WIDTH = vm.width;
SCREEN_HEIGHT = vm.height;
SCREEN_BPP = vm.bpp;
SCREEN_FB = XVideoGetFB();
} |
||
{ | ||
VIDEO_MODE vm = XVideoGetMode(); | ||
SCREEN_WIDTH = vm.width; | ||
SCREEN_HEIGHT = vm.height; | ||
SCREEN_BPP = vm.bpp; | ||
SCREEN_FB = XVideoGetFB(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Did you think about adding a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why would There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh oh. Yes you are right. I completely forgot that. Sry! |
||
} | ||
|
||
static void writebackBuffers() | ||
{ | ||
asm __volatile__("sfence"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is missing upstream. Let me try to explain it: So, because the CPU & compiler are "smart", they try to improve the performance of the given execution by doing out-of-order execution(I'm familiar with this) and also write-combining(also familiar for me). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't fully remember when it was a problem, but you can actually manage to break the displayed image if you don't do this. Basically if you get unlucky, your pixels will not be flushed to memory and instead they remain in the CPU write-combine-buffer, where the GPU won't see them. I believe flushing them to CPU cache was enough so the GPU can see that it needs to update? So this might be incorrect or I might have gotten lucky with |
||
} | ||
|
||
static void drawChar(unsigned char c, int x, int y, int fgColour, int bgColour) | ||
{ | ||
unsigned char *videoBuffer = XVideoGetFB(); | ||
unsigned char *videoBuffer = SCREEN_FB; | ||
videoBuffer += (y * SCREEN_WIDTH + x) * ((SCREEN_BPP+7)/8); | ||
|
||
unsigned char mask; | ||
|
@@ -146,17 +170,15 @@ void debugPrint(const char *format, ...) | |
va_start(argList, format); | ||
vsprintf(buffer, format, argList); | ||
va_end(argList); | ||
|
||
VIDEO_MODE vm = XVideoGetMode(); | ||
SCREEN_WIDTH = vm.width; | ||
SCREEN_HEIGHT = vm.height; | ||
SCREEN_BPP = vm.bpp; | ||
|
||
synchronizeVideoMode(); | ||
|
||
int fgColour; | ||
int bgColour; | ||
switch (SCREEN_BPP) { | ||
case 32: | ||
fgColour = WHITE; | ||
bgColour = BLACK; | ||
fgColour = WHITE_32BPP; | ||
bgColour = BLACK_32BPP; | ||
break; | ||
case 16: | ||
fgColour = WHITE_16BPP; | ||
|
@@ -194,30 +216,38 @@ void debugPrint(const char *format, ...) | |
|
||
s++; | ||
} | ||
|
||
writebackBuffers(); | ||
} | ||
|
||
void advanceScreen( void ) | ||
{ | ||
synchronizeVideoMode(); | ||
|
||
int pixelSize = (SCREEN_BPP+7)/8; | ||
int screenSize = SCREEN_WIDTH * (SCREEN_HEIGHT - MARGINS) * pixelSize; | ||
int lineSize = SCREEN_WIDTH * (FONT_HEIGHT + 1) * pixelSize; | ||
|
||
unsigned char* thisScreen = XVideoGetFB() + (SCREEN_WIDTH * MARGIN) * pixelSize; | ||
unsigned char* thisScreen = SCREEN_FB + (SCREEN_WIDTH * MARGIN) * pixelSize; | ||
unsigned char* prevScreen = thisScreen+lineSize; | ||
|
||
memmove(thisScreen, prevScreen, screenSize); | ||
|
||
nextRow -= (FONT_HEIGHT+1); | ||
nextCol = MARGIN; | ||
|
||
writebackBuffers(); | ||
} | ||
|
||
void debugClearScreen( void ) | ||
{ | ||
unsigned char* videoBuffer = XVideoGetFB(); | ||
synchronizeVideoMode(); | ||
|
||
memset( videoBuffer, 0, ((SCREEN_BPP+7)/8) * (SCREEN_WIDTH * SCREEN_HEIGHT) ); | ||
memset( SCREEN_FB, 0, ((SCREEN_BPP+7)/8) * (SCREEN_WIDTH * SCREEN_HEIGHT) ); | ||
nextRow = MARGIN; | ||
nextCol = MARGIN; | ||
|
||
writebackBuffers(); | ||
} | ||
|
||
void debugPrintHex(const char *buffer, int length) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,6 @@ extern "C" | |
|
||
// Defines for frame buffer | ||
#define VIDEO_BASE 0xFD000000 | ||
#define VIDEO_FRAMEBUFFER 0x03c00000 | ||
|
||
// Hardware access macros | ||
#define VIDEOREG(x) (*(volatile unsigned int*)(VIDEO_BASE + (x))) | ||
|
@@ -52,6 +51,7 @@ typedef struct _GAMMA_RAMP_ENTRY | |
|
||
DWORD XVideoGetEncoderSettings(void); | ||
unsigned char* XVideoGetFB(void); | ||
void XVideoSetFB(unsigned char *fb); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. all changes in this file are already upstream. |
||
VIDEO_MODE XVideoGetMode(void); | ||
|
||
void XVideoSetFlickerFilter(int level); | ||
|
@@ -74,7 +74,6 @@ If a value of 0 is provided for the bpp a default value of 32bpp is used. | |
BOOLEAN XVideoListModes(VIDEO_MODE *vm, int bpp, int refresh, void **p); | ||
|
||
void XVideoWaitForVBlank(); | ||
void XVideoSetDisplayStart(unsigned int offset); | ||
unsigned char* XVideoGetVideoBase(); | ||
int XVideoVideoMemorySize(); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -173,9 +173,6 @@ static const struct { | |
"\0\0\0\0\0\0\0\0\0\0\0", | ||
}; | ||
|
||
//Screen dimension constants | ||
const extern int SCREEN_WIDTH; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Has already been fixed in upstream in this commit. (valid for all three samples) |
||
const extern int SCREEN_HEIGHT; | ||
#define NUM_SPRITES 10 | ||
#define MAX_SPEED 5 | ||
|
||
|
@@ -284,7 +281,7 @@ void demo(void) | |
window = SDL_CreateWindow("Demo", | ||
SDL_WINDOWPOS_UNDEFINED, | ||
SDL_WINDOWPOS_UNDEFINED, | ||
SCREEN_WIDTH, SCREEN_HEIGHT, | ||
640, 480, | ||
SDL_WINDOW_SHOWN); | ||
if(window == NULL) | ||
{ | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why did you move the color defines into the c file? I would assume they were better suited in the header. Reason for that thought is, that one might include the header and switch the color of the text. A contradiction to that is that color switching is not supported by the debugPrint interface. This might be the reason for the change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WHITE
andBLACK
or red-black trees used it).= Generic macro names are not a good API, so it should not be exposed.
Adding color support to
debugPrint
should be avoided; consider the API soft-deprecated.