コード例 #1
0
 public void Write(ushort PC, byte data)
 {
     //RAM Enabled and ROM Bank Number
     if (PC >= 0x0000 && PC <= 0x3FFF)
     {
         byte bit8 = (byte)(GameBoyCPU.getBitFromWord(8, PC));
         if (bit8 != 1)
         {
             byte mask         = (byte)(data & 0x0F);
             bool prevRamState = ramEnable;
             ramEnable = (mask == 0x0A) ? true : false;
             //Went from true to false
             if (prevRamState && !ramEnable && battery)
             {
                 save();
             }
         }
         else
         {
             bank1 = (byte)(data & 0x0F);
             if (bank1 == 0)
             {
                 bank1 = 1;
             }
         }
     }
     else if (PC >= 0xA000 && PC <= 0xBFFF)
     {
         if (ramEnable)
         {
             byte newData = (byte)(data & 0x0F);
             int  offset  = PC - 0xA000;
             ramMemory[offset % 512] = data;
         }
     }
 }
コード例 #2
0
ファイル: GameBoyMemory.cs プロジェクト: slangev/gameboyunity
 public bool WriteToMemory(ushort address, byte data)
 {
     if (address >= 0x0000 && address <= 0x7FFF)
     {
         gbCart.Write(address, data);
     }
     else if (address >= 0x8000 && address <= 0x9FFF)
     {
         gbGraphic.Write(address, data);
     }
     else if (address == GameBoyTimer.DIV)
     {
         uint rate     = (byte)(memory[GameBoyTimer.TAC] & 0x3);
         byte divValue = memory[GameBoyTimer.DIV];
         //Failing Edge detector... don't know if this is correct
         if (rate == 0 && GameBoyCPU.getBitFromWord(9, gbTimer.TIMACycleCount) == 1)
         {
             gbTimer.IncrementTIMACheck();
         }
         else if (rate == 1 && GameBoyCPU.getBitFromWord(3, gbTimer.TIMACycleCount) == 1)
         {
             gbTimer.IncrementTIMACheck();
         }
         else if (rate == 2 && GameBoyCPU.getBitFromWord(5, gbTimer.TIMACycleCount) == 1)
         {
             gbTimer.IncrementTIMACheck();
         }
         else if (rate == 3 && GameBoyCPU.getBitFromWord(7, gbTimer.TIMACycleCount) == 1)
         {
             gbTimer.IncrementTIMACheck();
         }
         memory[GameBoyTimer.DIV] = 0;
         gbTimer.resetTimer();
     }
     else if (address == GameBoyTimer.TIMA)
     {
         //if(!gbTimer.isReloadingTIMA()) {
         memory[GameBoyTimer.TIMA] = data;
         //}
     }
     else if (address >= 0xA000 && address <= 0xBFFF)
     {
         gbCart.Write(address, data);
     }
     else if (address == GameBoyGraphic.LYAddr)
     {
         memory[address] = 0;
         gbGraphic.resetWindowLine();
     }
     else if (address >= 0xC000 && address <= 0xFDFF)
     {
         workRam.Write(address, data);
     }
     else if (address == DMA)
     {
         DMATransfer(data);
     }
     else if ((address == 0xFF4F || (address >= 0xFF51 && address <= 0xFF55) ||
               (address >= 0xFF68 && address <= 0xFF6B)) & GameBoyCartiridge.IsGameBoyColor)
     {
         gbGraphic.Write(address, data);
     }
     else if (address >= 0xFF01 && address <= 0xFF02)
     {
         Debug.Log("Link Port");
     }
     else if (address >= 0xFF10 && address <= 0xFF3F)
     {
         gbAudio.Write(address, data);
     }
     else if (address == GameBoyGraphic.STATAddr)
     {
         memory[address] = (byte)((memory[address] & 0x7) | (data & 0xF8));
     }
     else if (address == 0xFF70 && GameBoyCartiridge.IsGameBoyColor)
     {
         workRam.Write(address, data);
     }
     else if (address == KEY1)
     {
         data            = (byte)(data & 0x7f);
         memory[address] = data;
     }
     else
     {
         memory[address] = data;
     }
     return(true);
 }