void internal_ReadController(int Control, BYTE *Command) { switch (Command[2]) { case 1: if (Controls[Control].Present) { BUTTONS Keys; #ifdef VCR_SUPPORT VCR_getKeys(Control, &Keys); #else getKeys(Control, &Keys); #endif *((unsigned long *)(Command + 3)) = Keys.Value; #ifdef COMPARE_CORE check_input_sync(Command+3); #endif } break; case 2: // read controller pack if (Controls[Control].Present) { if (Controls[Control].Plugin == PLUGIN_RAW) if (controllerCommand) readController(Control, Command); } break; case 3: // write controller pack if (Controls[Control].Present) { if (Controls[Control].Plugin == PLUGIN_RAW) if (controllerCommand) readController(Control, Command); } break; } }
void update_pif_read() { int i=0, channel=0; #ifdef DEBUG_PIF printf("read\n"); print_pif(); #endif while (i<0x40) { switch(PIF_RAMb[i]) { case 0x00: channel++; if (channel > 6) i=0x40; break; case 0xFE: i = 0x40; break; case 0xFF: break; case 0xB4: case 0x56: case 0xB8: break; default: if (!(PIF_RAMb[i] & 0xC0)) { if (channel < 4) { if (Controls[channel].Present && Controls[channel].RawData) readController(channel, &PIF_RAMb[i]); else internal_ReadController(channel, &PIF_RAMb[i]); } i += PIF_RAMb[i] + (PIF_RAMb[(i+1)] & 0x3F) + 1; channel++; } else i=0x40; } i++; } readController(-1, NULL); #ifdef DEBUG_PIF print_pif(); #endif }
static void readPortChannel(Xml& xml, int midiPort) { int idx = 0; //torbenh for (;;) { Xml::Token token = xml.parse(); if (token == Xml::Error || token == Xml::End) break; QString tag = xml.s1(); switch (token) { case Xml::TagStart: if (tag == "controller") { readController(xml, midiPort, idx); } else xml.skip(tag); break; case Xml::Attribut: if (tag == "idx") idx = xml.s2().toInt(); break; case Xml::TagEnd: if (tag == "channel") return; default: break; } } }
int main(int argc, char **argv) { if (!openController()) { fprintf(stderr, "Could not open controller.\r\n"); return(-1); } unsigned int last=0; while (true) { if (controllerHasData()) { unsigned int c = readController(); if (c & P1_LEFT) printf("P1_LEFT "); if (c & P1_RIGHT) printf("P1_RIGHT "); if (c & P1_UP) printf("P1_UP "); if (c & P1_DOWN) printf("P1_DOWN "); if (c & P2_LEFT) printf("P2_LEFT "); if (c & P2_RIGHT) printf("P2_RIGHT "); if (c & P2_UP) printf("P2_UP "); if (c & P2_DOWN) printf("P2_DOWN "); if (c & START) printf("START "); if (c & SELECT) printf("SELECT "); if (c & P1_FIRE) printf("P1_FIRE "); if (c & P2_FIRE) printf("P2_FIRE "); printf("%i (%i)\n", c, c-last); fflush(stdout); last = c; } } }
void readSoftwareRadio(Element &headElem, RadioRepresentation& theRadio) { //Check for illegal nodes here Iterator< Node > c; for ( c = c.begin(&headElem); c != c.end(); c++ ) { if(c->Type() == TiXmlNode::ELEMENT) { string s = c->Value(); if(s != "controller" && s != "engine" && s!= "link") { LOG(LFATAL) << "Illegal element in xml file: " << s; throw XmlParsingException("Illegal element in xml file: " + s); } } } //Parse all the controllers Iterator< Element > child("controller"); for ( child = child.begin(&headElem); child != child.end(); child++ ) { ControllerDescription con = readController(*child); theRadio.addControllerDescription(con); } //Parse all the engines Iterator< Element > child1("engine"); for ( child1 = child1.begin(&headElem); child1 != child1.end(); child1++ ) { EngineDescription eng = readEngine(*child1); theRadio.addEngineDescription(eng); } //Parse all the links Iterator< Element > child2("link"); for ( child2 = child2.begin(&headElem); child2 != child2.end(); child2++ ) { LinkDescription link = readLink(*child2); theRadio.addLinkDescription(link); } }
void update_pif_read() { int i=0, channel=0; #ifdef DEBUG_PIF printf("read\n"); print_pif(); #endif while (i<0x40) { switch(PIF_RAMb[i]) { case 0x00: channel++; if (channel > 6) i=0x40; break; case 0xFE: i = 0x40; break; case 0xFF: break; case 0xB4: case 0x56: case 0xB8: break; default: #ifdef __WIN32__ if (KailleraRunningGame) { if (!(PIF_RAMb[i] & 0xC0)) { if (channel == 0) { getKeys(0,&NetPlayKeys); NetPlayInformation[0].KailleraMessageType = 0x01; NetPlayInformation[0].KailleraMessage = NetPlayKeys.Value; NetPlayKeys.Value = 0x00; KailleraModifyPlayValues(NetPlayInformation,5); } if (channel < 4 && Controls[channel].Present) { if (NetPlayInformation[channel].KailleraMessageType == 0x01) { NetPlayKeys.Value = NetPlayInformation[channel].KailleraMessage; } else { NetPlayKeys.Value = 0x0000; } // VCR_getKeys(channel, &NetPlayKeys); *((unsigned long *)(&PIF_RAMb[i] + 3)) = NetPlayKeys.Value; } i += PIF_RAMb[i] + (PIF_RAMb[(i+1)] & 0x3F) + 1; channel++; } else { i=0x40; } } else { #endif if (!(PIF_RAMb[i] & 0xC0)) { if (channel < 4) { if (Controls[channel].Present && Controls[channel].RawData) readController(channel, &PIF_RAMb[i]); else internal_ReadController(channel, &PIF_RAMb[i]); } i += PIF_RAMb[i] + (PIF_RAMb[(i+1)] & 0x3F) + 1; channel++; } else i=0x40; } #ifdef __WIN32__ } #endif i++; } readController(-1, NULL); #ifdef DEBUG_PIF print_pif(); #endif }
int menu(SDL_Surface *screen, SDL_Surface *vscreen) { unsigned frameStart; bool leave = false; // Load and prepare the background image SDL_Surface *loadedImage = IMG_Load("title.png"); if (!loadedImage) { fprintf(stderr, "Could not load title image.\n"); return MENU_ERROR; } SDL_Surface *background = SDL_DisplayFormatAlpha(loadedImage); SDL_FreeSurface(loadedImage); TTF_Font *fontSmall = TTF_OpenFont("FreeSansBold.ttf", 10); TTF_Font *fontLarge = TTF_OpenFont("FreeSansBold.ttf", 12); if (!fontSmall || !fontLarge) { fprintf(stderr, "Could not load font.\n"); return MENU_ERROR; } SDL_Color playerFontColour, autuinFontColour; playerFontColour.r = playerFontColour.g = playerFontColour.b = 230; autuinFontColour.r = autuinFontColour.g = autuinFontColour.b = 200; SDL_Surface *onePlayerTextSmall = TTF_RenderText_Solid(fontSmall, "ONE PLAYER", playerFontColour); SDL_Surface *twoPlayerTextSmall = TTF_RenderText_Solid(fontSmall, "TWO PLAYER", playerFontColour); SDL_Surface *onePlayerTextLarge = TTF_RenderText_Solid(fontLarge, "ONE PLAYER", playerFontColour); SDL_Surface *twoPlayerTextLarge = TTF_RenderText_Solid(fontLarge, "TWO PLAYER", playerFontColour); SDL_Surface *autuinText = TTF_RenderText_Solid(fontSmall, "(C) 2012 AUTOMATIC TURQUOISE INTERNATIONAL", autuinFontColour); TTF_CloseFont(fontSmall); TTF_CloseFont(fontLarge); SDL_Rect onePlayerRectSmall, onePlayerRectLarge; SDL_Rect twoPlayerRectSmall, twoPlayerRectLarge; onePlayerRectSmall.x = 60; onePlayerRectLarge.x = 50; twoPlayerRectSmall.x = 190; twoPlayerRectLarge.x = 180; onePlayerRectSmall.y = twoPlayerRectSmall.y = 172; onePlayerRectLarge.y = twoPlayerRectLarge.y = 170; SDL_Rect autuinRect; autuinRect.x = 35; autuinRect.y = 187; Uint32 black = SDL_MapRGB(vscreen->format, 0, 0, 0); Mix_Chunk *boop = Mix_LoadWAV("boop.wav"); Mix_Chunk *theme = Mix_LoadWAV("title.wav"); if (!boop || !theme) { fprintf(stderr, "Could not load audio.\n"); return MENU_ERROR; } // Initialize the star locations and speeds Star stars[NUM_STARS]; for (int i=0; i<NUM_STARS; i++) { stars[i].x = random() / ((float) RAND_MAX) * SCREEN_WIDTH; stars[i].y = random() / ((float) RAND_MAX) * SCREEN_HEIGHT; float intensity = random() / (float) RAND_MAX; unsigned char colourIntensity = (intensity * 155) + 100; stars[i].speed = intensity * .2; stars[i].colour = SDL_MapRGB(vscreen->format, colourIntensity, colourIntensity, colourIntensity); } Mix_PlayChannel(-1, theme, -1); char selectedOption = 0; unsigned int frame = 0; while (!leave) { // Handle events frameStart = SDL_GetTicks(); SDL_Event e; while (SDL_PollEvent(&e)) switch (e.type) { case SDL_KEYDOWN: switch (e.key.keysym.sym) { case SDLK_UP: case SDLK_LEFT: if (selectedOption != 0) Mix_PlayChannel(-1, boop, 0); selectedOption = 0; frame = 0; break; case SDLK_DOWN: case SDLK_RIGHT: if (selectedOption != 1) Mix_PlayChannel(-1, boop, 0); selectedOption = 1; frame = 0; break; case SDLK_ESCAPE: selectedOption = -1; leave = true; break; case SDLK_UNKNOWN: // Suspend button selectedOption = -2; leave = true; break; case SDLK_RETURN: leave = true; break; case SDL_QUIT: selectedOption = -1; leave = true; break; } } // Debounce any keys currently down (wait 1 sec) if (frame >= FPS && controllerHasData()) { unsigned int c = readController(); if ((c & P1_LEFT) && selectedOption != 0) { Mix_PlayChannel(-1, boop, 0); selectedOption = 0; } else if ((c & P1_RIGHT) && selectedOption != 1) { Mix_PlayChannel(-1, boop, 0); selectedOption = 1; } else if (c & P1_FIRE) { leave = true; } else if (c & SELECT) { selectedOption = -1; leave = true; } frame = FPS; } // Draw the frame SDL_FillRect(vscreen, NULL, black); SDL_LockSurface(vscreen); Uint32 *s = (Uint32 *) vscreen->pixels; for (unsigned int i=0; i<NUM_STARS; i++) { unsigned x = stars[i].x, y = stars[i].y; *(s + (y * SCREEN_WIDTH) + x) = stars[i].colour; stars[i].y += stars[i].speed; if (stars[i].y >= SCREEN_HEIGHT) stars[i].y = 0; } SDL_UnlockSurface(vscreen); SDL_BlitSurface(background, NULL, vscreen, NULL); SDL_BlitSurface(autuinText, NULL, vscreen, &autuinRect); SDL_BlitSurface( selectedOption==0?onePlayerTextLarge:onePlayerTextSmall, NULL, vscreen, selectedOption==0?&onePlayerRectLarge:&onePlayerRectSmall ); SDL_BlitSurface( selectedOption==1?twoPlayerTextLarge:twoPlayerTextSmall, NULL, vscreen, selectedOption==1?&twoPlayerRectLarge:&twoPlayerRectSmall ); // Double up the resolution SDL_Surface *zoomed = zoomSurface(vscreen, 2, 2.31, 0); SDL_BlitSurface(zoomed, NULL, screen, NULL); SDL_FreeSurface(zoomed); // Blit the frame SDL_Flip(screen); // Go to sleep SDL_Delay(FRAME_TICKS - (SDL_GetTicks() - frameStart)); frame++; if (frame > FPS * 30) { attractor(screen, vscreen); frame = 0; } } // Stop the audio Mix_HaltChannel(-1); // One last boop for the quit/play action Mix_PlayChannel(-1, boop, 0); while(Mix_Playing(-1) != 0) SDL_Delay(10); // Free resources SDL_FreeSurface (background); SDL_FreeSurface (autuinText); SDL_FreeSurface (onePlayerTextSmall); SDL_FreeSurface (twoPlayerTextSmall); SDL_FreeSurface (onePlayerTextLarge); SDL_FreeSurface (twoPlayerTextLarge); Mix_FreeChunk(boop); Mix_FreeChunk(theme); switch (selectedOption) { case -2: return MENU_SUSPEND; case -1: return MENU_QUIT; case 0: return MENU_ONEPLAYER; case 1: return MENU_TWOPLAYER; } }
static void twelveUpdate(void) { unsigned char data[REPORT_SIZE]; readController(data); memcpy(last_read_controller_bytes, data, REPORT_SIZE); }
// Run a state machine testing for inputs, which plays // a simple song as we go. void configure(void) { CONFIGURE state; //static uint16 scrollcredits; // How far to scroll the credits //const char* credits = "Edwin Amsler 2010 to 2012 Edwin Amsler 2010 to 2012"; Controller control; unsigned int oldControl = 0; uint8 changed = 0; // If we need to redraw the screen or update the eeprom DELTA settingDelta = NONE; // How much to change the current setting put(VFD_CLR); put(VFD_FF); println("Config Mode:"); print("Use directional pad"); state = INIT; for(;;) { playNote(); control = readController(); // Prevents key repeat when the user holds the button down buttonDelta(&control.buttons, &oldControl); // Increment decrement setting settingDelta = NONE; // Handle button presses switch (control.buttons) { case PS_SELECT: // Escape config mode put(VFD_CLR); put(VFD_FF); // Don't save if nothing changed if (0 == (changed & UPDATE_EEPROM)) return; print("Saving settings..."); if (volume != eeprom_read_byte((uint8_t*)VOLUME)) eeprom_write_byte((uint8_t*)VOLUME, volume); if (brightness != eeprom_read_byte((uint8_t*)BRIGHTNESS)) eeprom_write_byte((uint8_t*)BRIGHTNESS, brightness); if (attack != eeprom_read_byte((uint8_t*)ATTACK)) eeprom_write_byte((uint8_t*)ATTACK, attack); if (decay != eeprom_read_byte((uint8_t*)DECAY)) eeprom_write_byte((uint8_t*)DECAY, decay); if (sustain != eeprom_read_byte((uint8_t*)SUSTAIN)) eeprom_write_byte((uint8_t*)SUSTAIN, sustain); if (release != eeprom_read_byte((uint8_t*)RELEASE)) eeprom_write_byte((uint8_t*)RELEASE, release); if (waveform != eeprom_read_byte((uint8_t*)WAVEFORM)) eeprom_write_byte((uint8_t*)WAVEFORM, waveform); // Mark that we saved data. EEPROM inits to 0xFF on programming eeprom_write_byte(INIT, 0); put(VFD_CLR); put(VFD_FF); return; case PS_UP: // Go to previous config option state--; changed |= UPDATE_SCREEN; break; case PS_DOWN: // Go to next config option state++; changed |= UPDATE_SCREEN; break; case PS_LEFT: settingDelta = DECREMENT; changed |= UPDATE_EEPROM; break; case PS_RIGHT: settingDelta = INCREMENT; changed |= UPDATE_EEPROM; break; default: // If no buttons press, go back to continue; // the top of the loop } // So we don't navigate to nowhere. // As confusing as it is, WAVEFORM is just // the last configuration option. When adding // new options, change this. Should have used // a sentry value state %= (uint8)WAVEFORM + 1; // Draw our menu switch (state) { case VOLUME: if (changed) { put(VFD_CLR); put(VFD_FF); print("Volume: <->"); changed &= ~UPDATE_SCREEN; } volume = changeNumber(volume, 15, &settingDelta); SIDSet(MODE_VOL, volume & 0x0F); break; case BRIGHTNESS: if (changed) { put(VFD_CLR); put(VFD_FF); print("Brightness: <->"); changed &= ~UPDATE_SCREEN; } brightness = changeNumber(brightness, 3, &settingDelta); put(VFD_ESC); put(VFDA_LUM); put(brightness * 64); // The hell? *64? Oh! 255/4=64. The Noritake // VFD uses 0 to 255 for brightness. break; case ATTACK: if (changed) { put(VFD_CLR); put(VFD_FF); print("Note Attack: <->"); changed &= ~UPDATE_SCREEN; } // There's something critically wrong here (and in other cases below). // Since we don't factor in the other half of the byte, setting this nibble // is knocking the decay out of the picture. What needs to happen, is it needs // to OR the decay nibble before setting the SID's register. // Since the SID is mostly read-only, it's the only way to do it. attack = changeNumber(attack, 15, &settingDelta); //SIDSet(ATK_DECAY, attack << 4); // EX: (Need to verify this works) SIDSet(ATK_DECAY, (attack << 4) | (decay & 0x0f)); break; case DECAY: if (changed) { put(VFD_CLR); put(VFD_FF); print("Note Decay: <->"); changed &= ~UPDATE_SCREEN; } decay = changeNumber(decay, 15, &settingDelta); SIDSet(ATK_DECAY, (attack << 4) | (decay & 0x0F)); break; case SUSTAIN: if (changed) { put(VFD_CLR); put(VFD_FF); print("Note Sustain: <->"); changed &= ~UPDATE_SCREEN; } sustain = changeNumber(sustain, 15, &settingDelta); SIDSet(STN_RLS, (sustain << 4) | (release & 0x0F)); break; case RELEASE: if (changed) { put(VFD_CLR); put(VFD_FF); print("Note Release: <->"); changed &= ~UPDATE_SCREEN; } release = changeNumber(release, 15, &settingDelta); SIDSet(STN_RLS, (sustain << 4) | (release & 0x0F)); break; case WAVEFORM: if (changed) { put(VFD_CLR); put(VFD_FF); print("Waveform Type: <->"); changed &= ~UPDATE_SCREEN; } waveform = changeEnum(waveformEnum, waveform, 3, &settingDelta); controlRegister &= 0xF0; controlRegister |= 1 << (4 + waveform); SIDSet(CONTROL, controlRegister); break; default: put(VFD_CLR); put(VFD_FF); print(" PlaySynth 64 "); // I broke the credits :( break; } // TODO: Another switch statement for setting registers (remove code dupe) // TODO: Store text headers in an array that's indexed by state (remove yet more code dupe) } }
void vblank(void) { #ifdef WIN drawFramebuffer(); #endif #ifdef PS4 void readController(void); readController(); extern unsigned int buttons; keys.c = (unsigned char)buttons; sceKernelUsleep(1000000 / 60); #endif #ifdef DS // The Game Boy and DS use the same key layout, how convenient :) keys.c = (unsigned char)REG_KEYINPUT; // Support scrolling copyMap(); #endif #ifdef GC VIDEO_WaitVSync(); #endif #ifdef DS3 hidScanInput(); u32 kHeld = hidKeysHeld(); keys.keys1 = 0x0f; keys.keys2 = 0x0f; if(kHeld & KEY_B) keys.b = 0; if(kHeld & KEY_A) keys.a = 0; if(kHeld & KEY_START) keys.start = 0; if(kHeld & KEY_SELECT) keys.select = 0; if(kHeld & KEY_UP) keys.up = 0; if(kHeld & KEY_DOWN) keys.down = 0; if(kHeld & KEY_LEFT) keys.left = 0; if(kHeld & KEY_RIGHT) keys.right = 0; //gfxFlushBuffers(); gspWaitForVBlank(); gfxSwapBuffers(); if(!aptMainLoop() || ((kHeld & KEY_START) && (kHeld & KEY_SELECT) && (kHeld & KEY_L) && (kHeld & KEY_R))) quit(); #endif #ifdef LIN drawFramebuffer(); #endif #ifdef PSP SceCtrlData pad; sceCtrlReadBufferPositive(&pad, 1); keys.keys1 = 0x0f; keys.keys2 = 0x0f; if(pad.Buttons & PSP_CTRL_SQUARE) keys.b = 0; if(pad.Buttons & PSP_CTRL_CROSS) keys.a = 0; if(pad.Buttons & PSP_CTRL_START) keys.start = 0; if(pad.Buttons & PSP_CTRL_SELECT) keys.select = 0; if(pad.Buttons & PSP_CTRL_UP) keys.up = 0; if(pad.Buttons & PSP_CTRL_DOWN) keys.down = 0; if(pad.Buttons & PSP_CTRL_LEFT) keys.left = 0; if(pad.Buttons & PSP_CTRL_RIGHT) keys.right = 0; sceDisplayWaitVblankStart(); #endif interrupt.master = 0; writeShortToStack(registers.pc); registers.pc = 0x40; ticks += 12; }