home *** CD-ROM | disk | FTP | other *** search
- '* -------------------------------------------------- *
- '* HLPCX.BAS *
- '* (C) 1991 A. Maslo & DMV-Verlag *
- '* Sprache: Quick Basic *
- '* Funktion: PCX-Lader für VGA, 640x480 *
- '* monochrome Fassung *
- '* -------------------------------------------------- *
- DECLARE FUNCTION FILL$ (Binaer$)
- DECLARE FUNCTION BIN$ (Zahl%)
- DECLARE FUNCTION DEZ& (Binaer$)
- DECLARE FUNCTION LFILL$ (Binaer$, Char$, n%)
- DECLARE FUNCTION Combine% (FirstByte$, SecondByte$)
- DECLARE SUB LoadPCX (Datei$)
- DECLARE SUB ClosePCX ()
- DECLARE SUB OpenPCX (Datei$)
- DECLARE FUNCTION PCXHeader$ ()
- DECLARE SUB PCXInit ()
-
- ON ERROR GOTO Errorhandling '* Fehlerverfolgung
- CLS '* Bildschirm löschen
- LoadPCX "TEST.PCX" '* monochrome PCX-Datei
- WHILE INKEY$ = "": WEND '* Warten auf Tastendruck
- END '* Programm beenden
-
- Errorhandling: '* Sprungmarke Fehlerbehandlung
- SCREEN 0 '* Textbildschirm
- IF ERR = 1 THEN '* Fehler aus LoadPCX
- PRINT "Die Zeichnung beinhaltet mehrere Farbenenen!"
- PRINT "Eine Ausgabe ist mit diesem Programm nicht"
- PRINT "möglich!"
- ELSE
- PRINT "Dateiausgabe nicht möglich..."
- '* Datei fehlt oder ist defekt!
- END IF
- END '* Programm abbrechen, wenn ein
- RESUME '* Fehler aufgetreten ist...
-
-
- FUNCTION BIN$ (Zahl%) '* Integer in Binärstring
- '* umwandeln
- Zahl% = ABS(Zahl%)
- BIN$ = "" '* Leerstring
- x% = -1 '* Variable auf -1 setzen
- WHILE Dummy& <= Zahl% '* höchstmöglichen Exponent
- '* ermitteln
- x% = x% + 1 '* 1. Schleifenwert für x%=0
- Dummy& = 1 * 2 ^ x% '* Berechnungsformel
- WEND '* Ende While-Schleife
- Max% = x% - 1 '* höchster Exponent (Schleife
- '* wird 1x zuviel durchlaufen)
- Rest% = Zahl% '* Mit Kopie der Eingabezahl
- '* weiterarbeiten
- FOR Y% = Max% TO 0 STEP -1
- '* zum Stringaufbau von links nach rechts
- Rest% = Rest% - (1 * 2 ^ Y%)
- '* Rest für nächsten Exponenten
- IF Rest% >= 0 THEN Erg$ = "1"
- '* Interpretation wann 0 oder 1
- IF Rest% < 0 THEN
- Rest% = Rest% + (1 * 2 ^ Y%)
- Erg$ = "0"
- END IF
- Ergebnis$ = Ergebnis$ + Erg$
- '* Binärstring aufbauen
- NEXT Y% '* nächster Exponent
- IF Ergebnis$ = "" THEN Ergebnis$ = "0"
- '* falls String leer, Nullstring ausgeben
- BIN$ = Ergebnis$
- '* String an Funktion übergeben
- END FUNCTION
-
- SUB ClosePCX '* Datei schließen
- SHARED PCXNr '* globale Dateinummer
- CLOSE #PCXNr
- END SUB
-
- FUNCTION Combine% (FirstByte$, SecondByte$)
- '* Speicherwort generieren
- First% = ASC(FirstByte$)
- Second% = ASC(SecondByte$)
- Combine% = INT(First% + Second% * 256)
- END FUNCTION
-
- FUNCTION DEZ& (Binaer$) '* Binärstring in Dezimalzahl
- MaxLen% = LEN(Binaer$) '* konvertieren
- Dezimal% = 0
- FOR x% = 1 TO MaxLen%
- B% = VAL(MID$(Binaer$, x%, 1))
- Dezimal& = Dezimal& + B% * 2 ^ (MaxLen% - x%)
- NEXT x%
- DEZ& = Dezimal&
- END FUNCTION
-
- FUNCTION FILL$ (Binaer$)
- '* Binärstring auf 8 Zeichen auffüllen
- Laenge% = LEN(Binaer$) '* Ist-Länge ermitteln
- Fehl% = 8 - Laenge% '* Fehlende Zahl an Zeichen
- FILL$ = STRING$(Fehl%, "0") + Binaer$
- '* Ergebnisstring aufbauen
- END FUNCTION
-
- SUB LoadPCX (Datei$) '* PCX-Datei laden
- SHARED PCXNr '* im Modul globale Variablen
- SHARED ID%, Ver%, Komp%, Bits%, x1%, y1%, x2%, y2%
- SHARED AX%, ay%, Pal$, Reserve%, Ebenen%, BpL%, Pal%
- SCREEN 12 '* 640x480 Pixel
- OpenPCX Datei$ '* Datei öffnen
- PCXInit '* Headervariablen zuweisen
- IF Ebenen% > 1 THEN
- '* falls mehrere Ebenen=Farbmodus
- ERROR 1 '* Programm beenden!
- END IF
- BildBreite% = x2% - x1% + 1 '* Bildbreite
- Byte$ = SPACE$(1) '* Informationseinheit
- Zeile$ = SPACE$(BildBreite%)
- '* Bildschirmzeilenbreite
- FOR K% = 0 TO y2% - y1% '* Einzelne Bildschirmzeile
- Zeile$ = RIGHT$(Zeile$, LEN(Zeile$) - BildBreite%)
- I% = 0 '* Information
- WHILE NOT I% >= BildBreite%
- '* Zeileninformation vollständig?
- GET #PCXNr, , Byte$ '* Byte lesen
- Byte% = ASC(Byte$) '* ASCII-Code des Byte
- BByte$ = FILL$(BIN$(Byte%)) '* binär kodieren
- IF LEFT$(BByte$, 2) = "11" THEN
- '* obere 2 Bits gesetzt
- BinByte$ = BIN$(Byte%) '* Zähler aus rest-
- '* lichen 6 Bits
- Zaehler% = DEZ&(RIGHT$(BinByte$, 6))
- GET #PCXNr, , Byte$
- '* Bildinformation im nächsten Byte
- BildInfo$ = FILL$(RIGHT$(BIN$(ASC(Byte$)), 8))
- FOR a% = 1 TO Zaehler%
- Zeile$ = Zeile$ + BildInfo$
- '* Binärstring für einzelne Bild-
- '* schirmzeile aufbauen
- NEXT a%
- ELSE
- Zaehler% = 1 '* einmalige Information
- BinByte$ = FILL$(BIN$(Byte%))
- '* binär umkodieren
- BildInfo$ = RIGHT$(BinByte$, 8)
- Zeile$ = Zeile$ + BildInfo$
- '* Information der Zeile anfügen
- END IF
- I% = LEN(Zeile$) '* Informationslänge
- WEND
- FOR Z% = 1 TO BildBreite% - 1 STEP 1
- '* Farbe aus String ermitteln
- IF DEZ&(MID$(Zeile$, Z%, 1)) = 1 THEN
- FARBE% = 0
- ELSE
- FARBE% = 7
- END IF
- PSET (Z%, K%), FARBE% '* Punkt setzen, evtl. hier
- NEXT Z% '* die Farben ändern
- NEXT K%
- ClosePCX '* Datei schließen
- END SUB
-
- SUB OpenPCX (Datei$) '* Datei öffnen
- SHARED PCXNr '* globale Dateinummer
- PCXNr = FREEFILE '* freie Dateinummer
- OPEN Datei$ FOR BINARY AS #PCXNr '* binär öffnen
- END SUB
-
- FUNCTION PCXHeader$ '* PCX-Dateikopf lesen
- SHARED PCXNr '* (128 Byte Länge)
- Header$ = SPACE$(128)
- IF LOF(PCXNr) >= 128 THEN
- GET #PCXNr, , Header$
- PCXHeader$ = Header$
- END IF
- END FUNCTION
-
- SUB PCXInit
- SHARED ID%, Ver%, Komp%, Bits%, x1%, y1%, x2%, y2%
- '* im Modul global
- SHARED AX%, ay%, Pal$, Reserve%, Ebenen%, BpL%, Pal%
- Header$ = PCXHeader$ '* binäre Informationen
- ID% = ASC(LEFT$(Header$, 1))
- '* Identifikation=10, 1 Byte
- Ver% = ASC(MID$(Header$, 2, 1))
- '* Versionnummer, 1 Byte
- Komp% = ASC(MID$(Header$, 3, 1))
- '* Komprimierungsart=1, 1 Byte
- Bits% = ASC(MID$(Header$, 4, 1))
- '* Bits pro Bildpunkt, 1 Byte
- x1% = Combine%(MID$(Header$, 5, 1), _
- MID$(Header$, 6, 1)) '* linke obere Ecke, 2 Bytes
- y1% = Combine%(MID$(Header$, 7, 1), _
- MID$(Header$, 8, 1)) '* linke obere Ecke, 2 Bytes
- x2% = Combine%(MID$(Header$, 9, 1), _
- MID$(Header$, 10, 1)) '* rechte untere Ecke, 2 Bytes
- y2% = Combine%(MID$(Header$, 11, 1), _
- MID$(Header$, 12, 1)) '* rechte untere Ecke, 2 Bytes
- AX% = Combine%(MID$(Header$, 13, 1), _
- MID$(Header$, 14, 1)) '* hor. Auflösung 2 Bytes
- ay% = Combine%(MID$(Header$, 15, 1), _
- MID$(Header$, 16, 1)) '* ver. Auflösung 2 Bytes
- Pal$ = MID$(Header$, 17, 48)
- '* Palette jeweils 3 Byte
- Reserve% = ASC(MID$(Header$, 65, 1)) '* Reserve
- Ebenen% = ASC(MID$(Header$, 66, 1))
- '* Anzahl der Farbebenen
- BpL% = Combine%(MID$(Header$, 67, 1), _
- MID$(Header$, 68, 1)) '* Anzahl Bytes/Zeile, 2 Byte
- Pal% = Combine%(MID$(Header$, 69, 1), _
- MID$(Header$, 70, 1)) '* Art der Palette
- Rest$ = RIGHT$(Header$, 58) '* unbenutzt
- END SUB
-
- '* -------------------------------------------------- *
- '* Ende von HLPCX.BAS *