aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/demos/n00bdemo/disp.c28
-rw-r--r--examples/graphics/hdtv/main.c11
-rw-r--r--libpsn00b/psxcd/cdread.c2
-rw-r--r--libpsn00b/psxcd/common.c6
-rw-r--r--libpsn00b/psxetc/dl.c6
-rw-r--r--libpsn00b/psxgpu/common.c8
-rw-r--r--libpsn00b/psxgpu/env.c69
-rw-r--r--libpsn00b/psxsio/sio.c14
8 files changed, 72 insertions, 72 deletions
diff --git a/examples/demos/n00bdemo/disp.c b/examples/demos/n00bdemo/disp.c
index d8d2bbf..a43a1d6 100644
--- a/examples/demos/n00bdemo/disp.c
+++ b/examples/demos/n00bdemo/disp.c
@@ -18,9 +18,9 @@ MATRIX mtx;
void initDisplay() {
-
+
ResetGraph( 0 );
-
+
if( GetVideoMode() == MODE_NTSC ) {
SetDefDispEnv( &disp, 0, 0, 640, 480 );
SetDefDrawEnv( &draw, 0, 0, 640, 480 );
@@ -30,44 +30,44 @@ void initDisplay() {
SetDefDispEnv( &disp, 0, 0, 640, 512 );
SetDefDrawEnv( &draw, 0, 0, 640, 512 );
scSetClipRect( 0, 0, 640, 512 );
- disp.screen.y = 20;
- disp.screen.h = 256;
+ //disp.screen.y = 20;
+ //disp.screen.h = 256;
printf("PAL System.\n");
}
-
+
disp.isinter = 1;
draw.isbg = 1;
-
+
PutDispEnv( &disp );
PutDrawEnv( &draw );
-
+
ClearOTagR( ot[0], OT_LEN );
ClearOTagR( ot[1], OT_LEN );
nextpri = pribuff[0];
-
+
InitGeom();
gte_SetGeomScreen( 320 );
-
+
if( GetVideoMode() == MODE_NTSC ) {
gte_SetGeomOffset( 320, 240 );
} else {
gte_SetGeomOffset( 320, 256 );
}
-
+
}
void display() {
DrawSync(0);
VSync(0);
-
+
PutDrawEnv( &draw );
DrawOTag( ot[db]+OT_LEN-1 );
-
+
db ^= 1;
ClearOTagR( ot[db], OT_LEN );
nextpri = pribuff[db];
-
+
SetDispMask( 1 );
-
+
} \ No newline at end of file
diff --git a/examples/graphics/hdtv/main.c b/examples/graphics/hdtv/main.c
index 827b096..4d15742 100644
--- a/examples/graphics/hdtv/main.c
+++ b/examples/graphics/hdtv/main.c
@@ -651,13 +651,12 @@ void init() {
SetDefDispEnv( &db[0].disp, 0, 0, 640, SCREEN_YRES );
SetDefDrawEnv( &db[0].draw, 0, 0, SCREEN_XRES, SCREEN_YRES );
- db[0].disp.isinter = 1; // enable interlace, mandatory for hi-res modes
+ // Enable interlace (mandatory for hi-res modes)
+ db[0].disp.isinter = 1;
- db[0].disp.screen.x = -37; // shift left to center the widened picture
-
- db[0].disp.screen.w = 704; // increase the picture width to 704 pixels
- // (this does not strech the picture, it just
- // tells the GPU to output more pixels)
+ // Increase the picture width to 704 pixels
+ // (without stretching it, just tell the GPU to output more pixels)
+ db[0].disp.screen.w = (704 * 256) / 640;
// Enable draw area clear and dither processing
setRGB0( &db[0].draw, 63, 0, 127 );
diff --git a/libpsn00b/psxcd/cdread.c b/libpsn00b/psxcd/cdread.c
index 1adc255..7f480db 100644
--- a/libpsn00b/psxcd/cdread.c
+++ b/libpsn00b/psxcd/cdread.c
@@ -47,7 +47,7 @@ static void _sector_callback(CdlIntrResult irq, uint8_t *result) {
CdCommandF(CdlPause, 0, 0);
_cd_override_callback = (CdlCB) 0;
- if (!_pending_attempts && _read_callback)
+ if ((!_pending_sectors || !_pending_attempts) && _read_callback)
_read_callback(irq, result);
_read_timeout = VSync(-1) + CD_READ_COOLDOWN;
diff --git a/libpsn00b/psxcd/common.c b/libpsn00b/psxcd/common.c
index 438fcc1..e452b91 100644
--- a/libpsn00b/psxcd/common.c
+++ b/libpsn00b/psxcd/common.c
@@ -203,9 +203,11 @@ static void _cd_irq_handler(void) {
/* Initialization */
int CdInit(void) {
- EnterCriticalSection();
+ int _exit = EnterCriticalSection();
+
InterruptCallback(IRQ_CD, &_cd_irq_handler);
- ExitCriticalSection();
+ if (_exit)
+ ExitCriticalSection();
BUS_CD_CFG = 0x00020943;
diff --git a/libpsn00b/psxetc/dl.c b/libpsn00b/psxetc/dl.c
index 06302e2..4fa1370 100644
--- a/libpsn00b/psxetc/dl.c
+++ b/libpsn00b/psxetc/dl.c
@@ -422,9 +422,11 @@ DLL *DL_CreateDLL(DLL *dll, void *ptr, size_t size, DL_ResolveMode mode) {
}
}
- EnterCriticalSection();
+ int _exit = EnterCriticalSection();
+
FlushCache();
- ExitCriticalSection();
+ if (_exit)
+ ExitCriticalSection();
// Call the DLL's global constructors. This is the same thing we'd do in
// _start() for regular executables, but we have to do it outside of the
diff --git a/libpsn00b/psxgpu/common.c b/libpsn00b/psxgpu/common.c
index 7e0758b..5678f35 100644
--- a/libpsn00b/psxgpu/common.c
+++ b/libpsn00b/psxgpu/common.c
@@ -88,13 +88,15 @@ void ResetGraph(int mode) {
// Perform some basic system initialization when ResetGraph() is called for
// the first time.
if (!ResetCallback()) {
- EnterCriticalSection();
+ int _exit = EnterCriticalSection();
+
InterruptCallback(IRQ_VBLANK, &_vblank_handler);
InterruptCallback(IRQ_GPU, &_gpu_irq_handler);
DMACallback(DMA_GPU, &_gpu_dma_handler);
-
_gpu_video_mode = (GPU_GP1 >> 20) & 1;
- ExitCriticalSection();
+
+ if (_exit)
+ ExitCriticalSection();
_sdk_log("setup done, default mode is %s\n", _gpu_video_mode ? "PAL" : "NTSC");
}
diff --git a/libpsn00b/psxgpu/env.c b/libpsn00b/psxgpu/env.c
index 236ae4b..fdd4329 100644
--- a/libpsn00b/psxgpu/env.c
+++ b/libpsn00b/psxgpu/env.c
@@ -169,69 +169,62 @@ DISPENV *SetDefDispEnv(DISPENV *env, int x, int y, int w, int h) {
void PutDispEnv(const DISPENV *env) {
_sdk_validate_args_void(env);
- uint32_t h_range, v_range, mode, fb_pos;
+ uint32_t fb_pos, h_range, v_range, mode;
mode = _gpu_video_mode << 3;
mode |= (env->isrgb24 & 1) << 4;
mode |= (env->isinter & 1) << 5;
mode |= (env->reverse & 1) << 7;
- if (env->disp.h > 256)
- mode |= 1 << 2;
+ int h_span = env->screen.w ? env->screen.w : 256;
+ int v_span = env->screen.h ? env->screen.h : 240;
- // Calculate the horizontal display range values. The original code was
- // this bad; in actual fact it was even worse due to being written in
- // assembly and using slow multiplication even when not necessary.
- int offset, span, default_span = 2560;
+ // Calculate the horizontal and vertical display range values.
+ h_span *= 10;
if (env->disp.w > 560) {
// 640 pixels
- mode |= 3;
- offset = 620;
- span = env->screen.w * 4;
+ mode |= 3 << 0;
+ //h_span *= 4;
} else if (env->disp.w > 400) {
// 512 pixels
- mode |= 2;
- offset = 615;
- span = env->screen.w * 4 + env->screen.w;
+ mode |= 2 << 0;
+ //h_span *= 5;
} else if (env->disp.w > 352) {
- // 384 pixels (this mode is weird)
- mode |= 1 << 6;
- offset = 539;
- span = env->screen.w * 8 - env->screen.w;
- default_span = 2688;
+ // 368 pixels
+ mode |= 1 << 6;
+ //h_span *= 7;
} else if (env->disp.w > 280) {
// 320 pixels
- mode |= 1;
- offset = 600;
- span = env->screen.w * 8;
+ mode |= 1 << 0;
+ //h_span *= 8;
} else {
// 256 pixels
- offset = 590;
- span = env->screen.w * 8 + env->screen.w * 2;
+ mode |= 0 << 0;
+ //h_span *= 10;
}
- offset += env->screen.x * 4;
- if (!span)
- span = default_span;
-
- h_range = offset & 0xfff;
- h_range |= ((offset + span) & 0xfff) << 12;
-
- // Calculate the vertical display range values.
- offset = 16 + env->screen.y;
- span = env->screen.h ? env->screen.h : 240;
+ if (env->disp.h > 256) {
+ mode |= 1 << 2;
+ //v_span /= 2;
+ }
- v_range = offset & 0x3ff;
- v_range |= ((offset + span) & 0x3ff) << 10;
+ int x = env->screen.x + 0x760;
+ int y = env->screen.y + (_gpu_video_mode ? 0xa3 : 0x88);
+ h_span /= 2;
+ v_span /= 2;
- fb_pos = env->disp.x & 0x3ff;
- fb_pos |= (env->disp.y & 0x1ff) << 10;
+ fb_pos = (env->disp.x & 0x3ff);
+ fb_pos |= (env->disp.y & 0x1ff) << 10;
+ h_range = ((x - h_span) & 0xfff);
+ h_range |= ((x + h_span) & 0xfff) << 12;
+ v_range = ((y - v_span) & 0x3ff);
+ v_range |= ((y + v_span) & 0x3ff) << 10;
+ GPU_GP1 = 0x05000000 | fb_pos; // Set VRAM location to display
GPU_GP1 = 0x06000000 | h_range; // Set horizontal display range
GPU_GP1 = 0x07000000 | v_range; // Set vertical display range
GPU_GP1 = 0x08000000 | mode; // Set video mode
- GPU_GP1 = 0x05000000 | fb_pos; // Set VRAM location to display
}
/* Deprecated "raw" display API */
diff --git a/libpsn00b/psxsio/sio.c b/libpsn00b/psxsio/sio.c
index 919f0cb..b487148 100644
--- a/libpsn00b/psxsio/sio.c
+++ b/libpsn00b/psxsio/sio.c
@@ -74,7 +74,7 @@ static void _sio_handler(void) {
SIO_CTRL(1) |= CR_TXIEN;
SIO_DATA(1) = _tx_buffer.data[head];
} else {
- SIO_CTRL(1) &= CR_TXIEN ^ 0xffff;
+ SIO_CTRL(1) &= CR_TXIEN ^ 0xffff;
}
}
@@ -88,7 +88,7 @@ static void _sio_handler(void) {
/* Serial port initialization API */
void SIO_Init(int baud, uint16_t mode) {
- EnterCriticalSection();
+ int _exit = EnterCriticalSection();
_old_sio_handler = InterruptCallback(IRQ_SIO1, &_sio_handler);
SIO_CTRL(1) = CR_ERRRST;
@@ -106,16 +106,18 @@ void SIO_Init(int baud, uint16_t mode) {
_flow_control = SIO_FC_NONE;
_ctrl_reg_flag = 0;
- ExitCriticalSection();
+ if (_exit)
+ ExitCriticalSection();
}
void SIO_Quit(void) {
- EnterCriticalSection();
- InterruptCallback(IRQ_SIO1, _old_sio_handler);
+ int _exit = EnterCriticalSection();
+ InterruptCallback(IRQ_SIO1, _old_sio_handler);
SIO_CTRL(1) = CR_ERRRST;
- ExitCriticalSection();
+ if (_exit)
+ ExitCriticalSection();
}
void SIO_SetFlowControl(SIO_FlowControl mode) {