Copy Link
Add to Bookmark
Report

GP32 demo code (offscr)

sang's profile picture
Published in 
GP32
 · 4 Mar 2024

This simple demo demonstrates vertical scrolling using virtual screens and changing frame buffer pointers.

This demo bangs the hardware bypassing the BIOS (tested with 157e FW).

offscr.c

// (c) 13-Jul-2002 Jouni 'Mr.Spiv' Korhonen 
//

#include "gpdef.h"
#include "gpstdlib.h"
#include "gpgraphic.h"
#include "gpmain.h"
#include "gpfont.h"

#include <stdlib.h>
#include <string.h>

// strcoll, ptrdiff_t, memcmp, strspn strerror

GPDRAWSURFACE gpDraw;
GPDRAWTAG gpDrawTag;

volatile long* tpal = (long*)0x14a00050;
volatile long* lcdcon1 = (long*)0x14a00000;
volatile long* lcdcon2 = (long*)0x14a00004;
volatile long* lcdcon3 = (long*)0x14a00008;
volatile long* lcdcon4 = (long*)0x14a0000c;
volatile long* lcdcon5 = (long*)0x14a00010;

volatile long* lcdaddr1 = (long*)0x14a00014;
volatile long* lcdaddr2 = (long*)0x14a00018;
volatile long* lcdaddr3 = (long*)0x14a0001c;


volatile long* hwpal = (long*)0x14a00400;

extern unsigned char BK_Pic_c[];

//
//
//

void waitline( int line ) {
while (line != ((*lcdcon1 >> 18) & 0x1ff) );
}


//
//
//
//
//

void GpMain(void *arg)
{
long scrptru;
long scrptrl, scrptrl2;
long ptr;
char buf[100];
int m,n;

unsigned short *dst;
unsigned short *src;


volatile unsigned long *gpb = (unsigned long *)0x1560000c;
volatile unsigned long *gpe = (unsigned long *)0x15600030;

//

//GpGraphicModeSet(GPC_DFLAG_16BPP,NULL);
//*lcdcon5 |= 1;
//GpLcdSurfaceGet(&gpDraw, 0);
//GpRectFill(NULL, &gpDraw, 0, 0, gpDraw.buf_w, gpDraw.buf_h, 0x01);

//
//dst = (unsigned short*)gpDraw.ptbuffer;
dst = (unsigned short*)0x0C7B4000;
src = (unsigned short*)BK_Pic_c;

for (m = 0; m < 320; m++) {
for (n = 0; n < 240; n++) {
*dst++ = *src++;
}
for (n = 0; n < 240; n++) {
*dst = dst[-240];
dst++;
}
}


//gm_sprintf(buf,"src: %08x, dst: %08x",src,dst);
//GpTextOut(NULL,&gpDraw,10,120,buf,0xaa);


//GpSurfaceSet(&gpDraw); //gpDraw primary surface· setting

// 320x240x16 screen mode, 0 pixel offscreen
// expects 33MHz HCLK
#if 1
*lcdcon1 = ((3 << 8) | (0 << 7) | (3 << 5) | (12 << 1) | (0));
// CLKVAL=3, VNMODE=0, PNRMODE=TFT, BPPMODE=1100 (16bits), ENDID=0
*lcdcon2 = ((1 << 24) | (319 << 14) | (2 << 6) | 1);
// VBPD=1, LINEVAL=319, VFPD=2, VSPW=1
*lcdcon3 = ((6 << 19) | (239 << 8) | (2));
// HBPD=6, HOZVAL=239, HFPD=2
*lcdcon4 = ((0 << 24) | (0 << 16) | (4));
// PALADDEN=0, ADDVAL=0, HSPW=4
*lcdcon5 = ((1 << 10) | (1 << 9) | (1 << 8) | (0 << 7) | (0 << 6) | (0 << 4) | (0 << 2) | (1));
// INVVCLK=1, INVVLINE=1, INVVFRAME=1, INVVD=0, INVVDEN=0
// INVENDLINE=0, ENLEND=0, BSWP=0, HWSWP=1
*tpal = 0;

ptr = (long)0x0C7B4000;
*lcdaddr1 = ((ptr & 0x0fc00000) >> 1) | ((ptr & 0x3ffffe) >> 1);
*lcdaddr2 = ((ptr & 0x003ffffe) >> 1) + (240+240) * (319+1);

*lcdaddr3 = ((240 << 11) | (240));
// OFFSIZE=0, PAGEWIDTH=240 halfwords -> 240 pixels

*lcdcon1 |= 1; // enable lcd
#endif


//
scrptru = *lcdaddr1;
//scrptrl = *lcdaddr2;
//scrptrl = *lcdaddr2 - 240;
//scrptrl = *lcdaddr2 - 240*2;
scrptrl = *lcdaddr2;

n = 0;
m = 0;

while ((GpKeyGet() & (GPC_VK_FL | GPC_VK_FR)) != (GPC_VK_FL | GPC_VK_FR)) {
long reg, reg2;

waitline(2);

if (n++ == 240) {
*lcdaddr1 = scrptru;
*lcdaddr2 = scrptrl;
n = 0;
} else {
*lcdaddr1 += 1;
*lcdaddr2 += 1;
}

waitline(1);


}


*tpal = 0x0001ffff;
// reboot..

while ((GpKeyGet() & (GPC_VK_SELECT | GPC_VK_START)) != (GPC_VK_SELECT | GPC_VK_START));
GpAppExit();
}

← previous
next →
loading
sending ...
New to Neperos ? Sign Up for free
download Neperos App from Google Play
install Neperos as PWA

Let's discover also

Recent Articles

Recent Comments

Neperos cookies
This website uses cookies to store your preferences and improve the service. Cookies authorization will allow me and / or my partners to process personal data such as browsing behaviour.

By pressing OK you agree to the Terms of Service and acknowledge the Privacy Policy

By pressing REJECT you will be able to continue to use Neperos (like read articles or write comments) but some important cookies will not be set. This may affect certain features and functions of the platform.
OK
REJECT