let me preface this by explaining the reason i'm writing this code.. i've been writing an x86 PC emulator in FreeBASIC, and this program is designed to test it's handling of video mode 13h, including palette manipulation. i thought in addition to being fun (at least for a nerd like me), writing an 8086 CPU + PC architecture emulator from the ground up would be the ultimate crash course in teaching myself assembly language and understanding the PC's internals better. i've been on this project for about 3 months now.
anyway... i've written this code that has the data of a 320x200 8-bit photo of a stupid looking goat embedded in it, as well as the palette data. it compiles to a .COM file using MASM 6.11.. however, the output it draws to the screen looks all messed up. this is it running in the emulator i'm coding. (it's not a bug in my emu, it looks exactly the same if i use DOSBox)
i am not going to embed the whole source file in this post, because it's over 300 KB. (99.9% of that is just the raw image data after the code section) but here is the actual code lines:
.8086 .MODEL tiny .CODE start: org 100h ;we want to make a .com so align it after the DOS PSP mov ax, 13h ;function 0, AL = 13h int 10h ;on int 10h to set 320x200 256-color mode push cs ;make sure our DS is the same pop ds ;as our CS mov ax, word ptr [pal] ;place the pointer to the palette mov si, ax ;data start point into SI mov dx, 3C6h ;VGA palette mask register mov al, 0FFh ;mask all out dx, al ;send that byte! mov dx, 3C8h ;VGA palette index register mov al, 0h ;we want to start at entry 0 out dx, al ;send that byte! mov dx, 3C9h ;the palette data bytes will all go to this port mov cx, 768 ;256 colors to set, 3 bytes of data each nextpal: lodsb ;load current byte pointed to by SI into AL out dx, al ;and send it to the VGA palette data port inc si loop nextpal mov ax, word ptr [image] ;place the pointer to the image mov si, ax ;data start point into SI mov ax, 0A000h ;set the VGA base segment mov es, ax ;and put it into ES for our movsw cycles mov di, 0h ;and make sure we start at offset 0 mov cx, 32000 ;64,000 bytes, but moving 2 at a time rep movsw ;DRAW THAT GOAT!! mov ax, 0h ;finished, wait for the user int 16h ;to press a key mov ax, 3h ;before we go back into 80x25 16-color text mode int 10h ret .DATA image db ;SNIP! the next few thousand lines in the code is just the raw image data db'd .DATA pal db ;and the next 256 lines from here are RGB triplets db'd end start END
if you want the entire file, it's here:
any idea why it looks the way it does? i'm sure the answer is obvious to somebody more experienced.
Edited 5 Years Ago by miker00lz: n/a