Problem with KOS 320*240 50hz/60hz mode ?

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
bfg
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Problem with KOS 320*240 50hz/60hz mode ?

Post by bfg »

Hello,

i've a problem really strange and complex to explain ... I'm currently coding Sydney Hunter for Dreamcast. Trying my alpha version on a real Hardware on CRT TV make a blurry image. It's perfect in VGA.

To show that i'm not dreaming, i've check the title screen of my very old port of Pang on Dreamcast compiled with an old SDL Chui version (320*240) and the title screen in KOS.

Here's the differrence,

on SDL CHUI : (click for full screen)

Image

The picture is perfect ... Good pixel, not a blurry image

On KOS (1.3 and 2.0 last version) : vid_set_mode(DM_320x240_NTSC, PM_RGB565);

Image

The image seems to be streched vertically. A white line of pixel look 3 lines.

Example :

SDL :

**********************************

KOS :
------------------------------------------------
************************************
------------------------------------------------

For just a line of pixel. It's very complex to explain ... Is someone have an idea ? Sydney Hunter look very very strange on CRT (even PAL 50hz) but perfect on VGA ...

Thanks for help.
Chilly Willy
DC Developer
DC Developer
Posts: 414
Joined: Thu Aug 20, 2009 11:00 am
Has thanked: 0
Been thanked: 2 times

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by Chilly Willy »

320x240 is 4:3 in VGA with square pixels, but the pixels aren't square in NTSC. 320x224 is roughly 4:3 in NTSC, so you need to rescale graphics or they come out stretched. It's not a problem with the DC or the software, just the way TV works.
bfg
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by bfg »

So why it's "clean" with Chui's SDL and not with KOS on the same picture and same resolution ?
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by BlueCrab »

If I had to guess (without looking at source code, since I don't have Chui's SDL handy), I'd guess that Chui's SDL might be using 640x480 mode and upscaling your 320x240 image without you knowing about it.

Considering Chui's SDL is backed by KOS' video code, there shouldn't be any difference if the video is initialized the same way.
bfg
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by bfg »

Yes that's why i found that strange ... I can't found the old SDL CHUI source code user for my Pang, but the new version use DM320x340 for 320x240 mode.

I'll check my old archive to find what it does exactly, but on my TV 640*480 mode flicker, and my old Pang didn't flicker at all ...

I'll try different mode and look to find the old SDL chui source code.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by BlueCrab »

Are the two screenshots compiled against the same version of KOS? Just wanting to eliminate some sort of weird video bug being introduced recently.

Also, if 640x480 mode flickers on your TV, then it'd be impossible to run most Dreamcast games on it without experiencing the same flicker -- pretty much every Dreamcast game (commercial or homebrew) runs at 640x480.
bfg
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by bfg »

BlueCrab wrote:Are the two screenshots compiled against the same version of KOS? Just wanting to eliminate some sort of weird video bug being introduced recently.

Also, if 640x480 mode flickers on your TV, then it'd be impossible to run most Dreamcast games on it without experiencing the same flicker -- pretty much every Dreamcast game (commercial or homebrew) runs at 640x480.
I've compiled the image test with KOS1.3 and the latest SVN, same result on 320*240.

This morning i've compiled the test on KOS1.3 on DM_640x480, doubled the image, the image is ok but it flicker a little. To compare, i've launch the old sdl version, and the image is the same but not flicker at all ...

Don't understand wich option SDL use ... . I'll try a image test with Chui SDL and see how it react. (Not much time for the moment :( :( ).
User avatar
SWAT
Insane DCEmu
Insane DCEmu
Posts: 191
Joined: Sat Jan 31, 2004 2:34 pm
Location: Russia/Novosibirsk
Has thanked: 1 time
Been thanked: 0
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by SWAT »

You use SDL for rendering or just for setup video mode?
Chui SDL have textured video render and can render pixel data as texture by PVR hardware, it's stretches the image(polygon) to fill the screen.
I use this method too in my project (but with custom rendering, not Chui). The KOS SDL port doesn't have it.
Image
bfg
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by bfg »

SWAT wrote:You use SDL for rendering or just for setup video mode?
Chui SDL have textured video render and can render pixel data as texture by PVR hardware, it's stretches the image(polygon) to fill the screen.
I use this method too in my project (but with custom rendering, not Chui). The KOS SDL port doesn't have it.
I use SDL for rendering.

I've checked the KOS log :

Pang screenshot SDL : 320x240 NTSC
Pang screenshot KOS : 320x240 NTSC

and the difference between the 2 pictures is the same at the 1st post ... SDL must do something that KOS don't ...

Sorry but I don't understand the difference when you say : "Chui SDL have textured video render and can render pixel data as texture by PVR hardware, it's stretches the image(polygon) to fill the screen". (Sorry, i'm very bad at technical things ...)
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by BlueCrab »

As in, Chui's SDL code has a few different modes you can operate it in. Two of those modes (normal video access and DMA-based frame buffer) should produce identical results to simply writing to the framebuffer with KOS.

The third method is to render the entire scene to a texture in main memory, and then use the 3D hardware to render it to a full-screen polygon. This third method is what SWAT was talking about. Since the 3D hardware can do various filtering methods and things of that nature, this could very well produce visibly different output depending on what you do with it.

How exactly are you rendering the image you're putting out with KOS (and with Chui's SDL)? Can you post the code here so I might take a look?
bfg
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by bfg »

In KOS : (Extract from the whole source code, i haven't put the pvr_wait_ready(); ... and so)

Code: Select all

loadImageTra("cd/DATA/nocut.png",2,512,512);
blitImageTra(2,0,0);
Whith

Code: Select all

typedef struct si {
	int chargee;	// L'image est elle chargée ?
	int hauteur;	// Hauteur
	int largeur; // Largeur
	pvr_ptr_t surface;
} simage;

simage imagesTra[MAX_IMAGE_TRA];

int loadImageTra(char *filename,int noImage,int hauteur,int largeur)
{
	imagesTra[noImage].surface = pvr_mem_malloc(hauteur*largeur*2);
	png_to_texture(filename, imagesTra[noImage].surface, PNG_FULL_ALPHA);
	imagesTra[noImage].hauteur = hauteur;
	imagesTra[noImage].largeur = largeur;
	imagesTra[noImage].chargee = 1;

	return 0;
}
void blitImageTra(int ino,int dx,int dy)
{
	pvr_poly_cxt_t cxt;
	pvr_poly_hdr_t hdr;
	pvr_vertex_t vert;

	if (imagesTra[ino].chargee==0) return;

	ZPos++;

	pvr_poly_cxt_txr(&cxt, PVR_LIST_TR_POLY, PVR_TXRFMT_ARGB4444, imagesTra[ino].largeur, imagesTra[ino].hauteur, imagesTra[ino].surface, 0);
	pvr_poly_compile(&hdr, &cxt);
	pvr_prim(&hdr, sizeof(hdr));

    vert.argb = PVR_PACK_COLOR(1.0f, 1.0f, 1.0f, 1.0f);
    vert.oargb = 0;
    vert.flags = PVR_CMD_VERTEX;

    vert.x = dx;
    vert.y = dy;
    vert.z = ZPos;
    vert.u = 0;
    vert.v = 0;
    pvr_prim(&vert, sizeof(vert));

    vert.x = dx+imagesTra[ino].largeur;
    vert.y = dy;
    vert.z = ZPos;
    vert.u = 1;
    vert.v = 0;
    pvr_prim(&vert, sizeof(vert));

    vert.x = dx;
    vert.y = dy+imagesTra[ino].hauteur;
    vert.z = ZPos;
    vert.u = 0;
    vert.v = 1;
    pvr_prim(&vert, sizeof(vert));

    vert.x = dx+imagesTra[ino].largeur;
    vert.y = dy+imagesTra[ino].hauteur;
    vert.z = ZPos;
    vert.u = 1;
    vert.v = 1;
    vert.flags = PVR_CMD_VERTEX_EOL;
    pvr_prim(&vert, sizeof(vert));

}
In SDL

Code: Select all

loadBmp("","","romdisk/title.bmp","/rd/title.bmp",2);	 
blitImageToScreen(2,0,0,320,240,0,0,320,240,320,240);	
With

Code: Select all

SDL_Surface *images[10];
int loadBmp(char *path,char *filename,char * pathfilename,char *pathdc,int noImage)
{        
         SDL_FreeSurface(images[noImage]);
         images[noImage] = SDL_LoadBMP(pathdc);
         if (images[noImage]==NULL) exit(0);
         if ( (noImage==1) || (noImage==3) ) SDL_SetColorKey(images[noImage], (SDL_SRCCOLORKEY|SDL_RLEACCEL), SDL_MapRGB(images[noImage]->format,255,255,255));
    return 0;
}

void blitImageToScreen(int imageNo,int sx,int sy,int sw,int sh,int dx,int dy,int dw,int dh,int ttw,int tth)
{
            SDL_Rect dest;
            dest.x = dx;
            dest.y = dy;

            dest.h = dh;
            dest.w = dw;
                      
            SDL_Rect src;
            src.x = sx;

            src.y = sy;
            src.h = sh;
            src.w = sw;     

            SDL_BlitSurface(images[imageNo],&src,screen,&dest);
}
Thanks for help !
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by BlueCrab »

So... If I'm parsing what you're doing correctly, with SDL, you're blitting a BMP file that's of size 320x240 to the screen directly, right?

With your KOS code, you're blitting a PNG file that appears to be 512x512 in size, resizing it down to 320x240, if I'm reading it properly. That's where your problem is right there, if that's the case -- you've resized the image to a different size (which probably introduced its own set of weird artifact patterns to the image), then the video hardware is being forced to resize it once again back to the original size. You're definitely going to lose something in those conversions!

If this is indeed what you're doing, why not simply take the BMP, convert it to a PNG, then take the image and set the size to 512x256. I'm not suggesting to scale the image here, but rather just to increase the size the image while leaving the image data of the same size and keeping it aligned to the top-left corner of the image. Then you can use the u and v coordinates of each vertex to select the correct portion of the image to display (the top left u, v would still be 0, 0; the bottom right would then be 320.0f / 512, 240.0f / 256 -- you should be able to figure out what to do for the rest from that).

To give you an idea of what I'm suggesting (in case it isn't clear), here's the title screen code (and I've attached the image file too) from an emulator I wrote where I use the same technique (although, I'm displaying a 640x480 image, but the math works out the same either way). I only display the 640x480 pixels from the top left corner of the image...

Code: Select all

static void draw_textured_quad(pvr_poly_hdr_t *hdr, float x, float y, float z,
                               float w, float h, float umax, float vmax) {
    pvr_vertex_t vert;

    pvr_prim(hdr, sizeof(pvr_poly_hdr_t));

    vert.flags = PVR_CMD_VERTEX;
    vert.argb = 0xFFFFFFFF;
    vert.oargb = 0x00000000;

    vert.x = x;
    vert.y = y + h;
    vert.z = z;
    vert.u = 0.0f;
    vert.v = vmax;
    pvr_prim(&vert, sizeof(pvr_vertex_t));

    vert.y = y;
    vert.v = 0.0f;
    pvr_prim(&vert, sizeof(pvr_vertex_t));

    vert.x = x + w;
    vert.y = y + h;
    vert.u = umax;
    vert.v = vmax;
    pvr_prim(&vert, sizeof(pvr_vertex_t));

    vert.flags = PVR_CMD_VERTEX_EOL;
    vert.y = y;
    vert.v = 0.0f;
    pvr_prim(&vert, sizeof(pvr_vertex_t));
}

Code: Select all

            pvr_wait_ready();
            pvr_scene_begin();
            
            pvr_list_begin(PVR_LIST_OP_POLY);
            draw_textured_quad(&hdr_title, 0.0f, 0.0f, 1.0f, 640.0f, 480.0f,
                               640.0f / 1024.0f, 480.0f / 512.0f);
            
            pvr_list_finish();
            pvr_scene_finish();
Attachments
title.png
bfg
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by bfg »

No, that's not that. (i think :) ).

In SDL i have a 320*240 image that i show on 320*240 screen.

In KOS i have a 512*512 texture that i show on 320*240 screen, no resizing. The 320*240 image is in the 512*512 texture, no resize, the pixel > 320 are black and >240 are black not used.

In KOS i've already tryed to cut a part of the 512 *512 image, and put in the screen, no resize, like you suggest, the effect is the same ... That's why i don't understand, i don't resize anything ...

(Or there something in my KOS source code that i don't understand ...)
User avatar
Orion_
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Fri Nov 21, 2014 3:31 pm
Location: France
Has thanked: 0
Been thanked: 0
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by Orion_ »

I have the exact same problem, I'm using KOS 2.0
I use vid_init(DM_320x240, PM_RGB565);
on VGA screen, it's pixel perfect, but on my TV (using an RGB cable, on a PAL TV), I get blurry picture :/
My dreamcast is PAL, and my lib is doing pixel perfect blitting without resize using pvr_prim.

maybe this has to do with the "NTSC" thing I can see in KOS log, it seems to initialize the console in 320x240 NTSC mode even when PAL is selected (for example in nullDC)
Retro Game Programming -> http://onorisoft.free.fr/ <-
Dreamcast, PS1, PCe, MD, Atari, Jaguar, GP32, GBA, ...
User avatar
Orion_
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Fri Nov 21, 2014 3:31 pm
Location: France
Has thanked: 0
Been thanked: 0
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by Orion_ »

Here is my test (click on the image to get a higher resolution)
On the left, a photo of the game on a VGA LCD Screen in DM_320x240 mode with VGA cable.
On the right, a photo of the game on a TV LCD Screen in DM_320x240_PAL mode with RGB cable on a PAL TV/Dreamcast.
Image
Retro Game Programming -> http://onorisoft.free.fr/ <-
Dreamcast, PS1, PCe, MD, Atari, Jaguar, GP32, GBA, ...
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by BlueCrab »

Orion_ wrote:I have the exact same problem, I'm using KOS 2.0
I use vid_init(DM_320x240, PM_RGB565);
on VGA screen, it's pixel perfect, but on my TV (using an RGB cable, on a PAL TV), I get blurry picture :/
My dreamcast is PAL, and my lib is doing pixel perfect blitting without resize using pvr_prim.

maybe this has to do with the "NTSC" thing I can see in KOS log, it seems to initialize the console in 320x240 NTSC mode even when PAL is selected (for example in nullDC)
If you want to force PAL mode, you have to specify that when you initialize the hardware. The code will automatically select NTSC otherwise (unless you're hooked up to a VGA display, of course). The only difference is 60hz versus 50hz however.

That all said, as was already described, you're not going to get pixel-perfect results when using a non-VGA output. The image you've posted is about exactly what I'd expect out of VGA versus RGB...
bfg wrote:No, that's not that. (i think :) ).

In SDL i have a 320*240 image that i show on 320*240 screen.

In KOS i have a 512*512 texture that i show on 320*240 screen, no resizing. The 320*240 image is in the 512*512 texture, no resize, the pixel > 320 are black and >240 are black not used.

In KOS i've already tryed to cut a part of the 512 *512 image, and put in the screen, no resize, like you suggest, the effect is the same ... That's why i don't understand, i don't resize anything ...

(Or there something in my KOS source code that i don't understand ...)
Yeah, I see now that you're not really resizing. Thinking about it now, the PVR code in KOS does do some vertical scaling/smoothing on images when you're not using VGA. Perhaps try doing this (after you've called pvr_init() or pvr_init_defaults()) and see if it gets rid of the artifacting you're seeing:

Code: Select all

PVR_SET(PVR_SCALER_CFG, 0x400);
User avatar
Orion_
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Fri Nov 21, 2014 3:31 pm
Location: France
Has thanked: 0
Been thanked: 0
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by Orion_ »

I made a puzzle game on the PS1, in 320x240 resolution, and the RGB output is much cleaner than that on my TV, almost like a VGA output ;)
and, since "bfg" get a much cleaner output with SDL, I guess the problem is somewhere in the code (either KOS, or SDL do something more)
Retro Game Programming -> http://onorisoft.free.fr/ <-
Dreamcast, PS1, PCe, MD, Atari, Jaguar, GP32, GBA, ...
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5658
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by BlueCrab »

SDL (at least the one included with KOS) does direct framebuffer writes to do its "rendering". Two of the three modes Chui's SDL does do the exact same thing, basically.

The code he's using here is using the 3D hardware to do the rendering to the framebuffer. The 3D hardware does its own scaling and whatnot, and for 320x240 mode, that's probably not necessary to be done, hence why I told him how to tune that to the same settings that are used for VGA mode in the last post. If you're using 320x240 mode, you might well try the same thing to see if it helps in your case.

That said, as I've already expressed, VGA is going to produce a better picture than RGB, S-Video, or Composite. There's nothing that can be done about that.
User avatar
Orion_
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Fri Nov 21, 2014 3:31 pm
Location: France
Has thanked: 0
Been thanked: 0
Contact:

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by Orion_ »

I tried and it fix the problem ! The image is now clean and pixel perfect !
Here is my code:

Code: Select all

	vid_init(DM_320x240, PM_RGB565);
	pvr_init_defaults();
	if (vid_check_cable() != CT_VGA)
		PVR_SET(PVR_SCALER_CFG, 0x400);	// Disable Scaling in RGB mode (avoid having a blurry image on TV)
Do you know how to detect a PAL console so we can set PAL mode instead of NTSC ?
Retro Game Programming -> http://onorisoft.free.fr/ <-
Dreamcast, PS1, PCe, MD, Atari, Jaguar, GP32, GBA, ...
bfg
DCEmu Crazy Poster
DCEmu Crazy Poster
Posts: 31
Joined: Wed Oct 17, 2001 7:44 pm
Has thanked: 0
Been thanked: 0

Re: Problem with KOS 320*240 50hz/60hz mode ?

Post by bfg »

@BlueCrab : You're my new god !!!! It's just perfect !! Thanks !!!


@orion :

if(vid_check_cable()==CT_VGA) {
vid_set_mode(DM_320x240_VGA, PM_RGB565);
} else if(flashrom_get_region()==FLASHROM_REGION_EUROPE) {
vid_set_mode(DM_320x240_PAL,PM_RGB565);
} else {
vid_set_mode(DM_320x240_NTSC, PM_RGB565);
}
Post Reply