How to use the video registers in Assembly?

All aspects of programming on the Commander X16.
Post Reply
KaiLikesToCode
Posts: 6
Joined: Sun Sep 17, 2023 2:28 pm

Hardware How to use the video registers in Assembly?

Post by KaiLikesToCode »

In X16 Basic, you can use VPoke to poke to the VERA registers, like this:

Code: Select all

VPOKE 1,1
VPOKE 2,2
But in 6502 assembly, you use LDX and STA. How do we poke to the VERA in assembly?
Ser Olmy
Posts: 40
Joined: Thu Aug 18, 2022 8:20 pm

Re: How to use the video registers in Assembly?

Post by Ser Olmy »

VPOKE means "store in VERA video RAM." This can not be accomplished by a simple STA/STX instruction, as VRAM isn't mapped into the 65C02's address space.

Instead, VRAM is accessed indirectly using the memory-mapped registers at $9F20-$9F25. (Which is exactly what the VPOKE command does behind the scenes, it just hides all the complexity.)

The exact procedure looks something like this:
  1. Decide whether you are using data port 0 or data port 1, and set the ADDRSEL bit (bit 0) of $9F25 accordingly
  2. Write bits 0-7 of the VRAM address to $9F20
  3. Write bits 8-15 of the VRAM address to $9F21
  4. Write the MSB of the VRAM address to bit 0 of $9F22 [Edit: Original post said $9F21] (optionally: set the increment/decrement bits)
  5. Write the desired value to $9F23 (data port 0) or $9F24 (data port 1), depending on your choice in step 1
By the way, you say "poke to the VERA registers," but the addresses you VPOKE in the example (1 and 2) are not the locations of any VERA registers.
Last edited by Ser Olmy on Thu Dec 28, 2023 7:40 am, edited 1 time in total.
mgkaiser
Posts: 60
Joined: Sat Dec 02, 2023 6:49 pm

Re: How to use the video registers in Assembly?

Post by mgkaiser »

Create a "VPOKE" macro to hide the nasty details of writing to video memory.

Maybe also:
"VPOKEW" to poke 2 bytes in a row.

"VSTEP" to set the step by which to advance the address
"VPOKE-NEXT" and "VPOKEW-NEXT" to store values in the next address according to the step without doing addresses again.

"PEEK" macros to go with your pokes and maybe parameters to decide if you're using DATA0 or DATA1.

Macros are your friend. If you do it right you write really readable code that is still good, fast assembly.
KaiLikesToCode
Posts: 6
Joined: Sun Sep 17, 2023 2:28 pm

Re: How to use the video registers in Assembly?

Post by KaiLikesToCode »

I'm gonna make a macro for poking to the video memory, (named pvr). Can you please give me an example of poking to the vram? NOTE: I'm using DASM
Last edited by KaiLikesToCode on Sat Dec 09, 2023 1:53 am, edited 1 time in total.
SolarSurfer
Posts: 30
Joined: Sun Nov 26, 2023 2:18 am

Re: How to use the video registers in Assembly?

Post by SolarSurfer »

I highly recommend watching Matt Heffernan's video series on 6502 assembly.
https://www.youtube.com/watch?v=gqwIzbT ... SL1tkSTRI_

Specifically, Lesson 9 in the playllist. Keep in mind the vidoes are very old and based on early versions of the emulator. I think he's "poking" (the ASM equivalent) screen codes into $00000 of VRAM instead of what it is now, $1B000.

Lesson 12 shows how to use tiles
Lesson 15 shows how to use bitmaps
Lesson 18 shows how to use sprites

Another really good youtube channel is https://www.youtube.com/watch?v=v1_ivVa ... qC0IYEjCv6 which are also based on somewhat old versions of the emulator, but still are invaluable.
mortarm
Posts: 302
Joined: Tue May 16, 2023 6:21 pm

Re: How to use the video registers in Assembly?

Post by mortarm »

Ser Olmy wrote: Fri Dec 08, 2023 10:39 pm 3. Write bits 8-15 of the VRAM address to $9F21
4. Write the MSB of the VRAM address to bit 0 of $9F21 (optionally: set the increment/decrement bits)
This part confused me because your referencing the same address. What am I missing?
DragWx
Posts: 345
Joined: Tue Mar 07, 2023 9:07 pm

Re: How to use the video registers in Assembly?

Post by DragWx »

mortarm wrote: Mon Dec 11, 2023 7:51 pm
Ser Olmy wrote: Fri Dec 08, 2023 10:39 pm 3. Write bits 8-15 of the VRAM address to $9F21
4. Write the MSB of the VRAM address to bit 0 of $9F21 (optionally: set the increment/decrement bits)
This part confused me because your referencing the same address. What am I missing?
Oops, looks like a typo. On point 4, the address should be $9F22.

For reference, all of the VERA's registers are explained here in the documentation. This is just a technical reference though, so it won't contain tutorials on anything.
Ser Olmy
Posts: 40
Joined: Thu Aug 18, 2022 8:20 pm

Re: How to use the video registers in Assembly?

Post by Ser Olmy »

mortarm wrote: Mon Dec 11, 2023 7:51 pm
Ser Olmy wrote: Fri Dec 08, 2023 10:39 pm 3. Write bits 8-15 of the VRAM address to $9F21
4. Write the MSB of the VRAM address to bit 0 of $9F21 (optionally: set the increment/decrement bits)
This part confused me because your referencing the same address. What am I missing?
Nothing, because as DragWx pointed out, it's a typo. The correct address for step 4 is $9F22. Sorry about that.
Post Reply