@@ -57,8 +57,115 @@ write_simh (FILE *f, struct pdp10_memory *memory)
57
57
fprintf (f , ";execute %012llo\n" , start_instruction );
58
58
}
59
59
60
+ static int
61
+ whitespace (char c )
62
+ {
63
+ switch (c )
64
+ {
65
+ case ' ' :
66
+ case '\t' :
67
+ case '\r' :
68
+ case '\n' :
69
+ return 1 ;
70
+ default :
71
+ return 0 ;
72
+ }
73
+ }
74
+
75
+ static int
76
+ whitespace_or_nul (char c )
77
+ {
78
+ return whitespace (c ) || c == 0 ;
79
+ }
80
+
81
+ static void
82
+ fatal (char * format , char * line )
83
+ {
84
+ fprintf (stderr , format , line );
85
+ exit (1 );
86
+ }
87
+
88
+ static void
89
+ deposit (char * line , struct pdp10_memory * memory )
90
+ {
91
+ char * p ;
92
+ word_t * data ;
93
+ unsigned long x , address = strtoul (line , & p , 8 );
94
+ if (!whitespace (* p ))
95
+ fatal ("Invalid DEPOSIT arguments: \"%s\"\n" , line );
96
+
97
+ while (whitespace (* p ))
98
+ p ++ ;
99
+ if (* p == 0 )
100
+ fatal ("Invalid DEPOSIT arguments: \"%s\"\n" , line );
101
+
102
+ data = malloc (sizeof (word_t ));
103
+ if (data == NULL )
104
+ {
105
+ fprintf (stderr , "Out of memory\n" );
106
+ exit (1 );
107
+ }
108
+ x = strtoul (p , & p , 8 );
109
+ if (!whitespace_or_nul (* p ))
110
+ fatal ("Invalid DEPOSIT arguments: \"%s\"\n" , line );
111
+
112
+ * data = x ;
113
+ add_memory (memory , address , 1 , data );
114
+ }
115
+
116
+ static void
117
+ start (char * line )
118
+ {
119
+ char * p ;
120
+ unsigned long address = strtoul (line , & p , 8 );
121
+ if (p == line || !whitespace_or_nul (* p ))
122
+ fatal ("Invalid GO argument: \"%s\"\n" , line );
123
+ start_instruction = JRST | address ;
124
+ }
125
+
126
+ static void
127
+ read_line (char * line , struct pdp10_memory * memory )
128
+ {
129
+ char * p = line ;
130
+ size_t n ;
131
+
132
+ while (whitespace (* p ))
133
+ p ++ ;
134
+ if (* p == 0 || * p == ';' || * p == '#' )
135
+ return ;
136
+ line = p ++ ;
137
+ while (!whitespace_or_nul (* p ))
138
+ p ++ ;
139
+ if (* p == 0 )
140
+ fatal ("SIMH command has no argument: %s\n" , line );
141
+ * p ++ = 0 ;
142
+ n = strlen (line );
143
+ if (strncasecmp (line , "deposit" , n ) == 0 )
144
+ deposit (p , memory );
145
+ else if (strncasecmp (line , "go" , n ) == 0 )
146
+ start (p );
147
+ else
148
+ fatal ("Unsupported SIMH command: %s\n" , line );
149
+ }
150
+
151
+ static void
152
+ read_simh (FILE * f , struct pdp10_memory * memory , int cpu_model )
153
+ {
154
+ static char line [100 ];
155
+ (void )cpu_model ;
156
+
157
+ fprintf (output_file , ";SIMH script\n\n" );
158
+
159
+ for (;;)
160
+ {
161
+ if (fgets (line , sizeof line , f ) == NULL )
162
+ return ;
163
+ read_line (line , memory );
164
+ }
165
+ }
166
+
60
167
struct file_format simh_file_format = {
61
168
"simh" ,
62
- NULL ,
169
+ read_simh ,
63
170
write_simh
64
171
};
0 commit comments