forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Blit 320x240 image to VRAM

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
ChaosKnight



Joined: 14 Apr 2005
Posts: 142
Location: Florida, USA

PostPosted: Fri Oct 07, 2005 4:30 am    Post subject: Blit 320x240 image to VRAM Reply with quote

I seem to be having some extraordinary difficulty doing something routinely simple. I need to take a 320*240*4 (ARGB but color is not important to me right now) and put it in the PSP's framebuffer. I've tried a number of differant ways (including nested for loops with 2d->1d conversion to make up for the 320 vs 480 thing.) Anyway, I'll stop babbling and show what i have that is not working. VideoInterrupt is called at 60Hz. Most of the code should be fairly straight-forward.
Code:
#include <pspgu.h>

#define DEBUG 0
#include "debug.h"

// Basilisk display configuration
#define BII_SCREEN_WIDTH 320
#define BII_SCREEN_HEIGHT 240
int Temp;
static uint32 PspFrameBuffer[BII_SCREEN_WIDTH * BII_SCREEN_HEIGHT];

/// Things from LUAPlayer's graphics.c
//#define SCREEN_WIDTH 480
//#define SCREEN_HEIGHT 272
//#define PSP_LINE_SIZE 512
#define SCREEN_WIDTH 320
#define SCREEN_HEIGHT 240
#define PSP_LINE_SIZE 512
#define FRAMEBUFFER_SIZE (PSP_LINE_SIZE*SCREEN_HEIGHT*2)
u16* g_vram_base = (u16*) (0x40000000 | 0x04000000);
typedef struct
{
        unsigned short u, v;
        unsigned short color;
        short x, y, z;
} Vertex;
static unsigned int __attribute__((aligned(16))) list[256];
static int dispBufferNumber;
typedef u16 Color;
Color* getVramDrawBuffer()
{
        Color* vram = (Color*) g_vram_base;
        if (dispBufferNumber == 0) vram += FRAMEBUFFER_SIZE / 2;
        return vram;
}
/// Things from LUAPlayer's graphics.c

/*
 *  Initialization
 */

bool VideoInit(bool classic)
{
   // Buffer
//   PspFrameBuffer = (uint32 *)malloc(BII_SCREEN_WIDTH * BII_SCREEN_HEIGHT * 4);
   
   // guInit - Taken from initGraphics() in graphics.c from LUAPlayer
        sceDisplaySetMode(0, SCREEN_WIDTH, SCREEN_HEIGHT);

        dispBufferNumber = 0;
        sceDisplayWaitVblankStart();
        sceDisplaySetFrameBuf((void*) g_vram_base, PSP_LINE_SIZE, 1, 1);

        sceGuInit();

        sceGuStart(GU_DIRECT, list);
        sceGuDrawBuffer(GU_PSM_8888, (void*)FRAMEBUFFER_SIZE, PSP_LINE_SIZE);
        sceGuDispBuffer(SCREEN_WIDTH, SCREEN_HEIGHT, (void*)0, PSP_LINE_SIZE);
        sceGuClear(GU_COLOR_BUFFER_BIT | GU_DEPTH_BUFFER_BIT);
        sceGuDepthBuffer((void*) 0x110000, PSP_LINE_SIZE);
        sceGuOffset(2048 - (SCREEN_WIDTH / 2), 2048 - (SCREEN_HEIGHT / 2));
        sceGuViewport(2048, 2048, SCREEN_WIDTH, SCREEN_HEIGHT);
        sceGuDepthRange(0xc350, 0x2710);
        sceGuScissor(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
        sceGuEnable(GU_SCISSOR_TEST);
        sceGuAlphaFunc(GU_GREATER, 0, 0xff);
        sceGuEnable(GU_ALPHA_TEST);
        sceGuDepthFunc(GU_GEQUAL);
        sceGuEnable(GU_DEPTH_TEST);
        sceGuFrontFace(GU_CW);
        sceGuShadeModel(GU_SMOOTH);
        sceGuEnable(GU_CULL_FACE);
        sceGuEnable(GU_TEXTURE_2D);
        sceGuTexMode(GU_PSM_8888, 0, 0, 0);
        sceGuTexFunc(GU_TFX_REPLACE, GU_TCC_RGBA);
        sceGuTexFilter(GU_NEAREST, GU_NEAREST);
        sceGuAmbientColor(0xffffffff);
        sceGuFinish();
        sceGuSync(0, 0);

        sceDisplayWaitVblankStart();
        sceGuDisplay(1);

   // Configure the Basilisk II framebuffer.
   VideoMonitor.x = BII_SCREEN_WIDTH;
   VideoMonitor.y = BII_SCREEN_HEIGHT;
   VideoMonitor.mode = VMODE_32BIT;
   VideoMonitor.bytes_per_row = SCREEN_WIDTH * 4;
   VideoMonitor.mac_frame_base = Host2MacAddr((uint8 *)PspFrameBuffer);

   // Done.
   D(bug("video "));
   return true;
}

void video_set_palette(unsigned char *p)
{
   D(bug("video_set_palette called\n"));
}

/*
 *  Deinitialization
 */

void VideoExit(void)
{
//   free(PspFrameBuffer);
   sceGuTerm();
}


/*
 *  Video message handling
 */

void VideoInterrupt(void)
{
   // blitImageToScreen(...) with some modifications.
        Color* vram = getVramDrawBuffer();
        sceKernelDcacheWritebackInvalidateAll();
        sceGuStart(GU_DIRECT,list);
        sceGuCopyImage(GU_PSM_8888, 0, 0, BII_SCREEN_WIDTH, BII_SCREEN_HEIGHT,
      SCREEN_WIDTH, PspFrameBuffer, 0, 0, PSP_LINE_SIZE, vram);
        sceGuFinish();
        sceGuSync(0,0);
   
   // flipScreen()
        sceGuSwapBuffers();
        sceDisplaySetFrameBuf(vram, PSP_LINE_SIZE, 1, 1);
        dispBufferNumber ^= 1;
}

_________________
w00t
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
Arwin



Joined: 12 Jul 2005
Posts: 426

PostPosted: Fri Oct 07, 2005 5:11 am    Post subject: Reply with quote

I'm an idiot at video on this level, I'm only just learning the basics and I barely understand them. But a guess still is still better than nothing ...

As far as I can tell, you're treating the PSP memory as 16bit (which is fine if that's what you want to use) but you're setting this for Basilisk:

VideoMonitor.mode = VMODE_32BIT;

Might that cause problems?
Back to top
View user's profile Send private message
ChaosKnight



Joined: 14 Apr 2005
Posts: 142
Location: Florida, USA

PostPosted: Fri Oct 07, 2005 5:19 am    Post subject: Reply with quote

Arwin wrote:
VideoMonitor.mode = VMODE_32BIT;

Might that cause problems?
Yes. It does, I noticed that and changed everything to 16 bit mode which is now crashing. Fun fun. It's weird how you can't just write these things to video memory and how you need the buffer to be 512 wide when only 480 of it is going to be used even though 480 is divisible by 16 just like 512.

-- EDIT --
Fixed it. I was telling basilisk i had a lot more memory than i was allocating.
Things seem to be working now ok. Still not perfect but then again what is?
_________________
w00t
Back to top
View user's profile Send private message AIM Address Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group