4 Replies - 1213 Views - Last Post: 25 February 2011 - 04:48 PM

#1 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

why does this code not display the image correctly? (VGA mode 13h)

Posted 16 February 2011 - 12:19 AM

(i have posted this elsewhere, but nobody is responding or even viewing the thread so i'm hoping you DIC-heads can help me out)

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)

Posted Image

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! :gun_bandana:

Is This A Good Question/Topic? 0
  • +

Replies To: why does this code not display the image correctly? (VGA mode 13h)

#2 ishkabible  Icon User is offline

  • spelling expret
  • member icon





Reputation: 1616
  • View blog
  • Posts: 5,707
  • Joined: 03-August 09

Re: why does this code not display the image correctly? (VGA mode 13h)

Posted 22 February 2011 - 01:53 PM

have you seen the picture in 8-bit correctly? i know that converting an image meant for 32-bit color to 8-bit color will almost always produce this effect. try saving that file as an 8-bit picture and see what it looks like
Was This Post Helpful? 0
  • +
  • -

#3 Mike Chambers  Icon User is offline

  • D.I.C Head

Reputation: 22
  • View blog
  • Posts: 59
  • Joined: 30-March 09

Re: why does this code not display the image correctly? (VGA mode 13h)

Posted 22 February 2011 - 10:38 PM

yeah, i know. i converted it to an 8-bit palette indexed image with an optimized palette generated from the original 24-bit photo. the image itself is fine.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Head MFIC
  • member icon

Reputation: 5060
  • View blog
  • Posts: 26,429
  • Joined: 10-May 07

Re: why does this code not display the image correctly? (VGA mode 13h)

Posted 22 February 2011 - 10:56 PM

I agree with ishkabible. Seems like you are trying to push more colors than the palette of the altered image offers. Can you save it as gray scale or a lower quality image, like a sixteen bit bitmap & then add the image to the program.
Was This Post Helpful? 0
  • +
  • -

#5 Guest_Guest*


Reputation:

Re: why does this code not display the image correctly? (VGA mode 13h)

Posted 25 February 2011 - 04:48 PM

no, the 768 number is because it's in RGB triplets. 256 times 3 bytes of palette info.
Was This Post Helpful? 0

Page 1 of 1