标题:【原创】用16位汇编显示256色位图
只看楼主
zhulei1978
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
结帖率:100%
 问题点数:0 回复次数:4 
【原创】用16位汇编显示256色位图
;**************************************************************************************
;
;        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@
;                         oicq :19820914
;**************************************************************************************

Stack    Segment
         Stk          db    65535    dup(?)
Stack    Ends
Data     Segment
         ImageBuffer  db    65078    dup(?)
     ImageSrc     db    '6.bmp',0
     Eflag        db    ?
     OpenErrorMsg db    'open file error',24h
     Not256Color  db    'Not a 256 color bitmap',24h
     handle       dw    ?
         sg db 'http://bbs.bccn.net/'
Data     Ends
Code     Segment
         Assume cs:Code,ds:Data,ss:Stack
Start:
         mov ax,Data
     mov ds,ax
         MOV ES,AX
     mov di,24
         mov si,20
     mov dx,offset ImageSrc
     push si
     push di
     push dx
     call Bitmap

         MOV BP,OFFSET SG
         MOV     DX,1733H
         PUSH CX
         MOV     CX,20
         MOV AL,0H
         MOV BH,0H
         MOV     BL,01011010B
         MOV AH,13H
         INT 10H
         POP CX



     mov ax,0
     int 16h
         mov ax,4c01h
         int 21h
         
BitMap   Proc

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                          ;
;               ===================                                        ;
;             * Local Variable list *                                      ;
;               ===================                                        ;
;                                                                          ;
;        (1)  BmpWidth           (:Word)                                   ;
;        (2)  BmpOnScreenWidth   (:Word)                                   ;
;        (3)  BytePerRow         (:Word)                                   ;
;        (4)  LeftCutWidth       (:Word)                                   ;
;        (5)  BmpHeight          (:Word)                                   ;
;        (6)  BmpOnScreenHeight  (:Word)                                   ;
;        (7)  BytePerPixel       (:Word)                                   ;
;        (8)  PaletteOffset      (:Word)                                   ;
;        (9)  ImgDataOffset      (:Word)                                   ;
;        (10) RowOffset          (:Word)                                   ;
;                                                                          ;
;                                                                          ;
;===========================================================================

         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                                    ;;
                                                                                     ;;
;====================================================================================;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                          ;
;        Save Information to local variable                                ;;;;;;;;;;;;
;                                                                          ;         ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;         ;;
                                                                                     ;;
         mov si,012h                                                                 ;;
         mov ax,[si]                                                                 ;;
     mov [bp-2],ax     ;Save BmpWidth                                            ;;
     mov [bp-4],ax     ;Save BmpOnScreenWidth                                    ;;
     mov [bp-6],ax     ;Save BytePerRow                                          ;;
         mov cl,4                                                                    ;;
     div cl                                                                      ;;
     cmp ah,0                                                                    ;;
     jz  NoDwAA        ;No Dword align adjust                                    ;;
     mov cl,4                                                                    ;;
     sub cl,ah                                                                   ;;
     add [bp-6],cl                                                               ;;
NoDwAA:                                                                              ;;
         mov cx,0                                                                    ;;
     mov [bp-8],cx     ;Save LeftCutWidth,Default = 0                            ;;
     mov si,016h                                                                 ;;
     mov ax,[si]                                                                 ;;
     mov [bp-10],ax    ;Save BmpHeight                                           ;;
     mov [bp-12],ax    ;Save BmpOnScreenHeight                                   ;;
         mov si,01ch                                                                 ;;
     mov ax,[si]                                                                 ;;
     mov [bp-14],ax    ;Save BitPerPixel                                         ;;
     mov si,0eh                                                                  ;;
     mov ax,[si]       ;Save bmpfileheader length                                ;;
     add ax,14                                                                   ;;
     mov [bp-16],ax    ;Save PaletteOffset                                       ;;
         mov si,0ah                                                                  ;;
     mov ax,[si]                                                                 ;;
     mov [bp-18],ax    ;Save ImgDataOffset                                       ;;
         ;mov [bp-20],0     ;Save RowOffset                                          ;;
                                                                                     ;;
;====================================================================================;;

;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;                                                                                    
;        Seve the value to Local variable
;
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

         jmp CoorDinateX
exitzz:
         jmp exit
CoordinateX:         
     mov ax,[bp+6]     ;X coordinate
     push ax
     and ah,80
     pop ax
     jz  PositiveX     ;If X coordinate>=0,jump
     mov ax,[bp+6]
     push ax
     not ax
     inc ax
     mov [bp-8],ax     ;Save LeftCutWidth
     pop ax
     add ax,[bp-2]     ;X coordinate add BmpWidth
     jnc exitzz        ;Exit if X coordinate add BmpWidth < 0
     jz exitzz         ;Exit if X coordinate add BmpWidth = 0
     push ax
     mov cx,320
     sub cx,ax
     mov [bp-20],cx    ;Save RowOffset
         add ax,[bp-8]     
     mov [bp-4],ax     ;Save BmpOnScreenWidth + LeftCut
     pop ax
     mov cx,320
     cmp cx,ax
     jnc NoWOverf      ;No Width Overflow
     mov ax,[bp-8]
     add ax,320
     mov [bp-4],ax     ;Save BmpOnScreenWidth = 320 + LeftCutWidth
     mov ax,0
     mov [bp-20],ax
NoWOverf:
         mov ax,0
         mov [bp+6],ax
     jmp CoordinateY
PositiveX:
         cmp ax,320
     jnc exitzz
         mov cx,320
     sub cx,[bp-2]
     mov [bp-20],cx
     add ax,[bp-2]
     mov cx,320
     cmp cx,ax
     jnc CoordinateY
     mov ax,320
     sub ax,[bp+6]
     mov [bp-4],ax     ;Save OnScreenWidth
     mov cx,320
     sub cx,ax
     mov [bp-20],cx    ;SaveRowOffset
CoordinateY:
         mov ax,[bp+8]     ;Y coordinate
         push ax
     and ah,80
     pop ax
     jz PositiveY
     add ax,[bp-10]
     jnc exitzz1
     jz exitzz1
     mov [bp-10],ax    ;Save BmpHeight
     mov [bp-12],ax    ;Save OnScreenHeight
     mov cx,0
         mov [bp+8],cx
     mov cx,200
         cmp cx,ax
     jnc SetInt10      ;No Height Overflow
     mov cx,200
     mov [bp-12],cx
NoHOverf:        
     jmp SetInt10
exitzz1:
         jmp exit
PositiveY:
         cmp ax,200
     jnc exitzz1
     add ax,[bp-10]
     mov cx,200
     cmp cx,ax
     jnc SetInt10
     mov ax,200
     sub ax,[bp+8]
     mov [bp-12],ax

;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

;**************************************************************************************
;                                                                                    
;        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
   
;**************************************************************************************

exit:
         pop es
     pop di
     pop si
     pop dx
     pop cx
     pop bx
     pop ax
         add sp,20
     pop bp
     ret 6
Bitmap   endp
Code     Ends
         End Start

[此贴子已经被作者于2016-7-13 14:16编辑过]

搜索更多相关主题的帖子: function called file 
2016-07-13 14:03
zhulei1978
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
得分:0 
源程序下载:
13.zip (8.39 KB)

其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2016-07-13 14:03
zhulei1978
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:53
帖 子:1351
专家分:1200
注 册:2006-12-17
得分:0 

其实我就是改变社会风气,提高少女素质,刺激电影市道,提高年轻人内涵,玉树临风,风度翩翩的整蛊专家,我名叫古晶,英文名叫JingKoo!
2016-07-13 14:04
hu9jj
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:红土地
等 级:贵宾
威 望:396
帖 子:11713
专家分:43267
注 册:2006-5-13
得分:0 
不错的资源啊,做记号备用。

活到老,学到老! http://www. E-mail:hu-jj@
2016-07-14 07:37
Valenciax
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
等 级:版主
威 望:11
帖 子:337
专家分:2462
注 册:2016-5-15
得分:0 
约略看了看,写得不错,有几点可以讨论一下。

1.masm6.x以后仿效高阶语言,支持子程序设定暂时变量。暂时变量只存活在该个子程序,子程序结束后,暂时变量也不存在,更重要的是暂时变量不能被其他程序存取,收到保护数据的效果。回到班竹的子程序BitMap,当中大量使用暂时变量,由[bp-2]到[bp-20],尽管已有说明,但大量的[bp-xx]看得愣一愣,改用local的变量宣告,代码容易明白许多。

先做local暂时变数的宣告

程序代码:
Bitmap proc near
local BmpWidth,BmpOnScreenWidth,BytePerRow,LeftCutWidth,BmpHeight:word
local BmpOnScreenHeight,BytePerPixel,PaletteOffset,ImgDataOffset,RowOffset:word


然后代码中就可以直接使用,比如
程序代码:
 mov BmpWidth,ax
 mov BmpOnScreenWidth,ax   
 mov BytePerRow,ax     


2.代码可以再精简些,比如这一段
程序代码:
     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                                    
     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                                    

做法是读取档案前4个bytes,关档,再开档。
根据之前读取的第2,3bytes(记录档案长度)读取整个档案,关档。

精简的做法是,读取前4bytes,根据第2,3bytes(记录档案长度)读取剩余的资料,关档。
程序代码:
  mov dx,offset ImageBuffer                                                   
  mov cx,4                                                                    
  mov ah,3fh                                                                  
  int 21h           ;Read the first 4 byte to memory                          
  mov cx,word ptr ImageBuffer[2] ;Save the Bitmap file entire size to CX Register      mov dx,offset ImageBuffer + 4
  mov ah,3fh                                                                  
  int 21h           ;Read the entire Bitmap file to memory                    
  mov ah,3eh                                                                  
  mov bx,handle                                                               
  int 21h           ;Close the Bitmap file                                    


编译须用masm6.x , ml xxx.asm

下面是修改后的代码:
程序代码:
.286
;**************************************************************************************
;
;        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@
;                         oicq :19820914
;**************************************************************************************
Stack    Segment
         Stk          db   100    dup(?)
Stack    Ends
Data     Segment
         ImageBuffer  db    65078    dup(?)
         ImageSrc     db    '6.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 ES,AX
     mov dx,offset ImageSrc
     push 20
     push 24
     push dx
     call Bitmap
     mov ah,0
     int 16h
     MOV AX,0003H
     INT 10H
     mov ax,4c01h
     int 21h
;----------------------------------------
Bitmap proc near
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                          ;
;               ===================                                        ;
;             * Local Variable list *                                      ;
;               ===================                                        ;
;                                                                          ;
;        (1)  BmpWidth           (:Word)                                   ;
;        (2)  BmpOnScreenWidth   (:Word)                                   ;
;        (3)  BytePerRow         (:Word)                                   ;
;        (4)  LeftCutWidth       (:Word)                                   ;
;        (5)  BmpHeight          (:Word)                                   ;
;        (6)  BmpOnScreenHeight  (:Word)                                   ;
;        (7)  BytePerPixel       (:Word)                                   ;
;        (8)  PaletteOffset      (:Word)                                   ;
;        (9)  ImgDataOffset      (:Word)                                   ;
;        (10) RowOffset          (:Word)                                   ;
;                                                                          ;
;                                                                          ;
;===========================================================================
fileOffset textequ <[BP+4]> ;若改用invoke,可代替这3句
Xcoordinate textequ <[BP+6]> 
Ycoordinate textequ <[BP+8]> 

local BmpWidth,BmpOnScreenWidth,BytePerRow,LeftCutWidth,BmpHeight:word
local BmpOnScreenHeight,BytePerPixel,PaletteOffset,ImgDataOffset,RowOffset:word

     pusha
     push di
     push es
     mov dx,fileOffset
     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 ah,3fh                                                                  ;;
     int 21h           ;Read the first 4 byte to memory                          ;;
                                                                                     ;;
;====================================================================================;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                          ;     
;        Read The entire Bitmap file to memory                             ;;;;;;;;;;;;
;                                                                          ;         ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;         ;;

     mov cx,word ptr ImageBuffer[2] ;Save the Bitmap file entire size to CX Register        
     mov dx,offset ImageBuffer + 4
     mov ah,3fh                                                                  ;;
     int 21h           ;Read the entire Bitmap file to memory                    ;;
     mov ah,3eh                                                                  ;;
     mov bx,handle                                                               ;;
     int 21h           ;Close the Bitmap file                                    ;;
                                                                                     ;;
;====================================================================================;;

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                          ;
;        Save Information to local variable                                ;;;;;;;;;;;;
;                                                                          ;         ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;         ;;
                                                                                     ;;
     mov ax,word ptr ImageBuffer[12h]
     mov BmpWidth,ax     ;Save BmpWidth                                          ;;
     mov BmpOnScreenWidth,ax     ;Save BmpOnScreenWidth                          ;;
     mov BytePerRow,ax     ;Save BytePerRow                                      ;;
     mov cl,4                                                                    ;;
     div cl                                                                      ;;
     cmp ah,0                                                                    ;;
     jz  NoDwAA        ;No Dword align adjust                                    ;;
     mov cl,4                                                                    ;;
     sub cl,ah                                                                   ;;
     add byte ptr BytePerRow,cl                                                  ;;
NoDwAA:                                                                              ;;
     mov cx,0                                                                    ;;
     mov LeftCutWidth,cx    ;Save LeftCutWidth = 0                               ;;
     mov ax,word ptr ImageBuffer[16h]
     mov BmpHeight,ax    ;Save BmpHeight                                         ;;
     mov BmpOnScreenHeight,ax    ;Save BmpOnScreenHeight                         ;;
     mov ax,word ptr ImageBuffer[1ch]
     mov BytePerPixel,ax    ;Save BitPerPixel                                    ;;
     mov ax,word ptr ImageBuffer[0eh]
     add ax,14                                                                   ;;
     mov PaletteOffset,ax    ;Save PaletteOffset                                 ;;
     mov ax,word ptr ImageBuffer[0ah]
     mov ImgDataOffset,ax    ;Save ImgDataOffset                                 ;;
     ;mov RowOffset,0     ;Save RowOffset                                        ;;
                                                                                     ;;
;====================================================================================;;

;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
;                                                                                    
;        Seve the value to Local variable
;
;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

     jmp CoorDinateX
exitzz:
     jmp exit
CoordinateX:         
     mov ax,Xcoordinate     ;X coordinate
     push ax
     and ah,80
     pop ax
     jz  PositiveX     ;If X coordinate>=0,jump
     mov ax,Xcoordinate
     push ax
     not ax
     inc ax
     mov LeftCutWidth,ax     ;Save LeftCutWidth
     pop ax
     add ax,BmpWidth     ;X coordinate add BmpWidth
     jnc exitzz        ;Exit if X coordinate add BmpWidth < 0
     jz exitzz         ;Exit if X coordinate add BmpWidth = 0
     push ax
     mov cx,320
     sub cx,ax
     mov RowOffset,cx    ;Save RowOffset
     add ax,LeftCutWidth     
     mov BmpOnScreenWidth,ax     ;Save BmpOnScreenWidth + LeftCut
     pop ax
     mov cx,320
     cmp cx,ax
     jnc NoWOverf      ;No Width Overflow
     mov ax,LeftCutWidth
     add ax,320
     mov BmpOnScreenWidth,ax     ;Save BmpOnScreenWidth = 320 + LeftCutWidth
     mov ax,0
     mov RowOffset,ax
NoWOverf: 
     mov ax,0
     mov Xcoordinate,ax
     jmp CoordinateY
PositiveX:
     cmp ax,320
     jnc exitzz
     mov cx,320
     sub cx,BmpWidth
     mov RowOffset,cx
     add ax,BmpWidth
     mov cx,320
     cmp cx,ax
     jnc CoordinateY
     mov ax,320
     sub ax,Xcoordinate
     mov BmpOnScreenWidth,ax     ;Save OnScreenWidth
     mov cx,320
     sub cx,ax
     mov RowOffset,cx    ;SaveRowOffset
CoordinateY:
     mov ax,Ycoordinate     ;Y coordinate
     push ax
     and ah,80
     pop ax
     jz PositiveY
     add ax,BmpHeight
     jnc exitzz1
     jz exitzz1
     mov BmpHeight,ax    ;Save BmpHeight
     mov BmpOnScreenHeight,ax    ;Save OnScreenHeight
     mov cx,0
     mov Ycoordinate,cx
     mov cx,200
     cmp cx,ax
     jnc SetInt10      ;No Height Overflow
     mov cx,200
     mov BmpOnScreenHeight,cx
NoHOverf:        
     jmp SetInt10
exitzz1:
     jmp exit
PositiveY:
     cmp ax,200
     jnc exitzz1
     add ax,BmpHeight
     mov cx,200
     cmp cx,ax
     jnc SetInt10
     mov ax,200
     sub ax,Ycoordinate
     mov BmpOnScreenHeight,ax

;<><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>

;**************************************************************************************
;                                                                                    
;        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,PaletteOffset
     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,Ycoordinate
     mov cx,320
     mul cx
     add ax,Xcoordinate
     mov di,ax
vertical:
     cmp word ptr BmpOnScreenHeight,0
     jz exit
     dec word ptr BmpHeight
     dec word ptr BmpOnScreenHeight
     mov ax,BmpHeight
     mul word ptr BytePerRow
     mov bx,ax
     add bx,ImgDataOffset
     mov si,0
     add si,LeftCutWidth
horizon:
     cmp si,word ptr BmpOnScreenWidth
     jz horizonend
     mov al,[bx][si]
     mov es:[di],al
     inc si
     inc di
     jmp horizon
horizonend:
     add di,RowOffset
     jmp Vertical
    
;**************************************************************************************
exit:
     pop es
     pop di
     popa
     ret
Bitmap   endp
Code     Ends
         End Start 





[此贴子已经被作者于2016-7-16 23:40编辑过]

2016-07-16 20:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-466890-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.164948 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved