Download Parallel Processing
Transcript
By Thomas L. Dehs Structured Scientific Software 1509 Queen Ave. SW Albany, OR 97321 Data abstraction and dynamic memory allocation are two areas where Modula-2 and Ada shine. easily, and move them about the screen. No use wasting memory after we've thrown away a block, so we'll allocate and deallocate memory dynamically. (Since we want our program to be portable, we won't be able to move blocks from display memory, since the locations may be hardware dependent.) We have a DEFINITION MODULE of procedures, so we can start building the low-level tools we need to implement this set of procedures. The first of these tools is a data structure for storing a screen block. This structure must know where the block came from, its size, where its characters lie, and their attributes. In The Low Levels The most primitive unit in this data structure is the character and its attribute - a pair of bytes. The Modula 2 module called SYSTEM has a data type BYTE with which we'll set up a two-byte (character and attribute) data structure. TYPE CA = ARRAY[O .. l] OF ~YTE; (continued next page) Figure 3 - ScreenBlocks Implementation Module IMPLEMENTATION MODULE ScreenBlocks; (* This module is system specific. This version is written for the IBM-PC and clones using MS-DOS. *) FROM Storage IMPORT ALLOCATE,DEALLOCATE,Available; FROM Strings IMPORT Assign,CompareStr; FROM SYSTEM IMPORT AX,BX,CX,DX,SETREG,GETREG,CODE, SWI,TSIZE,BYTE,WORD; CONST TYPE rows 25; cols ao; NumBlocks = 10; PUSHBP 0055H; POPBP 005DH; INT10 OOlOH; READCH OaOOH; WRITECH 0900H; GETMODE OFOOH; CURSOR 0200H; ROWINC OlOOH; NAMELENGTH = 24; CA = ARRAY [0 .. 1] OF BYTE; (* Contains char value and attribute. *) (* CA[O] is the character and CA[l] is the attribute. *) = ARRAY[O .. cols - 1] OF CA; (* Each line of the ao col display. *) R RowPointer = POINTER TO R; BlockType = ARRAY[O .. rows - 1] OF RowPointer; ScreenBlock RECORD Handle: ARRAY[O .. NAMELENGTH] OF CHAR; FirstRow,LastRow,FirstCol,LastCol : CARDINAL; Row : BlockType; END; BlockPointer = POINTER TO ScreenBlock; BlockArray = ARRAY[O .. NumBlocks - 1] OF BlockPointer; = VAR BlockSpace : BlockArray; PROCEDURE CutBlock(FirstRow,LastRow,FirstCol,LastCol Handle: ARRAY OF CHAR ; VAR done CARDINAL; BOOLEAN); VAR I,J,K,NumCols,Position : CARDINAL; A : BlockPointer; MODE,PAGE,TEMP : WORD; BEGIN done := FALSE; (* Test for legitimate input. *) IF «(FirstRow <= LastRow) AND (FirstCol <= LastCol» AND «LastRow < rows) AND (LastCol < cols») THEN MICRO CORNUCOPIA, #38, Nov-Dec 1987 49