Advertisement
Guest User

Untitled

a guest
Jun 3rd, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. proc OpenFile1
  2. ; Open file
  3.     mov ah, 3Dh
  4.     xor al, al
  5.     mov dx, offset filename1
  6.     int 21h
  7.     jc openerror1
  8.     mov [filehandle], ax
  9.     ret
  10. openerror1:
  11.     mov dx, offset ErrorMsg
  12.     mov ah, 9h
  13.     int 21h
  14.     ret
  15. endp OpenFile1
  16.  
  17. proc ReadHeader
  18. ; Read BMP file header, 54 bytes
  19.     mov ah,3fh
  20.     mov bx, [filehandle]
  21.     mov cx,54
  22.     mov dx,offset Header
  23.     int 21h
  24.     ret
  25. endp ReadHeader
  26.  
  27. proc ReadPalette
  28.     ; Read BMP file color palette, 256 colors * 4 bytes (400h)
  29.     mov ah,3fh
  30.     mov cx,400h
  31.     mov dx,offset Palette
  32.     int 21h
  33.     ret
  34. endp ReadPalette
  35.  
  36. proc CopyPal
  37.         ; Copy the colors palette to the video memory
  38.         ; The number of the first color should be sent to port 3C8h
  39.         ; The palette is sent to port 3C9h
  40.         mov si,offset Palette
  41.         mov cx,256
  42.         mov dx,3C8h
  43.         mov al,0
  44.         ; Copy starting color to port 3C8h
  45.         out dx,al
  46.         ; Copy palette itself to port 3C9h
  47.         inc dx
  48.     PalLoop:
  49.         ; Note: Colors in a BMP file are saved as BGR values rather than RGB.
  50.         mov al,[si+2] ; Get red value.
  51.         shr al,2 ; Max. is 255, but video palette maximal
  52.         ; value is 63. Therefore dividing by 4.
  53.         out dx,al ; Send it.
  54.         mov al,[si+1] ; Get green value.
  55.         shr al,2
  56.         out dx,al ; Send it.
  57.         mov al,[si] ; Get blue value.
  58.         shr al,2
  59.         out dx,al ; Send it.
  60.         add si,4 ; Point to next color.
  61.         ; (There is a null chr. after every color.)
  62.     loop PalLoop
  63.         ret
  64. endp CopyPal
  65.  
  66. proc CopyBitmap
  67.         ; BMP graphics are saved upside-down.
  68.         ; Read the graphic line by line (200 lines in VGA format),
  69.         ; displaying the lines from bottom to top.
  70.         mov ax, 0A000h
  71.         mov es, ax
  72.         mov cx,200
  73.     PrintBMPLoop:
  74.         push cx
  75.         ; di = cx*320, point to the correct screen line
  76.         mov di,cx
  77.         shl cx,6
  78.         shl di,8
  79.         add di,cx
  80.         ; Read one line
  81.         mov ah,3fh
  82.         mov cx,320
  83.         mov dx,offset ScrLine
  84.         int 21h
  85.         ; Copy one line into video memory
  86.         cld ; Clear direction flag, for movsb
  87.         mov cx,320
  88.         mov si,offset ScrLine
  89.         rep movsb ; Copy line to the screen
  90.          ;rep movsb is same as the following code:
  91.          ;mov es:di, ds:si
  92.          ;inc si
  93.          ;inc di
  94.          ;dec cx
  95.          ;loop until cx=0
  96.         pop cx
  97.     loop PrintBMPLoop
  98.         ret
  99. endp CopyBitmap
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement