Code: Select all
#include "types.h"
#include "video.h"
#include "vga.h"
#include "screen.h"
#include "openbor.h"
#include "filecache.h"
static pvr_ptr_t screen;
static int width, height, bpp=0;
int video_set_mode(s_videomodes videomodes)
{
if(screen != NULL) return 1;
bpp = videomodes.pixel;
width = videomodes.hRes;
height = videomodes.vRes;
pvr_dma_init();
vid_init(DM_320x240, PM_RGB888);
screen = pvr_mem_malloc(width*height);
pvr_set_pal_format(PVR_PAL_ARGB8888);
return 1;
}
int video_copy_screen(s_screen* src)
{
pvr_poly_cxt_t cxt;
pvr_poly_hdr_t hdr;
pvr_vertex_t vert;
filecache_process();
pvr_scene_begin();
pvr_list_begin(PVR_LIST_OP_POLY);
pvr_txr_load_ex(src->data, screen, width, height, PVR_TXRLOAD_8BPP | PVR_TXRLOAD_FMT_TWIDDLED);
pvr_poly_cxt_txr(&cxt, PVR_LIST_OP_POLY, PVR_TXRFMT_PAL8BPP, 512, 512, screen, PVR_FILTER_NONE);
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.z = 0;
vert.u = 0;
vert.v = 0;
vert.flags = PVR_CMD_VERTEX;
vert.x = 0;
vert.y = height;
pvr_prim(&vert, sizeof(vert));
vert.x = 0;
vert.y = 0;
pvr_prim(&vert, sizeof(vert));
vert.x = width;
vert.y = height;
pvr_prim(&vert, sizeof(vert));
vert.x = width;
vert.y = 0;
vert.flags = PVR_CMD_VERTEX_EOL;
pvr_prim(&vert, sizeof(vert));
pvr_list_finish();
pvr_scene_finish();
return 1;
}
void video_clearscreen()
{
}
#define PACK_ARGB8888(a,r,g,b) ( ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF) )
void vga_setpalette(char* palette)
{
int i;
for (i = 0; i < 256; i++)
{
pvr_set_pal_entry(i, PACK_ARGB8888(0, palette[0], palette[1], palette[2]));
palette+=3;
}
}
void vga_vwait(void)
{
vid_waitvbl();
}
Now here is the same code running using the SDL library which works great.
Code: Select all
#include <SDL.h>
#include "types.h"
#include "video.h"
#include "vga.h"
#include "screen.h"
#include "openbor.h"
#include "filecache.h"
static SDL_Surface *screen = NULL;
static SDL_Color colors[256];
static int width=0, height=0, bpp=0, mode=0;
int video_set_mode(s_videomodes videomodes)
{
bpp = videomodes.pixel;
width = videomodes.hRes;
height = videomodes.vRes;
if(screen) SDL_FreeSurface(screen);
screen = SDL_SetVideoMode(width,height,8*bpp,SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_FULLSCREEN);
if(screen==NULL) return 0;
video_clearscreen();
SDL_ShowCursor(SDL_DISABLE);
return 1;
}
int video_copy_screen(s_screen* src)
{
filecache_process();
screen->pixels = src->data;
SDL_Flip(screen);
return 1;
}
void video_clearscreen()
{
memset(screen->pixels, 0, screen->pitch*screen->h);
}
void vga_setpalette(char* palette)
{
int i;
for(i=0;i<256;i++){
colors[i].r=palette[0];
colors[i].g=palette[1];
colors[i].b=palette[2];
palette+=3;
}
SDL_SetColors(screen,colors,0,256);
}
void video_fullscreen_flip()
{
}
void vga_vwait(void)
{
}