Image Map Image Map
View RSS Feed

DOS / IBM PC Programming

This is the development journal of Neil C. Obremski for my ongoing efforts into the old world of coding for IBM PC's and compatibles running DOS.

  1. C's itoa() in Assembler with mini-sprintf bonus

    I've been poking around for a quick way to convert 16-bit words into digit characters a la the itoa() function in C. [1] I thought and searched a lot around dividing by constants and clever ways of converting numbers to strings. In the end, I chose the K&R method as the base for my algorithm [2] which goes like this:

    1. Divide number by base (10).
    2. Write remainder as next digit (converting to ASCII by adding 30h).
    3. Use quotient as number and repeat loop if non-zero.
    4. Reverse
    ...
    Categories
    Asm
  2. CGA Tiny Font (4x4)

    In accordance with yesterday's entry on text rendering, I've now created the routine for a "tiny" font. What this does is take the 8x8 glyphs and compresses them into 4x4 squares by creating a sort of average brightness of each pixel based on the surrounding 4. The four distinct colors of CGA mode 4 (black, magenta, white, cyan) are thus used for brightness and the caller cannot specify the foreground or background colors of the text.

    Click image for larger version. 

Name:	tinyblit.jpg 
Views:	9 
Size:	8.2 KB 
ID:	39906
    ...
    Tags: assember, bios, cga, font, x86 Add / Edit Tags
    Categories
    Asm
  3. CGA Text Blit

    I went back and forth over whether or not to write my own text rendering routine in assembler. DOS supplies a decent print string function [1] but it turned out to be insufficient to my needs. My requirements include the ability to change color mid-stream as well as repeat lines of pixel data twice to create a "large" font. Here's a screenshot from a test of the C functions I created back in January:

    Click image for larger version. 

Name:	fonts-testcga.jpg 
Views:	11 
Size:	30.4 KB 
ID:	39886

    There were three functions ...
    Tags: bios, cga, x86 Add / Edit Tags
    Categories
    Asm
  4. Variable FPS Animation with DDA

    I just finished writing some code to animate movement and turning. When initially planning to tackled this task I was going to make a lot of assumptions and fix the framerate regardless of the computer speed. This would mean that on fast-enough computers the animation would run as expected but on slower computers it would slow down. Of course, once I started down this path I immediately didn't like it and decided to delve into writing something that would adjust the FPS [1] depending on how much ...
    Tags: bresenham, math Add / Edit Tags
    Categories
    Asm
  5. IDIV and IMUL do not set Sign Flag

    Or more specifically:

    The CF, OF, SF, ZF, AF, and PF flags are undefined.
    What it comes down to is that you cannot safely jump (JS / JNS) based on a signed multiply or divide.

    Code:
    MOV AX, FF00	;
    CWD		; DX:AX = -256
    MOV BX, 0012	; BX = +18
    IDIV	BX	;
    JNS	$+4	; WRONG!
    NEG	AX	; AX = ABS(DX:AX / BX)
    The fix is to re-test the highest byte of the result (DH, AH or AL depending ...):

    Code:
    MOV AX, FF00	;
    ...

    Updated July 11th, 2017 at 07:15 AM by neilobremski (Corrected mistakes identified by Krille)

    Categories
    Asm
Page 1 of 7 12345 ... LastLast