From max at tyndur.org Thu Oct 1 21:46:27 2009 From: max at tyndur.org (max at tyndur.org) Date: Thu, 1 Oct 2009 21:46:27 +0200 Subject: [tyndur-devel] [PATCH] lbuilds: libogg 1.1.4, libvorbis 1.2.3 Message-ID: <1254426387-6967-1-git-send-email-max@tyndur.org> From: Max Reitz + lbuilds: libogg 1.1.4 hinzugefügt + lbuilds: libvorbis 1.2.3 hinzugefügt Signed-off-by: Max Reitz --- lbuilds/libogg/1.1.4/files/configure.patch | 13 ++++++ lbuilds/libogg/1.1.4/libogg-1.1.4.lbuild | 53 ++++++++++++++++++++++++ lbuilds/libvorbis/1.2.3/files/configure.patch | 13 ++++++ lbuilds/libvorbis/1.2.3/libvorbis-1.2.3.lbuild | 53 ++++++++++++++++++++++++ 4 files changed, 132 insertions(+), 0 deletions(-) create mode 100644 lbuilds/libogg/1.1.4/files/configure.patch create mode 100644 lbuilds/libogg/1.1.4/libogg-1.1.4.lbuild create mode 100644 lbuilds/libvorbis/1.2.3/files/configure.patch create mode 100644 lbuilds/libvorbis/1.2.3/libvorbis-1.2.3.lbuild diff --git a/lbuilds/libogg/1.1.4/files/configure.patch b/lbuilds/libogg/1.1.4/files/configure.patch new file mode 100644 index 0000000..5807a46 --- /dev/null +++ b/lbuilds/libogg/1.1.4/files/configure.patch @@ -0,0 +1,13 @@ +Index: libogg-1.1.4/config.sub +=================================================================== +--- libogg-1.1.4.orig/config.sub ++++ libogg-1.1.4/config.sub +@@ -1195,7 +1195,7 @@ case $os in + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ +- | -aos* \ ++ | -aos* | -tyndur* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ diff --git a/lbuilds/libogg/1.1.4/libogg-1.1.4.lbuild b/lbuilds/libogg/1.1.4/libogg-1.1.4.lbuild new file mode 100644 index 0000000..cd41bea --- /dev/null +++ b/lbuilds/libogg/1.1.4/libogg-1.1.4.lbuild @@ -0,0 +1,53 @@ +include toolchain +include lutils + +DESCRIPTION="libogg" +HOMEPAGE="http://lowlevel.brainsware.org/wiki/index.php/LOST/Pakete/libogg" +SRC_URI="http://downloads.xiph.org/releases/ogg/${P}.tar.gz" +PS="lib" + +LICENSE="unknown" + +BUILD_DEPEND="" +RUN_DEPEND="" + +MY_S="${S}/${P}" + +src_unpack() { +lunpack ${P}.tar.gz +cd ${MY_S} + + ln -s ${F} patches + [ -f ${F}/series ] && ln -s ${F}/series series + for i in ${F}/*.patch; do + [ -L series ] || echo `basename $i` >> series + (which quilt > /dev/null 2>&1) || (patch -p1 < $i) || die "Fehler beim Anwenden von $i" + done + (which quilt > /dev/null 2>&1) && quilt push -a || die "Fehler beim Anwenden der Patches" +} + +src_configure() { + cd ${MY_S} + + ./configure \ + CC=`tc-cc` \ + --build=`tc-build` \ + --target=`tc-host` \ + --host=`tc-host` \ + --prefix="${R}" \ + || die "configure failed" +} + +src_compile() { + cd ${MY_S} + + lmake || die "make failed" + cd .. +} + +src_install() { + cd ${MY_S} + + lmake install prefix="${D}${R}" || die "make install failed" + rm -rf ${D}${R}/share +} diff --git a/lbuilds/libvorbis/1.2.3/files/configure.patch b/lbuilds/libvorbis/1.2.3/files/configure.patch new file mode 100644 index 0000000..f0a02de --- /dev/null +++ b/lbuilds/libvorbis/1.2.3/files/configure.patch @@ -0,0 +1,13 @@ +Index: libvorbis-1.2.3/config.sub +=================================================================== +--- libvorbis-1.2.3.orig/config.sub ++++ libvorbis-1.2.3/config.sub +@@ -1195,7 +1195,7 @@ case $os in + | -*vms* | -sco* | -esix* | -isc* | -aix* | -sunos | -sunos[34]*\ + | -hpux* | -unos* | -osf* | -luna* | -dgux* | -solaris* | -sym* \ + | -amigaos* | -amigados* | -msdos* | -newsos* | -unicos* | -aof* \ +- | -aos* \ ++ | -aos* | -tyndur* \ + | -nindy* | -vxsim* | -vxworks* | -ebmon* | -hms* | -mvs* \ + | -clix* | -riscos* | -uniplus* | -iris* | -rtu* | -xenix* \ + | -hiux* | -386bsd* | -knetbsd* | -mirbsd* | -netbsd* \ diff --git a/lbuilds/libvorbis/1.2.3/libvorbis-1.2.3.lbuild b/lbuilds/libvorbis/1.2.3/libvorbis-1.2.3.lbuild new file mode 100644 index 0000000..f4621b3 --- /dev/null +++ b/lbuilds/libvorbis/1.2.3/libvorbis-1.2.3.lbuild @@ -0,0 +1,53 @@ +include toolchain +include lutils + +DESCRIPTION="libvorbis" +HOMEPAGE="http://lowlevel.brainsware.org/wiki/index.php/LOST/Pakete/libvorbis" +SRC_URI="http://downloads.xiph.org/releases/vorbis/${P}.tar.bz2" +PS="lib" + +LICENSE="unknown" + +BUILD_DEPEND="" +RUN_DEPEND="" + +MY_S="${S}/${P}" + +src_unpack() { +lunpack ${P}.tar.bz2 +cd ${MY_S} + + ln -s ${F} patches + [ -f ${F}/series ] && ln -s ${F}/series series + for i in ${F}/*.patch; do + [ -L series ] || echo `basename $i` >> series + (which quilt > /dev/null 2>&1) || (patch -p1 < $i) || die "Fehler beim Anwenden von $i" + done + (which quilt > /dev/null 2>&1) && quilt push -a || die "Fehler beim Anwenden der Patches" +} + +src_configure() { + cd ${MY_S} + + ./configure \ + CC=`tc-cc` \ + --build=`tc-build` \ + --target=`tc-host` \ + --host=`tc-host` \ + --prefix="${R}" \ + || die "configure failed" +} + +src_compile() { + cd ${MY_S} + + lmake || die "make failed" + cd .. +} + +src_install() { + cd ${MY_S} + + lmake install prefix="${D}${R}" || die "make install failed" + rm -rf ${D}${R}/share +} -- 1.6.3.3 From max at tyndur.org Thu Oct 1 22:07:04 2009 From: max at tyndur.org (max at tyndur.org) Date: Thu, 1 Oct 2009 22:07:04 +0200 Subject: [tyndur-devel] =?utf-8?b?W1BBVENIXSBsaWJtOiBwb3coKSB1bmQgcmludCgp?= =?utf-8?q?_f=C3=BCr_libvorbis?= Message-ID: <1254427624-13788-1-git-send-email-max@tyndur.org> From: Max Reitz + pow() und rint() so dürftig als nötig hinzugefügt, damit die libvorbis funktioniert Signed-off-by: Max Reitz --- src/modules/lib/stdlibc/math/pow.c | 7 +++++++ src/modules/lib/stdlibc/math/rint.c | 6 ++++++ 2 files changed, 13 insertions(+), 0 deletions(-) create mode 100644 src/modules/lib/stdlibc/math/pow.c create mode 100644 src/modules/lib/stdlibc/math/rint.c diff --git a/src/modules/lib/stdlibc/math/pow.c b/src/modules/lib/stdlibc/math/pow.c new file mode 100644 index 0000000..8059625 --- /dev/null +++ b/src/modules/lib/stdlibc/math/pow.c @@ -0,0 +1,7 @@ +#include + +double pow(double x, double y) +{ + return exp(y * log(x)); +} + diff --git a/src/modules/lib/stdlibc/math/rint.c b/src/modules/lib/stdlibc/math/rint.c new file mode 100644 index 0000000..9d606d2 --- /dev/null +++ b/src/modules/lib/stdlibc/math/rint.c @@ -0,0 +1,6 @@ +double rint(double x) +{ + //FIXME Was ist mit sehr großen Zahlen? + return (double)(unsigned long long)(x + 0.5); +} + -- 1.6.3.3 From max at tyndur.org Thu Oct 1 22:14:27 2009 From: max at tyndur.org (max at tyndur.org) Date: Thu, 1 Oct 2009 22:14:27 +0200 Subject: [tyndur-devel] =?utf-8?b?W1BBVENIXSBsaWJtOiBwb3coKSB1bmQgcmludCgp?= =?utf-8?q?_f=C3=BCr_libvorbis?= Message-ID: <1254428067-14053-1-git-send-email-max@tyndur.org> From: Max Reitz + pow() und rint() so dürftig als nötig hinzugefügt, damit die libvorbis funktioniert Signed-off-by: Max Reitz --- src/modules/include/math.h | 3 +++ src/modules/lib/stdlibc/math/pow.c | 35 +++++++++++++++++++++++++++++++++++ src/modules/lib/stdlibc/math/rint.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 72 insertions(+), 0 deletions(-) create mode 100644 src/modules/lib/stdlibc/math/pow.c create mode 100644 src/modules/lib/stdlibc/math/rint.c diff --git a/src/modules/include/math.h b/src/modules/include/math.h index 1cbb54f..486e21e 100644 --- a/src/modules/include/math.h +++ b/src/modules/include/math.h @@ -110,5 +110,8 @@ double nearbyint(double x); float nearbyintf(float x); long double nearbyintl(long double x); +double rint(double x); +double pow(double x, double y); + #endif diff --git a/src/modules/lib/stdlibc/math/pow.c b/src/modules/lib/stdlibc/math/pow.c new file mode 100644 index 0000000..b1f791a --- /dev/null +++ b/src/modules/lib/stdlibc/math/pow.c @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Max Reitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include + +double pow(double x, double y) +{ + return exp(y * log(x)); +} + diff --git a/src/modules/lib/stdlibc/math/rint.c b/src/modules/lib/stdlibc/math/rint.c new file mode 100644 index 0000000..0b81d87 --- /dev/null +++ b/src/modules/lib/stdlibc/math/rint.c @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Max Reitz. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +double rint(double x) +{ + //FIXME Was ist mit sehr großen Zahlen? + return (double)(unsigned long long)(x + 0.5); +} + -- 1.6.3.3 From hartmut at tyndur.org Fri Oct 2 03:53:59 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 2 Oct 2009 03:53:59 +0200 Subject: [tyndur-devel] [PATCH] kedit: NULL-Pointer abgefangen Message-ID: <1254448439-31079-1-git-send-email-hartmut@tyndur.org> * kedit: kedit_tui.pas: Wenn keine zu highlightende Datei geladen wird, wird der entstehende NULL-Pointer abgefangen * kedit: kedit_main.pas: Tabs zu Leerzeichen (ja kwolf, mecker ruhig *g*) Signed-off-by: Alexander Hartmut Kluth --- src/modules/pas/kedit/kedit_main.pas | 29 +++++++++++++++++++++++++---- src/modules/pas/kedit/kedit_tui.pas | 21 ++++++++++++++++++--- 2 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/modules/pas/kedit/kedit_main.pas b/src/modules/pas/kedit/kedit_main.pas index 18dbef7..0195ca3 100644 --- a/src/modules/pas/kedit/kedit_main.pas +++ b/src/modules/pas/kedit/kedit_main.pas @@ -12,6 +12,7 @@ type // Beschreibt einen offenen Puffer kedit_state = record filename: String; + extension: String; cursX: longint; cursY: longint; @@ -141,6 +142,8 @@ var lfile: textfile; i: integer; attr: word; s: String; + ext: String; + reversed: String; begin if loadname = '' then begin Textbackground(1); @@ -149,10 +152,6 @@ begin Textbackground(0); end; - if loadname = '' then begin - exit; - end; - if not FileExists(loadname) then begin if create then begin state^.filename := loadname; @@ -167,6 +166,28 @@ begin end; with state^ do begin + loadname := Trim(loadname); + + { + Dieses wundervolle Code-Konstrukt ist das Ergebnis + stundenlanger Codearbeit von Patrick Pokatilo a.k.a + the incredible SHyx0rmz und von Alexander H. Kluth a.k.a. + 'Pagefault-it!'-DerHartmut. + } + if RightStr(loadname, 4) = '.pas' then begin + extension := 'pas'; + end else if RightStr(loadname, 4) = '.asm' then begin + extension := 'asm'; + end else if RightStr(loadname, 2) = '.c' then begin + extension := 'c'; + end else if RightStr(loadname, 2) = '.S' then begin + extension := 's'; + end else if RightStr(loadname, 2) = '.s' then begin + extension := 's'; + end; + + SetSyntaxHighlighting(state); + Assign(lfile,loadname); GetFAttr(lfile, attr); if attr and dos.ReadOnly = dos.ReadOnly then readonly := true; diff --git a/src/modules/pas/kedit/kedit_tui.pas b/src/modules/pas/kedit/kedit_tui.pas index 13c7781..f9bd5b7 100644 --- a/src/modules/pas/kedit/kedit_tui.pas +++ b/src/modules/pas/kedit/kedit_tui.pas @@ -61,10 +61,12 @@ function YesNoCancel(question: string; cancel: boolean): integer; procedure RedrawLine(state: pkedit_state; y: longint); procedure DrawTitleBar(state: pkedit_state); procedure DrawEditor(state: pkedit_state); +procedure SetSyntaxHighlighting(state: pkedit_state); implementation -uses crt, syntax; +uses crt, strutils, sysutils, syntax, syntax_c, syntax_pas, syntax_intel, +syntax_atandt; var highlighter: TSyntax; @@ -276,7 +278,7 @@ begin GotoXY(1,2); firstVisible := 1 + state^.scrolly; lastVisible := TextLines + state^.scrolly; - if not highlight then begin + if (not highlight) or (highlighter = nil) then begin for i := firstVisible to lastVisible do begin s := Copy(state^.text^[i], 1 + state^.scrollx, 80); Write(Utf8Encode(s)); @@ -357,6 +359,19 @@ begin flush(output); end; +procedure SetSyntaxHighlighting(state: pkedit_state); begin - highlighter := TSyntax_C.create; + if state^.extension = 'c' then begin + highlighter := TSyntax_C.create; + end else if state^.extension = 'pas' then begin + highlighter := TSyntax_Pas.create; + end else if state^.extension = 'asm' then begin + highlighter := TSyntax_INTEL.create; + end else if state^.extension = 's' then begin + highlighter := TSyntax_ATANDT.create; + end; +end; + +begin + highlighter := nil; end. -- 1.6.0.4 From max at tyndur.org Fri Oct 2 19:20:56 2009 From: max at tyndur.org (max at tyndur.org) Date: Fri, 2 Oct 2009 19:20:56 +0200 Subject: [tyndur-devel] [PATCH] Player: Ein einfaches Musikabspielprogramm Message-ID: <1254504056-2122-1-git-send-email-max@tyndur.org> From: Max Reitz + Ein Musikabspielprogramm für .wav und .ogg (bisher). Für Ogg Vorbis werden allerdings noch libogg und libvorbis (bzw. vorbisfile) benötigt (siehe lbuilds), also folgende Libs nach src/modules/c/player kopieren: libogg.a, libvorbis.a, libvorbisfile.a, evtl. libvorbisenc.a Außerdem die entsprechenden Header (Verzeichnisse "ogg" und "vorbis") nach src/modules/include kopieren. Signed-off-by: Max Reitz --- src/modules/c/player/.nobuild | 1 + src/modules/c/player/Makefile.all | 9 + src/modules/c/player/main.c | 228 ++++++++++++++++++++++++++ src/modules/c/player/ogg-vorbis.c | 124 ++++++++++++++ src/modules/c/player/ogg-vorbis.h | 28 ++++ src/modules/c/player/player.h | 39 +++++ src/modules/c/player/riff-wave.c | 322 +++++++++++++++++++++++++++++++++++++ src/modules/c/player/riff-wave.h | 28 ++++ 8 files changed, 779 insertions(+), 0 deletions(-) create mode 100644 src/modules/c/player/.nobuild create mode 100644 src/modules/c/player/Makefile.all create mode 100644 src/modules/c/player/main.c create mode 100644 src/modules/c/player/ogg-vorbis.c create mode 100644 src/modules/c/player/ogg-vorbis.h create mode 100644 src/modules/c/player/player.h create mode 100644 src/modules/c/player/riff-wave.c create mode 100644 src/modules/c/player/riff-wave.h diff --git a/src/modules/c/player/.nobuild b/src/modules/c/player/.nobuild new file mode 100644 index 0000000..fbef933 --- /dev/null +++ b/src/modules/c/player/.nobuild @@ -0,0 +1 @@ +$(eval $(NOBUILD)) \ No newline at end of file diff --git a/src/modules/c/player/Makefile.all b/src/modules/c/player/Makefile.all new file mode 100644 index 0000000..fdd306d --- /dev/null +++ b/src/modules/c/player/Makefile.all @@ -0,0 +1,9 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +echo "LD $1/apps/player" + +$LOST_TOOLS_LD -oplayer -Ttext=0x40000000 *.o --start-group $2 *.a --end-group + + +mv player $1/apps/ diff --git a/src/modules/c/player/main.c b/src/modules/c/player/main.c new file mode 100644 index 0000000..5dfb295 --- /dev/null +++ b/src/modules/c/player/main.c @@ -0,0 +1,228 @@ +/****************************************************************************** + * Copyright (c) 2009 Max Reitz * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the "Software"), * + * to deal in the Software without restriction, including without limitation * + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * + * and/or sell copies of the Software, and to permit persons to whom the * + * Software is furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included in * + * all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * + * DEALINGS IN THE SOFTWARE. * + *****************************************************************************/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "player.h" + +#include "ogg-vorbis.h" +#include "riff-wave.h" + + +#define BUF_SIZE 1048576 + + +struct format { + struct format* next_format; + + void* (*is_this_format)(FILE* fp, void** format_inf); + const char* name; +}; + + +static struct format* formats = NULL; + +int add_format_support(void* (*is_this_format)(FILE* fp, void** format_inf), + const char* name) +{ + struct format* new_format; + struct format* format; + + if (is_this_format == NULL) { + return 0; + } + + new_format = calloc(sizeof(*new_format), 1); + new_format->is_this_format = is_this_format; + new_format->name = name; + new_format->next_format = NULL; + + if (formats == NULL) { + formats = new_format; + return 1; + } + + format = formats; + while (format->next_format != NULL) { + format = format->next_format; + } + format->next_format = new_format; + + return 1; +} + +struct format* get_file_format(FILE* fp, void** format_inf, + size_t (**transform_data)(FILE* fp, void* format_inf, size_t out_frames, + void* buffer)) +{ + struct format* format; + size_t (*rval)(FILE*, void*, size_t, void*); + + format = formats; + while (format) { + rval = format->is_this_format(fp, format_inf); + if (rval != NULL) { + *transform_data = rval; + return format; + } + + format = format->next_format; + } + + return NULL; +} + +int main(void) +{ + FILE* ifp = NULL; + FILE* ofp = NULL; + FILE* tfp; + void* buf; + void* fmt; + char* line; + char* command; + char* par; + char ofname[64] = "ac97:/crd0"; + struct format* file_fmt; + struct general_file_format* gen_fmt; + int i, now, pwas; + size_t ifsize = 0; + struct stat stt; + size_t (*get_music)(FILE*, void*, size_t, void*); + + add_wave_support(); + add_vorbis_support(); + + printf("Ausgabedatei: \"%s\"\n", ofname); + ofp = fopen(ofname, "r+"); + if (ofp == NULL) { + fprintf(stderr, "Ausgabedatei konnte nicht geöffnet werden.\n"); + } + + putchar('\n'); + for (;;) + { + line = readline("> "); + if (line == NULL) { + continue; + } + + command = strtok(line, " "); + if (command == NULL) { + command = line; + } + while (isspace(*command) && *command) { + command++; + } + for (i = 0; command[i]; i++) { + command[i] = tolower(command[i]); + } + + par = &command[++i]; + while (isspace(*par) && *par) { + par++; + } + + if (!*command) { + continue; + } else if (!strcmp(command, "open")) { + if ((tfp = fopen(par, "r")) == NULL) { + fprintf(stderr, "Die Datei konnte nicht geöffnet werden.\n"); + continue; + } + if (ifp != NULL) { + fclose(ifp); + } + ifp = tfp; + fstat(fileno(ifp), &stt); + ifsize = stt.st_size; + } else if (!strcmp(command, "quit") || !strcmp(command, "exit")) { + break; + } else if (!strcmp(command, "play")) { + if ((ifp == NULL) || (ofp == NULL)) { + fprintf(stderr, "Es werden sowohl Datei als auch Ausgabegerät " + "benötigt.\n"); + continue; + } + fseek(ifp, 0, SEEK_SET); + clearerr(ifp); + + file_fmt = get_file_format(ifp, &fmt, &get_music); + if (file_fmt == NULL) { + fprintf(stderr, "Unbekanntes Dateiformat.\n"); + continue; + } + printf("Dateiformat \"%s\".\n", file_fmt->name); + buf = calloc(1, BUF_SIZE); + gen_fmt = fmt; + printf("0:00 von %i:%02i\r", (int)(gen_fmt->length / 60), + gen_fmt->length % 60); + do { + pwas = gen_fmt->position; + fflush(stdout); + now = get_music(ifp, fmt, BUF_SIZE >> 2, buf); + fwrite(buf, 4, now, ofp); + printf("%i:%02i von %i:%02i\r", (int)(pwas / 60), pwas % 60, + (int)(gen_fmt->length / 60), gen_fmt->length % 60); + } while (now >= (BUF_SIZE >> 2)); + printf("\n"); + free(buf); + free(fmt); + } else if (!strcmp(command, "help")) { + printf("Musikplayer (ohne Namen) für tyndur\n\n"); + printf("Verfügbare Befehle:\n"); + printf(" - help: Zeigt diese Liste an\n"); + printf(" - version: Zeigt Versionsinformationen an\n"); + printf(" - open : Öffnet die Datei\n"); + printf(" - play: Spielt eine geöffnete Datei ab\n"); + printf(" - quit/exit: Beendet das Programm\n"); + } else if (!strcmp(command, "version")) { + printf("Musikplayer (ohne Namen) für tyndur\n\n"); + printf("Von Max Reitz\n\n"); + printf("Unterstützte Formate:\n"); + file_fmt = formats; + while (file_fmt != NULL) { + printf(" - \"%s\"\n", file_fmt->name); + file_fmt = file_fmt->next_format; + } + } else { + fprintf(stderr, "Unbekannter Befehl.\n"); + } + } + + if (ofp != NULL) { + fclose(ofp); + } + if (ifp != NULL) { + fclose(ifp); + } + + return EXIT_SUCCESS; +} diff --git a/src/modules/c/player/ogg-vorbis.c b/src/modules/c/player/ogg-vorbis.c new file mode 100644 index 0000000..7513167 --- /dev/null +++ b/src/modules/c/player/ogg-vorbis.c @@ -0,0 +1,124 @@ +/****************************************************************************** + * Copyright (c) 2009 Max Reitz * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the "Software"), * + * to deal in the Software without restriction, including without limitation * + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * + * and/or sell copies of the Software, and to permit persons to whom the * + * Software is furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included in * + * all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * + * DEALINGS IN THE SOFTWARE. * + *****************************************************************************/ + +#include +#include +#include + +#include "player.h" + +struct vorbis_format { + struct general_file_format gen; + OggVorbis_File vorbis_file; + int bitstream; + int channels; +}; + +static void* is_vorbis(FILE* fp, void** format_inf); +static size_t vorbis2raw(FILE* fp, void* format_inf, size_t out_frames, + void* out_buf); + +void add_vorbis_support(void) +{ + add_format_support(&is_vorbis, "Ogg Vorbis"); +} + +static void* is_vorbis(FILE* fp, void** format_inf) +{ + long pos = ftell(fp); + OggVorbis_File vorbis_file; + struct vorbis_format* fmt; + + if (ov_open(fp, &vorbis_file, NULL, 0) < 0) { + fseek(fp, pos, SEEK_SET); + return NULL; + } + + *format_inf = calloc(sizeof(*fmt), 1); + fmt = *format_inf; + memcpy(&fmt->vorbis_file, &vorbis_file, sizeof(vorbis_file)); + fmt->bitstream = 0; + fmt->channels = ov_info(&fmt->vorbis_file, -1)->channels; + fmt->gen.position = 0; + fmt->gen.length = ov_time_total(&fmt->vorbis_file, -1); + + return &vorbis2raw; +} + +static size_t vorbis2raw(FILE* fp, void* format_inf, size_t out_frames, + void* out_buf) +{ + struct vorbis_format* fmt = format_inf; + int sum = 0, now = 1024; + void* tbuf; + void* out; +#ifndef USE_INLINE_ASM + uint16_t *ibuf; + uint16_t *obuf; + int swas; +#endif + + //TODO Resamplen + + if (fmt->channels == 1) { + tbuf = calloc(2, out_frames); + out = tbuf; + + while (out_frames && now) { + now = ov_read(&fmt->vorbis_file, out, out_frames * 2, 0, 2, 1, + &fmt->bitstream) >> 1; + sum += now; + out += now * 2; + out_frames -= now; + } + +#ifdef USE_INLINE_ASM + __asm__ __volatile__ (".blow_up_to_two:" + "lodsw;" + "stosw;" + "stosw;" + "loop .blow_up_to_two"::"c"(sum),"S"(tbuf),"D"(out_buf)); +#else + ibuf = tbuf; + obuf = out_buf; + swas = sum; + while (swas--) { + *(obuf++) = *ibuf; + *(obuf++) = *(ibuf++); + } +#endif + + free(tbuf); + } else { + while (out_frames && now) { + now = ov_read(&fmt->vorbis_file, out_buf, out_frames * 4, 0, 2, 1, + &fmt->bitstream) >> 2; + sum += now; + out_buf += now * 4; + out_frames -= now; + } + } + + fmt->gen.position = (volatile int)ov_time_tell(&fmt->vorbis_file); + + return sum; +} diff --git a/src/modules/c/player/ogg-vorbis.h b/src/modules/c/player/ogg-vorbis.h new file mode 100644 index 0000000..3b509fe --- /dev/null +++ b/src/modules/c/player/ogg-vorbis.h @@ -0,0 +1,28 @@ +/****************************************************************************** + * Copyright (c) 2009 Max Reitz * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the "Software"), * + * to deal in the Software without restriction, including without limitation * + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * + * and/or sell copies of the Software, and to permit persons to whom the * + * Software is furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included in * + * all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * + * DEALINGS IN THE SOFTWARE. * + *****************************************************************************/ + +#ifndef OGG_VORBIS_H +#define OGG_VORBIS_H + +void add_vorbis_support(void); + +#endif diff --git a/src/modules/c/player/player.h b/src/modules/c/player/player.h new file mode 100644 index 0000000..74a0d87 --- /dev/null +++ b/src/modules/c/player/player.h @@ -0,0 +1,39 @@ +/****************************************************************************** + * Copyright (c) 2009 Max Reitz * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the "Software"), * + * to deal in the Software without restriction, including without limitation * + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * + * and/or sell copies of the Software, and to permit persons to whom the * + * Software is furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included in * + * all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * + * DEALINGS IN THE SOFTWARE. * + *****************************************************************************/ + +#ifndef PLAYER_H +#define PLAYER_H + +//Das definieren, um x86-Inline-Assembler für ein paar Sachen zu benutzen +#define USE_INLINE_ASM + + +struct general_file_format { + int length; + volatile int position; +}; + + +int add_format_support(void* (*is_this_format)(FILE* fp, void** format_inf), + const char* name); + +#endif diff --git a/src/modules/c/player/riff-wave.c b/src/modules/c/player/riff-wave.c new file mode 100644 index 0000000..a3a206a --- /dev/null +++ b/src/modules/c/player/riff-wave.c @@ -0,0 +1,322 @@ +/****************************************************************************** + * Copyright (c) 2009 Max Reitz * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the "Software"), * + * to deal in the Software without restriction, including without limitation * + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * + * and/or sell copies of the Software, and to permit persons to whom the * + * Software is furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included in * + * all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * + * DEALINGS IN THE SOFTWARE. * + *****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "player.h" + + +struct wave_header { + char fmt_chunk[4]; + uint32_t fmt_chunk_len; + uint16_t tag; + uint16_t channels; + uint32_t sample_rate; + uint32_t bytes_per_second; + uint16_t block_align; + uint16_t bits_per_sample; +} __attribute__ ((packed)); + +struct wave_format { + struct general_file_format gen; + + int channels; + int sample_rate; + int bits_per_sample; + size_t size; + int pos; + int bytes_per_second; +}; + + +static void* is_wave(FILE* fp, void** format_inf); +static size_t wave2raw(FILE* fp, void* format_inf, size_t out_frames, void* out_buf); + + +void add_wave_support(void) +{ + add_format_support(&is_wave, "RIFF Wave"); +} + +static void* is_wave(FILE* fp, void** format_inf) +{ + char chunk_name[4]; + struct wave_header wav_fmt; + int i; + long pos; + size_t ifsize; + struct wave_format* fmt; + + pos = ftell(fp); + + fread(chunk_name, 1, 4, fp); + if (!strncmp(chunk_name, "RIFF", 4)) { + fseek(fp, 4, SEEK_CUR); + fread(chunk_name, 1, 4, fp); + if (!strncmp(chunk_name, "WAVE", 4)) { + fread(&wav_fmt, 1, sizeof(wav_fmt), fp); + for (i = 0; i < 4; i++) { + wav_fmt.fmt_chunk[i] = toupper(wav_fmt.fmt_chunk[i]); + } + if (strncmp(wav_fmt.fmt_chunk, "FMT ", 4) || + (wav_fmt.fmt_chunk_len != 16)) + { + fseek(fp, pos, SEEK_SET); + return NULL; + } + + if ((wav_fmt.tag != 1) || ((wav_fmt.channels != 2) && + (wav_fmt.channels != 1)) || (wav_fmt.sample_rate != 44100) || + ((wav_fmt.bits_per_sample != 16) && + (wav_fmt.bits_per_sample != 8) && + (wav_fmt.bits_per_sample != 24) && + (wav_fmt.bits_per_sample != 32))) + { + fseek(fp, pos, SEEK_SET); + return NULL; + } + + do { + fread(chunk_name, 1, 4, fp); + fread(&ifsize, 1, 4, fp); + if (strncmp(chunk_name, "data", 4)) { + fseek(fp, ifsize, SEEK_CUR); + } + } while (strncmp(chunk_name, "data", 4) && !feof(fp)); + + if (feof(fp)) { + fseek(fp, pos, SEEK_SET); + return NULL; + } + } else { + fseek(fp, pos, SEEK_SET); + return NULL; + } + } else { + fseek(fp, pos, SEEK_SET); + return NULL; + } + + *format_inf = calloc(sizeof(*fmt), 1); + fmt = *format_inf; + fmt->channels = wav_fmt.channels; + fmt->sample_rate = wav_fmt.sample_rate; + fmt->bits_per_sample = wav_fmt.bits_per_sample; + fmt->size = ifsize; + fmt->pos = 0; + fmt->bytes_per_second = wav_fmt.bytes_per_second; + fmt->gen.length = ifsize / wav_fmt.bytes_per_second; + fmt->gen.position = 0; + + return &wave2raw; +} + +static size_t wave2raw(FILE* fp, void* format_inf, size_t out_frames, void* out_buf) +{ + struct wave_format* fmt = format_inf; + size_t now; + void* tbuf; +#ifndef USE_INLINE_ASM + size_t count; + uint8_t* i8buf; + uint16_t* ibuf; + uint32_t* i32buf; + uint16_t* obuf; +#endif + + //TODO Resamplen + + now = fmt->size / (fmt->channels * (fmt->bits_per_sample >> 3)); + if (now > out_frames) { + now = out_frames; + } + + if ((fmt->channels == 2) && (fmt->bits_per_sample == 16)) { + fread(out_buf, 4, now, fp); + fmt->size -= now * 4; + fmt->pos += now * 4; + } else if ((fmt->channels == 1) && (fmt->bits_per_sample == 16)) { + tbuf = calloc(now, 2); + fread(tbuf, 2, now, fp); + fmt->size -= now * 2; + fmt->pos += now * 2; + +#ifdef USE_INLINE_ASM + __asm__ __volatile__ (".blow_up_to_two:" + "lodsw;" + "stosw;" + "stosw;" + "loop .blow_up_to_two"::"c"(now),"S"(tbuf),"D"(out_buf)); +#else + count = now; + ibuf = tbuf; + obuf = out_buf; + while (count--) { + *(obuf++) = *ibuf; + *(obuf++) = *(ibuf++); + } +#endif + + free(tbuf); + } else if (fmt->channels == 2) { + tbuf = calloc(now, fmt->bits_per_sample >> 2); + fread(tbuf, fmt->bits_per_sample >> 2, now, fp); + fmt->size -= now * (fmt->bits_per_sample >> 2); + fmt->pos += now * (fmt->bits_per_sample >> 2); + switch (fmt->bits_per_sample) + { + case 8: +#ifdef USE_INLINE_ASM + __asm__ __volatile__ (".from_2_8:" + "xor %%eax,%%eax;" + "lodsb;" + "shl $7,%%eax;" //Bitte *nicht* fragen, warum nicht $8 + "stosw;" + "loop .from_2_8"::"c"(now * 2),"S"(tbuf),"D"(out_buf)); +#else + count = now * 2; + i8buf = tbuf; + obuf = out_buf; + while (count--) { + *(obuf++) = *(i8buf++) << 7; + } +#endif + break; + case 24: +#ifdef USE_INLINE_ASM + __asm__ __volatile__ (".from_2_24:" + "lodsb;" + "lodsw;" + "stosw;" + "loop .from_2_24" + ::"c"(now * 2),"S"(tbuf),"D"(out_buf)); +#else + count = now * 2; + i8buf = tbuf; + obuf = out_buf; + i8buf -= 2; + while (count--) { + i8buf += 3; + *(obuf++) = i8buf[0] | (i8buf[1] << 8); + } +#endif + break; + case 32: + //Gibts eigentlich gar nicht. Aber warum nicht? Dann ist das + //eben der einzige Player mit RIFF-WAVE-PCM-32-Bit-Unter- + //stützung. Wow. +#ifdef USE_INLINE_ASM + __asm__ __volatile__ (".from_2_32:" + "lodsl;" + "shr $16,%%eax;" + "stosw;" + "loop .from_2_32" + ::"c"(now * 2),"S"(tbuf),"D"(out_buf)); +#else + count = now * 2; + i32buf = tbuf; + obuf = out_buf; + while (count--) { + *(obuf++) = *(i32buf++) >> 16; + } +#endif + break; + } + free(tbuf); + } + else if (fmt->channels == 1) + { + tbuf = calloc(now, fmt->bits_per_sample >> 3); + fread(tbuf, fmt->bits_per_sample >> 3, now, fp); + fmt->size -= now * (fmt->bits_per_sample >> 3); + fmt->pos += now * (fmt->bits_per_sample >> 3); + switch (fmt->bits_per_sample) + { + case 8: +#ifdef USE_INLINE_ASM + __asm__ __volatile__ (".from_1_8:" + "xor %%eax,%%eax;" + "lodsb;" + "shl $7,%%eax;" //Bitte *nicht* fragen, warum nicht $8 + "stosw;" + "stosw;" + "loop .from_1_8"::"c"(now),"S"(tbuf),"D"(out_buf)); +#else + count = now; + i8buf = tbuf; + obuf = out_buf; + while (count--) { + *(obuf++) = *(i8buf) << 7; + *(obuf++) = *(i8buf++) << 7; + } +#endif + break; + case 24: +#ifdef USE_INLINE_ASM + __asm__ __volatile__ (".from_1_24:" + "lodsb;" + "lodsw;" + "stosw;" + "stosw;" + "loop .from_1_24"::"c"(now),"S"(tbuf),"D"(out_buf)); +#else + count = now; + i8buf = tbuf; + obuf = out_buf; + i8buf -= 2; + while (count--) { + i8buf += 3; + *(obuf++) = i8buf[0] | (i8buf[1] << 8); + *(obuf++) = i8buf[0] | (i8buf[1] << 8); + } +#endif + break; + case 32: +#ifdef USE_INLINE_ASM + __asm__ __volatile__ (".from_1_32:" + "lodsl;" + "shr $16,%%eax;" + "stosw;" + "stosw;" + "loop .from_1_32"::"c"(now),"S"(tbuf),"D"(out_buf)); +#else + count = now; + i32buf = tbuf; + obuf = out_buf; + while (count--) { + *(obuf++) = *i32buf >> 16; + *(obuf++) = *(i32buf++) >> 16; + } +#endif + break; + } + free(tbuf); + } + + fmt->gen.position = fmt->pos / fmt->bytes_per_second; + + return now; +} diff --git a/src/modules/c/player/riff-wave.h b/src/modules/c/player/riff-wave.h new file mode 100644 index 0000000..9eff4b3 --- /dev/null +++ b/src/modules/c/player/riff-wave.h @@ -0,0 +1,28 @@ +/****************************************************************************** + * Copyright (c) 2009 Max Reitz * + * * + * Permission is hereby granted, free of charge, to any person obtaining a * + * copy of this software and associated documentation files (the "Software"), * + * to deal in the Software without restriction, including without limitation * + * the rights to use, copy, modify, merge, publish, distribute, sublicense, * + * and/or sell copies of the Software, and to permit persons to whom the * + * Software is furnished to do so, subject to the following conditions: * + * * + * The above copyright notice and this permission notice shall be included in * + * all copies or substantial portions of the Software. * + * * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING * + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER * + * DEALINGS IN THE SOFTWARE. * + *****************************************************************************/ + +#ifndef RIFF_WAVE_H +#define RIFF_WAVE_H + +void add_wave_support(void); + +#endif -- 1.6.3.3 From max at tyndur.org Fri Oct 2 21:40:20 2009 From: max at tyndur.org (max at tyndur.org) Date: Fri, 2 Oct 2009 21:40:20 +0200 Subject: [tyndur-devel] [PATCH] stdlib: RAND_MAX Message-ID: <1254512420-22920-1-git-send-email-max@tyndur.org> From: Max Reitz + RAND_MAX hinzugefügt, das braucht die libvorbis auch Signed-off-by: Max Reitz --- src/include/stdlib.h | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/src/include/stdlib.h b/src/include/stdlib.h index f5f446e..745d32d 100644 --- a/src/include/stdlib.h +++ b/src/include/stdlib.h @@ -35,6 +35,8 @@ #define EXIT_SUCCESS 0 #define EXIT_FAILURE 1 +#define RAND_MAX 0x7FFFFFFF + /** Maximale laenge eines Multibyte-Zeichens in Bytes */ #define MB_CUR_MAX 4 -- 1.6.3.3 From max at tyndur.org Fri Oct 2 22:02:22 2009 From: max at tyndur.org (max at tyndur.org) Date: Fri, 2 Oct 2009 22:02:22 +0200 Subject: [tyndur-devel] [PATCH] lbuilds: Player Message-ID: <1254513742-30070-1-git-send-email-max@tyndur.org> From: Max Reitz + Das einfache Musikabspielprogramm mit RIFF-Wave- und Ogg-Vorbis- Support (bisher) für lbuilds Signed-off-by: Max Reitz --- lbuilds/player/0.0.1/player-0.0.1.lbuild | 31 ++++++++++++++++++++++++++++++ 1 files changed, 31 insertions(+), 0 deletions(-) create mode 100644 lbuilds/player/0.0.1/player-0.0.1.lbuild diff --git a/lbuilds/player/0.0.1/player-0.0.1.lbuild b/lbuilds/player/0.0.1/player-0.0.1.lbuild new file mode 100644 index 0000000..753455a --- /dev/null +++ b/lbuilds/player/0.0.1/player-0.0.1.lbuild @@ -0,0 +1,31 @@ +include toolchain +include lutils + +DESCRIPTION="Ein Musikabspielprogramm" +HOMEPAGE="http://lowlevel.brainsware.org/wiki/index.php/LOST/Pakete/player" +SRC_URI="http://www.xanclic.bplaced.net/${P}.tar.bz2" + +LICENSE="MIT" + +BUILD_DEPEND="=libogg-1.1.4 =libvorbis-1.2.3" +RUN_DEPEND="" + +MY_S="${S}/${P}" + +src_unpack() { +lunpack ${P}.tar.bz2 +} + +src_compile() { + cd ${MY_S} + + lmake CC=i386-pc-tyndur-gcc || die "make failed" + cd .. +} + +src_install() { + cd ${MY_S} + + lmake install INSTALL_TO="${D}${R}" || die "make install failed" + rm -rf ${D}${R}/share +} -- 1.6.3.3 From hartmut at tyndur.org Fri Oct 9 03:13:11 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 9 Oct 2009 03:13:11 +0200 Subject: [tyndur-devel] [PATCH] Kernel: paging.c: Klammern in if-Bedingung korrigiert Message-ID: <1255050791-22286-1-git-send-email-hartmut@tyndur.org> !: paging.c: Ubuntu's gcc 4.4 hat bei der Klammerung gemeckert, Klammern nun richtig gesetzt Signed-off-by: Alexander Hartmut Kluth --- src/kernel/src/mm/paging.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/kernel/src/mm/paging.c b/src/kernel/src/mm/paging.c index 30ba46a..82d34c6 100644 --- a/src/kernel/src/mm/paging.c +++ b/src/kernel/src/mm/paging.c @@ -379,7 +379,7 @@ bool is_userspace(vaddr_t start, dword len) cur += PAGE_SIZE) { dword pte = get_pagetable_entry(current_task->cr3, cur); - if ((pte == 0) || (!pte & PTE_U)) { + if ((pte == 0) || ((!pte) & PTE_U)) { return FALSE; } } -- 1.6.3.3 From hartmut at tyndur.org Fri Oct 9 06:16:55 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 9 Oct 2009 06:16:55 +0200 Subject: [tyndur-devel] [PATCH 0/5] kedit: Syntax-Highlighting umstrukturiert und erweitert Message-ID: <1255061820-15945-1-git-send-email-hartmut@tyndur.org> In dieser (schon lange überfalligen...:$) Patchserie habe ich das Syntax-Highlighting von kedit umstrukturiert und erweitert. Leider Funktionieren verschachtelte Kommentare in Pascal nicht so ganz und die Keywords funktionieren bei den Assembler-Syntaxen auch nicht richtig. Aber sonst funktioniert alles :D Alexander Hartmut Kluth (5): kedit: syntax.pas aufgesplitted kedit: Syntaxhighlighting-Modus anhand der Dateientdung einstellen kedit: Pascal-Highlighting hinzugefügt kedit: Intel-Assembler-Highlighting hinzugefügt kedit: AT&T-Assembler-Highlighting hinzugefügt src/modules/pas/kedit/kedit.pas | 5 +- src/modules/pas/kedit/kedit_main.pas | 29 ++++- src/modules/pas/kedit/kedit_tui.pas | 103 +++++++++++++- src/modules/pas/kedit/syntax.pas | 195 ++------------------------ src/modules/pas/kedit/syntax_atandt.pas | 209 +++++++++++++++++++++++++++ src/modules/pas/kedit/syntax_c.pas | 197 +++++++++++++++++++++++++ src/modules/pas/kedit/syntax_intel.pas | 205 ++++++++++++++++++++++++++ src/modules/pas/kedit/syntax_pas.pas | 239 +++++++++++++++++++++++++++++++ 8 files changed, 987 insertions(+), 195 deletions(-) create mode 100644 src/modules/pas/kedit/syntax_atandt.pas create mode 100644 src/modules/pas/kedit/syntax_c.pas create mode 100644 src/modules/pas/kedit/syntax_intel.pas create mode 100644 src/modules/pas/kedit/syntax_pas.pas From hartmut at tyndur.org Fri Oct 9 06:16:56 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 9 Oct 2009 06:16:56 +0200 Subject: [tyndur-devel] [PATCH 1/5] kedit: syntax.pas aufgesplitted In-Reply-To: <1255061820-15945-1-git-send-email-hartmut@tyndur.org> References: <1255061820-15945-1-git-send-email-hartmut@tyndur.org> Message-ID: <1255061820-15945-2-git-send-email-hartmut@tyndur.org> * syntax.pas: C-Syntax extrahiert, nun nur noch TSyntax-Klasse + syntax_c.pas: C-Syntax hier implementiert Signed-off-by: Alexander Hartmut Kluth --- src/modules/pas/kedit/syntax.pas | 195 ++---------------------------------- src/modules/pas/kedit/syntax_c.pas | 197 ++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+), 186 deletions(-) create mode 100644 src/modules/pas/kedit/syntax_c.pas diff --git a/src/modules/pas/kedit/syntax.pas b/src/modules/pas/kedit/syntax.pas index b382265..0f9950e 100644 --- a/src/modules/pas/kedit/syntax.pas +++ b/src/modules/pas/kedit/syntax.pas @@ -29,30 +29,18 @@ type property GetState: integer read f_state; end; - TSyntax_C = class(TSyntax) - public - procedure StartLine(s: String; state: integer); override; - function Next: TSyntaxChange; override; - end; - function SyntaxColor(c: TSyntaxColor): byte; function SyntaxBgColor(c: TSyntaxColor): byte; +function Matches(s: String; pos: integer; pattern: String): boolean; +function MatchesNumber(s: string; pos: integer): integer; +function MatchesKeyword(s: string; pos: integer; p: Array of String): integer; +function MatchesLabel(s: string; pos: integer): integer; +function MatchesType(s: string; pos: integer): integer; +function MatchesTrailingSpace(s: string; pos: integer): boolean; implementation - -const - Keywords_C: Array [1..15] of String = ( - 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default', 'goto', - 'break', 'continue', 'return', 'sizeof', 'typedef', 'asm' - ); - Types_C: Array [1..17] of String = ( - 'void', 'char', 'short', 'int', 'long', 'signed', 'unsigned', 'float', 'double', - 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile', 'const' - ); - - function SyntaxColor(c: TSyntaxColor): byte; begin case c of @@ -70,6 +58,7 @@ begin exit(8); end; + function SyntaxBgColor(c: TSyntaxColor): byte; begin case c of @@ -79,11 +68,13 @@ begin exit(0); end; + function Matches(s: String; pos: integer; pattern: String): boolean; begin Matches := (Copy(s, pos, length(pattern)) = pattern); end; + function MatchesNumber(s: String; pos: integer): integer; var i: integer; @@ -261,172 +252,4 @@ begin color := c; end; -procedure TSyntax_C.StartLine(s: String; state: integer); -begin - line := s; - f_state := state; - pos := 1; - - case f_state of - 1: color := syn_comment; - 2: color := syn_comment; - 3: color := syn_number; - 4: color := syn_string; - 5: color := syn_string_special; - 6: color := syn_keyword; - 7: color := syn_type; - 8: color := syn_label; - else color := syn_other; - end; -end; - -function TSyntax_C.Next: TSyntaxChange; -var - c: char; - tmp: integer; -begin - Next.posY := 0; - Next.color := color; - - while pos <= length(line) do begin - c := line[pos]; - - case f_state of - - 0: { Normaler Text } - case c of - '/': - if Matches(line, pos, '//') then begin - f_state := 1; - exit(Highlight(syn_comment)); - end else if Matches(line, pos, '/*') then begin - f_state := 2; - exit(Highlight(syn_comment)); - end; - - '0' .. '9', '-', '+': - begin - tmp := MatchesNumber(line, pos); - if tmp <> 0 then begin - Next := Highlight(syn_number); - Inc(pos, tmp); - f_state := 3; - exit; - end; - end; - - '#': - begin - if Copy(line, 1, pos - 1) = Space(pos - 1) then begin - f_state := 1; - exit(Highlight(syn_compiler)); - end; - end; - - '"': - begin - Next := Highlight(syn_string); - Inc(pos); - f_state := 4; - exit; - end; - ' ': - begin - if MatchesTrailingSpace(line, pos) then begin - Next := Highlight(syn_trailing_space); - pos := length(line) + 1; - exit; - end; - end; - - else - begin - tmp := MatchesKeyword(line, pos, Keywords_C); - if tmp <> 0 then begin - Next := Highlight(syn_keyword); - Inc(pos, tmp); - f_state := 6; - exit; - end; - - tmp := MatchesKeyword(line, pos, Types_C); - if tmp <> 0 then begin - Next := Highlight(syn_type); - Inc(pos, tmp); - f_state := 7; - exit; - end; - - tmp := MatchesType(line, pos); - if tmp <> 0 then begin - Next := Highlight(syn_type); - Inc(pos, tmp); - f_state := 7; - exit; - end; - - tmp := MatchesLabel(line, pos); - if tmp <> 0 then begin - Next := Highlight(syn_label); - Inc(pos, tmp); - f_state := 8; - exit; - end; - end; - end; - - 1: { Kommentar bis Zeilenende } - begin - pos := length(line); - break; - end; - - 2: { C-Kommentar } - if Matches(line, pos, '*/') then begin - f_state := 0; - Inc(pos, 2); - exit(Highlight(syn_other)); - end; - - 3, 6, 7, 8: { Ende eines gefaerbten Worts } - begin - f_state := 0; - exit(Highlight(syn_other)); - end; - - 4: { String } - case c of - '\': - begin - f_state := 5; - Next := Highlight(syn_string_special); - Inc(pos); - exit; - end; - - '"': - begin - f_state := 0; - Inc(pos); - exit(Highlight(syn_other)); - end; - end; - - 5: { Escaptes Zeichen in einem String } - begin - f_state := 4; - Inc(pos); - exit(Highlight(syn_string)); - end; - - end; - - Inc(pos); - end; - - if f_state in [1, 3, 4, 5] then begin - f_state := 0; - end; -end; - end. diff --git a/src/modules/pas/kedit/syntax_c.pas b/src/modules/pas/kedit/syntax_c.pas new file mode 100644 index 0000000..f7662cc --- /dev/null +++ b/src/modules/pas/kedit/syntax_c.pas @@ -0,0 +1,197 @@ +unit syntax_c; +{$mode ObjFPC} + +interface + +uses syntax; + +type + TSyntax_C = class(TSyntax) + public + procedure StartLine(s: String; state: integer); override; + function Next: TSyntaxChange; override; + end; + + +implementation +const + Keywords_C: Array [1..15] of String = ( + 'if', 'else', 'for', 'while', 'do', 'switch', 'case', 'default', 'goto', + 'break', 'continue', 'return', 'sizeof', 'typedef', 'asm' + ); + + Types_C: Array [1..17] of String = ( + 'void', 'char', 'short', 'int', 'long', 'signed', 'unsigned', 'float', 'double', + 'static', 'inline', 'extern', 'enum', 'struct', 'union', 'volatile', 'const' + ); + +procedure TSyntax_C.StartLine(s: String; state: integer); +begin + line := s; + f_state := state; + pos := 1; + + case f_state of + 1: color := syn_comment; + 2: color := syn_comment; + 3: color := syn_number; + 4: color := syn_string; + 5: color := syn_string_special; + 6: color := syn_keyword; + 7: color := syn_type; + 8: color := syn_label; + else color := syn_other; + end; +end; + + +function TSyntax_C.Next: TSyntaxChange; +var + c: char; + tmp: integer; +begin + Next.posY := 0; + Next.color := color; + + while pos <= length(line) do begin + c := line[pos]; + + case f_state of + + 0: { Normaler Text } + case c of + '/': + if Matches(line, pos, '//') then begin + f_state := 1; + exit(Highlight(syn_comment)); + end else if Matches(line, pos, '/*') then begin + f_state := 2; + exit(Highlight(syn_comment)); + end; + + '0' .. '9', '-', '+': + begin + tmp := MatchesNumber(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_number); + Inc(pos, tmp); + f_state := 3; + exit; + end; + end; + + '#': + begin + if Copy(line, 1, pos - 1) = Space(pos - 1) then begin + f_state := 1; + exit(Highlight(syn_compiler)); + end; + end; + + '"': + begin + Next := Highlight(syn_string); + Inc(pos); + f_state := 4; + exit; + end; + ' ': + begin + if MatchesTrailingSpace(line, pos) then begin + Next := Highlight(syn_trailing_space); + pos := length(line) + 1; + exit; + end; + end; + + else + begin + tmp := MatchesKeyword(line, pos, Keywords_C); + if tmp <> 0 then begin + Next := Highlight(syn_keyword); + Inc(pos, tmp); + f_state := 6; + exit; + end; + + tmp := MatchesKeyword(line, pos, Types_C); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesType(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesLabel(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_label); + Inc(pos, tmp); + f_state := 8; + exit; + end; + end; + end; + + 1: { Kommentar bis Zeilenende } + begin + pos := length(line); + break; + end; + + 2: { C-Kommentar } + if Matches(line, pos, '*/') then begin + f_state := 0; + Inc(pos, 2); + exit(Highlight(syn_other)); + end; + + 3, 6, 7, 8: { Ende eines gefaerbten Worts } + begin + f_state := 0; + exit(Highlight(syn_other)); + end; + + 4: { String } + case c of + '\': + begin + f_state := 5; + Next := Highlight(syn_string_special); + Inc(pos); + exit; + end; + + '"': + begin + f_state := 0; + Inc(pos); + exit(Highlight(syn_other)); + end; + end; + + 5: { Escaptes Zeichen in einem String } + begin + f_state := 4; + Inc(pos); + exit(Highlight(syn_string)); + end; + + end; + + Inc(pos); + end; + + if f_state in [1, 3, 4, 5] then begin + f_state := 0; + end; +end; + +end. -- 1.6.3.3 From hartmut at tyndur.org Fri Oct 9 06:16:57 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 9 Oct 2009 06:16:57 +0200 Subject: [tyndur-devel] [PATCH 2/5] kedit: Syntaxhighlighting-Modus anhand der Dateientdung einstellen In-Reply-To: <1255061820-15945-2-git-send-email-hartmut@tyndur.org> References: <1255061820-15945-1-git-send-email-hartmut@tyndur.org> <1255061820-15945-2-git-send-email-hartmut@tyndur.org> Message-ID: <1255061820-15945-3-git-send-email-hartmut@tyndur.org> * kedit.pas: Feld 'extension' hinzugefügt für die Dateiendung * kedit_tui.pas: Funktion zum Setzen des Syntax-Modus implementiert * kedit_main.pas: Auseinanderfrickeln der Dateiendung und Syntax-Modus setzen Signed-off-by: Alexander Hartmut Kluth --- src/modules/pas/kedit/kedit.pas | 5 +- src/modules/pas/kedit/kedit_main.pas | 29 ++++++++- src/modules/pas/kedit/kedit_tui.pas | 103 +++++++++++++++++++++++++++++++++- 3 files changed, 128 insertions(+), 9 deletions(-) diff --git a/src/modules/pas/kedit/kedit.pas b/src/modules/pas/kedit/kedit.pas index dc956d5..5741842 100644 --- a/src/modules/pas/kedit/kedit.pas +++ b/src/modules/pas/kedit/kedit.pas @@ -12,7 +12,7 @@ var state: kedit_state; (*********************************************** - * Dummyfunktionen für LOST * + * Dummyfunktionen für tyndur * ***********************************************) procedure DisableFlushing(var f: Textfile); external name 'disable_flushing'; @@ -61,6 +61,7 @@ var begin with state do begin filename := '(unbenannt)'; + extension := ''; highlight := false; readonly := false; @@ -103,7 +104,7 @@ procedure Edit; case key of #27: { VT100-Escapesequenz } begin - key := ReadEscapeSequence(); + key := HandleEscapeSequence(); if (key >= SK_MIN) and (key <= SK_MAX) and (special_key_handler[key] <> nil) then begin special_key_handler[key](@state); end else begin diff --git a/src/modules/pas/kedit/kedit_main.pas b/src/modules/pas/kedit/kedit_main.pas index 18dbef7..0195ca3 100644 --- a/src/modules/pas/kedit/kedit_main.pas +++ b/src/modules/pas/kedit/kedit_main.pas @@ -12,6 +12,7 @@ type // Beschreibt einen offenen Puffer kedit_state = record filename: String; + extension: String; cursX: longint; cursY: longint; @@ -141,6 +142,8 @@ var lfile: textfile; i: integer; attr: word; s: String; + ext: String; + reversed: String; begin if loadname = '' then begin Textbackground(1); @@ -149,10 +152,6 @@ begin Textbackground(0); end; - if loadname = '' then begin - exit; - end; - if not FileExists(loadname) then begin if create then begin state^.filename := loadname; @@ -167,6 +166,28 @@ begin end; with state^ do begin + loadname := Trim(loadname); + + { + Dieses wundervolle Code-Konstrukt ist das Ergebnis + stundenlanger Codearbeit von Patrick Pokatilo a.k.a + the incredible SHyx0rmz und von Alexander H. Kluth a.k.a. + 'Pagefault-it!'-DerHartmut. + } + if RightStr(loadname, 4) = '.pas' then begin + extension := 'pas'; + end else if RightStr(loadname, 4) = '.asm' then begin + extension := 'asm'; + end else if RightStr(loadname, 2) = '.c' then begin + extension := 'c'; + end else if RightStr(loadname, 2) = '.S' then begin + extension := 's'; + end else if RightStr(loadname, 2) = '.s' then begin + extension := 's'; + end; + + SetSyntaxHighlighting(state); + Assign(lfile,loadname); GetFAttr(lfile, attr); if attr and dos.ReadOnly = dos.ReadOnly then readonly := true; diff --git a/src/modules/pas/kedit/kedit_tui.pas b/src/modules/pas/kedit/kedit_tui.pas index 028d9b6..f9bd5b7 100644 --- a/src/modules/pas/kedit/kedit_tui.pas +++ b/src/modules/pas/kedit/kedit_tui.pas @@ -16,6 +16,40 @@ const OPT_NO = 2; OPT_CANCEL = 3; + + SK_F1 = #59; + SK_F2 = #60; + SK_F3 = #61; + SK_F4 = #62; + SK_F5 = #63; + SK_F6 = #64; + SK_F7 = #65; + SK_F8 = #66; + SK_F9 = #67; + SK_F10 = #68; + SK_F11 = #133; + SK_F12 = #134; + + SK_INS = #82; + SK_DEL = #83; + SK_HOME = #71; + SK_END = #79; + SK_PGUP = #73; + SK_PGDN = #81; + + SK_UP = #72; + SK_DOWN = #80; + SK_LEFT = #75; + SK_RIGHT = #77; + + SK_CTRL_PGUP = #132; + SK_CTRL_PGDN = #118; + + SK_MIN = #59; + SK_MAX = #134; + +function HandleEscapeSequence: char; + procedure ShowCursor(visible: boolean); procedure FillRectangle(x1, y1, x2, y2: integer); function Space(n: integer): string; @@ -27,10 +61,12 @@ function YesNoCancel(question: string; cancel: boolean): integer; procedure RedrawLine(state: pkedit_state; y: longint); procedure DrawTitleBar(state: pkedit_state); procedure DrawEditor(state: pkedit_state); +procedure SetSyntaxHighlighting(state: pkedit_state); implementation -uses crt, syntax; +uses crt, strutils, sysutils, syntax, syntax_c, syntax_pas, syntax_intel, +syntax_atandt; var highlighter: TSyntax; @@ -40,6 +76,54 @@ begin if visible then CursorOn else CursorOff; end; +(* Eingabeverarbeitung ************************************************) + +function HandleEscapeSequence: char; +begin + HandleEscapeSequence := #0; + + case readkey of + 'O': + case readkey of + 'P': exit(SK_F1); + 'Q': exit(SK_F2); + 'R': exit(SK_F3); + 'S': exit(SK_F4); + end; + + '[': + case readkey of + 'A': exit(SK_UP); + 'B': exit(SK_DOWN); + 'C': exit(SK_RIGHT); + 'D': exit(SK_LEFT); + 'F': exit(SK_END); + 'H': exit(SK_HOME); + + '3': if readkey = '~' then exit(SK_DEL); + '5': if readkey = '~' then exit(SK_PGUP); + '6': if readkey = '~' then exit(SK_PGDN); + + '1': + case readkey of + '5': if readkey = '~' then exit(SK_F5); + '7': if readkey = '~' then exit(SK_F6); + '8': if readkey = '~' then exit(SK_F7); + '9': if readkey = '~' then exit(SK_F8); + end; + + '2': + case readkey of + '0': if readkey = '~' then exit(SK_F9); + '1': if readkey = '~' then exit(SK_F10); + '3': if readkey = '~' then exit(SK_F11); + '4': if readkey = '~' then exit(SK_F12); + '~': exit(SK_INS); + end; + end; + end; +end; + (* Rein grafisches Zeug ***********************************************) procedure FillRectangle(x1, y1, x2, y2: integer); @@ -194,7 +278,7 @@ begin GotoXY(1,2); firstVisible := 1 + state^.scrolly; lastVisible := TextLines + state^.scrolly; - if not highlight then begin + if (not highlight) or (highlighter = nil) then begin for i := firstVisible to lastVisible do begin s := Copy(state^.text^[i], 1 + state^.scrollx, 80); Write(Utf8Encode(s)); @@ -275,6 +359,19 @@ begin flush(output); end; +procedure SetSyntaxHighlighting(state: pkedit_state); +begin + if state^.extension = 'c' then begin + highlighter := TSyntax_C.create; + end else if state^.extension = 'pas' then begin + highlighter := TSyntax_Pas.create; + end else if state^.extension = 'asm' then begin + highlighter := TSyntax_INTEL.create; + end else if state^.extension = 's' then begin + highlighter := TSyntax_ATANDT.create; + end; +end; + begin - highlighter := TSyntax_C.create; + highlighter := nil; end. -- 1.6.3.3 From hartmut at tyndur.org Fri Oct 9 06:16:58 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 9 Oct 2009 06:16:58 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_3/5=5D_kedit=3A_Pascal-Highligh?= =?utf-8?q?ting_hinzugef=C3=BCgt?= In-Reply-To: <1255061820-15945-3-git-send-email-hartmut@tyndur.org> References: <1255061820-15945-1-git-send-email-hartmut@tyndur.org> <1255061820-15945-2-git-send-email-hartmut@tyndur.org> <1255061820-15945-3-git-send-email-hartmut@tyndur.org> Message-ID: <1255061820-15945-4-git-send-email-hartmut@tyndur.org> + syntax_pas.pas: Pascsal-Highlighting hinzugefügt Signed-off-by: Alexander Hartmut Kluth --- src/modules/pas/kedit/syntax_pas.pas | 239 ++++++++++++++++++++++++++++++++++ 1 files changed, 239 insertions(+), 0 deletions(-) create mode 100644 src/modules/pas/kedit/syntax_pas.pas diff --git a/src/modules/pas/kedit/syntax_pas.pas b/src/modules/pas/kedit/syntax_pas.pas new file mode 100644 index 0000000..ded9e45 --- /dev/null +++ b/src/modules/pas/kedit/syntax_pas.pas @@ -0,0 +1,239 @@ +unit syntax_pas; +{$mode ObjFPC} + +interface + +uses syntax; + +type + TSyntax_Pas = class(TSyntax) + public + procedure StartLine(s: String; state: integer); override; + function Next: TSyntaxChange; override; + end; + + +implementation +const + Keywords_Pas: Array [1..88] of String = ( + 'absolute', 'abstract', 'and', 'ansistring', 'array', 'assembler', 'asm', + 'automated', 'begin', 'case', 'cdecl', + 'class', 'compilerprog', 'const', 'constructor', + 'deconstructor', 'default', 'deprecated', 'div', 'do', 'downto', + 'dword', 'dynamic', 'else', 'end', 'export', 'external', 'far', + 'forward', 'finalization', 'for', + 'function', 'generic', 'goto', 'inline', 'if', 'implementation', 'in', + 'interface', 'label', 'longint', 'message', 'mod', 'near', 'nil', 'not', + 'object', 'overlay', 'overload', 'override', 'of', 'or', 'packed', + 'pchar', 'platform', 'pointer', 'private', 'procedure', + 'program', 'property', 'protected', 'public', 'published', 'raise', + 'record', 'reintroduce', 'resourcestring', + 'repeat', 'sealed', 'set', 'shl', 'shortint', 'shr', 'specialize', 'stdcall', + 'then', 'threadvar', 'to', + 'type', 'unit', 'until', 'uses', 'var', 'virtual', 'while', 'with', + 'word', 'xor' + ); + + Types_Pas: Array [1..8] of String = ( + 'integer', 'byte', 'real', 'char', 'string', 'boolean', 'string', + 'file' + ); + + +procedure TSyntax_Pas.StartLine(s: String; state: integer); +begin + line := s; + f_state := state; + pos := 1; + + case f_state of + 1: color := syn_comment; + 2: color := syn_comment; + 3: color := syn_number; + 4: color := syn_string; + 5: color := syn_string_special; + 6: color := syn_keyword; + 7: color := syn_type; + 8: color := syn_label; + else color := syn_other; + end; +end; + + +function TSyntax_Pas.Next: TSyntaxChange; +var + c: char; + tmp: integer; + curly_comment: boolean; + star_comment: boolean; +begin + Next.posY := 0; + Next.color := color; + + while pos <= length(line) do begin + c := line[pos]; + + case f_state of + 0: + case c of + { FIXME: Kommentar-Ebenen funktionieren nicht richtig } + '{': + if Matches(line, pos, '{$') then begin + f_state := 1; + exit(Highlight(syn_compiler)); + end else begin + if star_comment = true then begin + curly_comment := false; + end else begin + curly_comment := true; + f_state := 2; + exit(Highlight(syn_comment)); + end; + end; + + '(': + if Matches(line, pos, '(*') then begin + if curly_comment = true then begin + star_comment := false; + end else begin + star_comment := true; + f_state := 2; + exit(Highlight(syn_comment)); + end; + end; + + '/': + if (Matches(line, pos, '//')) then begin + f_state := 1; + exit(Highlight(syn_comment)); + end; + + '0' .. '9', '-', '+', '$', '%', '&': + begin + tmp := MatchesNumber(line, pos); + + if tmp <> 0 then begin + Next := Highlight(syn_number); + Inc(pos, tmp); + f_state := 3; + exit; + end; + end; + + '''': + begin + Next := Highlight(syn_string); + Inc(pos); + f_state := 4; + exit; + end; + + ' ': + begin + if MatchesTrailingSpace(line, pos) then begin + Next := Highlight(syn_trailing_space); + pos := length(line) + 1; + exit; + end; + end; + + else + begin + tmp := MatchesKeyword(line, pos, Keywords_Pas); + if tmp <> 0 then begin + Next := Highlight(syn_keyword); + Inc(pos, tmp); + f_state := 6; + exit; + end; + + tmp := MatchesKeyword(line, pos, Types_Pas); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesType(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesLabel(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_label); + Inc(pos, tmp); + f_state := 8; + exit; + end; + end; + end; + + 1: { Kommentar bis Zeilenende } + begin + pos := length(line); + break; + end; + + 2: { Pascal-Kommentar } + if Matches(line, pos, '}') then begin + if (star_comment = true) and (curly_comment = false) then + begin + exit; + end else begin + f_state := 0; + Inc(pos, 1); + exit(Highlight(syn_other)); + end; + end else if Matches(line, pos, '*)') then begin + if (curly_comment = true) and (star_comment = false) then + begin + exit; + end else begin + f_state := 0; + Inc(pos, 2); + exit(Highlight(syn_other)); + end; + end; + + 3, 6, 7, 8: { Ende eines gefaerbten Worts } + begin + f_state := 0; + exit(Highlight(syn_other)); + end; + + 4: { String } + case c of + { TODO: Escape-Sequenzen } + + '''': + begin + f_state := 0; + Inc(pos); + exit(Highlight(syn_other)); + end; + end; + + 5: { Escaptes Zeichen in einem String } + begin + f_state := 4; + Inc(pos); + exit(Highlight(syn_string)); + end; + + end; + + Inc(pos); + end; + + if f_state in [1, 3, 4, 5] then begin + f_state := 0; + end; +end; + +end. + -- 1.6.3.3 From hartmut at tyndur.org Fri Oct 9 06:16:59 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 9 Oct 2009 06:16:59 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_4/5=5D_kedit=3A_Intel-Assembler?= =?utf-8?q?-Highlighting_hinzugef=C3=BCgt?= In-Reply-To: <1255061820-15945-4-git-send-email-hartmut@tyndur.org> References: <1255061820-15945-1-git-send-email-hartmut@tyndur.org> <1255061820-15945-2-git-send-email-hartmut@tyndur.org> <1255061820-15945-3-git-send-email-hartmut@tyndur.org> <1255061820-15945-4-git-send-email-hartmut@tyndur.org> Message-ID: <1255061820-15945-5-git-send-email-hartmut@tyndur.org> Leider funktioniert das Highlighten der Keywords noch nicht so ganz + syntax_intel.pas: Intel-Assembler_Highlighting hinzugefügt Signed-off-by: Alexander Hartmut Kluth --- src/modules/pas/kedit/syntax_intel.pas | 205 ++++++++++++++++++++++++++++++++ 1 files changed, 205 insertions(+), 0 deletions(-) create mode 100644 src/modules/pas/kedit/syntax_intel.pas diff --git a/src/modules/pas/kedit/syntax_intel.pas b/src/modules/pas/kedit/syntax_intel.pas new file mode 100644 index 0000000..867c9d3 --- /dev/null +++ b/src/modules/pas/kedit/syntax_intel.pas @@ -0,0 +1,205 @@ +unit syntax_intel; + +{$mode ObjFpc} + +interface + +uses syntax; + +type + TSyntax_INTEL = class(TSyntax) + public + procedure StartLine(s: String; state: integer); override; + function Next: TSyntaxChange; override; + end; + + +implementation +const + Keywords_INTEL: Array [1..12] of String = ( + 'equ', 'macro', '%macro', 'db', 'dw', 'dd', 'dq', 'end', + 'far', 'near', 'short', 'proc' + ); + + Register_INTEL: Array [1..95] of String = ( + 'cr0', 'cr1', 'cr2', 'cr3', 'cr4', + 'ax', 'ah', 'al', 'bx', 'bh', 'bl', 'cx', 'ch', 'cl', + 'dx', 'dh', 'dl', 'si', 'ss', 'sp', 'bp', 'cs', 'ds', + 'es', 'fs', 'gs', 'eax', 'ebx', 'ecx', 'edx', 'edi', + 'esi', 'ebp', 'esp', 'eip', 'rax', 'rbx', 'rcx', + 'rdx', 'rdi', 'rsi', 'rbp', 'rsp', 'rip', 'r8', 'r9', + 'r10', 'r11', 'r12', 'r13', 'r14', 'r15', 'dil', 'sil', 'bpl', + 'spl', 'r8l', 'r9l', 'r10l', 'r11l', 'r12l', 'r13l', 'r14l', + 'r15l', 'r8w', 'r9w', 'r10w', 'r11w', 'r13w', 'r14w', 'r15w', + 'r8d', 'r9d', 'r10d', 'r11d', 'r12d', 'r13d', 'r14d', 'r15d', + 'xmm0', 'xmm1', 'xmm2', 'xmm3', 'xmm4', 'xmm5', 'xmm6', 'xmm7', + 'xmm8', 'xmm9', 'xmm10', 'xmm11', 'xmm12', 'xmm13', 'xmm14', + 'xmm15' + ); + +procedure TSyntax_INTEL.StartLine(s: String; state: integer); +begin + line := s; + f_state := state; + pos := 1; + + case f_state of + 1: color := syn_comment; + 2: color := syn_comment; + 3: color := syn_number; + 4: color := syn_string; + 5: color := syn_string_special; + 6: color := syn_keyword; + 7: color := syn_type; + 8: color := syn_label; + else color := syn_other; + end; +end; + + +function TSyntax_INTEL.Next: TSyntaxChange; +var + c: char; + tmp: integer; +begin + Next.posY := 0; + Next.color := color; + + while pos <= length(line) do begin + c := line[pos]; + + case f_state of + + 0: { Normaler Text } + case c of + ';': + begin + f_state := 1; + exit(Highlight(syn_comment)); + end; + + '0' .. '9', '-', '+': + begin + tmp := MatchesNumber(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_number); + Inc(pos, tmp); + f_state := 3; + exit; + end; + end; + + '%': + begin + if Copy(line, 1, pos - 1) = Space(pos - 1) then begin + f_state := 1; + exit(Highlight(syn_compiler)); + end; + end; + + '"': + begin + Next := Highlight(syn_string); + Inc(pos); + f_state := 4; + exit; + end; + + ' ': + begin + if MatchesTrailingSpace(line, pos) then begin + Next := Highlight(syn_trailing_space); + pos := length(line) + 1; + exit; + end; + end; + + else + begin + tmp := MatchesKeyword(line, pos, Keywords_INTEL); + if tmp <> 0 then begin + Next := Highlight(syn_keyword); + Inc(pos, tmp); + f_state := 6; + exit; + end; + + tmp := MatchesKeyword(line, pos, Register_INTEL); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesType(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesLabel(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_label); + Inc(pos, tmp); + f_state := 8; + exit; + end; + + { FIXME: Keywords werden nicht erkannt } + Next := Highlight(syn_label); + Inc(pos, tmp); + f_state := 8; + end; + end; + + 1: { Kommentar bis Zeilenende } + begin + pos := length(line); + break; + end; + + 3, 6, 7, 8: { Ende eines gefaerbten Worts } + begin + f_state := 0; + exit(Highlight(syn_other)); + end; + + 4: { String } + case c of + '\': + begin + f_state := 5; + Next := Highlight(syn_string_special); + Inc(pos); + exit; + end; + + '"': + begin + f_state := 0; + Inc(pos); + exit(Highlight(syn_other)); + end; + end; + + 5: { Escaptes Zeichen in einem String } + begin + f_state := 4; + Inc(pos); + exit(Highlight(syn_string)); + end; + + end; + + Inc(pos); + end; + + if f_state in [1, 3, 4, 5] then begin + f_state := 0; + end; +end; + +end. -- 1.6.3.3 From hartmut at tyndur.org Fri Oct 9 06:17:00 2009 From: hartmut at tyndur.org (Alexander Hartmut Kluth) Date: Fri, 9 Oct 2009 06:17:00 +0200 Subject: [tyndur-devel] =?utf-8?q?=5BPATCH_5/5=5D_kedit=3A_AT=26T-Assemble?= =?utf-8?q?r-Highlighting_hinzugef=C3=BCgt?= In-Reply-To: <1255061820-15945-5-git-send-email-hartmut@tyndur.org> References: <1255061820-15945-1-git-send-email-hartmut@tyndur.org> <1255061820-15945-2-git-send-email-hartmut@tyndur.org> <1255061820-15945-3-git-send-email-hartmut@tyndur.org> <1255061820-15945-4-git-send-email-hartmut@tyndur.org> <1255061820-15945-5-git-send-email-hartmut@tyndur.org> Message-ID: <1255061820-15945-6-git-send-email-hartmut@tyndur.org> Hier gleiches wie beim Intel-Highlighting und es fehlen AT&T-Keywords, die sollte bitte einer nachtragen + syntax_atandt.pas: AT&T-Syntax-Highlighting hinzugefügt Signed-off-by: Alexander Hartmut Kluth --- src/modules/pas/kedit/syntax_atandt.pas | 209 +++++++++++++++++++++++++++++++ 1 files changed, 209 insertions(+), 0 deletions(-) create mode 100644 src/modules/pas/kedit/syntax_atandt.pas diff --git a/src/modules/pas/kedit/syntax_atandt.pas b/src/modules/pas/kedit/syntax_atandt.pas new file mode 100644 index 0000000..c61b84b --- /dev/null +++ b/src/modules/pas/kedit/syntax_atandt.pas @@ -0,0 +1,209 @@ +unit syntax_atandt; +{$mode ObjFPC} + +interface + +uses syntax; + +type + TSyntax_ATANDT = class(TSyntax) + public + procedure StartLine(s: String; state: integer); override; + function Next: TSyntaxChange; override; + end; + + +implementation +const +{ TODO: Keine Ahnung... } +{ Keywords_ATANDT: Array [1..48] of String = ( + +} + Types_ATANDT: Array [1..90] of String = ( + '%ax', '%ah', '%al', '%bx', '%bh', '%bl', '%cx', '%ch', '%cl', + '%dx', '%dh', '%dl', '%si', '%ss', '%sp', '%bp', '%cs', '%ds', + '%es', '%fs', '%gs', '%eax', '%ebx', '%ecx', '%edx', '%edi', + '%esi', '%ebp', '%esp', '%eip', '%rax', '%rbx', '%rcx', + '%rdx', '%rdi', '%rsi', '%rbp', '%rsp', '%rip', '%r8', '%r9', + '%r10', '%r11', '%r12', '%r13', '%r14', '%r15', '%dil', '%sil', '%bpl', + '%spl', '%r8l', '%r9l', '%r10l', '%r11l', '%r12l', '%r13l', '%r14l', + '%r15l', '%r8w', '%r9w', '%r10w', '%r11w', '%r13w', '%r14w', '%r15w', + '%r8d', '%r9d', '%r10d', '%r11d', '%r12d', '%r13d', '%r14d', '%r15d', + '%xmm0', '%xmm1', '%xmm2', '%xmm3', '%xmm4', '%xmm5', '%xmm6', '%xmm7', + '%xmm8', '%xmm9', '%xmm10', '%xmm11', '%xmm12', '%xmm13', '%xmm14', + '%xmm15' + ); + +procedure TSyntax_ATANDT.StartLine(s: String; state: integer); +begin + line := s; + f_state := state; + pos := 1; + + case f_state of + 1: color := syn_comment; + 2: color := syn_comment; + 3: color := syn_number; + 4: color := syn_string; + 5: color := syn_string_special; + 6: color := syn_keyword; + 7: color := syn_type; + 8: color := syn_label; + else color := syn_other; + end; +end; + + +function TSyntax_ATANDT.Next: TSyntaxChange; +var + c: char; + tmp: integer; +begin + Next.posY := 0; + Next.color := color; + + while pos <= length(line) do begin + c := line[pos]; + + case f_state of + + 0: { Normaler Text } + case c of + '/': + if Matches(line, pos, '/*') then begin + f_state := 2; + exit(Highlight(syn_comment)); + end; + + '0' .. '9', '-', '+': + begin + tmp := MatchesNumber(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_number); + Inc(pos, tmp); + f_state := 3; + exit; + end; + end; + + '#': + begin + if Copy(line, 1, pos - 1) = Space(pos - 1) then begin + f_state := 1; + exit(Highlight(syn_compiler)); + end; + end; + + '"': + begin + Next := Highlight(syn_string); + Inc(pos); + f_state := 4; + exit; + end; + ' ': + begin + if MatchesTrailingSpace(line, pos) then begin + Next := Highlight(syn_trailing_space); + pos := length(line) + 1; + exit; + end; + end; + + else + begin + {tmp := MatchesKeyword(line, pos, Keywords_ATANDT); + if tmp <> 0 then begin + Next := Highlight(syn_keyword); + Inc(pos, tmp); + f_state := 6; + exit; + end; + } + + tmp := MatchesKeyword(line, pos, Types_ATANDT); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesType(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_type); + Inc(pos, tmp); + f_state := 7; + exit; + end; + + tmp := MatchesLabel(line, pos); + if tmp <> 0 then begin + Next := Highlight(syn_label); + Inc(pos, tmp); + f_state := 8; + exit; + end; + + { FIXME: Keywords werden nicht erkannt } + Next := Highlight(syn_label); + Inc(pos, tmp); + f_state := 8; + end; + end; + + 1: { Kommentar bis Zeilenende } + begin + pos := length(line); + break; + end; + + 2: { C-ähnlicher-Kommentar } + if Matches(line, pos, '*/') then begin + f_state := 0; + Inc(pos, 2); + exit(Highlight(syn_other)); + end; + + 3, 6, 7, 8: { Ende eines gefaerbten Worts } + begin + f_state := 0; + exit(Highlight(syn_other)); + end; + + 4: { String } + case c of + '\': + begin + f_state := 5; + Next := Highlight(syn_string_special); + Inc(pos); + exit; + end; + + '"': + begin + f_state := 0; + Inc(pos); + exit(Highlight(syn_other)); + end; + end; + + 5: { Escaptes Zeichen in einem String } + begin + f_state := 4; + Inc(pos); + exit(Highlight(syn_string)); + end; + + end; + + Inc(pos); + end; + + if f_state in [1, 3, 4, 5] then begin + f_state := 0; + end; +end; + +end. -- 1.6.3.3 From alex at tyndur.org Sat Oct 10 15:31:44 2009 From: alex at tyndur.org (Alexander Siol) Date: Sat, 10 Oct 2009 15:31:44 +0200 Subject: [tyndur-devel] [PATCH v2] + cdi: video-Header Message-ID: <1255181508-22334-1-git-send-email-alex@tyndur.org> Signed-off-by: Alexander Siol --- src/modules/cdi/include/cdi.h | 1 + src/modules/cdi/include/cdi/vesa.h | 118 ++++++++++++++ src/modules/cdi/include/cdi/video.h | 297 +++++++++++++++++++++++++++++++++++ 3 files changed, 416 insertions(+), 0 deletions(-) create mode 100644 src/modules/cdi/include/cdi/vesa.h create mode 100644 src/modules/cdi/include/cdi/video.h diff --git a/src/modules/cdi/include/cdi.h b/src/modules/cdi/include/cdi.h index 7bcf9e4..fee8976 100644 --- a/src/modules/cdi/include/cdi.h +++ b/src/modules/cdi/include/cdi.h @@ -26,6 +26,7 @@ typedef enum { CDI_NETWORK = 1, CDI_STORAGE = 2, CDI_SCSI = 3, + CDI_VIDEO = 4, } cdi_device_type_t; struct cdi_driver; diff --git a/src/modules/cdi/include/cdi/vesa.h b/src/modules/cdi/include/cdi/vesa.h new file mode 100644 index 0000000..1f0eaaa --- /dev/null +++ b/src/modules/cdi/include/cdi/vesa.h @@ -0,0 +1,118 @@ +/* + * Copyright (c) 2008-2009 Mathias Gottschlag, Janosch Graef, Alexander Siol + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#ifndef _CDI_VESA_H_ +#define _CDI_VESA_H_ + +#include +#include +#include + +/** + * Allgemeiner VESA / VBE Informationsblock, wird verwendet um Informationen + * ueber vorhande Faehigkeiten und Modi der Grafikkarte zu erhalten. + */ +struct cdi_video_vesa_info_block { + char signature[4]; + char version[2]; + uint32_t oemname; + uint32_t capabilities; + uint32_t modeptr; + uint16_t videomem; + // VBE 2.0 + uint16_t oemversion; + uint32_t vendornameptr; + uint32_t productnameptr; + uint32_t revisionptr; + uint16_t modes[111]; + uint8_t oem[256]; +} __attribute__ ((packed)); + +/** + * VBE Modus-Informationsblock. + * Enthaelt Infos ueber den speziellen Modus. + */ +struct cdi_video_vesa_mode_info { + uint16_t modeattr; + uint8_t windowattra; + uint8_t windowattrb; + uint16_t windowgran; + uint16_t windowsize; + uint16_t startsega; + uint16_t startsegb; + uint32_t posfunc; + uint16_t scanline; + + uint16_t width; + uint16_t height; + uint8_t charwidth; + uint8_t charheight; + uint8_t planecount; + uint8_t depth; + uint8_t banks; + uint8_t type; + uint8_t banksize; + uint8_t imagepages; + uint8_t reserved; + // VBE v1.2+ + uint8_t redmasksize; + uint8_t redfieldpos; + uint8_t greenmasksize; + uint8_t greenfieldpos; + uint8_t bluemasksize; + uint8_t bluefieldpos; + uint8_t resmasksize; + uint8_t resfieldsize; + uint8_t dircolormode; + // VBE v2.0 + uint32_t linearfb; + uint32_t offscreenmem; + uint32_t offscreensize; + + char reserved2[206]; +} __attribute__ ((packed)); + +/** + * CDI-Video-Mode mit Erweiterung um VESA/VBE-Modusnummer + */ +struct cdi_video_vesa_mode { + struct cdi_video_displaymode mode; + uint16_t vesamode; +}; + +/** + * Liest den allgemeinen VESA/VBE-Informationsblock aus und uebergibt einen + * Pointer auf diesen, ruft fuer jeden gefundenen Modus einen + * Callback auf. + * @param vesainfo Zeiger auf Infoblock-Zeiger + * @param mode_callback Zeiger auf Modus-Callback-Funktion + * @return 0 bei Erfolg, -1 im Fehlerfall + */ +int cdi_video_vesa_initialize + (struct cdi_video_vesa_info_block **vesainfo, + void (*mode_callback)(int modenum, struct cdi_video_vesa_mode_info *mode)); + +/** + * Liefert Informationen zu einem spezifischen Modus + * @param modenum Die Modusnummer - fuer gueltige Nummern siehe den allgemeinen + * Infoblock + * @return Zeiger auf Modus-Informationsblock. 0 bei Fehler. + */ +struct cdi_video_vesa_mode_info* cdi_video_vesa_get_mode(int modenum); + +/** + * Setzt den Modus via int10 + * @param modenum Die Modusnummer - fuer gueltige Nummern siehe den allgemeinen + * Infoblock + * @return 0 bei Erfolg, -1 im Fehlerfall + */ +int cdi_video_vesa_change_mode(int modenum); + +#endif diff --git a/src/modules/cdi/include/cdi/video.h b/src/modules/cdi/include/cdi/video.h new file mode 100644 index 0000000..727e476 --- /dev/null +++ b/src/modules/cdi/include/cdi/video.h @@ -0,0 +1,297 @@ +/* + * Copyright (c) 2007-2009 Mathias Gottschlag, Janosch Graef, Alexander Siol + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#ifndef _CDI_VIDEO_H_ +#define _CDI_VIDEO_H_ + +#include "cdi.h" +#include "cdi/lists.h" + +/** + * Modus fuer Anzeigen + */ +struct cdi_video_displaymode { + unsigned int width; + unsigned int height; + unsigned int depth; // In BPP + int refreshrate; // Vsync in Hz, 0 fuer Irrelevant/Automatisch +}; + +enum cdi_video_bitmap_usage_hint { + CDI_VIDEO_PRIO_HIGH, + CDI_VIDEO_PRIO_NORMAL, + CDI_VIDEO_PRIO_LOW, +}; + +struct cdi_video_pixel_format { + uint8_t bpp; + uint8_t red_bits; + uint8_t red_offset; + uint8_t green_bits; + uint8_t green_offset; + uint8_t blue_bits; + uint8_t blue_offset; + uint8_t alpha_bits; + uint8_t alpha_offset; +}; + +struct cdi_video_bitmap { + /// Aufloesung des Bitmaps - Breite + int width; + /// Aufloesung des Bitmaps - Hoehe + int height; + /// Verwendetes Pixelformat + struct cdi_video_pixel_format format; + + /// Zeilenlaenge in Bytes. Achtung, muss nicht width * bpp sein! + int pitch; + + /// Das Geraet zu dem das Bitmap gehoert. + struct cdi_video_device* device; + + /// 1 wenn im VRAM, 0 wenn im RAM + int in_vram; + + /// Addresse (ggf. im VRAM) + int* pixeldata; +}; + +enum cdi_video_raster_op { + CDI_VIDEO_ROP_COPY, + CDI_VIDEO_ROP_OR, + CDI_VIDEO_ROP_AND, + CDI_VIDEO_ROP_XOR, + // TODO: Erweitern +}; + +struct cdi_video_device { + /// CDI-Geraet + struct cdi_device dev; + + /// Liste der Bildschirme + cdi_list_t displays; + + /// Aktuelle RasterOP (fuer Software-Helfer noetig) + enum cdi_video_raster_op raster_op; + + /// Daten zur Moduswiederherstellung + void* restore_data; + + /// Pointer zum Beginn des (gemappten) VRAM + void* vram; + + /// Groesse des VRAM + size_t vram_size; +}; + +/** + * Eine benutzbare Anzeige - Geraet, Modus, verfuegbare Modi und der Frontbuffer + */ +struct cdi_video_display { + /// Videogeraet, dem dieser Bildschirm angehoert + struct cdi_video_device* device; + + /// Momentaner Modus + struct cdi_video_displaymode* mode; + + /// Liste mit verfuegbaren Modi + cdi_list_t modes; + + /// Zeichenbuffer fuer Display + struct cdi_video_bitmap* frontbuffer; +}; + +/** + * Speichert eine Farbe in jeweils 8-bit ARGB. + */ +struct cdi_video_color { + uint8_t alpha; + uint8_t red; + uint8_t green; + uint8_t blue; +}; + +struct cdi_video_driver { + /// CDI-Treiber + struct cdi_driver drv; + + // Basis-Funktionen + /** + * Sichert die aktiven Modi der Displays zur spaeteren Wiederherstellung + * @param device Das zu sichernde Device + * @return 0 = Erfolg; -1 = Fehlschlag + */ + int (*driver_save)(struct cdi_video_device* device); + + /** + * Stellt den gesicherten Zustand wieder her. + * @param device Das Device das wiederherstellen soll + * @return 0 = Erfolg; -1 = Fehlschlag + */ + int (*driver_restore)(struct cdi_video_device* device); + + + + // Anzeigenkontrolle + + /** + * Setzt die Aufloesung eines Bildschirms + * @param display Bildschirm + * @param mode Modus + * @return 0 = Erfolg; -1 = Fehlschlag + */ + int (*display_set_mode) + (struct cdi_video_device* device, struct cdi_video_display* display, + struct cdi_video_displaymode* mode); + + + + // Bitmap-Funktionen + + /** + * Erstellt ein Bitmap + * @param device Das Geraet auf dem das Bitmap liegt + * @param width Breite des Bitmaps + * @param height Hoehe des Bitmaps + * @param data Pixeldaten, oder 0, wenn keine Initialisierung gewuenscht ist + * @return Zeiger auf die neue Bitmap + */ + struct cdi_video_bitmap* (*bitmap_create) + (struct cdi_video_device* device, unsigned int width, + unsigned int height, void* data); + + /** + * Loescht ein Bitmap + * @param bitmap Zu loeschendes Bitmap + */ + void (*bitmap_destroy) + (struct cdi_video_bitmap* bitmap); + + /** + * Setzt den Gebrauchsmodus eines Bitmaps (bestimmt zB, ob ein Bitmap gecacht wird) + * @param device Videogeraet + * @param bitmap Betroffenes Bitmap + * @param hint Hinweis auf die Prioritaet des Bitmaps + */ + void (*bitmap_set_usage_hint) + (struct cdi_video_device* device, struct cdi_video_bitmap* bitmap, + enum cdi_video_bitmap_usage_hint hint); + + + + // Zeichen-Funktionen + + /** + * Setzt den Raster-Op fuer die folgenden Zeichenfunktionen. + * Der Raster-Op bestimmt, auf welche Art Grafik gezeichnet wird. + * @param target Bitmap auf das gezeichnet werden soll + * @param rop Raster-Op + */ + void (*set_raster_op) + (struct cdi_video_device* device, enum cdi_video_raster_op rop); + + /** + * Zeichnet eine Linie + * @param target Bitmap auf das gezeichnet wird + * @param x1 X-Koordinate des Anfangs + * @param y1 Y-Koordinate des Anfangs + * @param x1 X-Koordinate des Endpunktes + * @param y1 Y-Koordinate des Endpunktes + * @param color Farbe der Linie + */ + void (*draw_line) + (struct cdi_video_bitmap* target, unsigned int x1, unsigned int y1, + unsigned int x2, unsigned int y2, struct cdi_video_color* color); + + /** + * Zeichnet ein Rechteck + * @param target Bitmap auf das gezeichnet wird + * @param x X-Koordinate + * @param y Y-Koordinate + * @param width Breite + * @param height Hoehe + * @param color Farbe des Rechtecks + */ + void (*draw_rectangle) + (struct cdi_video_bitmap* target, unsigned int x, unsigned int y, + unsigned int width, unsigned int height, struct cdi_video_color* color); + + /** + * Zeichnet eine Ellipse + * @param target Bitmap auf das gezeichnet wird + * @param x X-Koordinate + * @param y Y-Koordinate + * @param width Breite + * @param height Hoehe + * @param color Farbe der Ellipse + */ + void (*draw_ellipse) + (struct cdi_video_bitmap* target, unsigned int x, unsigned int y, + unsigned int width, unsigned int height, struct cdi_video_color* color); + + /** + * Zeichnet ein Bitmap + * @param target Bitmap auf das gezeichnet wird + * @param bitmap Zu zeichnendes Bitmap + * @param x X-Koordinate + * @param y Y-Koordinate + * @note Es wird nur so viel kopiert wie das Zielbitmap aufnehmen kann + */ + void (*draw_bitmap) + (struct cdi_video_bitmap* target, struct cdi_video_bitmap* bitmap, + unsigned int x, unsigned int y); + + /** + * Zeichnet einen Teil einer Bitmap + * @param target Bitmap auf das gezeichnet wird + * @param bitmap Zu zeichnendes Bitmap + * @param x X-Koordinate (Ziel) + * @param y Y-Koordinate (Ziel) + * @param srcx X-Koordinate (Quelle) + * @param srcy Y-Koordinate (Quelle) + * @param width Breite + * @param height Hoehe + */ + void (*draw_bitmap_part) + (struct cdi_video_bitmap* target, struct cdi_video_bitmap* bitmap, + unsigned int x, unsigned int y, unsigned int srcx, unsigned int srcy, + unsigned int width, unsigned int height); + + /** + * Zeichnet einen Punkt + * @param target Display, auf dem gezeichnet wird + * @param x X-Koordinate (Ziel) + * @param y Y-Koordinate (Ziel) + * @param color Zeiger auf die zu verwendende Farbe + * @note Sollte Sparsam eingesetzt werden, Viele Punkte so zeichnen ist + * meistens sehr langsam. + */ + void (*draw_dot) + (struct cdi_video_bitmap* target, unsigned int x, unsigned int y, + struct cdi_video_color* color); +}; + +/** + * Initialisiert die Datenstrukturen fuer einen Grafikkartentreiber + */ +void cdi_video_driver_init(struct cdi_video_driver* driver); + +/** + * Deinitialisiert die Datenstrukturen fuer einen Grafikkartentreiber + */ +void cdi_video_driver_destroy(struct cdi_video_driver* driver); + +/** + * Registiert einen Grafikkartentreiber + */ +void cdi_video_driver_register(struct cdi_video_driver* driver); + + +#endif -- 1.6.0.4 From alex at tyndur.org Sat Oct 10 15:31:45 2009 From: alex at tyndur.org (Alexander Siol) Date: Sat, 10 Oct 2009 15:31:45 +0200 Subject: [tyndur-devel] [PATCH v2] + libvideo: Header In-Reply-To: <1255181508-22334-1-git-send-email-alex@tyndur.org> References: <1255181508-22334-1-git-send-email-alex@tyndur.org> Message-ID: <1255181508-22334-2-git-send-email-alex@tyndur.org> Signed-off-by: Alexander Siol --- src/modules/include/video/commands.h | 80 ++++++++++ src/modules/include/video/video.h | 269 ++++++++++++++++++++++++++++++++++ 2 files changed, 349 insertions(+), 0 deletions(-) create mode 100644 src/modules/include/video/commands.h create mode 100644 src/modules/include/video/video.h diff --git a/src/modules/include/video/commands.h b/src/modules/include/video/commands.h new file mode 100644 index 0000000..2ec8c6e --- /dev/null +++ b/src/modules/include/video/commands.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +/// Kommandos + +enum video_commands { + /// Kontextsteuerung + + /// Erzeugt einen neuen Treiberkontext + VIDEO_CMD_CREATE_CONTEXT, + /// Setzt den aktiven Treiberkontext + VIDEO_CMD_USE_CONTEXT, + /// Setzt das Geraet (per Nummer) im aktiven Treiberkontext + VIDEO_CMD_USE_DEVICE, + /// Setzt das aktive Ziel (Bitmap) im aktiven Treiberkontext + VIDEO_CMD_USE_TARGET, + /// Setzt die aktive Zeichenfarbe im aktiven Treiberkontext + VIDEO_CMD_USE_COLOR, + /// Setzt die aktive Raster-OP im aktiven Treiberkontext + VIDEO_CMD_USE_ROP, + /// Fordert einen Kommandobuffer fuer den Treiberkontext an. + VIDEO_CMD_GET_CMD_BUFFER, + /// Fordert die Ausfuehrung des Buffers an. + VIDEO_CMD_DO_CMD_BUFFER, + + /// Geräteabfrage + + /// Fragt die Anzahl Geraete ab + VIDEO_CMD_GET_NUM_DEVICES, + /// Fragt die Anzahl der Anzeigen am Geraet ab + VIDEO_CMD_GET_NUM_DISPLAYS, + /// Fragt die Displaymodi ab + VIDEO_CMD_GET_DISPLAY_MODES, + + /// Anderes + + /// Setzt den Modus + /// FIXME Umbenennen + VIDEO_CMD_SET_RESOLUTION, + + /// Bitmaps + /// Erzeugt ein Bitmap + VIDEO_CMD_CREATE_BITMAP, + /// Zerstoert ein Bitmap + VIDEO_CMD_DESTROY_BITMAP, + /// Erzeugt eine Bitmap auf den Display-Frontbuffer + VIDEO_CMD_CREATE_FRONTBUFFER_BITMAP, + + /// Primitiven Zeichnen + VIDEO_CMD_DRAW_PIXEL, + VIDEO_CMD_DRAW_RECTANGLE, + VIDEO_CMD_DRAW_ELLIPSE, + VIDEO_CMD_DRAW_LINE, + VIDEO_CMD_DRAW_BITMAP, + VIDEO_CMD_DRAW_BITMAP_PART, +}; \ No newline at end of file diff --git a/src/modules/include/video/video.h b/src/modules/include/video/video.h new file mode 100644 index 0000000..b2881d2 --- /dev/null +++ b/src/modules/include/video/video.h @@ -0,0 +1,269 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +#ifndef __LIBVIDEO_VIDEO_H__ +#define __LIBVIDEO_VIDEO_H__ + +#include +#include + +#define VIDEORPC_GET_DWORD(size, data) \ + rpc_get_dword(context->driverpid, "VIDEODRV", size, data) + +#define REQUIRE_CMD_BUFFER(length) \ + do { \ + if (context->cmdbuffer == 0) return -1; \ + if (context->cmdbufferlen < context->cmdbufferpos + length) \ + libvideo_do_command_buffer(); \ + } while (0); + +#define REQUIRE_CMD_BUFFER_RETURN_VOID(length) \ + do { \ + if (context->cmdbuffer == 0) return; \ + if (context->cmdbufferlen < context->cmdbufferpos + length) \ + libvideo_do_command_buffer(); \ + } while (0); + +#define SET_CMD_BUFFER(value) \ + context->cmdbuffer[context->cmdbufferpos++] = value + + +typedef struct { + pid_t driverpid; + uint32_t drivercontext; + uint32_t* cmdbuffer; + uint32_t cmdbufferpos; + uint32_t cmdbufferlen; + uint32_t cmdbufferid; +} driver_context_t; + +typedef struct { + uint32_t id; + uint32_t width; + uint32_t height; +} video_bitmap_t; + + +// FIXME: Muss immer mit CDI (cdi/video.h) abgeglichen werden! + +typedef enum { + VIDEO_ROP_COPY, + VIDEO_ROP_OR, + VIDEO_ROP_AND, + VIDEO_ROP_XOR, + // TODO: Erweitern +} rop_t; + +/// Kontextsteuerung + +/** + * Erstellt einen neuen Kontext fuer den angebenen Treiber + * @param driver String, Name des Treibers (= Prozessname) + * @return Zeiger auf Kontext. NULL im Fehlerfall. + */ +driver_context_t* libvideo_create_driver_context(char* driver); + +/** + * Setzt den aktuell aktiven Kontext + * @param context Zeiger auf den zu aktivierenden Kontext. + */ +void libvideo_use_driver_context(driver_context_t* context); + +/// Kontextabhaengig + +/** + * Setzt das aktive Geraet im aktuellen Kontext + * @param devicenum Geraetenummer. + * @return 0 bei Erfolg, sonst -1 + */ +int libvideo_change_device(int devicenum); + +/** + * Setzt das aktive Ziel(bitmap) im aktuellen Kontext + * @param bitmap Zeiger auf Bitmap. + * @return 0 bei Erfolg, sonst -1 + */ +int libvideo_change_target(video_bitmap_t *bitmap); + +/** + * Setzt die Zeichenfarbe im aktuellen Kontext + * @param alpha Alpha-Anteil (0-255) + * @param red Rot-Anteil (0-255) + * @param green Gruen-Anteil (0-255) + * @param blue Blau-Anteil (0-255) + * @return 0 bei Erfolg, sonst -1 + */ +int libvideo_change_color(char alpha, char red, char green, char blue); + +/** + * Setzt die Raster-OP fuer weitere Zeichenvorgaenge im aktuellen Kontext + * @param rop Die Raster-OP + * @return 0 bei Erfolg, sonst -1 + */ +int libvideo_change_rop(rop_t rop); + +/** + * Fordert einen neuen Kommandobuffer fuer den Kontext an. + * @param length Die Laenge des Zeichenbuffers in 4 Bytes. + * @return 0 bei Erfolg, sonst -1 + */ +int libvideo_get_command_buffer(size_t length); + +/** + * Gibt dem Treiber die Anweisung den Buffer auszufuehren. + * Achtung, dies wird auch automatisch getan wenn der Buffer voll ist! + * Achtung, nicht nach jedem Zeichenvorgang aufrufen - kostet Geschwindigkeit! + * @return 0 bei Erfolg, sonst -1 + */ +int libvideo_do_command_buffer(void); + +/// Geraeteabfrage + +/** + * Gibt die Anzahl der Geraete am Treiber des aktuellen Kontexts zurueck. + * @return die Anzahl der Geraete des Treibers. + */ +int libvideo_get_num_devices(void); + +/** + * Gibt die Zahl der Anzeigen am angegebenen Geraete im aktuellen Kontext zurueck + * @param device Geraetenummer + * @return Anzahl der Anzeigen am Grafikadapter + */ +int libvideo_get_num_displays(int device); + +/** + * Liefert ein Array mit Modusinformationen + * @param device Geraetenummer + * @param display Anzeigennummer + * @return dword[0] enthaelt die Anzahl an Modi. Fuer jeden Modus: + * dword[i + 1] Breite (px), dword[i + 2] Hoehe (px), dword[i + 3] Bits per Pixel, + * dword[i + 4] Bildwiederholrate (VSync Hz), 0 fuer automatische Einstellung. + */ +dword* libvideo_get_modes(int device, int display); + +/// Bitmaps +/** + * Erzeugt ein Bitmap, laedt ggf. Initialisierungsdaten zum Treiber. + * Ohne Initialisierung erhaelt man ein schwarzes Bitmap. + * @param width Breite in Pixel + * @param height Hoehe in Pixel + * @param length Laenge der Nutzdaten, 0 fuer keine. + * @param data Zeiger auf Datenbuffer, Pixelformat wird als 32-bit ARGB angenommen + */ +video_bitmap_t* libvideo_create_bitmap(int width, int height, + size_t data_length, void* data); + +/** + * Gibt ein Bitmap wieder frei. + * @param bitmap Das Bitmap. + */ +void libvideo_destroy_bitmap(video_bitmap_t *bitmap); + +/** + * Holt ein Bitmap-Objekt fuer den Anzeigenfrontbuffer + * @param display Die Anzeige deren Frontbuffer einen interessiert + * @return Zeiger auf Bitmap, NULL im Fehlerfall + * @note Es kann global nur eine Bitmap fuer Frontbufferzugriff geben! + */ +video_bitmap_t* libvideo_get_frontbuffer_bitmap(int display); + +/// Primitiven Zeichnen + +/** + * Zeichnet einen Pixel in der gesetzten Farbe auf das aktuelle Ziel. + * @param x X-Koordinate + * @param y Y-Koordinate + */ +void libvideo_draw_pixel(int x, int y); + +/** + * Zeichnet einen Rechteck in der gesetzten Farbe auf das aktuelle Ziel. + * @param x X-Koordinate + * @param y Y-Koordinate + * @param width Breite in Pixel + * @param height Hoehe in Pixel + */ +void libvideo_draw_rectangle(int x, int y, int width, int height); + +/** + * Zeichnet eine Ellipse (die das spezifizierte Rechteck bestmoeglich ausfuellt) + * in der gesetzten Farbe auf das aktuelle Ziel. + * @param x X-Koordinate + * @param y Y-Koordinate + * @param width Breite in Pixel + * @param height Hoehe in Pixel + */ +void libvideo_draw_ellipse(int x, int y, int width, int height); + + +/** + * Zeichnet eine Linie in der gesetzten Farbe auf das aktuelle Ziel. + * @param x1 Start-X-Koordinate + * @param y1 Start-Y-Koordinate + * @param x2 End-X-Koordinate + * @param y2 End-Y-Koordinate + */ +void libvideo_draw_line(int x1, int y1, int x2, int y2); + +/** + * Zeichnet eine Bitmap auf das aktuelle Ziel. + * @param bitmap die Quell-Bitmap + * @param x X-Koordinate + * @param y Y-Koordinate + */ +void libvideo_draw_bitmap(video_bitmap_t *bitmap, int x, int y); + +/** + * Zeichnet einen Bitmapausschnitt auf das aktuelle Ziel. + * @param bitmap die Quell-Bitmap + * @param x Ziel-X-Koordinate + * @param y Ziel-Y-Koordinate + * @param srcx Start-X-Koordinate des Quellrechtecks + * @param srcy Start-Y-Koordinate des Quellrechtecks + * @param width Breite des zu kopierenden Rechtecks in Pixel + * @param height Hoehe des zu kopierenden Rechtecks in Pixel + */ +void libvideo_draw_bitmap_part(video_bitmap_t *bitmap, int x, int y, int srcx, + int srcy, int width, int height); + +/// Anderes + +/** + * Setzt die Aufloesung einer Anzeige + * @param display Die Anzeige + * @param width Breite + * @param height Hoehe + * @param depth Gewuenschte Farbtiefe (in BPP) + * @return 0 bei Erfolg, sonst -1 + * @note Die Farbtiefe ist nur ein Richtwert - es wird gegebenfalls eine andere + * verwendet, allerdings werden die Farbwerte transparent umgerechnet. + */ +int libvideo_change_display_resolution(int display, int width, int height, + int depth); + +#endif /* __LIBVIDEO_VIDEO_H__ */ -- 1.6.0.4 From alex at tyndur.org Sat Oct 10 15:31:46 2009 From: alex at tyndur.org (Alexander Siol) Date: Sat, 10 Oct 2009 15:31:46 +0200 Subject: [tyndur-devel] [PATCH v2] + cdi.video: vesa In-Reply-To: <1255181508-22334-1-git-send-email-alex@tyndur.org> References: <1255181508-22334-1-git-send-email-alex@tyndur.org> Message-ID: <1255181508-22334-3-git-send-email-alex@tyndur.org> Achtung, qemu-spezifisch! Funktioniert so in anderen Umgebungen nicht. Signed-off-by: Alexander Siol --- src/modules/cdi/vesa/Makefile.all | 6 + src/modules/cdi/vesa/bitmap.c | 77 ++++++++ src/modules/cdi/vesa/bitmap.h | 13 ++ src/modules/cdi/vesa/device.c | 185 ++++++++++++++++++++ src/modules/cdi/vesa/device.h | 15 ++ src/modules/cdi/vesa/drawing.c | 345 +++++++++++++++++++++++++++++++++++++ src/modules/cdi/vesa/drawing.h | 59 +++++++ src/modules/cdi/vesa/main.c | 124 +++++++++++++ src/modules/cdi/vesa/vesa.h | 47 +++++ 9 files changed, 871 insertions(+), 0 deletions(-) create mode 100644 src/modules/cdi/vesa/Makefile.all create mode 100644 src/modules/cdi/vesa/bitmap.c create mode 100644 src/modules/cdi/vesa/bitmap.h create mode 100644 src/modules/cdi/vesa/device.c create mode 100644 src/modules/cdi/vesa/device.h create mode 100644 src/modules/cdi/vesa/drawing.c create mode 100644 src/modules/cdi/vesa/drawing.h create mode 100644 src/modules/cdi/vesa/main.c create mode 100644 src/modules/cdi/vesa/vesa.h diff --git a/src/modules/cdi/vesa/Makefile.all b/src/modules/cdi/vesa/Makefile.all new file mode 100644 index 0000000..ec6f85a --- /dev/null +++ b/src/modules/cdi/vesa/Makefile.all @@ -0,0 +1,6 @@ +shopt -s extglob +source $LOST_BUILDMK_ROOT/config.sh + +echo "LD $1/modules/vesa" +$LOST_TOOLS_LD -ovesa.mod -Ttext=0x40000000 *.o --start-group $2 --end-group +$LOST_TOOLS_STRIP -s vesa.mod -o $1/modules/vesa diff --git a/src/modules/cdi/vesa/bitmap.c b/src/modules/cdi/vesa/bitmap.c new file mode 100644 index 0000000..1609c70 --- /dev/null +++ b/src/modules/cdi/vesa/bitmap.c @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +#include +#include +#include +#include + +struct cdi_video_bitmap* vesa_bitmap_create(struct cdi_video_device* device, + unsigned int width, unsigned int height, void* data) +{ + struct cdi_video_bitmap* bitmap = calloc(1,sizeof(struct cdi_video_bitmap)); + + bitmap->device = device; + bitmap->width = width; + bitmap->height = height; + bitmap->format.bpp = 32; + bitmap->format.red_bits = 8; + bitmap->format.red_offset = 16; + bitmap->format.green_bits = 8; + bitmap->format.green_offset = 8; + bitmap->format.blue_bits = 8; + bitmap->format.blue_offset = 0; + + bitmap->pitch = bitmap->format.bpp / 8 * width; + + bitmap->in_vram = 0; + + bitmap->pixeldata = calloc(1, width * height * 4); + if (data) { + memcpy(bitmap->pixeldata, data, width * height * 4); + } + + return bitmap; +} + +void vesa_bitmap_destroy(struct cdi_video_bitmap* bitmap) +{ + if (bitmap->in_vram == 0) { + free(bitmap->pixeldata); + } + free(bitmap); +} + +void vesa_bitmap_set_usage_hint(struct cdi_video_device* device, + struct cdi_video_bitmap* bitmap, enum cdi_video_bitmap_usage_hint hint) +{ + /* + Meiner Meinung nach kann sowas mit VESA garnicht gescheit gemacht werden - + immerhin sind eh alle Bitmaps im genau gleichen RAM. + */ + return; +} \ No newline at end of file diff --git a/src/modules/cdi/vesa/bitmap.h b/src/modules/cdi/vesa/bitmap.h new file mode 100644 index 0000000..636b700 --- /dev/null +++ b/src/modules/cdi/vesa/bitmap.h @@ -0,0 +1,13 @@ + +#ifndef __VESA_BITMAP_H__ +#define __VESA_BITMAP_H__ + +#include + +void vesa_bitmap_set_usage_hint(struct cdi_video_device *device, + struct cdi_video_bitmap *bitmap, enum cdi_video_bitmap_usage_hint hint); +void vesa_bitmap_destroy(struct cdi_video_bitmap *bitmap); +struct cdi_video_bitmap *vesa_bitmap_create(struct cdi_video_device *device, + unsigned int width, unsigned int height, void *data); + +#endif /* __VESA_BITMAP_H__ */ diff --git a/src/modules/cdi/vesa/device.c b/src/modules/cdi/vesa/device.c new file mode 100644 index 0000000..df9a438 --- /dev/null +++ b/src/modules/cdi/vesa/device.c @@ -0,0 +1,185 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +#include "device.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include "vesa.h" +#include "drawing.h" +#include "bitmap.h" + +struct vesa_device* vesa_device_create(char* name, struct cdi_pci_device* pci) +{ + // Device anlegen + struct vesa_device* dev; + dev = malloc(sizeof(struct vesa_device)); + dev->dev.dev.name = name; + dev->dev.displays = cdi_list_create(); + + dev->dev.raster_op = CDI_VIDEO_ROP_COPY; + dev->dev.restore_data = NULL; + + dev->dev.vram = NULL; + dev->dev.vram_size = 0; + + int i; + + // Ressourcen holen (Speicher als Framebuffer) + // FIXME: Hack, Keine Ahnung ob das außerhalb von qemu tut. + cdi_pci_alloc_memory(pci); + for (i = 0; i < cdi_list_size(pci->resources); i++) { + struct cdi_pci_resource* res; + res = cdi_list_get(pci->resources, i); + if (res->type == CDI_PCI_MEMORY && res->length > 0x1000) { + dev->dev.vram = res->address; + dev->dev.vram_size = res->length; + break; + } + } + + // Display anlegen + struct cdi_video_display* vesadisplay; + vesadisplay = calloc(1,sizeof(struct cdi_video_display)); + + vesadisplay->device = (struct cdi_video_device*)dev; + vesadisplay->mode = NULL; + vesadisplay->modes = cdi_list_create(); + + // Muss bei change_mode sinnvoll gesetzt werden + vesadisplay->frontbuffer = NULL; + + cdi_list_push(dev->dev.displays, vesadisplay); + + return dev; +} + +/** + * Callback fuer CDI-Vesa-Modi + */ +void vesa_mode_callback(int modenum, struct cdi_video_vesa_mode_info *modeinfo) +{ + switch (modeinfo->depth) { + case 32: + case 24: + case 16: + printf("Modus OK: %dx%d\n", modeinfo->width, modeinfo->height); + struct cdi_video_display *vesadisplay; + struct vesa_device *vesadev; + // Geraet & Display suchen. + // VESA kann nur ein Geraet und ein Display + vesadev = cdi_list_get(vesa_driver.drv.drv.devices, 0); + vesadisplay = cdi_list_get(vesadev->dev.displays, 0); + + // Modus hinzufuegen + struct cdi_video_vesa_mode *vesamode; + vesamode = calloc(1,sizeof(struct cdi_video_vesa_mode)); + vesamode->vesamode = modenum; + vesamode->mode.width = modeinfo->width; + vesamode->mode.height = modeinfo->height; + vesamode->mode.depth = modeinfo->depth; + cdi_list_push(vesadisplay->modes, vesamode); + + break; + default: + /* + Andere Modi sind einfach zu ungenau um die wirklich in Erwaegung zu + ziehen, auch wenn die technisch moeglich waeren + */ + break; + } + return; +} + +/** + * Modus setzen + */ +int vesa_display_set_mode(struct cdi_video_device* device, + struct cdi_video_display* display, struct cdi_video_displaymode* mode) +{ + struct cdi_video_vesa_mode* vesamode; + vesamode = (struct cdi_video_vesa_mode*)mode; + cdi_video_vesa_change_mode(vesamode->vesamode); + + struct cdi_video_bitmap* bitmap; + if (display->frontbuffer != NULL) { + bitmap = display->frontbuffer; + } else { + bitmap = calloc(1, sizeof(struct cdi_video_bitmap)); + } + + struct cdi_video_vesa_mode_info* vesamodeinfo; + vesamodeinfo = cdi_video_vesa_get_mode(vesamode->vesamode); + + bitmap->width = mode->width; + bitmap->height = mode->height; + bitmap->format.bpp = vesamodeinfo->depth; + bitmap->format.red_bits = vesamodeinfo->redmasksize; + bitmap->format.red_offset = vesamodeinfo->redfieldpos; + bitmap->format.green_bits = vesamodeinfo->greenmasksize; + bitmap->format.green_offset = vesamodeinfo->greenfieldpos; + bitmap->format.blue_bits = vesamodeinfo->bluemasksize; + bitmap->format.blue_offset = vesamodeinfo->bluefieldpos; + bitmap->format.alpha_bits = 0; + bitmap->format.alpha_offset = 0; + + // Offsets muessen auf 32-bit passen. + if (bitmap->format.bpp == 16) { + bitmap->format.red_offset += 16; + bitmap->format.green_offset += 16; + bitmap->format.blue_offset += 16; + } + + bitmap->in_vram = 1; + bitmap->device = device; + bitmap->pixeldata = NULL; // Im VRAM, passt so + bitmap->pitch = bitmap->width * bitmap->format.bpp / 8; + + display->frontbuffer = bitmap; + +#if 0 + // Die Sichere Variante um das Bitmap zu schwaerzen + struct cdi_video_color color; + color.alpha = 0; + color.red = 0; + color.green = 0; + color.blue = 0; + + vesa_draw_rectangle(bitmap, 0, 0, bitmap->width, bitmap->height, &color); +#endif + + // Inkorrekte Variante, aber schneller - und macht effektiv das gleiche. + memset(bitmap->device->vram, 0, bitmap->width * bitmap->height * + bitmap->format.bpp); + + return 0; +} diff --git a/src/modules/cdi/vesa/device.h b/src/modules/cdi/vesa/device.h new file mode 100644 index 0000000..7f5ea22 --- /dev/null +++ b/src/modules/cdi/vesa/device.h @@ -0,0 +1,15 @@ + +#ifndef __VESA_DEVICE_H__ +#define __VESA_DEVICE_H__ + +#include +#include +#include + +void vesa_mode_callback(int modenum, + struct cdi_video_vesa_mode_info *modeinfo); +struct vesa_device *vesa_device_create(char *name, struct cdi_pci_device* pci); +int vesa_display_set_mode(struct cdi_video_device *device, + struct cdi_video_display *display, struct cdi_video_displaymode *mode); + +#endif /* __VESA_DEVICE_H__ */ diff --git a/src/modules/cdi/vesa/drawing.c b/src/modules/cdi/vesa/drawing.c new file mode 100644 index 0000000..480dbd1 --- /dev/null +++ b/src/modules/cdi/vesa/drawing.c @@ -0,0 +1,345 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +#include +#include +#include "drawing.h" +#include + + +#define min(x,y) (((x) < (y)) ? (x) : (y)) + +uint32_t colormasks[3] = { 0xffff0000, 0x00ffffff, 0xffffffff }; // 16, 24, 32 bpp + +void vesa_set_raster_op(struct cdi_video_device* device, + enum cdi_video_raster_op rop) +{ + device->raster_op = rop; +} + +void vesa_draw_line(struct cdi_video_bitmap* target, unsigned int x1, + unsigned int y1, unsigned int x2, unsigned int y2, + struct cdi_video_color* color) +{ + // Speicher suchen + char *dstchar = NULL; + if (target->in_vram == 1) { + dstchar = target->device->vram; + } + int x_shift = target->format.bpp / 8; + + dstchar += (uint32_t)target->pixeldata; + dstchar += y1 * target->pitch; + dstchar += x1 * x_shift; + + // Farben und Farbmasken + uint32_t new = 0, old = 0; + uint32_t colormask, keepmask; + + colormask = colormasks[(target->format.bpp - 16) / 8]; + keepmask = ~colormask; + + new = convert_color(target->format, color); + + // Bresenham Initialisierung + int dx = x2 - x1; + int dy = y2 - y1; + + int xstep = 0, ystep = 0; + int normal_step_x, normal_step_y, error_fast, error_slow; + int error, i; + + if (dx > 0) { + xstep = x_shift; + } else if (dx < 0) { + xstep = -x_shift; + dx = -dx; + } + + if (dy > 0) { + ystep = target->pitch; + } else if (dy < 0) { + ystep = -target->pitch; + dy = -dy; + } + + if (dx > dy) { + normal_step_x = xstep; + normal_step_y = 0; + error_fast = dy; + error_slow = dx; + } else { + normal_step_x = 0; + normal_step_y = ystep; + error_fast = dx; + error_slow = dy; + } + error = error_slow >> 1; + + + for (i = 0; i <= error_slow; i++) { + old = *(uint32_t*)dstchar & colormask; + *(uint32_t*)dstchar &= keepmask; + *(uint32_t*)dstchar |= new & colormask; + + error -= error_fast; + if (error < 0) { + error += error_slow; + dstchar += xstep; + dstchar += ystep; + } else { + dstchar += normal_step_x; + dstchar += normal_step_y; + } + } +} + +void vesa_draw_rectangle(struct cdi_video_bitmap* target, unsigned int x, + unsigned int y, unsigned int width, unsigned int height, + struct cdi_video_color* color) +{ + int widthctr; + // Pixel vorbereiten + char* linestart = NULL; + char* in_line; + if (target->in_vram == 1) { + linestart = target->device->vram; + } + int x_shift = target->format.bpp / 8; + + linestart += (uint32_t)target->pixeldata; + linestart += y * target->pitch; + linestart += x * x_shift; + + // Farben und Farbmasken + uint32_t new = 0, old = 0; + uint32_t colormask, keepmask; + + colormask = colormasks[(target->format.bpp - 16) / 8]; + keepmask = ~colormask; + + new = convert_color(target->format, color); + + while (height > 0) { + // Render Line + widthctr = width; + in_line = linestart; + while (widthctr > 0) { + // Render Pixel + old = *(uint32_t*)in_line & colormask; + new = do_rop(target->device->raster_op, new, old); + + *(uint32_t*)in_line &= keepmask; + *(uint32_t*)in_line |= new & colormask; + + in_line += x_shift; + widthctr--; + } + // Eine Reihe weiter + height--; + linestart += target->pitch; + } +} + +// TODO TODO TODO TODO TODO +void vesa_draw_ellipse(struct cdi_video_bitmap* target, unsigned int x, + unsigned int y, unsigned int width, unsigned int height, + struct cdi_video_color* color); + +void vesa_draw_bitmap(struct cdi_video_bitmap* target, + struct cdi_video_bitmap* source, unsigned int x, unsigned int y) +{ + vesa_draw_bitmap_part(target, source, x, y, 0, 0, source->width, + source->height); +} + +void vesa_draw_bitmap_part(struct cdi_video_bitmap* target, + struct cdi_video_bitmap* source, unsigned int x, unsigned int y, + unsigned int srcx, unsigned int srcy, unsigned int width, + unsigned int height) +{ + int copywidth, copyheight, origcopywidth; + + // Zu kopierenden Bereich festlegen + copywidth = min( min( target->width - x, width ), + source->width - srcx); + copyheight = min (min (target->height - y, height), + source->height - srcy); + + // Speicherstellen berechnen + char* srcchar = NULL; + if (source->in_vram == 1) { srcchar = source->device->vram; } + srcchar += (int)source->pixeldata; + srcchar += (int)(srcx * source->format.bpp / 8); + srcchar += (int)(srcy * source->pitch); + + char* dstchar = NULL; + if (target->in_vram == 1) { dstchar = target->device->vram; } + dstchar += (int)target->pixeldata; + dstchar += (int)(x * target->format.bpp / 8); + dstchar += (int)(y * target->pitch); + + char *dstline, *srcline; + + // Farben und Farbmasken + uint32_t new = 0, old = 0; + struct cdi_video_color* newcolor; + uint32_t colormask, keepmask; + + colormask = colormasks[(target->format.bpp - 16) / 8]; + keepmask = ~colormask; + + // Schleifenvorbereitung + dstline = dstchar; + srcline = srcchar; + origcopywidth = copywidth; + while (copyheight > 0) { + copywidth = origcopywidth; + while (copywidth > 0) { + // Farben vorbereiten + old = *(uint32_t*)dstchar & colormask; + newcolor = convert_color_from_pixel(source->format, + *(uint32_t*)srcchar); + new = convert_color(target->format, newcolor); + new = do_rop(target->device->raster_op, new, old); + free(newcolor); + + // Malen + *(uint32_t*)dstchar &= keepmask; + *(uint32_t*)dstchar |= new & colormask; + + // Zeiger einen Pixel weitersetzen + srcchar += source->format.bpp / 8; + dstchar += target->format.bpp / 8; + copywidth--; + } + // Linie fertig, naechste benutzen. + dstline += target->pitch; + srcline += source->pitch; + srcchar = srcline; + dstchar = dstline; + copyheight--; + } +} + +inline void vesa_draw_dot(struct cdi_video_bitmap* target, unsigned int x, + unsigned int y, struct cdi_video_color* color) +{ + // Speicherposition berechnen + char *tmp; + if (target->in_vram == 1) { + tmp = target->device->vram; + } else { + tmp = NULL; + } + tmp += (int)(target->pixeldata); + tmp += (int)(y * (target->pitch)); + tmp += (int)(x * (target->format.bpp) / 8); + + uint32_t *start = (uint32_t*)tmp; + + // Farben und Farbmasken definieren. + uint32_t newcolor = 0, oldcolor = 0; + uint32_t colormask, keepmask; + colormask = colormasks[(target->format.bpp - 16) / 8]; + keepmask = ~colormask; + + // Farbe berechnen + oldcolor = *start & colormask; + newcolor = convert_color(target->format, color); + newcolor = do_rop(target->device->raster_op, newcolor, oldcolor); + + // und setzen. + *start &= keepmask; + *start |= newcolor & colormask; +} + +inline uint32_t do_rop(enum cdi_video_raster_op rop, uint32_t new, uint32_t old) +{ + switch (rop) { + case CDI_VIDEO_ROP_OR: + return new | old; + case CDI_VIDEO_ROP_XOR: + return new ^ old; + case CDI_VIDEO_ROP_AND: + return new & old; + default: + fprintf(0, "VESA unterstützt ROP %d nicht\n", + rop); + // Hier _kein_ break, damit im Fehlerfall wenigstens was rauskommt. + case CDI_VIDEO_ROP_COPY: + return new; + } +} + +inline uint32_t convert_color(struct cdi_video_pixel_format fmt, + struct cdi_video_color* cdicolor) +{ + uint32_t red, blue, green, alpha, color; + red = cdicolor->red << fmt.red_bits >> 8; + green = cdicolor->green << fmt.green_bits >> 8; + blue = cdicolor->blue << fmt.blue_bits >> 8; + + // Hier pruefen reicht, RGB sollte eigentlich immer da sein. + if (fmt.alpha_bits > 0) { + alpha = cdicolor->alpha << fmt.alpha_bits >> 8; + } else { + alpha = 0; + } + color = red << fmt.red_offset | + green << fmt.green_offset | + blue << fmt.blue_offset | + alpha << fmt.alpha_offset; + return color; +} + +struct cdi_video_color* convert_color_from_pixel(struct cdi_video_pixel_format + fmt, uint32_t value) +{ + struct cdi_video_color* color = malloc(sizeof(struct cdi_video_color)); + int redmask, bluemask, greenmask, alphamask; + + // Masken setzen + redmask = ((1 << fmt.red_bits) - 1) << fmt.red_offset; + greenmask = ((1 << fmt.green_bits) - 1) << fmt.green_offset; + bluemask = ((1 << fmt.blue_bits) - 1) << fmt.blue_offset; + alphamask = ((1 << fmt.alpha_bits) - 1) << fmt.alpha_offset; + + // Farben extrahieren + color->red = (value & redmask) >> fmt.red_offset; + color->green = (value & greenmask) >> fmt.green_offset; + color->blue = (value & bluemask) >> fmt.blue_offset; + color->alpha = (value & alphamask) >> fmt.alpha_offset; + + // Auf die richtige Aufloesung bringen. + color->red = color->red << 8 >> fmt.red_bits; + color->green = color->green << 8 >> fmt.green_bits; + color->blue = color->blue << 8 >> fmt.blue_bits; + color->alpha = color->alpha << 8 >> fmt.alpha_bits; + + return color; +} diff --git a/src/modules/cdi/vesa/drawing.h b/src/modules/cdi/vesa/drawing.h new file mode 100644 index 0000000..2232cfe --- /dev/null +++ b/src/modules/cdi/vesa/drawing.h @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +#ifndef __VESA_DRAWING_H__ +#define __VESA_DRAWING_H__ + +#include + +void vesa_set_raster_op(struct cdi_video_device* device, + enum cdi_video_raster_op rop); +void vesa_draw_line(struct cdi_video_bitmap* target, unsigned int x1, + unsigned int y1, unsigned int x2, unsigned int y2, + struct cdi_video_color* color); +void vesa_draw_rectangle(struct cdi_video_bitmap* target, unsigned int x, + unsigned int y, unsigned int width, unsigned int height, + struct cdi_video_color* color); +void vesa_draw_ellipse(struct cdi_video_bitmap* target, unsigned int x, + unsigned int y, unsigned int width, unsigned int height, + struct cdi_video_color* color); +void vesa_draw_bitmap(struct cdi_video_bitmap* target, + struct cdi_video_bitmap* bitmap, unsigned int x, unsigned int y); +void vesa_draw_bitmap_part(struct cdi_video_bitmap* target, + struct cdi_video_bitmap* bitmap, unsigned int x, unsigned int y, + unsigned int srcx, unsigned int srcy, unsigned int width, + unsigned int height); +inline void vesa_draw_dot(struct cdi_video_bitmap* target, unsigned int x, + unsigned int y, struct cdi_video_color* color); + +inline uint32_t do_rop(enum cdi_video_raster_op rop, uint32_t new, uint32_t old); +inline uint32_t convert_color(struct cdi_video_pixel_format fmt, + struct cdi_video_color* cdicolor); +struct cdi_video_color* convert_color_from_pixel(struct cdi_video_pixel_format + fmt, uint32_t value); + +#endif /* __VESA_DRAWING_H__ */ diff --git a/src/modules/cdi/vesa/main.c b/src/modules/cdi/vesa/main.c new file mode 100644 index 0000000..416138f --- /dev/null +++ b/src/modules/cdi/vesa/main.c @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2008 Alexander Siol + * + * This program is free software. It comes without any warranty, to + * the extent permitted by applicable law. You can redistribute it + * and/or modify it under the terms of the Do What The Fuck You Want + * To Public License, Version 2, as published by Sam Hocevar. See + * http://sam.zoy.org/projects/COPYING.WTFPL for more details. + */ + +#include +#include +#include + +#include +#include +#include +#include +#include +#include + +#include "vesa.h" +#include "bitmap.h" +#include "device.h" +#include "drawing.h" + +char* driver_name = "vesa"; +struct cdi_video_vesa_driver vesa_driver; + +static void vesa_driver_init(void); +static void vesa_driver_destroy(struct cdi_driver* driver); +void vesa_init_device(struct cdi_device* device); + +#define DEBUG printf +#define TODO // + +#ifdef CDI_STANDALONE +int main(void) +#else +int init_vesa(void) +#endif +{ + DEBUG("vesa driver running\n"); + cdi_init(); + vesa_driver_init(); + + cdi_run_drivers(); + + return 0; +} + +/** + * Initialisiert den Treiber und registriert ihn + */ +static void vesa_driver_init(void) +{ + cdi_list_t pci_devices; + struct cdi_pci_device* pci; + + memset(&vesa_driver, 0, sizeof(vesa_driver)); + cdi_video_driver_init((struct cdi_video_driver*)&vesa_driver); + + // Fill driver struct + vesa_driver.drv.drv.name = driver_name; + vesa_driver.drv.drv.type = CDI_VIDEO; + vesa_driver.drv.drv.init_device = NULL;//vesa_init_device; + vesa_driver.drv.drv.remove_device = NULL; + vesa_driver.drv.drv.destroy = vesa_driver_destroy; + + vesa_driver.drv.display_set_mode = vesa_display_set_mode; + + vesa_driver.drv.bitmap_create = vesa_bitmap_create; + vesa_driver.drv.bitmap_destroy = vesa_bitmap_destroy; + vesa_driver.drv.bitmap_set_usage_hint = vesa_bitmap_set_usage_hint; + + vesa_driver.drv.set_raster_op = vesa_set_raster_op; + vesa_driver.drv.draw_line = vesa_draw_line; + vesa_driver.drv.draw_rectangle = vesa_draw_rectangle; + vesa_driver.drv.draw_ellipse = NULL;//vesa_draw_ellipse; + vesa_driver.drv.draw_bitmap = vesa_draw_bitmap; + vesa_driver.drv.draw_bitmap_part = vesa_draw_bitmap_part; + vesa_driver.drv.draw_dot = vesa_draw_dot; + + // Suche VGA-Karten + pci_devices = cdi_list_create(); + cdi_pci_get_all_devices(pci_devices); + while ((pci = cdi_list_pop(pci_devices))) { + if (pci->class_id == 0x03 && pci->subclass_id == 0x00 && + pci->interface_id == 0x00) { + char* name = malloc(8); + snprintf(name, 8, "vesa%01d", cdi_list_size(vesa_driver.drv.drv.devices)); + struct vesa_device *dev = vesa_device_create(name, pci); + dev->dev.dev.driver = (struct cdi_driver*)&vesa_driver; + cdi_list_push(vesa_driver.drv.drv.devices, dev); + } else { + cdi_pci_device_destroy(pci); + } + } + cdi_list_destroy(pci_devices); + + // TODO FIXME Nach init_device verschieben! + struct cdi_video_vesa_info_block **vesainfo_ptr; + vesainfo_ptr = malloc(sizeof(void*)); + // Ohne VBE abbrechen + if (cdi_video_vesa_initialize(vesainfo_ptr, vesa_mode_callback) == -1) { + return; + } + + // Treiber registrieren + cdi_video_driver_register((struct cdi_video_driver*)&vesa_driver); +} + +void vesa_init_device(struct cdi_device* device) { + return; +} + +/** + * Zerstoert den Treiber + * @param driver Pointer to the driver + */ +static void vesa_driver_destroy(struct cdi_driver* driver) +{ + cdi_video_driver_destroy((struct cdi_video_driver*)driver); +} diff --git a/src/modules/cdi/vesa/vesa.h b/src/modules/cdi/vesa/vesa.h new file mode 100644 index 0000000..d6c6271 --- /dev/null +++ b/src/modules/cdi/vesa/vesa.h @@ -0,0 +1,47 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander SIol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef VESA_H +#define VESA_H + +#include + + +extern struct cdi_video_vesa_driver vesa_driver; + +struct cdi_video_vesa_driver { + struct cdi_video_driver drv; +}; + +struct vesa_device { + struct cdi_video_device dev; +}; + +struct vesa_device *vesa_device_create(char *name, struct cdi_pci_device* pci); + +#endif /* VESA_H */ \ No newline at end of file -- 1.6.0.4 From alex at tyndur.org Sat Oct 10 15:31:47 2009 From: alex at tyndur.org (Alexander Siol) Date: Sat, 10 Oct 2009 15:31:47 +0200 Subject: [tyndur-devel] [PATCH v2] + videolib In-Reply-To: <1255181508-22334-1-git-send-email-alex@tyndur.org> References: <1255181508-22334-1-git-send-email-alex@tyndur.org> Message-ID: <1255181508-22334-4-git-send-email-alex@tyndur.org> Signed-off-by: Alexander Siol --- src/modules/lib/video/bitmaps.c | 88 ++++++++++++++++++++++++++++++ src/modules/lib/video/context.c | 112 +++++++++++++++++++++++++++++++++++++++ src/modules/lib/video/drawing.c | 103 +++++++++++++++++++++++++++++++++++ src/modules/lib/video/query.c | 63 ++++++++++++++++++++++ src/modules/lib/video/video.c | 67 +++++++++++++++++++++++ 5 files changed, 433 insertions(+), 0 deletions(-) create mode 100644 src/modules/lib/video/bitmaps.c create mode 100644 src/modules/lib/video/context.c create mode 100644 src/modules/lib/video/drawing.c create mode 100644 src/modules/lib/video/query.c create mode 100644 src/modules/lib/video/video.c diff --git a/src/modules/lib/video/bitmaps.c b/src/modules/lib/video/bitmaps.c new file mode 100644 index 0000000..8295a5a --- /dev/null +++ b/src/modules/lib/video/bitmaps.c @@ -0,0 +1,88 @@ +/* + * Copyright (c) 2009 The tyndur Project. All rights reserved. + * + * This code is derived from software contributed to the tyndur Project + * by Alexander Siol. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED + * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; + * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, + * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR + * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/ + +#include