public void WriteScroll(byte data) { if (!WriteLatch) // First write. { // The data is split into two parts. The first 3 bits are the fine X scroll and the upper 5 bits are // the course X scroll. FineX = (byte)(data & 0b000_0111); // Set course X in the temporary address register without touching the other TAddress = (ushort)((TAddress & ~0x001f) | ((data >> 3) & 0x001f)); WriteLatch = true; } else // Second write. { // The data is split into two parts again. The first 5 bits are the course Y scroll and the upper 3 // bits are the fine Y scroll. // First set the course Y scroll in the temporary address register without touching the other // Course Y is stored as bits 3-7 in data so we only have to left shift data by 2 to get bits 3-7 into // positions 5-9 for the temporary address register. TAddress = (ushort)((TAddress & ~0x03e0) | ((data << 2) & 0x03e0)); // Now set the fine Y scroll in the temporary address register without touching the other Fine Y // is stored as bits 0-2 in data so we have to left shift data by 12 to get bits 0-2 into positions // 12-14. TAddress = (ushort)((TAddress & ~0x7000) | ((data << 12) & 0x7000)); WriteLatch = false; } }
public void WriteAddress(byte data) { if (!WriteLatch) // First write. { // Write data into the high byte position of the temporary address register. Don't touch the low byte // of the temporary address register. TAddress = (ushort)((TAddress & ~0xff00) | ((data << 8) & 0xff00)); // We do have to set bit 15 of the temporary address register to zero since it technically doesn't // exist. TAddress &= 0x7fff; // Mask the bottom 15 WriteLatch = true; } else // Second write. { // Write data into the low byte position of the temporary address register. Don't touch the high byte // of the temporary address register. TAddress = (TAddress & ~0x00ff) | data; // Set the current address register to the value of the temporary address register. VAddress = TAddress; WriteLatch = false; } }