mirror of
https://github.com/RaySollium99/libpicofe.git
synced 2025-09-05 06:47:45 -04:00
initial import
git-svn-id: file:///home/notaz/opt/svn/PicoDrive/platform@2 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
commit
720ee7f624
36 changed files with 6740 additions and 0 deletions
112
linux/940ctl_ym2612.c
Normal file
112
linux/940ctl_ym2612.c
Normal file
|
@ -0,0 +1,112 @@
|
|||
/* faked 940 code just uses local copy of ym2612 */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../../Pico/sound/ym2612.h"
|
||||
#include "../gp2x/gp2x.h"
|
||||
#include "../gp2x/emu.h"
|
||||
#include "../gp2x/menu.h"
|
||||
|
||||
|
||||
static YM2612 ym2612;
|
||||
|
||||
YM2612 *ym2612_940 = &ym2612;
|
||||
int mix_buffer_[44100/50*2]; /* this is where the YM2612 samples will be mixed to */
|
||||
int *mix_buffer = mix_buffer_;
|
||||
|
||||
|
||||
/***********************************************************/
|
||||
|
||||
#define MAXOUT (+32767)
|
||||
#define MINOUT (-32768)
|
||||
|
||||
/* limitter */
|
||||
#define Limit(val, max,min) { \
|
||||
if ( val > max ) val = max; \
|
||||
else if ( val < min ) val = min; \
|
||||
}
|
||||
|
||||
|
||||
int YM2612Write_940(unsigned int a, unsigned int v)
|
||||
{
|
||||
YM2612Write_(a, v);
|
||||
|
||||
return 0; // cause the engine to do updates once per frame only
|
||||
}
|
||||
|
||||
UINT8 YM2612Read_940(void)
|
||||
{
|
||||
return YM2612Read_();
|
||||
}
|
||||
|
||||
|
||||
int YM2612PicoTick_940(int n)
|
||||
{
|
||||
YM2612PicoTick_(n);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void YM2612PicoStateLoad_940(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
YM2612PicoStateLoad_();
|
||||
|
||||
for(i = 0; i < 0x100; i++) {
|
||||
YM2612Write_(0, i);
|
||||
YM2612Write_(1, ym2612.REGS[i]);
|
||||
}
|
||||
for(i = 0; i < 0x100; i++) {
|
||||
YM2612Write_(2, i);
|
||||
YM2612Write_(3, ym2612.REGS[i|0x100]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void YM2612Init_940(int baseclock, int rate)
|
||||
{
|
||||
YM2612Init_(baseclock, rate);
|
||||
}
|
||||
|
||||
|
||||
void YM2612ResetChip_940(void)
|
||||
{
|
||||
YM2612ResetChip_();
|
||||
}
|
||||
|
||||
|
||||
void YM2612UpdateOne_940(short *buffer, int length, int stereo)
|
||||
{
|
||||
int i;
|
||||
|
||||
YM2612UpdateOne_(buffer, length, stereo);
|
||||
|
||||
/* mix data */
|
||||
if (stereo) {
|
||||
int *mb = mix_buffer;
|
||||
for (i = length; i > 0; i--) {
|
||||
int l, r;
|
||||
l = r = *buffer;
|
||||
l += *mb++, r += *mb++;
|
||||
Limit( l, MAXOUT, MINOUT );
|
||||
Limit( r, MAXOUT, MINOUT );
|
||||
*buffer++ = l; *buffer++ = r;
|
||||
}
|
||||
} else {
|
||||
for (i = 0; i < length; i++) {
|
||||
int l = mix_buffer[i];
|
||||
l += buffer[i];
|
||||
Limit( l, MAXOUT, MINOUT );
|
||||
buffer[i] = l;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
91
linux/Makefile
Normal file
91
linux/Makefile
Normal file
|
@ -0,0 +1,91 @@
|
|||
|
||||
# settings
|
||||
dprint = 1
|
||||
# profile = 1
|
||||
|
||||
|
||||
DEFINC = -I../.. -I. -D__GP2X__ -D_UNZIP_SUPPORT # -DBENCHMARK
|
||||
GCC = gcc
|
||||
STRIP = strip
|
||||
AS = gcc
|
||||
|
||||
ifeq "$(profile)" "1"
|
||||
COPT_COMMON = -s -O3 -ftracer -fstrength-reduce -Wall -funroll-loops -fomit-frame-pointer -fstrict-aliasing -ffast-math -fprofile-generate # -static
|
||||
COPT = $(COPT_COMMON) # -mtune=arm920t
|
||||
else
|
||||
COPT = -ggdb -Wall -fno-strict-aliasing # -pg -O3 -ftracer -fstrength-reduce -funroll-loops -fomit-frame-pointer -ffast-math
|
||||
COPT_COMMON = $(COPT)
|
||||
endif
|
||||
|
||||
# gtk
|
||||
COPT += `pkg-config --cflags gtk+-2.0`
|
||||
LDFLAGS += `pkg-config --libs gtk+-2.0`
|
||||
COPT += `pkg-config --cflags gthread-2.0`
|
||||
LDFLAGS += `pkg-config --libs gthread-2.0`
|
||||
|
||||
# frontend
|
||||
OBJS += ../gp2x/main.o ../gp2x/menu.o ../gp2x/emu.o ../gp2x/usbjoy.o blit.o gp2x.o 940ctl_ym2612.o
|
||||
# Pico
|
||||
OBJS += ../../Pico/Area.o ../../Pico/Cart.o ../../Pico/Utils.o ../../Pico/Memory.o ../../Pico/Misc.o \
|
||||
../../Pico/Pico.o ../../Pico/Sek.o ../../Pico/VideoPort.o ../../Pico/Draw2.o ../../Pico/Draw.o
|
||||
# Pico - CD
|
||||
OBJS += ../../Pico/cd/Pico.o ../../Pico/cd/Memory.o ../../Pico/cd/Sek.o ../../Pico/cd/LC89510.o \
|
||||
../../Pico/cd/cd_sys.o
|
||||
# Pico - sound
|
||||
OBJS += ../../Pico/sound/sound.o ../../Pico/sound/sn76496.o ../../Pico/sound/ym2612.o
|
||||
# zlib
|
||||
OBJS += ../../zlib/gzio.o ../../zlib/inffast.o ../../zlib/inflate.o ../../zlib/inftrees.o ../../zlib/trees.o \
|
||||
../../zlib/deflate.o ../../zlib/crc32.o ../../zlib/adler32.o ../../zlib/zutil.o ../../zlib/compress.o
|
||||
# unzip
|
||||
OBJS += ../../unzip/unzip.o
|
||||
# CPU cores
|
||||
DEFINC += -DEMU_M68K
|
||||
OBJS += ../../cpu/musashi/m68kcpu.o ../../cpu/musashi/m68kopac.o ../../cpu/musashi/m68kopdm.o \
|
||||
../../cpu/musashi/m68kopnz.o ../../cpu/musashi/m68kops.o
|
||||
# mz80
|
||||
DEFINC += -D_USE_MZ80
|
||||
OBJS += ../../cpu/mz80/mz80.o
|
||||
|
||||
# faked asm
|
||||
#DEFINC += -D_ASM_DRAW_C
|
||||
#DEFINC += -D_ASM_MEMORY_C
|
||||
#DEFINC += -D_ASM_YM2612_C
|
||||
OBJS += fakedasm.o
|
||||
|
||||
|
||||
all: PicoDrive
|
||||
clean: tidy
|
||||
@$(RM) PicoDrive
|
||||
tidy:
|
||||
@$(RM) $(OBJS)
|
||||
@make -C ../../cpu/mz80/ clean
|
||||
|
||||
PicoDrive : $(OBJS)
|
||||
@echo $@
|
||||
@$(GCC) $(COPT) $(OBJS) $(LDFLAGS) -lm -o $@
|
||||
|
||||
|
||||
../../cpu/mz80/mz80.o : ../../cpu/mz80/mz80.asm
|
||||
@echo $@
|
||||
@nasm -f elf $< -o $@
|
||||
|
||||
../../cpu/mz80/mz80.asm :
|
||||
@make -C ../../cpu/mz80/
|
||||
|
||||
.c.o:
|
||||
@echo $<
|
||||
@$(GCC) $(COPT) $(DEFINC) -c $< -o $@
|
||||
.s.o:
|
||||
@echo $<
|
||||
@$(GCC) $(COPT) $(DEFINC) -c $< -o $@
|
||||
|
||||
|
||||
../../Pico/sound/ym2612.o : ../../Pico/sound/ym2612.c
|
||||
@echo $@
|
||||
@$(GCC) $(COPT_COMMON) $(DEFINC) -DEXTERNAL_YM2612 -c $< -o $@ # -mtune=arm940t
|
||||
|
||||
# faked asm
|
||||
../../Pico/Draw.o : ../../Pico/Draw.c
|
||||
@echo $<
|
||||
@$(GCC) $(COPT) $(DEFINC) -D_ASM_DRAW_C -c $< -o $@
|
||||
|
4
linux/README
Normal file
4
linux/README
Normal file
|
@ -0,0 +1,4 @@
|
|||
This port tries to emulate gp2x environment on a standard linux box for testing
|
||||
(i.e. to be able to use things like valgrind and efence, gcc runtime
|
||||
optimizations, etc.).
|
||||
|
81
linux/blit.c
Normal file
81
linux/blit.c
Normal file
|
@ -0,0 +1,81 @@
|
|||
|
||||
// Convert 0000bbb0 ggg0rrr0 0000bbb0 ggg0rrr0
|
||||
// to 00000000 rrr00000 ggg00000 bbb00000 ...
|
||||
|
||||
void vidConvCpyRGB32 (void *to, void *from, int pixels)
|
||||
{
|
||||
unsigned short *ps = from;
|
||||
unsigned int *pd = to;
|
||||
|
||||
for (; pixels; pixels--, ps++, pd++)
|
||||
{
|
||||
*pd = ((*ps<<20)&0xe00000) | ((*ps<<8)&0xe000) | ((*ps>>4)&0xe0);
|
||||
*pd |= *pd >> 3;
|
||||
}
|
||||
}
|
||||
|
||||
void vidConvCpyRGB32sh(void *to, void *from, int pixels)
|
||||
{
|
||||
unsigned short *ps = from;
|
||||
unsigned int *pd = to;
|
||||
|
||||
for (; pixels; pixels--, ps++, pd++)
|
||||
{
|
||||
*pd = ((*ps<<20)&0xe00000) | ((*ps<<8)&0xe000) | ((*ps>>4)&0xe0);
|
||||
*pd >>= 1;
|
||||
*pd |= *pd >> 3;
|
||||
}
|
||||
}
|
||||
|
||||
void vidConvCpyRGB32hi(void *to, void *from, int pixels)
|
||||
{
|
||||
unsigned short *ps = from;
|
||||
unsigned int *pd = to;
|
||||
|
||||
for (; pixels; pixels--, ps++, pd++)
|
||||
{
|
||||
*pd = ((*ps<<20)&0xe00000) | ((*ps<<8)&0xe000) | ((*ps>>4)&0xe0);
|
||||
continue;
|
||||
*pd += 0x00404040;
|
||||
if (*pd & 0x01000000) *pd |= 0x00e00000;
|
||||
if (*pd & 0x00010000) *pd |= 0x0000e000;
|
||||
if (*pd & 0x00000100) *pd |= 0x000000e0;
|
||||
*pd &= 0x00e0e0e0;
|
||||
*pd |= *pd >> 3;
|
||||
}
|
||||
}
|
||||
|
||||
void vidCpyM2_40col(void *dest, void *src)
|
||||
{
|
||||
unsigned char *pd = dest, *ps = src;
|
||||
int i, u;
|
||||
|
||||
for (i = 0; i < 224; i++)
|
||||
{
|
||||
ps += 8;
|
||||
for (u = 0; u < 320; u++)
|
||||
*pd++ = *ps++;
|
||||
}
|
||||
}
|
||||
|
||||
void vidCpyM2_32col(void *dest, void *src)
|
||||
{
|
||||
unsigned char *pd = dest, *ps = src;
|
||||
int i, u;
|
||||
|
||||
for (i = 0; i < 224; i++)
|
||||
{
|
||||
ps += 8;
|
||||
pd += 32;
|
||||
for (u = 0; u < 256; u++)
|
||||
*pd++ = *ps++;
|
||||
ps += 64;
|
||||
pd += 32;
|
||||
}
|
||||
}
|
||||
|
||||
void vidCpyM2_32col_nobord(void *dest, void *src)
|
||||
{
|
||||
vidCpyM2_32col(dest, src);
|
||||
}
|
||||
|
667
linux/fakedasm.c
Normal file
667
linux/fakedasm.c
Normal file
|
@ -0,0 +1,667 @@
|
|||
// This is part of Pico Library
|
||||
|
||||
// (c) Copyright 2004 Dave, All rights reserved.
|
||||
// (c) Copyright 2006 notaz, All rights reserved.
|
||||
// Free for non-commercial use.
|
||||
|
||||
// For commercial use, separate licencing terms must be obtained.
|
||||
|
||||
|
||||
#include "../../Pico/PicoInt.h"
|
||||
#undef blockcpy
|
||||
|
||||
extern unsigned short DefOutBuff[320*2];
|
||||
extern unsigned char HighCol[8+320+8];
|
||||
extern char HighSprZ[320+8+8]; // Z-buffer for accurate sprites and shadow/hilight mode
|
||||
// (if bit 7 == 0, sh caused by tile; if bit 6 == 0 pixel must be shadowed, else hilighted, if bit5 == 1)
|
||||
// lsb->msb: moved sprites, all window tiles don't use same priority, accurate sprites (copied from PicoOpt), interlace
|
||||
// dirty sprites, sonic mode
|
||||
extern int rendstatus;
|
||||
extern int Scanline; // Scanline
|
||||
|
||||
|
||||
struct TileStrip
|
||||
{
|
||||
int nametab; // Position in VRAM of name table (for this tile line)
|
||||
int line; // Line number in pixels 0x000-0x3ff within the virtual tilemap
|
||||
int hscroll; // Horizontal scroll value in pixels for the line
|
||||
int xmask; // X-Mask (0x1f - 0x7f) for horizontal wraparound in the tilemap
|
||||
int *hc; // cache for high tile codes and their positions
|
||||
int cells; // cells (tiles) to draw (32 col mode doesn't need to update whole 320)
|
||||
};
|
||||
|
||||
// utility
|
||||
void *blockcpy(void *dst, const void *src, size_t n)
|
||||
{
|
||||
return memcpy(dst, src, n);
|
||||
}
|
||||
|
||||
void blockcpy_or(void *dst, void *src, size_t n, int pat)
|
||||
{
|
||||
unsigned char *pd = dst, *ps = src;
|
||||
for (; n; n--)
|
||||
*pd++ = (unsigned char) (*ps++ | pat);
|
||||
}
|
||||
|
||||
|
||||
static int TileNorm(int sx,int addr,int pal)
|
||||
{
|
||||
unsigned char *pd = HighCol+sx;
|
||||
unsigned int pack=0; unsigned int t=0;
|
||||
|
||||
pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
|
||||
if (pack)
|
||||
{
|
||||
t=pack&0x0000f000; if (t) pd[0]=(unsigned char)(pal|(t>>12));
|
||||
t=pack&0x00000f00; if (t) pd[1]=(unsigned char)(pal|(t>> 8));
|
||||
t=pack&0x000000f0; if (t) pd[2]=(unsigned char)(pal|(t>> 4));
|
||||
t=pack&0x0000000f; if (t) pd[3]=(unsigned char)(pal|(t ));
|
||||
t=pack&0xf0000000; if (t) pd[4]=(unsigned char)(pal|(t>>28));
|
||||
t=pack&0x0f000000; if (t) pd[5]=(unsigned char)(pal|(t>>24));
|
||||
t=pack&0x00f00000; if (t) pd[6]=(unsigned char)(pal|(t>>20));
|
||||
t=pack&0x000f0000; if (t) pd[7]=(unsigned char)(pal|(t>>16));
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1; // Tile blank
|
||||
}
|
||||
|
||||
static int TileFlip(int sx,int addr,int pal)
|
||||
{
|
||||
unsigned char *pd = HighCol+sx;
|
||||
unsigned int pack=0; unsigned int t=0;
|
||||
|
||||
pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
|
||||
if (pack)
|
||||
{
|
||||
t=pack&0x000f0000; if (t) pd[0]=(unsigned char)(pal|(t>>16));
|
||||
t=pack&0x00f00000; if (t) pd[1]=(unsigned char)(pal|(t>>20));
|
||||
t=pack&0x0f000000; if (t) pd[2]=(unsigned char)(pal|(t>>24));
|
||||
t=pack&0xf0000000; if (t) pd[3]=(unsigned char)(pal|(t>>28));
|
||||
t=pack&0x0000000f; if (t) pd[4]=(unsigned char)(pal|(t ));
|
||||
t=pack&0x000000f0; if (t) pd[5]=(unsigned char)(pal|(t>> 4));
|
||||
t=pack&0x00000f00; if (t) pd[6]=(unsigned char)(pal|(t>> 8));
|
||||
t=pack&0x0000f000; if (t) pd[7]=(unsigned char)(pal|(t>>12));
|
||||
return 0;
|
||||
}
|
||||
return 1; // Tile blank
|
||||
}
|
||||
|
||||
|
||||
// tile renderers for hacky operator sprite support
|
||||
#define sh_pix(x) \
|
||||
if(!t); \
|
||||
else if(t==0xe) pd[x]=(unsigned char)((pd[x]&0x3f)|0x80); /* hilight */ \
|
||||
else if(t==0xf) pd[x]=(unsigned char)((pd[x]&0x3f)|0xc0); /* shadow */ \
|
||||
else pd[x]=(unsigned char)(pal|t);
|
||||
|
||||
static int TileNormSH(int sx,int addr,int pal)
|
||||
{
|
||||
unsigned int pack=0; unsigned int t=0;
|
||||
unsigned char *pd = HighCol+sx;
|
||||
|
||||
pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
|
||||
if (pack)
|
||||
{
|
||||
t=(pack&0x0000f000)>>12; sh_pix(0);
|
||||
t=(pack&0x00000f00)>> 8; sh_pix(1);
|
||||
t=(pack&0x000000f0)>> 4; sh_pix(2);
|
||||
t=(pack&0x0000000f) ; sh_pix(3);
|
||||
t=(pack&0xf0000000)>>28; sh_pix(4);
|
||||
t=(pack&0x0f000000)>>24; sh_pix(5);
|
||||
t=(pack&0x00f00000)>>20; sh_pix(6);
|
||||
t=(pack&0x000f0000)>>16; sh_pix(7);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 1; // Tile blank
|
||||
}
|
||||
|
||||
static int TileFlipSH(int sx,int addr,int pal)
|
||||
{
|
||||
unsigned int pack=0; unsigned int t=0;
|
||||
unsigned char *pd = HighCol+sx;
|
||||
|
||||
pack=*(unsigned int *)(Pico.vram+addr); // Get 8 pixels
|
||||
if (pack)
|
||||
{
|
||||
t=(pack&0x000f0000)>>16; sh_pix(0);
|
||||
t=(pack&0x00f00000)>>20; sh_pix(1);
|
||||
t=(pack&0x0f000000)>>24; sh_pix(2);
|
||||
t=(pack&0xf0000000)>>28; sh_pix(3);
|
||||
t=(pack&0x0000000f) ; sh_pix(4);
|
||||
t=(pack&0x000000f0)>> 4; sh_pix(5);
|
||||
t=(pack&0x00000f00)>> 8; sh_pix(6);
|
||||
t=(pack&0x0000f000)>>12; sh_pix(7);
|
||||
return 0;
|
||||
}
|
||||
return 1; // Tile blank
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
static void DrawStrip(struct TileStrip *ts, int sh)
|
||||
{
|
||||
int tilex=0,dx=0,ty=0,code=0,addr=0,cells;
|
||||
int oldcode=-1,blank=-1; // The tile we know is blank
|
||||
int pal=0;
|
||||
|
||||
// Draw tiles across screen:
|
||||
tilex=(-ts->hscroll)>>3;
|
||||
ty=(ts->line&7)<<1; // Y-Offset into tile
|
||||
dx=((ts->hscroll-1)&7)+1;
|
||||
cells = ts->cells;
|
||||
if(dx != 8) cells++; // have hscroll, need to draw 1 cell more
|
||||
|
||||
for (; cells; dx+=8,tilex++,cells--)
|
||||
{
|
||||
int zero=0;
|
||||
|
||||
code=Pico.vram[ts->nametab+(tilex&ts->xmask)];
|
||||
if (code==blank) continue;
|
||||
if (code>>15) { // high priority tile
|
||||
int cval = code | (dx<<16) | (ty<<25);
|
||||
if(code&0x1000) cval^=7<<26;
|
||||
*ts->hc++ = cval; // cache it
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code!=oldcode) {
|
||||
oldcode = code;
|
||||
// Get tile address/2:
|
||||
addr=(code&0x7ff)<<4;
|
||||
addr+=ty;
|
||||
if (code&0x1000) addr^=0xe; // Y-flip
|
||||
|
||||
// pal=Pico.cram+((code>>9)&0x30);
|
||||
pal=((code>>9)&0x30)|(sh<<6);
|
||||
}
|
||||
|
||||
if (code&0x0800) zero=TileFlip(dx,addr,pal);
|
||||
else zero=TileNorm(dx,addr,pal);
|
||||
|
||||
if (zero) blank=code; // We know this tile is blank now
|
||||
}
|
||||
|
||||
// terminate the cache list
|
||||
*ts->hc = 0;
|
||||
}
|
||||
|
||||
static void DrawStripVSRam(struct TileStrip *ts, int plane)
|
||||
{
|
||||
int tilex=0,dx=0,ty=0,code=0,addr=0,cell=0,nametabadd=0;
|
||||
int oldcode=-1,blank=-1; // The tile we know is blank
|
||||
int pal=0,scan=Scanline;
|
||||
|
||||
// Draw tiles across screen:
|
||||
tilex=(-ts->hscroll)>>3;
|
||||
dx=((ts->hscroll-1)&7)+1;
|
||||
if(dx != 8) {
|
||||
int vscroll, line;
|
||||
cell--; // have hscroll, start with negative cell
|
||||
// also calculate intial VS stuff
|
||||
vscroll=Pico.vsram[plane];
|
||||
|
||||
// Find the line in the name table
|
||||
line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask ..
|
||||
nametabadd=(line>>3)<<(ts->line>>24); // .. and shift[width]
|
||||
ty=(line&7)<<1; // Y-Offset into tile
|
||||
}
|
||||
|
||||
for (; cell < ts->cells; dx+=8,tilex++,cell++)
|
||||
{
|
||||
int zero=0;
|
||||
|
||||
if((cell&1)==0) {
|
||||
int line,vscroll;
|
||||
vscroll=Pico.vsram[plane+(cell&~1)];
|
||||
|
||||
// Find the line in the name table
|
||||
line=(vscroll+scan)&ts->line&0xffff; // ts->line is really ymask ..
|
||||
nametabadd=(line>>3)<<(ts->line>>24); // .. and shift[width]
|
||||
ty=(line&7)<<1; // Y-Offset into tile
|
||||
}
|
||||
|
||||
code=Pico.vram[ts->nametab+nametabadd+(tilex&ts->xmask)];
|
||||
if (code==blank) continue;
|
||||
if (code>>15) { // high priority tile
|
||||
int cval = code | (dx<<16) | (ty<<25);
|
||||
if(code&0x1000) cval^=7<<26;
|
||||
*ts->hc++ = cval; // cache it
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code!=oldcode) {
|
||||
oldcode = code;
|
||||
// Get tile address/2:
|
||||
addr=(code&0x7ff)<<4;
|
||||
if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
|
||||
|
||||
// pal=Pico.cram+((code>>9)&0x30);
|
||||
pal=((code>>9)&0x30);
|
||||
}
|
||||
|
||||
if (code&0x0800) zero=TileFlip(dx,addr,pal);
|
||||
else zero=TileNorm(dx,addr,pal);
|
||||
|
||||
if (zero) blank=code; // We know this tile is blank now
|
||||
}
|
||||
|
||||
// terminate the cache list
|
||||
*ts->hc = 0;
|
||||
}
|
||||
|
||||
static void DrawStripInterlace(struct TileStrip *ts)
|
||||
{
|
||||
int tilex=0,dx=0,ty=0,code=0,addr=0,cells;
|
||||
int oldcode=-1,blank=-1; // The tile we know is blank
|
||||
int pal=0;
|
||||
|
||||
// Draw tiles across screen:
|
||||
tilex=(-ts->hscroll)>>3;
|
||||
ty=(ts->line&15)<<1; // Y-Offset into tile
|
||||
dx=((ts->hscroll-1)&7)+1;
|
||||
cells = ts->cells;
|
||||
if(dx != 8) cells++; // have hscroll, need to draw 1 cell more
|
||||
|
||||
for (; cells; dx+=8,tilex++,cells--)
|
||||
{
|
||||
int zero=0;
|
||||
|
||||
code=Pico.vram[ts->nametab+(tilex&ts->xmask)];
|
||||
if (code==blank) continue;
|
||||
if (code>>15) { // high priority tile
|
||||
int cval = (code&0xfc00) | (dx<<16) | (ty<<25);
|
||||
cval|=(code&0x3ff)<<1;
|
||||
if(code&0x1000) cval^=0xf<<26;
|
||||
*ts->hc++ = cval; // cache it
|
||||
continue;
|
||||
}
|
||||
|
||||
if (code!=oldcode) {
|
||||
oldcode = code;
|
||||
// Get tile address/2:
|
||||
addr=(code&0x7ff)<<5;
|
||||
if (code&0x1000) addr+=30-ty; else addr+=ty; // Y-flip
|
||||
|
||||
// pal=Pico.cram+((code>>9)&0x30);
|
||||
pal=((code>>9)&0x30);
|
||||
}
|
||||
|
||||
if (code&0x0800) zero=TileFlip(dx,addr,pal);
|
||||
else zero=TileNorm(dx,addr,pal);
|
||||
|
||||
if (zero) blank=code; // We know this tile is blank now
|
||||
}
|
||||
|
||||
// terminate the cache list
|
||||
*ts->hc = 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
void DrawLayer(int plane, int *hcache, int maxcells, int sh)
|
||||
{
|
||||
struct PicoVideo *pvid=&Pico.video;
|
||||
const char shift[4]={5,6,5,7}; // 32,64 or 128 sized tilemaps (2 is invalid)
|
||||
struct TileStrip ts;
|
||||
int width, height, ymask;
|
||||
int vscroll, htab;
|
||||
|
||||
ts.hc=hcache;
|
||||
ts.cells=maxcells;
|
||||
|
||||
// Work out the TileStrip to draw
|
||||
|
||||
// Work out the name table size: 32 64 or 128 tiles (0-3)
|
||||
width=pvid->reg[16];
|
||||
height=(width>>4)&3; width&=3;
|
||||
|
||||
ts.xmask=(1<<shift[width])-1; // X Mask in tiles (0x1f-0x7f)
|
||||
ymask=(height<<8)|0xff; // Y Mask in pixels
|
||||
if(width == 1) ymask&=0x1ff;
|
||||
else if(width>1) ymask =0x0ff;
|
||||
|
||||
// Find name table:
|
||||
if (plane==0) ts.nametab=(pvid->reg[2]&0x38)<< 9; // A
|
||||
else ts.nametab=(pvid->reg[4]&0x07)<<12; // B
|
||||
|
||||
htab=pvid->reg[13]<<9; // Horizontal scroll table address
|
||||
if ( pvid->reg[11]&2) htab+=Scanline<<1; // Offset by line
|
||||
if ((pvid->reg[11]&1)==0) htab&=~0xf; // Offset by tile
|
||||
htab+=plane; // A or B
|
||||
|
||||
// Get horizontal scroll value, will be masked later
|
||||
ts.hscroll=Pico.vram[htab&0x7fff];
|
||||
|
||||
if((pvid->reg[12]&6) == 6) {
|
||||
// interlace mode 2
|
||||
vscroll=Pico.vsram[plane]; // Get vertical scroll value
|
||||
|
||||
// Find the line in the name table
|
||||
ts.line=(vscroll+(Scanline<<1))&((ymask<<1)|1);
|
||||
ts.nametab+=(ts.line>>4)<<shift[width];
|
||||
|
||||
DrawStripInterlace(&ts);
|
||||
} else if( pvid->reg[11]&4) {
|
||||
// shit, we have 2-cell column based vscroll
|
||||
// luckily this doesn't happen too often
|
||||
ts.line=ymask|(shift[width]<<24); // save some stuff instead of line
|
||||
DrawStripVSRam(&ts, plane);
|
||||
} else {
|
||||
vscroll=Pico.vsram[plane]; // Get vertical scroll value
|
||||
|
||||
// Find the line in the name table
|
||||
ts.line=(vscroll+Scanline)&ymask;
|
||||
ts.nametab+=(ts.line>>3)<<shift[width];
|
||||
|
||||
DrawStrip(&ts, sh);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
// tstart & tend are tile pair numbers
|
||||
void DrawWindow(int tstart, int tend, int prio, int sh) // int *hcache
|
||||
{
|
||||
struct PicoVideo *pvid=&Pico.video;
|
||||
int tilex=0,ty=0,nametab,code=0;
|
||||
int blank=-1; // The tile we know is blank
|
||||
|
||||
// Find name table line:
|
||||
if (pvid->reg[12]&1)
|
||||
{
|
||||
nametab=(pvid->reg[3]&0x3c)<<9; // 40-cell mode
|
||||
nametab+=(Scanline>>3)<<6;
|
||||
}
|
||||
else
|
||||
{
|
||||
nametab=(pvid->reg[3]&0x3e)<<9; // 32-cell mode
|
||||
nametab+=(Scanline>>3)<<5;
|
||||
}
|
||||
|
||||
tilex=tstart<<1;
|
||||
tend<<=1;
|
||||
|
||||
ty=(Scanline&7)<<1; // Y-Offset into tile
|
||||
|
||||
if(!(rendstatus&2)) {
|
||||
// check the first tile code
|
||||
code=Pico.vram[nametab+tilex];
|
||||
// if the whole window uses same priority (what is often the case), we may be able to skip this field
|
||||
if((code>>15) != prio) return;
|
||||
}
|
||||
|
||||
// Draw tiles across screen:
|
||||
for (; tilex < tend; tilex++)
|
||||
{
|
||||
int addr=0,zero=0;
|
||||
int pal;
|
||||
|
||||
code=Pico.vram[nametab+tilex];
|
||||
if(code==blank) continue;
|
||||
if((code>>15) != prio) {
|
||||
rendstatus|=2;
|
||||
continue;
|
||||
}
|
||||
|
||||
pal=((code>>9)&0x30);
|
||||
|
||||
if(sh) {
|
||||
int tmp, *zb = (int *)(HighCol+8+(tilex<<3));
|
||||
if(prio) {
|
||||
tmp = *zb;
|
||||
if(!(tmp&0x00000080)) tmp&=~0x000000c0; if(!(tmp&0x00008000)) tmp&=~0x0000c000;
|
||||
if(!(tmp&0x00800000)) tmp&=~0x00c00000; if(!(tmp&0x80000000)) tmp&=~0xc0000000;
|
||||
*zb++=tmp; tmp = *zb;
|
||||
if(!(tmp&0x00000080)) tmp&=~0x000000c0; if(!(tmp&0x00008000)) tmp&=~0x0000c000;
|
||||
if(!(tmp&0x00800000)) tmp&=~0x00c00000; if(!(tmp&0x80000000)) tmp&=~0xc0000000;
|
||||
*zb++=tmp;
|
||||
} else {
|
||||
pal |= 0x40;
|
||||
}
|
||||
}
|
||||
|
||||
// Get tile address/2:
|
||||
addr=(code&0x7ff)<<4;
|
||||
if (code&0x1000) addr+=14-ty; else addr+=ty; // Y-flip
|
||||
|
||||
if (code&0x0800) zero=TileFlip(8+(tilex<<3),addr,pal);
|
||||
else zero=TileNorm(8+(tilex<<3),addr,pal);
|
||||
|
||||
if (zero) blank=code; // We know this tile is blank now
|
||||
}
|
||||
|
||||
// terminate the cache list
|
||||
//*hcache = 0;
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
void DrawTilesFromCache(int *hc, int sh)
|
||||
{
|
||||
int code, addr, zero, dx;
|
||||
int pal;
|
||||
short blank=-1; // The tile we know is blank
|
||||
|
||||
// *ts->hc++ = code | (dx<<16) | (ty<<25); // cache it
|
||||
|
||||
while((code=*hc++)) {
|
||||
if(!sh && (short)code == blank) continue;
|
||||
|
||||
// Get tile address/2:
|
||||
addr=(code&0x7ff)<<4;
|
||||
addr+=(unsigned int)code>>25; // y offset into tile
|
||||
dx=(code>>16)&0x1ff;
|
||||
if(sh) {
|
||||
unsigned char *zb = HighCol+dx;
|
||||
if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
|
||||
if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
|
||||
if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
|
||||
if(!(*zb&0x80)) *zb&=0x3f; zb++; if(!(*zb&0x80)) *zb&=0x3f; zb++;
|
||||
}
|
||||
|
||||
pal=((code>>9)&0x30);
|
||||
|
||||
if (code&0x0800) zero=TileFlip(dx,addr,pal);
|
||||
else zero=TileNorm(dx,addr,pal);
|
||||
|
||||
if(zero) blank=(short)code;
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
// Index + 0 : hhhhvvvv ab--hhvv yyyyyyyy yyyyyyyy // a: offscreen h, b: offs. v, h: horiz. size
|
||||
// Index + 4 : xxxxxxxx xxxxxxxx pccvhnnn nnnnnnnn // x: x coord + 8
|
||||
|
||||
void DrawSprite(int *sprite, int **hc, int sh)
|
||||
{
|
||||
int width=0,height=0;
|
||||
int row=0,code=0;
|
||||
int pal;
|
||||
int tile=0,delta=0;
|
||||
int sx, sy;
|
||||
int (*fTileFunc)(int sx,int addr,int pal);
|
||||
|
||||
// parse the sprite data
|
||||
sy=sprite[0];
|
||||
code=sprite[1];
|
||||
sx=code>>16; // X
|
||||
width=sy>>28;
|
||||
height=(sy>>24)&7; // Width and height in tiles
|
||||
sy=(sy<<16)>>16; // Y
|
||||
|
||||
row=Scanline-sy; // Row of the sprite we are on
|
||||
|
||||
if (code&0x1000) row=(height<<3)-1-row; // Flip Y
|
||||
|
||||
tile=code&0x7ff; // Tile number
|
||||
tile+=row>>3; // Tile number increases going down
|
||||
delta=height; // Delta to increase tile by going right
|
||||
if (code&0x0800) { tile+=delta*(width-1); delta=-delta; } // Flip X
|
||||
|
||||
tile<<=4; tile+=(row&7)<<1; // Tile address
|
||||
|
||||
if(code&0x8000) { // high priority - cache it
|
||||
*(*hc)++ = (tile<<16)|((code&0x0800)<<5)|((sx<<6)&0x0000ffc0)|((code>>9)&0x30)|((sprite[0]>>16)&0xf);
|
||||
} else {
|
||||
delta<<=4; // Delta of address
|
||||
pal=((code>>9)&0x30)|(sh<<6);
|
||||
|
||||
if(sh && (code&0x6000) == 0x6000) {
|
||||
if(code&0x0800) fTileFunc=TileFlipSH;
|
||||
else fTileFunc=TileNormSH;
|
||||
} else {
|
||||
if(code&0x0800) fTileFunc=TileFlip;
|
||||
else fTileFunc=TileNorm;
|
||||
}
|
||||
|
||||
for (; width; width--,sx+=8,tile+=delta)
|
||||
{
|
||||
if(sx<=0) continue;
|
||||
if(sx>=328) break; // Offscreen
|
||||
|
||||
tile&=0x7fff; // Clip tile address
|
||||
fTileFunc(sx,tile,pal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DrawSpritesFromCache(int *hc, int sh)
|
||||
{
|
||||
int code, tile, sx, delta, width;
|
||||
int pal;
|
||||
int (*fTileFunc)(int sx,int addr,int pal);
|
||||
|
||||
// *(*hc)++ = (tile<<16)|((code&0x0800)<<5)|((sx<<6)&0x0000ffc0)|((code>>9)&0x30)|((sprite[0]>>24)&0xf);
|
||||
|
||||
while((code=*hc++)) {
|
||||
pal=(code&0x30);
|
||||
delta=code&0xf;
|
||||
width=delta>>2; delta&=3;
|
||||
width++; delta++; // Width and height in tiles
|
||||
if (code&0x10000) delta=-delta; // Flip X
|
||||
delta<<=4;
|
||||
tile=((unsigned int)code>>17)<<1;
|
||||
sx=(code<<16)>>22; // sx can be negative (start offscreen), so sign extend
|
||||
|
||||
if(sh && pal == 0x30) { //
|
||||
if(code&0x10000) fTileFunc=TileFlipSH;
|
||||
else fTileFunc=TileNormSH;
|
||||
} else {
|
||||
if(code&0x10000) fTileFunc=TileFlip;
|
||||
else fTileFunc=TileNorm;
|
||||
}
|
||||
|
||||
for (; width; width--,sx+=8,tile+=delta)
|
||||
{
|
||||
if(sx<=0) continue;
|
||||
if(sx>=328) break; // Offscreen
|
||||
|
||||
tile&=0x7fff; // Clip tile address
|
||||
fTileFunc(sx,tile,pal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void BackFill(int reg7, int sh)
|
||||
{
|
||||
unsigned int back=0;
|
||||
unsigned int *pd=NULL,*end=NULL;
|
||||
|
||||
// Start with a blank scanline (background colour):
|
||||
back=reg7&0x3f;
|
||||
back|=sh<<6;
|
||||
back|=back<<8;
|
||||
back|=back<<16;
|
||||
|
||||
pd= (unsigned int *)(HighCol+8);
|
||||
end=(unsigned int *)(HighCol+8+320);
|
||||
|
||||
do { pd[0]=pd[1]=pd[2]=pd[3]=back; pd+=4; } while (pd<end);
|
||||
}
|
||||
|
||||
// --------------------------------------------
|
||||
|
||||
extern unsigned short HighPal[0x100];
|
||||
|
||||
void FinalizeLineBGR444(int sh)
|
||||
{
|
||||
unsigned short *pd=DrawLineDest;
|
||||
unsigned char *ps=HighCol+8;
|
||||
unsigned short *pal=Pico.cram;
|
||||
int len, i, t;
|
||||
|
||||
if (Pico.video.reg[12]&1) {
|
||||
len = 320;
|
||||
} else {
|
||||
if(!(PicoOpt&0x100)) pd+=32;
|
||||
len = 256;
|
||||
}
|
||||
|
||||
if(sh) {
|
||||
pal=HighPal;
|
||||
if(Pico.m.dirtyPal) {
|
||||
blockcpy(pal, Pico.cram, 0x40*2);
|
||||
// shadowed pixels
|
||||
for(i = 0x3f; i >= 0; i--)
|
||||
pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x0777);
|
||||
// hilighted pixels
|
||||
for(i = 0x3f; i >= 0; i--) {
|
||||
t=pal[i]&0xeee;t+=0x444;if(t&0x10)t|=0xe;if(t&0x100)t|=0xe0;if(t&0x1000)t|=0xe00;t&=0xeee;
|
||||
pal[0x80|i]=(unsigned short)t;
|
||||
}
|
||||
Pico.m.dirtyPal = 0;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < len; i++)
|
||||
pd[i] = pal[ps[i]];
|
||||
}
|
||||
|
||||
|
||||
void FinalizeLineRGB555(int sh)
|
||||
{
|
||||
unsigned short *pd=DrawLineDest;
|
||||
unsigned char *ps=HighCol+8;
|
||||
unsigned short *pal=HighPal;
|
||||
int len, i, t, dirtyPal = Pico.m.dirtyPal;
|
||||
|
||||
if(dirtyPal) {
|
||||
unsigned short *ppal=Pico.cram;
|
||||
for(i = 0x3f; i >= 0; i--)
|
||||
pal[i] = (unsigned short) (((ppal[i]&0x00f)<<12)|((ppal[i]&0x0f0)<<3)|((ppal[i]&0xf00)>>7));
|
||||
Pico.m.dirtyPal = 0;
|
||||
}
|
||||
|
||||
if (Pico.video.reg[12]&1) {
|
||||
len = 320;
|
||||
} else {
|
||||
if(!(PicoOpt&0x100)) pd+=32;
|
||||
len = 256;
|
||||
}
|
||||
|
||||
if(sh) {
|
||||
if(dirtyPal) {
|
||||
// shadowed pixels
|
||||
for(i = 0x3f; i >= 0; i--)
|
||||
pal[0x40|i] = pal[0xc0|i] = (unsigned short)((pal[i]>>1)&0x738e);
|
||||
// hilighted pixels
|
||||
for(i = 0x3f; i >= 0; i--) {
|
||||
t=pal[i]&0xe71c;t+=0x4208;if(t&0x20)t|=0x1c;if(t&0x800)t|=0x700;if(t&0x10000)t|=0xe000;t&=0xe71c;
|
||||
pal[0x80|i]=(unsigned short)t;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < len; i++)
|
||||
pd[i] = pal[ps[i]];
|
||||
}
|
||||
|
||||
|
||||
|
384
linux/gp2x.c
Normal file
384
linux/gp2x.c
Normal file
|
@ -0,0 +1,384 @@
|
|||
/* faking/emulating gp2x.c by using gtk */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <pthread.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/soundcard.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "../gp2x/emu.h"
|
||||
#include "../gp2x/gp2x.h"
|
||||
#include "../gp2x/usbjoy.h"
|
||||
#include "../gp2x/version.h"
|
||||
|
||||
void *gp2x_screen;
|
||||
static int current_bpp = 8;
|
||||
static int current_pal[256];
|
||||
static unsigned long current_keys = 0;
|
||||
static int sounddev = 0, mixerdev = 0;
|
||||
static const char *verstring = "PicoDrive " VERSION;
|
||||
|
||||
// dummies
|
||||
char *ext_menu = 0, *ext_state = 0;
|
||||
|
||||
/* gtk */
|
||||
struct gtk_global_struct
|
||||
{
|
||||
GtkWidget *window;
|
||||
GtkWidget *pixmap1;
|
||||
} gtk_items;
|
||||
|
||||
|
||||
static gboolean delete_event (GtkWidget *widget, GdkEvent *event, gpointer data)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void destroy (GtkWidget *widget, gpointer data)
|
||||
{
|
||||
gtk_main_quit ();
|
||||
}
|
||||
|
||||
static gint key_press_event (GtkWidget *widget, GdkEventKey *event)
|
||||
{
|
||||
switch (event->hardware_keycode)
|
||||
{
|
||||
case 0x62: current_keys |= GP2X_UP; break;
|
||||
case 0x68: current_keys |= GP2X_DOWN; break;
|
||||
case 0x64: current_keys |= GP2X_LEFT; break;
|
||||
case 0x66: current_keys |= GP2X_RIGHT; break;
|
||||
case 0x24: current_keys |= GP2X_START; break; // enter
|
||||
case 0x23: current_keys |= GP2X_SELECT;break; // ]
|
||||
case 0x34: current_keys |= GP2X_A; break; // z
|
||||
case 0x35: current_keys |= GP2X_X; break; // x
|
||||
case 0x36: current_keys |= GP2X_B; break; // c
|
||||
case 0x37: current_keys |= GP2X_Y; break; // v
|
||||
case 0x27: current_keys |= GP2X_L; break; // s
|
||||
case 0x28: current_keys |= GP2X_R; break; // d
|
||||
case 0x29: current_keys |= GP2X_PUSH; break; // f
|
||||
case 0x18: current_keys |= GP2X_VOL_DOWN;break; // q
|
||||
case 0x19: current_keys |= GP2X_VOL_UP;break; // w
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static gint key_release_event (GtkWidget *widget, GdkEventKey *event)
|
||||
{
|
||||
switch (event->hardware_keycode)
|
||||
{
|
||||
case 0x62: current_keys &= ~GP2X_UP; break;
|
||||
case 0x68: current_keys &= ~GP2X_DOWN; break;
|
||||
case 0x64: current_keys &= ~GP2X_LEFT; break;
|
||||
case 0x66: current_keys &= ~GP2X_RIGHT; break;
|
||||
case 0x24: current_keys &= ~GP2X_START; break; // enter
|
||||
case 0x23: current_keys &= ~GP2X_SELECT;break; // ]
|
||||
case 0x34: current_keys &= ~GP2X_A; break; // z
|
||||
case 0x35: current_keys &= ~GP2X_X; break; // x
|
||||
case 0x36: current_keys &= ~GP2X_B; break; // c
|
||||
case 0x37: current_keys &= ~GP2X_Y; break; // v
|
||||
case 0x27: current_keys &= ~GP2X_L; break; // s
|
||||
case 0x28: current_keys &= ~GP2X_R; break; // d
|
||||
case 0x29: current_keys &= ~GP2X_PUSH; break; // f
|
||||
case 0x18: current_keys &= ~GP2X_VOL_DOWN;break; // q
|
||||
case 0x19: current_keys &= ~GP2X_VOL_UP;break; // w
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void *gtk_threadf(void *none)
|
||||
{
|
||||
gtk_main();
|
||||
|
||||
printf("linux: gtk thread finishing\n");
|
||||
engineState = PGS_Quit;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void gtk_initf(void)
|
||||
{
|
||||
int argc = 0;
|
||||
char *argv[] = { "" };
|
||||
GtkWidget *box;
|
||||
pthread_t gtk_thread;
|
||||
|
||||
g_thread_init (NULL);
|
||||
gdk_threads_init ();
|
||||
gdk_set_locale ();
|
||||
gtk_init (&argc, (char ***) &argv);
|
||||
|
||||
/* create new window */
|
||||
gtk_items.window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
|
||||
g_signal_connect (G_OBJECT (gtk_items.window), "delete_event",
|
||||
G_CALLBACK (delete_event), NULL);
|
||||
|
||||
g_signal_connect (G_OBJECT (gtk_items.window), "destroy",
|
||||
G_CALLBACK (destroy), NULL);
|
||||
|
||||
g_signal_connect (G_OBJECT (gtk_items.window), "key_press_event",
|
||||
G_CALLBACK (key_press_event), NULL);
|
||||
|
||||
g_signal_connect (G_OBJECT (gtk_items.window), "key_release_event",
|
||||
G_CALLBACK (key_release_event), NULL);
|
||||
|
||||
gtk_container_set_border_width (GTK_CONTAINER (gtk_items.window), 2);
|
||||
gtk_window_set_title ((GtkWindow *) gtk_items.window, verstring);
|
||||
|
||||
box = gtk_hbox_new(FALSE, 0);
|
||||
gtk_widget_show(box);
|
||||
gtk_container_add (GTK_CONTAINER (gtk_items.window), box);
|
||||
|
||||
/* live pixmap */
|
||||
gtk_items.pixmap1 = gtk_image_new ();
|
||||
gtk_container_add (GTK_CONTAINER (box), gtk_items.pixmap1);
|
||||
gtk_widget_show (gtk_items.pixmap1);
|
||||
gtk_widget_set_size_request (gtk_items.pixmap1, 320, 240);
|
||||
|
||||
gtk_widget_show (gtk_items.window);
|
||||
|
||||
// pthread_mutex_init (&thr_mutex, NULL);
|
||||
// pthread_mutex_lock (&thr_mutex);
|
||||
// pthread_mutex_init (&scanner_muttex, NULL);
|
||||
|
||||
pthread_create(>k_thread, NULL, gtk_threadf, NULL);
|
||||
}
|
||||
|
||||
void finalize_image(guchar *pixels, gpointer data)
|
||||
{
|
||||
free(pixels);
|
||||
}
|
||||
|
||||
/* --- */
|
||||
|
||||
void gp2x_init(void)
|
||||
{
|
||||
printf("entering init()\n"); fflush(stdout);
|
||||
|
||||
gp2x_screen = malloc(320*240*2 + 320*2);
|
||||
|
||||
// snd
|
||||
mixerdev = open("/dev/mixer", O_RDWR);
|
||||
if (mixerdev == -1)
|
||||
printf("open(\"/dev/mixer\") failed with %i\n", errno);
|
||||
|
||||
gtk_initf();
|
||||
|
||||
gp2x_usbjoy_init();
|
||||
|
||||
printf("exitting init()\n"); fflush(stdout);
|
||||
}
|
||||
|
||||
void gp2x_deinit(void)
|
||||
{
|
||||
free(gp2x_screen);
|
||||
if (sounddev > 0) close(sounddev);
|
||||
close(mixerdev);
|
||||
gp2x_usbjoy_deinit();
|
||||
}
|
||||
|
||||
/* video */
|
||||
void gp2x_video_flip(void)
|
||||
{
|
||||
GdkPixbuf *pixbuf;
|
||||
unsigned char *image;
|
||||
int i;
|
||||
|
||||
gdk_threads_enter();
|
||||
|
||||
image = malloc (320*240*3);
|
||||
if (image == NULL)
|
||||
{
|
||||
gdk_threads_leave();
|
||||
return;
|
||||
}
|
||||
|
||||
if (current_bpp == 8)
|
||||
{
|
||||
unsigned char *pixels = gp2x_screen;
|
||||
int pix;
|
||||
|
||||
for (i = 0; i < 320*240; i++)
|
||||
{
|
||||
pix = current_pal[pixels[i]];
|
||||
image[3 * i + 0] = pix >> 16;
|
||||
image[3 * i + 1] = pix >> 8;
|
||||
image[3 * i + 2] = pix;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
unsigned short *pixels = gp2x_screen;
|
||||
|
||||
for (i = 0; i < 320*240; i++)
|
||||
{
|
||||
/* in: rrrr rggg gggb bbbb */
|
||||
/* out: rrrr r000 gggg gg00 bbbb b000 */
|
||||
image[3 * i + 0] = (pixels[i] >> 8) & 0xf8;
|
||||
image[3 * i + 1] = (pixels[i] >> 3) & 0xfc;
|
||||
image[3 * i + 2] = (pixels[i] << 3);
|
||||
}
|
||||
}
|
||||
|
||||
pixbuf = gdk_pixbuf_new_from_data (image, GDK_COLORSPACE_RGB,
|
||||
FALSE, 8, 320, 240, 320*3, finalize_image, NULL);
|
||||
gtk_image_set_from_pixbuf (GTK_IMAGE (gtk_items.pixmap1), pixbuf);
|
||||
g_object_unref (pixbuf);
|
||||
|
||||
gdk_threads_leave();
|
||||
}
|
||||
|
||||
void gp2x_video_changemode(int bpp)
|
||||
{
|
||||
current_bpp = bpp;
|
||||
}
|
||||
|
||||
void gp2x_video_setpalette(int *pal, int len)
|
||||
{
|
||||
memcpy(current_pal, pal, len*4);
|
||||
}
|
||||
|
||||
void gp2x_video_RGB_setscaling(int W, int H)
|
||||
{
|
||||
}
|
||||
|
||||
void gp2x_memcpy_all_buffers(void *data, int offset, int len)
|
||||
{
|
||||
memcpy((char *)gp2x_screen + offset, data, len);
|
||||
}
|
||||
|
||||
|
||||
void gp2x_memset_all_buffers(int offset, int byte, int len)
|
||||
{
|
||||
memset((char *)gp2x_screen + offset, byte, len);
|
||||
}
|
||||
|
||||
|
||||
/* sound */
|
||||
static int s_oldrate = 0, s_oldbits = 0, s_oldstereo = 0;
|
||||
|
||||
void gp2x_start_sound(int rate, int bits, int stereo)
|
||||
{
|
||||
int frag = 0, bsize, buffers;
|
||||
|
||||
// if no settings change, we don't need to do anything
|
||||
if (rate == s_oldrate && s_oldbits == bits && s_oldstereo == stereo) return;
|
||||
|
||||
if (sounddev > 0) close(sounddev);
|
||||
sounddev = open("/dev/dsp", O_WRONLY|O_ASYNC);
|
||||
if (sounddev == -1)
|
||||
printf("open(\"/dev/dsp\") failed with %i\n", errno);
|
||||
|
||||
ioctl(sounddev, SNDCTL_DSP_SPEED, &rate);
|
||||
ioctl(sounddev, SNDCTL_DSP_SETFMT, &bits);
|
||||
ioctl(sounddev, SNDCTL_DSP_STEREO, &stereo);
|
||||
// calculate buffer size
|
||||
buffers = 16;
|
||||
bsize = rate / 32;
|
||||
if (rate > 22050) { bsize*=4; buffers*=2; } // 44k mode seems to be very demanding
|
||||
while ((bsize>>=1)) frag++;
|
||||
frag |= buffers<<16; // 16 buffers
|
||||
ioctl(sounddev, SNDCTL_DSP_SETFRAGMENT, &frag);
|
||||
printf("gp2x_set_sound: %i/%ibit/%s, %i buffers of %i bytes\n",
|
||||
rate, bits, stereo?"stereo":"mono", frag>>16, 1<<(frag&0xffff));
|
||||
|
||||
s_oldrate = rate; s_oldbits = bits; s_oldstereo = stereo;
|
||||
}
|
||||
|
||||
void gp2x_sound_write(void *buff, int len)
|
||||
{
|
||||
write(sounddev, buff, len);
|
||||
}
|
||||
|
||||
void gp2x_sound_volume(int l, int r)
|
||||
{
|
||||
l=l<0?0:l; l=l>255?255:l; r=r<0?0:r; r=r>255?255:r;
|
||||
l<<=8; l|=r;
|
||||
ioctl(mixerdev, SOUND_MIXER_WRITE_PCM, &l); /*SOUND_MIXER_WRITE_VOLUME*/
|
||||
}
|
||||
|
||||
/* joy */
|
||||
unsigned long gp2x_joystick_read(int allow_usb_joy)
|
||||
{
|
||||
unsigned long value = current_keys;
|
||||
int i;
|
||||
|
||||
if (allow_usb_joy && num_of_joys > 0) {
|
||||
// check the usb joy as well..
|
||||
gp2x_usbjoy_update();
|
||||
for (i = 0; i < num_of_joys; i++)
|
||||
value |= gp2x_usbjoy_check(i);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
/* 940 */
|
||||
int crashed_940 = 0;
|
||||
void Pause940(int yes)
|
||||
{
|
||||
}
|
||||
|
||||
void Reset940(int yes)
|
||||
{
|
||||
}
|
||||
|
||||
/* faking gp2x cpuctrl.c */
|
||||
void cpuctrl_init(void)
|
||||
{
|
||||
}
|
||||
|
||||
void cpuctrl_deinit(void)
|
||||
{
|
||||
}
|
||||
|
||||
void set_FCLK(unsigned MHZ)
|
||||
{
|
||||
}
|
||||
|
||||
void Disable_940(void)
|
||||
{
|
||||
}
|
||||
|
||||
void gp2x_video_wait_vsync(void)
|
||||
{
|
||||
}
|
||||
|
||||
void set_RAM_Timings(int tRC, int tRAS, int tWR, int tMRD, int tRFC, int tRP, int tRCD)
|
||||
{
|
||||
}
|
||||
|
||||
void set_gamma(int g100)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
/* squidgehack.c */
|
||||
int mmuhack(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int mmuunhack(void)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/* misc */
|
||||
void spend_cycles(int c)
|
||||
{
|
||||
usleep(c/*/200*/);
|
||||
}
|
||||
|
||||
|
||||
|
19
linux/port_config.h
Normal file
19
linux/port_config.h
Normal file
|
@ -0,0 +1,19 @@
|
|||
// port specific settings
|
||||
|
||||
#ifndef PORT_CONFIG_H
|
||||
#define PORT_CONFIG_H
|
||||
|
||||
#define CPU_CALL
|
||||
|
||||
// draw2.c
|
||||
#define START_ROW 0 // which row of tiles to start rendering at?
|
||||
#define END_ROW 28 // ..end
|
||||
|
||||
// pico.c
|
||||
#define CAN_HANDLE_240_LINES 1
|
||||
|
||||
#define dprintf(f,...) printf(f"\n",##__VA_ARGS__)
|
||||
//#define dprintf(x...)
|
||||
|
||||
#endif //PORT_CONFIG_H
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue