{"id":1813,"date":"2012-10-07T20:00:59","date_gmt":"2012-10-07T19:00:59","guid":{"rendered":"https:\/\/www.reenigne.org\/blog\/?p=1813"},"modified":"2012-09-23T11:40:31","modified_gmt":"2012-09-23T10:40:31","slug":"improved-composite-mode-support-for-dosbox","status":"publish","type":"post","link":"https:\/\/www.reenigne.org\/blog\/improved-composite-mode-support-for-dosbox\/","title":{"rendered":"Improved composite mode support for DOSBox"},"content":{"rendered":"<p>I recently contributed to a DOSBox patch to make composite output work in all CGA graphics modes. Most CGA composite games use BIOS mode 6 (port 0x3d8 value 0x1a, aka 640x200 1bpp mode) which gives a <a href=\"http:\/\/en.wikipedia.org\/wiki\/File:CGA_Composite_Vs_RGB_640_Smaller_File.png\">nice range of colours<\/a>. However, there are a rare few games which use a 2bpp mode but have 3.57MHz vertical lines which are quite obviously designed to yield a <a href=\"http:\/\/en.wikipedia.org\/wiki\/File:CGA_CompVsRGB_320p0.png\">different palette on the composite output<\/a>. DOSBox currently shows the output of such games as they would appear on a digital (aka TTL or RGBI) monitor, which isn't always what the game author intended - the example that started <a href=\"http:\/\/vogons.zetafleet.com\/viewtopic.php?t=12319\">the thread<\/a> was <a href=\"http:\/\/www.mobygames.com\/game\/dos\/fooblitzky\/screenshots\">Fooblitsky<\/a>.<\/p>\n<p>I had already written code to simulate composite CGA in 2bpp mode (and indeed all modes) but there is a complication - DOSBox is based around a 256 colour palette and my code assumes 24-bit colour. The first 16 colours are also reserved for the digital CGA colours so that the palette entries don't have to be reloaded when switching between composite and digital, so only 240 colours can be used for composite CGA. The current DOSBox CGA composite implementation uses 80 palette entries - 16 colours (one for each bit pattern) times 5 brightness levels (0, 1, 2, 3 or 4 pixels lit). I realized that actually only 16 of these palette entries are really needed, since the same information is being used to dereference both the \"bit pattern\" table and the \"brightness\" table. Also, DOSBox's current implementation isn't quite right since some of the colour fringes are desaturated - look at the top tapper screenshot (the one from DOSBox) <a href=\"http:\/\/vogons.zetafleet.com\/viewtopic.php?t=12319&postdays=0&postorder=asc&start=140#263143\">here<\/a> and compare it to the more correct version below - look in particular at the middle of the \"SODA\" sign in the window, the right edge of the D and the left edge of the O, which is grey in DOSBox (missing its fringing entirely). Since DOSBox uses a (1, 1, 1, 1) kernel for its NTSC filter, there are only actually 16 possible colour combinations (though they are permutated depending on the colour carrier phase).<\/p>\n<p>I realized that a similar technique might be possible for the 2bpp modes. Each output composite pixel depends on the colours of four consecutive pixels of <a href=\"https:\/\/www.reenigne.org\/blog\/the-cga-wait-states\">hdot<\/a> width. These pixels cover at most 3 consecutive ldots, so any given pixel position depends on at most 6 bits of video data. It also depends on 2 bits of x position, so we need 8 bits of palette entries, or 256 colours - just slightly too many. There's an easy way to reduce the amount of palette entries though - half of the output hdots depend on only 2 consecutive ldots (since the sampled hdots exactly cover 2 ldots). So even hdots have 16 possible colours and odd hdots have 64, for a total of 16+64+16+64 = 160 colours - plenty to spare. What's more, the \"render\" part of the new algorithm is even faster than it used to be (although the mode setting part is probably much slower - however it's run sufficiently rarely that there's no need to optimize it).<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently contributed to a DOSBox patch to make composite output work in all CGA graphics modes. Most CGA composite games use BIOS mode 6 (port 0x3d8 value 0x1a, aka 640x200 1bpp mode) which gives a nice range of colours. However, there are a rare few games which use a 2bpp mode but have 3.57MHz [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,38],"tags":[],"class_list":["post-1813","post","type-post","status-publish","format-standard","hentry","category-computer","category-emulation"],"_links":{"self":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/1813","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/comments?post=1813"}],"version-history":[{"count":2,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/1813\/revisions"}],"predecessor-version":[{"id":1906,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/posts\/1813\/revisions\/1906"}],"wp:attachment":[{"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/media?parent=1813"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/categories?post=1813"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.reenigne.org\/blog\/wp-json\/wp\/v2\/tags?post=1813"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}