DECLARE FUNCTION SAVEBMP% (bmpfilename$) DECLARE FUNCTION loadbmp% (bmpfilename$) TYPE BMPFileHeader FileType AS STRING * 2 Size AS LONG Reserved1 AS INTEGER Reserved2 AS INTEGER OffBits AS LONG END TYPE TYPE BMPInfoHeader Size AS LONG Imagewidth AS LONG Imageheight AS LONG Planes AS INTEGER bitcount AS INTEGER Compression AS LONG SizeImage AS LONG XPelsPerMeter AS LONG YPelsPerMeter AS LONG ClrUsed AS LONG ClrImportant AS LONG END TYPE ' SCREEN 12 'draw something RANDOMIZE TIMER FOR i% = 0 TO 15 READ c& PALETTE i%, c& NEXT DATA &h5,&h10,&h20,&h30 DATA &h500,&h1000,&h2000,&h3000 DATA &h50000,&h100000,&h200000,&h300000 DATA &h50505,&h101010,&h202020,&h303030 FOR k% = 1 TO 20 x% = RND * 640 + 1 y% = RND * 480 r% = RND * 80 + (80 \ 8) clr% = INT(RND * 4) * 3 a = RND * 3.141592 b = RND * 3.141592 / 1.5 x1% = CINT(COS(a) * SIN(b) * 100) y1% = CINT(SIN(a) * SIN(b) * 100) z1% = CINT(COS(b) * 100) FOR i% = -r% TO r% i1% = i% * 100 / CSNG(r%) FOR j% = -SQR(r% * r% - i% * i%) TO SQR(r% * r% - i% * i%) j1% = j% * 100 / CSNG(r%) k1% = SQR(11000 - i1% * i1% - j1% * j1%) c! = 3 * (x1% * i1% + j1% * y1% + k1% * z1%) / 10000 ccc% = 1 + clr% + INT(c!) + (RND > (c! - INT(c!))) PSET (x% + i%, y% + j%), ccc% NEXT j%, i% NEXT PRINT "Saving.." t! = TIMER dummy = SAVEBMP("balls.bmp") PRINT dummy, TIMER - t! SLEEP 5 CLS PRINT "Loading..." dummy = loadbmp("balls.bmp") PRINT dummy SLEEP ' '------------------------------------------------------------------ FUNCTION loadbmp% (bmpfilename$) 'returns 0 for success, 1 for file does not exist, 2 for file is not a saved Screen 12 DIM fh AS BMPFileHeader DIM ih AS BMPInfoHeader f = FREEFILE OPEN bmpfilename$ FOR BINARY AS f IF LOF(f) = 0 THEN CLOSE #1: KILL bmpfilename$: loadbmp% = 1: EXIT FUNCTION GET #f, , fh GET #f, , ih IF (ih.Imagewidth <> 640) OR (ih.Imageheight <> 480) OR (ih.bitcount) <> 4 THEN loadbmp% = 2: CLOSE f: EXIT FUNCTION END IF Buffer$ = SPACE$(64) GET #f, , Buffer$ DEF SEG = VARSEG(Buffer$) offs& = SADD(Buffer$) OUT &H3C8, 0 FOR i% = 0 TO 15 OUT &H3C9, PEEK(offs& + 2) \ 4 OUT &H3C9, PEEK(offs& + 1) \ 4 OUT &H3C9, PEEK(offs&) \ 4 offs& = offs& + 4 NEXT 'Get image Buffer$ = SPACE$(320 * 48) DEF SEG = VARSEG(Buffer$) FOR k% = 9 TO 0 STEP -1 GET #f, , Buffer$ offs& = SADD(Buffer$) FOR i% = 48 * (k% + 1) - 1 TO 48 * k% STEP -1 FOR j% = 0 TO 639 STEP 2 PSET (j%, i%), PEEK(offs&) \ 16 PSET (j% + 1, i%), PEEK(offs&) AND 15 offs& = offs& + 1 NEXT j%, i% NEXT k% CLOSE f END FUNCTION ' '------------------------------------------------------------------ FUNCTION SAVEBMP% (bmpfilename$) 'returns 0 for success, 1 for file already exists DIM FileHeader AS BMPFileHeader DIM InfoHeader AS BMPInfoHeader ' BITMAPFILEHEADER FileHeader.FileType = "BM"'BMP format marker FileHeader.Size = 640& * 480 \ 2 + 118 FileHeader.OffBits = 118 InfoHeader.Size = 40 InfoHeader.Imagewidth = 640 InfoHeader.Imageheight = 480 InfoHeader.Planes = 1 InfoHeader.bitcount = 4 InfoHeader.SizeImage = 640& * 480 \ 2' Image size in bytes InfoHeader.ClrUsed = 16' Colors used in picture f = FREEFILE OPEN bmpfilename$ FOR BINARY AS f IF LOF(f) <> 0 THEN CLOSE f: KILL bmpfilename$: SAVEBMP = 1: EXIT FUNCTION PUT #f, , FileHeader PUT #f, , InfoHeader 'Save palette data Buffer$ = SPACE$(64) OUT &H3C7, 0 FOR i% = 0 TO 15 Red% = INP(&H3C9) Green% = INP(&H3C9) blue% = INP(&H3C9) MID$(Buffer$, 4 * i% + 1) = CHR$(blue% * 4) + CHR$(Green% * 4) + CHR$(Red% * 4) + CHR$(0) NEXT i% PUT #f, , Buffer$ 'Save image data-use poke for speed Buffer$ = SPACE$(320 * 48) DEF SEG = VARSEG(Buffer$) FOR k% = 9 TO 0 STEP -1 offs& = SADD(Buffer$) FOR i% = 48 * (k% + 1) - 1 TO 48 * k% STEP -1 FOR j% = 0 TO 639 STEP 2 POKE offs&, 16 * POINT(j%, i%) + POINT(j% + 1, i%) offs& = offs& + 1 NEXT j%, i% PUT #f, , Buffer$ NEXT k% CLOSE f END FUNCTION