site banner

Friday Fun Thread for September 23, 2022

Be advised; this thread is not for serious in depth discussion of weighty topics, this thread is not for anything Culture War related. This thread is for Fun. You got jokes? Share 'em. You got silly questions? Ask 'em.

7
Jump in the discussion.

No email address required.

This week I spent a lot of time on EGA. Namely, putting a lot of the stuff I read last week into practice this week.

It took me a while to fully grock the different EGA write modes and register settings. And then there were the memory latches! Jeeze! I guess I should start at the beginning.

There are 4 bitplanes in EGA that overlap in memory space. One bit out of each of the 4 bitplanes combines to determine the color of 1 pixel on the screen. There are also 4 bytes of latches in EGA that correspond to each of the 4 bitplanes. These latches get loaded when you try to read EGA memory space, and some of it ends up in whatever register you read it to. Then when you write back to EGA memory space, the contents of the latches form the basis of what gets written back, modified in all manner of ways by the write mode and the registers set.

So far as I figure, write mode 0 is the most complex. In write mode 0, many registers effect what gets written to EGA memory. You have the bitmask, which determines which bits of the latches get overwritten by whatever byte you are writing to memory. You have the bitplane masks, which determines which bitplane latches get overwritten by the byte you are writing. You have the function/rotate register which sets if the bits get overwriten, or'ed, anded or xor'ed with the latches, and how far bits get rotated. And then you have the set/reset value/enable registers, which can override certain bitplanes to be set low or high regardless of the byte you are writing to memory says.

Mode 1 just dumps withever is in the latches. You mostly use it for dumb copying from EGA memory space to another spot in EGA memory space.

Mode 2 only uses the bitmask, and the lower nibble of the byte being written corresponds to what gets written to the bitplanes. So basically you can write colors to the screen without having to fuck with bitplane masks or the set/reset registers. I'm told it's good for plotting arbitrary pixels on the screen.

Anyways, as proof of concept I wrote a program to draw 16x16 sprites in a memory format that can easily be written to the screen in EGA. All in assembly, also in EGA screen mode 0x0d. I plan on using it to create artwork I can then load into other games.

Fun things I've found out. Using the mouse when you draw to the screen fucks up your drawing. The mouse stomps all over the EGA registers when you move it. So you either need to set the registers using an overly complicated API in the mouse drivers, so that it can restore them properly when it exits it's interrupts. Or you hide the mouse while you are drawing. Something I swear I remember the old Sierra adventures games like Space Quest III doing.

...or draw mouse cursor yourself... (which, I think, is the preferred way for games)