# Plotting a single dot on screen

Página 1/4
| 2 | 3 | 4

I looked around on the site but maybe it is my wording so I will ask.

Is there a formula, source code, something I can learn from.

On the MSX the screen is set up as 768 8x8 tiles that are individually created patterns.

What I would like to do is know how to plot a single dot anywhere on the screen ACCURATELY.
So through Z80 assembly language plot a single dot anywhere on a 256x192 grid.
Would be great to do circles, strait lines even LOGO type actions in Z80 but for now just the plotting a single point will work.

Thank you for everyone's help, you guys have been awesome.

Login sesión o register para postear comentarios

You simply want to put something on screen and a dot is enough?

Use screen5 its the easiest screen. Just simply write to vram.

Vdp commands are the easiest. Look up the v9938 programmers guide by eugeny brichkov.

There is a vdp command to draw a single dot.

First switch to screen 5. Use the bios

```ld a, 5
Call \$5f```

I can write down some formula, I just used it yesterday.
you can get the offset of the byte inside the pattern table (screen 2) that contains the (x,y) pixel by doing the following:

```offset = (x / 8) * 8 + (y / 8) * 8 * 32 + y % 8;
```

and apply that offset to set both the pattern (base address 0) and the color (base address 0x2000).

To calculate the actual pixel inside the byte, you can just do:

```bit = x % 8
```

And just set that bit in the offset byte.

geijoenr wrote:

I can write down some formula, I just used it yesterday.
you can get the offset of the byte inside the pattern table (screen 2) that contains the (x,y) pixel by doing the following:

```offset = (x / 8) * 8 + (y / 8) * 8 * 32 + y % 8;
```

and apply that offset to set both the pattern (base address 0) and the color (base address 0x2000).

To calculate the actual pixel inside the byte, you can just do:

```bit = x % 8
```

And just set that bit in the offset byte.

Non so easy, unfortunately. if you want to take in account the dot color. In this case you need to do a lot of bit mask manipulation in some situation and eventually swap the color nibble bytes.

Assume you have a region of pixels all in color 8. the vram attribute byte could be 0xFF and the color byte could be 0x88.
If you want to plot a white dot inside the 8 pixels you can't simply turn on a bit in the 0xFF byte, because all bits are already turned on!
You MUST:
turn *OFF* the bit in the position where the pixel is.
read in the corresponding color byte and then mask out the right nibble ( sorry i do not remember if it is the high or low one) and store instead the 0xF hex decimal.

Tricky and slow like a dead snail .

Is the bit to set really x % 8? I thought that for x=0, the bit to set would be 7 and not 0?

indeed, it needs to be reversed.

What is the end goal of plotting individual pixels? If the end goal is to plot the pixels, that's fine, but the MSX VDP was really not designed to draw pixel by pixel, and trying to draw anything this way will be very slow. I hope the formulas shared above help, but if you give us a bit more context, we could help better. Maybe you don't really need plotting individual pixels

Uninteresting wrote:

Is the bit to set really x % 8? I thought that for x=0, the bit to set would be 7 and not 0?

no it this not the bit number is the bit state!

normally if you want to set the pixel at 1,0 for example you need to write in vram the value you read in or'ed with 64
note that 64 is in binary form is 01000000:

vpoke adr, vpeek(adr) or 64 : REM pixel at 1, set to on.

but if vpeek(adr)=255 then the instruction will be

vpoke adr, vpeek(adr) and (255 xor 64) that is equivalent to do

note that 191 in binary form is 01000000 reversed 10111111 -> 191

With all this confusing explanations probably Chilly Willy is now deterred from attempting to write pixels

Thank your for all the input.

Being tactful by saying that I asked how to plot a single point.
I will expand on that formula and program later but to ask "why would I want to do that" instead of an answer like come on dude....

These things are done every day when drawing lines across the screen like in a drawing program.

It is all in Z80, self booting.

No calls, no pokes, no 9938. Just Z80 Assembly language on an MSX original.

I can set all the 8x8 tiles patterns to blocks then plot a single point turn a pixel off showing the background or even when plotting the pixel set the color using the VRAM Name Table+\$2000

However, I can read the formula above but do you already have it written in Z80 so I don't fudge the math?

I do appreciate everyone's help and not trying to bite heads or step on toes.
Some of these are huge learning curves.
Trust me when I say I know how to use the pattern tables and can make some pretty cool effects.
My issues come when learning new stuff trying to push the MSX to the limit.
When I can not find it written then I ask.

Ultimately I am trying to create a drawing program that uses an old koala tablet with an arduino interface but one step at a time.

geijoenr wrote:

With all this confusing explanations probably Chilly Willy is now deterred from attempting to write pixels

The complexity arises from the display arrangement and layout, not by my explanations.
If you think my explanation is complex, just make your one more simple, for sure it will be appreciated by Chilly Willy.
I've done a more indepth explanation on how to manage vram contents that is more useful than a simple message saying "It does need to be reversed", without giving any reason justifying because it should be done in this way

Página 1/4
| 2 | 3 | 4