From 6aaccb0eb39242c43b94466fa22806bf159a7d9e Mon Sep 17 00:00:00 2001 From: Raphael Assenat Date: Tue, 27 Oct 2015 23:50:18 -0400 Subject: [PATCH] Half the memory footprint for reception code --- gcn64_protocol.c | 74 +++++++++--------------------------------------- gcn64txrx.S | 63 +++++++++++++++++++++++++++++++++-------- 2 files changed, 65 insertions(+), 72 deletions(-) diff --git a/gcn64_protocol.c b/gcn64_protocol.c index 5195e60..bb40e85 100644 --- a/gcn64_protocol.c +++ b/gcn64_protocol.c @@ -71,54 +71,6 @@ void gcn64_protocol_getBytes(int offset, int n_bytes, unsigned char *dstbuf) } } -/* \brief Decode the received length of low/high states to byte-per-bit format - * - * The result is in workbuf. - * - **/ -static void gcn64_decodeWorkbuf(unsigned int count) -{ - unsigned int i; - volatile unsigned char *output = gcn64_workbuf; - volatile unsigned char *input = gcn64_workbuf; - unsigned char t; - - // - // ________ - // ________/ - // - // [i*2] [i*2+1] - // - // ________________ - // 0 : ____/ - // ____ - // 1 : ________________/ - // - // The timings on a real N64 are - // - // 0 : 1 us low, 3 us high - // 1 : 3 us low, 1 us high - // - // However, HORI pads use something similar to - // - // 0 : 1.5 us low, 4.5 us high - // 1 : 4.5 us low, 1.5 us high - // - // - // No64 us = microseconds - - // This operation takes approximately 100uS on 64bit gamecube messages - for (i=0; i 127 (approx 50uS timeout) + brmi timeout_waitlow ; > 127 (approx 50uS timeout) sbic GCN64_DATA_PIN, GCN64_DATA_BIT rjmp waitlow_lp - adiw xl, 1 ; count this timed low level + adiw xl, 1 ; count this bit breq overflow ; > 255 - st z+,r18 + +#if 0 + st z+, r19 + st z+, r18 + rjmp waithigh +#else + ; Compare the low period and the high period. + sub r19, r18 + brcs got1 +got0: + st z+, __zero_reg__ + rjmp waithigh +got1: + st z+,r20 +#endif waithigh: - ldi r18, TIMING_OFFSET + ldi r19, TIMING_OFFSET waithigh_lp: - inc r18 + inc r19 brmi timeout ; > 127 sbis GCN64_DATA_PIN, GCN64_DATA_BIT rjmp waithigh_lp - adiw xl, 1 ; count this timed high level - - breq overflow ; > 255 - st z+,r18 - rjmp waitlow +timeout_waitlow: + adiw xl, 1 ; + breq overflow ; > 255 + + ; Compare the low period and the high period. + sub r19, r21 + brcs lastwas1 +lastwas0: + st z+, __zero_reg__ + rjmp rxdone +lastwas1: + st z+,r20 + rjmp rxdone + overflow: + clr xl + clr xh timeout: +rxdone: ; Return the number if received bits in r24,r25 mov r24, xl ; yl mov r25, xh ; yh