1 // 2 // Copyright (c) 2010-2023 Antmicro 3 // Copyright (c) 2011-2015 Realtime Embedded 4 // 5 // This file is licensed under the MIT License. 6 // Full license text is available in 'licenses/MIT.txt'. 7 // 8 using System; 9 using Antmicro.Renode.Backends.Display; 10 using Antmicro.Renode.Core; 11 using Antmicro.Renode.Peripherals.Bus; 12 using Antmicro.Renode.Logging; 13 14 namespace Antmicro.Renode.Peripherals.Video 15 { 16 public class VybridDCU : AutoRepaintingVideo, IDoubleWordPeripheral 17 { VybridDCU(IMachine machine)18 public VybridDCU(IMachine machine) : base(machine) 19 { 20 Reconfigure(format: PixelFormat.BGR888); 21 22 sysbus = machine.GetSystemBus(this); 23 lock_obj = new object(); 24 } 25 WriteDoubleWord(long address, uint value)26 public void WriteDoubleWord(long address, uint value) 27 { 28 switch(address) 29 { 30 case 0x200: 31 lock(lock_obj) 32 { 33 var width = (int)(value & 0xFFFF); 34 var height = (int)((value >> 16) & 0xFFFF); 35 this.DebugLog("Setting resolution to {0} x {1}", Width, Height); 36 37 if(value == 0) 38 { 39 break; 40 } 41 Reconfigure(width, height); 42 } 43 break; 44 case 0x208: 45 this.DebugLog("Setting buffer addr to 0x{0:X}", value); 46 bufferAddress = value; 47 break; 48 case 0x20c: 49 lock(lock_obj) 50 { 51 var bpp = (value >> 16) & 7; 52 switch(bpp) 53 { 54 case 4: // BPP_16_RGB565 55 Reconfigure(format: PixelFormat.RGB565); 56 break; 57 case 5: // BPP_24_RGB888 58 Reconfigure(format: PixelFormat.RGB888); 59 break; 60 case 6: // BPP_32_ARGB8888 61 Reconfigure(format: PixelFormat.ARGB8888); 62 break; 63 default: 64 this.Log(LogLevel.Warning, "Unsupported layer encoding format: 0x{0:X}", bpp); 65 break; 66 } 67 } 68 this.DebugLog("Change dpp mode to {0}-bit", 8 * (((value >> 16) & 7) - 2)); 69 break; 70 default: 71 this.LogUnhandledWrite(address, value); 72 break; 73 } 74 } 75 ReadDoubleWord(long offset)76 public uint ReadDoubleWord(long offset) 77 { 78 this.LogUnhandledRead(offset); 79 return 0x00; 80 } 81 Reset()82 public override void Reset() 83 { 84 // TODO! 85 } 86 Repaint()87 protected override void Repaint() 88 { 89 lock (lock_obj) 90 { 91 if ((bufferAddress == 0xFFFFFFFF)) 92 { 93 return; 94 } 95 sysbus.ReadBytes(bufferAddress, buffer.Length, buffer, 0); 96 } 97 } 98 99 private uint bufferAddress = 0xFFFFFFFF; 100 101 private readonly object lock_obj; 102 103 private readonly IBusController sysbus; 104 } 105 } 106 107