unit EGA; interface const planMaxSize = 60000; var screenH, screenV : word; type Plan = array [0..planMaxSize-1] of byte; Image16 = object h, v : word; bitmap : array [0..3] of ^Plan; procedure disp (x, y : integer); procedure link (p : pointer); procedure load (fileName : string); end; procedure rowsCopy (var source, target : array of byte; srcStep, tarStep, rowSize, rowNumber : word); procedure waitScan; implementation procedure rowsCopy (var source, target : array of byte; srcStep, tarStep, rowSize, rowNumber : word); var s, t : word; begin s := 0; t := 0; while (rowNumber > 0) do begin move (source[s], target[t], rowSize); inc (s, srcStep); inc (t, tarStep); dec (rowNumber); end; end; procedure Image16.disp (x, y : integer); var x2, y2, h2, v2, source, target, srcStep, tarStep, i : word; begin if (x >= screenH) or (y >= screenV) or (x + h < 1) or (y + v < 1) then exit; h2 := screenH - x; if h2 > h then h2 := h; v2 := screenV - y; if v2 > v then v2 := v; x2 := 0; if x < 0 then begin x := -((abs(x + 1) shr 3 + 1) shl 3); dec (x2, x); inc (h2, x); x := 0; end; y2 := 0; if y < 0 then begin dec (y2, y); inc (v2, y); y := 0; end; h2 := h2 shr 3; srcStep := h shr 3; source := x2 shr 3 + y2 * srcStep; tarStep := screenH shr 3; target := x shr 3 + y * tarStep; for i := 0 to 3 do begin port [$3C5] := 1 shl i; rowsCopy (bitmap[i]^[source], mem[40960:target], srcStep, tarStep, h2, v2); end; end; procedure Image16.link (p : pointer); var s, o : word; size : longint; i : byte; begin s := seg (p^); o := ofs (p^); h := memw [s : o]; v := memw [s : o + 2]; size := h shr 3 * v; if size > planMaxSize then halt; for i := 0 to 3 do begin bitmap [i] := ptr ((size * i + 4) div 16 + s, (size * i + 4) mod 16 + o); end; end; procedure Image16.load (fileName : string); var f : file; size, i : word; begin assign (f, fileName); reset (f, 1); blockread (f, h, 2); blockread (f, v, 2); size := h shr 3 * v; if size > planMaxSize then halt; for i := 0 to 3 do begin getMem (bitmap[i], size); blockread (f, bitmap[i]^, size); end; close(f); writeln(fileName + ' ', h, ' x ', v, ' Loaded. '); end; { wait for end vertical scan screen } procedure waitScan;begin asm mov dx, 03DAh @@1 : in al, dx test al, 8 jne @@1 @@2 : in al, dx test al, 8 je @@2 end; end; begin screenH := 640; screenV := 350; end.