Great Hierophant
Veteran Member
Several years ago, I found a way to display images from standard file formats on even the most humble hardware : https://nerdlypleasures.blogspot.com/2016/01/displaying-dosbox-screenshots-on-real.html
But I found that the solution for CGA cards was rather limited (and slow). Of all the graphics adapters, CGA is only one of two graphics cards where its graphics modes cannot fully display an image of its text modes. CGA can show all 16 colors in text modes but for graphics modes which support the effective text mode resolutions, the colors are limited to 4 and 2 and they are not freely selectable. Moreover, the CompuShow program is limited to BIOS functionality when it comes to CGA color. This means no 640x200 composite color, no selectable foreground color in 640x200, no non-intense palettes, no alternate palettes, no background/border select for 320x200.
If someone were to write an image display program to run on older PCs, the program would have difficulties with displaying images. I think the easiest way to overcome these difficulties is by adding a header which can tell a program what it needs to do with the CGA registers to display the image properly. Here is what I suggest as the structure for the header :
00 - $43 "C"
01 - $47 "G"
02 - $41 "A"
03 - $1A DOS End-of-File
04 - 6845 R0
05 - 6845 R1
06 - 6845 R2
07 - 6845 R3
08 - 6845 R4
09 - 6845 R5
0A - 6845 R6
0B - 6845 R7
0C - 6845 R8
0D - 6845 R9
0E - 6845 R10
0F - 6845 R11
10 - 6845 R12
11 - 6845 R13
12 - 6845 R14
13 - 6845 R15
14 - CGA Mode Control ($00-$3F)
15 - CGA Color Select ($00-$3F)
16 - Palette Change Scanline (FF = No palette Change, otherwise $00-C8)
17 - CGA Color Select ($00-$3F)
18 - File Type (00 = Respect Image File Header, 01 = Raw Index Values, 02 = Raw Memory Values)
19-1F - Reserved for Future Expansion
So, the header should be reasonably self-explanatory, the CGA register values are included to ensure image fidelity, then there is a byte to indicate whether there a palette change will occur. For most images, this will not happen, but if it does then the image must indicate the scanline where the palette will change and the image viewer will have to try to accommodate that.
The image should be in an indexed format limited to no more than 16 colors. Common, low-color friendly uncompressed or losslessly compressed format like bmp, png, gif or pcx support color indexing. These files can be converted to RAW files that contain only the indexes and are 64000 bytes in size.
The palette order for the indexes must be in the CGA order, and for DOSBox and other emulators, it typically is.
If you wish to show any image that is based in a text mode, you will need to dump a raw memory dump which will indicate which ASCII characters are being used and each cell's attributes.
But I found that the solution for CGA cards was rather limited (and slow). Of all the graphics adapters, CGA is only one of two graphics cards where its graphics modes cannot fully display an image of its text modes. CGA can show all 16 colors in text modes but for graphics modes which support the effective text mode resolutions, the colors are limited to 4 and 2 and they are not freely selectable. Moreover, the CompuShow program is limited to BIOS functionality when it comes to CGA color. This means no 640x200 composite color, no selectable foreground color in 640x200, no non-intense palettes, no alternate palettes, no background/border select for 320x200.
If someone were to write an image display program to run on older PCs, the program would have difficulties with displaying images. I think the easiest way to overcome these difficulties is by adding a header which can tell a program what it needs to do with the CGA registers to display the image properly. Here is what I suggest as the structure for the header :
00 - $43 "C"
01 - $47 "G"
02 - $41 "A"
03 - $1A DOS End-of-File
04 - 6845 R0
05 - 6845 R1
06 - 6845 R2
07 - 6845 R3
08 - 6845 R4
09 - 6845 R5
0A - 6845 R6
0B - 6845 R7
0C - 6845 R8
0D - 6845 R9
0E - 6845 R10
0F - 6845 R11
10 - 6845 R12
11 - 6845 R13
12 - 6845 R14
13 - 6845 R15
14 - CGA Mode Control ($00-$3F)
15 - CGA Color Select ($00-$3F)
16 - Palette Change Scanline (FF = No palette Change, otherwise $00-C8)
17 - CGA Color Select ($00-$3F)
18 - File Type (00 = Respect Image File Header, 01 = Raw Index Values, 02 = Raw Memory Values)
19-1F - Reserved for Future Expansion
So, the header should be reasonably self-explanatory, the CGA register values are included to ensure image fidelity, then there is a byte to indicate whether there a palette change will occur. For most images, this will not happen, but if it does then the image must indicate the scanline where the palette will change and the image viewer will have to try to accommodate that.
The image should be in an indexed format limited to no more than 16 colors. Common, low-color friendly uncompressed or losslessly compressed format like bmp, png, gif or pcx support color indexing. These files can be converted to RAW files that contain only the indexes and are 64000 bytes in size.
The palette order for the indexes must be in the CGA order, and for DOSBox and other emulators, it typically is.
If you wish to show any image that is based in a text mode, you will need to dump a raw memory dump which will indicate which ASCII characters are being used and each cell's attributes.