don't click here

Basic VDP drawing

Discussion in 'Technical Discussion' started by saxman, Jun 22, 2024.

  1. saxman

    saxman

    Oldbie Tech Member
    Hello. I don't like to ask for help, but I feel like I've wasted far too much time trying to figure this out. And I've done this in the past, but can't remember how much of it works very well anymore. I've looked at documents for too long.

    I have patterns in VRAM already, starting at the very top. I want to place those on the screen... scroll A or B, I'm not too picky. I just need to know some basic assembly instructions I can use to manually place some tiles, sort of quick and dirty. I don't want to make it super fancy, I just need something pretty short and simple that I can use to aid me the rest of the way. Will someone assist me in this? Feel free to provide any details/explanation of your code that you think I might need to know.
     
  2. Devon

    Devon

    A̸ ̴S̴ ̵C̵ ̷E̶ ̸N̸ ̴D̶ ̵E̶ ̸D̶ Tech Member
    1,299
    1,508
    93
    your mom
    To manually place a tile, you'll wanna locate the VRAM address in the plane you wanna draw in and create a VRAM WRITE command out of that. A plane is just a 2D array of tile IDs and properties, which each tile being formatted as so in binary:

    Code (Text):
    1. PCCVHTTTTTTTTTTT
    • P = Priority flag
    • C = Palette line
    • V = Vertical flip
    • H = Horizontal flip
    • T = Tile ID
    To construct the VRAM address needed to make the write command, you'll also need to know what the plane size is set to. The following are valid sizes:
    • 32x32
    • 32x64
    • 32x128
    • 64x32
    • 64x64
    • 128x32
    So with that, to calculate the VRAM address, you, of course, start with the starting VRAM address of the plane. To get the X offset, you just add (X offset in tiles * 2) to the address. The "* 2" comes from the fact a tile ID is 2 bytes. To add the Y offset, you jsut add (Y offset in tiles * plane width in tiles * 2). So, for example, the VRAM address for drawing a tile 4 tiles to the right and 3 tiles down on a 64 tile width plane starting at $C000 would be ($C000 + (4 * 2) + (3 * 64 * 2)), which is $C188.

    Then, to convert that into a VRAM write command, you will first need to split it into 2 values. The way you can look at this is to view VRAM as 4 banks that are $4000 bytes in size each. Basically, you get which "bank" the address lies in and the offset within that "bank". You can get the former by dividing the address by $4000, and the latter by ANDing the address by $3FFF. You should get 3 and $188 respectively from $C188. With that, to make the command, you just set the high word to the latter value + $4000, and the low word to the former value, which we will get $41880003.

    All that you need to do now is write that command to the VDP control port, and then you can write the tile ID to the VDP data port. The VDP's auto-increment value will be added onto VRAM address that is set for writing. Generally, by default, it is set to 2, which in this context, basically means it goes to the next tile in the plane's memory space, which is useful for writing a row of tiles in sequence. If your plane width is 32 or 64, then you can set the VDP auto-increment value to (32 * 2) or (64 * 2) to write a column of tiles instead (won't work so well for 128 wide planes, because 128 * 2 does not fit in a byte).

    Hope this helps!
     
    • Informative Informative x 3
    • Like Like x 2
    • List
  3. saxman

    saxman

    Oldbie Tech Member
    This was a bit more technical than I was originally looking for, but it DID end up helping in my overall understanding. I think I've got things working now. Thank you for your input, it is very much appreciated!
     
  4. Devon

    Devon

    A̸ ̴S̴ ̵C̵ ̷E̶ ̸N̸ ̴D̶ ̵E̶ ̸D̶ Tech Member
    1,299
    1,508
    93
    your mom
    Just wanted to cover all the bases I could. Glad to hear. :)