Beispiel #1
0
SoundWavData::SoundWavData(SoundSystem& sys, ConstBinaryData dat) : ISoundData(sys)
{
	_data = 0;
	_channels = 0;
	_frames = 0;

	if(dat.byteSize() < sizeof(WAVFileHeader) + sizeof(WAVFileFormatChunk))
		return;
	EndianSafeConstBinaryDataAccessor a(dat);

	WAVFileHeader fh;
	fh.load(a);
	if(!fh.isValid())
		return;

	WAVFileFormatChunk ffc;
	ffc.load(a);
	if(!ffc.isValid())
		return;

	WAVFileDataChunk fdc;
	fdc.load(a);
	if(!fdc.isValid())
		return;

	_channels = ffc.wChannels;
	_frames = fdc.dwChunkSize / (_channels * sizeof(uint16));
	_data = new int16 [_channels * _frames];
	memoryCopy(_data, a.seek() + (const byte*)dat.first(), fdc.dwChunkSize);
}
Beispiel #2
0
SoundOpusData::SoundOpusData(SoundSystem& sys, ConstBinaryData dat) : ISoundData(sys)
{
	_opusData = 0;
	_samples = 0;
	_channels = 0;
	_frames = 0;
	samplesDecodingProgress = 0;

	if(dat.byteSize() < sizeof(MyOpusFileHeader))
		return;
	EndianSafeConstBinaryDataAccessor a(dat);

	MyOpusFileHeader fh;
	fh.load(a);

	_channels = fh.channels;
	uint s = dat.byteSize() - a.seek();
	_frames = (s / fh.packetSize) * fh.packetFrames;
	_opusData = new byte [s];
	memoryCopy(_opusData, a.seek() + (const byte*)dat.first(), s);

	renderCallbackActive(true);
}
Beispiel #3
0
void processDeviceInfoCommand(void)
/*++

	Function Description:
  		This function process the LED commands. This device has the standard keyboard
  		LEDs, which this command is not meant for. This command is to be used on the
  		Logo LED (ID = 0x04), Macro Record LED (ID = 0x07), and Game Mode LED (ID = 0x09).

         	Commands                LEDs => Logo     MacroRecord   GameMode
        LED State                         x              x           x
        LED Effect                        x              x           x
        LED Brightness                    x 
        LED Blinking Parameters           x              x           x
        LED Pulsating Parameters          x

  		If there is a LED state change, all of the variables are set here, but the actual
  		state of the LED will be changed on the next interrupt. Note that an LED reports
  		"on", even if it in a special effect during it "off" cycle. Therefore "off" means
  		nothing is happening to the LED, nor will it happen until another command occurs
  		to change that.

	Arguments:
  		NONE

	Returns: 
  		NONE

--*/
{
  U8 *ptr;
  ptr = &protocolTransmit[PAYLOAD];
  switch (protocolTransmit[COMMAND_ID]) {
    case (SET | DEVICE_MODE):
      deviceMode = ptr[0];
//      if (deviceMode == BOOTLOADER_MODE) {
//        HAL_GPIO_WritePin(LED_RESET_GPIO_Port, BOOT_CTR_Pin, GPIO_PIN_RESET);
//        while(1); 
//      }
      break;
    case (GET | DEVICE_MODE):
      ptr[0] = deviceMode;
      break;      
    case (GET | FW_VERSION):
      ptr[0] = VERSIONNUMBER[0];
      ptr[1] = VERSIONNUMBER[1];
      ptr[2] = VERSIONNUMBER[2];
     break;
    case (GET | MATRIX_INFO):
      ptr[0] = mX;
      ptr[1] = mY;
     break;    
    case (GET | DEBOUNCE_INFO):
      ptr[0] = ram.debounce;
      break;  
    case (SET | DEBOUNCE_INFO):
      ram.debounce = ptr[0];
      break; 
    case (GET | POLLING_INFO):
      ptr[0] = ram.pollingRate;
      break;  
    case (SET | POLLING_INFO):
      ram.pollingRate = ptr[0];
      break;      
    case (GET | LAYOUT_INFO):
      ptr[0] = sys.editionInfo[0];
      ptr[1] = sys.editionInfo[1];
      break;  
    case (SET | LAYOUT_INFO):
      sys.editionInfo[0] = ptr[0];
      sys.editionInfo[1] = ptr[1];
      requestVariableUpdate(FACTORY_CHANGED);  
      break; 
//    case (GET | LAYOUT_INFO):
//      ptr[0] = sys.editionInfo[0];
//      ptr[1] = sys.editionInfo[1];
//      break;  
    case (SET | DEVICE_RESET):
    memoryCopy((void *)&ram, (void *)&dft_generic, sizeof(ram));
    requestVariableUpdate(SW_CHANGED); 
    forceLightingReload(); 
    factoryReset = 0;
      break;    
    default:
      break;
  }
}
Beispiel #4
0
void processVariableUpdate(void)
/*++

Function Description:
  This function saves the designated variables in flash storage. All variables are stored
  in a flash sector (4K), as specified by the STORAGE structure. The size of STORAGE can be
  up to 4K - 256 maximum. If there is a update variable request, the interrupts are disabled;
  since there can be no interruptions during the flash process, nor can we have any of the 
  variables to be stored changing. A checksum is generated to give some validity to the ROM
  based variables. Then the last sector (0x7000) is erased and the variables are written in 
  256 byte blocks until complete. Also contained in this sector is the firmware Signature, 
  which must also be updated. Finally the update request is cleared if the flash update was
  successful and the interrupts are restored again.

  The Signature bits that are '1' can be set to '0' without erasing the sector or upsetting
  the rest of the variables. This technique is used by the Bootloader so it can indicate the
  completion of Firmware Update without knowing the variable definition.

  There are two blocks of variables that can be updated. The 'SPECIAL_DATA' block is reserved
  for manufacturing information: Serial Number, Keyboard Layout, and LED calibration values.
  These manufacturing variables are rarely updated (most likely only once on the line), the
  separating of these variables provides protection against accidentaly erasure of these values.
  The other page 'GENERIC_STORAGE' is for generic type variables and will be updated in the 
  field many times.

  The SPECIAL_DATA in not a flash page as they are 4K in size, this storage is accomplished by
  writing into the unused space at the top of the BootBlock page starting at SPECIAL_STORAGE.
  This uses the same prinpical as mention about the Signature, you can write zeros if the
  values are all ones to begin with. Since this means these variables have a limited number
  of times they can be updated, great care is taken not to waste and update. The data is 
  always checked to see if the current values already match the new values. Other check is
  made to see if the current block can be correctly written over with with the new data. If
  not the block is abandon and the next block on a 64 byte boundary is used.

Arguments:
  NONE

Returns: 
  NONE

--*/
{
  if ((updateStorage != 0) && (updateOneshot == 0)) {     // If variable storage need updating, then...
//    __disable_irq();                                      // Disable interrupts while flashing, take about 12ms to write the eeprom
//    if (updateOneshot !=0) {__enable_irq();}               // Check updateOneshot flag again, incase that when disableing the irq,then the USB come to change the updateOneshort value.
//    
    if ((updateStorage & SPECIAL_DATA) != 0) {            // If it is a special variable request, then...
      sys.crc = crc16((U8 *)&sys, sizeof(sys)-2);
      if (flashProgram(MANUFACTURING_SATRT, (void *)&sys, sizeof(sys)) == 1) {
        updateStorage &= ~SPECIAL_DATA;                   // If flash was successful, clear need to update        
//        updateStorage &= ~CRC_DATA;
      }
    }
    if ((updateStorage & GENERIC_DATA) != 0) {            // If it is a generic variable request, then...
      ram.crc = crc16((U8 *)&ram, sizeof(ram)-2);
      if (flashProgram(USER_SETTING_START, (void *)&ram, sizeof(ram)) == 1) {
        updateStorage &= ~GENERIC_DATA;                   // If flash was successful, clear need to update
 //       crc.ram = crc16((U8 *)&ram, sizeof(ram));
 //       updateStorage |= CRC_DATA;
      }
      
    }
		
//    if ((updateStorage & USER_LED_DATA) != 0) {            // If it is a generic variable request(For LED matrix data), then...
//      if (dfu_WriteEEPROM((void*)USER_SETTING_START1, (void *)&user, sizeof(user)) == CMD_SUCCESS) {
//        updateStorage &= ~USER_LED_DATA;                  // If flash was successful, clear need to update
//        crc.user = crc16((U8 *)&user, sizeof(user));
//				updateStorage |= GENERIC_DATA | CRC_DATA;                    // Also need to save the ram.ledEffect
//        updateOneshot = BUFFERING_TIME_SW;                // Apply one short
//      }	
//    }

//    if ((updateStorage & CRC_DATA) != 0) {
//      if (dfu_WriteEEPROM((void*)CRC16_START, (void *)&crc, sizeof(crc)) == CMD_SUCCESS) {
//        updateStorage &= ~CRC_DATA;                  // If flash was successful, clear need to update
//      }
//    }

//    if (deviceMode == BOOTLOADER_MODE) {                // If switching to Bootloader mode, then...
//#if 0     
//      *(U32 *)(0x10000FF8) = 0xAAAAAAAA;                // Set soft enter bootloader flag
//      NVIC_SystemReset();                               // Request a MCU soft reset
//#else
//      dfu_EraseSector(SIGNATURE_ADDR>>12, SIGNATURE_ADDR>>12);
//      NVIC_SystemReset();   
//      for (; ; );
//      //if (dfu_EraseSector(5, 5) == CMD_SUCCESS) {       // Erase the last sector (number 7)
//      //  dfu_InitializeBuffer();                         // Initialize the flash buffer
//      //  flashBuffer[(SIGNATURE_ADDR&0x00FF)>>2] = DFU_SIGNATURE;
//      //  dfu_CopyToFlash((void *)flashBuffer, (void *)(SIGNATURE_ADDR&0xFF00), 256);
//      //  NVIC_SystemReset();    
//      //}
//#endif
//    }

//    __enable_irq();                                       // Re-enable interrupts
  }
  if (factoryReset == 4) {
    memoryCopy((void *)&ram, (void *)&dft_generic, sizeof(ram));
    requestVariableUpdate(SW_CHANGED); 
    forceLightingReload(); 
//    forceLightingUpdate();   
    factoryReset = 0;
  }
}
Beispiel #5
0
/**
 * writeMemoryIOPorts - write IO registers.
 *
 * @data    a byte of information to be written
 * @address	the position to write to
 */
void writeMemoryIOPorts(unsigned short address, unsigned char data)
{
    switch (address) {
    case 0xFF00 :                   /* P1 */ 
        data |= 0xC0;               /* BIT 7,6 Not Used */
        data &= 0xF0;               /* BIT 3,2,1,0 Not Writable */
        memory[address] &= 0x0F;    /* clear upper half */
        memory[address] |= data;    /* set upper half */
        inputCheckInterrupt();
        break;
    case 0xFF01 :                   /* SB */
        memory[address] = data;
        break;
    case 0xFF02 :                   /* SC */
        data |= 0x7E;               /* BIT 6,5,4,3,2,1 Not Used */
        serialSetControl(data);
        memory[address] = data;
        break;
    case 0xFF04 :                   /* DIV */
        timersSetDIV();
        break;
    case 0xFF05 :                   /* TIMA */
        timersSetTIMA(data);
        break;
    case 0xFF06 :                   /* TMA */
        timersSetTMA(data);
        break;    
    case 0xFF07 :                   /* TAC */
        timersSetTAC(data);
        break;
    case 0xFF0F :                   /* IF */
        data |= 0xE0;               /* BIT 7,6,5 Not Used */
        memory[address] = data;
        break;
#ifdef SOUND
        case 0xFF10 :                   /* NR10 */
        data |= 0x80;               /* BIT 7 Not Used */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF11 :                   /* NR11 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF12 :                   /* NR12 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF13 :                   /* NR13 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF14 :                   /* NR14 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF16 :                   /* NR21 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF17 :                   /* NR22 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF18 :                   /* NR23 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF19 :                   /* NR24 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF1A :                   /* NR30 */
        data |= 0x7F;               /* BIT 6,5,4,3,2,1,0 Not Used  */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF1B :                   /* NR31 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF1C :                   /* NR32 */
        data |= 0x9F;               /* BIT 7,4,3,2,1,0 Not Used  */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF1D :                   /* NR33 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF1E :                   /* NR34 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF20 :                   /* NR41 */
        data |= 0xC0;               /* BIT 7,6 Not Used  */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF21 :                   /* NR42 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF22 :                   /* NR43 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF23 :                   /* NR44 */
        data |= 0x3F;               /* BIT 5,4,3,2,1,0 Not Used  */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF24 :                   /* NR50 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF25 :                   /* NR51 */
        write_memory_apu(address,data);
        memory[address] = data;
        break;
    case 0xFF26 :                   /* NR52 */
        data |= 0x70;               /* BIT 6,5,4 Not Used */
        write_memory_apu(address,data);
        memory[address] = data | 0x01; /* Nasty Hack */
        break;
    case 0xFF30 ... 0xFF3F :        /* WAVE pattern RAM */
        write_memory_apu(address,data);
        memory[address] = data;
        break;         
#else
    case 0xFF10 ... 0xFF3F :        /* Hande Sound */
        soundWriteRegister(address,data);
        break;
#endif
    case 0xFF40 :                   /* LCDC */
        gpuSetStatus(data);
        memory[address] = data;
        break;            
    case 0xFF41 :                   /* STAT */
        data |= 0x80;               /* BIT 7 Not Used */
        data &= 0xFC;
        data |= memory[address] & 0x03;    /* bobonis assumes 3 LSB cannot be set */
        memory[address] = data;
        gpuCheckStatSignal();
        
        //Road Rush 
        /*if(gpustate.enable && ((gpustate.mode == 0) || (gpustate.mode == 0)))
        {
            printf("[MEM] Trigger IRQ from STAT Bug, mode = %d, LY = %d\n",gpustate.mode, gpustate.line);
            triggerInterrupt(LCDC_INTERRUPT);
        }*/
        break;
    case 0xFF42 :                   /* SCY */
        memory[address] = data;
        break;
    case 0xFF43 :                   /* SCX */
        memory[address] = data;
        break;
    case 0xFF44 :                   /* LY */
        memory[address] = 0x00;     /* Writing will reset the counter */
        memory[LY] = 0;
        gpustate.line = 0;
        break;
    case 0xFF45 :                   /* LYC */
        memory[address] = data;
        if (gpustate.enable){
            gpuCheckLYC();
            gpuCheckStatSignal();
        }
        break;            
    case 0xFF46 :                   /* DMA */
        dmastate.prepare = TRUE;
        dmastate.address = data << 8;
        break;
    case 0xFF47 :                   /* BGP */
        memory[address] = data;
        break;
    case 0xFF48 :                   /* OBP0 */
        memory[address] = data;
        break;
    case 0xFF49 :                   /* OBP1 */
        memory[address] = data;
        break;
    case 0xFF4A :                   /* WY */
        memory[address] = data;
        break;
    case 0xFF4B :                   /* WX */
        memory[address] = data;
        break;
    case 0xFF50 :
        /* Writing the value of 1 to the address 0xFF50 unmaps the boot ROM, 
         * and the first 256 bytes of the address space, where it effectively 
         * was mapped, now gets mapped to the beginning of the cartridge’s ROM. */
        if (data == 0x01)
            memoryCopy(0x0000, cart_ROM, 0xFF);
        break;
    case 0xFF76 :                   /* ???? */
        memory[address] = 0x00;     /* Not Readable */
        break;
    case 0xFF77 :                   /* ???? */
        memory[address] = 0x00;     /* Not Readable */
        break;
    default :
        memory[address] = 0xFF;
        break;  
    }
}
Beispiel #6
0
/**
 * memoryReset - Clear main memory and set initial values to control registers
 *      Handles startup with or without bios.
 */
void memoryReset(void)
{
    int i;
    
    /*
     * Clear main memory. This action shouldn't be needed, but it seems we are missing
     * some register initializations
     */
    for (i = 0; i < 0x10000; i++)
        memory[i] = 0;
    
    /* load 16kb ROM bank 0 */
    memoryCopy(0x0000, cart_ROM, 0x3FFF);
    
    if (USINGBIOS){
        registers.PC = 0x0000;
        /* map the bios in the main memory */
        for (i = 0; i <= 255; i++){
            memory[i] = bios[i];
        }
        /* init cartrige ram */
        for (i = 0; i < 512; i++){
            memory_SRAM[i] = 0xFF;
        }

        memory[0xFF00] = 0xCF;    
        memory[0xFF07] = 0xF8;
#ifdef SOUND
        memory[0xFF10] = 0x80;	/* NR10 */
	    memory[0xFF11] = 0xBF;	/* NR11 */
	    memory[0xFF12] = 0xF3;	/* NR12 */
	    memory[0xFF14] = 0xBF;	/* NR14 */
	    memory[0xFF16] = 0x3F;	/* NR21 */
	    memory[0xFF17] = 0x00;	/* NR22 */
	    memory[0xFF19] = 0xBF;	/* NR24 */
	    memory[0xFF1A] = 0x7F;	/* NR30 */
	    memory[0xFF1B] = 0xFF;	/* NR31 */
	    memory[0xFF1C] = 0x9F;	/* NR32 */
	    memory[0xFF1E] = 0xBF;	/* NR33 */
	    memory[0xFF20] = 0xFF;	/* NR41 */
	    memory[0xFF21] = 0x00;	/* NR42 */
	    memory[0xFF22] = 0x00;	/* NR43 */
	    memory[0xFF23] = 0xBF;	/* NR30 */
	    memory[0xFF24] = 0x77;	/* NR50 */
	    memory[0xFF25] = 0xF3;	/* NR51 */
	    memory[0xFF26] = 0xF1;	/* NR52 */
#endif
        memory[0xFF0F] = 0xE0;
        memory[0xFFFF] = 0xE0;
        memory[0xFF46] = 0xFF;
        memory[0xFF48] = 0xFF;
        memory[0xFF49] = 0xFF;
        memory[0xFF4F] = 0xFF;
        memory[0xFF68] = 0xFF;
        memory[0xFF6A] = 0xFF;
        memory[0xFF72] = 0xFF;
        memory[0xFF73] = 0xFF;
        memory[0xFF75] = 0xFF;
        memory[0xFF76] = 0xFF;
        memory[0xFF77] = 0xFF;
    } else {
	   registers.AF = 0x01B0;
	   registers.BC = 0x0013;
	   registers.DE = 0x00D8;
	   registers.HL = 0x014D;
	   registers.SP = 0xFFFE;
	   registers.PC = 0x0100;
	   memory[0xFF05] = 0x00;	/* TIMA */
	   memory[0xFF06] = 0x00;	/* TMA */
	   memory[0xFF07] = 0x00;	/* TAC */
	   memory[0xFF10] = 0x80;	/* NR10 */
	   memory[0xFF11] = 0xBF;	/* NR11 */
	   memory[0xFF12] = 0xF3;	/* NR12 */
	   memory[0xFF14] = 0xBF;	/* NR14 */
	   memory[0xFF16] = 0x3F;	/* NR21 */
	   memory[0xFF17] = 0x00;	/* NR22 */
	   memory[0xFF19] = 0xBF;	/* NR24 */
	   memory[0xFF1A] = 0x7F;	/* NR30 */
	   memory[0xFF1B] = 0xFF;	/* NR31 */
	   memory[0xFF1C] = 0x9F;	/* NR32 */
	   memory[0xFF1E] = 0xBF;	/* NR33 */
	   memory[0xFF20] = 0xFF;	/* NR41 */
	   memory[0xFF21] = 0x00;	/* NR42 */
	   memory[0xFF22] = 0x00;	/* NR43 */
	   memory[0xFF23] = 0xBF;	/* NR30 */
	   memory[0xFF24] = 0x77;	/* NR50 */
	   memory[0xFF25] = 0xF3;	/* NR51 */
	   memory[0xFF26] = 0xF1;	/* NR52 */
	   memory[0xFF40] = 0x91;	/* LCDC */
       memory[0xFF41] = 0x80;   /* LCDS */
	   memory[0xFF42] = 0x00;	/* SCY */
	   memory[0xFF43] = 0x00;	/* SCX */
	   memory[0xFF45] = 0x00;	/* LYC */
	   memory[0xFF47] = 0xFC;	/* BGP */
	   memory[0xFF48] = 0xFF;	/* OBP0 */
	   memory[0xFF49] = 0xFF;	/* OBP1 */
	   memory[0xFF4A] = 0x00;	/* WY */
	   memory[0xFF4B] = 0x00;	/* WX */
	   memory[0xFFFF] = 0x00;	/* IE */     
    }
}
void apbMessageHandler (void) {
    commCounter = 0;
    
    switch (apbInst->function) {
#if SELECTABLE_OUTPUT
        case 2: { //setup single channel
            uint8_t channel = apbInst->message [3] + 1; //0 is channel 1
            uint8_t type    = apbInst->message [4];

            //type 255 is PWM output so close relay to bypass filter
            if (type == 255)
                PORTB |= 1 << channel;
            else
                PORTB &= ~(1 << channel);

            eeprom_write (channel - 1, type);

            sendDefualtResponse ();

            break;
        }
#endif
        case 10: { //read single channel value
            uint8_t channel = apbInst->message [3];
            uint16_t value  = getChannelValue (channel);
            
            uint8_t m [7];
            uint8_t crc [2];

            m [0] = apbInst->address;
            m [1] = 10; //function number
            m [2] = 7;  //message length
            memoryCopy (&(m [3]), &value, sizeof (uint16_t));
            apb_crc16 (m, crc, 7);
            m [5] = crc [0];
            m [6] = crc [1];

            writeUartData (m, 7);

            break;
        }
        case 20: { //read all channels values
            uint16_t values [4];

            int i;
            for (i = 0; i < 4; ++i) 
                values [i] = getChannelValue (i);

            uint8_t m [13];
            uint8_t crc [2];

            m [0] = apbInst->address;
            m [1] = 20; //function number
            m [2] = 13; //message length
            memoryCopy (&(m [3]), values, sizeof (uint16_t) * 4);
            apb_crc16 (m, crc, 13);
            m [11] = crc [0];
            m [12] = crc [1];

            writeUartData (m, 13);

            break;
        }
        case 30: { //write all channels values
            uint16_t values [4];
            memoryCopy (values, &(apbInst->message[3]), sizeof (uint16_t) * 4);

            int i;
            for (i = 0; i < 4; ++i)
                setChannelValue (i, values [i]);

            sendDefualtResponse ();

            break;
        }
        case 31: { //write single channel value
            uint8_t channel = apbInst->message [3];
            uint16_t value;
            memoryCopy (&value, &(apbInst->message[4]), sizeof (uint16_t));
            
            //value = (value >> 8) | (value << 8); // reverse the endianess
            
            setChannelValue (channel, value);

            sendDefualtResponse ();

            break;
        }
        default:
            break;
    }
}