'********************************
'
' Acid Works Draw
'
'
'********************************
' $INCLUDE: 'c:\qb\qb4\qb.bi'
DEFINT A-Z
DECLARE SUB Mouse (cx, dx, bx)
DECLARE SUB MousePointer (SW)
DECLARE SUB SetupScreen ()
DECLARE SUB UpdatePtStatus ()
DECLARE SUB UpdateBrush ()
DECLARE SUB TimeIt (lent%)
DECLARE SUB ChangeColor ()
DECLARE SUB ChangePic ()
DECLARE SUB ColorSq ()
DECLARE SUB FillPart ()
DECLARE SUB ReadPalette ()
DECLARE SUB GetColor (wk%)
DECLARE SUB MakeMask ()
DECLARE SUB Undo ()
DECLARE SUB ChangeGrid ()
DECLARE SUB DoText ()
DECLARE SUB Font (words$)
DECLARE SUB CopyPic ()
DECLARE SUB PastePic ()
DECLARE SUB FlipPic (way%)
DECLARE SUB TeoTeu (teo%, teu%)
DECLARE SUB RotPic (way%)
DECLARE SUB MovePic (way%)
DECLARE SUB Invert (wk%)
DECLARE SUB Tone (direc%)
DECLARE SUB DoLine ()
DECLARE SUB Stretch ()
DECLARE SUB XLoadPic ()
DECLARE SUB XSavePic ()
DECLARE SUB LoadFont ()
DECLARE SUB ShowFont (xx%, yy%, st$, sty%)
DECLARE SUB InputString (strng%)
DECLARE SUB PalChange (wk%)
DECLARE SUB XWritePal (wk%)
DECLARE SUB XPalLoad (wk%)
DECLARE SUB PalStuff ()
DECLARE SUB MenuStuff ()
DECLARE SUB SizeStuff ()
DECLARE FUNCTION CB% (o1%, u1%, o2%, u2%)
DECLARE SUB EraseDot ()
DECLARE SUB Selection ()
DECLARE SUB RotatePal ()
DECLARE SUB XDrawBMP8 (Pic$, x%, y%)
DECLARE SUB XSaveBMP8 (Pic$, X1%, Y1%, x2%, y2%)
DECLARE FUNCTION XLongToString$ (L&)
DECLARE SUB XBufferWrite (a%)
DECLARE FUNCTION XGetByte% ()
DECLARE SUB XMakeGIF (a$, ScreenX%, ScreenY%, XStart%, YStart%, XEnd%, YEnd%, NumColors%, AdaptorType%)
DECLARE SUB XPutByte (a%)
DECLARE SUB XPutCode (a%)
DECLARE SUB XLoadGif (File$)
DECLARE SUB AboutAWD ()
DECLARE FUNCTION ZDirBox$ (ArgD$, ArgF$)
DECLARE SUB ZDList ()
DECLARE SUB UpdatePic ()
DECLARE SUB DoMouse (x%, y%, lines%)
DECLARE SUB CheckBound (co1%, co2%, cu1%, cu2%)
DECLARE SUB AntiAlias (o1%, o2%, u1%, u2%)
'********************************
DIM SHARED Pic(1 TO 50, 1 TO 50), Shift(7) AS LONG, shape
DIM SHARED MoveHold(1 TO 50, 1 TO 50), so1, so2, su1, su2
DIM SHARED CopyHold(1 TO 50, 1 TO 50), tclr, selecton, cx, cy
DIM SHARED fontt(1 TO 116, 1 TO 10, 1 TO 10), aa(9), arrow(50)
DIM SHARED cp(0 TO 255, 1 TO 3), brush, balias, bachold(50)
DIM SHARED px, py, invhold(1375), sh(1375), clr, palname AS STRING
DIM SHARED PointType, o, u, DriveList AS STRING, FD AS STRING
DIM SHARED over, up, filname AS STRING, grid, amask(50), button
DIM SHARED Register AS RegType, XRegister AS RegTypeX
DIM SHARED OutBuffer$, OStartAddress, OAddress, OEndAddress, Oseg
DIM SHARED CodeSize, CurrentBit, Char&, BlockLength, HD AS STRING
DIM SHARED x, y, Minx, MinY, MaxX, MaxY, Done, giffile, LastLoc&
CONST TRUE = -1, FALSE = 0
'********************************
RANDOMIZE TIMER: CLS : DEF SEG = VARSEG(aa(0))
CALL LoadFont: SCREEN 13: balias = 0: grid = 1
FOR i = 0 TO 17: READ r: POKE VARPTR(aa(0)) + i, r: NEXT i
CALL MousePointer(0): CALL MousePointer(3)
FOR i = 1 TO 10: READ pnt$: FOR a = 1 TO 7
 IF MID$(pnt$, a, 1) <> "0" THEN PSET (a - 1, i - 1), 15
NEXT a: NEXT i: GET (0, 0)-(6, 9), arrow
FOR i = 1 TO 10: FOR a = 1 TO 7
 IF POINT(a - 1, i - 1) = 0 THEN PSET (a - 1, i - 1), 255
NEXT a: NEXT i: GET (0, 0)-(6, 9), amask: CLS : tclr = 23
CALL XPalLoad(0)
DEF SEG = &HA000: BLOAD "awdraw.dat", 0
ShowFont 0, 0, "File Pal Image", 1: selecton = 0
GET (over, up)-(over + 6, up + 9), bachold
PointType = 1: but = 0: brush = 1: shape = 1: palname$ = ""
px = 50: py = 50: filname$ = "": cx = 0: cy = 0
CALL ChangeColor: CALL UpdateBrush: CALL ZDList
CALL UpdatePtStatus: CALL SetupScreen: CALL ChangePic
CALL SizeStuff: ON ERROR GOTO ErrorTrap
'********************************
ReStart:

DO
 o = over: u = up: CALL Mouse(up, over, button)
 CALL CheckBound(0, 312, 0, 189)
 IF o <> over OR u <> up THEN CALL DoMouse(o, u, 1)

 IF button = 1 THEN
  IF over > 206 AND up > 98 AND over < 240 AND up < 108 THEN CALL Undo: but = 1
  IF selecton = 1 THEN PUT (150, 12), sh, PSET
  GET (150, 12)-(149 + px, 11 + py), invhold
  IF up > 10 AND over < (3 * px) - 1 AND up < (3 * py) + 10 THEN
   IF PointType = 1 THEN ColorSq
   IF PointType = 2 THEN FillPart: but = 1
   IF PointType = 3 THEN GetColor 2
   IF PointType > 3 AND PointType < 8 THEN DoLine: but = 1
   IF PointType = 10 THEN DoLine: but = 1
   IF PointType = 8 THEN DoText
   IF PointType = 9 THEN EraseDot
   IF PointType = 11 THEN Selection: but = 1
   IF PointType = 12 THEN PastePic: but = 1
  END IF
  IF CB(259, 36, 293, 46) = 1 THEN CopyPic
  IF CB(6, 164, 151, 185) = 1 THEN CALL GetColor(1)
  IF CB(6, 184, 55, 188) = 1 THEN CALL GetColor(1)
  IF CB(206, 57, 240, 67) = 1 THEN CALL FlipPic(1): but = 1
  IF CB(206, 41, 240, 51) = 1 THEN CALL FlipPic(2): but = 1
  IF CB(206, 27, 217, 38) = 1 THEN CALL MovePic(1): but = 1
  IF CB(217, 16, 229, 27) = 1 THEN CALL MovePic(3): but = 1
  IF CB(217, 27, 229, 38) = 1 THEN CALL MovePic(4): but = 1
  IF CB(229, 27, 240, 38) = 1 THEN CALL MovePic(2): but = 1
  IF CB(206, 16, 217, 27) = 1 THEN CALL RotPic(1): but = 1
  IF CB(229, 16, 240, 27) = 1 THEN CALL RotPic(2): but = 1
  IF CB(242, 70, 276, 80) = 1 THEN CALL Invert(1): but = 1
  IF CB(242, 81, 276, 91) = 1 THEN CALL Invert(2): but = 1
  IF CB(242, 93, 276, 114) = 1 THEN CALL MakeMask
  IF CB(278, 93, 312, 103) = 1 THEN CALL Tone(1): but = 1
  IF CB(278, 104, 312, 114) = 1 THEN CALL Tone(2): but = 1
  IF CB(278, 70, 312, 80) = 1 THEN CALL Tone(3): but = 1
  IF CB(278, 81, 312, 91) = 1 THEN CALL Tone(4): but = 1
  IF CB(242, 48, 276, 58) = 1 THEN CALL Tone(10): but = 1
  IF CB(242, 59, 276, 69) = 1 THEN CALL Tone(6): but = 1
  IF CB(278, 59, 312, 69) = 1 THEN CALL Tone(7): but = 1
  IF CB(278, 48, 312, 58) = 1 THEN CALL Tone(5): but = 1
  IF CB(304, 157, 312, 193) = 1 THEN CALL PalStuff: but = 7
  IF over < 145 AND up < 10 THEN CALL MenuStuff: but = 1
  IF CB(297, 116, 313, 135) = 1 THEN CALL SizeStuff: but = 1
  IF CB(161, 104, 195, 116) = 1 THEN PointType = 1: CALL UpdatePtStatus
  IF CB(161, 117, 195, 138) = 1 THEN PointType = 2: CALL UpdatePtStatus
  IF over > 161 AND up > 139 AND over < 195 AND up < 151 THEN PointType = 3: CALL UpdatePtStatus
  IF over > 161 AND up > 152 AND over < 178 AND up < 162 THEN PointType = 4: CALL UpdatePtStatus
  IF over > 178 AND up > 152 AND over < 195 AND up < 162 THEN PointType = 10: CALL UpdatePtStatus
  IF over > 161 AND up > 162 AND over < 172 AND up < 173 THEN PointType = 5: CALL UpdatePtStatus
  IF over > 172 AND up > 162 AND over < 184 AND up < 173 THEN PointType = 6: CALL UpdatePtStatus
  IF over > 184 AND up > 162 AND over < 195 AND up < 173 THEN PointType = 7: CALL UpdatePtStatus
  IF over > 161 AND up > 174 AND over < 195 AND up < 184 THEN PointType = 8: CALL UpdatePtStatus
  IF over > 161 AND up > 184 AND over < 195 AND up < 194 THEN PointType = 9: CALL UpdatePtStatus
  IF over > 253 AND up > 16 AND over < 287 AND up < 26 THEN PointType = 11: CALL UpdatePtStatus
  IF over > 259 AND up > 26 AND over < 293 AND up < 36 THEN PointType = 12: CALL UpdatePtStatus
  IF over > 290 AND up > 16 AND over < 300 AND up < 26 THEN selecton = 0: CALL UpdatePtStatus
  IF over > 210 AND up > 86 AND over < 222 AND up < 92 THEN balias = balias + 1: CALL UpdateBrush: but = 1
  IF over > 161 AND up > 79 AND over < 167 AND up < 88 THEN brush = 1: CALL UpdateBrush
  IF over > 166 AND up > 79 AND over < 173 AND up < 88 THEN brush = 2: CALL UpdateBrush
  IF over > 172 AND up > 79 AND over < 180 AND up < 88 THEN brush = 3: CALL UpdateBrush
  IF over > 178 AND up > 79 AND over < 187 AND up < 88 THEN brush = 4: CALL UpdateBrush
  IF over > 186 AND up > 79 AND over < 196 AND up < 89 THEN brush = 5: CALL UpdateBrush
  IF over > 161 AND up > 94 AND over < 170 AND up < 102 THEN shape = 1: CALL UpdateBrush
  IF over > 168 AND up > 94 AND over < 177 AND up < 102 THEN shape = 2: CALL UpdateBrush
  IF over > 175 AND up > 94 AND over < 184 AND up < 102 THEN shape = 3: CALL UpdateBrush
  IF over > 182 AND up > 94 AND over < 191 AND up < 102 THEN shape = 4: CALL UpdateBrush
  IF over > 189 AND up > 94 AND over < 195 AND up < 102 THEN shape = 5: CALL UpdateBrush
  IF selecton = 1 THEN
   GET (150, 12)-(149 + px, 11 + py), sh
   LINE (149 + so1, 11 + su1)-(149 + so2, 11 + su2), 15, B
  END IF
 END IF

 IF but = 1 THEN TimeIt 4: but = 0
 IF but = 7 THEN TimeIt 2: but = 0

 IF up > 10 AND over < (3 * px) - 1 AND up < (3 * py) + 10 THEN
  CALL TeoTeu(teo, teu)
  ShowFont 210, 0, "X:" + STR$(teo) + " ", 2
  ShowFont 270, 0, "Y:" + STR$(teu) + " ", 2
 ELSE
  ShowFont 210, 0, "           ", 1
 END IF
 WAIT &H3DA, 8
LOOP

ErrorTrap:
 palname$ = "": filname$ = "": CLOSE
 PUT (over, up), bachold, PSET: BEEP
 ShowFont 5, 20, "Not a valid file!", 4
 WHILE INKEY$ = "": WEND
 CALL SetupScreen: CALL ChangePic: CALL DoMouse(o, u, 0)
 RESUME ReStart

DATA &HB8,&H00,&H00   :
DATA &H55             :
DATA &H8B,&HEC        :
DATA &HCD,&H33        :
DATA &H92             :
DATA &H8B,&H5E,&H06   :
DATA &H89,&H07        :
DATA &H5D             :
DATA &HCA,&H02,&H00   :

DATA 1000000
DATA 1100000
DATA 1110000
DATA 1111000
DATA 1111100
DATA 1111110
DATA 1111111
DATA 1111100
DATA 1001110
DATA 0000110

ShiftTable:
DATA 1,2,4,8,16,32,64,128

SUB AboutAWD
 PUT (over, up), bachold, PSET: CALL TimeIt(4)
 LINE (10, 20)-(130, 110), 7, BF: LINE (15, 25)-(125, 105), 0, BF
 LINE (10, 20)-(10, 110), 15: LINE (10, 20)-(130, 20), 15
 LINE (130, 20)-(130, 110), 8: LINE (130, 110)-(11, 110), 8
 ShowFont 20, 27, "Acid Works", 3
 ShowFont 25, 37, "Draw v2.0", 3
 ShowFont 20, 47, "    by    ", 1
 ShowFont 25, 57, "  Steve", 4
 ShowFont 20, 67, " Nunnally", 4
 ShowFont 50, 85, "Okay", 2
 LINE (48, 83)-(91, 96), 8, B
 GET (over, up)-(over + 6, up + 9), bachold
 DO
  o = over: u = up
  CALL Mouse(up, over, button)
  CALL CheckBound(10, 130, 20, 110)
  IF o <> over OR u <> up THEN CALL DoMouse(o, u, 1)
  IF button = 1 THEN IF over > 50 AND over < 90 AND up > 84 AND up < 96 THEN EXIT DO
  WAIT &H3DA, 8
 LOOP
END SUB

SUB AntiAlias (o1, o2, u1, u2)
 FOR x = o1 TO o2
  FOR y = u1 TO u2
   Pic(x, y) = POINT(149 + x, 11 + y)
   pc = Pic(x, y): cl = pc: tc = 1
   tr = cp(cl, 1): tg = cp(cl, 2): tb = cp(cl, 3)
   IF y <> u2 THEN cl = Pic(x, y + 1): tc = tc + 1: tr = tr + cp(cl, 1): tg = tg + cp(cl, 2): tb = tb + cp(cl, 3)
   IF x <> o2 THEN cl = Pic(x + 1, y): tc = tc + 1: tr = tr + cp(cl, 1): tg = tg + cp(cl, 2): tb = tb + cp(cl, 3)
   IF y <> u1 THEN cl = Pic(x, y - 1): tc = tc + 1: tr = tr + cp(cl, 1): tg = tg + cp(cl, 2): tb = tb + cp(cl, 3)
   IF x <> o1 THEN cl = Pic(x - 1, y): tc = tc + 1: tr = tr + cp(cl, 1): tg = tg + cp(cl, 2): tb = tb + cp(cl, 3)
   tr = tr / tc: tg = tg / tc: tb = tb / tc: cc = 200: cl = pc: i = 0
   DO
    dr = cp(i, 1): dg = cp(i, 2): db = cp(i, 3)
    dr = ABS(tr - dr): dg = ABS(tg - dg): db = ABS(tb - db)
    IF dr + dg + db < cc THEN cc = dr + dg + db: cl = i
    i = i + 1
   LOOP UNTIL cc < 4 OR i = 256
   PSET (x + 149, y + 11), cl
 NEXT y, x
END SUB

FUNCTION CB (o1, u1, o2, u2)
 IF over > o1 AND up > u1 AND over < o2 AND up < u2 THEN CB = 1
END FUNCTION

SUB ChangeColor
 PUT (over, up), bachold, PSET
 cl$ = STR$(tclr): cl$ = LTRIM$(cl$)
 IF LEN(cl$) = 1 THEN spaces$ = "  "
 IF LEN(cl$) = 2 THEN spaces$ = " "
 IF LEN(cl$) = 3 THEN spaces$ = ""
 ShowFont 65, 185, "Color:" + cl$ + spaces$, 1
 FOR a = 0 TO 4
  FOR B = 0 TO 47
  o1 = 7 + (B * 3): o2 = 9 + (B * 3)
  u1 = 165 + (a * 4): u2 = 167 + (a * 4)
  LINE (o1, u1)-(o2, u2), B + (a * 48), BF
  IF (a * 48) + B = clr THEN LINE (o1, u1 - 1)-(o2, u1 - 1), 0, BF: LINE (o1, u2 + 1)-(o2, u2 + 1), 0, BF
  IF (a * 48) + B = tclr THEN LINE (o1, u1 - 1)-(o2, u1 - 1), 15, BF: LINE (o1, u2 + 1)-(o2, u2 + 1), 15, BF
 NEXT B, a
 FOR B = 0 TO 15
  o1 = 7 + (B * 3): o2 = 9 + (B * 3)
  LINE (o1, 185)-(o2, 187), B + 240, BF
  IF B + 240 = clr THEN LINE (o1, 184)-(o2, 184), 0, BF: LINE (o1, 188)-(o2, 188), 0, BF
  IF B + 240 = tclr THEN LINE (o1, 184)-(o2, 184), 15, BF: LINE (o1, 188)-(o2, 188), 15, BF
 NEXT B
 LINE (7, 190)-(60, 193), tclr, BF
 clr = tclr: CALL PalStuff: CALL DoMouse(over, up, 0)
END SUB

SUB ChangeGrid
 FOR a = 0 TO (px - 1): FOR B = 0 TO (py - 1)
  o3 = a * 3: u3 = (B * 3) + 11
  o4 = (a * 3) + 1: u4 = (B * 3) + 12
  IF grid = 1 THEN
   LINE (o3, u3)-(o4, u4), Pic(a + 1, B + 1), BF
  ELSE
   LINE (o3, u3)-(o4 + 1, u4 + 1), Pic(a + 1, B + 1), BF
  END IF
 NEXT B, a
 LINE (149, 11)-(149, 160), 8: LINE (0, 160)-(149, 160), 8
END SUB

SUB ChangePic
 FOR a = 0 TO (px - 1)
  FOR B = 0 TO (py - 1)
   PSET (150 + a, 12 + B), Pic(a + 1, B + 1)
 NEXT B, a
 FOR a = 0 TO (px - 1)
  FOR B = 0 TO (py - 1)
   o1 = a * 3: u1 = (B * 3) + 11
   o2 = (a * 3) + 1: u2 = (B * 3) + 12
   IF grid = 1 THEN
    LINE (o1, u1)-(o2, u2), Pic(a + 1, B + 1), BF
   ELSE
    LINE (o1, u1)-(o2 + 1, u2 + 1), Pic(a + 1, B + 1), BF
   END IF
 NEXT B, a
 LINE (149, 11)-(149, 160), 8: LINE (0, 160)-(149, 160), 8
END SUB

SUB CheckBound (co1, co2, cu1, cu2)
 IF over < co1 THEN over = co1
 IF over > co2 THEN over = co2
 IF up < cu1 THEN up = cu1
 IF up > cu2 THEN up = cu2
END SUB

SUB ColorSq

IF balias = 1 THEN CALL ReadPalette
DO
 o = over: u = up: CALL Mouse(up, over, button)
 CALL CheckBound(0, 148, 11, 159)
 IF o <> over OR u <> up THEN CALL DoMouse(o, u, 1)
 CALL TeoTeu(teo, teu)
 o1 = (149 + teo) - INT(brush / 2): u1 = (11 + teu) - INT(brush / 2)
 o2 = (149 + teo) + INT((brush - 1) / 2): u2 = (11 + teu) + INT((brush - 1) / 2)
 IF shape = 5 THEN o1 = (149 + teo): o2 = (149 + teo)
 IF o1 < 150 THEN o1 = 150
 IF o2 > (149 + px) THEN o2 = (149 + px)
 IF u1 < 12 THEN u1 = 12
 IF u2 > (11 + py) THEN u2 = (11 + py)
 PUT (over, up), bachold, PSET
 IF shape = 1 THEN LINE (o1, u1)-(o2, u2), clr, BF
 IF shape = 3 THEN LINE (o1, u2)-(o2, u1), clr
 IF shape = 4 THEN LINE (o1, u1)-(o2, u2), clr
 IF shape = 5 THEN LINE (o1, u1)-(o2, u2), clr
 o1 = teo - INT(brush / 2): u1 = teu - INT(brush / 2)
 o2 = teo + INT((brush - 1) / 2): u2 = teu + INT((brush - 1) / 2)
 IF o1 < 1 THEN o1 = 1
 IF o2 > px THEN o2 = px
 IF u1 < 1 THEN u1 = 1
 IF u2 > py THEN u2 = py

 IF shape = 2 THEN
  o1 = (149 + teo): u1 = (11 + teu)
  IF o1 - brush < 150 THEN o1 = 149 + brush
  IF u1 - brush < 12 THEN u1 = 11 + brush
  IF o1 + brush > 149 + px THEN o1 = 150 + px - brush
  IF u1 + brush > 11 + py THEN u1 = 12 + py - brush
  FOR a = 0 TO brush - 1: CIRCLE (o1, u1), a, clr, , , .9: NEXT a
  IF brush > 2 THEN
   LINE (o1 - 1, u1 + 1)-(o1 + 1, u1 - 1), clr
   LINE (o1 - 1, u1 - 1)-(o1 + 1, u1 + 1), clr
  END IF
  o1 = o1 - 149: u1 = u1 - 11
  o2 = o1 + (brush - 1): u2 = u1 + (brush - 1)
  o1 = o1 - (brush - 1): u1 = u1 - (brush - 1)
 END IF
 o1 = o1 - 1: o2 = o2 + 1: u1 = u1 - 1: u2 = u2 + 1
 IF o1 < 1 THEN o1 = 1
 IF u1 < 1 THEN u1 = 1
 IF o2 > px THEN o2 = px
 IF u2 > py THEN u2 = py
 IF balias = 1 THEN CALL AntiAlias(o1, o2, u1, u2)
 FOR a = o1 TO o2
  FOR B = u1 TO u2
   Pic(a, B) = POINT(149 + a, 11 + B)
   o3 = a * 3: u3 = (B * 3) + 11
   o4 = (a * 3) + 1: u4 = (B * 3) + 12
   IF grid = 1 THEN
    LINE (o3 - 3, u3 - 3)-(o4 - 3, u4 - 3), Pic(a, B), BF
   ELSE
    LINE (o3 - 3, u3 - 3)-(o4 - 2, u4 - 2), Pic(a, B), BF
   END IF
 NEXT B, a
 LINE (149, 11)-(149, 160), 8: LINE (0, 160)-(149, 160), 8
 CALL DoMouse(over, up, 0)
 WAIT &H3DA, 8: WAIT &H3DA, 8, 8
LOOP UNTIL button = 0

END SUB

SUB CopyPic
 oo1 = 1: oo2 = px: uu1 = 1: uu2 = py
 IF selecton = 1 THEN oo1 = so1: oo2 = so2: uu1 = su1: uu2 = su2
 aa = 0
 FOR a = oo1 TO oo2
  aa = aa + 1: bb = 1
  FOR B = uu1 TO uu2
   CopyHold(aa, bb) = Pic(a, B)
   bb = bb + 1
 NEXT B, a
END SUB

SUB DoLine
 CALL TeoTeu(teo, teu): o1 = teo: u1 = teu
 PUT (over, up), bachold, PSET: CALL TimeIt(4)
 GET (150, 12)-(149 + px, 11 + py), invhold
 om = (px * 3) - 1: um = (py * 3) + 10
 over = 500: up = 500
 DO
  o = over: u = up: CALL Mouse(up, over, button)
  CALL CheckBound(0, om, 11, um)
  IF o <> over OR u <> up THEN
   CALL TeoTeu(teo, teu)
   ShowFont 210, 0, "X:" + STR$(teo) + " ", 2
   ShowFont 270, 0, "Y:" + STR$(teu) + " ", 2
   PUT (150, 12), invhold, PSET
   GET (150, 12)-(149 + px, 11 + py), invhold
   IF PointType = 4 THEN LINE (149 + o1, 11 + u1)-(149 + teo, 11 + teu), clr
   IF PointType = 5 THEN LINE (149 + o1, 11 + u1)-(149 + teo, 11 + teu), clr, B
   IF PointType = 6 THEN
    IF teo >= o1 THEN o3 = o1: o4 = teo
    IF teo < o1 THEN o3 = teo: o4 = o1
    FOR a = o3 TO o4
     LINE (149 + a, 11 + u1)-(149 + a, 11 + teu), clr, B
    NEXT a
   END IF
   IF PointType = 10 THEN
    xl = INT(ABS(teo - o1)): yl = INT(ABS(teu - u1))
    IF yl < 1 THEN yl = 1
    IF xl < 1 THEN xl = 1
    IF xl > yl THEN r = INT(xl / 2) ELSE r = INT(yl / 2)
    IF teo - o1 < 0 THEN o3 = o1 - (xl / 2) ELSE o3 = o1 + (xl / 2)
    IF teu - u1 < 0 THEN u3 = u1 - (yl / 2) ELSE u3 = u1 + (yl / 2)
    CIRCLE (149 + o3, 11 + u3), r, clr, , , (3 * (yl / xl)) / 3
    LINE (149, 11)-(200, 62), 7, B
   END IF
   IF PointType = 7 THEN
    IF teo <= o1 THEN ro = o1 - ABS(teo)
    IF teo > o1 THEN ro = teo - o1
    IF teu <= u1 THEN ru = u1 - ABS(teu)
    IF teu > u1 THEN ru = teu - u1
    IF ru > ro THEN r = ru ELSE r = ro
    DO WHILE o1 - r < 0: r = r - 1: LOOP
    DO WHILE u1 - r < 0: r = r - 1: LOOP
    DO WHILE o1 + r > px: r = r - 1: LOOP
    DO WHILE u1 + r > py: r = r - 1: LOOP
    CIRCLE (o1 + 149, u1 + 11), r, clr, , , .9
    LINE (o1 + 149, u1 + 11)-(teo + 149, teu + 11), 15
    LINE (149, 11)-(200, 62), 7, B
   END IF
   CALL UpdatePic: CALL ChangeGrid
  END IF
  WAIT &H3DA, 8
 LOOP UNTIL button = 1 OR button = 2
 IF button = 2 OR (PointType = 7 AND button = 1) THEN
  PUT (150, 12), invhold, PSET
  CALL UpdatePic: CALL ChangePic
 END IF
 IF (PointType = 7 AND button = 1) THEN
  CIRCLE (o1 + 149, u1 + 11), r, clr, , , .9
  LINE (149, 11)-(200, 62), 7, B
  CALL UpdatePic: CALL ChangeGrid
 END IF
 CALL DoMouse(over, up, 0)
END SUB

SUB DoMouse (x, y, lines)
 IF lines = 1 THEN PUT (x, y), bachold, PSET
 GET (over, up)-(over + 6, up + 9), bachold
 PUT (over, up), arrow, OR: PUT (over, up), amask, AND
END SUB

SUB DoText
 CALL TeoTeu(teo, teu): PUT (over, up), bachold, PSET
 GET (150, 12)-(149 + px, 11 + py), invhold: CALL UpdatePic
 LINE (1, 16)-(178, 33), 7, BF: LINE (5, 20)-(174, 29), 0, BF
 LINE (1, 16)-(1, 33), 15: LINE (1, 16)-(178, 16), 15
 LINE (2, 33)-(178, 33), 8: LINE (178, 16)-(178, 33), 8
 ShowFont 5, 20, "Text:", 1
 ip$ = "": id = 0: x = 55: y = 20: TimeIt 4: tlimit = ((px - teo) / 7) + 1
 DO
  key$ = INKEY$
  IF key$ <> "" THEN
   IF ASC(key$) > 31 THEN
    IF id < tlimit THEN id = id + 1: ip$ = ip$ + key$
   END IF
   IF ASC(key$) = 8 THEN
    IF id > 0 THEN
     ShowFont x + (10 * (id - 1)), y, " ", 2
     id = id - 1: ip$ = LEFT$(ip$, id)
    END IF
   END IF
   IF id <= 8 THEN ShowFont x, y, ip$, 2
  END IF
 LOOP UNTIL key$ = CHR$(13)
 CALL SetupScreen: CALL ChangePic
 DRAW "BM " + STR$(149 + teo) + "," + STR$(11 + teu) + " C" + STR$(clr) + " S4"
 Font LCASE$(ip$)
 UpdatePic
 LINE (201, 12)-(202, 65), 15, BF: LINE (150, 63)-(202, 65), 15, BF
 LINE (150, 63)-(152, 65), 7: LINE (200, 63)-(202, 65), 7
 LINE (201, 13)-(202, 14), 7: LINE (149, 11)-(200, 62), 7, B
 LINE (152, 66)-(203, 66), 7: LINE (203, 66)-(203, 15), 7
 CALL ChangePic: CALL DoMouse(over, up, 0)
END SUB

SUB EraseDot

 CALL TeoTeu(teo, teu): PUT (over, up), bachold, PSET
 IF POINT(149 + teo, 11 + teu) = clr THEN
  PSET (149 + teo, 11 + teu), 0
  Pic(teo, teu) = 0
 END IF
 o3 = (teo * 3) - 3: u3 = ((teu * 3) + 11) - 3
 IF grid = 1 THEN LINE (o3, u3)-(o3 + 1, u3 + 1), Pic(teo, teu), BF
 IF grid = 0 THEN LINE (o3, u3)-(o3 + 2, u3 + 2), Pic(teo, teu), BF
 LINE (149, 11)-(149, 160), 8: LINE (0, 160)-(149, 160), 8
 CALL DoMouse(over, up, 0)

END SUB

SUB FillPart

 DIM tempfigure(1 TO 2500, 1 TO 12) AS INTEGER

 CALL TeoTeu(teo, teu)
 FOR a = 1 TO 2500: FOR B = 1 TO 12: tempfigure(a, B) = 300: NEXT B, a

 e = Pic(teo, teu): Pic(teo, teu) = clr: c = 1
 IF e = clr THEN GOTO DoneFilling
 DO
  F = 0
  IF teo < px THEN tempfigure(c, 1) = Pic(teo + 1, teu): tempfigure(c, 2) = teo + 1: tempfigure(c, 3) = teu
  IF teo > 1 THEN tempfigure(c, 7) = Pic(teo - 1, teu): tempfigure(c, 8) = teo - 1: tempfigure(c, 9) = teu
  IF teu > 1 THEN tempfigure(c, 4) = Pic(teo, teu - 1): tempfigure(c, 5) = teo: tempfigure(c, 6) = teu - 1
  IF teu < py THEN tempfigure(c, 10) = Pic(teo, teu + 1): tempfigure(c, 11) = teo: tempfigure(c, 12) = teu + 1
  IF teo < px THEN
   IF tempfigure(c, 1) = e THEN
    teo = teo + 1: Pic(teo, teu) = clr: F = 1: tempfigure(c, 1) = clr
   END IF
  END IF
  IF teu > 1 AND F = 0 THEN
   IF tempfigure(c, 4) = e THEN
    teu = teu - 1: Pic(teo, teu) = clr: F = 1: tempfigure(c, 4) = clr
   END IF
  END IF
  IF teo > 1 AND F = 0 THEN
   IF tempfigure(c, 7) = e THEN
    teo = teo - 1: Pic(teo, teu) = clr: F = 1: tempfigure(c, 7) = clr
   END IF
  END IF
  IF teu < py AND F = 0 THEN
   IF tempfigure(c, 10) = e THEN
    teu = teu + 1: Pic(teo, teu) = clr: F = 1: tempfigure(c, 10) = clr
   END IF
  END IF
  IF F = 0 THEN
   g = 1: h = c: i = -2
   DO
    i = i + 3
    IF i = 13 THEN i = 1: h = h - 1
    IF h = 0 THEN GOSUB DoneFilling
    IF tempfigure(h, i) = e THEN
     teo = tempfigure(h, i + 1): teu = tempfigure(h, i + 2)
     tempfigure(h, i) = clr: g = 0: Pic(teo, teu) = clr: c = h
    END IF
   LOOP UNTIL g = 0
  END IF
  c = c + 1
 LOOP

DoneFilling:
 PUT (over, up), bachold, PSET: CALL ChangePic: CALL DoMouse(over, up, 0)

END SUB

SUB FlipPic (way%)

 FOR a = 0 TO (px - 1): FOR B = 0 TO (py - 1): MoveHold(a + 1, B + 1) = POINT(150 + a, 12 + B): NEXT B, a
 IF way = 1 THEN
  c = px + 1
  FOR a = 0 TO (px - 1): c = c - 1: FOR B = 0 TO (py - 1): Pic(a + 1, B + 1) = MoveHold(c, B + 1): NEXT B, a
 ELSE
  FOR a = 0 TO (px - 1): c = py: FOR B = 0 TO (py - 1): Pic(a + 1, B + 1) = MoveHold(a + 1, c): c = c - 1: NEXT B, a
 END IF
 CALL ChangePic

END SUB

SUB Font (words$)

FontLength% = LEN(words$)

FOR i% = 1 TO FontLength%
 ct$ = MID$(words$, i%, 1)
 IF ct$ = "a" THEN DRAW "BR2G2D2ER2FU2H2BR4"
 IF ct$ = "b" THEN DRAW "D4R3EHL3U2R3FBEBR"
 IF ct$ = "c" THEN DRAW "BDD2FR2EBUBUHL2BR5"
 IF ct$ = "d" THEN DRAW "D4R3EU2HL3BR6"
 IF ct$ = "e" THEN DRAW "D4R4BHBUL3U2R4BR2"
 IF ct$ = "f" THEN DRAW "D4U2R3BUBEL4BR6"
 IF ct$ = "g" THEN DRAW "BDD2FR3U2L2BE2NL3BR2"
 IF ct$ = "h" THEN DRAW "D4U2R4D2U4BR2"
 IF ct$ = "i" THEN DRAW "BRBD4R2HU3LR2BR3"
 IF ct$ = "j" THEN DRAW "BD3DR2U4L2R4BR2"
 IF ct$ = "k" THEN DRAW "D4BR3H2E2BR3"
 IF ct$ = "l" THEN DRAW "D4R4BU4BR2"
 IF ct$ = "m" THEN DRAW "BD4U4F2E2ND4BR2"
 IF ct$ = "n" THEN DRAW "ND4F4U4BR2"
 IF ct$ = "o" THEN DRAW "BDD2FR2EU2HL2BR5"
 IF ct$ = "p" THEN DRAW "D4U2R3EHL3BR6"
 IF ct$ = "q" THEN DRAW "BDDFR2DRBU2U1HL2BR5"
 IF ct$ = "r" THEN DRAW "D4U2R3FDBU3HL3BR6"
 IF ct$ = "s" THEN DRAW "BD4R3EHL2HER3BR2"
 IF ct$ = "t" THEN DRAW "R2ND4R2BR2"
 IF ct$ = "u" THEN DRAW "D3FR2EU3BR2"
 IF ct$ = "v" THEN DRAW "D2F2E2U2BR2"
 IF ct$ = "w" THEN DRAW "D4E2F2U4BR2"
 IF ct$ = "x" THEN DRAW "F4BL4E4BR2"
 IF ct$ = "y" THEN DRAW "F2ND2E2BR2"
 IF ct$ = "z" THEN DRAW "R4G4R4BU4BR2"
 IF ct$ = "0" THEN DRAW "BD1D2FR2EU2LNG2UL2BR5"
 IF ct$ = "1" THEN DRAW "BFED4NL2R2BU4BR2"
 IF ct$ = "2" THEN DRAW "BDER2FGLG2R4BU4BR2"
 IF ct$ = "3" THEN DRAW "BDER2FGLRFGL2HBR6BU3"
 IF ct$ = "4" THEN DRAW "D2R3NRND2U2BR3"
 IF ct$ = "5" THEN DRAW "NR4D2R3FGNL3BE3BU"
 IF ct$ = "6" THEN DRAW "BR3L2GD2FR2EHNL3BE2BR"
 IF ct$ = "7" THEN DRAW "R4G2D2BE4"
 IF ct$ = "8" THEN DRAW "BRNR2GFNR2GFR2EHEHBR3"
 IF ct$ = "9" THEN DRAW "BRR2FD2GNL2BU2L2HEBR5"
 IF ct$ = "." THEN DRAW "BF2BD2RC0UC" + STR$(clr) + "BE3"
 IF ct$ = "?" THEN DRAW "BDER2FGLBD2RC0UC" + STR$(clr) + "BE3"
 IF ct$ = "!" THEN DRAW "BR2D2BD2RC0UC" + STR$(clr) + "BE3"
 IF ct$ = CHR$(34) THEN DRAW "BRDBR2UBR3"
 IF ct$ = ":" THEN DRAW "BR2BDD2BUC0R2C" + STR$(clr) + "BE2"
 IF ct$ = "'" THEN DRAW "BFEBR4"
 IF ct$ = "," THEN DRAW "BD4BREBE3BR"
 IF ct$ = "-" THEN DRAW "BD2BRR2BRBU2BR2"
 IF ct$ = "=" THEN DRAW "BF3L2BU2R2BEBR2"
 IF ct$ = "+" THEN DRAW "BD2BRED2EBE2BR"
 IF ct$ = ";" THEN DRAW "BR2BDD2GBU2C0R5C" + STR$(clr) + "BU2"
 IF ct$ = "(" THEN DRAW "BRGD2FBE4BR"
 IF ct$ = ")" THEN DRAW "BF4BLEU2HBR3"
 IF ct$ = "<" THEN DRAW "BR2G2F2BE4"
 IF ct$ = ">" THEN DRAW "BR2F2G2BE4"
 IF ct$ = "/" THEN DRAW "BD4E4BR2"
 IF ct$ = " " THEN DRAW "BR5"
NEXT i%

END SUB

SUB GetColor (wk%)

 IF wk = 1 THEN
  PUT (over, up), bachold, PSET: tclr = POINT(over, up)
  IF tclr = 0 THEN tclr = POINT(over, up - 1)
  IF tclr = 15 THEN tclr = POINT(over, up - 1)
  GET (over, up)-(over + 6, up + 9), bachold
  PUT (over, up), arrow, OR: PUT (over, up), amask, AND
 ELSEIF wk = 2 THEN
  CALL TeoTeu(teo, teu)
  tclr = Pic(teo, teu)
 END IF
 CALL ChangeColor

END SUB

SUB InputString (strng%)

 PUT (over, up), bachold, PSET
 GET (150, 12)-(149 + px, 11 + py), invhold
 CALL UpdatePic
 ON ERROR GOTO ErrorTrap
 LINE (1, 16)-(178, 33), 7, BF: LINE (5, 20)-(174, 29), 0, BF
 LINE (1, 16)-(1, 33), 15: LINE (1, 16)-(178, 16), 15
 LINE (2, 33)-(178, 33), 8: LINE (178, 16)-(178, 33), 8
 ShowFont 5, 20, "File:", 1
 IF strng = 1 THEN ShowFont 535, 20, ".awd", 3
 IF strng = 2 THEN ShowFont 535, 20, ".gif", 3
 IF strng = 3 THEN ShowFont 535, 20, ".bmp", 3
 IF strng = 4 THEN ShowFont 535, 20, ".pal", 3
 ip$ = "": id = 0: x = 55: y = 20: TimeIt 4

 DO
  key$ = INKEY$
  IF key$ <> "" THEN
   IF ASC(key$) > 32 THEN
    IF key$ <> "." THEN id = id + 1: ip$ = ip$ + key$
  END IF
  IF ASC(key$) = 8 THEN
   IF id > 0 AND id <= 8 THEN
    ShowFont x + (10 * (id - 1)), y, " ", 3
    id = id - 1: ip$ = LEFT$(ip$, id)
   END IF
   IF id > 8 THEN
    ShowFont 125, y, " ", 3
    id = id - 1: ip$ = LEFT$(ip$, id)
   END IF
  END IF
  IF id <= 8 THEN ShowFont x, y, ip$, 3
   IF id > 8 THEN
    B = 125
    FOR a = id TO id - 7 STEP -1
     ShowFont B, y, MID$(ip$, a, 1), 3: B = B - 10
    NEXT a
   END IF
  END IF
 LOOP UNTIL key$ = CHR$(13)
 IF strng < 4 THEN filname$ = ip$
 IF strng = 4 THEN palname$ = ip$
 CALL DoMouse(over, up, 0)

END SUB

SUB Invert (wk%)

 DIM pcol(0 TO 255)
 FOR a = 0 TO 255: pcol(a) = 300: NEXT a
 oo1 = 1: oo2 = px: uu1 = 1: uu2 = py
 IF selecton = 1 THEN oo1 = so1: oo2 = so2: uu1 = su1: uu2 = su2

 IF wk = 1 THEN
  CALL ReadPalette
  FOR a = oo1 TO oo2
   FOR d = uu1 TO uu2
    pc = Pic(a, d)
    IF pcol(pc) = 300 THEN
     r = cp(pc, 1): g = cp(pc, 2): B = cp(pc, 3)
     cc = 300: cl = pc
     r = 63 - r: g = 63 - g: B = 63 - B
     FOR i = 0 TO 255
      dr = ABS(cp(i, 1) - r): dg = ABS(cp(i, 2) - g): db = ABS(cp(i, 3) - B)
      IF dr + dg + db < cc THEN cc = dr + dg + db: cl = i
     NEXT i
     pcol(pc) = cl
     Pic(a, d) = pcol(pc)
    ELSE
     Pic(a, d) = pcol(pc)
    END IF
  NEXT d, a
 ELSEIF wk = 2 THEN
  GET (149 + oo1, 11 + uu1)-(149 + oo2, 11 + uu2), sh
  LINE (149 + oo1, 11 + uu1)-(149 + oo2, 11 + uu2), 15, BF
  PUT (149 + oo1, 11 + uu1), sh, PRESET
  CALL UpdatePic
 END IF
 CALL ChangePic

END SUB

SUB LoadFont

 DIM t(1 TO 10) AS INTEGER
 OnFont = 1
 OPEN "awdraw.fnt" FOR INPUT AS #1
  FOR i = 1 TO 116
   FOR a = 1 TO 10
    INPUT #1, t(1), t(2), t(3), t(4), t(5), t(6), t(7), t(8), t(9), t(10)
    FOR B = 1 TO 10
     fontt(i, a, B) = t(B)
  NEXT B, a, i
 CLOSE #1

END SUB

SUB MakeMask

 FOR a = 1 TO px
  FOR B = 1 TO py
   IF Pic(a, B) = 0 THEN Pic(a, B) = 255
 NEXT B, a
 CALL ChangePic

END SUB

SUB MenuStuff

 PUT (over, up), bachold, PSET: CALL TimeIt(4)

 IF over < 43 THEN
  LINE (0, 10)-(70, 65), 0, BF: LINE (0, 10)-(70, 65), 10, B
  ShowFont 2, 11, "New", 1: ShowFont 2, 21, "Open", 1
  ShowFont 2, 31, "SaveAs", 1
  ShowFont 2, 41, "Exit", 1: LINE (0, 52)-(70, 52), 10
  ShowFont 2, 54, "About", 1: B = 1
 END IF
 IF over > 43 AND over < 84 THEN
  LINE (43, 10)-(140, 132), 0, BF: LINE (43, 10)-(140, 132), 10, B
  ShowFont 46, 11, "Reset", 1: ShowFont 46, 21, "Load", 1
  ShowFont 46, 31, "Save", 1: ShowFont 46, 41, "SaveAs", 1
  LINE (43, 52)-(140, 52), 10: B = 2
  ShowFont 46, 54, "Redness", 1: ShowFont 46, 64, "Greenness", 1
  ShowFont 46, 74, "Blueness", 1: LINE (43, 86)-(140, 86), 10
  ShowFont 46, 88, "Grayscale", 1: ShowFont 46, 98, "Randomize", 1
  ShowFont 46, 108, "Default", 1
  LINE (43, 119)-(140, 119), 10
  ShowFont 46, 121, "Rotate", 1
 END IF
 IF over > 83 THEN
  LINE (84, 10)-(178, 56), 0, BF: LINE (84, 10)-(178, 56), 10, B
  ShowFont 87, 11, "Pixelize", 1: ShowFont 87, 21, "Add Noise", 1
  LINE (84, 31)-(178, 31), 10: ShowFont 87, 33, "Stretch", 1
  LINE (84, 43)-(178, 43), 10: B = 4
  IF grid = 1 THEN ShowFont 87, 45, "Grid Off", 1
  IF grid = 0 THEN ShowFont 87, 45, "Grid On", 1
 END IF
 GET (over, up)-(over + 6, up + 9), bachold

 DO
   o = over: u = up: CALL Mouse(up, over, button)
   CALL CheckBound(0, 312, 0, 189)
   IF o <> over OR u <> up THEN CALL DoMouse(o, u, 1)
 
   IF button = 1 THEN
    IF B = 1 THEN
    IF over > 70 OR up > 75 OR up < 11 THEN EXIT DO
    IF up > 10 AND up < 22 THEN
     B = 3: filname$ = ""
     FOR a = 1 TO 50: FOR F = 1 TO 50: Pic(a, F) = 0: NEXT F, a
    END IF
    IF up > 40 AND up < 52 THEN SYSTEM
    IF up > 20 AND up < 31 THEN CALL XLoadPic: EXIT DO
    IF up > 30 AND up < 41 THEN CALL XSavePic: EXIT DO
    IF up > 53 AND up < 66 THEN CALL AboutAWD: EXIT DO
   END IF
   IF B = 2 THEN
    IF over < 43 OR up > 132 OR over > 140 OR up < 11 THEN EXIT DO
    IF up > 10 AND up < 21 THEN GOSUB PrepareToLeave: CALL XPalLoad(0): EXIT DO
    IF up > 20 AND up < 31 THEN GOSUB PrepareToLeave: CALL XPalLoad(1): EXIT DO
    IF up > 30 AND up < 41 THEN GOSUB PrepareToLeave: CALL XWritePal(1): EXIT DO
    IF up > 40 AND up < 51 THEN GOSUB PrepareToLeave: CALL XWritePal(2): EXIT DO
    IF up > 53 AND up < 64 THEN GOSUB PrepareToLeave: CALL PalChange(1): B = 3
    IF up > 63 AND up < 74 THEN GOSUB PrepareToLeave: CALL PalChange(2): B = 3
    IF up > 73 AND up < 84 THEN GOSUB PrepareToLeave: CALL PalChange(3): B = 3
    IF up > 84 AND up < 98 THEN GOSUB PrepareToLeave: CALL PalChange(4): B = 3
    IF up > 97 AND up < 108 THEN GOSUB PrepareToLeave: CALL PalChange(5): B = 3
    IF up > 107 AND up < 118 THEN PALETTE: B = 3
    IF up > 118 AND up < 132 THEN GOSUB PrepareToLeave: CALL RotatePal: B = 3
   END IF
   IF B = 4 THEN
    IF over < 84 OR up > 56 OR over > 178 OR up < 11 THEN EXIT DO
    IF up > 10 AND up < 21 THEN GOSUB PrepareToLeave: CALL Tone(8): B = 3
    IF up > 20 AND up < 31 THEN GOSUB PrepareToLeave: CALL Tone(9): B = 3
    IF up > 30 AND up < 43 THEN GOSUB PrepareToLeave: CALL Stretch: B = 3
    IF up > 42 AND up < 57 THEN
     GOSUB PrepareToLeave: B = 3: grid = grid + 1
     IF grid > 1 THEN grid = 0
    END IF
   END IF
  END IF
  WAIT &H3DA, 8
 LOOP UNTIL B = 3
 GOTO DoneMenu

PrepareToLeave:
 PUT (over, up), bachold, PSET
 CALL SetupScreen: CALL ChangePic: CALL DoMouse(over, up, 0)
 RETURN
DoneMenu:
 PUT (over, up), bachold, PSET
 CALL SetupScreen: CALL ChangePic: CALL DoMouse(over, up, 0)
 LINE (149, 11)-(200, 62), 7, B

END SUB

SUB Mouse (up, over, button)
 DEF SEG = VARSEG(aa(0))
 POKE VARPTR(aa(4)), &H92: CALL ABSOLUTE(up, VARPTR(aa(0)))
 POKE VARPTR(aa(4)), &H91: CALL ABSOLUTE(over, VARPTR(aa(0)))
 over = over / 2
 POKE VARPTR(aa(4)), &H93: CALL ABSOLUTE(button, VARPTR(aa(0)))
END SUB

SUB MousePointer (SW)
 POKE VARPTR(aa(0)) + 1, SW
 CALL ABSOLUTE(c, VARPTR(aa(0)))
END SUB

SUB MovePic (way%)

 FOR a = 0 TO (px - 1): FOR B = 0 TO (py - 1): MoveHold(a + 1, B + 1) = POINT(150 + a, 12 + B): NEXT B, a
 IF way = 1 THEN
  FOR a = 0 TO (px - 2): FOR B = 0 TO (py - 1): Pic(a + 1, B + 1) = MoveHold(a + 2, B + 1): NEXT B, a
  FOR B = 0 TO (py - 1): Pic(px, B + 1) = MoveHold(1, B + 1): NEXT B
 ELSEIF way = 2 THEN
  FOR a = 1 TO (px - 1): FOR B = 0 TO (py - 1): Pic(a + 1, B + 1) = MoveHold(a, B + 1): NEXT B, a
  FOR B = 0 TO (py - 1): Pic(1, B + 1) = MoveHold(px, B + 1): NEXT B
 ELSEIF way = 3 THEN
  FOR a = 0 TO (px - 1): FOR B = 0 TO (py - 2): Pic(a + 1, B + 1) = MoveHold(a + 1, B + 2): NEXT B, a
  FOR a = 0 TO (px - 1): Pic(a + 1, py) = MoveHold(a + 1, 1): NEXT a
 ELSE
  FOR a = 0 TO (px - 1): FOR B = 1 TO (py - 1): Pic(a + 1, B + 1) = MoveHold(a + 1, B): NEXT B, a
  FOR a = 0 TO (px - 1): Pic(a + 1, 1) = MoveHold(a + 1, py): NEXT a
 END IF
 CALL ChangePic

END SUB

SUB PalChange (wk%)

 IF wk < 4 THEN
  PUT (over, up), bachold, PSET
  LINE (16, 20)-(146, 70), 7, BF: LINE (20, 24)-(142, 66), 0, BF
  LINE (16, 20)-(146, 20), 15: LINE (16, 20)-(16, 70), 15: but = 2
  LINE (17, 70)-(146, 70), 8: LINE (146, 70)-(146, 20), 8
  IF wk = 1 THEN ShowFont 45, 26, "Redness", 1
  IF wk = 2 THEN ShowFont 36, 26, "Greenness", 1
  IF wk = 3 THEN ShowFont 42, 26, "Blueness", 1
  ShowFont 22, 38, "Less    More", 4
  LINE (21, 36)-(61, 48), 7, B: LINE (100, 36)-(141, 48), 7, B
  ShowFont 62, 54, "Done", 3: LINE (60, 52)-(101, 63), 7, B
  CALL DoMouse(over, up, 0)

  DO
   o = over: u = up: CALL Mouse(up, over, button)
   CALL CheckBound(16, 147, 20, 70)
   IF o <> over OR u <> up THEN CALL DoMouse(o, u, 1)
  
   IF button = 1 THEN
    IF over > 99 AND up > 35 AND over < 142 AND up < 49 THEN
     FOR col% = 0 TO 255
      OUT &H3C7, col: r% = INP(&H3C9): g = INP(&H3C9): B = INP(&H3C9)
      IF wk = 1 THEN r = r + 5: but = 2: IF r > 63 THEN r = 63
      IF wk = 2 THEN g = g + 5: but = 2: IF g > 63 THEN g = 63
      IF wk = 3 THEN B = B + 5: but = 2: IF B > 63 THEN B = 63
      OUT &H3C8, col: OUT &H3C9, r: OUT &H3C9, g: OUT &H3C9, B
     NEXT col%
    END IF
    IF over > 20 AND up > 35 AND over < 62 AND up < 49 THEN
     FOR col% = 0 TO 255
      OUT &H3C7, col: r% = INP(&H3C9): g = INP(&H3C9): B = INP(&H3C9)
      IF wk = 1 THEN r = r - 5: but = 2: IF r < 0 THEN r = 0
      IF wk = 2 THEN g = g - 5: but = 2: IF g < 0 THEN g = 0
      IF wk = 3 THEN B = B - 5: but = 2: IF B < 0 THEN B = 0
      OUT &H3C8, col: OUT &H3C9, r: OUT &H3C9, g: OUT &H3C9, B
     NEXT col%
    END IF
    IF over > 59 AND up > 51 AND over < 102 AND up < 64 THEN EXIT DO
   END IF
   IF but = 2 THEN TimeIt 4: but = 0: CALL PalStuff
   WAIT &H3DA, 8
  LOOP
  CALL PalStuff: EXIT SUB
 END IF

 IF wk = 4 THEN
  FOR col% = 0 TO 255
   OUT &H3C7, col: r% = INP(&H3C9): g = INP(&H3C9): B = INP(&H3C9)
   r = (r + B + g) / 3
   OUT &H3C8, col: OUT &H3C9, r: OUT &H3C9, r: OUT &H3C9, r
  NEXT col%
  CALL PalStuff
 END IF
 IF wk = 5 THEN
  FOR col% = 0 TO 255
   r = INT(RND * 64): g = INT(RND * 64): B = INT(RND * 64)
   OUT &H3C8, col: OUT &H3C9, r: OUT &H3C9, g: OUT &H3C9, B
  NEXT col%
  CALL PalStuff
 END IF

END SUB

SUB PalStuff

 LOCATE 19, 26: PRINT "Palette"; clr; "  "
 LINE (296, 143)-(312, 151), clr, BF
 OUT &H3C7, clr: r = INP(&H3C9): g = INP(&H3C9): B = INP(&H3C9)

 IF over > 304 AND over < 312 THEN
  IF up > 157 AND up < 163 THEN IF r < 63 THEN r = r + 1
  IF up > 163 AND up < 169 THEN IF r > 0 THEN r = r - 1
  IF up > 169 AND up < 175 THEN IF g < 63 THEN g = g + 1
  IF up > 175 AND up < 181 THEN IF g > 0 THEN g = g - 1
  IF up > 181 AND up < 187 THEN IF B < 63 THEN B = B + 1
  IF up > 187 AND up < 193 THEN IF B > 0 THEN B = B - 1
 END IF

 IF r < 10 THEN spac$ = " " ELSE spac$ = ""
 ShowFont 200, 160, "R:" + RTRIM$(LTRIM$(STR$(r))) + spac$, 3
 IF g < 10 THEN spac$ = " " ELSE spac$ = ""
 ShowFont 200, 172, "G:" + RTRIM$(LTRIM$(STR$(g))) + spac$, 3
 IF B < 10 THEN spac$ = " " ELSE spac$ = ""
 ShowFont 200, 184, "B:" + RTRIM$(LTRIM$(STR$(B))) + spac$, 3

 LINE (240, 161)-(240 + 63, 168), 0, BF
 LINE (240, 161)-(240 + r, 169), 167, BF
 LINE (240, 173)-(240 + 63, 179), 0, BF
 LINE (240, 173)-(240 + g, 180), 95, BF
 LINE (240, 185)-(240 + 63, 190), 0, BF
 LINE (240, 185)-(240 + B, 191), 23, BF
 OUT &H3C8, clr: OUT &H3C9, r: OUT &H3C9, g: OUT &H3C9, B

END SUB

SUB PastePic

 PUT (over, up), bachold, PSET
 CALL TeoTeu(teo, teu): o1 = teo: u1 = teu
 dx = cx: dy = cy: tx = cx + teo: ty = cy + teu
 IF tx > px - 1 THEN dx = px - teo
 IF ty > py - 1 THEN dy = py - teu

 FOR a = 0 TO dx: FOR B = 0 TO dy
  Pic(a + teo, B + teu) = CopyHold(a + 1, B + 1)
 NEXT B, a
 CALL ChangePic: CALL DoMouse(over, up, 0)

END SUB

SUB ReadPalette

 FOR a = 0 TO 255
  OUT &H3C7, a: r = INP(&H3C9): g = INP(&H3C9): B = INP(&H3C9)
  cp(a, 1) = r: cp(a, 2) = g: cp(a, 3) = B
 NEXT a

END SUB

SUB RotatePal

 PUT (over, up), bachold, PSET
 LINE (16, 20)-(146, 70), 7, BF: LINE (20, 24)-(142, 66), 0, BF
 LINE (16, 20)-(146, 20), 15: LINE (16, 20)-(16, 70), 15: but = 2
 LINE (17, 70)-(146, 70), 8: LINE (146, 80)-(146, 20), 8
 ShowFont 30, 26, "Pal Rotate", 1
 ShowFont 32, 38, "<<<< >>>>", 3
 ShowFont 62, 54, "Okay", 2: LINE (60, 52)-(101, 64), 7, B
 GET (over, up)-(over + 6, up + 9), bachold
 PUT (over, up), arrow, OR: PUT (over, up), amask, AND

 DO
  o = over: u = up: CALL Mouse(up, over, button)
  CALL CheckBound(16, 145, 20, 80)
  IF o <> over OR u <> up THEN CALL DoMouse(o, u, 1)
  IF button = 1 THEN
   FOR a = 0 TO 255
    OUT &H3C7, a: r = INP(&H3C9): g = INP(&H3C9): B = INP(&H3C9)
    cp(a, 1) = r: cp(a, 2) = g: cp(a, 3) = B
   NEXT a
   IF over > 83 AND up > 37 AND over < 123 AND up < 49 THEN
    FOR x = 0 TO 254
     rr = cp(x, 1): gg = cp(x, 2): bb = cp(x, 3)
     OUT &H3C8, x + 1: OUT &H3C9, rr: OUT &H3C9, gg: OUT &H3C9, bb
    NEXT x
    rr = cp(255, 1): gg = cp(255, 2): bb = cp(255, 3)
    OUT &H3C8, 0: OUT &H3C9, rr: OUT &H3C9, gg: OUT &H3C9, bb
    TimeIt 3
   END IF
   IF over > 32 AND up > 37 AND over < 73 AND up < 49 THEN
    FOR x = 1 TO 255
     rr = cp(x, 1): gg = cp(x, 2): bb = cp(x, 3)
     OUT &H3C8, x - 1: OUT &H3C9, rr: OUT &H3C9, gg: OUT &H3C9, bb
    NEXT x
    rr = cp(0, 1): gg = cp(0, 2): bb = cp(0, 3)
    OUT &H3C8, 255: OUT &H3C9, rr: OUT &H3C9, gg: OUT &H3C9, bb
    TimeIt 3
   END IF
   IF over > 59 AND up > 51 AND over < 102 AND up < 65 THEN EXIT DO
  END IF
  WAIT &H3DA, 8
 LOOP

END SUB

SUB RotPic (way%)

 FOR a = 0 TO (px - 1): FOR B = 0 TO (py - 1): MoveHold(a + 1, B + 1) = POINT(150 + a, 12 + B): NEXT B, a
 IF way = 1 THEN
  c = 0
  FOR a = 0 TO (py - 1): c = c + 1: d = px: FOR B = 0 TO (px - 1): Pic(a + 1, B + 1) = MoveHold(d, c): d = d - 1: NEXT B, a
 ELSE
  c = px + 1
  FOR a = 0 TO (px - 1): c = c - 1: d = 1: FOR B = 0 TO (py - 1): Pic(a + 1, B + 1) = MoveHold(d, c): d = d + 1: NEXT B, a
 END IF
 CALL ChangePic

END SUB

SUB Selection

 CALL TeoTeu(teo, teu): o1 = teo: u1 = teu
 PUT (over, up), bachold, PSET: TimeIt 4
 GET (150, 12)-(149 + px, 11 + py), invhold
 GET (150, 12)-(149 + px, 11 + py), sh
 om = (px * 3) - 1: um = (py * 3) + 10
 over = 500: up = 500

 DO
  o = over: u = up: CALL Mouse(up, over, button)
  CALL CheckBound(0, om, 11, um)
 
  IF o <> over OR u <> up THEN
   CALL TeoTeu(teo, teu)
   ShowFont 210, 0, "X:" + STR$(teo) + " ", 2
   ShowFont 270, 0, "Y:" + STR$(teu) + " ", 2
   PUT (150, 12), invhold, PSET
   LINE (149 + o1, 11 + u1)-(149 + teo, 11 + teu), 15, B
   CALL UpdatePic: CALL ChangeGrid
  END IF
  WAIT &H3DA, 8
 LOOP UNTIL button = 1

 IF teo >= o1 THEN cx = teo - o1: so1 = o1
 IF teo < o1 THEN cx = o1 - teo: so1 = teo
 IF teu >= u1 THEN cy = teu - u1: su1 = u1
 IF teu < u1 THEN cy = u1 - teu: su1 = teu
 so2 = so1 + cx: su2 = su1 + cy: selecton = 1
 LINE (292, 18)-(298, 24), 79: LINE (292, 24)-(298, 18), 79
 PUT (150, 12), sh, PSET
 CALL UpdatePic: CALL ChangePic
 CALL DoMouse(over, up, 0)

END SUB

SUB SetupScreen
 LINE (150, 12)-(150 + 49, 12 + 49), 7, BF: LINE (0, 11)-(148, 159), 7, BF
 LINE (0, 11)-((px * 3) - 2, (py * 3) + 9), 0, BF
 LINE (43, 0)-(43, 10), 10: LINE (84, 0)-(84, 10), 10
 LINE (149, 11)-(149, 158), 7: LINE (149, 11)-(200, 11), 7
END SUB

SUB ShowFont (xx%, yy%, st$, sty)

 leng = LEN(st$)
 IF sty = 1 THEN fc = 0
 IF sty = 2 THEN fc = 48
 IF sty = 3 THEN fc = 88
 IF sty = 4 THEN fc = 120

 FOR a = 1 TO leng
  ft$ = MID$(st$, a, 1)
  IF ft$ = " " THEN ftnum = 1
  IF ft$ = CHR$(1) THEN ftnum = 2
  IF ft$ = CHR$(2) THEN ftnum = 3
  IF ft$ = CHR$(3) THEN ftnum = 4
  IF ASC(ft$) > 47 AND ASC(ft$) < 58 THEN ftnum = ASC(ft$) - 43
  IF ASC(ft$) > 64 AND ASC(ft$) < 91 THEN ftnum = ASC(ft$) - 50
  IF ASC(ft$) > 96 AND ASC(ft$) < 123 THEN ftnum = ASC(ft$) - 56
  IF ft$ = CHR$(19) THEN ftnum = 67
  IF ft$ = CHR$(33) THEN ftnum = 68
  IF ft$ = CHR$(63) THEN ftnum = 69
  IF ft$ = CHR$(168) THEN ftnum = 70
  IF ft$ = CHR$(34) THEN ftnum = 71
  IF ft$ = CHR$(39) THEN ftnum = 72
  IF ft$ = CHR$(44) THEN ftnum = 73
  IF ft$ = CHR$(46) THEN ftnum = 74
  IF ft$ = CHR$(249) THEN ftnum = 75
  IF ft$ = CHR$(254) THEN ftnum = 76
  IF ft$ = CHR$(58) THEN ftnum = 77
  IF ft$ = CHR$(59) THEN ftnum = 78
  IF ft$ = CHR$(124) THEN ftnum = 79
  IF ft$ = CHR$(123) THEN ftnum = 80
  IF ft$ = CHR$(125) THEN ftnum = 81
  IF ft$ = CHR$(40) THEN ftnum = 82
  IF ft$ = CHR$(41) THEN ftnum = 83
  IF ft$ = CHR$(91) THEN ftnum = 84
  IF ft$ = CHR$(93) THEN ftnum = 85
  IF ft$ = CHR$(239) THEN ftnum = 86
  IF ft$ = CHR$(126) THEN ftnum = 87
  IF ft$ = CHR$(35) THEN ftnum = 88
  IF ft$ = CHR$(36) THEN ftnum = 89
  IF ft$ = CHR$(37) THEN ftnum = 90
  IF ft$ = CHR$(38) THEN ftnum = 91
  IF ft$ = CHR$(64) THEN ftnum = 92
  IF ft$ = CHR$(174) THEN ftnum = 93
  IF ft$ = CHR$(175) THEN ftnum = 94
  IF ft$ = CHR$(42) THEN ftnum = 95
  IF ft$ = CHR$(43) THEN ftnum = 96
  IF ft$ = CHR$(45) THEN ftnum = 97
  IF ft$ = CHR$(47) THEN ftnum = 98
  IF ft$ = CHR$(92) THEN ftnum = 99
  IF ft$ = CHR$(60) THEN ftnum = 100
  IF ft$ = CHR$(243) THEN ftnum = 101
  IF ft$ = CHR$(61) THEN ftnum = 102
  IF ft$ = CHR$(241) THEN ftnum = 103
  IF ft$ = CHR$(247) THEN ftnum = 104
  IF ft$ = CHR$(242) THEN ftnum = 105
  IF ft$ = CHR$(62) THEN ftnum = 106
  IF ft$ = CHR$(176) THEN ftnum = 107
  IF ft$ = CHR$(177) THEN ftnum = 108
  IF ft$ = CHR$(178) THEN ftnum = 109
  IF ft$ = CHR$(219) THEN ftnum = 110
  IF ft$ = CHR$(179) THEN ftnum = 111
  IF ft$ = CHR$(191) THEN ftnum = 112
  IF ft$ = CHR$(192) THEN ftnum = 113
  IF ft$ = CHR$(196) THEN ftnum = 114
  IF ft$ = CHR$(217) THEN ftnum = 115
  IF ft$ = CHR$(218) THEN ftnum = 116
	 
  FOR B = 1 TO 10
   FOR c = 1 TO 10
    PSET ((xx + ((a - 1) * 10)) + (c - 1), yy + (B - 1)), fontt(ftnum, B, c) + fc
    IF fontt(ftnum, B, c) = 0 THEN PSET ((xx + ((a - 1) * 10)) + (c - 1), yy + (B - 1)), 0
   NEXT c
  NEXT B
 NEXT a

END SUB

SUB SizeStuff

 IF button = 1 THEN
  IF over < 305 AND up < 124 THEN IF px > 1 THEN px = px - 1
  IF over > 305 AND up < 124 THEN IF px < 50 THEN px = px + 1
  IF over < 305 AND up > 127 THEN IF py > 1 THEN py = py - 1
  IF over > 305 AND up > 127 THEN IF py < 50 THEN py = py + 1
  CALL SetupScreen: CALL ChangePic
 END IF
 IF px < 10 THEN st$ = " " ELSE st$ = ""
 ShowFont 243, 117, "X: " + LTRIM$(RTRIM$(STR$(px))) + st$, 4
 IF py < 10 THEN st$ = " " ELSE st$ = ""
 ShowFont 243, 127, "Y: " + LTRIM$(RTRIM$(STR$(py))) + st$, 4

END SUB

SUB Stretch

 PUT (over, up), bachold, PSET
 LINE (16, 20)-(146, 80), 7, BF: LINE (20, 24)-(142, 76), 0, BF
 LINE (16, 20)-(146, 20), 15: LINE (16, 20)-(16, 80), 15: but = 2
 LINE (17, 80)-(146, 80), 8: LINE (146, 80)-(146, 20), 8
 ShowFont 44, 26, "Stretch", 1
 ShowFont 22, 38, "New X:" + RTRIM$(STR$(px)), 2
 ShowFont 22, 50, "New Y:" + RTRIM$(STR$(py)), 2
 LINE (122, 41)-(126, 45), 7, BF: LINE (123, 43)-(125, 43), 32
 LINE (130, 41)-(134, 45), 7, BF: LINE (131, 43)-(133, 43), 32
 LINE (132, 42)-(132, 44), 32: LINE (122, 53)-(126, 57), 7, BF
 LINE (123, 55)-(125, 55), 32: LINE (130, 53)-(134, 57), 7, BF
 LINE (131, 55)-(133, 55), 32: LINE (132, 54)-(132, 56), 32
 ShowFont 62, 64, "Okay", 3: LINE (60, 62)-(101, 74), 7, B
 GET (over, up)-(over + 6, up + 9), bachold
 PUT (over, up), arrow, OR: PUT (over, up), amask, AND
 opx = px: opy = py

 DO
  o = over: u = up: CALL Mouse(up, over, button)
  CALL CheckBound(16, 145, 20, 80)
  IF o <> over OR u <> up THEN CALL DoMouse(o, u, 1)
 
  IF button = 1 THEN
   IF CB(121, 40, 127, 46) = 1 THEN IF px > 1 THEN px = px - 1: but = 2
   IF CB(129, 40, 135, 46) = 1 THEN IF px < 50 THEN px = px + 1: but = 2
   IF CB(121, 52, 127, 58) = 1 THEN IF py > 1 THEN py = py - 1: but = 2
   IF CB(129, 52, 135, 58) = 1 THEN IF py < 50 THEN py = py + 1: but = 2
   IF CB(59, 61, 102, 75) = 1 THEN EXIT DO
  END IF
  IF but = 2 THEN
   TimeIt 4: but = 0
   IF px < 10 THEN st$ = " " ELSE st$ = ""
   ShowFont 22, 38, "New X:" + RTRIM$(STR$(px)) + st$, 2
   IF py < 10 THEN st$ = " " ELSE st$ = ""
   ShowFont 22, 50, "New Y:" + RTRIM$(STR$(py)) + st$, 2
  END IF
  WAIT &H3DA, 8
 LOOP
 FOR a = 1 TO px: FOR B = 1 TO py: MoveHold(a, B) = 0: NEXT B, a
 a = 1
 FOR i! = 1 TO opx STEP opx / px
  B = 1
  FOR g! = 1 TO opy STEP opy / py
   MoveHold(a, B) = Pic(CINT(i!), CINT(g!)): B = B + 1
  NEXT g!
  a = a + 1
 NEXT i!
 FOR a = 1 TO px: FOR B = 1 TO py: Pic(a, B) = MoveHold(a, B): NEXT B, a
 IF px < 10 THEN st$ = " " ELSE st$ = ""
 ShowFont 243, 117, "X: " + LTRIM$(RTRIM$(STR$(px))) + st$, 4
 IF py < 10 THEN st$ = " " ELSE st$ = ""
 ShowFont 243, 127, "Y: " + LTRIM$(RTRIM$(STR$(py))) + st$, 4
 CALL SetupScreen: CALL ChangePic: selecton = 0

END SUB

SUB TeoTeu (teo, teu)
 teu = up - 11: teo = over
 DO: teu = teu + 1: LOOP UNTIL teu / 3 = INT(teu / 3)
 DO: teo = teo + 1: LOOP UNTIL teo / 3 = INT(teo / 3)
 teu = (teu / 3): teo = (teo / 3)
END SUB

SUB TimeIt (lent%)

 DEF SEG = 0
 DO UNTIL lent < 1
  CurrentTick% = PEEK(&H46C)
  DO WHILE CurrentTick% = PEEK(&H46C): LOOP
  lent = lent - 1
 LOOP

END SUB

SUB Tone (direc%)

 DIM pcol(0 TO 255)
 FOR a = 0 TO 255: pcol(a) = 300: NEXT a

 oo1 = 1: oo2 = px: uu1 = 1: uu2 = py
 IF selecton = 1 THEN oo1 = so1: oo2 = so2: uu1 = su1: uu2 = su2

 IF direc = 1 OR direc = 2 THEN
  CALL ReadPalette
  FOR a = oo1 TO oo2
   FOR d = uu1 TO uu2
    pc = Pic(a, d)
    IF pcol(pc) = 300 THEN
     r = cp(pc, 1): g = cp(pc, 2): B = cp(pc, 3)
     gh = 0: cc = 300: cl = pc
     IF direc = 1 THEN
       IF r < 63 THEN gh = 1
       IF g < 63 THEN gh = 1
       IF B < 63 THEN gh = 1
       IF gh = 1 THEN
	vv = 0
	IF r > g AND r > B THEN vv = 1: r = r + 4: IF g > B THEN g = g + 2: B = B + 1 ELSE B = B + 2: g = g + 1
	IF g > B AND g > r THEN vv = 1: g = g + 4: IF r > B THEN r = r + 2: B = B + 1 ELSE B = B + 2: r = r + 1
	IF B > g AND B > r THEN vv = 1: B = B + 4: IF g > r THEN g = g + 2: r = r + 1 ELSE r = r + 2: g = g + 1
	IF vv = 0 THEN g = g + 2: B = B + 2: r = r + 2
	IF r > 63 THEN r = 63
	IF g > 63 THEN g = 63
	IF B > 63 THEN B = 63
	FOR i = 0 TO 255
	 dr = cp(i, 1): dg = cp(i, 2): db = cp(i, 3)
	 IF dr >= r OR dg >= g OR db >= B THEN
	  IF dr >= r THEN dr = dr - r ELSE dr = r - dr
	  IF dg >= g THEN dg = dg - g ELSE dg = g - dg
	  IF db >= B THEN db = db - B ELSE db = B - db
	  dt = dr + dg + db
	  IF dt <= cc THEN cc = dt: cl = i
	 END IF
	NEXT i
	pcol(pc) = cl: Pic(a, d) = pcol(pc)
       ELSE
	pcol(pc) = pc
       END IF
     END IF
     IF direc = 2 THEN
      IF r > 0 THEN gh = 1
      IF g > 0 THEN gh = 1
      IF B > 0 THEN gh = 1
      IF gh = 1 THEN
       vv = 0
       IF r > g AND r > B THEN vv = 1: r = r - 4: IF g > B THEN g = g - 2: B = B - 1 ELSE B = B - 2: g = g - 1
       IF g > B AND g > r THEN vv = 1: g = g - 4: IF r > B THEN r = r - 2: B = B - 1 ELSE B = B - 2: r = r - 1
       IF B > g AND B > r THEN vv = 1: B = B - 4: IF r > g THEN r = r - 2: g = g - 1 ELSE g = g - 2: r = r - 1
       IF vv = 0 THEN g = g - 2: B = B - 2: r = r - 2
       IF r < 0 THEN r = 0
       IF g < 0 THEN g = 0
       IF B < 0 THEN B = 0
       FOR i = 0 TO 255
	dr = cp(i, 1): dg = cp(i, 2): db = cp(i, 3)
	IF dr <= r AND dg <= g AND db <= B THEN
	 dr = r - dr: dg = g - dg: db = B - db: dt = dr + dg + db
	 IF dt < cc THEN cc = dt: cl = i
	END IF
       NEXT i
       pcol(pc) = cl: Pic(a, d) = pcol(pc)
      ELSE
       pcol(pc) = pc
      END IF
     END IF
    ELSE
     Pic(a, d) = pcol(pc)
    END IF
  NEXT d, a
 END IF

 IF direc = 3 OR direc = 4 THEN
  CALL ReadPalette
  FOR x = 149 + oo1 TO 149 + oo2
   FOR y = 11 + uu1 TO 11 + uu2
    pc = Pic(x - 149, y - 11): cl = POINT(x, y): tc = 1
    tr = cp(cl, 1): tg = cp(cl, 2): tb = cp(cl, 3)
    IF y <> 11 + uu2 THEN
     cl = POINT(x, y + 1): tc = tc + 1
     tr = tr + cp(cl, 1): tg = tg + cp(cl, 2): tb = tb + cp(cl, 3)
    END IF
    IF x <> 149 + oo2 THEN
     cl = POINT(x + 1, y): tc = tc + 1
     tr = tr + cp(cl, 1): tg = tg + cp(cl, 2): tb = tb + cp(cl, 3)
    END IF
    IF y <> 11 + uu1 THEN
     cl = POINT(x, y - 1): tc = tc + 1
     tr = tr + cp(cl, 1): tg = tg + cp(cl, 2): tb = tb + cp(cl, 3)
    END IF
    IF x <> 149 + oo1 THEN
     cl = POINT(x - 1, y): tc = tc + 1
     tr = tr + cp(cl, 1): tg = tg + cp(cl, 2): tb = tb + cp(cl, 3)
    END IF
    tr = tr / tc: tg = tg / tc: tb = tb / tc: cc = 200: cl = pc: i = 0
    IF direc = 3 THEN
     DO
      dr = cp(i, 1): dg = cp(i, 2): db = cp(i, 3)
      dr = ABS(tr - dr): dg = ABS(tg - dg): db = ABS(tb - db)
      IF dr + dg + db < cc THEN cc = dr + dg + db: cl = i
      i = i + 1
     LOOP UNTIL cc < 4 OR i = 256
    END IF
    IF direc = 4 THEN
     tc = tr + tg + tb
     IF tc < 80 THEN
      DO
       dr = cp(i, 1): dg = cp(i, 2): db = cp(i, 3)
       IF dr < tr AND dg < tg AND db < tb THEN
	dr = tr - dr: dg = tg - dg: db = tb - db: dt = dr + dg + db
	IF dt < cc THEN cc = dt: cl = i
       END IF
       i = i + 1
      LOOP UNTIL cc < 4 OR i = 256
     END IF
    END IF
    PSET (x, y), cl
  NEXT y, x
 END IF

 IF direc = 5 THEN
  FOR dd = 1 TO 2
   FOR x = oo1 TO oo2
    FOR y = uu1 TO uu2
     col = Pic(x, y): c = 1
     IF y <> uu2 THEN col = col + Pic(x, y + 1): c = c + 1
     IF x <> oo2 THEN col = col + Pic(x + 1, y): c = c + 1
     IF x <> oo2 AND y <> uu2 THEN col = col + Pic(x + 1, y + 1): c = c + 1
     IF y <> uu1 THEN col = col + Pic(x, y - 1): c = c + 1
     IF x <> oo1 THEN col = col + Pic(x - 1, y): c = c + 1
     IF x <> oo1 AND y <> uu1 THEN col = col + Pic(x - 1, y - 1): c = c + 1
     IF x <> oo2 AND y <> uu1 THEN col = col + Pic(x + 1, y - 1): c = c + 1
     IF x <> oo1 AND y <> uu2 THEN col = col + Pic(x - 1, y + 1): c = c + 1
     col = col / c
     Pic(x, y) = INT(col)
   NEXT y, x
  NEXT dd
 END IF

 IF direc = 6 OR direc = 10 THEN
  x = 149 + oo1: y = 11 + uu1: x2 = 149 + oo2: y2 = 11 + uu2
  FOR i = 0 TO ((((oo2 - oo1) + 1) * ((uu2 - uu1) + 1)) * 1.5)
   xx = RND * (x2 - x)
   yy = RND * (y2 - y - 1)
   ttx = POINT(xx + x, yy + y)
   IF direc = 6 THEN PSET (xx + x + RND * 2 - 1, yy + y + RND * 2 - 1), ttx
   IF direc = 10 THEN PSET (xx + x, yy + y + 1), ttx
  NEXT i
 END IF

 IF direc = 7 OR direc = 8 OR direc = 9 THEN
  stepe = 1
  IF direc = 8 THEN stepe = 2
  FOR xx = 149 + oo1 TO 149 + oo2 STEP stepe
   FOR yy = 11 + uu1 TO 11 + uu2 STEP stepe
    IF direc = 7 THEN
     ttx = Pic(xx - 149, yy - 11): ttx = ttx + INT(RND * 5)
     IF ttx > 255 THEN ttx = 255
     PSET (xx, yy), ttx
    END IF
    IF direc = 8 THEN LINE (xx, yy)-(xx + 1, yy + 1), POINT(xx, yy), BF
    IF direc = 9 THEN
     doit = INT(RND * 9) + 1
     IF doit = 6 THEN docol = INT(RND * 256): PSET (xx, yy), docol
    END IF
   NEXT yy
  NEXT xx
 END IF

 IF direc <> 1 AND direc <> 2 AND direc <> 5 THEN CALL UpdatePic
 LINE (149, 11)-(200, 62), 7, B: CALL ChangePic

END SUB

SUB Undo

 PUT (over, up), bachold, PSET: PUT (150, 12), invhold, PSET
 CALL UpdatePic: CALL ChangePic
 IF selecton = 1 THEN GET (150, 12)-(149 + px, 11 + py), sh
 CALL DoMouse(over, up, 0)

END SUB

SUB UpdateBrush

 PUT (over, up), bachold, PSET

 IF balias = 2 THEN balias = 0
 IF balias = 0 THEN LINE (212, 88)-(220, 90), 0, BF
 IF balias = 1 THEN LINE (212, 88)-(220, 90), 15, BF

 LINE (162, 80)-(166, 87), 0, B: LINE (167, 80)-(172, 87), 0, B
 LINE (173, 80)-(179, 87), 0, B: LINE (179, 80)-(186, 87), 0, B
 LINE (187, 80)-(195, 88), 0, B: LINE (162, 95)-(169, 102), 0, B
 LINE (169, 95)-(176, 102), 0, B: LINE (176, 95)-(183, 102), 0, B
 LINE (183, 95)-(190, 102), 0, B: LINE (190, 95)-(194, 102), 0, B

 IF brush = 1 THEN LINE (162, 80)-(166, 87), 14, B
 IF brush = 2 THEN LINE (167, 80)-(172, 87), 14, B
 IF brush = 3 THEN LINE (173, 80)-(179, 87), 14, B
 IF brush = 4 THEN LINE (179, 80)-(186, 87), 14, B
 IF brush = 5 THEN LINE (187, 80)-(195, 88), 14, B

 IF shape = 1 THEN LINE (162, 95)-(169, 102), 14, B
 IF shape = 2 THEN LINE (169, 95)-(176, 102), 14, B
 IF shape = 3 THEN LINE (176, 95)-(183, 102), 14, B
 IF shape = 4 THEN LINE (183, 95)-(190, 102), 14, B
 IF shape = 5 THEN LINE (190, 95)-(194, 102), 14, B
 CALL DoMouse(over, up, 0)

END SUB

SUB UpdatePic
 FOR a = 1 TO px
  FOR B = 1 TO py
   Pic(a, B) = POINT(149 + a, 11 + B)
 NEXT B, a
END SUB

SUB UpdatePtStatus

 PUT (over, up), bachold, PSET
 FOR a = 1 TO 12
  IF a = 1 THEN u1 = 105: u2 = 115: o1 = 162: o2 = 194
  IF a = 2 THEN u1 = 118: u2 = 137: o1 = 162: o2 = 194
  IF a = 3 THEN u1 = 140: u2 = 150: o1 = 162: o2 = 194
  IF a = 4 THEN u1 = 153: u2 = 161: o1 = 162: o2 = 177
  IF a = 5 THEN u1 = 163: u2 = 172: o1 = 162: o2 = 171
  IF a = 6 THEN u1 = 163: u2 = 172: o1 = 173: o2 = 183
  IF a = 7 THEN u1 = 163: u2 = 172: o1 = 185: o2 = 194
  IF a = 8 THEN u1 = 175: u2 = 183: o1 = 162: o2 = 194
  IF a = 9 THEN u1 = 185: u2 = 193: o1 = 162: o2 = 194
  IF a = 10 THEN u1 = 153: u2 = 161: o1 = 179: o2 = 194
  IF a = 11 THEN u1 = 17: u2 = 25: o1 = 254: o2 = 286
  IF a = 12 THEN u1 = 27: u2 = 35: o1 = 260: o2 = 292
  LINE (o1, u1)-(o2 - 1, u1), 15: LINE (o1, u1)-(o1, u2), 15
  LINE (o2, u1)-(o2, u2), 8: LINE (o1 + 1, u2)-(o2, u2), 8
 NEXT a
 LINE (292, 18)-(298, 24), 0: LINE (292, 24)-(298, 18), 0

 IF PointType <> 11 THEN selecton = 0
 IF PointType = 1 THEN u1 = 105: u2 = 115: o1 = 162: o2 = 194
 IF PointType = 2 THEN u1 = 118: u2 = 137: o1 = 162: o2 = 194
 IF PointType = 3 THEN u1 = 140: u2 = 150: o1 = 162: o2 = 194
 IF PointType = 4 THEN u1 = 153: u2 = 161: o1 = 162: o2 = 177
 IF PointType = 5 THEN u1 = 163: u2 = 172: o1 = 162: o2 = 171
 IF PointType = 6 THEN u1 = 163: u2 = 172: o1 = 173: o2 = 183
 IF PointType = 7 THEN u1 = 163: u2 = 172: o1 = 185: o2 = 194
 IF PointType = 8 THEN u1 = 175: u2 = 183: o1 = 162: o2 = 194
 IF PointType = 9 THEN u1 = 185: u2 = 193: o1 = 162: o2 = 194
 IF PointType = 10 THEN u1 = 153: u2 = 161: o1 = 179: o2 = 194
 IF PointType = 11 THEN
  u1 = 17: u2 = 25: o1 = 254: o2 = 286
  IF selecton = 1 THEN LINE (292, 18)-(298, 24), 79: LINE (292, 24)-(298, 18), 79
 END IF
 IF PointType = 12 THEN u1 = 27: u2 = 35: o1 = 260: o2 = 292

 LINE (o1, u1)-(o2 - 1, u1), 8: LINE (o1, u1)-(o1, u2), 8
 LINE (o2, u1)-(o2, u2), 15: LINE (o1 + 1, u2)-(o2, u2), 15
 CALL DoMouse(over, up, 0)

END SUB

SUB XBufferWrite (a) STATIC

 IF OAddress = OEndAddress THEN
  PUT giffile, , OutBuffer$: OAddress = OStartAddress
 END IF
 POKE OAddress, a: OAddress = OAddress + 1

END SUB

SUB XDrawBMP8 (Pic$, x%, y%)

BufferMax% = 10000
OPEN Pic$ FOR INPUT AS #1: CLOSE #1
OPEN Pic$ FOR BINARY AS #1
 FOR a = 1 TO 50: FOR B = 1 TO 50: Pic(a, B) = 0: NEXT B, a
 GET #1, 19, BMPWidth%: GET #1, 23, BMPHeight%

 IF BMPWidth% / 4 <> BMPWidth% \ 4 THEN PadBytes% = 4 - (BMPWidth% MOD 4)
 a$ = SPACE$(1024): GET #1, 55, a$
 FOR i% = 0 TO 255
  Blue% = ASC(MID$(a$, i% * 4 + 1, 1)) \ 4
  Green% = ASC(MID$(a$, i% * 4 + 2, 1)) \ 4
  Red% = ASC(MID$(a$, i% * 4 + 3, 1)) \ 4
  OUT &H3C7, i%: OUT &H3C8, i%
  OUT &H3C9, Red%: OUT &H3C9, Green%: OUT &H3C9, Blue%
 NEXT i%
 N& = 1079: a% = BufferMax%
 a% = a% - (BufferMax% MOD (BMPWidth% + PadBytes%))
 B% = a% \ (BMPWidth% + PadBytes%) - 1
 a$ = SPACE$(a%): K% = BMPHeight% - 1
 DO
  DO WHILE K% - B% > (199 - y%)
   GET #1, N&, a$: N& = N& + a%: K% = K% - B%
  LOOP
  GET #1, N&, a$
  FOR i% = 0 TO B%
   FOR J% = 0 TO (BMPWidth% - 1)
    c% = ASC(MID$(a$, i% * (BMPWidth% + PadBytes%) + J% + 1, 1))
    o1 = J% + x%: u1 = K% + y%
    IF o1 > 200 THEN o1 = 200
    IF u1 > 62 THEN u1 = 62
    IF J% < (320 - x%) AND K% < (200 - y%) THEN PSET (o1, u1), c%
   NEXT J%
   K% = K% - 1
   IF K% < 0 THEN EXIT FOR
  NEXT i%
  N& = N& + a%
 LOOP UNTIL K% < 0
CLOSE #1

END SUB

FUNCTION XGetByte STATIC

 XGetByte = POINT(x, y): x = x + 1
 IF x > MaxX THEN
  LINE (Minx, y)-(MaxX, y), 0
  x = Minx: y = y + 1
  IF y > MaxY THEN Done = TRUE
 END IF

END FUNCTION

SUB XLoadGif (File$)

DIM byte AS STRING * 1
DIM Prefix(3095), Suffix(3095), OutStack(3095), shiftout(8)
DIM Ybase AS LONG, powersof2(11) AS LONG, WorkCode AS LONG

FOR a = 0 TO 7: shiftout(8 - a) = 2 ^ a: NEXT a
FOR a = 0 TO 11: powersof2(a) = 2 ^ a: NEXT a
DEF SEG = &HA000: giffile = FREEFILE

OPEN File$ FOR INPUT AS #giffile: CLOSE #giffile
OPEN File$ FOR BINARY AS #giffile
 File$ = "      ": GET #giffile, , File$
 IF File$ <> "GIF87a" THEN GOSUB LeaveProc
 GET #giffile, , TotalX: GET #giffile, , TotalY
 GOSUB GetByte: NumColors = 2 ^ ((a AND 7) + 1): NoPalette = (a AND 128) = 0
 GOSUB GetByte: Background = a: GOSUB GetByte: IF a <> 0 THEN GOSUB LeaveProc
 IF NoPalette = 0 THEN P$ = SPACE$(NumColors * 3): GET #giffile, , P$
 DO
  GOSUB GetByte
  IF a = 44 THEN EXIT DO
  IF a <> 33 THEN GOSUB LeaveProc
  GOSUB GetByte
  DO
   GOSUB GetByte: File$ = SPACE$(a): GET #giffile, , File$
  LOOP UNTIL a = 0
 LOOP
 GET #giffile, , XStart: GET #giffile, , YStart
 GET #giffile, , XLength: GET #giffile, , YLength
 XStart = 150: YStart = 12
 XEnd = XLength + 150: YEnd = YLength + 12
 x = 150: y = 12: Ybase = y * 320&

 GOSUB GetByte
 IF a AND 128 THEN GOSUB LeaveProc
 Interlaced = a AND 64: PassNumber = 0: PassStep = 8
 GOSUB GetByte: ClearCode = 2 ^ a: EOSCode = ClearCode + 1
 FirstCode = ClearCode + 2: NextCode = FirstCode
 StartCodeSize = a + 1: CodeSize = StartCodeSize
 StartMaxCode = 2 ^ (a + 1) - 1: MaxCode = StartMaxCode
 BitsIn = 0: BlockSize = 0: BlockPointer = 1
 IF NoPalette = 0 THEN
  OUT &H3C7, 0: OUT &H3C8, 0
  FOR a = 1 TO NumColors * 3: OUT &H3C9, ASC(MID$(P$, a, 1)) \ 4: NEXT a
 END IF

 DO
  GOSUB GetCode
  IF Code <> EOSCode THEN
   IF Code = ClearCode THEN
    NextCode = FirstCode: CodeSize = StartCodeSize
    MaxCode = StartMaxCode: GOSUB GetCode
    CurCode = Code: LastCode = Code: LastPixel = Code
    IF x < 200 THEN POKE x + Ybase, LastPixel
    x = x + 1: IF x = XEnd THEN GOSUB NextScanLine
   ELSE
    CurCode = Code: StackPointer = 0
    IF Code > NextCode THEN EXIT DO
    IF Code = NextCode THEN
     CurCode = LastCode
     OutStack(StackPointer) = LastPixel
     StackPointer = StackPointer + 1
    END IF
    DO WHILE CurCode >= FirstCode
     OutStack(StackPointer) = Suffix(CurCode)
     StackPointer = StackPointer + 1
     CurCode = Prefix(CurCode)
    LOOP
    LastPixel = CurCode
    IF x < 200 THEN POKE x + Ybase, LastPixel
    x = x + 1: IF x = XEnd THEN GOSUB NextScanLine
    FOR a = StackPointer - 1 TO 0 STEP -1
     IF x < 200 THEN POKE x + Ybase, OutStack(a)
     x = x + 1: IF x = XEnd THEN GOSUB NextScanLine
    NEXT a
    IF NextCode < 4096 THEN
     Prefix(NextCode) = LastCode
     Suffix(NextCode) = LastPixel
     NextCode = NextCode + 1
     IF NextCode > MaxCode AND CodeSize < 12 THEN
      CodeSize = CodeSize + 1: MaxCode = MaxCode * 2 + 1
     END IF
    END IF
    LastCode = Code
   END IF
 END IF
LOOP UNTIL DoneFlag OR Code = EOSCode
GOTO LeaveProc

GetByte:
 File$ = " "
 GET #giffile, , File$
 a = ASC(File$)
RETURN

NextScanLine:
 IF Interlaced THEN
  y = y + PassStep
  IF y >= YEnd THEN
   PassNumber = PassNumber + 1
   SELECT CASE PassNumber
    CASE 1: y = 4: PassStep = 8
    CASE 2: y = 2: PassStep = 4
    CASE 3: y = 1: PassStep = 2
   END SELECT
  END IF
 ELSE
  y = y + 1
 END IF
 x = 150: Ybase = y * 320&: DoneFlag = y > 61
RETURN
GetCode:
 IF BitsIn = 0 THEN GOSUB ReadBufferedByte: LastChar = a: BitsIn = 8
 WorkCode = LastChar \ shiftout(BitsIn)
 DO WHILE CodeSize > BitsIn
  GOSUB ReadBufferedByte: LastChar = a
  WorkCode = WorkCode OR LastChar * powersof2(BitsIn)
  BitsIn = BitsIn + 8
 LOOP
 BitsIn = BitsIn - CodeSize
 Code = WorkCode AND MaxCode
RETURN
ReadBufferedByte:
 IF BlockPointer > BlockSize THEN
  GOSUB GetByte: BlockSize = a
  File$ = SPACE$(BlockSize): GET #giffile, , File$
  BlockPointer = 1
 END IF
 a = ASC(MID$(File$, BlockPointer, 1)): BlockPointer = BlockPointer + 1
RETURN
LeaveProc:
CLOSE

END SUB

SUB XLoadPic

 PUT (over, up), bachold, PSET
 LINE (16, 20)-(146, 80), 7, BF: LINE (20, 24)-(142, 76), 0, BF
 LINE (16, 20)-(146, 20), 15: LINE (16, 20)-(16, 80), 15: but = 2
 LINE (17, 80)-(146, 80), 8: LINE (146, 80)-(146, 20), 8
 ShowFont 58, 26, "Load:", 1: ShowFont 54, 36, "Binary", 2
 ShowFont 68, 46, "Gif", 2: ShowFont 68, 56, "Bmp", 2: st = 0
 ShowFont 54, 66, "Cancel", 3: GET (over, up)-(over + 6, up + 9), bachold
 PUT (over, up), arrow, OR: PUT (over, up), amask, AND: TimeIt 4

 DO
  o = over: u = up: CALL Mouse(up, over, button)
  CALL CheckBound(16, 145, 20, 80)
  IF o <> over OR u <> up THEN CALL DoMouse(o, u, 1)
  IF button = 1 THEN
   IF up > 35 AND up < 46 THEN st = 1: EXIT DO
   IF up > 45 AND up < 56 THEN st = 2: EXIT DO
   IF up > 55 AND up < 66 THEN st = 3: EXIT DO
   IF up > 65 THEN GOSUB DoneLoading
  END IF
  WAIT &H3DA, 8
 LOOP

 IF st = 1 THEN filname$ = ZDirBox$("C:\", "*.awd")
 IF st = 2 THEN filname$ = ZDirBox$("C:\", "*.gif")
 IF st = 3 THEN filname$ = ZDirBox$("C:\", "*.bmp")

 DEF SEG = &HA000: BLOAD "awdraw.dat", 0
 ShowFont 0, 0, "File Pal Image", 1
 GET (over, up)-(over + 6, up + 9), bachold
 CALL ChangeColor: CALL UpdateBrush: CALL UpdatePtStatus
 PUT (over, up), bachold, PSET
 button = 0: CALL SizeStuff: TimeIt 2
 IF filname$ = "" THEN GOTO DoneLoading

 LINE (150, 12)-(199, 61), 0, BF
 FOR a = 1 TO 50: FOR B = 1 TO 50: Pic(a, B) = 0: NEXT B, a
 IF st = 1 THEN
  ff = FREEFILE
  OPEN filname$ FOR INPUT AS ff: CLOSE ff
  OPEN filname$ FOR BINARY AS ff
   GET ff, , xx: GET ff, , yy
   lb = LBOUND(invhold)
   DEF SEG = VARSEG(invhold(lb))
   ptr& = VARPTR(invhold(lb))
   pline$ = SPACE$((xx * yy) + 4)
   GET ff, , pline$
   FOR aa = 1 TO ((xx * yy) + 4)
    pl = ASC(MID$(pline$, aa, 1))
    POKE ptr&, pl
    ptr& = ptr& + 1
   NEXT aa
  CLOSE ff
  px = xx: py = yy: CALL SizeStuff
  PUT (150, 12), invhold, PSET
 ELSEIF st = 2 THEN
  CALL XLoadGif(filname$)
  px = 50: py = 50
 ELSE
  CALL XDrawBMP8(filname$, 150, 12)
  px = 50: py = 50
 END IF
 CALL UpdatePic: CALL SetupScreen: CALL ChangePic

DoneLoading:
 GET (over, up)-(over + 6, up + 9), bachold

END SUB

FUNCTION XLongToString$ (L&)

 B4% = L& \ 16777216: L& = L& - B4% * 16777216
 B3% = L& \ 65536: L& = L& - B3% * 65536
 B2% = L& \ 256: L& = L& - B2% * 256: B1% = L&
 XLongToString$ = CHR$(B1%) + CHR$(B2%) + CHR$(B3%) + CHR$(B4%)

END FUNCTION

SUB XMakeGIF (a$, ScreenX, ScreenY, XStart, YStart, XEnd, YEnd, NumColors, AdaptorType)

 CONST Table.Size = 2000
 DIM Prefix(Table.Size - 1), Suffix(Table.Size - 1), Code(Table.Size - 1)
 RESTORE ShiftTable
 FOR a = 0 TO 7: READ Shift(a): NEXT
 Minx = XStart: MinY = YStart
 MaxX = XEnd: MaxY = YEnd
 giffile = FREEFILE
 OPEN a$ FOR BINARY AS giffile
  B$ = "GIF87a": PUT giffile, , B$
  BitsPixel = 8: StartSize = 9: StartCode = 256
  StartMax = 512: ColorBits = 6
  PUT giffile, , ScreenX: PUT giffile, , ScreenY
  a = 128 + (ColorBits - 1) * 16 + (BitsPixel - 1)
  PUT giffile, , a
  a$ = CHR$(0): PUT giffile, , a$
  OUT &H3C7, 0
  FOR a = 0 TO NumColors - 1
   r = (INP(&H3C9) * 65280) \ 16128
   g = (INP(&H3C9) * 65280) \ 16128
   B = (INP(&H3C9) * 65280) \ 16128
   a$ = CHR$(r): PUT giffile, , a$
   a$ = CHR$(g): PUT giffile, , a$
   a$ = CHR$(B): PUT giffile, , a$
  NEXT
  a$ = ",": PUT giffile, , a$
  PUT giffile, , Minx: PUT giffile, , MinY
  ImageWidth = (MaxX - Minx + 1): ImageHeight = (MaxY - MinY + 1)
  PUT giffile, , ImageWidth: PUT giffile, , ImageHeight
  a$ = CHR$(BitsPixel - 1): PUT giffile, , a$
  a$ = CHR$(StartSize - 1): PUT giffile, , a$
  CurrentBit = 0: Char& = 0
  MaxCode = StartMax: CodeSize = StartSize
  ClearCode = StartCode: EOFCode = StartCode + 1
  StartCode = StartCode + 2: NextCode = StartCode
  OutBuffer$ = STRING$(5000, 32): a& = SADD(OutBuffer$)
  a& = a& - 65536 * (a& < 0)
  Oseg = VARSEG(OutBuffer$) + (a& \ 16)
  OAddress = a& AND 15
  OEndAddress = OAddress + 5000: OStartAddress = OAddress
  DEF SEG = Oseg

  GOSUB ClearTree
  XPutCode ClearCode
  x = XStart: y = YStart: Prefix = XGetByte: Done = FALSE
  DO
   DO
    IF Done THEN
     XPutCode Prefix: XPutCode EOFCode
     IF CurrentBit <> 0 THEN XPutCode 0
     XPutByte 0
     OutBuffer$ = LEFT$(OutBuffer$, OAddress - OStartAddress)
     PUT giffile, , OutBuffer$
     a$ = ";" + STRING$(8, &H1A): PUT giffile, , a$
     a$ = CHR$(255 - BlockLength): PUT giffile, LastLoc&, a$
     CLOSE giffile
     EXIT SUB
    ELSE
     Suffix = XGetByte
     GOSUB Hash
     IF Found = TRUE THEN Prefix = Code(Index)
    END IF
   LOOP WHILE Found
   XPutCode Prefix: Prefix(Index) = Prefix
   Suffix(Index) = Suffix: Code(Index) = NextCode
   Prefix = Suffix: NextCode = NextCode + 1
   IF NextCode = MaxCode + 1 THEN
    MaxCode = MaxCode * 2
    IF CodeSize = 12 THEN
     XPutCode ClearCode
     GOSUB ClearTree
     NextCode = StartCode
     CodeSize = StartSize
     MaxCode = StartMax
    ELSE
     CodeSize = CodeSize + 1
    END IF
  END IF
 LOOP

ClearTree:
 FOR a = 0 TO Table.Size - 1
  Prefix(a) = -1: Suffix(a) = -1: Code(a) = -1
 NEXT
RETURN

Hash:
 Index = ((Prefix * 256&) XOR Suffix) MOD Table.Size
 IF Index = 0 THEN Offset = 1 ELSE Offset = Table.Size - Index
 DO
  IF Code(Index) = -1 THEN
   Found = FALSE
   RETURN
  ELSEIF Prefix(Index) = Prefix AND Suffix(Index) = Suffix THEN
   Found = TRUE
   RETURN
  ELSE
   Index = Index - Offset
   IF Index < 0 THEN Index = Index + Table.Size
  END IF
 LOOP

END SUB

SUB XPalLoad (wk%)

 IF wk = 0 THEN palname$ = "awdraw.pal"
 IF wk = 1 THEN
  palname$ = ZDirBox$("C:\", "*.pal")
  DEF SEG = &HA000: BLOAD "awdraw.dat", 0
  ShowFont 0, 0, "File Pal Image", 1
  GET (over, up)-(over + 6, up + 9), bachold
  CALL ChangeColor: CALL UpdateBrush: CALL UpdatePtStatus
  PUT (over, up), bachold, PSET
  button = 0: CALL SizeStuff: TimeIt 2
  IF palname$ = "" THEN GOTO PDoneLoading
 END IF

 DIM byte AS STRING * 1
 OPEN palname$ FOR INPUT AS #1: CLOSE #1
 OPEN palname$ FOR BINARY AS #1
  FOR Att% = 0 TO 255
   OUT &H3C8, Att%
   FOR RedGreenAndBlue% = 1 TO 3
    GET #1, , byte
    Valew% = ASC(byte)
    OUT &H3C9, Valew%
   NEXT RedGreenAndBlue%
  NEXT Att%
 CLOSE #1
 CALL PalStuff
PDoneLoading:

END SUB

SUB XPutByte (a) STATIC

 BlockLength = BlockLength - 1
 IF BlockLength <= 0 THEN
  BlockLength = 255
  LastLoc& = LOC(1) + 1 + (OAddress - OStartAddress)
  XBufferWrite 255
 END IF
 XBufferWrite a

END SUB

SUB XPutCode (a) STATIC

 Char& = Char& + a * Shift(CurrentBit)
 CurrentBit = CurrentBit + CodeSize
 DO WHILE CurrentBit > 7
  XPutByte Char& AND 255
  Char& = Char& \ 256
  CurrentBit = CurrentBit - 8
 LOOP

END SUB

SUB XSaveBMP8 (Pic$, X1%, Y1%, x2%, y2%)

BMPWidth% = x2% - X1% + 1: BMPHeight% = y2% - Y1% + 1
IF BMPWidth% / 4 <> BMPWidth% \ 4 THEN PadBytes% = 4 - (BMPWidth% MOD 4)
OPEN Pic$ FOR BINARY AS #1
 Buffer$ = "BM"
 L& = (BMPWidth% + PadBytes%) * BMPHeight% + 1078
 Buffer$ = Buffer$ + XLongToString$(L&)
 Buffer$ = Buffer$ + CHR$(0) + CHR$(0)
 Buffer$ = Buffer$ + CHR$(0) + CHR$(0)
 Buffer$ = Buffer$ + XLongToString$(1078)
 Buffer$ = Buffer$ + XLongToString$(40)
 L& = BMPWidth%
 Buffer$ = Buffer$ + XLongToString$(L&)
 L& = BMPHeight%
 Buffer$ = Buffer$ + XLongToString$(L&)
 Buffer$ = Buffer$ + CHR$(1) + CHR$(0)
 Buffer$ = Buffer$ + CHR$(8) + CHR$(0)
 Buffer$ = Buffer$ + XLongToString$(0)
 L& = (BMPWidth% + PadBytes%) * BMPHeight%
 Buffer$ = Buffer$ + XLongToString$(L&)
 Buffer$ = Buffer$ + XLongToString$(0)
 Buffer$ = Buffer$ + XLongToString$(0)
 Buffer$ = Buffer$ + XLongToString$(256)
 Buffer$ = Buffer$ + XLongToString$(256)
 PUT #1, 1, Buffer$
 Buffer$ = ""
 FOR i% = 0 TO 255
  OUT &H3C7, i%: Red% = INP(&H3C9): Green% = INP(&H3C9): Blue% = INP(&H3C9)
  Buffer$ = Buffer$ + CHR$(Blue% * 4)
  Buffer$ = Buffer$ + CHR$(Green% * 4)
  Buffer$ = Buffer$ + CHR$(Red% * 4)
  Buffer$ = Buffer$ + CHR$(0)
 NEXT i%
 PUT #1, , Buffer$
 FOR i% = (BMPHeight% - 1) TO 0 STEP -1
  Buffer$ = ""
  FOR J% = 0 TO (BMPWidth% - 1)
   Buffer$ = Buffer$ + CHR$(POINT(X1% + J%, Y1% + i%))
  NEXT J%
  IF PadBytes% > 0 THEN
   FOR J% = 1 TO PadBytes%
    Buffer$ = Buffer$ + CHR$(0)
   NEXT J%
  END IF
  PUT #1, , Buffer$
 NEXT i%
CLOSE #1

END SUB

SUB XSavePic

 PUT (over, up), bachold, PSET
 LINE (16, 20)-(146, 80), 7, BF: LINE (20, 24)-(142, 76), 0, BF
 LINE (16, 20)-(146, 20), 15: LINE (16, 20)-(16, 80), 15: but = 2
 LINE (17, 80)-(146, 80), 8: LINE (146, 80)-(146, 20), 8
 ShowFont 44, 26, "Save As:", 1: ShowFont 54, 36, "Binary", 2
 ShowFont 68, 46, "Gif", 2: ShowFont 68, 56, "Bmp", 2
 ShowFont 54, 66, "Cancel", 3: st = 0
 CALL DoMouse(over, up, 0): TimeIt 4

 DO
  o = over: u = up: CALL Mouse(up, over, button)
  CALL CheckBound(16, 145, 20, 80)
  IF o <> over OR u <> up THEN CALL DoMouse(o, u, 1)
  IF button = 1 THEN
   IF up > 35 AND up < 46 THEN st = 1: EXIT DO
   IF up > 45 AND up < 56 THEN st = 2: EXIT DO
   IF up > 55 AND up < 66 THEN st = 3: EXIT DO
   IF up > 65 THEN GOSUB DoneSaving
  END IF
  WAIT &H3DA, 8
 LOOP

 CALL InputString(st)

 IF filname$ = "" THEN GOTO NoGood
 FOR a = 1 TO LEN(filname$)
  IF MID$(filname$, a, 1) = " " THEN GOTO NoGood
 NEXT a

 IF st = 1 THEN
  filname$ = filname$ + ".awd"
  PUT (150, 12), invhold, PSET
  ff = FREEFILE
  OPEN filname$ FOR BINARY AS ff
   PUT ff, , px: PUT ff, , py
   bytes = (px * py) * .54
   FOR a = 0 TO bytes
    pline = invhold(a)
    PUT ff, , pline
   NEXT a
  CLOSE ff
 ELSEIF st = 2 THEN
  PUT (150, 12), invhold, PSET
  CALL XMakeGIF(filname$ + ".gif", 320, 200, 150, 12, 149 + px, 11 + py, 256, 2)
 ELSE
  PUT (150, 12), invhold, PSET
  CALL XSaveBMP8(filname$ + ".bmp", 150, 12, 149 + px, 11 + py)
 END IF
 GOTO DoneSaving

NoGood:
 filname$ = "": CLOSE
 PUT (over, up), bachold, PSET: BEEP
 ShowFont 5, 20, "Not a valid file!", 3
 WHILE INKEY$ = "": WEND
 CALL SetupScreen

DoneSaving:
 CALL SetupScreen: CALL ChangePic: CALL DoMouse(over, up, 0)

END SUB

SUB XWritePal (wk%)

 GET (150, 12)-(149 + px, 11 + py), invhold
 IF wk = 1 THEN
  LINE (1, 16)-(178, 33), 7, BF: LINE (5, 20)-(174, 29), 0, BF
  LINE (1, 16)-(1, 33), 15: LINE (1, 16)-(178, 16), 15
  LINE (2, 33)-(178, 33), 8: LINE (178, 16)-(178, 33), 8
 END IF
 IF wk = 2 OR palname$ = "" THEN CALL InputString(4)
 IF palname$ = "" THEN GOTO PNoGood
 FOR a = 1 TO LEN(filname$)
  IF MID$(palname$, a, 1) = " " THEN GOTO PNoGood
 NEXT a
 DIM byte AS STRING * 1
 OPEN palname$ + ".pal" FOR BINARY AS #1
  FOR Att% = 0 TO 255
   OUT &H3C7, Att%
   FOR RedGreenAndBlue% = 1 TO 3
    Buffer% = INP(&H3C9): byte = CHR$(Buffer%): PUT #1, , byte
    NEXT RedGreenAndBlue%
   NEXT Att%
 CLOSE #1
 GOTO PDoneSaving

PNoGood:
 palname$ = "": CLOSE
 PUT (over, up), bachold, PSET: BEEP
 ShowFont 5, 20, "Not a valid file!", 3
 WHILE INKEY$ = "": WEND
PDoneSaving:
 PUT (150, 12), invhold, PSET
 CALL SetupScreen: CALL ChangePic: CALL DoMouse(over, up, 0)

END SUB

FUNCTION ZDirBox$ (ArgD$, ArgF$)

x = 0: y = 15: DinView = 0: FinView = 0
DIM Dirs$(0), File$(0)

GOSUB DrawBackGr: GOSUB GetDirs: GOSUB GetFiles
GOSUB DrawFileBox: GOSUB DrawDirBox
CurFile = -1: CurDrive$ = LEFT$(ArgD$, 1): GOSUB DCL
GET (over, up)-(over + 6, up + 9), bachold: TimeIt .3
PUT (over, up), arrow, OR: PUT (over, up), amask, AND

DO
 o = over: u = up: CALL Mouse(up, over, button)
 CALL CheckBound(1, 312, 19, 174)
 IF o <> over OR u <> up THEN CALL DoMouse(o, u, 1)

 IF button = 1 THEN
  IF over > 19 AND up > 44 AND over < 139 AND up < 114 THEN
   TCurFile = ((up - 49) / 10) + FinView
   IF TCurFile <= AllFiles THEN CurFile = TCurFile
   GOSUB DCL
  END IF
  IF over > 139 AND up > 44 AND over < 149 AND up < 54 THEN
   IF FinView - 1 > -1 THEN FinView = FinView - 1
   GOSUB DrawFileBox
  END IF
  IF over > 139 AND up > 104 AND over < 149 AND up < 114 THEN
   IF FinView + 6 < AllFiles THEN FinView = FinView + 1
   GOSUB DrawFileBox
  END IF
  IF over > 169 AND up > 44 AND over < 289 AND up < 114 THEN
   CurDir = ((up - 49) / 10) + DinView
   IF CurDir <= AllDirs THEN
    PUT (over, up), bachold, PSET
    IF Dirs$(CurDir) = ".." THEN
     DirLen = LEN(ArgD$)
     DO
      ArgD$ = LEFT$(ArgD$, DirLen - 1)
      DirLen = DirLen - 1
     LOOP UNTIL RIGHT$(ArgD$, 1) = "\"
    ELSEIF RIGHT$(Dirs$(CurDir), 2) = ":\" THEN
     IF INSTR(FD$, LEFT$(Dirs$(CurDir), 1)) THEN
      Driv$ = LEFT$(Dirs$(CurDir), 1)
      Drv = (ASC(Driv$) OR 32) - 97
      Register.ax = 0: Register.dx = Drv
      CALL INTERRUPT(&H13, Register, Register)
      Register.ax = &H401: Register.cx = &H101: Register.dx = Drv
      CALL INTERRUPT(&H13, Register, Register)
      Register.ax = &H401: Register.cx = &H101: Register.dx = Drv
      CALL INTERRUPT(&H13, Register, Register)
      FDR = ((Register.flags AND 1) = 0)
      dchk = ((Register.ax AND &HFF00) \ &H100) AND &HFF
      IF FDR = -1 THEN ArgD$ = Dirs$(CurDir)
     ELSE
      ArgD$ = Dirs$(CurDir)
     END IF
    ELSE
     ArgD$ = ArgD$ + Dirs$(CurDir) + "\"
    END IF
    CurFile = -1: GOSUB GetDirs: GOSUB GetFiles: DinView = 0: FinView = 0
    GOSUB DrawFileBox: GOSUB DrawDirBox: GOSUB DCL
    GET (over, up)-(over + 6, up + 9), bachold
    PUT (over, up), arrow, OR: PUT (over, up), amask, AND
   END IF
  END IF
  IF over > 289 AND up > 44 AND over < 299 AND up < 54 THEN
   IF DinView - 1 > -1 THEN DinView = DinView - 1
   GOSUB DrawDirBox
  END IF
  IF over > 289 AND up > 104 AND over < 299 AND up < 114 THEN
   IF DinView + 6 < AllDirs THEN DinView = DinView + 1
   GOSUB DrawDirBox
  END IF
  IF over > 189 AND up > 129 AND over < 229 AND up < 139 THEN
   IF CurFile <> -1 THEN
    IF File$(CurFile) <> "" THEN
     ZDirBox$ = ArgD$ + File$(CurFile)
     EXIT FUNCTION
    END IF
   END IF
  END IF
  IF over > 239 AND up > 129 AND over < 300 AND up < 139 THEN
   ZDirBox$ = "": EXIT FUNCTION
  END IF
 END IF
 WAIT &H3DA, 8
LOOP

DrawBackGr:
  ShowFont x, y, "Ú" + STRING$(30, "Ä") + "¿", 1
  FOR a = y + 10 TO y + 140 STEP 10: ShowFont x, a, "³" + SPACE$(30) + "³", 1: NEXT a
  ShowFont x, y + 150, "À" + STRING$(30, "Ä") + "Ù", 1
  ShowFont x + 55, y + 10, "Files", 2
  ShowFont x + 10, y + 20, "ÚÄÄÄÄÄÄÄÄÄÄÄÄÄ¿", 3
  FOR a = y + 30 TO y + 90 STEP 10: ShowFont x + 10, a, "³             ³", 3: NEXT a
  ShowFont x + 10, y + 100, "ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÙ", 3
  ShowFont x + 180, y + 10, "Dirs/Drives", 2
  ShowFont x + 160, y + 20, "ÚÄÄÄÄÄÄÄÄÄÄÄÄÄ¿", 3
  FOR a = y + 30 TO y + 90 STEP 10: ShowFont x + 160, a, "³             ³", 3: NEXT a
  ShowFont x + 160, y + 100, "ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÙ", 3
  ShowFont x + 190, y + 115, "Okay Cancel", 4
RETURN
GetFiles:
  DosCmd$ = "DIR " + ArgD$ + ArgF$ + " /B /A-D /ON > DIR.TMP"
  SHELL DosCmd$: ff = FREEFILE
  OPEN "DIR.TMP" FOR INPUT AS ff: InFile$ = INPUT$(LOF(1), #1): CLOSE ff
  KILL "DIR.TMP": AllFiles = -1: NewLine$ = CHR$(13)
  FOR a = 1 TO LEN(InFile$)
   IF MID$(InFile$, a, 1) = NewLine$ THEN AllFiles = AllFiles + 1
  NEXT a
  IF AllFiles = -1 THEN RETURN
  REDIM File$(AllFiles)
  Sloc = 1: File$(0) = LEFT$(InFile$, INSTR(InFile$, NewLine$) - 1)
  FOR a = 1 TO AllFiles
   Sloc = INSTR(Sloc + 2, InFile$, NewLine$)
   IF Sloc = 0 OR INSTR(MID$(InFile$, Sloc + 2), NewLine$) = 0 THEN EXIT FOR
   File$(a) = LEFT$(MID$(InFile$, Sloc + 2), INSTR(MID$(InFile$, Sloc + 2), NewLine$) - 1)
  NEXT a
  FOR a = 0 TO AllFiles
   IF File$(a) = "" THEN FOR B = a TO AllFiles - 1: File$(B) = File$(B + 1): NEXT B: AllFiles = AllFiles - 1
  NEXT a
  InFile$ = ""
  RETURN
DrawFileBox:
  LINE (142, 53)-(148, 53), 124: LINE (142, 53)-(145, 46), 124
  LINE (145, 46)-(148, 53), 124: PAINT (145, 51), 124
  LINE (142, 106)-(148, 106), 124: LINE (142, 106)-(145, 113), 124
  LINE (145, 113)-(148, 106), 124: PAINT (145, 109), 124
  FOR a = y + 40 TO y + 80 STEP 10: ShowFont x + 140, a, "°", 4: NEXT a
  IF AllFiles > 6 THEN
   CurSel = (INT(FinView / (AllFiles / 5))) * 10: d = 0
   ShowFont x + 140, y + 40 + CurSel, "°", 1
   FOR a = FinView TO FinView + 6
    IF LEN(File$(a)) > 12 THEN
     ShowFont x + 20, y + 30 + d, LEFT$(File$(a), 9) + "...", 3
    ELSE
     ShowFont x + 20, y + 30 + d, File$(a) + SPACE$(12 - LEN(File$(a))), 3
    END IF
    d = d + 10
   NEXT a
  ELSE
   CurSel = 0: ShowFont x + 140, y + 40 + CurSel, "°", 1
   FOR a = 0 TO AllFiles
    IF LEN(File$(a)) > 12 THEN
     ShowFont x + 20, y + 30 + (a * 10), LEFT$(File$(a), 9) + "...", 3
    ELSE
     ShowFont x + 20, y + 30 + (a * 10), File$(a) + SPACE$(12 - LEN(File$(a))), 3
    END IF
   NEXT a
   FOR a = AllFiles + 1 TO 6: ShowFont x + 20, y + 30 + (a * 10), SPACE$(12), 3: NEXT a
  END IF
RETURN
GetDirs:
  DosCmd$ = "DIR " + ArgD$ + "*.* /B /AD /ON > DIR.TMP"
  SHELL DosCmd$: ff = FREEFILE
 
  IF LEN(ArgD$) = 3 THEN
   OPEN "DIR.TMP" FOR APPEND AS ff
    FOR i = 1 TO LEN(FD$)
     IF MID$(FD$, i, 1) <> LEFT$(ArgD$, 1) THEN
      PRINT #ff, MID$(FD$, i, 1) + ":\"
     END IF
    NEXT i
    FOR i = 1 TO LEN(HD$)
     IF MID$(HD$, i, 1) <> LEFT$(ArgD$, 1) AND MID$(HD$, i, 1) <> " " THEN
      PRINT #ff, MID$(HD$, i, 1) + ":\"
     END IF
    NEXT i
   CLOSE ff
  END IF
  
  OPEN "DIR.TMP" FOR INPUT AS ff: InFile$ = INPUT$(LOF(1), ff): CLOSE ff
  KILL "DIR.TMP": NewLine$ = CHR$(13): AllDirs = -1
  FOR a = 1 TO LEN(InFile$)
   IF MID$(InFile$, a, 1) = NewLine$ THEN AllDirs = AllDirs + 1
  NEXT a
  IF AllDirs = -1 AND LEN(ArgD$) = 3 THEN RETURN
  REDIM Dirs$(AllDirs + 1)
  IF AllDirs = -1 THEN GOTO SkipFill
  Sloc = 1: Dirs$(0) = LEFT$(InFile$, INSTR(InFile$, NewLine$) - 1)
  FOR a = 1 TO AllDirs
   Sloc = INSTR(Sloc + 2, InFile$, NewLine$)
   IF Sloc = 0 OR INSTR(MID$(InFile$, Sloc + 2), NewLine$) = 0 THEN EXIT FOR
   Dirs$(a) = LEFT$(MID$(InFile$, Sloc + 2), INSTR(MID$(InFile$, Sloc + 2), NewLine$) - 1)
  NEXT a
  FOR a = 0 TO AllDirs
   IF Dirs$(a) = "" THEN FOR B = a TO AllDirs - 1: Dirs$(B) = Dirs$(B + 1): NEXT B: AllDirs = AllDirs - 1
  NEXT a
SkipFill:
  IF LEN(ArgD$) > 3 THEN
   AllDirs = AllDirs + 1
   IF AllDirs > 0 THEN
    FOR a = AllDirs - 1 TO 0 STEP -1: Dirs$(a + 1) = Dirs$(a): NEXT a
    Dirs$(0) = ".."
   ELSE
    Dirs$(0) = ".."
   END IF
  END IF
  InFile$ = ""
  RETURN
DrawDirBox:
  LINE (292, 53)-(298, 53), 124: LINE (292, 53)-(295, 46), 124
  LINE (295, 46)-(298, 53), 124: PAINT (295, 51), 124
  LINE (292, 106)-(298, 106), 124: LINE (292, 106)-(295, 113), 124
  LINE (295, 113)-(298, 106), 124: PAINT (295, 109), 124
  FOR a = y + 40 TO y + 80 STEP 10: ShowFont x + 290, a, "°", 4: NEXT a
  IF AllDirs > 6 THEN
   CurSel = (INT(DinView / (AllDirs / 5))) * 10: d = 0
   ShowFont x + 290, y + 40 + CurSel, "°", 1
   FOR a = DinView TO DinView + 6
    IF LEN(Dirs$(a)) > 12 THEN
     ShowFont x + 170, y + 30 + d, LEFT$(Dirs$(a), 9) + "...", 3
    ELSE
     ShowFont x + 170, y + 30 + d, Dirs$(a) + SPACE$(12 - LEN(Dirs$(a))), 3
    END IF
    d = d + 10
   NEXT a
  ELSE
   CurSel = 0: ShowFont x + 290, y + 40 + CurSel, "°", 1
   FOR a = 0 TO AllDirs
    IF LEN(Dirs$(a)) > 12 THEN
     ShowFont x + 170, y + 30 + (a * 10), LEFT$(Dirs$(a), 9) + "...", 3
    ELSE
     ShowFont x + 170, y + 30 + (a * 10), Dirs$(a) + SPACE$(12 - LEN(Dirs$(a))), 3
    END IF
   NEXT a
   FOR a = AllDirs + 1 TO 6: ShowFont x + 170, y + 30 + (a * 10), SPACE$(12), 3: NEXT a
  END IF
RETURN
DCL:
 ShowFont x + 25, y + 119, "            ", 3
 IF CurFile > -1 THEN
  IF LEN(File$(CurFile)) > 12 THEN
   ShowFont x + 25, y + 119, LEFT$(File$(CurFile), 9) + "...", 2
  ELSE
   ShowFont x + 25, y + 119, File$(CurFile) + SPACE$(12 - LEN(File$(CurFile))), 2
  END IF
 END IF
 IF LEN(ArgD$) > 28 THEN
  ShowFont x + 10, y + 140, LEFT$(ArgD$, 28) + "..", 1
 ELSE
  ShowFont x + 10, y + 140, ArgD$ + SPACE$(30 - LEN(ArgD$)), 1
 END IF
 RETURN

END FUNCTION

SUB ZDList

 DIM IRegs AS RegType, ORegs AS RegType

 DEF SEG = 0: FDe = PEEK(&H410) \ 64 + 1
 FD$ = SPACE$(FDe)
 FOR N = 1 TO FDe: MID$(FD$, N, 1) = CHR$(64 + N): NEXT
 FDs = LEN(FD$)
 HDe = FDs + 1 + ABS(FDe = 1)
 HD$ = SPACE$(HDe)
 FOR BL = HDe TO 26
  IRegs.ax = &H4409: IRegs.bx = BL
  INTERRUPT &H21, IRegs, ORegs
  IF (ORegs.flags AND 1) THEN EXIT FOR
  MID$(HD$, HDe, 1) = CHR$(64 + ORegs.bx)
 NEXT

END SUB

