;-----------------------------
;文件满足256色调的
;-----------------------------
Stack    Segment
         Stk          db    65535    dup(?)
Stack    Ends
Data     Segment
         ImageBuffer  db    65078    dup(?)
         ImageSrc     db    'bitmap.bmp',0                 ;修改同目录下图片的文件名
         Eflag        db    ?
         OpenErrorMsg db    'file not found',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,0                ;修改读取开始的Y坐标
     mov si,0        ;修改读取开始的X坐标
         mov dx,offset ImageSrc
         push si
         push di
         push dx
         call Bitmap
         mov ax,0
         int 16h
         mov ax,4c01h
         int 21h
          
BitMap   Proc

;===========================================================================

         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],

相关文章:

  • 2022-12-23
  • 2021-10-17
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-08-22
  • 2022-12-23
  • 2021-12-15
猜你喜欢
  • 2022-02-07
  • 2022-12-23
  • 2021-05-02
  • 2021-09-20
  • 2021-05-20
  • 2022-01-06
  • 2022-12-23
相关资源
相似解决方案