How to draw Image
How to draw Image
How can I impliment a script to draw an image (*.bmp) onto screen over VGA?
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: How to draw Image
Well, it needs to fit the exact screen size, you need to load the image off of a floppy or drive via the filesystem (probably the hardest part), get rid of the headers, and draw it on the screen. There are probably other things I've missed though.
Good luck!
Troy
Good luck!
Troy
Re: How to draw Image
Thanks for reply!
And how can I get for example the bytes of the file? Is there any example you know?
And how can I get for example the bytes of the file? Is there any example you know?
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: How to draw Image
I don't know exactly how to do it, but I'll ask you this: can your OS load files off of a disk?
-
- Member
- Posts: 155
- Joined: Fri Oct 27, 2006 5:11 am
- Location: Oberbayern
- Contact:
Re: How to draw Image
Without knowing the type of OS you're using (16-bit real mode? 32-bit protected mode?) or programming language, it's hard to say. My OS project includes a program which displays 320x200 PCX images to the screen using real mode x86 assembly language: see pcxview.asm in the programs directory from the downloads at http://mikeos.berlios.de
I know you're trying to use BMPs, but many of the concepts are the same, so it might be useful.
M
I know you're trying to use BMPs, but many of the concepts are the same, so it might be useful.
M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
http://mikeos.sourceforge.net
Re: How to draw Image
thanks, that works!
Re: How to draw Image
Here this may help a simple load BMP image.
Code: Select all
;**********************************;
; Simple load bmp demo ;
; Assemble like this: ;
; c:\fasm BmpDemo.asm BmpDemo.com ;
; ;
; By Dex. 15/06/07 ;
;**********************************;
org 100h
use16
start:
mov [LoadAddress],0 ; this is the offset of the top corner of image on screen.
; So to put mario in middle of screem you would do this
; mov [LoadAddress],320*100+160
mov ax,0013h ; set video mode13h
int 10h
mov ax,image ; move the address of our image into ax
mov [ImageBase],ax ; load ax into the var "ImageBase"
call DisplayBmp ; call the bmp display function.
jc error ; check for errors
mov ah,00h ; wait for key press.
int 16h
error:
mov ax,0003h ; change to text mode
int 10h
ret ; return to dos
DisplayBmp:
pusha ; save the regs
push ds
push es
mov si,[ImageBase] ; make sure si as the image address
cmp word [si+00h],4D42h ; test for 'BM' to make sure its a BMP file.
jnz BmpError ; if jump to exit with error
mov bx,[si+12h] ; start of header + 18 = width
mov bp,[si+16h] ; start of header + 22 = depth
cmp bx,320
ja BmpError
cmp bp,200
ja BmpError
cmp word [si+1Ch],8 ; start of header + 28 = bpp
jnz BmpError
mov si,0036h ;start of header + 54 = start of palette
add si,[ImageBase]
mov cx,256 ;number of colors for patette
mov dx,03C8h
mov al,0
out dx,al
inc dx
SetPalete:
mov al,[si+2] ; red
shr al,2
out dx,al
mov al,[si+1] ; green
shr al,2
out dx,al
mov al,[si] ; blue
shr al,2
out dx,al
add si,4
loop SetPalete
push 0A000h
pop es
lea dx,[bx+3] ; round bmp width ;)
and dx,-4
imul di,bp,320
add di,[LoadAddress] ; this is the X Y offset of the screen
new_line:
sub di,320
pusha
mov cx,bx
rep movsb
popa
add si,dx
dec bp
jnz new_line
ExitOK:
clc
pop es
pop ds
popa
ret
BmpError:
stc
pop es
pop ds
popa
ret
;----------------------------------------------------;
; Data ;
;----------------------------------------------------;
LoadAddress dw 0
ImageBase dw 0
; you can include a bmp or file like this with fasm
; (NOTE: You can only use upto 64k with a com file).
image:
file 'mario.bmp' ; image1
Re: How to draw Image
thanks
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: How to draw Image
If you're using NASM basically all you have to do is change the file 'mario.bmp' to %incbin "mario.bmp".
Re: How to draw Image
Can I use this code in my OS? How?
-
- Member
- Posts: 155
- Joined: Fri Oct 27, 2006 5:11 am
- Location: Oberbayern
- Contact:
Re: How to draw Image
By learning to program computers.sadisoft wrote:Can I use this code in my OS? How?
Seriously, if you don't understand the relationship/differences between C/asm and 32-bit protected mode/real mode, you are not ready to write an operating system. Sorry, but it's true. I have absolutely no idea why people think OS development is just like writing an MS Paint clone or something like that -- it's much, much more complex and involved.
Then again, maybe we're just being trolled on a large scale
M
MikeOS -- simple, well-documented x86 real-mode OS written in assembly language
http://mikeos.sourceforge.net
http://mikeos.sourceforge.net
- Troy Martin
- Member
- Posts: 1686
- Joined: Fri Apr 18, 2008 4:40 pm
- Location: Langley, Vancouver, BC, Canada
- Contact:
Re: How to draw Image
I think part of what sadisoft meant was "Am I allowed to use this in my OS?"
But the how is another lead to trolling. This is getting fun! I'd love to be a temporary mod and smash the hammer a few times right now!
But the how is another lead to trolling. This is getting fun! I'd love to be a temporary mod and smash the hammer a few times right now!
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: How to draw Image
Same here.
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]
[ Project UDI ]