How to draw Image
Posted: Sun Nov 16, 2008 11:11 am
How can I impliment a script to draw an image (*.bmp) onto screen over VGA?
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
By learning to program computers.sadisoft wrote:Can I use this code in my OS? How?