]> bicyclesonthemoon.info Git - cpied/commitdiff
- Added CPX support (read only) v1.3a
authorb <rowerynaksiezycu@gmail.com>
Thu, 1 Aug 2013 20:54:00 +0000 (22:54 +0200)
committerb <rowerynaksiezycu@gmail.com>
Thu, 1 Aug 2013 20:54:00 +0000 (22:54 +0200)
- Added a list of codepages which is also clickable
- Removed dependancy on Borland's EGAVGA driver:
  Code ported to Open Watcom, Borland's graphic functions replaced with Open Watcom's equivalents

CPIED.PRJ [deleted file]
DOC/COPYING.TXT [moved from COPYING.TXT with 100% similarity]
DOC/readthis.txt [moved from readthis.txt with 72% similarity]
EGAVGA.OBJ [deleted file]
SRC/CPIED.CPP [moved from CPIED.CPP with 63% similarity]
SRC/cpitrick.asm [new file with mode: 0644]
SRC/cpx2cpi.c [new file with mode: 0644]
SRC/makefile [new file with mode: 0644]

diff --git a/CPIED.PRJ b/CPIED.PRJ
deleted file mode 100644 (file)
index d32e214..0000000
Binary files a/CPIED.PRJ and /dev/null differ
similarity index 100%
rename from COPYING.TXT
rename to DOC/COPYING.TXT
similarity index 72%
rename from readthis.txt
rename to DOC/readthis.txt
index aab821d0f2b4229b2d74f50217d5050d3950dc3a..6ebb2905614dd9e2e6336f40f905f3d2b7835875 100644 (file)
@@ -1,27 +1,26 @@
-####    #       #\r
-#       #       #\r
-###   ### #  # ####  ##  ###     \r
-#    #  # #  #  #   #  # #        \r
-####  ###  ###  ##   ##  #                  \r
-             #                               #\r
-           ##  #  #   ##   ###   #   ###   ##   #   #\r
-               ## #  #  #  #  #  #  #__   #  #  #   #\r
-               # ##  ####  ###   #     #  #  #  # # #\r
-               #  #  #  #  #     #  ###    ##    # #   \r
-                                       Balthasar Szczepaäski\r
-Edytor napis¢w 1.2b - the cpi editor\r
+\r
+  ÛÛÛÛ  ÛÛÛÛÛÛ   ÛÛÛÛ   ÛÛÛÛÛÛÛ ÛÛÛÛÛ     Û    ÛÛ     \r
+ ÛÛ  ÛÛ  ÛÛ  ÛÛ   ÛÛ     ÛÛ   Û  ÛÛ ÛÛ   ÛÛ      Û\r
+ÛÛ       ÛÛ  ÛÛ   ÛÛ     ÛÛ      ÛÛ  ÛÛ   Û     Û      \r
+ÛÛ       ÛÛÛÛÛ    ÛÛ     ÛÛÛÛ    ÛÛ  ÛÛ   Û      Û     \r
+ÛÛ       ÛÛ       ÛÛ     ÛÛ      ÛÛ  ÛÛ  ÛÛÛ Û ÛÛ  A   \r
+ ÛÛ  ÛÛ  ÛÛ       ÛÛ     ÛÛ   Û  ÛÛ ÛÛ\r
+  ÛÛÛÛ  ÛÛÛÛ     ÛÛÛÛ   ÛÛÛÛÛÛÛ ÛÛÛÛÛ  Balthasar Szczepaäski\r
+\r
+       CPIED 1.3a - the CPI editor\r
 \r
 ============================================================\r
 \r
-1. Description\r
-2. System requirements\r
-3. Features and limitations\r
-4. Controls\r
-5. Changes\r
-6. Planned features\r
-7. Known bugs\r
-8. Files\r
-9. Contact information\r
+ 1. Description\r
+ 2. System requirements\r
+ 3. Features and limitations\r
+ 4. Controls\r
+ 5. Changes\r
+ 6. Planned features\r
+ 7. Known bugs\r
+ 8. Compiling, installing\r
+ 9. Files\r
+10. Contact information\r
 \r
 ============================================================\r
 \r
@@ -29,7 +28,7 @@ Edytor napis
 \r
 This program is a CPI file editor. It can edit CPI files\r
 which are used by DOS to store codepage information.\r
-Compiled with Turbo C++ 3.0. Released under the terms of the\r
+Released under the terms of the\r
 GPL 3 license (see ccopying.txt)\r
 \r
 ============================================================\r
@@ -78,6 +77,7 @@ There can be problems in NT-based versions of windows:
 were no problems. The previous version of the program (1.0)\r
 does not run on DOSBox 0.63. No other emulators were tested.\r
 \r
+cpx2cpi was not tested on those systems yet!\r
 ============================================================\r
 \r
 3. Features and limitations\r
@@ -89,12 +89,12 @@ The following file formats are supported:
   This format is not fully supported. Files can be loaded in\r
   this format, but can only be saved in FONT format.\r
   Windows supports both formats, so this is not a problem.\r
+3.CPX - used by FreeDOS. Files can be loaded in\r
+  this format, but can only be saved in CPI format.\r
 \r
 The following file formats are not supported:\r
 \r
-3.DRFONT - used by DR-DOS\r
-4.CPX - used by FreeDOS. FreeDOS also supports the FONT\r
-  file format.\r
+4.DRFONT - used by DR-DOS\r
 \r
 Loaded files must meet the following restrictions:\r
 1.Number of all codepages cannot be 0 or bigger than 16.\r
@@ -140,7 +140,7 @@ The following actions can be performed:
 Everything can be controlled by the keyboard or mouse (if\r
 there is a mouse installed).\r
 \r
-Action             Keyboard       Mouse\r
+Action             Keyboard    Mouse\r
 \r
 create a new CPI   F1          click the "1.new" text\r
 save a CPI file    F2          click the "2.save" text\r
@@ -161,15 +161,21 @@ change a pixel     Space       middle click the pixel
 switch edit/select Tab         changes automatically\r
 next codepage      PageDown    left click the "cp___" text\r
 previous codepage  PageUp      right click the "cp___" text\r
+select a codepage              click the number on the list\r
 next font          End         left click the "8x__" text\r
 previous font      Home        right click the "8x__" text\r
 \r
 *The function of arrow keys is changed with Tab.\r
 \r
-A file can also be opened using it's name as a command line\r
-parameter or by clicking its icon in Windows GUI. If a wrong\r
-path is given the program closes without entering graphic\r
-mode.\r
+Command line:\r
+\r
+cpied [cpifile] - edir cpi or cpx files\r
+  cpifile - file to be loaded CPI or CPX\r
+\r
+cpx2cpi cpxfile cpifile [q] - convert cpx to cpi\r
+  cpxfile - input file, cpx\r
+       cpxfile - output file, cpi\r
+       q       - no console output\r
 \r
 ============================================================\r
 \r
@@ -211,13 +217,18 @@ beta:
  - Further optimization of graphic procedures\r
  - Fixed a bug that placed the cursor outside the edited\r
    character when switching between heights with the mouse.\r
+1.3a\r
+ - Added CPX support (read only)\r
+ - Added a list of codepages which is also clickable\r
+ - Removed dependancy on Borland's EGAVGA driver:\r
+   Code ported to Open Watcom, Borland's graphic functions\r
+        replaced with Open Watcom's equivalents\r
         \r
 ============================================================\r
 \r
 6. Planned features\r
 \r
  - Saving FONT.NT files \r
- - CPX file format support\r
  - Exporting codepages to CP files\r
  - Importing codepages from CP flies\r
  - Exporting fonts to bitmaps\r
@@ -228,20 +239,54 @@ beta:
 \r
 7. Known bugs\r
 \r
+Dialog boxes need improving.\r
+\r
 ============================================================\r
 \r
-8. Files\r
+8. Compiling, installing\r
+\r
+Compiling:\r
+\r
+Requirements:\r
+ cpx2cpi:\r
+       NASM\r
+       Turbo C\r
+ cpied:\r
+       Open Watcom\r
+\r
+The makefile should be processed by a make program.\r
+I used Borland's make, the real-mode version, makeR. Open\r
+Watcom's wmake doesn't compile cpx2cpi.\r
+\r
+Installing:\r
+\r
+cpied.exe and cpx2cpi.com should be copied to somwere in the\r
+%PATH%\r
+\r
+On Windows you may register *.cpi and*.cpx file extensions\r
+to CPIED.\r
+\r
+============================================================ \r
+\r
+9. Files\r
+\r
+BIN:\r
+  CPIED   .EXE The CPI editor\r
+  CPX2CPI .COM CPX to CPI converter\r
+SRC:\r
+  CPIED   .CPP Source for the CPI editor\r
+  CPX2CPI .C   Source for the CPX to CPI converter\r
+  CPITRICK.ASM Source for the CPX to CPI converter\r
+  MAKEFILE     Makefile for both programs\r
+DOC:\r
+  COPYING .TXT License information\r
+  READTHIS.TXT This file\r
 \r
-EGAVGA  .OBJ   5658 BGI driver compiled to OBJ\r
-CPIED   .EXE 101275 The program\r
-CPIED   .CPP  60912 Source for the program\r
-CPIED   .PRJ   4608 Turbo C++ 3.0 project file\r
-COPYING .TXT  35821 License information\r
-READTHIS.TXT   8443 This file\r
+cpitrick.asm and cpx2cpi.c contain code from FreeDOS mode.\r
 \r
 ============================================================\r
 \r
-9. Contact information\r
+10. Contact information\r
 \r
 e-mail:   balthasar_s@interia.pl\r
           rowerynaksiezycu@gmail.com\r
diff --git a/EGAVGA.OBJ b/EGAVGA.OBJ
deleted file mode 100644 (file)
index 9098132..0000000
Binary files a/EGAVGA.OBJ and /dev/null differ
similarity index 63%
rename from CPIED.CPP
rename to SRC/CPIED.CPP
index 94c5ca68f7194646cd5f094b7456da2dcb4ffd90..82f8859e6f7f16a21d95942d068af2a3be92d548 100644 (file)
--- a/CPIED.CPP
@@ -1,7 +1,7 @@
-    //CPI EDITOR vresion 1.2b\r
+    //CPIED version 1.3a\r
    // Balthasar Szczepaäski Copyright 2013\r
   //\r
- //   This file is part of CPIED also known as the CPI EDITOR or EDYTOR NAPISàW\r
+ //   This file is part of CPIED\r
 //    \r
     //CPIED is free software: you can redistribute it and/or modify\r
    // it under the terms of the GNU General Public License as published by\r
 //\r
     //You should have received a copy of the GNU General Public License along\r
    // with CPIED (copying.txt).  If not, see <http://www.gnu.org/licenses/>.\r
-  //  \r
- //\r
-//    Compiled with Turbo C++ 3.0\r
-#include <graphics.h>\r
+\r
+#define BLACK   0\r
+#define GRAY    8\r
+#define BLUE    1\r
+#define LBLUE   9\r
+#define GREEN   2      \r
+#define LGREEN 10\r
+#define CYAN    3\r
+#define LCYAN  11\r
+#define RED     4\r
+#define LRED   12\r
+#define MAGEN   5\r
+#define LMAGEN 13\r
+#define BROWN   6\r
+#define YELLOW 14\r
+#define LGRAY   7\r
+#define WHITE  15\r
+\r
+//#define C_BACK BLACK\r
+#define C_SET  BROWN\r
+#define C_NON  RED\r
+#define C_SEL  GREEN\r
+\r
+#include <graph.h>\r
 #include <stdio.h>\r
 #include <conio.h>\r
 #include <string.h>\r
 #include <mem.h>\r
 #include <dos.h>\r
 #include <bios.h>\r
+#include <process.h>\r
 \r
 #define resetMaus setMaus\r
 \r
-//Strustures in the CPI file format\r
+//Structures in the CPI file format\r
 struct FontFileHeader\r
 {\r
        unsigned char id0;\r
@@ -105,11 +126,25 @@ struct ScreenFontBitmap8
        int status;\r
        char nazwap[256]="Nie_wybrano_pliku";\r
        char err[256];\r
-\r
-       int kart16=VGA;\r
-\r
-       int tryb16=VGAHI;\r
-\r
+       unsigned char NOFONT[8]={\r
+               0x80,\r
+               0x00,\r
+               0x08,\r
+               0x00,\r
+               0x80,\r
+               0x00,\r
+               0x08,\r
+               0x00};\r
+       unsigned char FULLF[8]={\r
+               0xff,\r
+               0xff,\r
+               0xff,\r
+               0xff,\r
+               0xff,\r
+               0xff,\r
+               0xff,\r
+               0xff};\r
+       \r
        FILE *CPI;\r
        FontFileHeader *FFH;\r
        FontInfoHeader *FIH;\r
@@ -159,7 +194,7 @@ void offset      ();
 \r
 void new8  ();\r
 void menu8 ();\r
-void cpwys ();\r
+void cpwys (int mode=0);\r
 void redraw();\r
 \r
 void displayDialog(int  color, char *text,  int type=0);\r
@@ -312,29 +347,39 @@ void offset()
 }\r
 void new8()\r
 {\r
-       cleardevice();\r
-       setcolor(GREEN);\r
-       \r
-       outtextxy(0,0,  "CPI editor 1.2±");\r
-       outtextxy(0,8,  "±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±");\r
-       //outtextxy(600,16,"v1.2b");\r
+       _clearscreen(_GCLEARSCREEN);\r
+       _setcolor(C_SEL);\r
+       _moveto(0,0);\r
+       _outgtext("CPIED     1.3a±");\r
+       _moveto(0,8);\r
+       _outgtext("±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±");\r
 }\r
 void menu8()\r
 {\r
-       setcolor(GREEN);\r
-       outtextxy(609,449,",");\r
-       outtextxy(472,456,"Balthasar Szczepanski");\r
-       outtextxy(0,464,"±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±");\r
+       _setcolor(C_SEL);\r
+       _moveto(609,449);\r
+       _outgtext(",");\r
+       _moveto(472,456);\r
+       _outgtext("Balthasar Szczepanski");\r
+       _moveto(0,464);\r
+       _outgtext("±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±");\r
        if(any)\r
-               outtextxy(0,472,"1.new°°2.save°°3.load°°4.use°°5.number°°6.newF°°7.newCP°°8.delF°°9.delCP°°10.end");\r
+       {\r
+               _moveto(0,472);\r
+               _outgtext("1.new°°2.save°°3.load°°4.use°°5.number°°6.newF°°7.newCP°°8.delF°°9.delCP°°10.end");\r
+       }\r
        else\r
-               outtextxy(0,472,"1.new°°°°°°°°°°3.load°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°10.end");\r
+       {\r
+               _moveto(0,472);\r
+               _outgtext("1.new°°°°°°°°°°3.load°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°10.end");\r
+       }\r
 }\r
-void cpwys()\r
+void cpwys(int mode)\r
 {\r
        char cpw[256];\r
-       setfillstyle(EMPTY_FILL,BLACK);\r
-       bar(120,0,639,7);\r
+       _setfillmask(FULLF);\r
+       _setcolor(BLACK);\r
+       _rectangle(_GFILLINTERIOR,120,0,639,7);\r
        if(any)\r
        {\r
                if((unsigned)(CPEH[cp]->codepage)>=1000)\r
@@ -364,9 +409,24 @@ void cpwys()
        }\r
        else\r
                strcpy(cpw, "°No CPI open°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°°");\r
-       setcolor(GREEN);\r
-\r
-       outtextxy(120,0,cpw);\r
+       _setcolor(C_SEL);\r
+       _moveto(120,0);\r
+       _outgtext(cpw);\r
+       if(mode||!any)\r
+               return;\r
+       for(short i=0;i<FIH->num_codepages;++i)\r
+       {\r
+               if(i==cp)\r
+                       _setcolor(C_SEL);\r
+               else\r
+                       _setcolor(C_NON);\r
+               _moveto(328+(i%6)*48,16+(i/6)*8);\r
+               if((unsigned)(CPEH[i]->codepage)>=1000)\r
+                       sprintf(cpw,"%5u",CPEH[i]->codepage);\r
+               else\r
+                       sprintf(cpw,"  %03u",CPEH[i]->codepage);\r
+               _outgtext(cpw);\r
+       }\r
 }\r
 void redraw()//\r
 {\r
@@ -388,27 +448,31 @@ void redraw()//
 \r
 void displayDialog(int color,char *text,int type)\r
 {\r
-       gotoxy(21,13);\r
+       _settextposition(13,21);\r
        char t1[43]="±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±";\r
        strcpy(t1+1,text);\r
        t1[strlen(t1)]='±';\r
-       setfillstyle(EMPTY_FILL,BLACK);\r
-       bar(152,184,487,215);\r
-       setcolor(color);\r
-       outtextxy(152,184,t1);\r
-       outtextxy(152,192,"±                                        ±");\r
-       outtextxy(152,200,"±                                        ±");\r
+       _setfillmask(FULLF);\r
+       _setcolor(BLACK);\r
+       _rectangle(_GFILLINTERIOR,152,184,487,215);\r
+       _setcolor(color);\r
+       _moveto(152,184);\r
+       _outgtext(t1);\r
+       _moveto(152,192);\r
+       _outgtext("±                                        ±");\r
+       _moveto(152,200);\r
+       _outgtext("±                                        ±");\r
        switch(type)\r
        {\r
        case 2:\r
-               outtextxy(152,208,"±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±again?(y/n)±");\r
+               _moveto(152,208);_outgtext("±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±again?(y/n)±");\r
                break;\r
        case 1:\r
-               outtextxy(152,208,"±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±anykey±");\r
+               _moveto(152,208);_outgtext("±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±anykey±");\r
                break;\r
        case 0:\r
        default:\r
-               outtextxy(152,208,"±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±");\r
+               _moveto(152,208);_outgtext("±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±±");\r
                break;\r
        }\r
 }\r
@@ -416,19 +480,19 @@ int message(char *text, char *value, int type)
 {\r
        if (type!=2)\r
        {\r
-               displayDialog(BROWN,text,1);\r
+               displayDialog(C_SET,text,1);\r
                printf("%s",value);\r
-               bioskey(_KEYBRD_READ);\r
+               _bios_keybrd(_KEYBRD_READ);\r
                return 0;\r
        }\r
        else\r
        {\r
-               displayDialog(BROWN,text,2);\r
+               displayDialog(C_SET,text,2);\r
                printf("%s",value);\r
-               int a;\r
+               unsigned short a;\r
                for(;;)\r
                {\r
-                       a=bioskey(_KEYBRD_READ);\r
+                       a=_bios_keybrd(_KEYBRD_READ);\r
                        if((a&0xFF)==0x59||(a&0xFF)==0x79)\r
                                return 0;\r
                        if((a&0xFF)==0x4e||(a&0xff)==0x6e)\r
@@ -438,7 +502,7 @@ int message(char *text, char *value, int type)
 }\r
 inline void question(char *text, char *result)\r
 {\r
-       displayDialog(GREEN,text);\r
+       displayDialog(C_SEL,text);\r
        scanf("%s",result);\r
 }\r
 inline unsigned question(char *text)\r
@@ -453,45 +517,45 @@ void ramka8()
        if(!any)\r
                return;\r
        if(tab==0&&wys==8)\r
-               setcolor(GREEN);\r
+               _setcolor(C_SEL);\r
        else\r
-               setcolor(RED);\r
-       rectangle(15,31,144,160);\r
+               _setcolor(C_NON);\r
+       _rectangle(_GBORDER,15,31,144,160);\r
        if(tab!=0&&wys==8)\r
-               setcolor(GREEN);\r
+               _setcolor(C_SEL);\r
        else\r
-               setcolor(RED);\r
-       rectangle(175,31,304,160);\r
+               _setcolor(C_NON);\r
+       _rectangle(_GBORDER,175,31,304,160);\r
 }\r
 void ramka14()\r
 {\r
        if(!any)\r
                return;\r
        if(tab==0&&wys==14)\r
-               setcolor(GREEN);\r
+               _setcolor(C_SEL);\r
        else\r
-               setcolor(RED);\r
-       rectangle(15,223,144,448);\r
+               _setcolor(C_NON);\r
+       _rectangle(_GBORDER,15,223,144,448);\r
        if(tab!=0&&wys==14)\r
-               setcolor(GREEN);\r
+               _setcolor(C_SEL);\r
        else\r
-               setcolor(RED);\r
-       rectangle(175,223,304,448);\r
+               _setcolor(C_NON);\r
+       _rectangle(_GBORDER,175,223,304,448);\r
 }\r
 void ramka16()\r
 {\r
        if(!any)\r
                return;\r
        if(tab==0&&wys==16)\r
-               setcolor(GREEN);\r
+               _setcolor(C_SEL);\r
        else\r
-               setcolor(RED);\r
-       rectangle(335,111,464,368);\r
+               _setcolor(C_NON);\r
+       _rectangle(_GBORDER,335,111,464,368);\r
        if(tab!=0&&wys==16)\r
-               setcolor(GREEN);\r
+               _setcolor(C_SEL);\r
        else\r
-               setcolor(RED);\r
-       rectangle(495,111,624,368);\r
+               _setcolor(C_NON);\r
+       _rectangle(_GBORDER,495,111,624,368);\r
 }\r
 void lin8(int mode)\r
 {\r
@@ -500,83 +564,96 @@ void lin8(int mode)
        if(mode==3)\r
        {\r
                if(SFB8[cp]->lit[lit].lin[cury]&(0x80>>curx))\r
-                       putpixel(176+curx+((lit&15)<<3),32+cury+((lit>>4)<<3),GREEN);\r
+                       _setcolor(C_SEL);\r
                else\r
-                       putpixel(176+curx+((lit&15)<<3),32+cury+((lit>>4)<<3),BLACK);\r
+                       _setcolor(BLACK);\r
+               _setpixel(176+curx+((lit&15)<<3),32+cury+((lit>>4)<<3));\r
                return;\r
        }\r
        char ab[2]="X";\r
-       int color1,color2;\r
+       short color1,color2;\r
        if(byo8[cp]==0)\r
        {\r
-               setfillstyle(WIDE_DOT_FILL,RED);\r
-               bar(176,32,303,159);\r
+               _setfillmask(FULLF);\r
+               _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,176,32,303,159);\r
+               _setfillmask(NOFONT);\r
+               _setcolor(C_NON);\r
+               _rectangle(_GFILLINTERIOR,176,32,303,159);\r
                return;\r
        }\r
        if(wys==8)\r
        {\r
-               color1=GREEN;\r
-               color2=GREEN;\r
+               color1=C_SEL;\r
+               color2=C_SEL;\r
        }\r
        else\r
        {       \r
-               color1=BROWN;\r
-               color2=RED;\r
+               color1=C_SET;\r
+               color2=C_NON;\r
        }\r
        int l;\r
        switch(mode)\r
        {\r
        case 2:\r
-               setcolor(RED);\r
+               _setcolor(C_NON);\r
                if((pre&15)!=(lit&15))\r
                {\r
                        ab[0]=abc[pre&15];\r
-                       outtextxy(176+((pre&15)<<3),24,ab);\r
+                       _moveto(176+((pre&15)<<3),24);\r
+                       _outgtext(ab);\r
                }\r
                if(pre>>4!=lit>>4)\r
                {\r
                        ab[0]=abc[pre>>4];\r
-                       outtextxy(168,32+((pre>>4)<<3),ab);\r
+                       _moveto(168,32+((pre>>4)<<3));\r
+                       _outgtext(ab);\r
                }\r
-               setfillpattern(SFB8[cp]->lit[pre].lin,BROWN);\r
-               bar(176+((pre&15)<<3),32+((pre>>4)<<3),183+((pre&15)<<3),39+((pre>>4)<<3));\r
+               _setfillmask(SFB8[cp]->lit[pre].lin);\r
+               _setcolor(C_SET);\r
+               _rectangle(_GFILLINTERIOR,176+((pre&15)<<3),32+((pre>>4)<<3),183+((pre&15)<<3),39+((pre>>4)<<3));\r
        \r
        \r
        case 3:\r
        case 1:\r
-               setcolor(color2);\r
+               _setcolor(color2);\r
                ab[0]=abc[lit&15];\r
-               outtextxy(176+((lit&15)<<3),24,ab);\r
+               _moveto(176+((lit&15)<<3),24);\r
+               _outgtext(ab);\r
                ab[0]=abc[lit>>4];\r
-               outtextxy(168,32+((lit>>4)<<3),ab);\r
-               setfillpattern(SFB8[cp]->lit[lit].lin,color1);\r
-               bar(176+((lit&15)<<3),32+((lit>>4)<<3),183+((lit&15)<<3),39+((lit>>4)<<3));\r
-               \r
-               \r
+               _moveto(168,32+((lit>>4)<<3));\r
+               _outgtext(ab);\r
+               _setfillmask(SFB8[cp]->lit[lit].lin);\r
+               _setcolor(color1);\r
+               _rectangle(_GFILLINTERIOR,176+((lit&15)<<3),32+((lit>>4)<<3),183+((lit&15)<<3),39+((lit>>4)<<3));\r
                break;\r
        case 0:\r
        default:\r
+               _setfillmask(FULLF);\r
+               _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,176,32,303,159);\r
                for(l=0;l<16;++l)\r
                {\r
                        ab[0]=abc[l];\r
                        if((lit&15)==l)\r
-                               setcolor(color2);\r
+                               _setcolor(color2);\r
                        else\r
-                               setcolor(RED);\r
-                       outtextxy(176+(l<<3),24,ab);\r
+                               _setcolor(C_NON);\r
+                       _moveto(176+(l<<3),24);_outgtext(ab);\r
                        if(lit>>4==l)\r
-                               setcolor(color2);\r
+                               _setcolor(color2);\r
                        else\r
-                               setcolor(RED);\r
-                       outtextxy(168,32+(l<<3),ab);\r
+                               _setcolor(C_NON);\r
+                       _moveto(168,32+(l<<3));_outgtext(ab);\r
                }\r
                for(l=0;l<256;++l)\r
                {\r
                        if(l==lit)\r
-                               setfillpattern(SFB8[cp]->lit[l].lin,color1);\r
+                               _setcolor(color1);\r
                        else\r
-                               setfillpattern(SFB8[cp]->lit[l].lin,BROWN);\r
-                       bar(176+((l&15)<<3),32+((l>>4)<<3),183+((l&15)<<3),39+((l>>4)<<3));\r
+                               _setcolor(C_SET);\r
+                       _setfillmask(SFB8[cp]->lit[l].lin);\r
+                       _rectangle(_GFILLINTERIOR,176+((l&15)<<3),32+((l>>4)<<3),183+((l&15)<<3),39+((l>>4)<<3));\r
                }\r
                break;\r
        }\r
@@ -588,127 +665,126 @@ void lin14(int mode)
        if(mode==3)\r
        {\r
                if(SFB14[cp]->lit[lit].lin[cury]&(0x80>>curx))\r
-                       putpixel(176+curx+((lit&15)<<3),224+cury+(lit>>4)*14,GREEN);\r
+                       _setcolor(C_SEL);\r
                else\r
-                       putpixel(176+curx+((lit&15)<<3),224+cury+(lit>>4)*14,BLACK);\r
+                       _setcolor(BLACK);\r
+               _setpixel(176+curx+((lit&15)<<3),224+cury+(lit>>4)*14);\r
                return;\r
        }\r
        char ab[2]="X";\r
-       int color1,color2;\r
+       short color1,color2;\r
        if(byo14[cp]==0)\r
        {\r
-               setfillstyle(WIDE_DOT_FILL,RED);\r
-               bar(176,224,303,447);\r
+               _setfillmask(FULLF);\r
+               _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,176,224,303,447);\r
+               _setfillmask(NOFONT);\r
+               _setcolor(C_NON);\r
+               _rectangle(_GFILLINTERIOR,176,224,303,447);\r
                return;\r
        }\r
        if(wys==14)\r
        {\r
-               color1=GREEN;\r
-               color2=GREEN;\r
+               color1=C_SEL;\r
+               color2=C_SEL;\r
        }\r
        else\r
        {       \r
-               color1=BROWN;\r
-               color2=RED;\r
+               color1=C_SET;\r
+               color2=C_NON;\r
        }\r
        int a,l;\r
        switch(mode)\r
        {\r
        case 2:\r
-               setcolor(RED);\r
+               _setcolor(C_NON);\r
                if((pre&15)!=(lit&15))\r
                {\r
                        ab[0]=abc[pre&15];\r
-                       outtextxy(176+((pre&15)<<3),216,ab);\r
+                       _moveto(176+((pre&15)<<3),216);_outgtext(ab);\r
                }\r
                if(pre>>4!=lit>>4)\r
                {\r
                        ab[0]=abc[pre>>4];\r
-                       outtextxy(168,227+(pre>>4)*14,ab);\r
+                       _moveto(168,227+(pre>>4)*14);_outgtext(ab);\r
                }\r
                a=(pre>>4)&3;\r
+               _setcolor(C_SET);\r
                if(a)\r
                {\r
-                       setfillpattern(SFB14[cp]->lit[pre].lin+(a<<1)-8,BROWN);\r
-                       bar(176+((pre&15)<<3),224+(pre>>4)*14,183+((pre&15)<<3),223+(a<<1)+(pre>>4)*14);\r
+                       _setfillmask(SFB14[cp]->lit[pre].lin+(a<<1)-8);\r
+                       _rectangle(_GFILLINTERIOR,176+((pre&15)<<3),224+(pre>>4)*14,183+((pre&15)<<3),223+(a<<1)+(pre>>4)*14);\r
                }\r
-               setfillpattern(SFB14[cp]->lit[pre].lin+(a<<1),BROWN);\r
-               bar(176+((pre&15)<<3),224+(a<<1)+(pre>>4)*14,183+((pre&15)<<3),231+(a<<1)+(pre>>4)*14);\r
+               _setfillmask(SFB14[cp]->lit[pre].lin+(a<<1));\r
+               _rectangle(_GFILLINTERIOR,176+((pre&15)<<3),224+(a<<1)+(pre>>4)*14,183+((pre&15)<<3),231+(a<<1)+(pre>>4)*14);\r
                if(a!=3)\r
                {\r
-                       setfillpattern(SFB14[cp]->lit[pre].lin+(a<<1)+8,BROWN);\r
-                       bar(176+((pre&15)<<3),232+(a<<1)+(pre>>4)*14,183+((pre&15)<<3),237+(pre>>4)*14);\r
+                       _setfillmask(SFB14[cp]->lit[pre].lin+(a<<1)+8);\r
+                       _rectangle(_GFILLINTERIOR,176+((pre&15)<<3),232+(a<<1)+(pre>>4)*14,183+((pre&15)<<3),237+(pre>>4)*14);\r
                }\r
        case 3:\r
        case 1:\r
-               setcolor(color2);\r
+               _setcolor(color2);\r
                ab[0]=abc[lit&15];\r
-               outtextxy(176+((lit&15)<<3),216,ab);\r
+               _moveto(176+((lit&15)<<3),216);_outgtext(ab);\r
                ab[0]=abc[lit>>4];\r
-               outtextxy(168,227+(lit>>4)*14,ab);\r
+               _moveto(168,227+(lit>>4)*14);_outgtext(ab);\r
                a=(lit>>4)&3;\r
+               _setcolor(color1);\r
                if(a)\r
                {\r
-                       setfillpattern(SFB14[cp]->lit[lit].lin+(a<<1)-8,color1);\r
-                       bar(176+((lit&15)<<3),224+(lit>>4)*14,183+((lit&15)<<3),223+(a<<1)+(lit>>4)*14);\r
+                       _setfillmask(SFB14[cp]->lit[lit].lin+(a<<1)-8);\r
+                       _rectangle(_GFILLINTERIOR,176+((lit&15)<<3),224+(lit>>4)*14,183+((lit&15)<<3),223+(a<<1)+(lit>>4)*14);\r
                }\r
-               setfillpattern(SFB14[cp]->lit[lit].lin+(a<<1),color1);\r
-               bar(176+((lit&15)<<3),224+(a<<1)+(lit>>4)*14,183+((lit&15)<<3),231+(a<<1)+(lit>>4)*14);\r
+               _setfillmask(SFB14[cp]->lit[lit].lin+(a<<1));\r
+               _rectangle(_GFILLINTERIOR,176+((lit&15)<<3),224+(a<<1)+(lit>>4)*14,183+((lit&15)<<3),231+(a<<1)+(lit>>4)*14);\r
                if(a!=3)\r
                {\r
-                       setfillpattern(SFB14[cp]->lit[lit].lin+(a<<1)+8,color1);\r
-                       bar(176+((lit&15)<<3),232+(a<<1)+(lit>>4)*14,183+((lit&15)<<3),237+(lit>>4)*14);\r
+                       _setfillmask(SFB14[cp]->lit[lit].lin+(a<<1)+8);\r
+                       _rectangle(_GFILLINTERIOR,176+((lit&15)<<3),232+(a<<1)+(lit>>4)*14,183+((lit&15)<<3),237+(lit>>4)*14);\r
                }               \r
                break;\r
        case 0:\r
        default:\r
+               _setfillmask(FULLF);\r
+               _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,176,224,303,447);\r
                for(l=0;l<16;++l)\r
                {\r
                        ab[0]=abc[l];\r
                        if((lit&15)==l)\r
-                               setcolor(color2);\r
+                               _setcolor(color2);\r
                        else\r
-                               setcolor(RED);\r
-                       outtextxy(176+(l<<3),216,ab);\r
+                               _setcolor(C_NON);\r
+                       _moveto(176+(l<<3),216);\r
+                       _outgtext(ab);\r
                        if(lit>>4==l)\r
-                               setcolor(color2);\r
+                               _setcolor(color2);\r
                        else\r
-                               setcolor(RED);\r
-                       outtextxy(168,227+l*14,ab);\r
+                               _setcolor(C_NON);\r
+                       _moveto(168,227+l*14);\r
+                       _outgtext(ab);\r
                }\r
                for(l=0;l<256;++l)\r
                {\r
                        a=(l>>4)&3;\r
                        if(l==lit)\r
+                               _setcolor(color1);\r
+                       else\r
+                               _setcolor(C_SET);\r
+                       if(a)\r
                        {\r
-                               if(a)\r
-                               {\r
-                                       setfillpattern(SFB14[cp]->lit[l].lin+(a<<1)-8,color1);\r
-                                       bar(176+((l&15)<<3),224+(l>>4)*14,183+((l&15)<<3),223+(a<<1)+(l>>4)*14);\r
-                               }\r
-                               setfillpattern(SFB14[cp]->lit[l].lin+(a<<1),color1);\r
-                               bar(176+((l&15)<<3),224+(a<<1)+(l>>4)*14,183+((l&15)<<3),231+(a<<1)+(l>>4)*14);\r
-                               if(a!=3)\r
-                               {\r
-                                       setfillpattern(SFB14[cp]->lit[l].lin+(a<<1)+8,color1);\r
-                                       bar(176+((l&15)<<3),232+(a<<1)+(l>>4)*14,183+((l&15)<<3),237+(l>>4)*14);\r
-                               }\r
+                               _setfillmask(SFB14[cp]->lit[l].lin+(a<<1)-8);\r
+                               _rectangle(_GFILLINTERIOR,176+((l&15)<<3),224+(l>>4)*14,183+((l&15)<<3),223+(a<<1)+(l>>4)*14);\r
                        }\r
-                       else\r
+                       _setfillmask(SFB14[cp]->lit[l].lin+(a<<1));\r
+                       _rectangle(_GFILLINTERIOR,176+((l&15)<<3),224+(a<<1)+(l>>4)*14,183+((l&15)<<3),231+(a<<1)+(l>>4)*14);\r
+                       if(a!=3)\r
                        {\r
-                               if(a)\r
-                               {\r
-                                       setfillpattern(SFB14[cp]->lit[l].lin+(a<<1)-8,BROWN);\r
-                                       bar(176+((l&15)<<3),224+(l>>4)*14,183+((l&15)<<3),223+(a<<1)+(l>>4)*14);\r
-                               }\r
-                               setfillpattern(SFB14[cp]->lit[l].lin+(a<<1),BROWN);\r
-                               bar(176+((l&15)<<3),224+(a<<1)+(l>>4)*14,183+((l&15)<<3),231+(a<<1)+(l>>4)*14);\r
-                               if(a!=3)\r
-                               {\r
-                                       setfillpattern(SFB14[cp]->lit[l].lin+(a<<1)+8,BROWN);\r
-                                       bar(176+((l&15)<<3),232+(a<<1)+(l>>4)*14,183+((l&15)<<3),237+(l>>4)*14);\r
-                               }\r
+                               _setfillmask(SFB14[cp]->lit[l].lin+(a<<1)+8);\r
+                               _rectangle(_GFILLINTERIOR,176+((l&15)<<3),232+(a<<1)+(l>>4)*14,183+((l&15)<<3),237+(l>>4)*14);\r
                        }\r
+                       \r
                }\r
                break;\r
        }\r
@@ -720,92 +796,100 @@ void lin16(int mode)
        if(mode==3)\r
        {\r
                if(SFB16[cp]->lit[lit].lin[cury]&(0x80>>curx))\r
-                       putpixel(496+curx+((lit&15)<<3),112+cury+((lit>>4)<<4),GREEN);\r
+                       _setcolor(C_SEL);\r
                else\r
-                       putpixel(496+curx+((lit&15)<<3),112+cury+((lit>>4)<<4),BLACK);\r
+                       _setcolor(BLACK);\r
+               _setpixel(496+curx+((lit&15)<<3),112+cury+((lit>>4)<<4));\r
                return;\r
        }\r
        char ab[2]="X";\r
-       int color1,color2;\r
+       short color1,color2;\r
        if(byo16[cp]==0)\r
        {\r
-               setfillstyle(WIDE_DOT_FILL,RED);\r
-               bar(496,112,623,367);\r
+               _setfillmask(FULLF);\r
+               _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,496,112,623,367);\r
+               _setfillmask(NOFONT);\r
+               _setcolor(C_NON);\r
+               _rectangle(_GFILLINTERIOR,496,112,623,367);\r
                return;\r
        }\r
        if(wys==16)\r
        {\r
-               color1=GREEN;\r
-               color2=GREEN;\r
+               color1=C_SEL;\r
+               color2=C_SEL;\r
        }\r
        else\r
        {\r
-               color1=BROWN;\r
-               color2=RED;\r
+               color1=C_SET;\r
+               color2=C_NON;\r
        }\r
        int l;\r
        switch(mode)\r
        {\r
        case 2:\r
-               setcolor(RED);\r
+               _setcolor(C_NON);\r
                if((pre&15)!=(lit&15))\r
                {\r
                        ab[0]=abc[pre&15];\r
-                       outtextxy(496+((pre&15)<<3),104,ab);\r
+                       _moveto(496+((pre&15)<<3),104);\r
+                       _outgtext(ab);\r
                }\r
                if(pre>>4!=lit>>4)\r
                {\r
                        ab[0]=abc[pre>>4];\r
-                       outtextxy(488,116+((pre>>4)<<4),ab);\r
-               }\r
-               setfillpattern(SFB16[cp]->lit[pre].lin,BROWN);\r
-               bar(496+((pre&15)<<3),112+((pre>>4)<<4),503+((pre&15)<<3),119+((pre>>4)<<4));\r
-               setfillpattern(SFB16[cp]->lit[pre].lin+8,BROWN);\r
-               bar(496+((pre&15)<<3),120+((pre>>4)<<4),503+((pre&15)<<3),127+((pre>>4)<<4));\r
+                       _moveto(488,116+((pre>>4)<<4));\r
+                       _outgtext(ab);\r
+               }\r
+               _setcolor(C_SET);\r
+               _setfillmask(SFB16[cp]->lit[pre].lin);\r
+               _rectangle(_GFILLINTERIOR,496+((pre&15)<<3),112+((pre>>4)<<4),503+((pre&15)<<3),119+((pre>>4)<<4));\r
+               _setfillmask(SFB16[cp]->lit[pre].lin+8);\r
+               _rectangle(_GFILLINTERIOR,496+((pre&15)<<3),120+((pre>>4)<<4),503+((pre&15)<<3),127+((pre>>4)<<4));\r
        case 3: \r
        case 1:\r
-               setcolor(color2);\r
+               _setcolor(color2);\r
                ab[0]=abc[lit&15];\r
-               outtextxy(496+((lit&15)<<3),104,ab);\r
+               _moveto(496+((lit&15)<<3),104);\r
+               _outgtext(ab);\r
                ab[0]=abc[lit>>4];\r
-               outtextxy(488,116+((lit>>4)<<4),ab);\r
-               setfillpattern(SFB16[cp]->lit[lit].lin,color1);\r
-               bar(496+((lit&15)<<3),112+((lit>>4)<<4),503+((lit&15)<<3),119+((lit>>4)<<4));\r
-               setfillpattern(SFB16[cp]->lit[lit].lin+8,color1);\r
-               bar(496+((lit&15)<<3),120+((lit>>4)<<4),503+((lit&15)<<3),127+((lit>>4)<<4));\r
+               _moveto(488,116+((lit>>4)<<4));\r
+               _outgtext(ab);\r
+               _setcolor(color1);\r
+               _setfillmask(SFB16[cp]->lit[lit].lin);\r
+               _rectangle(_GFILLINTERIOR,496+((lit&15)<<3),112+((lit>>4)<<4),503+((lit&15)<<3),119+((lit>>4)<<4));\r
+               _setfillmask(SFB16[cp]->lit[lit].lin+8);\r
+               _rectangle(_GFILLINTERIOR,496+((lit&15)<<3),120+((lit>>4)<<4),503+((lit&15)<<3),127+((lit>>4)<<4));\r
                break;\r
        case 0:\r
        default:\r
+               _setfillmask(FULLF);\r
+               _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,496,112,623,367);\r
                for(l=0;l<16;++l)\r
                {\r
                        ab[0]=abc[l];\r
                        if((lit&15)==l)\r
-                               setcolor(color2);\r
+                               _setcolor(color2);\r
                        else\r
-                               setcolor(RED);\r
-                       outtextxy(496+(l<<3),104,ab);\r
+                               _setcolor(C_NON);\r
+                       _moveto(496+(l<<3),104);_outgtext(ab);\r
                        if(lit>>4==l)\r
-                               setcolor(color2);\r
+                               _setcolor(color2);\r
                        else\r
-                               setcolor(RED);\r
-                       outtextxy(488,116+(l<<4),ab);\r
+                               _setcolor(C_NON);\r
+                       _moveto(488,116+(l<<4));_outgtext(ab);\r
                }\r
                for(l=0;l<256;++l)\r
                {\r
                        if(l==lit)\r
-                       {\r
-                               setfillpattern(SFB16[cp]->lit[l].lin,color1);\r
-                               bar(496+((l&15)<<3),112+((l>>4)<<4),503+((l&15)<<3),119+((l>>4)<<4));\r
-                               setfillpattern(SFB16[cp]->lit[l].lin+8,color1);\r
-                               bar(496+((l&15)<<3),120+((l>>4)<<4),503+((l&15)<<3),127+((l>>4)<<4));\r
-                       }\r
+                               _setcolor(color1);\r
                        else\r
-                       {\r
-                               setfillpattern(SFB16[cp]->lit[l].lin,BROWN);\r
-                               bar(496+((l&15)<<3),112+((l>>4)<<4),503+((l&15)<<3),119+((l>>4)<<4));\r
-                               setfillpattern(SFB16[cp]->lit[l].lin+8,BROWN);\r
-                               bar(496+((l&15)<<3),120+((l>>4)<<4),503+((l&15)<<3),127+((l>>4)<<4));\r
-                       }\r
+                               _setcolor(C_SET);\r
+                       _setfillmask(SFB16[cp]->lit[l].lin);\r
+                       _rectangle(_GFILLINTERIOR,496+((l&15)<<3),112+((l>>4)<<4),503+((l&15)<<3),119+((l>>4)<<4));\r
+                       _setfillmask(SFB16[cp]->lit[l].lin+8);\r
+                       _rectangle(_GFILLINTERIOR,496+((l&15)<<3),120+((l>>4)<<4),503+((l&15)<<3),127+((l>>4)<<4));\r
                }\r
                break;\r
        }\r
@@ -814,72 +898,69 @@ void lit8(int mode)
 {\r
        if(!any)\r
                return;\r
-       int color;\r
-       setcolor(RED);\r
+       short color;\r
+       _setcolor(C_NON);\r
        if(byo8[cp]==0)\r
        {\r
-               setfillstyle(WIDE_DOT_FILL,RED);\r
-               bar(16,32,143,159);\r
+               _setfillmask(FULLF);\r
+               _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,16,32,143,159);\r
+               _setfillmask(NOFONT);\r
+               _setcolor(C_NON);\r
+               _rectangle(_GFILLINTERIOR,16,32,143,159);\r
                return;\r
        }\r
        char ab[2]="q";\r
        if(wys==8)\r
-               color=GREEN;\r
+               color=C_SEL;\r
        else\r
-               color=RED;\r
+               color=C_NON;\r
+       _setfillmask(FULLF);\r
        switch(mode)\r
        {\r
        case 2:\r
-               setcolor(RED);\r
+               _setcolor(C_NON);\r
                if(curx!=prex)\r
                {\r
                        ab[0]=abc[prex];\r
-                       outtextxy(20+(prex<<4),24,ab);\r
+                       _moveto(20+(prex<<4),24);\r
+                       _outgtext(ab);\r
                }\r
                if(prey<8)\r
                {\r
                        if(cury!=prey)\r
                        {\r
                                ab[0]=abc[prey];\r
-                               outtextxy(8,36+(prey<<4),ab);\r
+                               _moveto(8,36+(prey<<4));\r
+                               _outgtext(ab);\r
                        }\r
                        if(SFB8[cp]->lit[lit].lin[prey]&(0x80>>prex))\r
-                       {\r
-                               setcolor(BROWN);\r
-                               setfillstyle(SOLID_FILL,BROWN);\r
-                       }\r
+                               _setcolor(C_SET);\r
                        else\r
-                       {\r
-                               setcolor(BLACK);\r
-                               setfillstyle(SOLID_FILL,BLACK);\r
-                       }\r
-                       bar(16+(prex<<4),32+(prey<<4),31+(prex<<4),47+(prey<<4));\r
+                               _setcolor(BLACK);\r
+                       _rectangle(_GFILLINTERIOR,16+(prex<<4),32+(prey<<4),31+(prex<<4),47+(prey<<4));\r
                }\r
        case 1:\r
-               setcolor(color);\r
+               _setcolor(color);\r
                ab[0]=abc[curx];\r
-               outtextxy(20+(curx<<4),24,ab);\r
+               _moveto(20+(curx<<4),24);\r
+               _outgtext(ab);\r
                if(cury<8)\r
-                       {\r
+               {\r
                        ab[0]=abc[cury];\r
-                       outtextxy(8,36+(cury<<4),ab);\r
+                       _moveto(8,36+(cury<<4));\r
+                       _outgtext(ab);\r
                        if(SFB8[cp]->lit[lit].lin[cury]&(0x80>>curx))\r
-                       {\r
-                               setcolor(BROWN);\r
-                               setfillstyle(SOLID_FILL,BROWN);\r
-                       }\r
+                               _setcolor(C_SET);\r
                        else\r
-                       {\r
-                               setcolor(BLACK);\r
-                               setfillstyle(SOLID_FILL,BLACK);\r
-                       }\r
-                       bar(16+(curx<<4),32+(cury<<4),31+(curx<<4),47+(cury<<4));\r
+                               _setcolor(BLACK);\r
+                       _rectangle(_GFILLINTERIOR,16+(curx<<4),32+(cury<<4),31+(curx<<4),47+(cury<<4));\r
                        if(wys==8)\r
                        {\r
-                               setcolor(GREEN);\r
-                               rectangle(16+(curx<<4),32+(cury<<4),31+(curx<<4),47+(cury<<4));\r
-                               setcolor(BLACK);\r
-                               rectangle(17+(curx<<4),33+(cury<<4),30+(curx<<4),46+(cury<<4));\r
+                               _setcolor(C_SEL);\r
+                               _rectangle(_GBORDER,16+(curx<<4),32+(cury<<4),31+(curx<<4),47+(cury<<4));\r
+                               _setcolor(BLACK);\r
+                               _rectangle(_GBORDER,17+(curx<<4),33+(cury<<4),30+(curx<<4),46+(cury<<4));\r
                        }\r
                }\r
                break;\r
@@ -888,42 +969,38 @@ void lit8(int mode)
                for(int l=0;l<8;++l)\r
                {\r
                        if(l==curx)\r
-                               setcolor(color);\r
+                               _setcolor(color);\r
                        else\r
-                               setcolor(RED);\r
+                               _setcolor(C_NON);\r
                        ab[0]=abc[l];\r
                        \r
-                       outtextxy(20+(l<<4),24,ab);\r
+                       _moveto(20+(l<<4),24);\r
+                       _outgtext(ab);\r
                        if(l==cury)\r
-                               setcolor(color);\r
+                               _setcolor(color);\r
                        else\r
-                               setcolor(RED);\r
+                               _setcolor(C_NON);\r
                        ab[0]=abc[l];\r
-                       outtextxy(8,36+(l<<4),ab);\r
+                       _moveto(8,36+(l<<4));\r
+                       _outgtext(ab);\r
                }\r
                for(int a=0;a<8;++a)\r
                {\r
                        for(int b=0;b<8;++b)\r
                        {\r
                                if(SFB8[cp]->lit[lit].lin[a]&(0x80>>b))\r
-                               {\r
-                                       setcolor(BROWN);\r
-                                       setfillstyle(SOLID_FILL,BROWN);\r
-                               }\r
+                                       _setcolor(C_SET);\r
                                else\r
-                               {\r
-                                       setcolor(BLACK);\r
-                                       setfillstyle(SOLID_FILL,BLACK);\r
-                               }\r
-                               bar(16+(b<<4),32+(a<<4),31+(b<<4),47+(a<<4));\r
+                                       _setcolor(BLACK);\r
+                               _rectangle(_GFILLINTERIOR,16+(b<<4),32+(a<<4),31+(b<<4),47+(a<<4));\r
                        }\r
                }\r
                if(wys==8)\r
                {\r
-                       setcolor(GREEN);\r
-                       rectangle(16+(curx<<4),32+(cury<<4),31+(curx<<4),47+(cury<<4));\r
-                       setcolor(BLACK);\r
-                       rectangle(17+(curx<<4),33+(cury<<4),30+(curx<<4),46+(cury<<4));\r
+                       _setcolor(C_SEL);\r
+                       _rectangle(_GBORDER,16+(curx<<4),32+(cury<<4),31+(curx<<4),47+(cury<<4));\r
+                       _setcolor(BLACK);\r
+                       _rectangle(_GBORDER,17+(curx<<4),33+(cury<<4),30+(curx<<4),46+(cury<<4));\r
                }\r
                break;\r
        }\r
@@ -932,72 +1009,69 @@ void lit14(int mode)
 {\r
        if(!any)\r
                return;\r
-       int color;\r
-       setcolor(RED);\r
+       short color;\r
+       _setcolor(C_NON);\r
        if(byo14[cp]==0)\r
        {\r
-               setfillstyle(WIDE_DOT_FILL,RED);\r
-               bar(16,224,143,447);\r
+               _setfillmask(FULLF);\r
+               _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,16,224,143,447);\r
+               _setfillmask(NOFONT);\r
+               _setcolor(C_NON);\r
+               _rectangle(_GFILLINTERIOR,16,224,143,447);\r
                return;\r
        }\r
        char ab[2]="q";\r
        if(wys==14)\r
-               color=GREEN;\r
+               color=C_SEL;\r
        else\r
-               color=RED;\r
+               color=C_NON;\r
+       _setfillmask(FULLF);\r
        switch(mode)\r
        {\r
        case 2:\r
-               setcolor(RED);\r
+               _setcolor(C_NON);\r
                if(curx!=prex)\r
                {\r
                        ab[0]=abc[prex];\r
-                       outtextxy(20+(prex<<4),216,ab);\r
+                       _moveto(20+(prex<<4),216);\r
+                       _outgtext(ab);\r
                }\r
                if(prey<14)\r
                {\r
                        if(cury!=prey)\r
                        {\r
                                ab[0]=abc[prey];\r
-                               outtextxy(8,228+(prey<<4),ab);\r
+                               _moveto(8,228+(prey<<4));\r
+                               _outgtext(ab);\r
                        }\r
                        if(SFB14[cp]->lit[lit].lin[prey]&(0x80>>prex))\r
-                       {\r
-                               setcolor(BROWN);\r
-                               setfillstyle(SOLID_FILL,BROWN);\r
-                       }\r
+                               _setcolor(C_SET);\r
                        else\r
-                       {\r
-                               setcolor(BLACK);\r
-                               setfillstyle(SOLID_FILL,BLACK);\r
-                       }\r
-                       bar(16+(prex<<4),224+(prey<<4),31+(prex<<4),239+(prey<<4));\r
+                               _setcolor(BLACK);\r
+                       _rectangle(_GFILLINTERIOR,16+(prex<<4),224+(prey<<4),31+(prex<<4),239+(prey<<4));\r
                }\r
        case 1:\r
-               setcolor(color);\r
+               _setcolor(color);\r
                ab[0]=abc[curx];\r
-               outtextxy(20+(curx<<4),216,ab);\r
+               _moveto(20+(curx<<4),216);\r
+               _outgtext(ab);\r
                if(cury<14)\r
                {\r
                        ab[0]=abc[cury];\r
-                       outtextxy(8,228+(cury<<4),ab);\r
+                       _moveto(8,228+(cury<<4));\r
+                       _outgtext(ab);\r
                        if(SFB14[cp]->lit[lit].lin[cury]&(0x80>>curx))\r
-                       {\r
-                               setcolor(BROWN);\r
-                               setfillstyle(SOLID_FILL,BROWN);\r
-                       }\r
+                               _setcolor(C_SET);\r
                        else\r
-                       {\r
-                               setcolor(BLACK);\r
-                               setfillstyle(SOLID_FILL,BLACK);\r
-                       }\r
-                       bar(16+(curx<<4),224+(cury<<4),31+(curx<<4),239+(cury<<4));\r
+                               _setcolor(BLACK);\r
+                       _rectangle(_GFILLINTERIOR,16+(curx<<4),224+(cury<<4),31+(curx<<4),239+(cury<<4));\r
                        if(wys==14)\r
                        {\r
-                               setcolor(GREEN);\r
-                               rectangle(16+(curx<<4),224+(cury<<4),31+(curx<<4),239+(cury<<4));\r
-                               setcolor(BLACK);\r
-                               rectangle(17+(curx<<4),225+(cury<<4),30+(curx<<4),238+(cury<<4));\r
+                               _setcolor(C_SEL);\r
+                               _rectangle(_GBORDER,16+(curx<<4),224+(cury<<4),31+(curx<<4),239+(cury<<4));\r
+                               _setcolor(BLACK);\r
+                               _rectangle(_GBORDER,17+(curx<<4),225+(cury<<4),30+(curx<<4),238+(cury<<4));\r
                        }\r
                }\r
                break;\r
@@ -1006,42 +1080,40 @@ void lit14(int mode)
                for(int l=0;l<14;++l)\r
                {\r
                        if(l==curx)\r
-                               setcolor(color);\r
+                               _setcolor(color);\r
                        else\r
-                               setcolor(RED);\r
+                               _setcolor(C_NON);\r
                        ab[0]=abc[l];\r
                        if(l<8)\r
-                               outtextxy(20+(l<<4),216,ab);\r
+                       {\r
+                               _moveto(20+(l<<4),216);\r
+                               _outgtext(ab);\r
+                       }\r
                        if(l==cury)\r
-                               setcolor(color);\r
+                               _setcolor(color);\r
                        else\r
-                               setcolor(RED);\r
+                               _setcolor(C_NON);\r
                        ab[0]=abc[l];\r
-                       outtextxy(8,228+(l<<4),ab);\r
+                       _moveto(8,228+(l<<4));\r
+                       _outgtext(ab);\r
                }\r
                for(int a=0;a<14;++a)\r
                {\r
                        for(int b=0;b<8;++b)\r
                        {\r
                                if(SFB14[cp]->lit[lit].lin[a]&(0x80>>b))\r
-                               {\r
-                                       setcolor(BROWN);\r
-                                       setfillstyle(SOLID_FILL,BROWN);\r
-                               }\r
+                                       _setcolor(C_SET);\r
                                else\r
-                               {\r
-                                       setcolor(BLACK);\r
-                                       setfillstyle(SOLID_FILL,BLACK);\r
-                               }\r
-                               bar(16+(b<<4),224+(a<<4),31+(b<<4),239+(a<<4));                         \r
+                                       _setcolor(BLACK);\r
+                               _rectangle(_GFILLINTERIOR,16+(b<<4),224+(a<<4),31+(b<<4),239+(a<<4));                           \r
                        }\r
                }\r
                if(wys==14)\r
                {\r
-                       setcolor(GREEN);\r
-                       rectangle(16+(curx<<4),224+(cury<<4),31+(curx<<4),239+(cury<<4));\r
-                       setcolor(BLACK);\r
-                       rectangle(17+(curx<<4),225+(cury<<4),30+(curx<<4),238+(cury<<4));\r
+                       _setcolor(C_SEL);\r
+                       _rectangle(_GBORDER,16+(curx<<4),224+(cury<<4),31+(curx<<4),239+(cury<<4));\r
+                       _setcolor(BLACK);\r
+                       _rectangle(_GBORDER,17+(curx<<4),225+(cury<<4),30+(curx<<4),238+(cury<<4));\r
                }\r
                break;\r
        }\r
@@ -1050,67 +1122,64 @@ void lit16(int mode)
 {\r
        if(!any)\r
                return;\r
-       int color;\r
-       setcolor(RED);\r
+       short color;\r
+       _setcolor(C_NON);\r
        if(byo16[cp]==0)\r
        {\r
-               setfillstyle(WIDE_DOT_FILL,RED);\r
-               bar(336,112,463,367);\r
+               _setfillmask(FULLF);\r
+               _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,336,112,463,367);\r
+               _setfillmask(NOFONT);\r
+               _setcolor(C_NON);\r
+               _rectangle(_GFILLINTERIOR,336,112,463,367);\r
                return;\r
        }\r
        char ab[2]="q";\r
        if(wys==16)\r
-               color=GREEN;\r
+               color=C_SEL;\r
        else\r
-               color=RED;\r
+               color=C_NON;\r
+       _setfillmask(FULLF);\r
        switch(mode)\r
        {\r
        case 2:\r
-               setcolor(RED);\r
+               _setcolor(C_NON);\r
                if(curx!=prex)\r
                {\r
                        ab[0]=abc[prex];\r
-                       outtextxy(340+(prex<<4),104,ab);\r
+                       _moveto(340+(prex<<4),104);\r
+                       _outgtext(ab);\r
                }\r
                if(cury!=prey)\r
                {\r
                        ab[0]=abc[prey];\r
-                       outtextxy(328,116+(prey<<4),ab);\r
+                       _moveto(328,116+(prey<<4));\r
+                       _outgtext(ab);\r
                }\r
                if(SFB16[cp]->lit[lit].lin[prey]&(0x80>>prex))\r
-               {\r
-                       setcolor(BROWN);\r
-                       setfillstyle(SOLID_FILL,BROWN);\r
-               }\r
+                       _setcolor(C_SET);\r
                else\r
-               {\r
-                       setcolor(BLACK);\r
-                       setfillstyle(SOLID_FILL,BLACK);\r
-               }\r
-               bar(336+(prex<<4),112+(prey<<4),351+(prex<<4),127+(prey<<4));\r
+                       _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,336+(prex<<4),112+(prey<<4),351+(prex<<4),127+(prey<<4));\r
        case 1:\r
-               setcolor(color);\r
+               _setcolor(color);\r
                ab[0]=abc[curx];\r
-               outtextxy(340+(curx<<4),104,ab);\r
+               _moveto(340+(curx<<4),104);\r
+               _outgtext(ab);\r
                ab[0]=abc[cury];\r
-               outtextxy(328,116+(cury<<4),ab);\r
+               _moveto(328,116+(cury<<4));\r
+               _outgtext(ab);\r
                if(SFB16[cp]->lit[lit].lin[cury]&(0x80>>curx))\r
-               {\r
-                       setcolor(BROWN);\r
-                       setfillstyle(SOLID_FILL,BROWN);\r
-               }\r
+                       _setcolor(C_SET);\r
                else\r
-               {\r
-                       setcolor(BLACK);\r
-                       setfillstyle(SOLID_FILL,BLACK);\r
-               }\r
-               bar(336+(curx<<4),112+(cury<<4),351+(curx<<4),127+(cury<<4));           \r
+                       _setcolor(BLACK);\r
+               _rectangle(_GFILLINTERIOR,336+(curx<<4),112+(cury<<4),351+(curx<<4),127+(cury<<4));             \r
                if(wys==16)\r
                {\r
-                       setcolor(GREEN);\r
-                       rectangle(336+(curx<<4),112+(cury<<4),351+(curx<<4),127+(cury<<4));\r
-                       setcolor(BLACK);\r
-                       rectangle(337+(curx<<4),113+(cury<<4),350+(curx<<4),126+(cury<<4));\r
+                       _setcolor(C_SEL);\r
+                       _rectangle(_GBORDER,336+(curx<<4),112+(cury<<4),351+(curx<<4),127+(cury<<4));\r
+                       _setcolor(BLACK);\r
+                       _rectangle(_GBORDER,337+(curx<<4),113+(cury<<4),350+(curx<<4),126+(cury<<4));\r
                }\r
                break;\r
        case 0:\r
@@ -1118,42 +1187,40 @@ void lit16(int mode)
                for(int l=0;l<16;++l)\r
                {\r
                        if(l==curx)\r
-                               setcolor(color);\r
+                               _setcolor(color);\r
                        else\r
-                               setcolor(RED);\r
+                               _setcolor(C_NON);\r
                        ab[0]=abc[l];\r
                        if(l<8)\r
-                               outtextxy(340+(l<<4),104,ab);\r
+                       {\r
+                               _moveto(340+(l<<4),104);\r
+                               _outgtext(ab);\r
+                       }\r
                        if(l==cury)\r
-                               setcolor(color);\r
+                               _setcolor(color);\r
                        else\r
-                               setcolor(RED);\r
+                               _setcolor(C_NON);\r
                        ab[0]=abc[l];\r
-                       outtextxy(328,116+(l<<4),ab);\r
+                       _moveto(328,116+(l<<4));\r
+                       _outgtext(ab);\r
                }\r
                for(int a=0;a<16;++a)\r
                {\r
                        for(int b=0;b<8;++b)\r
                        {\r
                                if(SFB16[cp]->lit[lit].lin[a]&(0x80>>b))\r
-                               {\r
-                                       setcolor(BROWN);\r
-                                       setfillstyle(SOLID_FILL,BROWN);\r
-                               }\r
+                                       _setcolor(C_SET);\r
                                else\r
-                               {\r
-                                       setcolor(BLACK);\r
-                                       setfillstyle(SOLID_FILL,BLACK);\r
-                               }\r
-                               bar(336+(b<<4),112+(a<<4),351+(b<<4),127+(a<<4));\r
+                                       _setcolor(BLACK);\r
+                               _rectangle(_GFILLINTERIOR,336+(b<<4),112+(a<<4),351+(b<<4),127+(a<<4));\r
                        }\r
                }\r
                if(wys==16)\r
                {\r
-                       setcolor(GREEN);\r
-                       rectangle(336+(curx<<4),112+(cury<<4),351+(curx<<4),127+(cury<<4));\r
-                       setcolor(BLACK);\r
-                       rectangle(337+(curx<<4),113+(cury<<4),350+(curx<<4),126+(cury<<4));\r
+                       _setcolor(C_SEL);\r
+                       _rectangle(_GBORDER,336+(curx<<4),112+(cury<<4),351+(curx<<4),127+(cury<<4));\r
+                       _setcolor(BLACK);\r
+                       _rectangle(_GBORDER,337+(curx<<4),113+(cury<<4),350+(curx<<4),126+(cury<<4));\r
                }\r
        }\r
 }\r
@@ -1204,14 +1271,15 @@ int otw2()
 {\r
        int a;\r
        int b;\r
-       int c;\r
-       int d;\r
-       int NT;\r
+       //int c;\r
+       //int d;\r
+       bool NT=false;\r
+       bool CPX=false;\r
        \r
        CPI=fopen(nazwap,"rb");\r
        if(CPI==NULL)\r
        {\r
-               sprintf(err,"100:No valid file at this path");\r
+               sprintf(err,"100:No valid file at this path\n");\r
                return 100;\r
        }\r
        else\r
@@ -1220,45 +1288,91 @@ int otw2()
        FFH=new FontFileHeader;\r
        if(!FFH)\r
        {\r
-               sprintf(err,"116:Not enough memory for FFH");\r
+               sprintf(err,"116:Not enough memory for FFH\n");\r
                fclose(CPI);\r
                return 116;\r
        }\r
        fread(FFH,0x19,1,CPI);\r
        if(FFH->id0!=0xff)\r
        {\r
-               sprintf(err,"101:Unsupported format, id0=0x%02x",(short)(FFH->id0&0xff));\r
-               fclose(CPI);\r
-               deleteCPI(0);\r
-               return 101;\r
+               if(FFH->id0==0x81&&FFH->id[0]==0xfc)//maybe it's a CPX?\r
+               {\r
+                       fclose(CPI);\r
+                       deleteCPI(0);\r
+                       status=spawnlp(P_WAIT,"cpx2cpi","cpx2cpi",nazwap,"tempcpi","q",NULL);\r
+                       if(status)\r
+                       {\r
+                               sprintf(err,"101:Unsupported format, id0=0x81\n");\r
+                               if (status<3)\r
+                                       remove("tempcpi");\r
+                               return 101;\r
+                       }\r
+                       CPX=true;\r
+                       CPI=fopen("tempcpi","rb");\r
+                       if(CPI==NULL)\r
+                       {\r
+                               sprintf(err,"101:Unsupported format, id0=0x81\n");\r
+                               return 101;\r
+                       }\r
+                       FFH=new FontFileHeader;\r
+                       if(!FFH)\r
+                       {\r
+                               sprintf(err,"116:Not enough memory for FFH\n");\r
+                               fclose(CPI);\r
+                               remove("tempcpi");\r
+                               return 116;\r
+                       }\r
+                       fread(FFH,0x19,1,CPI);\r
+                       if(FFH->id0!=0xff)\r
+                       {\r
+                               sprintf(err,"101:Unsupported format, id0=0x%02x\n",(short)(FFH->id0&0xff));\r
+                               fclose(CPI);\r
+                               remove("tempcpi");\r
+                               deleteCPI(0);\r
+                               return 101;\r
+                       }\r
+               }\r
+               else\r
+               {\r
+                       sprintf(err,"101:Unsupported format, id0=0x%02x\n",(short)(FFH->id0&0xff));\r
+                       fclose(CPI);\r
+                       deleteCPI(0);\r
+                       return 101;\r
+               }\r
        }\r
-       if(!strcmp("FONT   ",FFH->id))\r
-               NT=0;\r
-       else if(!strcmp("FONT.NT",FFH->id))\r
+       if(!strcmp("FONT   ",(char *)(FFH->id)))\r
+               ;\r
+       else if(!strcmp("FONT.NT",(char *)(FFH->id)))\r
        {\r
-               NT=1;\r
+               NT=true;\r
                FFH->id[4]=' ';\r
                FFH->id[5]=' ';\r
                FFH->id[6]=' ';\r
        }\r
        else\r
        {\r
-               sprintf(err,"102:Unsupported format, id=\"%c%c%c%c%c%c%c\"",FFH->id[0],FFH->id[1],FFH->id[2],FFH->id[3],FFH->id[4],FFH->id[5],FFH->id[6]);\r
+               sprintf(err,"102:Unsupported format, id=\"%c%c%c%c%c%c%c\"\n",FFH->id[0],FFH->id[1],FFH->id[2],FFH->id[3],FFH->id[4],FFH->id[5],FFH->id[6]);\r
                fclose(CPI);\r
+               if(CPX)\r
+                       remove("tempcpi");\r
                deleteCPI(0);\r
                return 102;\r
        }\r
        if(FFH->pnum!=1)\r
        {\r
-               sprintf(err,"103:Wrong no. of pointers (%u)",FFH->pnum);\r
+               sprintf(err,"103:Wrong no. of pointers (%u)\n",FFH->pnum);\r
                fclose(CPI);\r
+               if(CPX)\r
+                       remove("tempcpi");\r
                deleteCPI(0);\r
                return 103;\r
        }\r
        if(FFH->ptyp!=1)\r
        {\r
-               sprintf(err,"104:Wrong pointer type, (%u)",(short)(FFH->ptyp&0xff));\r
+               sprintf(err,"104:Wrong pointer type, (%u)\n",(short)(FFH->ptyp&0xff));\r
                fclose(CPI);\r
+               if(CPX)\r
+                       remove("tempcpi");\r
                deleteCPI(0);\r
                return 104;\r
        }\r
@@ -1266,8 +1380,10 @@ int otw2()
        FIH=new FontInfoHeader;\r
        if(!FIH)\r
        {\r
-               sprintf(err,"116:Not enough memory for FIH");\r
+               sprintf(err,"116:Not enough memory for FIH\n");\r
                fclose(CPI);\r
+               if(CPX)\r
+                       remove("tempcpi");\r
                deleteCPI(0);\r
                return 116;\r
        }\r
@@ -1275,15 +1391,19 @@ int otw2()
        fread(FIH,0x2,1,CPI);\r
        if(FIH->num_codepages>16)\r
        {\r
-               sprintf(err,"105:Too many codepages (%u)",FIH->num_codepages);\r
+               sprintf(err,"105:Too many codepages (%u)\n",FIH->num_codepages);\r
                fclose(CPI);\r
+               if(CPX)\r
+                       remove("tempcpi");\r
                deleteCPI(1);\r
                return 105;\r
        }\r
        if(FIH->num_codepages==0)\r
        {\r
-               sprintf(err,"117:No codepages");\r
+               sprintf(err,"117:No codepages\n");\r
                fclose(CPI);\r
+               if(CPX)\r
+                       remove("tempcpi");\r
                deleteCPI(1);\r
                return 117;\r
        }\r
@@ -1295,7 +1415,10 @@ int otw2()
                CPEH[a] = new CodePageEntryHeader;\r
                if(!CPEH[a])\r
                {\r
-                       sprintf(err,"116:Not enough memory for CPEH[%d]",a);\r
+                       sprintf(err,"116:Not enough memory for CPEH[%d]\n",a);\r
+                       fclose(CPI);\r
+                       if(CPX)\r
+                               remove("tempcpi");\r
                        deleteCPI(1);\r
                        return 116;\r
                }\r
@@ -1307,15 +1430,19 @@ int otw2()
                }\r
                if(CPEH[a]->cpeh_size!=0x1c)\r
                {\r
-                       sprintf(err,"106:Wrong CPEH[%u] size (0x%x)",a,CPEH[a]->cpeh_size);\r
+                       sprintf(err,"106:Wrong CPEH[%u] size (0x%x)\n",a,CPEH[a]->cpeh_size);\r
                        fclose(CPI);\r
+                       if(CPX)\r
+                               remove("tempcpi");\r
                        deleteCPI(2,a);\r
                        return 106;\r
                }\r
                if(CPEH[a]->device_type!=1)\r
                {\r
-                       sprintf(err,"107:Wrong device type(%u) in CPEH[%u]",CPEH[a]->device_type,a);\r
+                       sprintf(err,"107:Wrong device type(%u) in CPEH[%u]\n",CPEH[a]->device_type,a);\r
                        fclose(CPI);\r
+                       if(CPX)\r
+                               remove("tempcpi");\r
                        deleteCPI(2,a);\r
                        return 107;\r
                }\r
@@ -1323,8 +1450,10 @@ int otw2()
                {\r
                        if(CPEH[a]->codepage==CPEH[i]->codepage)\r
                        {\r
-                               sprintf(err,"114:cp%03u (%u) already in CPEH[%u]",CPEH[a]->codepage,a,i);\r
+                               sprintf(err,"114:cp%03u (%u) already in CPEH[%u]\n",CPEH[a]->codepage,a,i);\r
                                fclose(CPI);\r
+                               if(CPX)\r
+                                       remove("tempcpi");\r
                                deleteCPI(2,a);\r
                                return 114;\r
                        }\r
@@ -1334,30 +1463,38 @@ int otw2()
                CPIH[a] = new CodePageInfoHeader;\r
                if(!CPIH[a])\r
                {\r
-                       sprintf(err,"116:Not enough memory for CPIH[%d]",a);\r
+                       sprintf(err,"116:Not enough memory for CPIH[%d]\n",a);\r
                        fclose(CPI);\r
+                       if(CPX)\r
+                               remove("tempcpi");\r
                        deleteCPI(2,a);\r
                        return 116;\r
                }\r
                fread(CPIH[a],0x6,1,CPI);\r
                if(CPIH[a]->version!=1)\r
                {\r
-                       sprintf(err,"108:Wrong version of CPIH[%u] (%u)",a,CPIH[a]->version);\r
+                       sprintf(err,"108:Wrong version of CPIH[%u] (%u)\n",a,CPIH[a]->version);\r
                        fclose(CPI);\r
+                       if(CPX)\r
+                               remove("tempcpi");\r
                        deleteCPI(3,a);\r
                        return 108;\r
                }\r
                if(CPIH[a]->num_fonts>3)\r
                {\r
-                       sprintf(err,"109:Too many fonts in CPIH[%u] (%u)",a,CPIH[a]->num_fonts);\r
+                       sprintf(err,"109:Too many fonts in CPIH[%u] (%u)\n",a,CPIH[a]->num_fonts);\r
                        fclose(CPI);\r
+                       if(CPX)\r
+                               remove("tempcpi");\r
                        deleteCPI(3,a);\r
                        return 109;\r
                }\r
                if(CPIH[a]->num_fonts==0)\r
                {\r
-                       sprintf(err,"115:No fonts in CPIH[%u])",a);\r
+                       sprintf(err,"115:No fonts in CPIH[%u])\n",a);\r
                        fclose(CPI);\r
+                       if(CPX)\r
+                               remove("tempcpi");\r
                        deleteCPI(3,a);\r
                        return 115;\r
                }\r
@@ -1367,8 +1504,10 @@ int otw2()
                        SFH[a][b] = new ScreenFontHeader;\r
                        if(!SFH[a][b])\r
                        {\r
-                               sprintf(err,"116:Not enough memory for SFH[%d][%d]",a);\r
+                               sprintf(err,"116:Not enough memory for SFH[%d][%d]\n",a);\r
                                fclose(CPI);\r
+                               if(CPX)\r
+                                       remove("tempcpi");\r
                                if(b==0)\r
                                        deleteCPI(3,a);\r
                                else\r
@@ -1380,8 +1519,10 @@ int otw2()
                        {\r
                                if (byo8[a]!=0)\r
                                {\r
-                                       sprintf(err,"113:Height 8 already in cp%03u (%u;%u)",CPEH[a]->codepage,a,b);\r
+                                       sprintf(err,"113:Height 8 already in cp%03u (%u;%u)\n",CPEH[a]->codepage,a,b);\r
                                        fclose(CPI);\r
+                                       if(CPX)\r
+                                               remove("tempcpi");\r
                                        deleteCPI(4,a,b);\r
                                        return 113;\r
                                }\r
@@ -1391,8 +1532,10 @@ int otw2()
                        {\r
                                if (byo14[a]!=0)\r
                                {\r
-                                       sprintf(err,"113:Height 14 already in cp%03u (%u;%u)",CPEH[a]->codepage,a,b);\r
+                                       sprintf(err,"113:Height 14 already in cp%03u (%u;%u)\n",CPEH[a]->codepage,a,b);\r
                                        fclose(CPI);\r
+                                       if(CPX)\r
+                                               remove("tempcpi");\r
                                        deleteCPI(4,a,b);\r
                                        return 113;\r
                                }\r
@@ -1402,8 +1545,10 @@ int otw2()
                        {\r
                                if (byo16[a]!=0)\r
                                {\r
-                                       sprintf(err,"113:Height 16 already in cp%03u (%u;%u)",CPEH[a]->codepage,a,b);\r
+                                       sprintf(err,"113:Height 16 already in cp%03u (%u;%u)\n",CPEH[a]->codepage,a,b);\r
                                        fclose(CPI);\r
+                                       if(CPX)\r
+                                               remove("tempcpi");\r
                                        deleteCPI(4,a,b);\r
                                        return 113;\r
                                }\r
@@ -1411,22 +1556,28 @@ int otw2()
                        }\r
                        if(SFH[a][b]->height!=8&&SFH[a][b]->height!=14&&SFH[a][b]->height!=16)\r
                        {\r
-                               sprintf(err,"110:Wrong height (%u) in SFH[%u][%u]",(short)(SFH[a][b]->height&0xff),a,b);\r
+                               sprintf(err,"110:Wrong height (%u) in SFH[%u][%u]\n",(short)(SFH[a][b]->height&0xff),a,b);\r
                                fclose(CPI);\r
+                               if(CPX)\r
+                                       remove("tempcpi");\r
                                deleteCPI(4,a,b);\r
                                return 110;\r
                        }\r
                        if(SFH[a][b]->width!=8)\r
                        {\r
-                               sprintf(err,"111:Wrong width (%u) in SFH[%u][%u]",(short)(SFH[a][b]->width&0xff),a,b);\r
+                               sprintf(err,"111:Wrong width (%u) in SFH[%u][%u]\n",(short)(SFH[a][b]->width&0xff),a,b);\r
                                fclose(CPI);\r
+                               if(CPX)\r
+                                       remove("tempcpi");\r
                                deleteCPI(4,a,b);\r
                                return 111;\r
                        }\r
                        if(SFH[a][b]->num_chars!=256)\r
                        {\r
-                               sprintf(err,"112:Wrong no.of chars(%u)in SFH[%u][%u]",SFH[a][b]->num_chars,a,b);\r
+                               sprintf(err,"112:Wrong no.of chars(%u)in SFH[%u][%u]\n",SFH[a][b]->num_chars,a,b);\r
                                fclose(CPI);\r
+                               if(CPX)\r
+                                       remove("tempcpi");\r
                                deleteCPI(4,a,b);\r
                                return 112;\r
                        }\r
@@ -1435,8 +1586,10 @@ int otw2()
                                SFB16[a] = new ScreenFontBitmap16;\r
                                if(!SFB16[a])\r
                                {\r
-                                       sprintf(err,"116:Not enough memory for SFB16[%d] (%d)",a,b);\r
+                                       sprintf(err,"116:Not enough memory for SFB16[%d] (%d)\n",a,b);\r
                                        fclose(CPI);\r
+                                       if(CPX)\r
+                                               remove("tempcpi");\r
                                        deleteCPI(4,a,b);\r
                                        return 116;\r
                                }\r
@@ -1447,8 +1600,10 @@ int otw2()
                                SFB14[a] = new ScreenFontBitmap14;\r
                                if(!SFB14[a])\r
                                {\r
-                                       sprintf(err,"116:Not enough memory for SFB14[%d] (%d)",a,b);\r
+                                       sprintf(err,"116:Not enough memory for SFB14[%d] (%d)\n",a,b);\r
                                        fclose(CPI);\r
+                                       if(CPX)\r
+                                               remove("tempcpi");\r
                                        deleteCPI(4,a,b);\r
                                        return 116;\r
                                }\r
@@ -1459,8 +1614,10 @@ int otw2()
                                SFB8[a] = new ScreenFontBitmap8;\r
                                if(!SFB8[a])\r
                                {\r
-                                       sprintf(err,"116:Not enough memory for SFB8[%d] (%d)",a,b);\r
+                                       sprintf(err,"116:Not enough memory for SFB8[%d] (%d)\n",a,b);\r
                                        fclose(CPI);\r
+                                       if(CPX)\r
+                                               remove("tempcpi");\r
                                        deleteCPI(4,a,b);\r
                                        return 116;\r
                                }\r
@@ -1469,13 +1626,16 @@ int otw2()
                }\r
        }\r
        fclose(CPI);\r
+       if(CPX)\r
+               remove("tempcpi");\r
        offset();\r
        return 0;\r
 }\r
 void otw3()//\r
 {\r
-       setcolor(RED);\r
-       outtextxy(136,472,"load");\r
+       _setcolor(C_NON);\r
+       _moveto(136,472);\r
+       _outgtext("load");\r
        deleteCPI();\r
        status=otw();\r
        while(status!=0)\r
@@ -1505,13 +1665,13 @@ int zap2()
 {\r
        int a;\r
        int b;\r
-       int c;\r
-       int d;\r
+       //int c;\r
+       //int d;\r
 \r
        CPI=fopen(nazwap,"wb");\r
        if(CPI==NULL)\r
        {\r
-               sprintf(err,"200:Cannot create file at this path");\r
+               sprintf(err,"200:Cannot create file at this path\n");\r
                return 200;\r
        }\r
        else\r
@@ -1547,14 +1707,15 @@ int zap2()
                }\r
        }\r
 \r
-       fprintf(CPI,"\r\nThis file was created with the CPI editor version 1.2b",0x1a);\r
+       fprintf(CPI,"\r\nThis file was created with the CPI editor version 1.3a",0x1a);\r
        fclose(CPI);\r
        return 0;\r
 }\r
 void zap3()//\r
 {\r
-       setcolor(RED);\r
-       outtextxy(72,472,"save");\r
+       _setcolor(C_NON);\r
+       _moveto(72,472);\r
+       _outgtext("save");\r
        status=zap();\r
        while(status!=0)\r
        {\r
@@ -1569,8 +1730,9 @@ void zap3()//
 \r
 void use3()///\r
 {\r
-       setcolor(RED);\r
-       outtextxy(72,472,"save            use");\r
+       _setcolor(C_NON);\r
+       _moveto(72,472);\r
+       _outgtext("save            use");\r
        status=zap();\r
        while(status!=0)\r
        {\r
@@ -1588,8 +1750,9 @@ void use3()///
                puts(err);\r
                system(err);\r
                delay(5000);\r
-               closegraph();\r
-               initgraph(&kart16,&tryb16,"");\r
+               //closegraph();\r
+               //initgraph(&kart16,&tryb16,"");\r
+               _setvideomode(_VRES16COLOR);\r
 \r
        }\r
        redraw();\r
@@ -1604,7 +1767,7 @@ int zmn()
        {\r
                if(CP==CPEH[i]->codepage&&i!=cp)\r
                {\r
-                       sprintf(err,"314:cp%03u already in CPEH[%u]",CP,i);\r
+                       sprintf(err,"314:cp%03u already in CPEH[%u]\n",CP,i);\r
                        return 314;\r
                }\r
        }\r
@@ -1613,8 +1776,9 @@ int zmn()
 }\r
 void zmn3()//\r
 {\r
-       setcolor(RED);\r
-       outtextxy(256,472,"number");\r
+       _setcolor(C_NON);\r
+       _moveto(256,472);\r
+       _outgtext("number");\r
        status=zmn();\r
        if(status!=0)\r
                message("Number not changed",err);\r
@@ -1624,12 +1788,12 @@ void zmn3()//
 int newCPI()\r
 {\r
        short CP,h;\r
-       char temp[51];\r
+       //char temp[51];\r
        CP=question("First codepage number:");\r
        h=question("Initial font height(8,14,16,all)");\r
        if(h!=0&&h!=8&&h!=14&&h!=16)\r
        {\r
-               sprintf(err,"310:Wrong height (%u)",h);\r
+               sprintf(err,"310:Wrong height (%u)\n",h);\r
                return 310;\r
        }\r
        return newCPI2(CP,h);\r
@@ -1640,18 +1804,18 @@ int newCPI2(short CP, short h)
        FFH=new FontFileHeader;\r
        if(!FFH)\r
        {\r
-               sprintf(err,"316:Not enough memory for FFH");\r
+               sprintf(err,"316:Not enough memory for FFH\n");\r
                return 316;\r
        }\r
        FFH->id0=0xFF;\r
-       strcpy(FFH->id,"FONT   ");\r
-       strcpy(FFH->reserved,"\0\0\0\0\0\0\0");\r
+       strcpy((char *)(FFH->id),"FONT   ");\r
+       strcpy((char *)(FFH->reserved),"\0\0\0\0\0\0\0");\r
        FFH->pnum=1;\r
        FFH->ptyp=1;\r
        FIH=new FontInfoHeader;\r
        if(!FIH)\r
        {\r
-               sprintf(err,"316:Not enough memory for FIH");\r
+               sprintf(err,"316:Not enough memory for FIH\n");\r
                deleteCPI(0);\r
                return 316;\r
        }\r
@@ -1667,8 +1831,9 @@ int newCPI2(short CP, short h)
 }\r
 void newCPI3()//\r
 {\r
-       setcolor(RED);\r
-       outtextxy(16,472,"new");\r
+       _setcolor(C_NON);\r
+       _moveto(16,472);\r
+       _outgtext("new");\r
        deleteCPI();\r
        status=newCPI();\r
        while(status!=0)\r
@@ -1797,10 +1962,10 @@ void deleteCPI(short st,short a,short b)
 int newCP()\r
 {\r
        short CP,h;\r
-       char temp[51];\r
+       //char temp[51];\r
        if(FIH->num_codepages>=16)\r
        {\r
-               sprintf(err,"305:Already 16 codepages in CPI");\r
+               sprintf(err,"305:Already 16 codepages in CPI\n");\r
                return 305;\r
        }\r
        CP=question("Codepage number:");\r
@@ -1808,14 +1973,14 @@ int newCP()
        {\r
                if(CP==CPEH[i]->codepage)\r
                {\r
-                       sprintf(err,"314:cp%03u already in CPEH[%u]",CP,i);\r
+                       sprintf(err,"314:cp%03u already in CPEH[%u]\n",CP,i);\r
                        return 314;\r
                }\r
        }\r
        h=question("Initial font height(8,14,16,all)");\r
        if(h!=0&&h!=8&&h!=14&&h!=16)\r
        {\r
-               sprintf(err,"310:Wrong height (%u)",h);\r
+               sprintf(err,"310:Wrong height (%u)\n",h);\r
                return 310;\r
        }\r
        return newCP2(CP,h);\r
@@ -1825,22 +1990,22 @@ int newCP2(short CP,short h)
        int t;\r
        if(!(CPEH[FIH->num_codepages] = new CodePageEntryHeader))\r
        {\r
-               sprintf(err,"316:Not enough memory for CPEH[%d]",FIH->num_codepages);\r
+               sprintf(err,"316:Not enough memory for CPEH[%d]\n",FIH->num_codepages);\r
                return 316;\r
        }\r
        if(!(CPIH[FIH->num_codepages] = new CodePageInfoHeader))\r
        {\r
                delete CPEH[FIH->num_codepages];\r
                CPEH[FIH->num_codepages] = NULL;\r
-               sprintf(err,"316:Not enough memory for CPIH[%d]",FIH->num_codepages);\r
+               sprintf(err,"316:Not enough memory for CPIH[%d]\n",FIH->num_codepages);\r
                return 316;\r
        }\r
        CPEH[FIH->num_codepages]->cpeh_size=0x1c;\r
        CPEH[FIH->num_codepages]->device_type=1;\r
-       strcpy(CPEH[FIH->num_codepages]->device_name,"EGA    ");\r
+       strcpy((char *)(CPEH[FIH->num_codepages]->device_name),"EGA    ");\r
        CPEH[FIH->num_codepages]->device_name[7]=' ';\r
        CPEH[FIH->num_codepages]->codepage=CP;\r
-       strcpy(CPEH[FIH->num_codepages]->reserved,"\0\0\0\0\0");\r
+       strcpy((char *)(CPEH[FIH->num_codepages]->reserved),"\0\0\0\0\0");\r
        CPIH[FIH->num_codepages]->version=1;\r
        CPIH[FIH->num_codepages]->num_fonts=0;\r
        switch(h)\r
@@ -1885,7 +2050,7 @@ int newCP2(short CP,short h)
                }\r
                break;\r
        default:\r
-               sprintf(err,"510:%u WT*?",h);\r
+               sprintf(err,"510:%u ***?",h);\r
                t = 510;\r
        }\r
        if(t!=0)\r
@@ -1902,8 +2067,9 @@ int newCP2(short CP,short h)
 }\r
 void newCP3()//\r
 {\r
-       setcolor(RED);\r
-       outtextxy(400,472,"newCP");\r
+       _setcolor(C_NON);\r
+       _moveto(400,472);\r
+       _outgtext("newCP");\r
        status=newCP();\r
        if(status!=0)\r
                message("Codepage not created",err);\r
@@ -1977,7 +2143,7 @@ int delCP()
        short i;\r
        if(FIH->num_codepages<=1)\r
        {\r
-               sprintf(err,"317:Last codepage");\r
+               sprintf(err,"317:Last codepage\n");\r
                return 317;\r
        }\r
        for(i=0;i<CPIH[cp]->num_fonts;++i)\r
@@ -2031,8 +2197,9 @@ int delCP()
 }\r
 void delCP3()//\r
 {\r
-       setcolor(RED);\r
-       outtextxy(536,472,"delCP");\r
+       _setcolor(C_NON);\r
+       _moveto(536,472);\r
+       _outgtext("delCP");\r
        status=delCP();\r
        if(status!=0)\r
                message("Codepage not deleted",err);\r
@@ -2049,7 +2216,7 @@ int newF()
        short h;\r
        if(CPIH[cp]->num_fonts>=3)\r
        {\r
-               sprintf(err,"309:Already 3 fonts in CPIH[%u]",cp);\r
+               sprintf(err,"309:Already 3 fonts in CPIH[%u]\n",cp);\r
                return 309;\r
        }\r
        h=question("Font height(8,14,16)");\r
@@ -2066,14 +2233,15 @@ int newF2(short h)
        case 16:\r
                return newF16(cp);\r
        default:\r
-               sprintf(err,"310:Wrong height (%u)",h);\r
+               sprintf(err,"310:Wrong height (%u)\n",h);\r
                return 310;\r
        }\r
 }\r
 void newF3()//\r
 {\r
-       setcolor(RED);\r
-       outtextxy(336,472,"newF");\r
+       _setcolor(C_NON);\r
+       _moveto(336,472);\r
+       _outgtext("newF");\r
        status=newF();\r
        if(status!=0)\r
                message("Font not created",err);\r
@@ -2085,17 +2253,17 @@ int newF8(short CP)
 {\r
        if(byo8[CP])\r
        {\r
-               sprintf(err,"313:Height 8 already in cp%03u",CPEH[CP]->codepage);\r
+               sprintf(err,"313:Height 8 already in cp%03u\n",CPEH[CP]->codepage);\r
                return 313;\r
        }\r
        if(!(SFH[CP][CPIH[CP]->num_fonts]=new ScreenFontHeader))\r
        {\r
-               sprintf(err,"316:Not enough memory for SFH[%d][%d]",CP,CPIH[CP]->num_fonts);\r
+               sprintf(err,"316:Not enough memory for SFH[%d][%d]\n",CP,CPIH[CP]->num_fonts);\r
                return 316;\r
        }\r
        if(!(SFB8[CP]=new ScreenFontBitmap8))\r
        {\r
-               sprintf(err,"316:Not enough memory for SFB8[%d]",CP);\r
+               sprintf(err,"316:Not enough memory for SFB8[%d]\n",CP);\r
                delete SFH[CP][CPIH[CP]->num_fonts];\r
                SFH[CP][CPIH[CP]->num_fonts] = NULL;\r
                return 316;\r
@@ -2116,17 +2284,17 @@ int newF14(short CP)
 {\r
        if(byo14[CP])\r
        {\r
-               sprintf(err,"313:Height 14 already in cp%03u",CPEH[CP]->codepage);\r
+               sprintf(err,"313:Height 14 already in cp%03u\n",CPEH[CP]->codepage);\r
                return 313;\r
        }\r
        if(!(SFH[CP][CPIH[CP]->num_fonts]=new ScreenFontHeader))\r
        {\r
-               sprintf(err,"316:Not enough memory for SFH[%d][%d]",CP,CPIH[CP]->num_fonts);\r
+               sprintf(err,"316:Not enough memory for SFH[%d][%d]\n",CP,CPIH[CP]->num_fonts);\r
                return 316;\r
        }\r
        if(!(SFB14[CP]=new ScreenFontBitmap14))\r
        {\r
-               sprintf(err,"316:Not enough memory for SFB14[%d]",CP);\r
+               sprintf(err,"316:Not enough memory for SFB14[%d]\n",CP);\r
                delete SFH[CP][CPIH[CP]->num_fonts];\r
                SFH[CP][CPIH[CP]->num_fonts] = NULL;\r
                return 316;\r
@@ -2147,17 +2315,17 @@ int newF16(short CP)
 {\r
        if(byo16[CP])\r
        {\r
-               sprintf(err,"313:Height 16 already in cp%03u",CPEH[CP]->codepage);\r
+               sprintf(err,"313:Height 16 already in cp%03u\n",CPEH[CP]->codepage);\r
                return 313;\r
        }\r
        if(!(SFH[CP][CPIH[CP]->num_fonts]=new ScreenFontHeader))\r
        {\r
-               sprintf(err,"316:Not enough memory for SFH[%d][%d]",CP,CPIH[CP]->num_fonts);\r
+               sprintf(err,"316:Not enough memory for SFH[%d][%d]\n",CP,CPIH[CP]->num_fonts);\r
                return 316;\r
        }\r
        if(!(SFB16[CP]=new ScreenFontBitmap16))\r
        {\r
-               sprintf(err,"316:Not enough memory for SFB16[%d]",CP);\r
+               sprintf(err,"316:Not enough memory for SFB16[%d]\n",CP);\r
                delete SFH[CP][CPIH[CP]->num_fonts];\r
                SFH[CP][CPIH[CP]->num_fonts] = NULL;\r
                return 316;\r
@@ -2241,7 +2409,7 @@ void prevF()//
                ramka16();\r
                break;\r
        }\r
-       cpwys();\r
+       cpwys(1);\r
        return;\r
 }\r
 void nextF()//\r
@@ -2311,7 +2479,7 @@ void nextF()//
                ramka16();\r
                break;\r
        }\r
-       cpwys();\r
+       cpwys(1);\r
        return;\r
 }\r
 \r
@@ -2320,7 +2488,7 @@ int delF()
        short h;\r
        if(CPIH[cp]->num_fonts<=1)\r
        {\r
-               sprintf(err,"315:Last font in CPIH[%u]",cp);\r
+               sprintf(err,"315:Last font in CPIH[%u]\n",cp);\r
                return 315;\r
        }\r
        for(short i=0;i<CPIH[cp]->num_fonts;++i)\r
@@ -2340,14 +2508,15 @@ int delF()
        case 16:\r
                return delF16(h);\r
        default:\r
-               sprintf(err,"510:%u WT*?",h);\r
+               sprintf(err,"510:%u ***?\n",h);\r
                return 510;\r
        }\r
 }\r
 void delF3()//\r
 {\r
-       setcolor(RED);\r
-       outtextxy(472,472,"delF");\r
+       _setcolor(C_NON);\r
+       _moveto(472,472);\r
+       _outgtext("delF");\r
        status=delF();\r
        if(status!=0)\r
        message("Font not deleted",err);\r
@@ -2369,7 +2538,7 @@ int delF8(short h)
                SFH[cp][i] = SFH[cp][i+1];\r
        }\r
        SFH[cp][CPIH[cp]->num_fonts] = NULL;\r
-       sprintf(err,"0:OK");\r
+       sprintf(err,"0:OK\n");\r
        return 0;\r
 }\r
 int delF14(short h)\r
@@ -2384,7 +2553,7 @@ int delF14(short h)
                SFH[cp][i] = SFH[cp][i+1];\r
        }\r
        SFH[cp][CPIH[cp]->num_fonts] = NULL;\r
-       sprintf(err,"0:OK");\r
+       sprintf(err,"0:OK\n");\r
        return 0;\r
 }\r
 int delF16(short h)\r
@@ -2399,7 +2568,7 @@ int delF16(short h)
                SFH[cp][i] = SFH[cp][i+1];\r
        }\r
        SFH[cp][CPIH[cp]->num_fonts] = NULL;\r
-       sprintf(err,"0:OK");\r
+       sprintf(err,"0:OK\n");\r
        return 0;\r
 }\r
 \r
@@ -2421,21 +2590,12 @@ int main(int argc,char* argv[])
        }\r
        else\r
                any=0;\r
-\r
-       status=registerbgidriver(EGAVGA_driver);\r
-       if (status < 0)\r
+       if(!_setvideomode(_VRES16COLOR))\r
        {\r
-               printf("g%d:%s\n",status,grapherrormsg(status));\r
-               return status;\r
+               printf("400:Cannot enter graphic mode\n");//change number\r
+               return 400;\r
        }\r
-       initgraph(&kart16,&tryb16,"");\r
-       status=graphresult();\r
-       if (status != grOk)\r
-       {\r
-               printf("g%d:%s\n",status,grapherrormsg(status));\r
-               return status;\r
-       }\r
-\r
+       _setplotaction(_GPSET); \r
        if(byo8[0])\r
                wys=8;\r
        else if(byo16[0])\r
@@ -2449,9 +2609,9 @@ int main(int argc,char* argv[])
                showMaus();\r
        for(;;)\r
        {\r
-               if(bioskey(_KEYBRD_READY))\r
+               if(/*_bios_keybrd(_KEYBRD_READY)*/kbhit())\r
                {\r
-                       key=bioskey(_KEYBRD_READ);\r
+                       key=_bios_keybrd(_KEYBRD_READ);\r
                        if(maus)\r
                                hideMaus();\r
                        if(tab==0)\r
@@ -2769,15 +2929,16 @@ int main(int argc,char* argv[])
                        if ((key&0xFF00)==0x4400)\r
                        {\r
                                //koniec\r
-                               setcolor(RED);\r
-                               outtextxy(616,472,"end");\r
+                               _setcolor(C_NON);\r
+                               _moveto(616,472);\r
+                               _outgtext("end");\r
                                if(maus)\r
                                        resetMaus();\r
                                break;\r
                        }\r
-                       while(bioskey(_KEYBRD_READY))\r
+                       while(kbhit())\r
                        {\r
-                               bioskey(_KEYBRD_READ);\r
+                               _bios_keybrd(_KEYBRD_READ);\r
                        }\r
                        if(maus&&mausv)\r
                                showMaus();\r
@@ -3157,7 +3318,7 @@ int main(int argc,char* argv[])
                                wys=16;\r
                                cury&=0xf;\r
                                tab=1;\r
-                               lit=((mausy-111)/16)*16+((mausx-496)/8);\r
+                               lit=((mausy-112)/16)*16+((mausx-496)/8);\r
                                if (pre==lit)\r
                                {\r
                                        switch(prew)\r
@@ -3214,7 +3375,18 @@ int main(int argc,char* argv[])
                                        }\r
                                }\r
                        }\r
-                       \r
+                       else if(any&&klik&&!prek&&mausx>=328&&mausx<616&&mausy>=16&&mausy<40)\r
+                       {\r
+                               int selcp;\r
+                               hideMaus();\r
+                               mausv=0;\r
+                               selcp=(mausx-328)/48+((mausy-16)/8)*6;\r
+                               if(selcp<FIH->num_codepages)\r
+                               {\r
+                                       cp=selcp;\r
+                                       normCP();\r
+                               }                               \r
+                       }\r
                        else if(any&&klik&&!prek&&mausx>=128&&mausx<184&&mausy<8)\r
                        {\r
                                hideMaus();\r
@@ -3303,21 +3475,25 @@ int main(int argc,char* argv[])
                        {\r
                                hideMaus();\r
                                mausv=0;\r
-                               setcolor(RED);\r
-                               outtextxy(616,472,"end");\r
+                               _setcolor(C_NON);\r
+                               _moveto(616,472);\r
+                               _outgtext("end");\r
                                resetMaus();\r
                                break;\r
                        }\r
                        \r
                        else\r
                        {\r
-                               mausv=1;\r
-                               showMaus();\r
+                               //if(!mausv)\r
+                               //{\r
+                                       mausv=1;\r
+                                       showMaus();\r
+                               //}\r
                        }\r
                }\r
        }\r
 \r
        deleteCPI();\r
-       closegraph();\r
+       _setvideomode(_DEFAULTMODE);    \r
        return 0;\r
-}
\ No newline at end of file
+}\r
diff --git a/SRC/cpitrick.asm b/SRC/cpitrick.asm
new file mode 100644 (file)
index 0000000..50406a9
--- /dev/null
@@ -0,0 +1,179 @@
+;;  CPITRICK.ASM      \r
+;;  This file is part of CPIED\r
+;;\r
+;;  CPIED is free software: you can redistribute it and/or modify\r
+;;  it under the terms of the GNU General Public License as published by\r
+;;  the Free Software Foundation, either version 3 of the License, or\r
+;;  (at your option) any later version.\r
+;;  \r
+;;  CPIED is distributed in the hope that it will be useful,\r
+;;  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+;;  GNU General Public License for more details.\r
+;;  \r
+;;  You should have received a copy of the GNU General Public License along\r
+;;  with CPIED (copying.txt).  If not, see <http://www.gnu.org/licenses/>.\r
+;;\r
+;;  This file is cpitrick.asm from FreeDOS mode without any change.\r
+;; \r
+%if 0\r
+Open UPXed (!) CPI files - for the FreeDOS MODE C utility\r
+Copyright (C) 2003, 2004  Eric Auer <eric@CoLi.Uni-SB.DE>\r
+[This file itself became part of MODE C on 29apr2004]\r
+\r
+This program is free software; you can redistribute it and/or\r
+modify it under the terms of the GNU General Public License\r
+as published by the Free Software Foundation; either version 2\r
+of the License, or (at your option) any later version.\r
+\r
+This program is distributed in the hope that it will be useful,\r
+but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+GNU General Public License for more details.\r
+\r
+You should have received a copy of the GNU General Public License\r
+along with this program; if not, write to the Free Software\r
+Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, \r
+USA. Or check http://www.gnu.org/licenses/gpl.txt on the internet.\r
+%endif\r
+\r
+SEGMENT _TEXT ALIGN=4 CLASS=CODE\r
+GLOBAL _cpx2cpi\r
+\r
+; int cpx2cpi(void far * buffer), returns 0 plain 1 upxed -1 error\r
+_cpx2cpi:\r
+        push bp\r
+        mov bp,sp\r
+       ; no need to save AX, as AX will hold the return value\r
+        push bx\r
+        push cx\r
+        push dx\r
+        push si\r
+        push di\r
+        push es\r
+        push ds\r
+       pushf\r
+       ; first argument can be found at BP+4 on stack now\r
+\r
+       lds si,[bp+4]   ; get that pointer\r
+       cld\r
+       lodsb\r
+       cmp al,-1       ; check CPI header (ff,"FONT   ")\r
+       jnz noplaincpi\r
+       lodsw\r
+       cmp ax,'FO'\r
+       jnz noplaincpi\r
+       lodsw\r
+       cmp ax,'NT'\r
+       jnz noplaincpi\r
+       jmp cpi_okay    ; it is an uncompressed CPI file! Will be 49100\r
+                       ; or more likely 58880 bytes in size, I think.\r
+\r
+noupxcpi:\r
+       jmp cpi_error\r
+\r
+noplaincpi:\r
+       lds si,[bp+4]   ; get that pointer\r
+       or si,si        ; pointer must be normalized to allow deUPXing\r
+       jnz noupxcpi\r
+\r
+       ; Next assumption: CPI file got renamed to COM and then\r
+       ; UPXed and renamed again. Then it should start with\r
+       ; cmp sp,0x100+cpisize+stubsize+stacksize (roughly 0x200+cpisize)\r
+       ; ja enoughram\r
+       ; int 20\r
+       ; enoughram: ... (here follows the "copy decompressor and compressed\r
+       ; data to end-of-the segment code, then the UPX header)\r
+       ; Binary: 81 fc xx xx 77 02 cd 20 ...\r
+       ; Because we have SS/SP somewhere else, we zap the test!\r
+\r
+       lodsw\r
+       cmp ax,0xfc81   ; cmp sp, ... ("check if enough free RAM")\r
+       jnz noupxcpi    ; does not look like an UPXed ".com" file\r
+       lodsw           ; ignore the something\r
+       mov al,0xeb     ; opcode: jmp short unconditionally\r
+       mov [si],al     ; make the test succeed all the time\r
+                       ; (the code must be: "cmp... jcc okay...")\r
+       mov bx,'UP'\r
+scan_upx:              ; find "UPX!" signature\r
+       dec si\r
+       lodsw\r
+       cmp si,100      ; first stub part must be smaller than this\r
+       ja noupxcpi     ; give up\r
+       cmp ax,bx\r
+       jnz scan_upx\r
+       lodsw\r
+       cmp ax,'X!'\r
+       jnz noupxcpi    ; no second try\r
+       lodsw\r
+       cmp al,10\r
+       jb noupxcpi     ; not accepting ancient versions\r
+       add si,16+2     ; skip over rest of the header plus 1 word\r
+               ; first word of compressed data is one of\r
+               ; the bitstream words which are mixed with the\r
+               ; literal bytes and low-byte-of-distance bytes\r
+               ; which are the ingredients of an UPXed data stream\r
+       mov al,0xcb     ; opcode for RETF\r
+       mov [si],al     ; overwrite first byte of CPI file to make it a\r
+       inc si          ; "program" ;-)\r
+       lodsw\r
+       cmp ax,'FO'     ; pointer and buffer contents correct?\r
+       jnz noupxcpi    ; give up, bad luck.\r
+       \r
+       ; header starts with the first byte of the UPX! string and\r
+       ; contains in UPX 1.something versions:\r
+       ; [4] version (e.g. 0B) [5] format (1 for COM) [6] method (4)\r
+       ; [7] compressionlevel (8) [8] adler32u [C] adler32c\r
+       ; (32bit checksums of uncompressed / compressed data)\r
+       ; [10] sizeu (16bit, e.g. EC00/58880) [12] sizec (16bit)\r
+       ; (sizes are 16bit for COM and SYS, 32bit otherwise...)\r
+       ; [14] "filter" [15?] headerchecksum [16] compressed data...\r
+\r
+       ; If version is below 0A, header is 20 instead of 22 bytes\r
+       ; for COM, and if version is below 03, it is 24 bytes, But\r
+       ; internal version 09 means UPX 0.7x which is very old.\r
+       ; Find UPX source code at http://upx.sourceforge.net/ ...\r
+       ; Some of the UPX compression libs are closed source.\r
+\r
+       push bp\r
+       mov ax,[bp+6]           ; get the buffer SEGMENT\r
+       sub ax,byte 0x10        ; move to allow offset 0x100\r
+       mov [bp+6],ax           ; denormalize pointer to .COM style\r
+       mov word [bp+4],0x100   ; denormalize pointer to .COM style\r
+       mov es,ax               ; deUPXing stub requires ES=CS\r
+       mov ds,ax               ; deUPXing stub requires DS=CS\r
+\r
+       call far [bp+4]         ; "run the COM file"\r
+               ; this will deUPX the CPI and then run the RETF\r
+               ; command which we patched into the byte which\r
+               ; will become the first byte of the deUPXed ".COM"!\r
+\r
+       pop bp\r
+       xor ax,ax\r
+       mov [bp+4],ax   ; renormalize pointer\r
+       add word [bp+6], byte 0x10\r
+       lds si,[bp+4]           ; get that pointer\r
+       mov byte [si],-1        ; restore first byte to FF\r
+       ; buffer now contains the contents of the deUPXed CPI file\r
+       \r
+cpi_upxed:\r
+       mov ax,1\r
+       jmp short cpi_fetched\r
+cpi_okay:\r
+       xor ax,ax\r
+       jmp short cpi_fetched\r
+cpi_error:\r
+       mov ax,-1\r
+cpi_fetched:\r
+\r
+       popf\r
+        pop ds\r
+        pop es\r
+        pop di\r
+        pop si\r
+        pop dx\r
+        pop cx\r
+        pop bx\r
+        pop bp\r
+        ret    ; ret or retf depending on memory model!\r
+\r
diff --git a/SRC/cpx2cpi.c b/SRC/cpx2cpi.c
new file mode 100644 (file)
index 0000000..e8cfe14
--- /dev/null
@@ -0,0 +1,176 @@
+    //CPX2CPI.C         \r
+   // Balthasar Szczepaäski Copyright 2013\r
+  //\r
+ // //This file is part of CPIED\r
+// // \r
+  //  CPIED is free software: you can redistribute it and/or modify\r
+ // //it under the terms of the GNU General Public License as published by\r
+// // the Free Software Foundation, either version 3 of the License, or\r
+  //  (at your option) any later version.\r
+ //   \r
+// // CPIED is distributed in the hope that it will be useful,\r
+  //  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ // //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+// // GNU General Public License for more details.\r
+  //\r
+ // //You should have received a copy of the GNU General Public License along\r
+// // with CPIED (copying.txt).  If not, see <http://www.gnu.org/licenses/>.\r
+  //  \r
+ // //This file contains code from FreeDOS mode's modecp.c\r
+// //                            \r
+  //\r
+ //modecp.c:\r
+/* This code can be used under the terms of  GNU Public License */\r
+/* (GPL) version 2 or later.   Written for FreeDOS MODE by Eric */\r
+/* Auer (eric@coli.uni-sb.de) (c) 2003-2005. GPL -> www.gnu.org */\r
+\r
+/* Modified 2005 by Eric Auer to model MODECON by Aitor Merino! */\r
+/* MODE command: CODEPAGE related parts */\r
+\r
+#include <io.h>\r
+#include <fcntl.h>\r
+#include <alloc.h>\r
+#include <stdio.h>\r
+#include <dos.h>\r
+#include <sys/stat.h>\r
+\r
+static union REGS r;\r
+\r
+#define BYTE unsigned char\r
+#define WORD unsigned int\r
+\r
+#define UPXoverhead  320       /* actually even less: UPX stub has  */\r
+       /* 2 parts - 1. relocate 2. decompress - and uses almost no  */\r
+       /* stack. We do not even use stack inside the buffer at all, */\r
+       /* makes no difference for the UPX stub. Actual overhead is  */\r
+       /* therefore only part 2 of the stub plus no extra stack...  */\r
+#define MaxBufSize   (58880U + UPXoverhead)\r
+       /* "CPX" support decompresses data  in place  in the buffer. */\r
+\r
+       BYTE far * buf;         /* made pointer far */\r
+\r
+extern int cpx2cpi(void far * buffer); /* returns 0 plain 1 upxed -1 error */\r
+       /* this part is written in NASM Assembly language, compile */\r
+       /* it with NASM -fobj -o cpitrick.obj cpitrick.asm */\r
+\r
+int main(int argc,char* argv[])\r
+{\r
+       unsigned char con=1;\r
+       unsigned int cpf;       /* file handle */\r
+       unsigned long m;        /* filelen is (FAT16: signed) long! */\r
+       struct SREGS sregs;\r
+\r
+       if(argc<3)\r
+  {\r
+    puts("cpx2cpi *.cpx *.cpi [q]");\r
+    return 1;\r
+  }\r
+       if(argc>3)\r
+       {\r
+               if(argv[3][0]=='q'||argv[3][0]=='Q')\r
+                       con=0;\r
+               else\r
+                       con=1;\r
+       }\r
+       else\r
+               con=1;\r
+       \r
+       /** Check that the file exists **/\r
+       if ((cpf = open(argv[1], O_RDONLY | O_BINARY)) == 0xffffU)\r
+       {\r
+    if(con)\r
+                       printf("could not open %s\n",argv[1]);\r
+    return 8;\r
+  }\r
+\r
+               buf = farmalloc(MaxBufSize+15); /* changed malloc to farmalloc */\r
+       if (buf == NULL) {\r
+          if(con)\r
+                       puts ("Out of memory!");\r
+               return 7;\r
+       }\r
+\r
+       /* for UPXed CPI file (CPX file) support, buffer must be aligned */\r
+       while (FP_OFF(buf) % 16)        /* "move" buf to next paragraph */\r
+               buf++;\r
+       while (FP_OFF(buf)) {           /* normalize buf to "someseg:0" */\r
+               buf = MK_FP(FP_SEG(buf)+1, FP_OFF(buf)-16);\r
+       }\r
+\r
+       /* we do NOT free malloced buf later - happens on exit anyway. */\r
+\r
+       /** Read the buffer **/\r
+\r
+       /* if memory model is TINY (.com file), we need our */\r
+       /* OWN read( handle, FAR buffer pointer, size ) ... */\r
+        sregs.ds = FP_SEG(buf);\r
+        r.x.dx = FP_OFF(buf);\r
+        r.h.ah = 0x3f; /* read from file handle */\r
+        r.x.cx = MaxBufSize - UPXoverhead;\r
+        r.x.bx = cpf;  /* handle */\r
+\r
+       int86x (0x21, &r, &r, &sregs);\r
+       if ( r.x.cflag ) {\r
+               if(con)\r
+                       printf("%s read error, code %u.\n",argv[1], r.x.ax);\r
+    close (cpf);\r
+               return 6;\r
+       \r
+       }\r
+       \r
+\r
+\r
+       close (cpf);\r
+\r
+       m = cpx2cpi(buf); /* ret: 0 plain 1 upxed -1 error */ /* new 29apr2004 */\r
+\r
+       if (m == -1)\r
+       {\r
+               if(con)\r
+                       puts("Not a CPI or CPX");\r
+               return 5;\r
+       }\r
+       else if (m == 1)\r
+       {\r
+               if(con)\r
+                       printf("%s is a cpx\n",argv[1]);\r
+       }\r
+       else {\r
+               if(con)\r
+                       printf("%s is already a CPI\n",argv[1]);\r
+               close (cpf);\r
+               return 4;\r
+       }\r
+       //create the cpi \r
+       if ((cpf = (unsigned)(creat(argv[2],S_IWRITE)))==0xffffU)\r
+       {\r
+               if(con)\r
+                       printf("could not create %s\n",argv[2]);\r
+               return 3;\r
+       }\r
+       close (cpf);\r
+       //for some reason open doesn't want to create a new file\r
+       if ((cpf = open(argv[2], O_WRONLY | O_BINARY | O_CREAT | O_TRUNC)) == 0xffffU)\r
+       {\r
+               if(con)\r
+                       printf("could not open %s\n",argv[2]);\r
+               return 2;\r
+       }\r
+       sregs.ds = FP_SEG(buf);\r
+       r.x.dx = FP_OFF(buf);\r
+       r.h.ah = 0x40;  /* write to file handle */\r
+       r.x.cx = MaxBufSize - UPXoverhead;\r
+       r.x.bx = cpf;   /* handle */\r
+       int86x (0x21, &r, &r, &sregs);\r
+       if ( r.x.cflag )\r
+       {\r
+               if(con)\r
+                       printf("%s write error, code %u.\n",argv[2], r.x.ax);\r
+               close (cpf);\r
+               return 1;\r
+       }\r
+       close (cpf);\r
+       if(con)\r
+               printf("%s converted to %s\n",argv[1],argv[2]);\r
+       return 0;\r
+}\r
diff --git a/SRC/makefile b/SRC/makefile
new file mode 100644 (file)
index 0000000..3e78133
--- /dev/null
@@ -0,0 +1,24 @@
+ASM=nasm\r
+CCX=tcc\r
+CFLAGSX=-w -M -f- -mt -lt -e\r
+\r
+CC=wpp\r
+CL=wlink\r
+CFLAGS=-w4 -e25 -zp1 -zq -ot -d2 -bt=dos -fo=.obj -ml -xs -xr\r
+LFLAGS=name cpied d all sys dos op m op maxe=25 op q op symf f cpied\r
+\r
+all: cpx2cpi.com cpied.exe\r
+\r
+cpied.obj:     cpied.cpp makefile\r
+       $(CC) cpied.cpp $(CFLAGS)\r
+\r
+cpied.exe:     cpied.obj makefile\r
+       $(CL) $(LFLAGS)\r
+\r
+cpitrick.obj:  cpitrick.asm makefile\r
+       $(ASM) -fobj -o cpitrick.obj cpitrick.asm\r
+\r
+cpx2cpi.com: cpitrick.obj cpx2cpi.c makefile \r
+       $(CCX) $(CFLAGSX)cpx2cpi cpx2cpi.c cpitrick.obj\r
+\r
+\r