]> git.sur5r.net Git - cc65/blob - libsrc/tgi/tgi_load.c
Added strftime
[cc65] / libsrc / tgi / tgi_load.c
1 /*
2  * TEST VERSION - CURRENTLY C64 SPECIFIC!!!
3  */
4
5
6
7 #include <string.h>
8 #include <cbm.h>
9 #include <modload.h>
10 #include <tgi.h>
11 #include <tgi/tgi-kernel.h>
12
13
14
15 static unsigned char ReadInputBlock (struct mod_ctrl* C, void* Buf, unsigned Size)
16 {
17     return (cbm_read (1, Buf, Size) != Size);
18 }
19
20
21
22 void __fastcall__ tgi_load (unsigned char mode)
23 /* Install the matching driver for the given mode. Will just load the driver
24  * and check if loading was successul. Will not switch to gaphics mode.
25  */
26 {
27     const char* name = tgi_map_mode (mode);
28     if (name == 0) {
29         /* No driver for this mode */
30         tgi_error = TGI_ERR_NO_DRIVER;
31     } else {
32         /* Laod the driver */
33         tgi_load_driver (name);
34     }
35 }
36
37
38
39 void __fastcall__ tgi_load_driver (const char* name)
40 /* Install the given driver. This function is identical to tgi_load with the
41  * only difference that the name of the driver is specified explicitly. You
42  * should NOT use this function in most cases, use tgi_load() instead.
43  */
44 {
45     static const unsigned char marker[4] = { 0x74, 0x67, 0x69, 0x00 };
46
47     static struct mod_ctrl ctrl = {
48         ReadInputBlock           /* read_block */
49     };
50     unsigned Res;
51
52     /* Check if we do already have a driver loaded. If so, remove it. */
53     if (tgi_drv != 0) {
54         tgi_unload ();
55     }
56
57     /* Now open the file */
58     if (cbm_open (1, 8, 2, name) != 0) {
59         tgi_error = TGI_ERR_CANNOT_LOAD;
60         return;
61     }
62
63     /* Load the module */
64     Res = mod_load (&ctrl);
65     cbm_close (1);
66
67     /* Check the return code */
68     if (Res == MLOAD_OK) {
69
70         /* Get a pointer to the loaded driver */
71         tgi_drv = (tgi_drv_header*) ctrl.module;
72
73         /* Check the header */
74         if (memcmp (tgi_drv, marker, sizeof (marker)) != 0) {
75             /* Invalid driver */
76             mod_free (tgi_drv);
77             tgi_drv = 0;
78             tgi_error = TGI_ERR_INV_DRIVER;
79         } else {
80             /* Driver is ok do setup */
81             tgi_setup ();
82         }
83
84     } else {
85
86         /* Error loading the driver */
87         tgi_error = TGI_ERR_CANNOT_LOAD;
88
89     }
90 }