Deja Vu???? posted this at the other spot already...
but I like this place so..
here you go.. Kosfree.. if you're using Marcus's Maple stuff,
just make sure you re-organise the parameters, mine is sent
as it is seen on the maple, this should be enough to get the keyboard
going as well.. same location as digital, except 1byte=shift/alt status
next byte is the LEDs, and then 6chars of 6 keys being pressed..
a note of caution, if you start getting back 0xFFFF's then toss the
data and poll it again.. it does that sometimes...
Code:
#include <math.h>
unsigned char dmabuffer[2128];
void *maple_docmd(int port, int unit, int cmd, int len, void *data)
{
Â*unsigned long *sbuf, *rbuf;
Â*int dst, src;
Â*src = port << 6;
Â*if(unit==0){
Â* Â* Â* Â*dst=0x0020;
Â*}else{
Â* Â* Â* Â*dst=((1<<(unit-1))&0x1f);
Â*}
Â*dst=((port<<6)+dst);
Â*rbuf = (unsigned long *) ((((unsigned long)dmabuffer+0x20)& 0xffffffe0)|0xa0000000);
Â*sbuf = (unsigned long *) (((unsigned char *)rbuf) + 1024);
Â* while((*(volatile unsigned long *)(0xa05f6c18)) & 1);//DMA Busy?
Â**(volatile unsigned long *)(0xa05f6c04) = ((unsigned long)sbuf) & 0xfffffff;
Â**sbuf++ = len + (port * 0x10000) + 0x80000000;
Â**sbuf++ = ((unsigned long)rbuf) & 0xfffffff;
Â**sbuf++ = (cmd & 0xff) + (dst * 0x100) + (src *0x10000) + (len * 0x1000000);
Â* if(len > 0) {
Â* Â* Â* Â* Â*unsigned long *param = data;
Â* Â* Â* Â* Â*int i;
Â* Â* Â* Â* Â*for(i=0; i<len; i++)*sbuf++ = *param++;
Â*}
Â**(volatile unsigned long *)(0xa05f6c18) = 1;//do dma..
Â* while((*(volatile unsigned long *)(0xa05f6c18)) & 1);
Â* return rbuf;
}//end
void delay(int t){
Â* Â* Â*float x = 1;
Â* Â* Â*while(t-->0)x=cos(x);
}//end delay
void main(void)
{
Â*unsigned int i=0,params[2];
Â*unsigned short *res,digital,trigger,joystick;
Â*//maple init
Â**(volatile unsigned long *)(0xa05f6c8c)= 0x6155404f;
Â**(volatile unsigned long *)(0xa05f6c10) = 0;
Â**(volatile unsigned long *)(0xa05f6c80) = 0xc3500000;
Â**(volatile unsigned long *)(0xa05f6c14) = 1;
while(i==0){
Â* Â* Â* Â* Â*params[0]=0x01000000; //controller
Â* Â* Â* Â* Â*do res = maple_docmd(0, 0, 9, 1, params);
Â* Â* Â* Â* Â*while(*res == -4);
Â* Â* Â* Â* Â*res+=4;//Dpad and buttons
Â* Â* Â* Â* Â*digital=*res; //for explination purposes..
Â* Â* Â* Â* Â**res++; Â* Â* Â* //but just make this a simple struct
Â* Â* Â* Â* Â*trigger=*res;
Â* Â* Â* Â* Â**res++;
Â* Â* Â* Â* Â*joystick=*res;//didn't bother.. but same as triggers
Â* Â* Â* Â* Â*
Â* Â* Â* Â* Â*printf("RT:%d\n",(trigger&0x00ff));
Â* Â* Â* Â* Â*printf("LT:%d\n\n",(trigger/=0x100));
Â* Â* Â* Â* Â*if(!(digital&0x0010))printf("Up\n");
Â* Â* Â* Â* Â*if(!(digital&0x0020))printf("Down\n");
Â* Â* Â* Â* Â*if(!(digital&0x0080))printf("Right\n");
Â* Â* Â* Â* Â*if(!(digital&0x0040))printf("Left\n");
Â* Â* Â* Â* Â*if(!(digital&0x0200))printf("Y\n");
Â* Â* Â* Â* Â*if(!(digital&0x0004))printf("A\n");
Â* Â* Â* Â* Â*if(!(digital&0x0002))printf("B\n");
Â* Â* Â* Â* Â*if(!(digital&0x0400))printf("X\n");
Â* Â* Â* Â* Â*if(!(digital&0x0008)){
Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* printf("START\n");
Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â* Â*i=1;//and exit
Â* Â* Â* Â* Â*}
Â* Â* Â* Â* Â*delay(500000);
}//end while
Bookmarks