Skip to content

Commit

Permalink
Joyrider Dingux port
Browse files Browse the repository at this point in the history
  • Loading branch information
uli committed Jun 19, 2010
1 parent 7c360f7 commit 0976747
Show file tree
Hide file tree
Showing 27 changed files with 5,973 additions and 3,623 deletions.
2,988 changes: 2 additions & 2,986 deletions src/Makefile

Large diffs are not rendered by default.

283 changes: 148 additions & 135 deletions src/Makefile.linux

Large diffs are not rendered by default.

124 changes: 124 additions & 0 deletions src/asfont.cpp
@@ -0,0 +1,124 @@
#include "asfont.h"
#include "surface.h"
#include "utilities.h"

#include <iostream>

using namespace std;

ASFont::ASFont(SDL_Surface* font) {
this->font.initFont(font);
halfHeight = getHeight()/2;
halfLineHeight = getLineHeight()/2;
}

ASFont::ASFont(Surface* font) {
this->font.initFont(font->raw);
halfHeight = getHeight()/2;
halfLineHeight = getLineHeight()/2;
}

ASFont::ASFont(string font) {
this->font.initFont(font);
halfHeight = getHeight()/2;
halfLineHeight = getLineHeight()/2;
}

ASFont::~ASFont() {
font.freeFont();
}

bool ASFont::utf8Code(unsigned char c) {
return font.utf8Code(c);
}

void ASFont::write(SDL_Surface* surface, const char* text, int x, int y) {
font.write(surface, text, x, y);
}

void ASFont::write(SDL_Surface* surface, const std::string& text, int x, int y, const unsigned short halign, const unsigned short valign) {
switch (halign) {
case SFontHAlignCenter:
x -= getTextWidth(text)/2;
break;
case SFontHAlignRight:
x -= getTextWidth(text);
break;
}

switch (valign) {
case SFontVAlignMiddle:
y -= getHalfHeight();
break;
case SFontVAlignBottom:
y -= getHeight();
break;
}

font.write(surface, text, x, y);
}
void ASFont::write(SDL_Surface* surface, vector<string> *text, int x, int y, const unsigned short halign, const unsigned short valign) {
switch (valign) {
case SFontVAlignMiddle:
y -= getHalfHeight()*text->size();
break;
case SFontVAlignBottom:
y -= getHeight()*text->size();
break;
}

for (uint i=0; i<text->size(); i++) {
int ix = x;
switch (halign) {
case SFontHAlignCenter:
ix -= getTextWidth(text->at(i))/2;
break;
case SFontHAlignRight:
ix -= getTextWidth(text->at(i));
break;
}

font.write(surface, text->at(i), x, y+getHeight()*i);
}
}

void ASFont::write(Surface* surface, const std::string& text, int x, int y, const unsigned short halign, const unsigned short valign) {
if (text.find("\n",0)!=string::npos) {
vector<string> textArr;
split(textArr,text,"\n");
write(surface->raw, &textArr, x, y, halign, valign);
} else
write(surface->raw, text, x, y, halign, valign);
}

int ASFont::getHeight() {
return font.getHeight();
}
int ASFont::getHalfHeight() {
return halfHeight;
}

int ASFont::getLineHeight() {
return font.getLineHeight();
}
int ASFont::getHalfLineHeight() {
return halfLineHeight;
}

int ASFont::getTextWidth(const char* text) {
return font.getTextWidth(text);
}
int ASFont::getTextWidth(const std::string& text) {
if (text.find("\n",0)!=string::npos) {
vector<string> textArr;
split(textArr,text,"\n");
return getTextWidth(&textArr);
} else
return getTextWidth(text.c_str());
}
int ASFont::getTextWidth(vector<string> *text) {
int w = 0;
for (uint i=0; i<text->size(); i++)
w = max( getTextWidth(text->at(i).c_str()), w );
return w;
}
49 changes: 49 additions & 0 deletions src/asfont.h
@@ -0,0 +1,49 @@
//Advanced SFont by Massimiliano Torromeo (cpp wrapper around SFont)

#ifndef ASFONT_H
#define ASFONT_H

#include <string>
#include <vector>
#include <SDL.h>
#include "sfontplus.h"

using std::string;
using std::vector;

const unsigned short SFontHAlignLeft = 0;
const unsigned short SFontHAlignRight = 1;
const unsigned short SFontHAlignCenter = 2;
const unsigned short SFontVAlignTop = 0;
const unsigned short SFontVAlignBottom = 1;
const unsigned short SFontVAlignMiddle = 2;

class Surface;

class ASFont {
public:
ASFont(SDL_Surface* font);
ASFont(Surface* font);
ASFont(string font);
~ASFont();

bool utf8Code(unsigned char c);

int getHeight();
int getHalfHeight();
int getLineHeight();
int getHalfLineHeight();
int getTextWidth(const char* text);
int getTextWidth(const string& text);
int getTextWidth(vector<string> *text);
void write(SDL_Surface* surface, const char* text, int x, int y);
void write(SDL_Surface* surface, const std::string& text, int x, int y, const unsigned short halign = 0, const unsigned short valign = 0);
void write(SDL_Surface* surface, vector<string> *text, int x, int y, const unsigned short halign = 0, const unsigned short valign = 0);
void write(Surface* surface, const std::string& text, int x, int y, const unsigned short halign = 0, const unsigned short valign = 0);

private:
SFontPlus font;
int halfHeight, halfLineHeight;
};

#endif /* ASFONT_H */
98 changes: 98 additions & 0 deletions src/cpu.cpp
@@ -0,0 +1,98 @@
#include <stdlib.h>
#include <stdio.h>
#include <sys/mman.h>
#include <unistd.h>
#include <fcntl.h>
#include "jz4740.h"
#include "cpu.h"

inline int sdram_convert(unsigned int pllin,unsigned int *sdram_freq)
{
register unsigned int ns, tmp;

ns = 1000000000 / pllin;
/* Set refresh registers */
tmp = SDRAM_TREF/ns;
tmp = tmp/64 + 1;
if (tmp > 0xff) tmp = 0xff;
*sdram_freq = tmp;

return 0;

}

void pll_init(unsigned int clock)
{
register unsigned int cfcr, plcr1;
unsigned int sdramclock = 0;
int n2FR[33] = {
0, 0, 1, 2, 3, 0, 4, 0, 5, 0, 0, 0, 6, 0, 0, 0,
7, 0, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 0,
9
};
//int div[5] = {1, 4, 4, 4, 4}; /* divisors of I:S:P:L:M */
int div[5] = {1, 3, 3, 3, 3}; /* divisors of I:S:P:L:M */
int nf, pllout2;

cfcr = CPM_CPCCR_CLKOEN |
(n2FR[div[0]] << CPM_CPCCR_CDIV_BIT) |
(n2FR[div[1]] << CPM_CPCCR_HDIV_BIT) |
(n2FR[div[2]] << CPM_CPCCR_PDIV_BIT) |
(n2FR[div[3]] << CPM_CPCCR_MDIV_BIT) |
(n2FR[div[4]] << CPM_CPCCR_LDIV_BIT);

pllout2 = (cfcr & CPM_CPCCR_PCS) ? clock : (clock / 2);

/* Init UHC clock */
// REG_CPM_UHCCDR = pllout2 / 48000000 - 1;
jz_cpmregl[0x6C>>2] = pllout2 / 48000000 - 1;

nf = clock * 2 / CFG_EXTAL;
plcr1 = ((nf - 2) << CPM_CPPCR_PLLM_BIT) | /* FD */
(0 << CPM_CPPCR_PLLN_BIT) | /* RD=0, NR=2 */
(0 << CPM_CPPCR_PLLOD_BIT) | /* OD=0, NO=1 */
(0x20 << CPM_CPPCR_PLLST_BIT) | /* PLL stable time */
CPM_CPPCR_PLLEN; /* enable PLL */

/* init PLL */
// REG_CPM_CPCCR = cfcr;
// REG_CPM_CPPCR = plcr1;
jz_cpmregl[0] = cfcr;
jz_cpmregl[0x10>>2] = plcr1;

sdram_convert(clock,&sdramclock);
if(sdramclock > 0)
{
// REG_EMC_RTCOR = sdramclock;
// REG_EMC_RTCNT = sdramclock;
jz_emcregs[0x8C>>1] = sdramclock;
jz_emcregs[0x88>>1] = sdramclock;

}else
{
printf("sdram init fail!\n");
while(1);
}

}


void jz_cpuspeed(unsigned clockspeed)
{
if (clockspeed >= 200 && clockspeed <= 430)
{
jz_dev = open("/dev/mem", O_RDWR);
if(jz_dev)
{
jz_cpmregl=(unsigned long *)mmap(0, 0x80, PROT_READ|PROT_WRITE, MAP_SHARED, jz_dev, 0x10000000);
jz_emcregl=(unsigned long *)mmap(0, 0x90, PROT_READ|PROT_WRITE, MAP_SHARED, jz_dev, 0x13010000);
jz_emcregs=(unsigned short *)jz_emcregl;
pll_init(clockspeed*1000000);
munmap((void *)jz_cpmregl, 0x80);
munmap((void *)jz_emcregl, 0x90);
close(jz_dev);
}
else
printf("failed opening /dev/mem \n");
}
}
24 changes: 24 additions & 0 deletions src/cpu.h
@@ -0,0 +1,24 @@
#ifndef CPU_H
#define CPU_H

/* Define this to the CPU frequency */
#define CPU_FREQ 336000000 /* CPU clock: 336 MHz */
#define CFG_EXTAL 12000000 /* EXT clock: 12 Mhz */

// SDRAM Timings, unit: ns
#define SDRAM_TRAS 45 /* RAS# Active Time */
#define SDRAM_RCD 20 /* RAS# to CAS# Delay */
#define SDRAM_TPC 20 /* RAS# Precharge Time */
#define SDRAM_TRWL 7 /* Write Latency Time */
#define SDRAM_TREF 15625 /* Refresh period: 4096 refresh cycles/64ms */
//#define SDRAM_TREF 7812 /* Refresh period: 8192 refresh cycles/64ms */

static unsigned long jz_dev;
static volatile unsigned long *jz_cpmregl, *jz_emcregl;
volatile unsigned short *jz_emcregs;

void jz_cpuspeed(unsigned clockspeed);
void pll_init(unsigned int clock);
inline int sdram_convert(unsigned int pllin,unsigned int *sdram_freq);

#endif
16 changes: 8 additions & 8 deletions src/dirdialog.cpp
Expand Up @@ -38,15 +38,15 @@ DirDialog::DirDialog(GMenu2X *gmenu2x, string text, string dir) {
this->text = text;
selRow = 0;
if (dir.empty())
path = "/mnt";
path = "/boot/local";
else
path = dir;

//Delegates
ButtonAction actionUp = MakeDelegate(this, &DirDialog::up);
ButtonAction actionEnter = MakeDelegate(this, &DirDialog::enter);
ButtonAction actionConfirm = MakeDelegate(this, &DirDialog::confirm);

btnUp = new IconButton(gmenu2x, "skin:imgs/buttons/x.png", gmenu2x->tr["Up one folder"]);
btnUp->setAction(actionUp);

Expand All @@ -60,25 +60,25 @@ DirDialog::DirDialog(GMenu2X *gmenu2x, string text, string dir) {
bool DirDialog::exec() {
bool ts_pressed = false;
uint i, firstElement = 0, iY, action;

if (!fileExists(path))
path = "/mnt";
path = "/boot/local";

fl = new FileLister(path,true,false);
fl->browse();

selected = 0;
close = false;
result = true;

uint rowHeight = gmenu2x->font->getHeight()+1; // gp2x=15+1 / pandora=19+1
uint numRows = (gmenu2x->resY-gmenu2x->skinConfInt["topBarHeight"]-20)/rowHeight;
SDL_Rect clipRect = {0, gmenu2x->skinConfInt["topBarHeight"]+1, gmenu2x->resX-9, gmenu2x->resY-gmenu2x->skinConfInt["topBarHeight"]-25};
SDL_Rect touchRect = {2, gmenu2x->skinConfInt["topBarHeight"]+4, gmenu2x->resX-12, clipRect.h};
while (!close) {
action = DirDialog::ACT_NONE;
if (gmenu2x->f200) gmenu2x->ts.poll();

gmenu2x->bg->blit(gmenu2x->s,0,0);
gmenu2x->drawTitleIcon("icons/explorer.png",true);
gmenu2x->writeTitle("Directory Browser");
Expand Down Expand Up @@ -173,15 +173,15 @@ bool DirDialog::exec() {
} break;
}
}

delete(fl);

return result;
}

void DirDialog::up() {
string::size_type p = path.rfind("/");
if (p==string::npos || path.substr(0,4)!="/mnt" || p<4) {
if (p==string::npos || path.substr(0,11)!="/boot/local" || p<4) {
close = true;
result = false;
} else {
Expand Down

0 comments on commit 0976747

Please sign in to comment.