dim bitpatt$(3)
readfonts
screen 12
colcoast% = 2
colngrgrid% = 3 : colngrlet% = 11 : colgr% = 7 : colet% = 15

open "r",2,"eucoast.dat",9
field 2,1 as col$,4 as ml$,4 as ma$
DR=180/3.141592654
n = 1300
for e = 0 to 700 step 100
	if e mod 500 = 0 then patt% = &hffff else patt% = &hcccc
	XYmap
	line (x% , 479) - (x% , y% ) , colngrgrid% ,, patt%
next e
e = 700
for n = 0 to 1300 step 100
	if n mod 500 = 0 then patt% = &hffff else patt% = &hcccc
	XYmap
	line (113 , y%) - (x% ,y%) , colngrgrid% ,, patt%
next n

do
	incr recordno%
	get 2,recordno%
	col%=val(col$)
	if asc(col$)=255 then exit loop
	long=cvs(ml$)
	lat=cvs(ma$)
	call LLtoEN(lat , long , e , n)

	XYmap
	if col%=0 then
		pset (x% ,y%),colcoast%
	else
		line -(x% , y%),colcoast%
	end if
loop
close 2
color colet%
for e = 0 to 600 step 100
	for n = 0 to 1200 step 100
		C1% = 83 - 5 * (N \ 500)+(E \ 500)
		IF C1% = 73 THEN C1% = 72
		EH% = (E MOD 500) \ 100
		NH% = (N MOD 500) \ 100
		C2% = (4 - NH%) * 5 + EH% + 65
		IF C2% > 72 THEN C2% = C2% + 1
		NGR$ = CHR$(C1%) + CHR$(C2%)
		XYmap
		call TextXY(ngr$ , x% + 10 , y% - 12 , colngrlet% , 1)
	next n%
next e%

for lat = 50 to 61 step 1
	for long = -12 to 14 step 2
		for yd = 0 to 1 step .1
			call LLtoEN(lat + yd , long , e , n)
			XYmap
			pset (x% , y%) , colgr%
		next yd

		for xd = 0 to 2 step .2
			call LLtoEN(lat , long + xd , e , n)
			XYmap
			pset (x% , y%) , colgr%
		next yd

		call LLtoEN(lat , long , e , n)
		XYmap
		locator$=chr$(65+int((long+180)/20))+chr$(65+int((lat+90)/10))+_
				chr$(48+int((long+180)/2 mod 10))+chr$(48+int((lat+90) mod 10))
		call TextXY(locator$ , x% + 10 , y% - 15 , colet% , 1)
		pset (x% , y%) , colet%
	next long
next lat
call textxy("Background 0" , 0 , 10 , 15 , 1)
call textxy("NGR grid   1" , 0 , 20, colngrgrid% , 1)
call textxy("NGR Labels 2" , 0 , 30, colngrlet% , 1)
call textxy("Loc grid   3" , 0 , 40, colgr% , 1)
call textxy("Loc Labels 4" , 0 , 50, colet% , 1)
call textxy("Coastline  5" , 0 , 60, colcoast% , 1)

do
	while not instat : wend
	ik$ = ucase$(inkey$)
	if ik$ = "0" then p0% = (p0% + 1) mod 64 : palette 0 , p0%
	if ik$ = "1" then p1% = (p1% + 1) mod 64 : palette colngrgrid% , p1%
	if ik$ = "2" then p2% = (p2% + 1) mod 64 : palette colngrlet% , p2%
	if ik$ = "3" then p3% = (p3% + 1) mod 64 : palette colgr% , p3%
	if ik$ = "4" then p4% = (p4% + 1) mod 64 : palette colet% , p4%
	if ik$ = "5" then p5% = (p5% + 1) mod 64 : palette colcoast% , p5%
loop until ik$ = chr$(27)
end

sub LLtoEN(lat , long , e , n)
	shared dr
	LATR=LAT/DR
	LONGR=LONG/DR
	Y=SQR(1-.00667054#*SIN(LATR)*SIN(LATR))
	N=-100+111.0793*(LAT-49)
	N=N-31.947*SIN((LAT-49)/DR)*COS(LATR+49/DR)+.971*(2+LONG)^2*SIN(LATR)*COS(LATR)/Y
	E=400+111.2651*(2+LONG)*COS(LATR)/Y
	E=E-.0056*(2+LONG)^3*(COS(LATR))^3*((TAN(LATR))^2-1)
end sub


function XYmap
	shared e , n , x% , y%
	x% = (e + 300) * 640 / 1700
	y% = 479 - n / 1300 * 480
end function

sub textxy(text$ , x% , y% , colour% , fontno%)
	shared bitpatt$()
	select case fontno%
	case 1 , 5 , 7                '7x5 font
		rowsperchar% = 8
		colsperchar% = 6
		arrayref% = 0
	case 2 , 8
   	rowsperchar% = 8
		colsperchar% = 8
		arrayref% = 1
	case 3 , 14
		rowsperchar% = 14
		colsperchar% = 8
		arrayref% = 2
	case 4 , 16
		rowsperchar% = 16
		colsperchar% = 9
		arrayref% = 3
	end select
	for charcount% = 1 to len(text$)
		ch% = asc(mid$(text$ , charcount% , 1))
		xbase% = x% + colsperchar% * (charcount% - 1)
		for rw% = 0 to rowsperchar% - 1
			thisch% = asc(mid$(bitpatt$(arrayref%) , 1 + rw% + ch% * rowsperchar% , 1))
			for bitno% = 0 to 7
				if bit(thisch% , 7 - bitno%) then
					pset (xbase% + bitno%  , y% + rw% - rowsperchar% ) , colour%
				end if
			next bitno%
		next rw%
	next charcount%
end sub

sub ReadFonts
	shared bitpatt$()
	fino% = freefile
	open "b" , fino% , "allfonts"
	get$  fino% , 2048 , bitpatt$(0)
	get$  fino% , 2048 , bitpatt$(1)
	get$  fino% , 3584 , bitpatt$(2)
	get$  fino% , 4096 , bitpatt$(3)
	close fino%
end sub