Skip to content

Commit

Permalink
builds on vista, arm7/print.c, support storage iofcs (r4tf.c) and cle…
Browse files Browse the repository at this point in the history
…anup
  • Loading branch information
saoret.one committed Jul 17, 2008
1 parent 7631312 commit 68d32fd
Show file tree
Hide file tree
Showing 33 changed files with 392 additions and 307 deletions.
3 changes: 2 additions & 1 deletion INSTALL
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ which is ready to be copied to your flashcard and run.
REQUIREMENTS
------------
The conf file (see $CONF in mkfile) and build process can require files which
are not in a default Inferno install, these can be found in the root/ directory.
are not in a default Inferno install, these can be found in the root/ directory,
and should be copied to their corresponding locations.

External tools
--------------
Expand Down
2 changes: 2 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ To setup/build your own i$CONF.nds file follow the INSTALL file.
After build launch the resulting i$CONF.nds file on your DS.

At boot time it prompts for the source location of the root fs,
choose your selection using the direction keys on your DS.
Currently the only usable option is `root from: kernel'
after the prompt, a window manager wm(1) instance is started
to interact/launch/control programs using a menu-like interface.

Expand Down
54 changes: 27 additions & 27 deletions arm7/audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
#include "../io.h"
#include "dat.h"
#include "fns.h"
#include "jtypes.h"
#include "ipc.h"
#include "audio.h"
#include "spi.h"

// TODO use SPIREG from io.h
void
PM_SetAmp(u8 control)
static void
pm_setamp(uchar control)
{
busywait();
SPIREG->ctl = Spiena | SpiDevpower | Spi1mhz | Spicont;
Expand All @@ -25,84 +23,86 @@ PM_SetAmp(u8 control)
SPIREG->data = control;
}

u8
MIC_ReadData(void) {
u16 res, res2;
static uchar
mic_readdata(void) {
ushort res[2];

busywait();
SPIREG->ctl = Spiena | SpiDevmic | Spi2mhz | Spicont;
SPIREG->data = 0xEC; // Touchscreen cmd format for AUX
busywait();
SPIREG->data = 0x00;
busywait();
res = SPIREG->data;
res[1] = SPIREG->data;
SPIREG->ctl = Spiena | SpiDevtouch | Spi2mhz;
SPIREG->data = 0x00;
busywait();
res2 = SPIREG->data;
return (((res & 0x7F) << 1) | ((res2>>7)&1));
res[0] = SPIREG->data;

return (((res[1] & 0x7F) << 1) | ((res[0] >> 7) & 0x01));
}

static u8* micbuf = 0;
static uchar *micbuf = 0;
static int micbuflen = 0;
static int curlen = 0;

static void
clock1intr(void)
clock1intr(void*)
{
if(micbuf && micbuflen > 0) {
*micbuf++ = MIC_ReadData() ^ 0x80;
*micbuf++ = mic_readdata() ^ 0x80;
--micbuflen;
curlen++;
}
intrclear(TIMER1bit, 0);
intrclear(TIMERAUDIObit, 0);
}

void
StartRecording(u8* buffer, int length)
startrecording(uchar* buffer, int length)
{
TimerReg *t = TIMERREG + 1;
TimerReg *t = TIMERREG + AUDIOtimer;

micbuf = buffer;
micbuflen = length;
curlen = 0;
PM_SetAmp(PM_AMP_ON);
pm_setamp(PM_AMP_ON);

// Setup a 16kHz timer
t->data = TIMER_BASE(Tmrdiv1) / 16000;
t->ctl = Tmrena | Tmrdiv1 | Tmrirq;
intrenable(TIMER1bit, clock1intr, 0);
intrenable(TIMERAUDIObit, clock1intr, 0);
}

int
StopRecording(void)
stoprecording(void)
{
TimerReg *t = TIMERREG + AUDIOtimer;

t->ctl &= ~Tmrena;
intrmask(TIMER1bit, 0);
intrmask(TIMERAUDIObit, 0);

PM_SetAmp(PM_AMP_OFF);
pm_setamp(PM_AMP_OFF);
micbuf = 0;
return curlen;
}

void
startSound(int rate, const void* d, u32 bytes, u8 ch, u8 vol, u8 pan, u8 pcm16bit)
static void
startSound(int hz, const void* d, ulong bytes, uchar ch, uchar vol, uchar pan, uchar pcm16bit)
{
SChanReg *schan = SCHANREG + ch;

POWERREG->pcr |= 1<<POWER_SOUND;
SNDREG->cr.ctl = Sndena | 0x7F;
SNDREG->cr.ctl = Sndena | Maxvol;

schan->tmr = SCHAN_FREQ(rate);
schan->tmr = SCHAN_BASE / hz;
schan->src = (ulong)d;
schan->wlen = bytes >> 2;
schan->cr.vol = vol;
schan->cr.pan = pan;
schan->cr.ctl |= SCena | SC1shot | (pcm16bit? SCpcm16bit: SCpcm8bit);
}

int
static int
getFreeSoundChannel(void)
{
int i;
Expand All @@ -117,7 +117,7 @@ getFreeSoundChannel(void)
void
vblankaudio(void)
{
u32 i;
ulong i;
TransferSound *snd = IPC->soundData;

IPC->soundData = 0;
Expand Down
13 changes: 4 additions & 9 deletions arm7/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ enum {
Maxvol = 0x7f,
};

/* usage: SCHANREG->tmr = SCHAN_FREQ(hz) */
#define SCHAN_FREQ(hz) ((-0x1000000 / (hz)))
/* usage: SCHANREG->tmr = SCHAN_BASE / hz */
#define SCHAN_BASE (-0x1000000)

/*
* Master sound
Expand Down Expand Up @@ -78,10 +78,5 @@ enum {

void vblankaudio(void);

/* Read a byte from the microphone */
u8 MIC_ReadData(void);

void StartRecording(u8* buffer, int length);
int StopRecording(void);

void PM_SetAmp(u8 control);
void startrecording(uchar *buffer, int length);
int stoprecording(void);
66 changes: 66 additions & 0 deletions arm7/dat.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,70 @@ enum {
enum {
WIFItimer = 0,
AUDIOtimer = 1,

TIMERWIFIbit = TIMER0bit+WIFItimer,
TIMERAUDIObit = TIMER0bit+AUDIOtimer,
};

typedef struct TransferSoundData TransferSoundData;
struct TransferSoundData {
const void *data;
ulong len;
ulong rate;
uchar vol;
uchar pan;
uchar fmt;
uchar PADDING;
};

typedef struct TransferSound TransferSound;
struct TransferSound {
TransferSoundData d[16];
uchar count;
uchar PADDING[3];
};

#define IPCMEM 0x027FF000
#define IPC ((volatile TransferRegion*)IPCMEM)
typedef struct TransferRegion TransferRegion;
struct TransferRegion {
ushort touchX, touchY; // TSC X, Y
ushort touchXpx, touchYpx; // TSC X, Y pixel values
short touchZ1, touchZ2; // TSC x-panel measurements
int td1, td2; // TSC temperature diodes
ushort temp; // TSC computed temperature

ushort buttons; // X, Y, /PENIRQ buttons

ushort hbt;

union {
uchar curtime[8]; // current time response from RTC

struct {
uchar cmd;
uchar year; // add 2000 to get 4 digit year
uchar month; // 1 to 12
uchar day; // 1 to (days in month)

uchar weekday; // day of week
uchar hours; // 0 to 11 for AM, 52 to 63 for PM
uchar minutes; // 0 to 59
uchar seconds; // 0 to 59
} rtc;
} time;
int unixTime;

ushort batt; // battery life ?? hopefully. :)
ushort aux; // i have no idea...

/* Don't rely on these below, will change or be removed in the future */
TransferSound *soundData;

ulong mailAddr;
ulong mailData;
uchar mailRead;
uchar mailBusy;
ulong mailSize;
};

28 changes: 13 additions & 15 deletions arm7/dma.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,32 @@
#include "../mem.h"
#include "../io.h"
#include <kern.h>
#include "jtypes.h"
#include "spi.h"

static void
dmaCopyWords(int8 channel, const void* src, void* dest, uint32 size, uchar sync)
dmaCopyWords(char channel, const void* src, void* dest, ulong size, uchar sync)
{
DmaReg *dmareg;
if (channel < 0 || channel > 3)
return;

dmareg = DMAREG + channel;
dmareg->src = (uint32)src;
dmareg->dst = (uint32)dest;
dmareg->src = (ulong)src;
dmareg->dst = (ulong)dest;
dmareg->ctl = Dmatxwords | (size>>2);
if (sync)
while(dmareg->ctl & Dmabusy);
}

static void
dmaCopyHalfWords(int8 channel, const void* src, void* dest, uint32 size, uchar sync)
dmaCopyHalfWords(char channel, const void* src, void* dest, ulong size, uchar sync)
{
DmaReg *dmareg;
if (channel < 0 || channel > 3)
return;

dmareg = DMAREG + channel;
dmareg->src = (uint32)src;
dmareg->dst = (uint32)dest;
dmareg->src = (ulong)src;
dmareg->dst = (ulong)dest;
dmareg->ctl = Dmatxhwords | (size>>1);
if (sync)
while(dmareg->ctl & Dmabusy);
Expand All @@ -38,31 +36,31 @@ dmaCopyHalfWords(int8 channel, const void* src, void* dest, uint32 size, uchar s
#define dmaCopy(src, dest, size, sync) dmaCopyWords(3, src, dest, size, sync)

static void
dmaFillWords(const void* src, void* dest, uint32 size)
dmaFillWords(const void* src, void* dest, ulong size)
{
DmaReg *dmareg;

dmareg = DMAREG + 3;
dmareg->src = (uint32)src;
dmareg->dst = (uint32)dest;
dmareg->src = (ulong)src;
dmareg->dst = (ulong)dest;
dmareg->ctl = Dmasrcfix | Dmatxwords | (size>>2);
while(dmareg->ctl & Dmabusy);
}

static void
dmaFillHalfWords(const void* src, void* dest, uint32 size)
dmaFillHalfWords(const void* src, void* dest, ulong size)
{
DmaReg *dmareg;

dmareg = DMAREG + 3;
dmareg->src = (uint32)src;
dmareg->dst = (uint32)dest;
dmareg->src = (ulong)src;
dmareg->dst = (ulong)dest;
dmareg->ctl = Dmasrcfix | Dmatxhwords | (size>>1);
while(dmareg->ctl & Dmabusy);
}

static int
dmaBusy(int8 channel)
dmaBusy(char channel)
{
DmaReg *dmareg;
if (channel < 0 || channel > 3)
Expand Down
6 changes: 5 additions & 1 deletion arm7/fns.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
void intrmask(int v, int tbdf);
void intrunmask(int v, int tbdf);
void intrclear(int v, int tbdf);
void intrenable(int v, void (*r)(void), int tbdf);
void intrenable(int v, void (*r)(void*), int tbdf);
void trapinit(void);

void nds_fifo_send(ulong v);
int nbfifoput(ulong cmd, ulong v);
void fifoput(ulong cmd, ulong v);


void swiSoftReset(void);
void swiWaitForVBlank(void);
void swiDelay(ulong);
10 changes: 0 additions & 10 deletions arm7/jtypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,6 @@ typedef volatile s16 vs16;
typedef volatile s32 vs32;
typedef volatile s64 vs64;

typedef struct touchPosition touchPosition;
struct touchPosition {
int16 x;
int16 y;
int16 px;
int16 py;
int16 z1;
int16 z2;
};

typedef enum { false, true } bool;

// Handy function pointer typedefs
Expand Down
Loading

0 comments on commit 68d32fd

Please sign in to comment.