clrscr, gotoxy, textcolor etc.

Hier dürfen auch unregistrierte Besucher posten.
Antworten
Charlie

clrscr, gotoxy, textcolor etc.

Beitrag von Charlie »

Hallo,
ich bräuchte eure Hilfe. Und zwar suche ich nach der Möglichkeit, folgendes in C in DOS zu realisieren (Einige der Punkte sind in den Borland-DOS-Compilern schon in speziellen Funktionen der conio.h vorhanden, aber ich suche nach einer Möglichkeit, das ganze unter jedem DOS-Compiler auszuführen):

- clrscr

- gotoxy

- textcolor, textbackground

- Den ganzen Bildschirm mit einem Mal mit beliebigen Zeichen, die beliebige Farben haben, füllen. (Also nicht per Schleife an jede Stelle gehen, die Farbe einstellen und das Zeichen schreiben, sondern ein Array mit allen Zeichen plus jeweiliger Farbe haben und dieses Array mit einem Mal in den Ausgabespeicher schreiben.)

- Auslesen und Ändern der Codepage

- Auslesen und Ändern der Textmodusauflösung (80 x 25, 80 x 50 etc.)

- Wechsel zwischen "16 Vordergrundfarben, 8 Hintergrundfarben und die Möglichkeit, Zeichen blinken zu lassen" und "16 Vordergrundfarben und 16 Hintergrundfarben"
freecrac
DOS-Guru
Beiträge: 861
Registriert: Mi 21. Apr 2010, 11:44
Wohnort: Hamburg Horn

Re: clrscr, gotoxy, textcolor etc.

Beitrag von freecrac »

Hallo Charle,
Charlie hat geschrieben:Hallo,
ich bräuchte eure Hilfe. Und zwar suche ich nach der Möglichkeit, folgendes in C in DOS zu realisieren (Einige der Punkte sind in den Borland-DOS-Compilern schon in speziellen Funktionen der conio.h vorhanden, aber ich suche nach einer Möglichkeit, das ganze unter jedem DOS-Compiler auszuführen):

- clrscr

- gotoxy

- textcolor, textbackground

- Den ganzen Bildschirm mit einem Mal mit beliebigen Zeichen, die beliebige Farben haben, füllen. (Also nicht per Schleife an jede Stelle gehen, die Farbe einstellen und das Zeichen schreiben, sondern ein Array mit allen Zeichen plus jeweiliger Farbe haben und dieses Array mit einem Mal in den Ausgabespeicher schreiben.)

- Auslesen und Ändern der Codepage

- Auslesen und Ändern der Textmodusauflösung (80 x 25, 80 x 50 etc.)

- Wechsel zwischen "16 Vordergrundfarben, 8 Hintergrundfarben und die Möglichkeit, Zeichen blinken zu lassen" und "16 Vordergrundfarben und 16 Hintergrundfarben"
Ich kenne mich mit C gar nicht aus und programmiere am liebsten alles in Assembler. Damit lassen sich solche Dinge relativ einfach realisieren.
Für einige diese Dinge benutzt man am besten Bios-Routinen, die man im "RBIL" finden kann.

Ralf Browns x86/MSDOS Interrupt List (RBIL)
http://www.pobox.com/~ralf
http://www.pobox.com/~ralf/files.html
ftp://ftp.cs.cmu.edu/afs/cs.cmu.edu/user/ralf/pub/

Zum Auslesen der Codepage:
RBIL->inter61b.zip->Interrup.h

Code: Alles auswählen

--------D-216601-----------------------------
INT 21 - DOS 3.3+ - GET GLOBAL CODE PAGE TABLE
	AX = 6601h
Return: CF set on error
	    AX = error code (see #01680 at AH=59h/BX=0000h)
	CF clear if successful
	    BX = active code page (see #01757)
	    DX = system code page (see #01757)
SeeAlso: AX=6602h
Zum Ändern der Codepage:

Code: Alles auswählen

--------D-216602-----------------------------
INT 21 - DOS 3.3+ - SET GLOBAL CODE PAGE TABLE
	AX = 6602h
	BX = active code page (see #01757)
	DX = system code page (active page at boot time)
Return: CF set on error
	    AX = error code (see #01680 at AH=59h/BX=0000h)
	CF clear if successful
	    AX = EB41h (Novell NWDOS v7.0 when NLSFUNC not installed and
		  request was for previously-active code page)
SeeAlso: AX=6601h,INT 2F/AX=14FFh

(Table 01757)
Values for code page:
 0	Reduced 7-bit ASCII			[NetWare]
 37	EBCDIC: US/Canada English (CECP)	[Windows NT 3.51+]
 38	EBCDIC: International (old)
 111	Greek
 112	Turkish
 113	Yugoslavian
 161	Arabic					[Linux]
 162	Arabic					[Linux]
 163	Arabic					[Linux]
 164	Arabic					[Linux]
 165	Arabic					[Linux]
 237	EBCDIC: Germany (CECP)
 273	EBCDIC: ??? (CECP)
 274	EBCDIC: Belgium
 275	EBCDIC: Brazilian
 277	EBCDIC: Danish/Norwegian (CECP)
 278	EBCDIC: Finnish/Swedish (CECP)
 280	EBCDIC: Italian (CECP)
 281	EBCDIC: Japanese-E
 284	EBCDIC: Latin-American/Spanish (CECP)
 285	EBCDIC: UK English (CECP)
 290	EBCDIC: Japanese Kana
 297	EBCDIC: French (CECP)
 367	US-ASCII (ISO 646-US, 7-bit)
 420	EBCDIC: Arabic 1
 423	EBCDIC: Greek
 424	EBCDIC: Hebrew
 437	US / English / PC-8 / IBM-2
 500	EBCDIC: Belgium/Switzerland (CECP)
 500	EBCDIC: International
 646	(??? reserved for ISO 646 7-bit codepages)
 667	Eastern Europe (Polish)
 668	Eastern Europe (Slavic)
 708	Arabic/Middle East
 737	Greek (2)
 775	Baltic / Baltic Rim
 819	Latin-1 (ISO 8859-1)
 850	Multilingual (Latin-1)
 851	Greek
 852	Slavic/Easter Europe (Latin-2)		[DOS 5+]
 853	Turkish (Latin-2)
 854	Spanish
 855	Cyrilic (1)
 857	Turkish
 860	Portugese
 861	Icelandic
 862	Hebrew
 863	French Canadian
 864	Arabic/Middle East
 865	Nordic (Norwegian/Danish)
 866	Russian (Cyrillic 2)
 867	Czech
 868	Arabic
 869	Greek (1)
 870	EBCDIC: Yugoslavia (Roece)
 871	EBCDIC: Icelandic
 874	Thailand
 875	EBCDIC: Greek
 880	Russian (Cyrillic GOST)
 880	EBCDIC: Cyrillic
 881	Latin 1 (ISO 8859-1)
 882	Latin 2 (ISO 8859-2)
 883	Latin 3 (ISO 8859-3)
 884	Latin 4 (ISO 8859-4)
 885	Latin 5 (ISO 8859-5)
 891	unknown
 897	Japanese (Shift-JIS)
 903	unknown
 904	unknown
 905	EBCDIC: Turkish
 912	Latin 2 (ISO 8859-2: Eastern Europe)
 913	(??? reserved for Latin 3)
 914	(??? reserved for Latin 4)
 915	Cyrillic (ISO 8859-5: Latin/Cyrillic)
 916	(??? reserved for ISO 8859-6: Latin/Arabic)
 917	(??? reserved for ISO 8859-7: Latin/Greek)
 918	EBCDIC: Arabic 2
 919	(??? reserved for ISO 8859-9: Latin 5)
 920	(??? reserved for ISO 8859-10: Latin 6/Sami)
 932	DBCS: Japanese (Shift-JIS)
 934	DBCS: Korean
 936	DBCS: Chinese (PRC/ROC, Simplified/xGB)
 938	DBCS: Taiwan
 938	DBCS: Chinese (PRC/ROC)
 942	DBCS: Japanese SAA
 944	DBCS: Korean SAA
 948	DBCS: Chinese SAA (PRC/ROC)
 949	Korean (Unified Hangul; Extended Wansung)
 950	Chinese Traditional, Big5 (Taiwan, Hong Kong)
 966	Saudi Arabian
 972	Hebrew (Israeli VT100)
 999	reserved for user-definable codepages
1004	Desktop Publishing
1026	EBCDIC: Turkish (Latin 5)
1047	EBCDIC: International (CECP, de-facto EBCDIC-US)
1250	MSWIN: Eastern Europe (Latin 2)
1251	MSWIN: Cyrillic
1252	MSWIN: English/W. Europe/Standard (Latin 1)
1253	MSWIN: Greek (GRC)
1254	MSWIN: Turkish
1255	MSWIN: Hebrew
1256	MSWIN: Arabic
1257	MSWIN: Baltic (Estonian, Latvian, Lithuanian)
1258	MSWIN: Vietnamese
1361	ANSI???: Korean (Johab)
10000	MAC: International/Standard (Roman)
10006	MAC: Greek
10007	MAC: Cyrillic
10029	MAC: Latin 2
10079	MAC: Icelandic
10081	MAC: Turkish
10646	(should be reserved for the future ISO 10646 32-bit codepage???)
65400	OS/2: reserved for Glyphs
Notes:	not all code pages are available in all versions of DOS or
	  DOS-compatibles, and many (particularly EBCDIC) have not been
	  implemented for *any* DOS to date
	CECP = 'Country Extended CodePage' by IBM.
	Unicode (UCS-2) is a 16-bit character codeset, covering all commonly
	  used characters from almost any language. Not all definitions are
	  fixed at the time of this writing. Unicode will be the future of
	  character coding for the foreseeable future, but is only the
	  "basic multilingual plane" (BMP) subset of 32-bit ISO 10646 codes
	  (UCS-4), a single character set standard covering requirements for
	  all countries and languages, which is still under construction.
	The MS Windows 'ANSI' codepage 1252 (based on the MS Windows 3.0+
	  implementation) appears to be 100% compatible with the code sets
	  used by Amiga OS and Acorn Archimedes RISC-OS and is also a linear
	  subset of the 16bit UniCode code set (UCS-2); the actual ANSI
	  codepage is defined by ISO 8859-1 (Latin 1).
	At least applications for OS/2 Warp 3 Presentation Manager can use
	  EBCDIC codepages, but the codepage ID assignments for EBCDIC
	  codepages are not known for OS/2. OS/2 SAA codepages are not
	  supported in CONFIG.SYS.  Codepage 65400 "Glyphs" is not actually a
	  codepage, but a way to directly access the first 256 of the 383
	  glyphs from the current font set.
	Novell DOS 7/DR DOS 6/Caldera OpenDOS undocumented codepage 853
	  does not necessarily match with MS-DOS' undocumented codepage 853.
	Undocumented codepages 667 and 668 can be found in Russian's PTS/DOS
	  6.51 and S/DOS 1.x DISPLAY.CPI and contain some Eastern European
	  characters.
	Novell NetWare 3.xx clients support UniCode and codepages 437, 850,
	  860, 863, 865, 897, 932, and 1252 (possibly more). NetWare 4.xx
	  clients also support 1250, 1251, 1256. Personal NetWare 1.0 (PNW),
	  as it was distributed in Europe, supports UniCode and codepages 437,
	  850 and 1252.	 Novell's Client32 for DOS/Windows supports 874, 932,
	  936, 949, 950, 1250 - 1257. For codesets not yet available, Novell
	  offers a reduced ASCII 7-bit support through a codepage 0 used as a
	  translation table to UniCode, that supports characters 32-127 except
	  92 ('\').

Format of DOS .CPI (Code Page Information) file header:
Offset	Size	Description	(Table 01758)
 00h	BYTE	ID tag
		FFh FONT file (Standard for generic display or
		      printer font files used by MS-DOS, PC-DOS, DR DOS
		      and Novell DOS)
		7Fh DRFONT file (Used by DR DOS 6.0 / Novell DOS 7 for
		      enhanced & compressed display font files. DR DOS 6.0
		      and Novell DOS 7 still support the standard FONT
		      files, thus allowing leaning of .CPI files from
		      MS-DOS to DR DOS / Novell DOS!)
 01h  7 BYTEs	ID string
		"FONT	" = FONT file (Standard for display or printer)
		"DRFONT " = DRFONT file (Enhanced compressed format used
			    by DR DOS 6.0 / Novell DOS 7 for display fonts)
 08h  8 BYTEs	reserved (0)
 10h	WORD	number of pointers (1)
 12h	BYTE	type of pointers (1)
 13h	DWORD	pointer to file offset of FontInfoHeader
		(Generally pointing to the byte just after FontFileHeader,
		     that is 0000h:0017h. Due to extra data at offset 17h, this
		     value has changed with DR DOS 6.0 / Novell DOS 7 DRFONTs!
		     "MS-DOS 4.0 programmers reference" claimed word offset
		     +15h as an endmarker (0000h), but actually it is the
		     High-Word of the pointer.)
--- Extended FontFileHeader with DR DOS 6.0 / Novell DOS 7 DRFONTs: ---
 17h	BYTE	number of fonts per codepage supported by this file
		     (N=4 with both DR DOS 6.0 / Novell DOS 7 DRFONT files)
 18h  N	BYTEs	cellsize (Height) of fonts 1..N
		the cellsize corresponds with the character boxes height,
		  but is also the count of bytes used for each of the
		  characters inside the font data (as currently all fonts
		  are organized heightx8 and 8 pixel width is just one byte).
 var  N DWORDs	file offsets of DisplayFontData.

Format of DOS .CPI file Font Information Header:
Offset	Size	Description	(Table 01759)
 00h	WORD	number of codepage entries
	var	N codepage entry headers (see #01760)
SeeAlso: #01758

Format of DOS .CPI file CodePage Entry Header:
Offset	Size	Description	(Table 01760)
 00h	WORD	size of this header (normally 1Ch)
 02h	DWORD	offset of next entry, or 0000h:0000h or FFFFh:FFFFh if last
		(if a valid "next" pointer but all of the fonts indicated in
		  the .CPI header have been processed, this field normally
		  points at an optional text area at the end of the .CPI file
		  containing copyright information)
 06h	WORD	device type
		01h display (FONT or DRFONT)
		02h printer (FONT)
 08h  8 BYTEs	blank-padded device name string
 10h	WORD	code page (see #01757)
 12h  3 WORDs	reserved (0)
 18h	DWORD	pointer to Font Data Header (see #00222)
		normally immediately follows this header
SeeAlso: #01758

Format of DOS .CPI file Font Data Header:
Offset	Size	Description	(Table 01761)
 00h	WORD	record type
		0001h FONT
		0002h DRFONT (DR DOS 6.0/Novell DOS 7 display font)
 02h	WORD	number of fonts
 04h	WORD	length of font data (display fonts)
		??? (printer fonts)
 06h	var	font data (#fonts * fontlength) bytes
SeeAlso: #01758

Format of DOS .CPI file ScreenFONT Header:
Offset	Size	Description	(Table 01762)
 00h  6 BYTEs	display-font header (see #01764)
 06h	var	display font data
SeeAlso: #01758

Format of .CPI file DRFONT Header:
Offset	Size	Description	(Table 01763)
 00h 6N BYTEs	DisplayFONT headers for N fonts (see #01764)
      M WORDs	character index table for cell offsets in font data
		currently 256 words in length
SeeAlso: #01758

Format of .CPI file DisplayFONT header:
Offset	Size	Description	(Table 01764)
 00h	BYTE	height of character cell
 01h	BYTE	width of character cell (currently always 08h)
 02h	BYTE	aspect ratio (height) (currently 00h, unused)
 03h	BYTE	aspect ratio (width) (currently 00h, unused)
 04h	WORD	number of characters per font (256)
SeeAlso: #01758

Format of .CPI file PrinterFONT header:
Offset	Size	Description	(Table 01765)
 00h	WORD	type of printer
		0001h (4201.CPI, 1050.CPI, EPS.CPI)
		0002h (4208.CPI, 5202.CPI, PPDS.CPI)
 02h	WORD	bytes per hardware/download codepage-select escape sequence
		(max 31, typically 12)
 04h  N BYTEs	escape sequence to select hardware codepage
      N BYTEs	escape sequence to select download codepage
	var	download data for printer font (including escape sequence to
		  transfer data)
SeeAlso: #01758
.....

Zum Auslesen der Textmodusauflösung:(8x8=80x50; 8x16=80x25; 8x14=80x43):
(80x43 wird kaum noch unterstützt)
RBIL->inter61a.zip->Interrup.a

Code: Alles auswählen

--------V-101130-----------------------------
INT 10 - VIDEO - GET FONT INFORMATION (EGA, MCGA, VGA)
	AX = 1130h
	BH = pointer specifier
	    00h INT 1Fh pointer
	    01h INT 43h pointer
	    02h ROM 8x14 character font pointer
	    03h ROM 8x8 double dot font pointer
	    04h ROM 8x8 double dot font (high 128 characters)
	    05h ROM alpha alternate (9 by 14) pointer (EGA,VGA)
	    06h ROM 8x16 font (MCGA, VGA)
	    07h ROM alternate 9x16 font (VGA only) (see #00021)
	    11h (UltraVision v2+) 8x20 font (VGA) or 8x19 font (autosync EGA)
	    12h (UltraVision v2+) 8x10 font (VGA) or 8x11 font (autosync EGA)
Return: ES:BP = specified pointer
	CX    = bytes/character of on-screen font (not the requested font!)
	DL    = highest character row on screen
Note:	for UltraVision v2+, the 9xN alternate fonts follow the corresponding
	  8xN font at ES:BP+256N
BUG:	the IBM EGA and some other EGA cards return in DL the number of rows on
	  screen rather than the highest row number (which is one less).
SeeAlso: AX=1100h,AX=1103h,AX=1120h,INT 1F"SYSTEM DATA",INT 43"VIDEO DATA"

Format of alternate font table [array]:
Offset	Size	Description	(Table 00021)
 00h	BYTE	character to be replaced (00h = end of table)
 01h  N BYTEs	graphics data for character, one byte per scan line
Zum Ändern der Textmodusauflösung (80 x 50):

Code: Alles auswählen

--------V-101112-----------------------------
INT 10 - VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x8 DBL-DOT PATTERNS (PS,EGA,VGA)
	AX = 1112h
	BL = block to load
Return: nothing
Notes:	(see AX=1110h)
SeeAlso: AX=1103h,AX=1110h,AX=1111h,AX=1114h,AH=1Bh,AX=CD10h
Zum Ändern der Textmodusauflösung (80 x 25):

Code: Alles auswählen

--------V-101114-----------------------------
INT 10 - VIDEO - TEXT-MODE CHARGEN - LOAD ROM 8x16 CHARACTER SET (VGA)
	AX = 1114h
	BL = block to load
Return: nothing
Notes:	(see AX=1110h)
SeeAlso: AX=1104h,AX=1110h,AX=1111h,AX=1112h,AH=1Bh,AX=CD10h
Zum Ändern der Textmodusauflösung (80x43):

Code: Alles auswählen

--------V-101111-----------------------------
INT 10 - VIDEO - Realtek RTVGA - SET ROM 8x14 GRAPHICS CHARACTERS
	AX = 1111h
	BL = row specifier (see AX=1121h)
Return: nothing
Note:	this function is meant to be called immediately after a mode set;
	  results are unpredictable at other times
SeeAlso: AX=110Fh"Realtek",AX=1110h"Realtek",AX=1122h

	BL = row specifier
	    00h user set
		DL = number of rows
	    01h 14 rows
	    02h 25 rows
	    03h 43 rows
...

Um den Textbildschirm zu löschen, oder zu befüllen gibt es unterschiedliche Möglichkeiten.
Soll es auch noch auf einem 80286er lauffähig sein, oder dürfen schon 32 Bit-Register eines 80386+ verwendet werden?

Bildschirm löschen mit der Verwendung von 32 Bit-Register/Befehle:

Code: Alles auswählen

         mov     ax, 0B800h                    ; Segmentadresse des Textbildschirms
         mov     es, ax 
         xor     di, di                        ; DI-Register auf null setzen
         mov      eax, 1F201F20h               ; Farben + Leerzeichen
         mov      cx, (Spalten * 2 * Zeilen)/4
         rep stosd
 
Bildschirm aus Array befüllen mit der Verwendung von 32 Bit-Register/Befehle:

Code: Alles auswählen

         mov     ax, 0B800h                    ; Segmentadresse des Textbildschirms
         mov     es, ax 
         xor     di, di                        ; DI-Register auf null setzen
         mov     ax, @DATA                     ; Segmentadresse unseres Datenbereichs
         mov     ds, ax 
         mov     si, OFFSET ARRAY              ; SI-Register mit OFFSET des Arrays laden
         mov     cx, (Spalten * 2 * Zeilen)/4
         rep movsd
Für blinkende Zeichen schaue doch mal hier rein:
http://de.wikipedia.org/wiki/Textmodus

Bei Textmodi die vom Standard abweichen kann dir evtl. ein anderer Leser weiterhelfen.

Dirk
Charlie

Re: clrscr, gotoxy, textcolor etc.

Beitrag von Charlie »

Danke erstmal. Aber mit Assembler kenne ich mich gar nicht aus. Mir wär's wirklich lieber, wenn ich das ganze in C mit Funktionen aus der dos.h machen könnte.
freecrac
DOS-Guru
Beiträge: 861
Registriert: Mi 21. Apr 2010, 11:44
Wohnort: Hamburg Horn

Re: clrscr, gotoxy, textcolor etc.

Beitrag von freecrac »

Charlie hat geschrieben:Danke erstmal. Aber mit Assembler kenne ich mich gar nicht aus. Mir wär's wirklich lieber, wenn ich das ganze in C mit Funktionen aus der dos.h machen könnte.
Wie schon erwähnt, weder C noch die Funktionen vom "dos.h" sind mir vertraut.
Falls die von dir gewünschten Funktionen dort enthalten sind und man verwendet diese auch, dann wird der damit erzeugte Opcode vorraussichtlich mehr Bytes erzeugen und auch umständlicher gestaltet sein,
als wenn man es für eine konkrete Einzellösung mit verschieden Funktionen kombiniert selber in Assembler optimiert.

Wenn der verwendet C-Compiler Inline-Assembler unterstützt, dann ist es nicht besonders schwer einen entsprechenden Assembler-Code in ein C-Listing einzufügen.
http://www.it-academy.cc/article/889/In ... C+C++.html
http://www.c-plusplus.de/forum/41479
http://de.wikipedia.org/wiki/Integrierter_Assembler

Beispiel zum Umschalten des Textmodes nach 80x50 Zeilen/Spalten (Syntax kann ggf. variieren):
(Siehe dazu auch in meinem vorherigen Beitrag die Beschreibung dieses Interrupts im RBIL.)
_asm
{
mov ax, 1112h
xor bl, bl
int 10h
}
In dem Fall wenn du es mal so versuchen möchtest und dein C-Compiler es auch unterstützt, dann helfe ich dir gerne beim Inline-Assemblern.

Dirk
Gast

Re: clrscr, gotoxy, textcolor etc.

Beitrag von Gast »

Diese Lib ist neben DOS auch noch für andere Systeme geeignet und beherrscht die von dir genannten Befehle in jedem Fall ab:

http://pdcurses.sourceforge.net/
Antworten