system.~c
来自「An complete pmp solution for mattel juic」· ~C 代码 · 共 342 行
~C
342 行
#include "system.h"
#define DISPOFF 8
#define LCDOFF 13
#define PORT_LCD *pdatc
/*===========================================================*/
/*----- System -----*/
void wCPUInit()
{
/* Set clock rate to 66.428MHz, just in case the JB has
it set wrong
*/
//*pllcon = 0x00034031;//
*pllcon=0x00049041;
/* Be sure we're in cacheable memory
Can the framebuffer be in cache too?
*/
*((long*) 0x01c00000)= 0x0000000E;
*((long*) 0x01c00004)= 0xC0000020;
*((long*) 0x01c00008)= 0xC140C000;
*((long*) 0x01c40000)= 0x80001B1B;
*((long*) 0x01c80000)= 0x11000002;
*((long*) 0x01c80004)= 0x00000600;
*((long*) 0x01c8001c)= 0x00018000;
*((long*) 0x01c80020)= 0x00018000;
*((long*) 0x01c80024)= 0x0082062B;
*((long*) 0x01c80028)= 0x00000016;
*((long*) 0x01c8002c)= 0x00000020;
*((long*) 0x01c80030)= 0x00000020;
*ncachbe0=0x80002000;
*ncachbe1=0x00000000;
*pcona = 0x000003FF;
*pconb = 0x000007FF;
*pconc = 0xF555FFCF;
PORT_LCD |= (1 << LCDOFF);
*pupc = 0x00000600;
*pcond = 0x0000AAAA;
*pupd = 0x000000FF;
*pcone = 0x0002AA80;
*pupe = 0x000000F8;
*pconf = 0x001B6CEA;
*pupf = 0x000001E3;
*pcong = 0x0000FFFF;
*pupg = 0x00000000;
*spucr = 0x00000007;
*intcon = 0x00000000;
*wtcon = 0x00000000;
*tcfg0 = 0x00020202;
*tcfg1 = 0x00111111;
*tcntb1 = 0x00000A00;
*tcntb2 = 0x00000A00;
*tcmpb1 = 0x000009FF;
*tcmpb2 = 0x00000003;
*tcon = 0x00002200;
*tcon = 0x00009900;
wMallocInit();
FatFs = wMalloc(sizeof(FATFS));
}
//-------------------------------------------------------------
void wDelayMs(u32 delay)
{
/* Delay hand tuned for use with 66.428MHz clock
(PLLCON = 0x55051, PLL reference of 10MHz).
Assumes code is running from cached memory.
fixme: use a hardware timer instead.
*/
u32 ms;
u32 i;
for (ms=0; ms<delay; ms++)
for (i=0; i<13288; i++)
;
}
//-------------------------------------------------------------
void wDelayCycles(u32 delay)
{
u32 i;
for (i = 0; i<delay/4; i++);
}
/*===========================================================*/
/*----- Interrupts -----*/
void wInterruptInit()
{
*intcon = 0x00000006;
*intmsk = 0x03FFFFFF;
}
//------------------------------------------------------------
void wInterruptHandlerInit (u32 uxInterrupt, void *vFunction)
{
switch (uxInterrupt)
{
case portIntADC: { HandlerADC = vFunction; return; }
case portIntRTC: { HandlerRTC = vFunction; return; }
case portIntUTXD1: { HandlerUTXD1 = vFunction; return; }
case portIntUTXD0: { HandlerUTXD0 = vFunction; return; }
case portIntSIO: { HandlerSIO = vFunction; return; }
case portIntIIC: { HandlerIIC = vFunction; return; }
case portIntURXD1: { HandlerURXD1 = vFunction; return; }
case portIntURXD0: { HandlerURXD0 = vFunction; return; }
case portIntTIMER5: { HandlerTIMER5 = vFunction; return; }
case portIntTIMER4: { HandlerTIMER4 = vFunction; return; }
case portIntTIMER3: { HandlerTIMER3 = vFunction; return; }
case portIntTIMER2: { HandlerTIMER2 = vFunction; return; }
case portIntTIMER1: { HandlerTIMER1 = vFunction; return; }
case portIntTIMER0: { HandlerTIMER0 = vFunction; return; }
case portIntUERR01: { HandlerUERR01 = vFunction; return; }
case portIntWDT: { HandlerWDT = vFunction; return; }
case portIntBDMA1: { HandlerBDMA1 = vFunction; return; }
case portIntBDMA0: { HandlerBDMA0 = vFunction; return; }
case portIntZDMA1: { HandlerZDMA1 = vFunction; return; }
case portIntZDMA0: { HandlerZDMA0 = vFunction; return; }
case portIntTICK: { HandlerTICK = vFunction; return; }
case portIntEINT4567: { HandlerEINT4567 = vFunction; return; }
case portIntEINT3: { HandlerEINT3 = vFunction; return; }
case portIntEINT2: { HandlerEINT2 = vFunction; return; }
case portIntEINT1: { HandlerEINT1 = vFunction; return; }
case portIntEINT0: { HandlerEINT0 = vFunction; return; }
}
}
/*===========================================================*/
/*----- Inter-IC Sound (IIS) -----*/
void wIISInit()
{
*iisfifcon = 0x00000300;
*iiscon = 0x00000002; /*IIS off */
*iismod = 0x00000084; /*CODECLK = 386fs */
*iiscon = 0x00000003; /*IIS on */
}
/*===========================================================*/
/*----- LCD Controller -----*/
void *wFramebufferStart()
{
/* Return with starting address of LCD framebuffer */
return (void*)(((*lcdsaddr1) & 0x07ffffff) << 1);
}
//-------------------------------------------------------------
void wSetFramebufferStart(u32 *addr)
{
*lcdsaddr1 &= ~((*lcdsaddr1) & 0x07ffffff);
*lcdsaddr1 |= ((((u32)(addr)) & 0x0fffffff) >> 1);
}
//-------------------------------------------------------------
void wClearLCD()
{
u32 i;
u08 *addr=(u08*)wFramebufferStart();
/* fill entire framebuffer, 32 bits at a whack */
for (i=0; i<240*160; i++)
{
*addr=0x00;
addr++;
}
}
//-------------------------------------------------------------
void wSetPixel(u32 x, u32 y, u08 color)
{
u08 *addr=(u08*)wFramebufferStart();
addr+=x;
addr+=(240*y);
*addr=color;
}
//-------------------------------------------------------------
void wLCDInit()
{
/* Set ENVID (bit 0 of lcdcon1) to 0 to disable panel */
*lcdcon1=0x00C0DF40; /* LCDCON1 (LCD Control 1) */
/* Configure the LCD panel, using settings borrowed from
the built in self test code.
Looks like it's one byte/pixel, using the palette LUT registers.
*/
*lcdcon2=0x0141649F; /* LCDCON2 (LCD Control 2) */
*lcdcon3=0x00000000; /* LCDCON3 (LCD Control 3) */
*lcdsaddr1=0x1E080000; /* LCDSADDR1 (Frame Upper Buffer Start Address 1) */
*lcdsaddr2=0x21884B00; /* LCDSADDR2 (Frame Lower Buffer Start Address 2) */
*lcdsaddr3=0x00000078; /* LCDSADDR3 (Virtual Screen Address) */
*redlut=0xFCA86420; /* REDLUT (RED Lookup Table) */
*greenlut=0xFCA86420; /* GREENLUT (GREEN Lookup Table) */
*bluelut=0x0000FA40; /* BLUELUT (BLUE Lookup Table) */
*dp1_2=0x0000A5A5; /* DP1_2 (Dithering Pattern duty 1/2) */
*dp4_7=0x0BA5DA65; /* DP4_7 (Dithering Pattern duty 4/7) */
*dp3_5=0x000A5A5F; /* DP3_5 (Dithering Pattern duty 3/5) */
*dp2_3=0x00000D6B; /* DP2_3 (Dithering Pattern duty 2/3) */
*dp5_7=0x0EB7B5ED; /* DP5_7 (Dithering Pattern duty 5/7) */
*dp3_4=0x00007DBE; /* DP3_4 (Dithering Pattern duty 3/4) */
*dp4_5=0x0007EBDF; /* DP4_5 (Dithering Pattern duty 4/5) */
*dp6_7=0x07FDFBFE; /* DP6_7 (Dithering Pattern duty 6/7) */
*dithmode=0x00000000; /* DITHMODE (Dithering Mode) */
/* Enable the panel now that the settings are in place */
*lcdcon1=0x00C0DF41; /* LCDCON1 (LCD Control 1) */
PORT_LCD |= (1 << LCDOFF);
PORT_LCD |= (1 << DISPOFF);
}
//-------------------------------------------------------------
void wFloodFill(u32 x1, u32 y1, u32 x2, u32 y2, u08 color)
{
u32 x, y;
for (x = x1; x < x2; x++)
for (y = y1; y < y2; y++)
wSetPixel(x, y, color);
}
//-------------------------------------------------------------
void wDrawChar( u08 c, u32 x, u32 y, u08 color)
{
/* Draw a single ascii character on screen at location x,y */
u32 i;
u32 j;
wFloodFill (x, y, x+6, y+7, 0x00);
/* Chars are 7 pixels tall, 5 pixels wide */
if (c>30)
{for (i=0; i<7; i++)
for (j=0; j<5; j++)
if (((ascii_lookup[c-32][i])<<(3+j)) & 0x80)
wSetPixel(x+j, y+i, color);
}
else
{for (i=0; i<7; i++)
for (j=0; j<5; j++)
if (((no_character_lookup[i])<<(3+j)) & 0x80)
wSetPixel(x+j, y+i, color);
}
}
//-------------------------------------------------------------
void wDrawString(u08* s, u32 x, u32 y, u08 color)
{
/* Draw a string of ascii chars on screen */
while (*s)
{
wDrawChar(*s, x, y, color);
x+=6;
s++;
}
}
//-------------------------------------------------------------
void wDrawStringL(u08* s, u32 x, u32 y,u32 length, u08 color)
{
/* Draw a string of ascii chars on screen */
u32 i;
for (i=0; i<length; i++)
{
wDrawChar(*s, x, y, color);
x+=6;
s++;
}
}
//----------------------------------------------------------
void wDrawHex32 (u32 s, u32 x, u32 y, u08 color)
{
u08 number;
x+=42;
u08 i = 0;
wFloodFill (x-42, y, x+6, y+7, 0x00);
for (;i<8;i++)
{
number = s%16;
if (number>9) number += 7;
wDrawChar((number+48), x, y, color);
x -= 6;
s/=16;
}
}
//----------------------------------------------------------
void wDrawHex8 (u08 s, u32 x, u32 y, u08 color)
{
u08 number;
x+=6;
u08 i = 0;
wFloodFill (x-12, y, x, y+7, 0x00);
for (;i<2;i++)
{
number = s%16;
if (number>9) number += 7;
wDrawChar((number+48), x, y, color);
x -= 6;
s/=16;
}
}
//----------------------------------------------------------
/*
c:
bit|function
8 |0 - zeroes aren't viewed, 1 - zeroes viewed
7:0|number length
*/
void draw_number (u32 s, u32 c, u32 x, u32 y, u08 color)
{
u08 number;
u08 zero = ((c&0x100)>>8);
u32 a = 1;
u32 length = (c&0xFF)-1;
wFloodFill (x, y, x+48, y+7, 0x00);
while (length)
{
a*=10;
length--;
}
while (a)
{
number = (s/a)%10;
if ((number)||(zero)||(a==1))
{
wDrawChar((number+48), x, y, color);
zero = 1;
}
x += 6;
a/=10;
}
}
//----------------------------------------
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?