So I'm writing a game in c++ for MS-DOS and I'm including some inline assembly for speed. This particular block of code would draw a star into the video memory (0A000h). The problem with my code is that it only draws one pixel in whatever color dh is set to. As far as I know mov dx, 00007h is equivalent to setting dh to 0 and dl to 7. What is wrong?
The equivalent C/C++ code (or at least my intention) is commented beside each line. My compiler is turbo C++ 3.0. I'm trying to only use 8086/8088 instructions.
Also I know how old MS-DOS is so don't tell me to write code for a newer compiler/operating system. Writing code for dos is kind of a hobby of mine.
pixelOffset = x + (y << 6) +  (y << 8);
_asm {
    mov  ax, WORD PTR pixelOffset
    mov  di, ax
    mov  ax, 0A000h         ;pointer to the video memory
    mov  es, ax
    mov  dx, 00007h         ;indexed color 00 and 07
    mov  cx, 0000Fh         ;indexed color white 0F
    add  ax, 2              ;pixelOffset += 2;
    mov  es:[di], dh        ;videomem[pixelOffset] = BLACK;
    add  ax, 319            ;pixelOffset += 319;
    mov  es:[di], dh        ;videomem[pixelOffset] = BLACK;
    add  ax, 1              ;pixelOffset += 1;
    mov  es:[di], dl        ;videomem[pixelOffset] = LIGHT_GRAY;
    add  ax, 1              ;pixelOffset += 1;
    mov  es:[di], dh        ;videomem[pixelOffset] = BLACK;
    add  ax, 317            ;pixelOffset += 317;
    mov  es:[di], dh        ;videomem[pixelOffset] = BLACK;
    add  ax, 1              ;pixelOffset += 1;
    mov  es:[di], dl        ;videomem[pixelOffset] = LIGHT_GRAY;
    add  ax, 1              ;pixelOffset += 1;
    mov  es:[di], cx        ;videomem[pixelOffset] = WHITE;
    add  ax, 1              ;pixelOffset += 1;
    mov  es:[di], dl        ;videomem[pixelOffset] = LIGHT_GRAY;
    add  ax, 1              ;pixelOffset += 1;
    mov  es:[di], dh        ;videomem[pixelOffset] = BLACK;
    add  ax, 317            ;pixelOffset += 317;
    mov  es:[di], dh        ;videomem[pixelOffset] = BLACK;
    add  ax, 1              ;pixelOffset += 1;
    mov  es:[di], dl        ;videomem[pixelOffset] = LIGHT_GRAY;
    add  ax, 1              ;pixelOffset += 1;
    mov  es:[di], dh        ;videomem[pixelOffset] = BLACK;
    add  ax, 319            ;pixelOffset += 319;
    mov  es:[di], dh        ;videomem[pixelOffset] = BLACK;
}
                I think you have forgotten to update di after updating ax
add ax,1
mov di,ax ;don't forget this line
mov es:[di],dl
                        It doesn't look like you're ever incrementing "di", does it? Perhaps you meant "movsb"?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With