VOGONS


First post, by PlaneVuki

User metadata
Rank Newbie
Rank
Newbie

Hi,

I am experimenting with the following code in pascal to plot pixels in 640x350 16color mode

******************************
setgmode;

port[$3C4]:=2; port[$3C5]:=15; {select all planes, white pixel will be plotted}
port[$3CE]:=8; port[$3CF]:=128; { plotting 0-th pixel, upper left corner, mask others}
mem[$a000:0]:=255;

readkey;

port[$3C4]:=2; port[$3C5]:=15; {again white}
port[$3CE]:=8; port[$3CF]:=64; {plot second pixel, mask others}
mem[$a000:0]:=255;

readkey;
******************************

But after the readkey it plots the second pixel, but still overwrites first pixel to black (set it to 0).

What am I doing wrong ?

Thanks in advance.

Reply 1 of 3, by Kalle

User metadata
Rank Newbie
Rank
Newbie

Hello,

you need to read from that memory location first in order to fill the latch registers.
A zero in the bit mask register means that the associated bit of the latch registers will be written back to that memory location. If you got zero in the latches, then zero is what will be written.

Reply 2 of 3, by PlaneVuki

User metadata
Rank Newbie
Rank
Newbie
Kalle wrote on 2022-02-27, 15:40:

Hello,

you need to read from that memory location first in order to fill the latch registers.
A zero in the bit mask register means that the associated bit of the latch registers will be written back to that memory location. If you got zero in the latches, then zero is what will be written.

That worked, thanks !

I did this instead of just writing:

*****************
temp:=mem[$a000:0]; ;read first
mem[$a000:0]:=255; ;then write
*****************

This is correct right?

Do you think that this is the fastest way to write a pixel to ega 640x480 16color ?:
Mask the plane(s), mask the bit(s), read from a video mem, write to a video mem.
Is there any faster method possible ? Algorithm-wise I mean, because I sure can make current faster with asembly.

Reply 3 of 3, by mkarcher

User metadata
Rank Oldbie
Rank
Oldbie
PlaneVuki wrote on 2022-02-27, 15:58:

Do you think that this is the fastest way to write a pixel to ega 640x480 16color ?:
Mask the plane(s), mask the bit(s), read from a video mem, write to a video mem.
Is there any faster method possible ? Algorithm-wise I mean, because I sure can make current faster with asembly.

Your algorithm doesn't work properly. The way you try to plot a pixel only can set bits to "1", not to "0". So you can always plot a white pixel that way, but trying to plot a black pixel will just do nothing. As long as you don't do funky color plane stuff, you should keep the map mask register ($3C4[2]) set to 15 all the time. You can not set or clear color bits that are not enabled by being set in this register. Instead, to select a color, use either

  • The set/reset mechanism provided by the graphics controller. You write the color you want to write into $3CE[0], and enable that register for all four planes by setting $3CE[1] to $F. The value you write to video memory is ignored in that case (the value would be used only on planes you didn't enable set/reset on). You can use Inc(mem[$A000:pixel]) in pascal to cause a read/write cycle on that address.
  • Use write mode 2. This modes acts like $3CE[1], the enable set/reset register is set to $0F all the time, i.e. it writes the same color to all pixels (that are not masked). The color written to those pixels doesn't come from the set/reset register $3CE[0] though, but from the low 4 bits of data byte written. You still need a dummy read before, so it's not as easy as inc to cause a dummy read and a write (this time with a fixed value) in one assembler instruction.

If you want to optimize write-mode 2 plotting, you might want to play with read mode 1 and set the color don't care register ($3CE[7]) to $0F. This ensures that all pixels match always, independent of their color, and the byte read from the EGA card is always $FF. You can then use "AND ES:[BX], color" to read to the latches, obtain $FF as read result and write back the color you want to plot.