Mental Maths Method of Calculating VRAM Addresses

Discussion in 'Tutorials Archive' started by DanielHall, Sep 7, 2017.

  1. DanielHall

    DanielHall Well-Known Member Member

    Jan 18, 2010
    North Wales
    Hey. I dunno if anyone's interested, but I've had this guide sitting about for like a year, and I thought I'd post an easy method of calculating VRAM addresses in your head, so you can save time over getting a converter if you learn it.

    Let's just say you wanted to write to VRAM address $C62E:

    Boundary 0 <=> $0000-$3FFF
    Boundary 1 <=> $4000-$7FFF
    Boundary 2 <=> $8000-$BFFF
    Boundary 3 <=> $C000-$FFFF

    Firstly, find what $4000 byte range the address slots into (Boundary 3). Then you subtract it by that boundary's starting value (in this case, $C000, giving $62E).
    After that, you add the subtracted value by $4000 (Which signifies the VRAM write mode, giving $462E). Now we can put the VDP command together:

    $462E <- That will be your first word of the command, which essentially tells you what relative offset from the boundary to start writing.

    $462E 00 <- Next two bytes are ALWAYS 00. The VDP doesn't use them!

    $462E 00 03 <- Your final two bytes are the boundary your address falls into, in this case 3.

    Combined, you get the final VDP command $462E0003, which will write to the VRAM address $C62E. If you wanted to turn DMA on, you'd add $80 to your value ($83).

    This is mainly for calculating VRAM addresses but a similar concept can be applied to other modes. Change the +$4000 value of the first word to +$C000 for CRAM write, and you'd add $10 to the boundary byte to change it to VSRAM write. I don't think it's worth covering the lesser-used modes such as read, as it will end up confusing matters.
  2. ⸸ devon ⸸

    ⸸ devon ⸸ I am CRUSHING YOUR HEAD!!!! Member

    Aug 26, 2013
    Heh, this is exactly how I've been calcluating VDP commands for a while now. Nice to see it being shared around here. (Yeah, I could've done it myself, but lazy :V)