joncampbell123 / dosbox-x

DOSBox-X fork of the DOSBox project
GNU General Public License v2.0
2.66k stars 378 forks source link

Hercules InColor bug #4375

Open viti95 opened 1 year ago

viti95 commented 1 year ago

Describe the bug

Wrong behaviour testing Learn222 program with latch.lst listing (Hercules InColor driver floppy, TUTOR folder http://www.dosdays.co.uk/media/hercules/incolor/hercules_incolor.zip)

86Box (correct): screen

DosBox-X (wrong): screen01

Steps to reproduce the behaviour

  1. Load learn222 program
  2. press enter
  3. write "read", press enter
  4. write "latch.lst", press enter
  5. press multiple times enter, each step will update the screen

Expected behavior

Show correct screen changes

What operating system(s) this bug have occurred on?

Linux Lubuntu 22.04

What version(s) of DOSBox-X have this bug?

Tested on commit 2e6f70c3ed9dd35a384a2e221acbd9f5e9101a5e, pretty sure the bug is elsewhere

Used configuration

machine=hercules_incolor

Output log

No response

Additional information

I think there is something wrong handling the latch register from the video card, but haven't debugged the issue in detail. Seems like the latch isn't preserved between calls.

Have you checked that no similar bug report(s) exist?

Code of Conduct & Contributing Guidelines

joncampbell123 commented 2 months ago

I'm kind of at a loss here... it's drawing the line in MPlot by making a bitmask (0x80 >> (x & 7)) and then ORing it to video memory.

That means it reads from video memory, which triggers the color compare on read, and writes the OR of the color compare result and (0x80 >> (x&7)) to video memory.

Write mode 1 writes for each pixel either the foreground color (if bit set) or latch contents (if bit clear). Foreground color is 3 (cyan).

Once it's written cyan to the leftmost pixel in the byte (0x80), reading back (color comparison) is 0x80, so the next byte sent to the card is 0x80 | (0x80 >> 1). Then 0xC0 | (0x80 >> 2). And so on. Which eventually fills the entire byte with cyan.

So I'm not clear how MPlot, ORing one bit at a time, despite documentation that the 1 bits are to become cyan (foreground color), is supposed to generate a line consisting entirely of the latch pattern.

joncampbell123 commented 2 months ago

See also: https://www.seasip.info/VintagePC/incolor.html

joncampbell123 commented 2 months ago

I suppose it's worth looking into why the other lines don't draw though.

joncampbell123 commented 2 months ago

Hey wait a minute... a diagram in the PC & PS/2 Video Systems programming book gives me a clue.

Maybe the InColor loads the latch according to the "latch protect" bits, and then compares the latch against the colors, not the raw video memory contents. And the LATCH.LST script sets all the latch protect bits.

PXL_20240630_215152597 MP sm

joncampbell123 commented 2 months ago

Ha, well, that's better at least.

learn222_000

joncampbell123 commented 2 months ago

Wait, I get it. I misread the Latch Protect as somehow protecting bitlanes, it protects individual bits across all four bitplanes. :facepalm: I wondered why the diagram showed 8 bits, not 4, for latch protect.