Final task

ICP'97

INVEX - Computer, Brno 1997

Map viewer

Write a program which will be used to view maps. Name the program xxmview (where xx is your starting number). The program will have one argument which specifies name of file with map definition. Format of the definition file is described bellow.

Map is a set of regions in our task. Each region has unique color. Each region is defined as unification of rectangular areas.

Your program should read definition file, parse it and show appropriate map on a screen. Then it will be possible to use mouse to select individual regions. Selection is done by clicking inside an area which belongs to the region. Selected region will then have highlighted border.

Interaction with the program can be canceled by pressing Esc key.

Description of definition file

Each definition file is text file. The first line contains information about format level:

MDF/level

level can take one of the four following values: 1, 2, 3 and 4.

Subsequent lines contain definition of areas. Each line can contain only one definition in following format:

index X1 Y1 X2 Y2 

index is used to specify region to which defined area belongs. index can take value from 1 to 239. Following four integers are coordinates of upper-left and bottom-right corner of rectangle which defines border of area.

X-coordinates can take value from 0 to 319; theirs Y counterparts are from 0 to 199.

Areas in definition file are non-overlapping.

Level 1
Level 1 files contain regions which are defined only by one area. (This means that each region has rectangular shape.)
Level 2
In level 2 files region can be built up by more than one area. Resulting regions all always continuous and do not contain gaps. (This means that border of each region is a single closed path.)
Level 3
Level 3 files can contain regions that are not continuous.
Level 4
Level 4 files can contain regions that are not continuous and can contain gaps.

Graphics presentation

For displaying you should use graphics mode 320 x 200 x 256 (VGA mode 13h).

Index of the region in the definition file should be used as index to palette when choosing color for displaying that region. In following table you can examine how individual entries are defined in the palette:

Index (I) Red Green Blue
0 0 0 0
1-239 ((I shr 5) * 255) div 7
((I >> 5) * 255) / 7
(((I shr 2) and 7) * 255) div 7
(((I >> 2) & 7) * 255) / 7
(I and 3) * 255) div 3
(I & 3) * 255) / 3
240-254 Free for you personal use
255 255 255 255

Notes

Your program and all its modules should be stored in the directory C:\ICP. Name the modules in such way that the two first letters of its name are your starting number.

Write your starting number, a list of all used modules and a list of levels which are supported in your program as a comment at the beginning of the program.

There are several files with extension mdf in the directory C:\ICP. These files contain definitions of several maps and you can use them for testing purposes. There is also mapview program which presents simple sample solution of the task.

Permitted aid is English vocabulary, books which describe programming language, its environment (IDE) and standard libraries. You can not use books with description of various methods, algorithms and data structures.

You can get total of 100 points. 60 out of them are used for evaluating functionality, 30 for evaluating efficiency (smart and fast algorithms, sophisticated data structures). Last ten points are used for documentation (description of algorithm, comments, naming convention, neat way of writing code).

Part Maximal no. of points assigned for functionality
Support for level 1 files 5
Support for level 2 files 15
Support for level 3 files 10
Support for level 4 files 15
Smoothness of border scrolling and overall graphics design 15

A gentle introduction to INT 10h and INT 33h

Following are an excerpts from Ralph Brown's Interrupt list:

------------------------------------------------------------------------
INT 10 - VIDEO - SET VIDEO MODE
	AH = 00h
	AL = mode 
Desc: specify the display mode for the currently active display adapter
------------------------------------------------------------------------
INT 10 - VIDEO - GET CURRENT VIDEO MODE
	AH = 0Fh
Return: AH = number of character columns
	AL = display mode 
------------------------------------------------------------------------
INT 10 - VIDEO - SET INDIVIDUAL DAC REGISTER (VGA/MCGA)
	AX = 1010h
	BX = register number
	CH = new value for green (0-63)
	CL = new value for blue (0-63)
	DH = new value for red (0-63)
------------------------------------------------------------------------
INT 10 - VIDEO - SET BLOCK OF DAC REGISTERS (VGA/MCGA)
	AX = 1012h
	BX = starting color register
	CX = number of registers to set
	ES:DX -> table of 3*CX bytes where each 3 byte group represents one
		 byte each of red, green and blue (0-63)
------------------------------------------------------------------------
INT 33 - MS MOUSE - RESET DRIVER AND READ STATUS
	AX = 0000h
Return: AX = status
	    0000h hardware/driver not installed
	    FFFFh hardware/driver installed
	BX = number of buttons
	    0000h other than two
	    0002h two buttons (many drivers)
	    0003h Mouse Systems/Logitech three-button mouse
	    FFFFh two buttons
------------------------------------------------------------------------
INT 33 - MS MOUSE v1.0+ - SHOW MOUSE CURSOR
	AX = 0001h
------------------------------------------------------------------------
INT 33 - MS MOUSE v1.0+ - HIDE MOUSE CURSOR
	AX = 0002h
Note:	multiple calls to hide the cursor will require multiple calls to
	  function 01h to unhide it.
------------------------------------------------------------------------
INT 33 - MS MOUSE v1.0+ - RETURN POSITION AND BUTTON STATUS
	AX = 0003h
Return: BX = button status (see #1699)
	CX = column
	DX = row
Note:	in text modes, all coordinates are specified as multiples of the cell
	  size, typically 8x8 pixels

    Bitfields for mouse button status:
    Bit(s)	Description	(Table 1699)
     0	left button pressed if 1
     1	right button pressed if 1
     2	middle button pressed if 1 (Mouse Systems/Logitech/Genius)
------------------------------------------------------------------------
INT 33 - MS MOUSE v1.0+ - DEFINE INTERRUPT SUBROUTINE PARAMETERS
	AX = 000Ch
	CX = call mask (see #1702)
	ES:DX -> FAR routine (see #1703)
SeeAlso: AX=0018h

    Bitfields for mouse call mask:
    Bit(s)	Description	(Table 1702)
     0	call if mouse moves
     1	call if left button pressed
     2	call if left button released
     3	call if right button pressed
     4	call if right button released
     5	call if middle button pressed (Mouse Systems/Logitech/Genius mouse)
     6	call if middle button released (Mouse Systems/Logitech/Genius mouse)
     7-15	unused

    (Table 1703)
    Values interrupt routine is called with:
    	AX = condition mask (same bit assignments as call mask)
    	BX = button state
    	CX = cursor column
    	DX = cursor row
    	SI = horizontal mickey count
    	DI = vertical mickey count
------------------------------------------------------------------------