The MS-DOS scalability mayhem


Clicca qui per la versione italiana! ;-)

When I approached Pacuvia's MS-DOS port I began my first draft of the code with Freebasic, but soon I decided to discard this option. DOS Freebasic works in a 32-bit extended/protected mode environment, so I was supposed to ditch support for any machine below a 386 with 4Mb and VGA. No dice, this was a "sentimental research project", after all. ;-) I experienced my first adventure game (Manhunter: New York, for the record) on an 8088 XT CGA machine with 512Kb RAM, so Pacuvia HAD to run in real-mode on older machines. That was mandatory.
So... there was no need to reinvent the wheel: I purchased a legitimate copy of QuickBasic 4.5 from Ebay. The language is still very popular and I found many tutorials, tools and wikis to support me in my journey.
Dav's Qbasic Site basically saved my life. I studied and used Dav's codes and tools to tackle the hardest challenge of this particular port: scalability of art assets. I had to provide three different versions of intro/ending credits: CGA (4 colors), EGA (16 colors) and VGA (256 colors).

How I displayed my VGA images

Premise: Pacuvia's VGA credits panels were born as uncompressed 320x200 8-bit color-depth BMP (64kb each). I discovered GIMP doesn't save purely uncompressed 8-bit BMP, even when you choose that option. I used IrfanView to convert my PNG to the correct BMP format I needed. Here are the steps I followed to implement the image in my code.

  1. I used Dav's "Save SCREEN 13 to Image file" tool ("save13.bas") to convert the BMPs to the BSAVED format. Although I couldn't make the resulting images work in my code, the tool was still useful to extract those final 768 bytes from each file: those bytes (which I cut & paste in separate ".pal" files through a Hex editor) contain the palette of each image! This is necessary to handle VGA screens: VGA offers a gigantic 262.144 colors palette, so the card needs to know the chosen 256 hues to display in a specific image.
  2. I extended Dav's simple image viewer "320x200, 8-bit BMP viewer - Version B" ("BMP320B.bas") with the following custom code, to capture and correctly BSAVE the screen data (I didn't care about the palettes, which I already got).
    DIM image (1 TO 32002) AS INTEGER
    GET (1, 1)-(320, 200), image
    SLEEP
    CLS
    PRINT "press any key to save the screen"
    SLEEP
    DEF SEG = VARSEG(image(1))
    BSAVE "intro.vga",  VARPTR(image(1)), 64004
    DEF SEG
  3. The results of #1 and #2 were two files for each picture: a "VGA" file with BSAVED pixel data, and a "PAL" file with palette data. PUT statements were the easiest and fastest way to show the basic picture, but I had to come up with my QB45 routine to send RGB palette data to the video card port: all the tutorials I found were written in different BASIC dialects or Assembly! Here's the complete routine, taken from the source code and slightly modified for this article.
    DIM image(1 TO 32002) AS INTEGER
    SCREEN 13
    CLS
    OPEN "palette.pal" FOR BINARY AS #1
    FOR i% = 0 TO 255
    rgb$ = INPUT$(3, 1)
    OUT &H3C8, i%
    OUT &H3C9, ASC(MID$(rgb$, 1, 1))
    OUT &H3C9, ASC(MID$(rgb$, 2, 1))
    OUT &H3C9, ASC(MID$(rgb$, 3, 1))
    NEXT i%
    CLOSE #1
    DEF SEG = VARSEG(image(1))
    BLOAD "intro.vga", VARPTR(image(1))
    DEF SEG
    PUT (0, 0), image, PSET

How I displayed my CGA/EGA images

Displaying CGA/EGA pictures SHOULD be easier, because you don't need to handle palette files. You just have a fixed 16 colors palette in a 320x200 CGA/EGA context. Numbers from 0 to 15 identify those colors, and that's it. More or less. I still had to create the pictures and save them in a format compatible with my code.
I couldn't find non-cracked tools that allowed me to easily use my GIMP pictures, so I had an idea. 

  1. I redrew the panels with 4 (CGA) and 16 colors (EGA), but I still saved them as 8-bit 256-colors uncompressed BMP.  The resulting files could be opened by Dav's tools, that only work with 256 colors images. Don't look at me like that, I was just getting creative! :-D Here's what I've done.
  2. I converted each image into DRAW statements through one of Dav's tools called "Save BMP to DRAW statements" ("BMP2DRAW.BAS"). I got a code too long (and too slow) to be embedded in my program, but that wasn't my goal. Wait and see. :-P
  3. I created new programs to show each image (through said DRAW statements) in mode SCREEN 1 (CGA) or SCREEN 7 (EGA). Then, I bsaved the whole screen with this code:
    DIM image(1 TO 8002) AS INTEGER: REM (FOR CGA)
    DIM image(1 TO 16004) AS INTEGER: REM (FOR EGA)
    GET (1, 1)-(320, 200), image
    SLEEP
    CLS
    PRINT "press any key to save the screen!"
    SLEEP
    DEF SEG = VARSEG(image(1))
    BSAVE "intro.cga", VARPTR(image(1)), 16004:REM (FOR CGA)
    BSAVE "intro.ega", VARPTR(image(1)), 32008:REM (FOR EGA)
    DEF SEG
  4. The resulting files could be opened in the game just by simple PUT statements.
    DIM image(1 TO 16002) AS INTEGER: SCREEN 7: REM (for EGA)
    DIM image(1 TO 8002) AS INTEGER: SCREEN 1: REM (for CGA)
    CLS
    DEF SEG = VARSEG(image(1))
    BLOAD "intro.cga", VARPTR(image(1)) : REM (for CGA)
    BLOAD "intro.ega", VARPTR(image(1)) : REM (for EGA)
    DEF SEG
    PUT (0, 0), image

Beware of one issue, though. Don't be stupid like me: during step #1, when working in GIMP or other tools, make sure that each color in your 4/16 palettes is indexed as it is in CGA/EGA standard palettes! Otherwise you'll get swapped or mismatched colors. Do you homework! I made this mistake and I had to manually correct "C" values in my DRAW statements during step #2. Argh. :-D


Get The Daring Rescue of Pacuvia the Sheep

Comments

Log in with itch.io to leave a comment.

Vabbè, che signore di gran classe a comprare QuickBASIC su eBay anziché rimediare setup e manuale dal web. Non scherzo, chapeau!

;-) Per principio volevo usare software in modo assolutamente legittimo, e andare nella direzione del freeware / open source era la strada migliore. Per questo ero partito col Freebasic, ma come ho spiegato non era adatto al mio approccio. E allora non mi rimaneva che una soluzione. :-D