Guest User

Untitled

a guest
Jun 23rd, 2018
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. IDEAL
  2. MODEL small
  3. STACK 1000h
  4. DATASEG
  5.  
  6. ; --------------------------
  7. ; Your variables here
  8.  
  9. ;black dw 0
  10. color1 db 12
  11. ;1-blue ,2-green ,3-azure ,4-red ,5-pink ,6-orange ,7-white ,8-gray ,9-purple
  12. filename db 'test.bmp',0
  13. filehandle dw ?
  14. Header db 54 dup (0)
  15. Palette db 256*4 dup (0)
  16. ScrLine db 320 dup (0)
  17. ErrorMsg db 'Error', 13, 10,'$'
  18.  
  19. ; --------------------------
  20. CODESEG
  21. proc OpenFile
  22. ; Open file
  23. mov ah, 3Dh
  24. xor al, al
  25. mov dx, offset filename
  26. int 21h
  27. jc openerror
  28. mov [filehandle], ax
  29.  
  30. ret
  31. openerror:
  32. mov dx, offset ErrorMsg
  33. mov ah, 9h
  34. int 21h
  35. ret
  36. endp OpenFile
  37.  
  38. proc ReadHeader
  39. ; Read BMP file header, 54 bytes
  40. mov ah,3fh
  41. mov bx, [filehandle]
  42. mov cx,54
  43. mov dx,offset Header
  44. int 21h
  45. ret
  46. endp ReadHeader
  47.  
  48. proc ReadPalette
  49. ; Read BMP file color palette, 256 colors * 4 bytes (400h)
  50. mov ah,3fh
  51. mov cx,400h
  52. mov dx,offset Palette
  53. int 21h
  54. ret
  55. endp ReadPalette
  56.  
  57. proc CopyPal
  58. ; Copy the colors palette to the video memory registers
  59. ; The number of the first color should be sent to port 3C8h
  60. ; The palette is sent to port 3C9h
  61. mov si,offset Palette
  62. mov cx,256
  63. mov dx,3C8h
  64. mov al,0
  65. ; Copy starting color to port 3C8h
  66. out dx,al
  67. ; Copy palette itself to port 3C9h
  68. inc dx
  69. PalLoop:
  70. ; Note: Colors in a BMP file are saved as BGR values rather than RGB.
  71. mov al,[si+2] ; Get red value.
  72. shr al,2 ; Max. is 255, but video palette maximal
  73. ; value is 63. Therefore dividing by 4.
  74. out dx,al ; Send it.
  75. mov al,[si+1] ; Get green value.
  76. shr al,2
  77. out dx,al ; Send it.
  78. mov al,[si] ; Get blue value.
  79. shr al,2
  80. out dx,al ; Send it.
  81. add si,4 ; Point to next color.
  82. ; (There is a null chr. after every color.)
  83.  
  84. loop PalLoop
  85. ret
  86. endp CopyPal
  87.  
  88. proc CopyBitmap
  89. ; BMP graphics are saved upside-down.
  90. ; Read the graphic line by line (200 lines in VGA format),
  91. ; displaying the lines from bottom to top.
  92. mov ax, 0A000h
  93. mov es, ax
  94. mov cx,200
  95. PrintBMPLoop:
  96. push cx
  97. ; di = cx*320, point to the correct screen line
  98. mov di,cx
  99. shl cx,6
  100. shl di,8
  101. add di,cx
  102. ; Read one line
  103. mov ah,3fh
  104. mov cx,320
  105. mov dx,offset ScrLine
  106. int 21h
  107. ; Copy one line into video memory
  108. cld ; Clear direction flag, for movsb
  109. mov cx,320
  110. mov si,offset ScrLine
  111.  
  112. rep movsb ; Copy line to the screen
  113. ;rep movsb is same as the following code:
  114. ;mov es:di, ds:si
  115. ;inc si
  116. ;inc di
  117. ;dec cx
  118. ;loop until cx=0
  119. pop cx
  120. loop PrintBMPLoop
  121. ret
  122. endp CopyBitmap
  123.  
  124. ;----------------------------------------
  125. start:
  126. mov ax, @data
  127. mov ds, ax
  128. ; --------------------------
  129. ; Your code here
  130. ; -----------------------
  131. ; Graphic mode
  132. mov ax, 13h
  133. int 10h
  134. ; Process BMP file
  135. call OpenFile
  136. call ReadHeader
  137. call ReadPalette
  138. call CopyPal
  139. call CopyBitmap
  140.  
  141. ;Show mouse
  142. mov ax,1h
  143. int 33h
  144. ;mov ax, 0003h
  145. ;int 33h
  146. ; Loop until mouse click
  147. MouseLP:
  148. mov ax,3h
  149. int 33h
  150. cmp bx, 01h ; check left mouse click
  151. mov ax, 0003h
  152. int 33h
  153. jne MouseLP
  154.  
  155. ; Press any key to continue
  156. mov ah,00h
  157. int 16h
  158. ; Text mode
  159. mov ax,3h
  160. int 10h
  161. ; return to text mode
  162. ;mov ah, 0
  163. ;mov al, 2
  164. ;int 10h
  165.  
  166.  
  167. exit:
  168.  
  169. mov ax, 4c00h
  170. int 21h
  171. END start
Add Comment
Please, Sign In to add comment