summaryrefslogtreecommitdiffstats
path: root/master/timex-pseudo-instructions.patch
blob: 0a64f5725d4e3db078c2d328406fd0b28659562c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
diff --git a/code6805.c b/code6805.c
index b89161e..9630e3b 100644
--- a/code6805.c
+++ b/code6805.c
@@ -393,6 +393,8 @@ BEGIN
 
    if (DecodePseudo()) return;
 
+   if (DecodeTimexPseudo(True)) return;
+
    if (DecodeMotoPseudo(True)) return;
 
    /* Anweisungen ohne Argument */
diff --git a/codepseudo.c b/codepseudo.c
index 8d474de..817cc93 100644
--- a/codepseudo.c
+++ b/codepseudo.c
@@ -639,6 +639,68 @@ BEGIN
     END
 END
 
+	static void DecodeWRD(Word Index)
+BEGIN
+   int z;
+   Boolean OK;
+   TempResult t;
+   LongInt Rep,z2;
+
+   if (ArgCnt==0) WrError(1110);
+   else
+    BEGIN
+     z=1; OK=True;
+     do
+      BEGIN
+       KillBlanks(ArgStr[z]);
+       OK=CutRep(ArgStr[z],&Rep);
+       if (OK)
+        BEGIN
+         EvalExpression(ArgStr[z],&t);
+         switch (t.Typ)
+          BEGIN
+           case TempInt:
+            if (NOT RangeCheck(t.Contents.Int,Int16))
+             BEGIN
+              WrError(1320); OK=False;
+             END
+            else if (CodeLen+(2*Rep)>MaxCodeLen)
+             BEGIN
+              WrError(1920); OK=False;
+             END
+            else
+             for (z2=0; z2<Rep; z2++)
+              BEGIN
+               if (M16Turn)
+                BEGIN
+                 BAsmCode[CodeLen++]=Hi(t.Contents.Int);
+                 BAsmCode[CodeLen++]=Lo(t.Contents.Int);
+                END
+               else
+                BEGIN
+                 BAsmCode[CodeLen++]=Lo(t.Contents.Int);
+                 BAsmCode[CodeLen++]=Hi(t.Contents.Int);
+                END
+             END
+            break;
+           case TempFloat:
+            WrError(1135); OK=False;
+            break;
+           case TempString:
+            WrError(1135); OK=False;
+            break;
+           default:
+            OK=False; 
+            break;
+          END
+        END  
+       z++;
+      END
+     while ((z<=ArgCnt) AND (OK));
+     if (NOT OK) CodeLen=0;
+    END
+END
+
 	static void DecodeADR(Word Index)
 BEGIN
    int z;
@@ -761,6 +823,375 @@ BEGIN
    return LookupInstTable(InstTable,OpPart);
 END
 
+
+static unsigned char timex_translate(unsigned char c)
+{
+  switch (c)
+    {
+    case '0':
+    case '1':
+    case '2':
+    case '3':
+    case '4':
+    case '5':
+    case '6':
+    case '7':
+    case '8':
+    case '9':
+      return c-'0';
+    case 'a':
+    case 'A':
+    case 'b':
+    case 'B':
+    case 'c':
+    case 'C':
+    case 'd':
+    case 'D':
+    case 'e':
+    case 'E':
+    case 'f':
+    case 'F':
+    case 'g':
+    case 'G':
+    case 'h':
+    case 'H':
+    case 'i':
+    case 'I':
+    case 'j':
+    case 'J':
+    case 'k':
+    case 'K':
+    case 'l':
+    case 'L':
+    case 'm':
+    case 'M':
+    case 'n':
+    case 'N':
+    case 'o':
+    case 'O':
+    case 'p':
+    case 'P':
+    case 'q':
+    case 'Q':
+    case 'r':
+    case 'R':
+    case 's':
+    case 'S':
+    case 't':
+    case 'T':
+    case 'u':
+    case 'U':
+    case 'v':
+    case 'V':
+    case 'w':
+    case 'W':
+    case 'x':
+    case 'X':
+    case 'y':
+    case 'Y':
+    case 'z':
+    case 'Z':
+	c &= ~0x20;
+	return 0xa + c - 'A';
+    case ' ':
+      return 0x24;
+    case '!':
+      return 0x25;
+    case '"':
+      return 0x26;
+    case '#':
+      return 0x27;
+    case '>':
+      return 0x28;
+    case '%':
+      return 0x29;
+    case '&':
+      return 0x2a;
+    case '\'':
+      return 0x2b;
+    case '(':
+      return 0x2c;
+    case ')':
+      return 0x2d;
+    case '*':
+      return 0x2e;
+    case '+':
+      return 0x2f;
+    case ',':
+      return 0x30;
+    case '-':
+      return 0x31;
+    case '.':
+      return 0x32;
+    case '/':
+      return 0x33;
+    case ':':
+      return 0x34;
+    case '\\':
+      return 0x35;
+    case '=':
+      return 0x37;
+    case '?':
+      return 0x39;
+    case '_':
+      return 0x3a;
+    default:
+      WrError(1320); 
+      CodeLen=0;
+      fprintf (stderr, "Cannot encode %c in 'timex' encoding\n", c);
+    }
+}
+
+
+static void timex_translate_buf(unsigned char *c, size_t l)
+{
+  for (;l;c++,l--) 
+    *c = timex_translate(*c);
+}
+
+
+	static void DecodeTIMEX(Word Index)
+BEGIN
+   int z;
+   Boolean OK;
+   TempResult t;
+   LongInt Rep,z2;
+
+   if (ArgCnt==0) WrError(1110);
+   else
+    BEGIN
+     z=1; OK=True;
+     do
+      BEGIN
+       KillBlanks(ArgStr[z]);
+       OK=CutRep(ArgStr[z],&Rep);
+       if (OK)
+        BEGIN
+         EvalExpression(ArgStr[z],&t);
+         switch (t.Typ)
+          BEGIN
+           case TempInt:
+            if (NOT RangeCheck(t.Contents.Int,Int8))
+             BEGIN
+              WrError(1320); OK=False;
+             END
+            else if (CodeLen+Rep>MaxCodeLen)
+             BEGIN
+              WrError(1920); OK=False;
+             END
+            else
+             BEGIN
+              memset(BAsmCode+CodeLen,t.Contents.Int,Rep);
+	      timex_translate_buf(BAsmCode+CodeLen,Rep);
+              CodeLen+=Rep;
+             END
+            break;
+           case TempFloat:
+            WrError(1135); OK=False;
+            break;
+           case TempString:
+            TranslateString(t.Contents.Ascii);
+            if (CodeLen+Rep*strlen(t.Contents.Ascii)>MaxCodeLen)
+             BEGIN
+              WrError(1920); OK=False;
+             END
+            else for (z2=0; z2<Rep; z2++)
+             BEGIN
+              memcpy(BAsmCode+CodeLen,t.Contents.Ascii,strlen(t.Contents.Ascii));
+	      timex_translate_buf(BAsmCode+CodeLen,strlen(t.Contents.Ascii));
+              CodeLen+=strlen(t.Contents.Ascii);
+             END
+            break;
+           default:
+            OK=False; 
+            break;
+          END
+        END  
+       z++;
+      END
+     while ((z<=ArgCnt) AND (OK));
+     if (NOT OK) CodeLen=0;
+    END
+END
+
+
+static unsigned char timex6_translate(unsigned char c)
+{
+  switch(c) {
+  case '0':
+  case '1':
+  case '2':
+  case '3':
+  case '4':
+  case '5':
+  case '6':
+  case '7':
+  case '8':
+  case '9':
+    return c - '0';  
+
+
+
+  case 'a':
+  case 'A':
+  case 'b':
+  case 'B':
+  case 'c':
+  case 'C':
+  case 'd':
+  case 'D':
+  case 'e':
+  case 'E':
+  case 'f':
+  case 'F':
+  case 'g':
+  case 'G':
+  case 'h':
+  case 'H':
+    c &= ~0x20;
+    return 0xa + c - 'A';
+
+  case 'i':
+  case 'I':
+    return 0x1;
+  case ':':
+    return 0x12;
+  case 'l':
+  case 'L':
+  case 'm':
+  case 'M':
+  case 'n':
+  case 'N':
+    c &= ~0x20;
+    return 0x13 + c - 'L';
+  case 'o':
+  case 'O':
+    return 0x0;
+  case 'p':
+  case 'P':
+    return 0x16;
+  case 'r':
+    return 0x1c;
+  case 'R':
+    return 0x17;
+  case 's':
+  case 'S':
+    return 0x5;
+  case 't':
+  case 'T':
+  case 'u':
+  case 'U':
+    return 0x18 + c - 'T';
+  case 'w':
+  case 'W':
+    return 0x1a;
+  case 'y':
+  case 'Y':
+    return 0x1b;
+  case ' ':
+    return 0x1d;
+  case '-':
+    return 0x1e;
+  case '+':
+    return 0x1f;
+  default:
+    WrError(1320); 
+    CodeLen=0;
+    fprintf (stderr, "Cannot encode %c in 'timex6' encoding\n", c);
+  }
+}
+
+
+static void timex6_translate_buf(unsigned char *c, size_t l)
+{
+  for (;l;c++,l--) 
+    *c = timex6_translate(*c);
+}
+
+
+	static void DecodeTIMEX6(Word Index)
+BEGIN
+   int z;
+   Boolean OK;
+   TempResult t;
+   LongInt Rep,z2;
+
+   if (ArgCnt==0) WrError(1110);
+   else
+    BEGIN
+     z=1; OK=True;
+     do
+      BEGIN
+       KillBlanks(ArgStr[z]);
+       OK=CutRep(ArgStr[z],&Rep);
+       if (OK)
+        BEGIN
+         EvalExpression(ArgStr[z],&t);
+         switch (t.Typ)
+          BEGIN
+           case TempInt:
+            if (NOT RangeCheck(t.Contents.Int,Int8))
+             BEGIN
+              WrError(1320); OK=False;
+             END
+            else if (CodeLen+Rep>MaxCodeLen)
+             BEGIN
+              WrError(1920); OK=False;
+             END
+            else
+             BEGIN
+              memset(BAsmCode+CodeLen,t.Contents.Int,Rep);
+	      timex6_translate_buf(BAsmCode+CodeLen,Rep);
+              CodeLen+=Rep;
+             END
+            break;
+           case TempFloat:
+            WrError(1135); OK=False;
+            break;
+           case TempString:
+            TranslateString(t.Contents.Ascii);
+            if (CodeLen+Rep*strlen(t.Contents.Ascii)>MaxCodeLen)
+             BEGIN
+              WrError(1920); OK=False;
+             END
+            else for (z2=0; z2<Rep; z2++)
+             BEGIN
+              memcpy(BAsmCode+CodeLen,t.Contents.Ascii,strlen(t.Contents.Ascii));
+	      timex6_translate_buf(BAsmCode+CodeLen,strlen(t.Contents.Ascii));
+              CodeLen+=strlen(t.Contents.Ascii);
+             END
+            break;
+           default:
+            OK=False; 
+            break;
+          END
+        END  
+       z++;
+      END
+     while ((z<=ArgCnt) AND (OK));
+     if (NOT OK) CodeLen=0;
+    END
+END
+
+
+	Boolean DecodeTimexPseudo(Boolean Turn)
+BEGIN
+   static PInstTable InstTable=Nil;
+
+   if (InstTable==Nil)
+    BEGIN
+     InstTable=CreateInstTable(17);
+     AddInstTable(InstTable,"DB",0,DecodeBYT);
+     AddInstTable(InstTable,"DW",0,DecodeWRD);
+     AddInstTable(InstTable,"TIMEX",0,DecodeTIMEX);
+     AddInstTable(InstTable,"TIMEX6",0,DecodeTIMEX6);
+    END
+
+   M16Turn=Turn;
+   return LookupInstTable(InstTable,OpPart);
+END
+
+
 	static void DigIns(char Ch, Byte Pos, Word *w)
 BEGIN
    Byte wpos=Pos>>2,bpos=(Pos&3)*4;
diff --git a/codepseudo.h b/codepseudo.h
index 0ffbfe8..fc164a7 100644
--- a/codepseudo.h
+++ b/codepseudo.h
@@ -24,6 +24,8 @@ extern void ConvertDec(Double F, Word *w);
 
 extern Boolean DecodeIntelPseudo(Boolean Turn);
 
+extern Boolean DecodeTimexPseudo(Boolean Turn);
+
 extern Boolean DecodeMotoPseudo(Boolean Turn);
 
 extern void AddMoto16PseudoONOFF(void);