As a small project I decided to add CGA graphics capability to my DOS platform game, Bob’s Fury. I have already implemented EGA, VGA (mode 13h) and VESA (640×400) modes. I had hoped to be able to run the game on older machines including 286 class machines as a minimum specification. The trouble being that the EGA mode tends to be a bit slower because of the way its video memory is laid out (planar mode). VGA mode 13h works quite well, but machines of that vintage do not necessarily have a VGA card.
Early 286 machines were about 6-8Mhz, but had speed advantage over 8086/8088 machines because of being a more advanced processor. Later 286 machines got to about 16-20Mhz on average, but as high as 25Mhz about the time the 386 came out. This makes the 286 class an interesting beast as performance can vary quite a bit not only based on the processor, but also the speed of the RAM and chipset. It also spanned quite a change in graphics capability as it started when CGA was standard and lived until the early days of VGA.
Hence my desire to add CGA support.
I haven’t written my own graphics drivers for the game, partly because that’s tones of work especially if you want to support multiple video cards. I’m using Borland’s Turbo Pascal 6.0 and I used the Graph unit built-in. It uses drivers stored in BGI files so you can write an application that works with a number of video cards and modes. This has made the programming relatively easy to add new graphics modes, which is part of the reason I started adding support for older cards. I have heard the disadvantage of the BGI/Graph system is that is can be slower performance wise compared with assembly code.
My main problem adding CGA support is the same as before, converting my existing VGA artwork to a 4 colour palette. I had solved this problem for 16 colours when I initially added EGA support with a horizontally doubled resolution, but because the only CGA modes with colour are 320×200 I wasn’t going to be able to do the exact same thing again.
I eventually worked out technique that I’m happy with. It’s a little bit more complex than the technique for EGA because of the very limited number of colours. I allocate CGA colours to the most commonly used VGA ones, then using the neighbouring pixels work out what the best CGA colour would be for the remaining VGA colours.
The end result is ok for CGA, but clearly not as good as the other modes. After testing I found it was quite a bit faster than EGA, but not as fast as VGA as expected. It means the game should run on a 286 of pretty much any type now. Whether they are slow or fast and have CGA,EGA, or VGA.
Recent Comments