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