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)

http://rubbermallet.org/goat1.png

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:
http://rubbermallet.org/goat.asm

any idea why it looks the way it does? i'm sure the answer is obvious to somebody more experienced.

thanks!
-mike

mov ax, word ptr [pal]
mov si, ax

shouldn't this be a "lea si, [pal]" or similar?

also, you are missing a "cld" instruction

I don't know if this will help, but your file, goat.asm, when I ran it on emu8086, a message that stated "Any code after 'END' directive is ignored." I don't know what that means since I'm a beginner in ASM, so I don't know what that means.

Wishes and regards,
Seth Price

I don't know if this will help, but your file, goat.asm, when I ran it on emu8086, a message that stated "Any code after 'END' directive is ignored." I don't know what that means since I'm a beginner in ASM, so I don't know what that means.

Wishes and regards,
Seth Price

oh wow i forgot about this. old thread.

END is required by many assembly compilers to indicate EOF in the code, but emu8086 doesn't require that. that message can be ignored.

anyway, i solved this a very long time ago but thanks for the effort. i've also become quite good at assembly in general since then if i do say so myself. i've written a fully working TCP/IP TSR stack for DOS in 100% assembly. :)

and as long as this thread is being bumped anyway, if anybody was interested at all the PC emulator i said i was writing works extremely well now. and i re-wrote the whole emulator in C, it's no longer FreeBASIC.

it's called fake86. source/binaries available on my site:

http://fake86.rubbermallet.org

enjoy, if interested. it's like a poor man's QEMU more or less.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.