]> git.sur5r.net Git - cc65/commitdiff
Added tgi_load_vectorfont(). Fixed tgi_free_vectorfont().
authoruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 1 Nov 2009 22:35:22 +0000 (22:35 +0000)
committeruz <uz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Sun, 1 Nov 2009 22:35:22 +0000 (22:35 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@4421 b7a2c559-68d2-44c3-8de9-860c34a00d81

libsrc/tgi/Makefile
libsrc/tgi/tgi_free_vectorfont.s
libsrc/tgi/tgi_load_vectorfont.c [new file with mode: 0644]

index d1158a7b50c8ef12df2dc1e291b1bdc74943d575..6f7b955b30dcb5bc9ec6cabf8dd180d6c168a8a6 100644 (file)
@@ -30,7 +30,8 @@ CFLAGS        = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
 # Object files
 
 C_OBJS =        tgi_load.o              \
-                tgi_load_driver.o
+                tgi_load_driver.o       \
+                tgi_load_vectorfont.o
 
 S_OBJS =               tgi-kernel.o            \
                 tgi_bar.o               \
index c8ecdb8325582a57eb9835598ea15aa28e38e654..a7181d54fe6eb9ad7551ec6feb22e8893faf7650 100644 (file)
@@ -7,5 +7,6 @@
 ; This function is identical to free(void*)
 ;
 
-        .export _tgi_free_vectorfont := free
+        .import _free
+        .export _tgi_free_vectorfont := _free
 
diff --git a/libsrc/tgi/tgi_load_vectorfont.c b/libsrc/tgi/tgi_load_vectorfont.c
new file mode 100644 (file)
index 0000000..ad141d0
--- /dev/null
@@ -0,0 +1,131 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                           tgi_load_vectorfont.c                           */
+/*                                                                           */
+/*                  Loader module for TGI vector font files                  */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2009,      Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#include <stdlib.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+
+#include <tgi.h>
+#include <tgi/tgi-kernel.h>
+#include <tgi/tgi-vectorfont.h>
+
+
+
+/*****************************************************************************/
+/*                                   Code                                    */
+/*****************************************************************************/
+
+
+
+const tgi_vectorfont* __fastcall__ tgi_load_vectorfont (const char* name)
+/* Load a vector font into memory and return it. In case of errors, NULL is
+ * returned and an error is set, which can be retrieved using tgi_geterror.
+ * To use the font, it has to be installed using tgi_install_vectorfont.
+ */
+{
+    static const char Magic[4] = {
+        0x54, 0x43, 0x48, TGI_VF_VERSION
+    };
+
+    tgi_vectorfont_header H;
+    int                   F;
+    tgi_vectorfont*       Font = 0;
+    unsigned              V;
+    unsigned char         I;
+
+
+    /* Open the file */
+    F = open (name, O_RDONLY);
+    if (F < 0) {
+        /* Cannot open file */
+        goto LoadError;
+    }
+
+    /* Read the header */
+    if (read (F, &H, sizeof (H)) != sizeof (H)) {
+        /* Cannot read header bytes */
+        goto LoadError;
+    }
+
+    /* Check the header */
+    if (memcmp (&H, Magic, sizeof (Magic)) != 0) {
+        /* Header magic not ok */
+        goto LoadError;
+    }
+
+    /* Allocate memory for the data */
+    Font = malloc (H.size);
+    if (Font == 0) {
+        /* Out of memory */
+        goto LoadError;
+    }
+
+    /* Read the whole font file into the buffer */
+    if (read (F, Font, H.size) != H.size) {
+        /* Problem reading font data */
+        free (Font);
+        goto LoadError;
+    }
+
+    /* Close the file */
+    close (F);
+
+    /* Fix the offset pointers. When loaded, they contain numeric offsets
+     * into the VectorOps, with the start of the VectorOps at offset zero.
+     * We will add a pointer to the VectorOps to make them actual pointers
+     * that may be used independently from anything else.
+     */
+    V = (unsigned) &Font->vec_ops;
+    for (I = 0; I < TGI_VF_CCOUNT; ++I) {
+        Font->chars[I] += V;
+    }
+
+    /* Return the vector font loaded */
+    return Font;
+
+LoadError:
+    /* Some sort of load problem. If the file is still open, be sure to
+     * close it
+     */
+    if (F >= 0) {
+        close (F);
+    }
+    tgi_error = TGI_ERR_CANNOT_LOAD;
+    return 0;
+}
+
+
+