• Please review our updated Terms and Rules here

Help me disassembling a CGA emulator

carlos12

Experienced Member
Joined
May 10, 2020
Messages
183
Location
Madrid, Spain
Since several decades ago I have an old CGA emulator for Hercules. It's just a TSR wich takes only 512 bytes. It's the best CGA emulator I know. As far as I tried, it seems that only works on real hardware, it hangs every emulator...

In real hardware, it works so great and accurate that I would love to use it's "secrets" to implement them into my programs, so an Hercules card could show CGA graphics converting them automatically. I already do it: I just set the Hercules CRT parameters to use the B800 memory space instead of defauly B000, and configure the card to set a 620x300 resolution with three scanlines (the 3rd one is blank). It definitely works and there's no need to program special routines for the Hercules, the CGA ones work perfectly.

So, what's the problem? The image quality is poor and plane. But this emulator manages to reproduce what seems 3 shades of gray. I tried to disassemble but got a little lost. With a lot of effort, I got the CRT parameters it sets (comments are mine):

Code:
CRTCParms       DB      00h,38h ; Horizontal Total:  56 characters
                DB      01h,28h ; Horizontal Displayed:  40 characters
                DB      02h,2Dh ; Horizontal Sync Position:  at 45th character
                DB      03h,0Ah ; Horizontal Sync Width:  10 character clocks
                DB      04h,7Fh ; Vertical Total:  127 characters
                DB      05h,1Fh ; Vertical Adjust:  31 scan lines
                DB      06h,64h ; Vertical Displayed:  100 character rows
                DB      07h,70h ; Vertical Sync Position:  after 112th char row
                DB      08h,02h
                DB      09h,01h ; Max Scan Line:  2 scan lines per char
                DB      0Ah,06h
                DB      0Bh,07h
                DB      0Ch,00h

They set a 620x200, two scanline mode. It kind of works but something is still missing. No shades emulation and no correct aspect ratio on real hardware. What's missing?

I attach the CGA emulator if someone wants to disassemble it.

Thanks everybody.
 

Attachments

  • CGA.zip
    477 bytes · Views: 9
No shades emulation and no correct aspect ratio on real hardware

You set two scan lines per character; for 640x300 with every third line blank wouldn’t you set it for three scan lines?

(Assuming here that on Hercules hardware this would result in the third line being fetched from 8k starting at BC000, which presumably you blanked?)
 
You set two scan lines per character; for 640x300 with every third line blank wouldn’t you set it for three scan lines?

(Assuming here that on Hercules hardware this would result in the third line being fetched from 8k starting at BC000, which presumably you blanked?)
I have another collection of CRT params to set a 640x300 mode (I can post it if someone wants it). If I dump a CGA screen after setting this Herc mode or draw sprites, it displays the 3rd scanline blank without any further intervention, which is nice because you can add Hercules support without doing extra things. The same drawing and sprite routines used with CGA do the work automatically on Hercules, and the aspect ratio is correct. But the price you pay is having some "Venetian blinds". This technique is used by several games, like, for example, Planet X3, and several others I don't remember right now. A workaround to get rid of the blank scanlines is copying one of the drawn scanlines to the 3rd one, but I don't like too much that solution as it makes the game noticeably slower on slow machines, and it's not visually that good.

Other games, like Prince of Persia, set a 640x200 mode, like the params I posted do. No "Venetian blinds" this time but we got a shrinked image.

The emulator I posted does something else apart from setting a 640x200 mode. The params I posted are the ones the emulator sets, as I found them while tried to disassemble it. The emulator does something else because the aspect ratio is correct (4:3) and it blends the horizontal lines into shades of gray. The problem is I got stuck at disassembling it. It has a call [BX] instruction that drives crazy all the disassemblers I tried.
 
Last edited:
A solution I figured out is substituting that call [BX] by call imm16. Because, IIRC, there's a mov bx,imm16 instruction just before. I would do it with HxD editor. That maybe would do life easier to the dissasemblers...
 
Your disassemblers must not be very good :) Here's something I did just now using IDA. I did some commenting, but the rest is up to you...
 

Attachments

  • CGA.txt
    13.4 KB · Views: 15
Your disassemblers must not be very good :) Here's something I did just now using IDA. I did some commenting, but the rest is up to you...
Thanks for coming to the rescue, Jim. One of the disassemblers I tried was, indeed, IDA. So I'm the one who's not good at disassembling, not the software 😅
 
Back
Top