From b7b07a37eeb64c5a15ccf58e687cdd0934d36094 Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Wed, 28 Oct 2015 23:30:26 -0400 Subject: [PATCH] Do away with the gcn64 work buffer (saves more memory!) --- gamecube.c | 25 ++++++++++++------------- gcn64_protocol.c | 45 ++++++++++++++------------------------------- gcn64_protocol.h | 5 +---- gcn64txrx.h | 2 +- hiddata.c | 3 +-- main.c | 2 ++ n64.c | 28 ++++++++++++++-------------- 7 files changed, 45 insertions(+), 65 deletions(-) diff --git a/gamecube.c b/gamecube.c index b9e07b7..e978572 100644 --- a/gamecube.c +++ b/gamecube.c @@ -41,7 +41,7 @@ static void gamecubeInit(void) gamecubeUpdate(); } -void gc_decodeAnswer() +void gc_decodeAnswer(unsigned char data[8]) { unsigned char x,y,cx,cy; @@ -87,14 +87,14 @@ void gc_decodeAnswer() */ last_built_report.pad_type = PAD_TYPE_GAMECUBE; - last_built_report.gc.buttons = gcn64_protocol_getByte(0) | gcn64_protocol_getByte(8) << 8; - x = gcn64_protocol_getByte(16); - y = gcn64_protocol_getByte(24); - cx = gcn64_protocol_getByte(32); - cy = gcn64_protocol_getByte(40); - last_built_report.gc.lt = gcn64_protocol_getByte(48); - last_built_report.gc.rt = gcn64_protocol_getByte(56); - gcn64_protocol_getBytes(0, 8, last_built_report.gc.raw_data); + last_built_report.gc.buttons = data[0] | data[1] << 8; + x = data[2]; + y = data[3]; + cx = data[4]; + cy = data[5]; + last_built_report.gc.lt = data[6]; + last_built_report.gc.rt = data[7]; + memcpy(last_built_report.gc.raw_data, data, 8); if (origins_set) { last_built_report.gc.x = ((int)x-(int)orig_x); @@ -117,8 +117,7 @@ void gc_decodeAnswer() static char gamecubeUpdate() { - //unsigned char tmp=0; - unsigned char tmpdata[8]; + unsigned char tmpdata[GC_GETSTATUS_REPLY_LENGTH]; unsigned char count; #if 0 @@ -147,12 +146,12 @@ static char gamecubeUpdate() tmpdata[1] = GC_GETSTATUS2; tmpdata[2] = GC_GETSTATUS3(gc_rumbling); - count = gcn64_transaction(tmpdata, 3); + count = gcn64_transaction(tmpdata, 3, tmpdata, GC_GETSTATUS_REPLY_LENGTH); if (count != GC_GETSTATUS_REPLY_LENGTH) { return 1; } - gc_decodeAnswer(); + gc_decodeAnswer(tmpdata); return 0; } diff --git a/gcn64_protocol.c b/gcn64_protocol.c index 14cec03..ce324ec 100644 --- a/gcn64_protocol.c +++ b/gcn64_protocol.c @@ -25,9 +25,6 @@ #undef FORCE_KEYBOARD -#define GCN64_BUF_SIZE 40 -static unsigned char gcn64_workbuf[GCN64_BUF_SIZE]; - /******** IO port definitions and options **************/ #ifndef STK525 #define GCN64_DATA_PORT PORTD @@ -45,20 +42,6 @@ static unsigned char gcn64_workbuf[GCN64_BUF_SIZE]; #define DISABLE_INTS_DURING_COMM - -/* Read a byte from the buffer (where 1 byte is 1 bit). - * MSb first. - */ -unsigned char gcn64_protocol_getByte(int offset) -{ - return gcn64_workbuf[offset/8]; -} - -void gcn64_protocol_getBytes(int offset, int n_bytes, unsigned char *dstbuf) -{ - memcpy(dstbuf, gcn64_workbuf + offset/8, n_bytes); -} - void gcn64protocol_hwinit(void) { // data as input @@ -79,22 +62,22 @@ void gcn64protocol_hwinit(void) * * The result is in gcn64_workbuf. */ -int gcn64_transaction(unsigned char *data_out, int data_out_len) +unsigned char gcn64_transaction(const unsigned char *tx, int tx_len, unsigned char *rx, unsigned char rx_max) { int count; unsigned char sreg = SREG; -// int i; + //int i; #ifdef DISABLE_INTS_DURING_COMM cli(); #endif - gcn64_sendBytes(data_out, data_out_len); - count = gcn64_receiveBytes(gcn64_workbuf, 0); + gcn64_sendBytes(tx, tx_len); + count = gcn64_receiveBytes(rx, rx_max); SREG = sreg; #if 0 printf("Count: %d { ", count); for (i=0; i