]> git.sur5r.net Git - cc65/blob - src/sim65/chips/stdio.c
New plugin stdio
[cc65] / src / sim65 / chips / stdio.c
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                  stdio.c                                  */
4 /*                                                                           */
5 /*                 STDIO plugin for the sim65 6502 simulator                 */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 2002      Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@musoftware.de                                            */
13 /*                                                                           */
14 /*                                                                           */
15 /* This software is provided 'as-is', without any expressed or implied       */
16 /* warranty.  In no event will the authors be held liable for any damages    */
17 /* arising from the use of this software.                                    */
18 /*                                                                           */
19 /* Permission is granted to anyone to use this software for any purpose,     */
20 /* including commercial applications, and to alter it and redistribute it    */
21 /* freely, subject to the following restrictions:                            */
22 /*                                                                           */
23 /* 1. The origin of this software must not be misrepresented; you must not   */
24 /*    claim that you wrote the original software. If you use this software   */
25 /*    in a product, an acknowledgment in the product documentation would be  */
26 /*    appreciated but is not required.                                       */
27 /* 2. Altered source versions must be plainly marked as such, and must not   */
28 /*    be misrepresented as being the original software.                      */
29 /* 3. This notice may not be removed or altered from any source              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35                    
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 /* common */
41 #include "attrib.h"
42
43 /* sim65 */
44 #include "chipif.h"
45
46
47
48 /*****************************************************************************/
49 /*                                   Forwards                                */
50 /*****************************************************************************/
51
52
53
54 int InitChip (const struct SimData* Data);
55 /* Initialize the chip, return an error code */
56
57 static void* InitInstance (unsigned Addr, unsigned Range);
58 /* Initialize a new chip instance */
59
60 static void Write (void* Data, unsigned Addr, unsigned char Val);
61 /* Write user data */
62
63 static unsigned char Read (void* Data, unsigned Addr);
64 /* Read user data */
65
66
67
68 /*****************************************************************************/
69 /*                                     Data                                  */
70 /*****************************************************************************/
71
72
73
74 /* Control data passed to the main program */
75 static const struct ChipData RAMData[1] = {
76     {
77         "STDIO",                /* Name of the chip */
78         CHIPDATA_VER_MAJOR,     /* Version information */
79         CHIPDATA_VER_MINOR,
80
81         /* -- Exported functions -- */
82         InitChip,
83         InitInstance,
84         Write,
85         Write,
86         Read,
87         Read
88     }
89 };
90
91 /* The SimData pointer we get when InitChip is called */
92 static const SimData* Sim;
93
94
95
96 /*****************************************************************************/
97 /*                               Exported function                           */
98 /*****************************************************************************/
99
100
101
102 int GetChipData (const ChipData** Data, unsigned* Count)
103 {
104     /* Pass the control structure to the caller */
105     *Data = RAMData;
106     *Count = sizeof (Data) / sizeof (Data[0]);
107
108     /* Call was successful */
109     return 0;
110 }
111
112
113
114 /*****************************************************************************/
115 /*                                     Code                                  */
116 /*****************************************************************************/
117
118
119
120 int InitChip (const struct SimData* Data)
121 /* Initialize the chip, return an error code */
122 {
123     /* Remember the pointer */
124     Sim = Data;
125
126     /* Always successful */
127     return 0;
128 }
129
130
131
132 static void* InitInstance (unsigned Addr attribute ((unused)),
133                            unsigned Range attribute ((unused)))
134 /* Initialize a new chip instance */
135 {
136     /* We don't need any instance data */
137     return 0;
138 }
139
140
141
142 static void Write (void* Data attribute ((unused)),
143                    unsigned Addr attribute ((unused)),
144                    unsigned char Val)
145 /* Write user data */
146 {
147     putchar (Val);
148 }
149
150
151
152 static unsigned char Read (void* Data attribute ((unused)),
153                            unsigned Addr attribute ((unused)))
154 /* Read user data */
155 {
156     /* Read a character and return the value */
157     return getchar ();
158 }
159
160
161