/* This file is part of Advanced Strategic Command; http://www.asc-hq.de Copyright (C) 1994-1999 Martin Bickel and Marc Schellenberger This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include #include #include "krkr.h" #include "..\basestrm.h" #define write(a) cprintf(a) #define left 0 #define right 1 #define up 1 #define down -1 #define reset 0 #define insert 1 #define on 1 #define off 0 #define sortname 1 #define sorttime 2 #define max_long 2147483647 #define fgcolor 15 #define bkcolor 1 /*********************************************************************************************/ /* setcurpos : setzt den Cursor an die Position x y */ /* getcurpos : liefert die Cursorposition */ /*********************************************************************************************/ extern void setcurpos( int col, int row ); #pragma aux setcurpos = \ "push bp" \ "shl edx,8" \ "or edx, ebx" \ "mov ah,2" \ "mov bx,0" \ "int 10h" \ "pop bp" \ parm [ebx] [edx] \ modify [ax ebx]; extern int biosgetcurpos( void ); #pragma aux biosgetcurpos = \ "push bp" \ "mov ah,3" \ "mov bx,0" \ "int 10h" \ "movzx eax, dx" \ "pop bp" \ modify [bx]; tcurpos getcurpos (void) { tcurpos pos; int a = biosgetcurpos(); pos.y = (a >> 8); pos.x = (a & 0xff); return pos; } /*********************************************************************************************/ /* Wait : wartet auf einen Tastendruck */ /*********************************************************************************************/ void _wait(void) { while ( kbhit() ) getch(); getch(); while ( kbhit() ) getch(); } /*********************************************************************************************/ /* charcat : h„ngt einen Buchstaben an einen string an */ /*********************************************************************************************/ void charcat (char s[], char c) { int i = 0; while (s[i] != 0) { i++; } /* endwhile */ s[i] = c; s[i+1] = 0; } /*********************************************************************************************/ /* unpack_date : entpackt das datum (von zb dateien) */ /*********************************************************************************************/ void unpack_date (unsigned short packed, int &day, int &month, int &year) { year = packed >> 9; month = (packed - year*512) >> 5; day = packed - year*512 - month*32; year +=1980; } /*********************************************************************************************/ /* unpack_time : entpackt die zeit (von zb dateien) */ /*********************************************************************************************/ void unpack_time (unsigned short packed, int &sec, int &min, int &hour) { hour = packed >> 11; min = (packed - hour*2048) >> 5; sec = packed - hour*2048 - min*32; // sekunden sind noch nicht getestet !!! } /*********************************************************************************************/ /* num_ed : Editor fr Zahlen */ /*********************************************************************************************/ void num_ed ( long &sel, long min, long max) { tcurpos pos; // Pos des Eingabefieldes if (min>max) { int i; i = min; min = max; max = i; } /* endif */ printf ("\n"); cprintf (" (%i <= x <= %i) : ", min, max); pos = getcurpos (); _settextposition (pos.y+1, pos.x+1); _settextcolor (fgcolor); _setbkcolor (bkcolor); _outtext (" "); _settextcolor (7); _setbkcolor (0); setcurpos (pos.x, pos.y); cprintf ("%11i", sel); do { int input; if ((selmax)) { if (sel max) sel = max; setcurpos (pos.x, pos.y); cprintf (" "); setcurpos (pos.x, pos.y); cprintf ("%11i", sel); } /* endif */ do { input = getch (); if (isdigit(input) && (-214748363<=sel) && (sel<=214748363)) { if (sel>=0) { sel = sel*10 + (input-48); } else { sel = sel*10 - (input-48); } /* endif */ setcurpos (pos.x, pos.y); cprintf ("%11i", sel); } /* endif */ if ((input==8) && (sel!=0)) { sel /= 10; setcurpos (pos.x, pos.y); cprintf (" "); setcurpos (pos.x, pos.y); cprintf ("%11i", sel); } /* endif */ if ((input==27) || (sel==0)) { sel = 0; setcurpos (pos.x, pos.y); cprintf ("%11i", sel); } /* endif */ if ((input=='-') && (sel!=0) && (min<0)) { sel *= -1; setcurpos (pos.x, pos.y); cprintf (" "); setcurpos (pos.x, pos.y); cprintf ("%11i", sel); } /* endif */ } while (input!=13); /* enddo */ } while ((selmax)); /* enddo */ printf("\n"); } void num_ed ( unsigned short &sel, long min, long max) { long tmp = sel; num_ed ( tmp, min, max ); sel = tmp; } void num_ed ( char &sel, long min, long max) { long tmp = sel; num_ed ( tmp, min, max ); sel = tmp; } void num_ed ( int &sel, long min, long max) { long tmp = sel; num_ed ( tmp, min, max ); sel = tmp; } /*********************************************************************************************/ /* stredit : Editor fr dynamische strings (ruft die Funktionen von class cstredit auf) */ /*********************************************************************************************/ void stredit (pchar &string, char maxlength, char xpos, char ypos) { cstredit se; se.init (&string, maxlength, xpos, ypos); se.edit (); se.done (); } /*********************************************************************************************/ /* stredit2 : Editor fr statische strings (ruft die Funktionen von class cstredit auf) */ /*********************************************************************************************/ void stredit2 (char *string, char maxlength, char xpos, char ypos) { char *c = strdup ( string ); cstredit se; se.init (&c, maxlength, xpos, ypos); se.edit (); se.done (); strcpy ( string, c ); free (c); } /*********************************************************************************************/ /* bitselect : Bit-Editor (ruft die Funktionen von class cbitselect auf) */ /*********************************************************************************************/ void bitselect (long &bits, const char *selection[], char bitnum) { cbitselect bs; tterrainbits bts ( bits ); bs.init (bts, (char**) selection, bitnum); bs.select (); bs.done (); bits = bts.terrain1; } void bitselect ( unsigned short &bits, const char *selection[], char bitnum) { cbitselect bs; tterrainbits bts ( bits ); /* char _selection[50][50]; // ?????????????????? for (int i=0; *selection[i]!=NULL; i++) { strcpy(_selection[i] , selection[i] ); }*/ bs.init (bts, (char**) selection, bitnum); bs.select (); bs.done (); bits = bts.terrain1; } void bitselect (char &bits, const char *selection[], char bitnum) { cbitselect bs; tterrainbits bts ( bits ); bs.init (bts, (char**) selection, bitnum); bs.select (); bs.done (); bits = bts.terrain1; } void bitselect (int &bits, const char *selection[], char bitnum) { cbitselect bs; tterrainbits bts ( bits ); /* char _selection[50][50]; // ?????????????????? for (int i=0; *selection[i]!=NULL; i++) { strcpy(_selection[i] , selection[i] ); } */ bs.init (bts, (char**) selection, bitnum); bs.select (); bs.done (); bits = bts.terrain1 ; } void bitselect ( tterrainbits &bits, const char *selection[], char bitnum) { cbitselect bs; bs.init (bits, (char**) selection, bitnum); bs.select (); bs.done (); } /*********************************************************************************************/ /* yn_switch : schalter (ruft die Funktionen von class cyn_switch auf) */ /*********************************************************************************************/ void yn_switch (char *s1, char *s2, char v1, char v2, char &oldvalue) { fflush ( stdout ); cyn_switch sw; sw.init (s1, s2, v1, v2, oldvalue); sw.select (); sw.done (); } /*********************************************************************************************/ /* fileselect : dateimen (ruft Funktionen von class cfileselect auf) */ /*********************************************************************************************/ void fileselect (char *searchstr, unsigned attributes, tfile &file) { cfileselect fs; fs.init (searchstr, attributes); fs.select (); fs.done (file); } /*********************************************************************************************/ /* class cstredit : Editor fr strings */ /*********************************************************************************************/ void cstredit :: init (char **_string, char _maxlength, char x, char y) { string = (char*) malloc ( _maxlength ); oldstring = _string ; if ( *_string != NULL ) { strcpy ( string , *_string ); } else { string[0]=0; *oldstring = (char*) malloc ( 1 ) ; (*oldstring)[0]=0; } maxlength = _maxlength; if ((x==255) || (y==255)) { printf ("\n "); textpos = getcurpos (); } else { textpos.x = x; textpos.y = y; } /* endif */ pos = strlen (string); status = insert; _settextcolor (fgcolor); _setbkcolor (bkcolor); _settextposition (textpos.y+1, textpos.x+1); for (int i=0; i<=maxlength; i++) { _outtext(" "); } /* endfor */ setcurpos (textpos.x, textpos.y); cprintf (string); } /*void cstredit :: showstr () { setcurpos (textpos.x, textpos.y); cprintf ("%s", string); setcurpos (textpos.x+pos, textpos.y); }*/ void cstredit :: addchar (char c) { int i=0; char s[255]; strcpy (s, string); string[0] = 0; while (i0)) { delchar (left); } /* endif */ if ((input==27) && (strcmp (string, *oldstring)!=0)) { setoldstr (); } /* endif */ if (input==255) { putch (7); } /* endif */ if (input==0) { input = getch (); if ((input==75) && (pos>0)) pos--; if ((input==77) && (pos0) { sel--; } else { sel=quantity-1; } /* endif */ break; case down: if (sel0) { position = 0; sel = 0; if (quantity>=num_odf) { maxposition = quantity-num_odf; maxsel = num_odf-1; } else { maxposition = 0; maxsel = quantity -1; } /* endif */ clearscreen (); sort (sortname); setcurpos (0,0); printf (" ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n"); printf (" filename size date time \n"); printf (" ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n"); displayallfiles (); printf (" ÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\n"); cprintf (" %3i files of %-12s ", quantity, searchstr); _settextcursor (0x2000); // cursor off bar (on); } /* endif */ }; void cfileselect :: search_files (char *searchstr, unsigned attributes) { quantity = 0; { // count tfindfile ff ( searchstr ); string filename = ff.getnextname(); while( !filename.empty() ) { quantity++; filename = ff.getnextname(); } } if (quantity>0) { int i=0; file = new tfile[quantity]; tfindfile ff ( searchstr ); string filename = ff.getnextname(); while( !filename.empty() ) { strcpy (file[i].name, filename.c_str() ); /* file[i].size = fileinfo.size; file[i].date = fileinfo.wr_date; file[i].time = fileinfo.wr_time; */ file[i].size = 0; file[i].date = 0; file[i].time = 0; i++; filename = ff.getnextname(); } } /* endif */ } void cfileselect :: displayallfiles (void) { char string[100]; setcurpos (0,3); for (long i=position; i= file[searcher].date * 100000 + file[searcher].time; cond2 = founddate <= file[searcher].date * 100000 + file[searcher].time; } /* endif */ if ((cond1 == 1) && (cond2 == 1)) { found = searcher; strcpy (foundname, file[found].name); founddate = file[searcher].date * 100000 + file[searcher].time; } /* endif */ } /* endfor */ strcpy (sortfile[_new].name, file[found].name); sortfile[_new].size = file[found].size; sortfile[_new].date = file[found].date; sortfile[_new].time = file[found].time; strcpy (file[found].name, ""); // dateiinfos werden "entwertet" file[found].date = 65535; // dateiinfos werden "entwertet" strcpy (lastname, foundname); strcpy (foundname, "ūūūūūūūūūūūū"); lastdate = founddate; founddate = 0; } /* endfor */ free (file); file = sortfile; _settextcolor (fgcolor); _setbkcolor (0); if (option==sortname) { _settextposition (2,5); _outtext ("filename"); _settextcolor (7); _settextposition (2,37); _outtext ("date"); sortstatus = sortname; } else { _settextposition (2,37); _outtext ("date"); _settextcolor (7); _settextposition (2,5); _outtext ("filename"); sortstatus = sorttime; } /* endif */ } void cfileselect :: select (void) { if (quantity>0) { char input; do { input = getch (); if ((toupper(input) == 'N') && (sortstatus != sortname)) { // left key sort (sortname); displayallfiles (); } /* endif */ if ((toupper(input) == 'D') && (sortstatus != sorttime)) { // right key sort (sorttime); displayallfiles (); } /* endif */ if (input==0) { input = getch (); if (input==72) { // up key if (sel>0) { bar (off); sel--; bar (on); } else { if (position>0) { position--; displayallfiles (); } /* endif */ } /* endif */ } /* endif */ if (input==80) { // down key if (sel0) { position=0; displayallfiles (); } /* endif */ } /* endif */ if (input==79) { //ende if (sel != maxsel) { bar (off); sel=maxsel; bar (on); } /* endif */ if (position != maxposition) { position = maxposition; displayallfiles (); } /* endif */ } /* endif */ if (input==73) { //Bild up if (position>0) { if (position>=num_odf) { position -= num_odf; } else { position = 0; } /* endif */ displayallfiles (); } else { if (sel>0) { bar (off); sel=0; bar (on); } /* endif */ } /* endif */ } /* endif */ if (input==81) { //Bild down if (position0) { strcpy (selected_file.name, file[position+sel].name); selected_file.size = file[position+sel].size; selected_file.date = file[position+sel].date; selected_file.time = file[position+sel].time; free (file); _settextcolor (7); _setbkcolor (0); _settextcursor (0x0607); // normal underline cursor clearscreen (); } else { strcpy (selected_file.name, ""); selected_file.size = 0; selected_file.date = 0; selected_file.time = 0; } /* endif */ } /* //------------------------------------------------------------------------------ void settxtmode33; char z12 [255,11]; char z14 [255,13]; char a; var az12:z12;pz14:^z14;a:byte;r: registers ;pz12:pointer; { r.ax:=$1130; r.bh:=2; intr($10,r); pz14:=ptr(r.es,r.bp); for a:=0 to 255 do move(pz14^[a,1],az12[a,0],12); pz12:=@az12; asm push bp mov ax,$1110 mov bx,$0C00 mov cx,256 mov dx,0 les bp,pz12 int $10 pop bp end; }; //------------------------------------------------------------------------------ */ /* boolean AnhangTest(char * s, Byte i) { int * untyped file * F1; Byte Counter; Char c; int size; Integer i2; return false; size = 0; assign(F1,paramstr(0)); reset(&F1,1); for (i2 = 1; i2 <= i; i2++) { Counter = 0; do { BlockRead(F1,c,1); if (c == '') inc(Counter); else Counter = 0; inc(size); } while (!((Counter == 10) || (size > FileSize(F1)))); if (Counter == 10) return true; else { return false; fclose(F1); return; } } fclose(F1); } void Anhaengen(char * s, Byte Pos) { int * untyped file / F1, F2, F3; Pointer p; Word NumRead, NumWritten; if (AnhangTest(s,Pos) == false) { GetMem(p,500); assign(F3,paramstr(0)); assign(F2,s); assign(F1,paramstr(0)); Rename(F3,"*.tmp"); reset(&F2); rewrite(&F1); do { BlockRead(F3,*p,500,NumRead); BlockWrite(F1,*p,NumRead,NumWritten); } while (!((NumRead == 0) || (NumWritten != NumRead))); fclose(F3); sbld(s,"%s",s); BlockWrite(F1,s,22); do { BlockRead(F2,*p,500,NumRead); BlockWrite(F1,*p,NumRead,NumWritten); } while (!((NumRead == 0) || (NumWritten != NumRead))); } } */ void settxt50mode ( void ) { /* ah = 11 al = 12 bl = 0 int 10 */ REGS regs; regs.w.ax = 0x3; int386 ( 0x10, ®s, ®s ); regs.w.ax = 0x1112; regs.w.bx = 0x0; int386 ( 0x10, ®s, ®s ); /* regs.w.ax = 0x1202; regs.w.bx = 0x30; int386 ( 0x10, ®s, ®s ); regs.w.ax = 0x03; int386 ( 0x10, ®s, ®s ); regs.w.ax = 0x1112; int386 ( 0x10, ®s, ®s ); */ /* initsvga ( 0x108 ); */ } void terrainaccess_ed ( pterrainaccess ft, char* name ) { printf ("\n Terrain the %s can drive on / be build on \n" " (for many %ss it is enough to specify only this field): \n", name, name ); bitselect (ft->terrain, cbodenarten, cbodenartennum); printf ("\n ALL these selected terrain-bits are necessary for the %s to drive / be build there : \n", name); bitselect (ft->terrainreq, cbodenarten, cbodenartennum); printf ("\n NONE of these bits must be set for the %s to drive / be build there\n" " if you are creating a vehicle: \n" " all ships (except icebreaker) must have the ice/snow bits set here) \n", name); bitselect (ft->terrainnot, cbodenarten, cbodenartennum); printf ("\n the %s dies on ... ( only if it cannot enter, see enntries above): \n" " most land based %ss should have the water-bits set here \n", name, name); bitselect (ft->terrainkill, cbodenarten, cbodenartennum); } #if 0 void fatalError ( const char* formatstring, ... ) { va_list paramlist; va_start ( paramlist, formatstring ); char tempbuf[1000]; int lng = vsprintf( tempbuf, formatstring, paramlist ); va_end ( paramlist ); fprintf(stderr, tempbuf ); exit(1); } #endif