;**************************************************************************************
;
; This Code Show a 256 Color bitmap file in 13h mode. Support negative
; coordinate and auto cut out. The 'Bitmap' function have there para:
; the pointer to bitmap file name, X coordinate and Y coordinate. The
; function can be called like this:
;
; push Y coordinate
; push X coordinate
; push offset ImageSrc
; call Bitmap
;
; Written By Nirvana
; email:westdatas@163.com
; oicq :19820914
;**************************************************************************************
Stack Segment
Stk db 65535 dup(?)
Stack Ends
Data Segment
ImageBuffer db 65078 dup(?)
ImageSrc db 'test.bmp',0
Eflag db ?
OpenErrorMsg db 'open file error',24h
Not256Color db 'Not a 256 color bitmap',24h
handle dw ?
Data Ends
Code Segment
Assume cs:Code,ds:Data,ss:Stack
Start:
mov ax,Data
mov ds,ax
mov di,-100
mov si,50
mov dx,offset ImageSrc
push si
push di
push dx
call Bitmap
mov ax,0
int 16h
mov ax,4c01h
int 21h
push bp
mov bp,sp
sub sp,20
push ax
push bx
push cx
push dx
push si
push di
push es
mov dx,[bp+4]
mov ax,3d00h
int 21h ;Open the bitmap file
jnc OpenOk
mov Eflag,0
Error: ;Show error message
cmp Eflag,0
jz OpenError
cmp Eflag,1
jz Not256
OpenError:
mov dx,offset OpenErrorMsg
jmp showtext
Not256:
mov dx,offset Not256Color
jmp ShowText
ShowText:
mov ah,09h
int 21h
jmp exit
OpenOk:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Read first 4 byte of the file in order to get the file size ;;;;;;;;;;;;
; ; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;
;;
mov bx,ax ;;
mov handle,bx ;;
mov dx,offset ImageBuffer ;;
mov cx,4 ;;
mov ax,3f00h ;;
int 21h ;Read the first 4 byte to memory ;;
mov ax,3e00h ;;
mov bx,handle ;;
int 21h ;Close the bitmap file ;;
;;
;====================================================================================;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; ;
; Read The entire bitmap file to memory ;;;;;;;;;;;;
; ; ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;
;;
mov si,2 ;;
mov cx,[si] ;Save the bitmap file entire size to CX Register ;;
mov dx,[bp+4] ; ;;
mov ax,3d00h ;;
int 21h ;Open the bitmap file again ;;
mov bx,ax ;;
mov handle,bx ;;
mov dx,offset ImageBuffer ;;
mov ax,3f00h ;;
int 21h ;Read the entire bitmap file to memory ;;
mov ax,3e00h ;;
mov bx,handle ;;
int 21h ;Close the bitmap file ;;
;;
;====================================================================================;;
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;
; Seve the value to Local variable
;
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;**************************************************************************************
;
; Set the Palette register and copy image data to video buffer which
; address start at A000:0000.
;
;**************************************************************************************
SetInt10:
mov ax,013h
int 10h ;Set Video Mode to 13h
mov dx,03c6h
mov ax,0ffh
out dx,ax
mov si,[bp-16]
mov di,0
mov cx,256
SetPalette:
mov dx,03c8h
mov ax,di
out dx,al
mov dx,03c9h
mov al,byte ptr[si+2]
push bx
mov bl,63
mul bl
mov bl,0ffh
div bl
pop bx
out dx,al
mov al,byte ptr[si+1]
push bx
mov bl,63
mul bl
mov bl,0ffh
div bl
pop bx
out dx,al
mov al,byte ptr[si]
push bx
mov bl,63
mul bl
mov bl,0ffh
div bl
pop bx
out dx,al
add si,4
inc di
loop SetPalette
Showbmp:
mov ax,0a000h ;Video memory start address
mov es,ax
mov ax,[bp+8]
mov cx,320
mul cx
add ax,[bp+6]
mov di,ax
vertical:
cmp word ptr[bp-12],0
jz exit
dec word ptr[bp-10]
dec word ptr[bp-12]
mov ax,[bp-10]
mul word ptr[bp-6]
mov bx,ax
add bx,[bp-18]
mov si,0
add si,[bp-8]
horizon:
cmp si,word ptr[bp-4]
jz horizonend
mov al,[bx][si]
mov es:[di],al
inc si
inc di
jmp horizon
horizonend:
add di,[bp-20]
jmp Vertical