1414#define N64_PINB_LOW DDRB |= pincode
1515#define N64_PINB_QUERY (PINB & pincode)
1616
17- void N64Controller::set_up () {
18- n64_PIN = 2 ; // might also be set/changed by constructor or begin() afterwards
19- n64_key_Dup = false ;
20- n64_key_Ddown = false ;
21- n64_key_Dleft = false ;
22- n64_key_Dright = false ;
23- n64_key_Start = false ;
24- n64_key_Z = false ;
25- n64_key_A = false ;
26- n64_key_B = false ;
27- n64_key_Cup = false ;
28- n64_key_Cdown = false ;
29- n64_key_Cleft = false ;
30- n64_key_Cright = false ;
31- n64_key_L = false ;
32- n64_key_R = false ;
33- n64_key_X = 0 ;
34- n64_key_Y = 0 ;
35- }
36-
3717N64Controller::N64Controller () {
38- set_up ();
3918}
19+
4020N64Controller::N64Controller (int serialPin) {
41- set_up ();
4221 n64_PIN = serialPin;
4322}
4423void N64Controller::begin (int serialPin) {
@@ -89,7 +68,6 @@ void N64Controller::begin() {
8968 } else {
9069 N64_init_PINB (n64_pincode);
9170 }
92- translate_raw_data ();
9371}
9472
9573void N64Controller::N64_init_PIND (char pincode) {
@@ -405,89 +383,44 @@ void N64Controller::print_N64_status()
405383 // bits: 0, 0, L, R, Cup, Cdown, Cleft, Cright
406384 Serial.println ();
407385 Serial.print (" Start: " );
408- Serial.println (N64_status. data1 & 16 ? 1 : 0 );
386+ Serial.println (Start () );
409387
410388 Serial.print (" Z: " );
411- Serial.println (N64_status. data1 & 32 ? 1 : 0 );
389+ Serial.println (Z () );
412390
413391 Serial.print (" B: " );
414- Serial.println (N64_status. data1 & 64 ? 1 : 0 );
392+ Serial.println (B () );
415393
416394 Serial.print (" A: " );
417- Serial.println (N64_status. data1 & 128 ? 1 : 0 );
395+ Serial.println (A () );
418396
419397 Serial.print (" L: " );
420- Serial.println (N64_status. data2 & 32 ? 1 : 0 );
398+ Serial.println (L () );
421399 Serial.print (" R: " );
422- Serial.println (N64_status. data2 & 16 ? 1 : 0 );
400+ Serial.println (R () );
423401
424402 Serial.print (" Cup: " );
425- Serial.println (N64_status. data2 & 0x08 ? 1 : 0 );
403+ Serial.println (C_up () );
426404 Serial.print (" Cdown: " );
427- Serial.println (N64_status. data2 & 0x04 ? 1 : 0 );
405+ Serial.println (C_down () );
428406 Serial.print (" Cright:" );
429- Serial.println (N64_status. data2 & 0x01 ? 1 : 0 );
407+ Serial.println (C_right () );
430408 Serial.print (" Cleft: " );
431- Serial.println (N64_status. data2 & 0x02 ? 1 : 0 );
409+ Serial.println (C_left () );
432410
433411 Serial.print (" Dup: " );
434- Serial.println (N64_status. data1 & 0x08 ? 1 : 0 );
412+ Serial.println (D_up () );
435413 Serial.print (" Ddown: " );
436- Serial.println (N64_status. data1 & 0x04 ? 1 : 0 );
414+ Serial.println (D_down () );
437415 Serial.print (" Dright:" );
438- Serial.println (N64_status. data1 & 0x01 ? 1 : 0 );
416+ Serial.println (D_right () );
439417 Serial.print (" Dleft: " );
440- Serial.println (N64_status. data1 & 0x02 ? 1 : 0 );
418+ Serial.println (D_left () );
441419
442420 Serial.print (" Stick X:" );
443- Serial.println (N64_status. stick_x , DEC);
421+ Serial.println (axis_x () , DEC);
444422 Serial.print (" Stick Y:" );
445- Serial.println (N64_status.stick_y , DEC);
446- }
447-
448- void N64Controller::translate_raw_data ()
449- {
450- // The get_N64_status function sloppily dumps its data 1 bit per byte
451- // into the get_status_extended char array. It's our job to go through
452- // that and put each piece neatly into the struct N64_status
453- int i;
454- memset (&N64_status, 0 , sizeof (N64_status));
455- // line 1
456- // bits: A, B, Z, Start, Dup, Ddown, Dleft, Dright
457- for (i=0 ; i<8 ; i++) {
458- N64_status.data1 |= N64_raw_dump[i] ? (0x80 >> i) : 0 ;
459- }
460- // line 2
461- // bits: 0, 0, L, R, Cup, Cdown, Cleft, Cright
462- for (i=0 ; i<8 ; i++) {
463- N64_status.data2 |= N64_raw_dump[8 +i] ? (0x80 >> i) : 0 ;
464- }
465- // line 3
466- // bits: joystick x value
467- // These are 8 bit values centered at 0x80 (128)
468- for (i=0 ; i<8 ; i++) {
469- N64_status.stick_x |= N64_raw_dump[16 +i] ? (0x80 >> i) : 0 ;
470- }
471- for (i=0 ; i<8 ; i++) {
472- N64_status.stick_y |= N64_raw_dump[24 +i] ? (0x80 >> i) : 0 ;
473- }
474-
475- n64_key_A = (bool )N64_raw_dump[0 ];
476- n64_key_B = (bool )N64_raw_dump[1 ];
477- n64_key_Z = (bool )N64_raw_dump[2 ];
478- n64_key_Start = (bool )N64_raw_dump[3 ];
479- n64_key_Dup = (bool )N64_raw_dump[4 ];
480- n64_key_Ddown = (bool )N64_raw_dump[5 ];
481- n64_key_Dleft = (bool )N64_raw_dump[6 ];
482- n64_key_Dright = (bool )N64_raw_dump[7 ];
483- n64_key_L = (bool )N64_raw_dump[10 ];
484- n64_key_R = (bool )N64_raw_dump[11 ];
485- n64_key_Cup = (bool )N64_raw_dump[12 ];
486- n64_key_Cdown = (bool )N64_raw_dump[13 ];
487- n64_key_Cleft = (bool )N64_raw_dump[14 ];
488- n64_key_Cright = (bool )N64_raw_dump[15 ];
489- n64_key_X = (int ) N64_status.stick_x ;
490- n64_key_Y = (int ) N64_status.stick_y ;
423+ Serial.println (axis_y (), DEC);
491424}
492425
493426void N64Controller::update () {
@@ -503,5 +436,4 @@ void N64Controller::update() {
503436 N64_PINB_get (n64_pincode);
504437 interrupts ();
505438 }
506- translate_raw_data ();
507439}
0 commit comments