### Calculate the start of a row in VGA VRAM?

How do I calculate the start of a row (e.g. row #0, #1 etc.) in the VGA's VRAM? (On a planar level)

So if I need to get row #13 on plane #0, with an offset register of 0x20 (32 decimal) and an pixel size of WORD (so 2 bytes in the calculation), where would this row start in VRAM? (Is there a formula to do this?)

EDIT: Is this correct?

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108`` ``````inline byte readVRAMdirect(uint_32 start, uint_32 offset) { return VGA.VRAM[(start+offset)%VGA.VRAM_size]; //Read with overflow protection! } inline void writeVRAMdirect(uint_32 start, uint_32 offset, byte value) { VGA.VRAM[(start+offset)%VGA.VRAM_size] = value; //Write with overflow protection! } inline byte readVRAMplane(uint_32 start, byte plane, uint_32 offset) //Read from a VRAM plane! { return VGA.VRAM[((plane*0x10000)+start+offset)%VGA.VRAM_size]; //Read with overflow protection! } inline void writeVRAMplane(uint_32 start, byte plane, uint_32 offset, byte value) //Write to a VRAM plane! { VGA.VRAM[((plane*0x10000)+start+offset)%VGA.VRAM_size] = value; //Write with overflow protection! } inline void *VGA_planeptr(uint_32 start, byte plane) //Pointer to VRAM plane! { return &VGA.VRAM[((plane*0x10000)+start)%VGA.VRAM_size]; //Pointer to the VRAM plane! } inline byte getBitPlaneBit(uint_32 start, int plane, uint_32 offset, byte bit) { return ((readVRAMplane(start,plane,offset)&(1<>bit); //Give the bit! } inline void setBitPlaneBit(uint_32 start, int plane, uint_32 offset, byte bit, byte on) { writeVRAMplane(start,plane,offset,((readVRAMplane(start,plane,offset)&~(1<>3)); //Plane highest setBitPlaneBit(VGA.info.startMap,plane+2,offset,7-(pixel*2),((colorbuf&0x4)>>2)); //Plane lower! setBitPlaneBit(VGA.info.startMap,plane,offset,6-(pixel*2),((colorbuf&0x2)>>1)); //Plane highest setBitPlaneBit(VGA.info.startMap,plane,offset,6-(pixel*2),(colorbuf&0x1)); //Plane lower! case 16: //Planar shift? offset = getVRAMScanLineStart(y); //The starting offset of the row! offset += (x/8)*getVRAMMemAddrSize(); //Add X! setBitPlaneBit(VGA.info.startMap,0,offset,(x%8),(colorbuf&0x1)); //Bit 0! setBitPlaneBit(VGA.info.startMap,1,offset,(x%8),(colorbuf&0x2)>>1); //Bit 1! setBitPlaneBit(VGA.info.startMap,2,offset,(x%8),(colorbuf&0x4)>>2); //Bit 2! setBitPlaneBit(VGA.info.startMap,3,offset,(x%8),(colorbuf&0x8)>>3); //Bit 3! case 256: //256 color shift mode? offset = getVRAMScanlineStart(y); //The starting offset! offset += ((x/4)*getVRAMMemAddrSize()); //Add X! plane = (x%4); //The plane: we're spread over the planes! writeVRAMplane(VGA.info.startMap,plane,offset); //Give the bit representing the pixel! } }``````
Last edited on
Topic archived. No new replies allowed.