1: /*
     2:  *  Guitar-ZyX(tm)::MasterControlProgram - portable guitar F/X controller
     3:  *  Copyright (C) 2009  Douglas McClendon
     4:  *
     5:  *  This program is free software: you can redistribute it and/or modify
     6:  *  it under the terms of the GNU General Public License as published by
     7:  *  the Free Software Foundation, version 3 of the License.
     8:  *
     9:  *  This program is distributed in the hope that it will be useful,
    10:  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
    11:  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    12:  *  GNU General Public License for more details.
    13:  *
    14:  *  You should have received a copy of the GNU General Public License
    15:  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
    16: */
    17: /*
    18: #############################################################################
    19: #############################################################################
    20: ## 
    21: ## gzmcpc::input: some source file
    22: ##
    23: #############################################################################
    24: ##
    25: ## Copyright 2008-2009 Douglas McClendon <dmc AT filteredperception DOT org>
    26: ##
    27: #############################################################################
    28: #############################################################################
    29: #
    30: */
    31: 
    32: 
    33: 
    34: 
    35: #include <nds.h> 
    36: 
    37: 
    38: #include "input.h" 
    39: 
    40: #include "modes.h" 
    41: 
    42: #include "network.h" 
    43: 
    44: #include "graphics.h" 
    45: 
    46: 
    47: 
    48: 
    49: touchPosition touchdata;
    50: u16 heldkeys = 0;
    51: u16 upkeys = 0;
    52: u16 downkeys = 0;
    53: 
    54: input_held_type heldover = IH_NONE;
    55: time_val heldover_sunset = {0, 0};
    56: 
    57: unsigned char input_poll_rate = DEFAULT_INPUT_POLL_RATE;
    58: time_val next_input_poll = {0, 0};
    59: 
    60: 
    61: 
    62: 
    63: void gzmcpc_poll_input(void) {
    64: 
    65:   //
    66:   // get input data
    67:   //
    68: 
    69:   touchRead(&touchdata);
    70: 
    71:   scanKeys();
    72: 
    73:   heldkeys = keysHeld();
    74: 
    75:   downkeys = keysDown();
    76: 
    77:   upkeys = keysUp();
    78: 
    79: }
    80: 
    81: 
    82: void global_input_processor(void) {
    83: 
    84:   //
    85:   // prepare input, i.e. transmogrify special held situations 
    86:   // into downkeys
    87:   //
    88: 
    89:   // only bother if sunset has expired
    90:   if (time_val_compare(num_ticks, heldover_sunset) < 0) {
    91:     
    92:     if ((heldkeys & KEY_L) && (heldkeys & KEY_R)) {
    93:       //
    94:       // held(L)+held(R)+something
    95:       //
    96:       
    97:       if (heldkeys & KEY_LEFT) {
    98: 	downkeys |= KEY_LEFT;
    99:       }
   100:       
   101:       if (heldkeys & KEY_RIGHT) {
   102: 	downkeys |= KEY_RIGHT;
   103:       }
   104:       
   105:       if (heldkeys & KEY_UP) {
   106: 	downkeys |= KEY_UP;
   107:       }
   108:       
   109:       if (heldkeys & KEY_DOWN) {
   110: 	downkeys |= KEY_DOWN;
   111:       }
   112:       
   113:     } else if (heldkeys & KEY_L) {
   114:       
   115:       if (heldkeys & KEY_A) {
   116: 	downkeys |= KEY_A;
   117:       }
   118:       
   119:       if (heldkeys & KEY_B) {
   120: 	downkeys |= KEY_B;
   121:       }
   122:       
   123:       if (heldkeys & KEY_X) {
   124: 	downkeys |= KEY_X;
   125:       }
   126:       
   127:       if (heldkeys & KEY_Y) {
   128: 	downkeys |= KEY_Y;
   129:       }
   130:       
   131:       if (heldkeys & KEY_LEFT) {
   132: 	downkeys |= KEY_LEFT;
   133:       }
   134:       
   135:       if (heldkeys & KEY_RIGHT) {
   136: 	downkeys |= KEY_RIGHT;
   137:       }
   138:       
   139:       if (heldkeys & KEY_UP) {
   140: 	downkeys |= KEY_UP;
   141:       }
   142:       
   143:       if (heldkeys & KEY_DOWN) {
   144: 	downkeys |= KEY_DOWN;
   145:       }
   146:       
   147:     } else if (heldkeys & KEY_R) {
   148:       
   149:       if (heldkeys & KEY_A) {
   150: 	downkeys |= KEY_A;
   151:       }
   152:       
   153:       if (heldkeys & KEY_B) {
   154: 	downkeys |= KEY_B;
   155:       }
   156:       
   157:       if (heldkeys & KEY_X) {
   158: 	downkeys |= KEY_X;
   159:       }
   160:       
   161:       if (heldkeys & KEY_Y) {
   162: 	downkeys |= KEY_Y;
   163:       }
   164: 
   165:       if (heldkeys & KEY_LEFT) {
   166: 	downkeys |= KEY_LEFT;
   167:       }
   168:       
   169:       if (heldkeys & KEY_RIGHT) {
   170: 	downkeys |= KEY_RIGHT;
   171:       }
   172:       
   173:       if (heldkeys & KEY_UP) {
   174: 	downkeys |= KEY_UP;
   175:       }
   176:       
   177:       if (heldkeys & KEY_DOWN) {
   178: 	downkeys |= KEY_DOWN;
   179:       }
   180:       
   181:     } else  {
   182:       
   183:       if (heldkeys & KEY_LEFT) {
   184: 	downkeys |= KEY_LEFT;
   185:       }
   186:       
   187:       if (heldkeys & KEY_RIGHT) {
   188: 	downkeys |= KEY_RIGHT;
   189:       }
   190:       
   191:       if (heldkeys & KEY_UP) {
   192: 	downkeys |= KEY_UP;
   193:       }
   194:       
   195:       if (heldkeys & KEY_DOWN) {
   196: 	downkeys |= KEY_DOWN;
   197:       }
   198:       
   199:     }
   200:     
   201:   } // end if heldover_sunset expired
   202: 
   203:   //
   204:   // handle input
   205:   //
   206:   if ((heldkeys & KEY_L) && (heldkeys & KEY_R)) {
   207:     //
   208:     // held(L)+held(R)+something
   209:     //
   210: 
   211:   } else if (heldkeys & KEY_L) {
   212:     //
   213:     // held(L)+something
   214:     //
   215: 
   216:     if (downkeys & KEY_START) {
   217: 
   218:       // TODO: functionify this
   219: 
   220:       if (network_state == NSM_OFFLINE) {
   221: 	
   222: 	// cursor rotating is online indicator
   223: 	cursor_rotating = 1;
   224: 	
   225: 	// begin network state machine, start starts a scan and subsequent 
   226: 	// conncection
   227: 	network_state = NSM_START;
   228: 	
   229:       } else {
   230: 	
   231: 	// go offline
   232: 	textout(TLT_STATUS, "player disconnected");
   233: 	network_state = NSM_OFFLINE;
   234: 	
   235:       } // end if/else (network_state == OFFLINE)
   236:     }
   237: 
   238:   } else if (heldkeys & KEY_R) {
   239:     //
   240:     // held(R)+something
   241:     //
   242: 
   243:   } else {
   244:     //
   245:     // no interesting modifer keys held
   246:     //
   247: 
   248:     if (downkeys & KEY_START) {
   249: 
   250:       if (mode == MODE_MAIN_MENU) {
   251: 	if (last_mode != MODE_NUM_MODES) system_xmode_new(last_mode);
   252:       } else {
   253: 	system_xmode_new(MODE_MAIN_MENU);
   254:       }
   255: 
   256:     }
   257: 
   258:   }
   259: 
   260: 
   261:   // touchpad handling is independent of modifiers (at the moment)
   262:   if ((downkeys & KEY_TOUCH) || (heldkeys & KEY_TOUCH)) {
   263: 
   264:   }
   265: 
   266: }
   267: