-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmpfile.asm
130 lines (120 loc) · 2.61 KB
/
bmpfile.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
proc OpenFile
;CurrentFile: file name of bmpfile to draw
;Opens file, puts handle in filehandle
mov ah, 3Dh
xor al, al
mov dx, [CurrentFile]
int 21h
jc openerror
mov [filehandle], ax
ret
openerror:
mov ax, 0003H; Return to Text mode
int 10H
mov dx, offset ErrorMsg
mov ah, 9h
int 21h
mov ax, 4c00h ; exit the program
int 21h
endp OpenFile
proc ReadHeader
; Read BMP file header, 54 bytes
; Put BMP file Header in Header variable
mov ah,3fh
mov bx, [filehandle]
mov cx , 54
mov dx,offset Header
int 21h
ret
endp ReadHeader
proc ReadPalette
; Read BMP file color palette, 256 ; colors * 4 bytes (400h)
; Puts BMP file Pallete in Pallete variable
mov ah,3fh
mov bx, [filehandle]
mov cx , 400h
mov dx,offset Palette
int 21h
ret
endp ReadPalette
proc CopyPal
; Copy the colors palette to the video memory registers
; The number of the first color should be sent to port 3C8h
; The palette is sent to port 3C9h
mov si,offset Palette
mov cx,256
mov dx,3C8h
xor al,al
; Copy starting color to port 3C8h
out dx,al
; Copy palette itself to port 3C9h
inc dx
PalLoop:
; Note: Colors in a BMP file are saved as BGR values rather than RGB.
mov al,[si+2] ; Get red value.
shr al,2 ; Max. is 255, but video palette maximal
; value is 63. Therefore dividing by 4.
out dx,al ; Send it.
mov al,[si+1] ; Get green value.
shr al,2
out dx,al ; Send it.
mov al,[si] ; Get blue value.
shr al,2
out dx,al ; Send it.
add si,4 ; Point to next color.
; (There is a null chr. after every color.)
loop PalLoop
ret
endp CopyPal
proc CopyBitmap
; BMP graphics are saved upside-down.
; Read the graphic line by line (200 lines in VGA format),
; displaying the lines from bottom to top.
mov ax, 0A000h
mov es, ax
mov bx, [filehandle]
mov cx,200
PrintBMPLoop:
push cx
; di = cx*320, point to the correct screen line
mov di,cx
shl cx,6
shl di,8
add di,cx
; ----------------------------------------------------------
; add di,100
; add di,20*320
; ----------------------------------------------------------
; Read one line
mov ah,3fh
mov cx,320
mov dx,offset ScrLine
int 21h
; Copy one line into video memory
cld ; Clear direction flag, for movsb
mov cx,320
mov si,offset ScrLine
rep movsb ; Copy line to the screen
pop cx
loop PrintBMPLoop
ret
endp CopyBitmap
proc CloseFile
; filehandle - filehandle of bmp file
; closes the bmp file
mov ah,3Eh
mov bx, [filehandle]
int 21h
ret
endp CloseFile
;Shows bmp file saved in CurrentFile
proc ShowBmp
; Process BMP file
call OpenFile
call ReadHeader
call ReadPalette
call CopyPal
call CopyBitmap
call CloseFile
ret
endp ShowBmp