' ================================================================= ' Program Name : BMPREAD2.BAS ' Programmer : B. Kahl ' Date : February 28, 1996 ' Description : This program will load a Windows 3 bitmap graphics ' file and display it. generally written for 16color 480x640 screen ' 12 modes. This is a primative version with slow disk read. (reading ' each pixel line 320 bytes per disk access) Future versions will ' load larger amounts of pixel data during a single disk access. ' ' Written w/PowerBASIC assisted by Dave Navarro, Jr., Gary J. Sibio, ' and John Pearson ' ================================================================= $string 8 'size of str segments 8k; max strng=8,174bytes bufsiz%=8174 cls f1% = freefile filename$ = "C:\WINDOWS\BOXES.BMP" ' filename$ = "C:\WINDOWS\CHESS.BMP" Open filename$ for binary as f1% FiLen& = lof(f1%) Map BMPFileHdr$$ * 14,_ 'Standrd BMP File Header Record=14Bytes 2 as FType$$,_ 'File Type BM or 0xD42 4 as FSize$$,_ 'File Size 2 as Resrv1$$,_ 'Not Used 2 as Resrv2$$,_ 'Not Used 4 as OffSet$$ 'Offset to Beginning of Data seek #f1%,0 'start of BMP get$ #f1%,14,BMPFileHdr$$ 'Read stndrd MBP File Header 14 bytes if FType$$ <> "BM" then print Ftype$$;"File Not BMP Format Cannot Display":end FSize&=cvl(FSize$$) OffSet& = cvl(OffSet$$) '3E = Mono, 76=16 Clr, 436=256 Clr, 36=16.7mil ' 62dec , 118dec , 1078 , 54dec Map BMPInfoHdr$$ * 40,_ 'Standrd BMP Info Header Record=40Bytes 4 as Size$$,_ 'Len of the header in bytes 4 as Wid$$,_ 'Width of the image in Pixels 4 as Height$$,_ 'height of the image in Pixels 2 as Planes$$,_ 'Num of Planes (min =1) 2 as BitCnt$$,_ 'Bits per Pixel 1,4,8,24 4 as Comprsn$$,_ 'comprsn Scheme 0=none,RGB,RLE8,RLE4 4 as SizeImage$$,_ 'size (bytes) of the bits in image 4 as XpelsPerMeter$$,_ 'horz Res in Pixels per Meter 4 as YpelsPerMeter$$,_ 'Ver Res in Pixels per Meter 4 as ClrUsed$$,_ 'Num of Colrs Used 0=max 4 as ClrImprtnt$$ 'Num of Colr Indexes considrd imptnt 0=all get$ #f1%,40,BMPInfoHdr$$ 'Read stndrd MBP Info Header 40 bytes size& =cvl(size$$) wid% =cvl(wid$$) height%=cvl(height$$) Planes%=cvi(Planes$$) BitCnt%=cvi(BitCnt$$) print "File Name$ = ";FileName$ print "FileSize =";FSize& print "Offset to Data =";OffSet& print "Header Size =";size& print "Image Width =";wid% print "Image Height =";height% print "Planes =";Planes% print "Bits Per Pixel =";BitCnt% Print "Press any Key to Continue" input a$ Map RGB$$*4,_ 'Color Values 1 as Blue$$,_ '0-255 1 as Green$$,_ '0-255 1 as red$$,_ '0-255 1 as rsrvd$$ screen 12 'VGA screen mode 12 16 colors 640x480 'this line has to be prior to setting palette cls for i%=0 to 15 'Read & Set 16 palette colors, 1 RGB set/loop get$ #f1%,4,RGB$$ 'Read RGB Values start at 54 bytes from start 0-255 Blue?= cvbyt(Blue$$)\4 '1 byte containing Blue Value from file convert to 0-63 Green?=cvbyt(Green$$)\4 'ditto Green Red? =cvbyt(red$$)\4 'ditto red reg 1, &h1010 'AX set individual DAC register 5-21 PC Interrupts reg 2, i% 'BX Register Number reg 3, Green?*256+Blue? 'CH=Green, CL=Blue 0-63 reg 4, Red?*256 'DH=Red 0-63 call interrupt &h10 next i% seek #f1%,offset& 'offset pnt read from BMP File header if bufSiz% > FSize& then BufSiz%=FSize& get$ f1%,BufSiz%,buf$ 'Get First Buffer of Pixel Data from file BP%=1 'Buffer Position BR&=BufSiz% 'Bytes Read from file for y% = height%-1 to 0 step -1 'bottom screen line first in file for x%=0 TO wid%-1 step 4 'build array from string pix??= cvwrd(mid$(buf$,BP%,2)) 'convert 2bytes string to array val ms? = pix??\256 'most significant 8 bits ls? = pix?? mod 256 'least significant 8 bits '------------first method: Assembler display 4 pixels ----------------------- ! push ax ! push bx ! push cx ! push dx ! mov al,ls? ;pixel data ! mov cl,4 ! shr ax,cl ;divide by 16 ! mov ah, &h0C ;subfunction 0C ! mov bx,&h00 ;page number ! mov cx,x% ;horizontal position column# ! mov dx,y% ;vertical position row# ! int &h10 ;write single graphics pixel ! mov al,ls? ;second pixel data ! and al,&h0F ;get rid of high 4 bits ! inc cx ;increment horizontal position ! int &h10 ! mov al,ms? ;third pixel data ! mov cl,4 ! shr ax,cl ;divide by 16 ! mov ah, &h0C ;subfunction 0C ! mov cx,x% ;horizontal position column# ! add cx,2 ;add 2 to horizontal postn ! mov dx,y% ;vertical position row# ! int &h10 ;write single graphics pixel ! mov al,ms? ;Fourth pixel data ! and al,&h0F ;get rid of high 4 bits ! inc cx ;increment horizontal position ! int &h10 ! pop dx ! pop cx ! pop bx ! pop ax '------------Second method: Power Basic Registers and Interrupt call -------- 'reg 1, &h0C00 + ls?\16 'write graphics pixel 'reg 2, &h00 'page number 'reg 3, x% 'x column position 0-639 'reg 4, y% 'y row position 0-279 'call interrupt &h10 'write single graphics pixel 'reg 1, &h0C00 + ls? mod 16 'reg 2, &h00 'reg 3, x%+1 'reg 4, y% 'call interrupt &h10 'reg 1, &h0C00 + ms?\16 'reg 2, &h00 'reg 3, x%+2 'reg 4, y% 'call interrupt &h10 'reg 1, &h0C00 + ms? mod 16 'reg 2, &h00 'reg 3, x%+3 'reg 4, y% 'call interrupt &h10 '------------Third method: Power Basic PSET Statement ----------------------- ' pset (x% ,y%),ls?\16 ' pset (x%+1,y%),ls? mod 16 'least signif ' pset (x%+2,y%),ms?\16 'most significant 4 bits ' pset (x%+3,y%),ms? mod 16 incr BP%,2 if BP%=>BufSiz% then 'buffer data depleated if offset&+BR&+BufSiz%>lof(f1%) then BufSiz%=lof(f1%)-offset&-BR& 'only read to end of file end if Get$ f1%,BufSiz%,buf$ 'read next buffer of pixel data BP%=1 'reset Buf Postn incr BR&,BufSiz% 'increase bytes read end if if instat then exit,exit 'exit loop when any key pressed next x% sound 50,.001 next y% close #f1% end