Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
5,973 additions
and
3,623 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.