]> git.sur5r.net Git - cc65/blob - src/sim65/chips/stdio.c
New module strstack
[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-2003 Ullrich von Bassewitz                                       */
10 /*               Römerstrasse 52                                             */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
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 static int InitChip (const struct SimData* Data);
55 /* Initialize the chip, return an error code */
56
57 static void* CreateInstance (unsigned Addr, unsigned Range, void* CfgInfo);
58 /* Create a new chip instance */
59
60 static void DestroyInstance (void* Data);
61 /* Destroy a chip instance */
62
63 static void Write (void* Data, unsigned Offs, unsigned char Val);
64 /* Write user data */
65
66 static unsigned char Read (void* Data, unsigned Offs);
67 /* Read user data */
68
69
70
71 /*****************************************************************************/
72 /*                                     Data                                  */
73 /*****************************************************************************/
74
75
76
77 /* Control data passed to the main program */
78 static const struct ChipData CData[1] = {
79     {
80         "STDIO",                /* Name of the chip */
81         CHIPDATA_TYPE_CHIP,     /* Type of the chip */
82         CHIPDATA_VER_MAJOR,     /* Version information */
83         CHIPDATA_VER_MINOR,
84
85         /* -- Exported functions -- */
86         InitChip,
87         CreateInstance,
88         DestroyInstance,
89         Write,
90         Write,
91         Read,
92         Read
93     }
94 };
95
96 /* The SimData pointer we get when InitChip is called */
97 static const SimData* Sim;
98
99
100
101 /*****************************************************************************/
102 /*                               Exported function                           */
103 /*****************************************************************************/
104
105
106
107 int GetChipData (const ChipData** Data, unsigned* Count)
108 {
109     /* Pass the control structure to the caller */
110     *Data = CData;
111     *Count = sizeof (CData) / sizeof (CData[0]);
112
113     /* Call was successful */
114     return 0;
115 }
116
117
118
119 /*****************************************************************************/
120 /*                                     Code                                  */
121 /*****************************************************************************/
122
123
124
125 static int InitChip (const struct SimData* Data)
126 /* Initialize the chip, return an error code */
127 {
128     /* Remember the pointer */
129     Sim = Data;
130
131     /* Always successful */
132     return 0;
133 }
134
135
136
137 static void* CreateInstance (unsigned Addr, unsigned Range, void* CfgInfo)
138 /* Initialize a new chip instance */
139 {
140     /* We don't need any instance data */
141     return 0;
142 }
143
144
145
146 static void DestroyInstance (void* Data)
147 /* Destroy a chip instance */
148 {
149 }
150
151
152
153 static void Write (void* Data attribute ((unused)),
154                    unsigned Offs attribute ((unused)),
155                    unsigned char Val)
156 /* Write user data */
157 {
158     putchar (Val);
159 }
160
161
162
163 static unsigned char Read (void* Data attribute ((unused)),
164                            unsigned Offs attribute ((unused)))
165 /* Read user data */
166 {
167     /* Read a character and return the value */
168     return getchar ();
169 }
170
171
172
173