-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIVOnano.java
1818 lines (1527 loc) · 62.5 KB
/
IVOnano.java
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
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.TextField;
import javax.microedition.midlet.MIDlet;
import javax.microedition.rms.*; // really needed?
import java.io.*;
import javax.microedition.io.*;
public class IVOnano extends MIDlet implements CommandListener {
private Display display;
private Form form = new Form("1V0");
private Command exit = new Command("EXIT", Command.EXIT, 1);
private Command submit = new Command("ENTER", Command.SCREEN, 1);
private Command reentry = new Command("INIT", Command.SCREEN, 1);
private Command runcode = new Command("RUN", Command.SCREEN, 1);
private Command setvalue = new Command("SET", Command.SCREEN, 1);
private Command previouscommand;
private TextField cmdfield = new TextField("CMDA:", "0", 4, TextField.ANY); // 3 OR 4
private TextField oprfield = new TextField("OPER:", "0", 3, TextField.NUMERIC);
private TextField d1_field = new TextField("ADR1:", "1", 4, TextField.NUMERIC);
private TextField d2_field = new TextField("ADR2:", "1", 4, TextField.NUMERIC);
private TextField rl_field = new TextField("NEW RUNLIMIT:", "32767", 5, TextField.NUMERIC);
private TextField flofield = new TextField("NUM:", "0", 11, TextField.ANY); // Maybe make the text "0000" on fixedpolong!
private TextField longfield = new TextField("INT:", "0", 11, TextField.ANY);
private String ephemeral = ""; // I CAN DECLARE HERE ANYTHING AND USE THE STUFF BELOW LIKE GOSUBS
private String rlstring = "";
private String trace1s = "";
private static long sqrt(long num) {
num = absvalu(num);
long guess = num / 4;
long maxrun = 1;
long TOLERN = 4;
long PRECIS = 10000;
while(absvalu((guess * guess / PRECIS) - num) >= TOLERN) {
guess = (num * PRECIS/guess + guess) / 2;
maxrun++;
if (maxrun > 200) {
break;
}
}
return guess;
}
private static long cbrt(long num) {
long guess = num / 2;
long maxrun = 1;
long TOLERN = 4;
long PRECIS = 10000;
while(absvalu((guess * guess * guess / (PRECIS * PRECIS)) - num) >= TOLERN) {
guess = (num * PRECIS/guess + guess) / 2;
maxrun++;
if (maxrun > 200) {
break;
}
}
return guess;
}
private static long pow(long base, long expo) {
long ff = 1;
long ij;
long PRECIS = 10000;
if (expo > 1) {
for (ij = 1; ij <= expo; ij++) {
ff = ff * base / PRECIS;
}
} else if (expo < 1) {
expo = -expo;
for (ij = 1; ij <= expo; ij++) {
ff = ff * PRECIS / base;
}
} else {
ff = 1;
}
return ff;
}
private static long absvalu(long x) {
if (x < 0) {
return -x;
} else {
return x;
}
}
/*
private static long rund(long x) {
long absv;
long rst;
long PRECIS = 10000;
if (x < 0) {
absv = -x;
} else {
absv = x;
}
rst = absv % PRECIS;
if (rst >= (PRECIS / 2)) {
absv = absv - rst + PRECIS;
} else {
absv = absv - rst;
}
if (x < 0) {
return -absv;
} else {
return absv;
}
}
*/
private int entryflag = 0;
private int PRECISION = 10000; // How many "decimal places" are counted.
/* REMEMBER IT INSIDE YOUR CUSTOM FUNCTIONS, TOO */
private int DATAMEM = 1001; // 8191 is the addressable space
private int EXECMEM = 1001; // ANYTHING YOU LIKE, BUT OTHERWISE YOU WAIT TOO LONG FOR THE END IF YOU DID NOT SPECIFY A JUMP BACK
// 2501, 1001
private short tracer = 0;
private int instr = 0;
/* instruction format: */
/* operator, data address 1 (=result), data address 2 */
/* every operator is at a command address. */
private int cmdadr = 0;
private int opr = 0;
private int datadr1 = 0;
private int datadr2 = 0;
private int pc = 0;
private int h = 0; /* beware: h & k are used for "transcendental" instructions ... */
private int i = 0; /* i & j are auxiliary looping variables */
private int j = 0;
private int k = 0; /* ... so ZERO THEM OUT after non-transcendental usage */
private int xx;
private int yy;
private int zz;
private int[] instruction = new int[(int) EXECMEM];
private int runlimit = 0;
/* If this is 0, run unlimited, else break when it becomes 1. */
/* This is a sort of "safety", to prevent infinite looping. */
private long f = 0; /* f & g are auxiliary longing polong temporary storage */
private long g = 0;
private int TOLERANCE = 4; // not "1", this is stupid! Little differences should be accounted for!
/* ADJUST THE TOLERANCE ALSO INSIDE THE FUNCTIONS BELOW */
private long[] datum = new long[(int) DATAMEM];
public IVOnano() {
// Better do stuff BEFORE showing controls.
for (i=0; i<EXECMEM; i++) {
instruction[(int) (i)] = 0;
}
for (i=0; i<DATAMEM; i++) {
datum[(int) (i)] = 0;
}
runlimit = 5 * EXECMEM;
display = Display.getDisplay(this);
form.append("WELCOME TO 1V0: 0000PRECISION -1show_instructions -2show_data -4enter_data 0NOOP 1JUMP 2IADR 5SADR 6SVAL 7IAAS 8IVAS 9PLUS 10MINS 11MULS 12DIVS 13POXY 17AMNT 19PCNT 22COPY 23FRIS 26CORS 28SUMR 30IXTH 32SQRT 34CBRT 46MSTD 53PLUR 54MINR 55MULR 56DIVR 57PLUN 58MINN 59MULN 60DIVN");
form.addCommand(exit);
form.addCommand(reentry);
form.setCommandListener(this);
}
public void startApp() {
display.setCurrent(form);
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command command, Displayable displayable) {
if (command == submit) {
previouscommand = command;
// TESTME2 IS MUTABLE HERE AND "REMEMBERS" BEING CHANGED!
// ephemeral = cmdfield.getString() + oprfield.getString() + d1_field.getString() + d2_field.getString();
ephemeral = cmdfield.getString(); // Turn the field strings longo numbers.
cmdadr = java.lang.Integer.parseInt(ephemeral);
ephemeral = oprfield.getString();
opr = java.lang.Integer.parseInt(ephemeral);
ephemeral = d1_field.getString();
datadr1 = java.lang.Integer.parseInt(ephemeral);
ephemeral = d2_field.getString();
datadr2 = java.lang.Integer.parseInt(ephemeral);
form.removeCommand(submit); // cycle the available commands
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); } // CLS at first safe place
if (cmdadr > 0) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); } // CLS at first safe place
// THIS WORKS:
ephemeral = Long.toString(cmdadr) + " " + Long.toString(opr) + " " + Long.toString(datadr1) + " " + Long.toString(datadr2);
form.append(ephemeral);
if ((datadr1 >= DATAMEM) || (datadr2 >= DATAMEM) ||
(datadr1 < 0) || (datadr1 < 0) || (cmdadr >= EXECMEM)) {
form.append(" CORRECTING RANGE. DATA 0 ... " + (DATAMEM - 1) + ", COMMANDS 0 ... " + (EXECMEM - 1));
}
/* only positive data addresses - and 0 - are allowed: */
datadr1 = (int) absvalu(datadr1);
datadr2 = (int) absvalu(datadr2);
/* force everything to be within range: */
if (cmdadr >= EXECMEM) {
cmdadr = EXECMEM - 1;
}
if (datadr1 >= DATAMEM) {
datadr1 = DATAMEM - 1;
}
if (datadr2 >= DATAMEM) {
datadr2 = DATAMEM - 1;
}
/* Having read the instruction, compose it and save it. */
xx = opr & 63;
yy = datadr1 & 8191;
zz = datadr2 & 8191;
instr = (xx << 26) | (yy << 13) | zz;
instruction[(int) (cmdadr)] = instr;
ephemeral = " ";
ephemeral = ephemeral + cmdadr + ":" + opr;
ephemeral = ephemeral + ":";
ephemeral = ephemeral + datadr1 + ">" + datum[(int) (datadr1)];
if ((datum[(int) (datadr1)] > -1 * DATAMEM) && (datum[(int) (datadr1)] < DATAMEM)) {
j = (int) absvalu((long)(datum[(int) (datadr1)]));
ephemeral = ephemeral + ">" + datum[(int) (j)];
}
ephemeral = ephemeral + ":";
ephemeral = ephemeral + datadr2 + ">" + datum[(int) (datadr2)];
if ((datum[(int) (datadr2)] > -1 * DATAMEM) && (datum[(int) (datadr2)] < DATAMEM)) {
j = (int) absvalu((long)(datum[(int) (datadr2)]));
ephemeral = ephemeral + ">" + datum[(int) (j)];
}
ephemeral = ephemeral + ":";
ephemeral = ephemeral + "DEC:" + instr;
form.append(ephemeral);
form.addCommand(reentry); // submit -> reentry
form.setCommandListener(this);
} else if (cmdadr == 0) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
// THIS WORKS:
ephemeral = Long.toString(cmdadr) + " " + Long.toString(opr) + " " + Long.toString(datadr1) + " " + Long.toString(datadr2);
form.append(ephemeral);
if ((datadr1 >= DATAMEM) || (datadr2 >= DATAMEM) ||
(datadr1 < 0) || (datadr1 < 0) || (cmdadr >= EXECMEM)) {
form.append(" CORRECTING RANGE. DATA 0 ... " + (DATAMEM - 1) + ", COMMANDS 0 ... " + (EXECMEM - 1));
}
/* only positive data addresses - and 0 - are allowed: */
datadr1 = (int) absvalu(datadr1);
datadr2 = (int) absvalu(datadr2);
/* force everything to be within range: */
if (cmdadr >= EXECMEM) {
cmdadr = EXECMEM - 1;
}
if (datadr1 >= DATAMEM) {
datadr1 = DATAMEM - 1;
}
if (datadr2 >= DATAMEM) {
datadr2 = DATAMEM - 1;
}
/* Having read the instruction, compose it and save it. */
xx = opr & 63;
yy = datadr1 & 8191;
zz = datadr2 & 8191;
instr = (xx << 26) | (yy << 13) | zz;
cmdadr = 0;
instruction[(int) (cmdadr)] = instr;
ephemeral = " ";
ephemeral = ephemeral + cmdadr + ":" + opr;
ephemeral = ephemeral + ":";
ephemeral = ephemeral + datadr1 + ">" + datum[(int) (datadr1)];
if ((datum[(int) (datadr1)] > -1 * DATAMEM) && (datum[(int) (datadr1)] < DATAMEM)) {
j = (int) absvalu((long)(datum[(int) (datadr1)]));
ephemeral = ephemeral + ">" + datum[(int) (j)];
}
ephemeral = ephemeral + ":";
ephemeral = ephemeral + datadr2 + ">" + datum[(int) (datadr2)];
if ((datum[(int) (datadr2)] > -1 * DATAMEM) && (datum[(int) (datadr2)] < DATAMEM)) {
j = (int) absvalu((long)(datum[(int) (datadr2)]));
ephemeral = ephemeral + ">" + datum[(int) (j)];
}
ephemeral = ephemeral + ":";
ephemeral = ephemeral + "DEC:" + instr;
form.append(ephemeral);
form.addCommand(runcode); // GO: submit -> runcode"SUBMIT TO RUN CODE EXIT TO CANCEL"
form.setCommandListener(this);
form.append(" ENTER TO RUN, EXIT TO ABORT");
} else if (cmdadr == -1) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
form.append(d1_field);
form.append(d2_field);
form.append(" LIST INSTRUCTION RANGE");
form.addCommand(setvalue);
form.setCommandListener(this);
} else if (cmdadr == -2) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
form.append(d1_field);
form.append(d2_field);
form.append(" LIST DATA RANGE");
form.addCommand(setvalue);
form.setCommandListener(this);
} else if (cmdadr == -3) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
form.append(d1_field);
form.append(" ENTER INSTRUCTIONS FROM ADDRESS UP");
form.addCommand(setvalue);
} else if (cmdadr == -4) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
form.append(d1_field);
form.append(d2_field);
form.append(" ENTER NUMBERS IN DATA RANGE");
form.addCommand(setvalue);
form.setCommandListener(this);
} else if (cmdadr == -5) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
form.append(d1_field);
form.append(d2_field);
form.append(" CLEAR INSTRUCTION RANGE");
form.addCommand(setvalue);
form.setCommandListener(this);
} else if (cmdadr == -6) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
form.append(d1_field);
form.append(d2_field);
form.append(" CLEAR DATA RANGE");
form.addCommand(setvalue);
form.setCommandListener(this);
} else if (cmdadr == -7) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
form.addCommand(reentry);
form.setCommandListener(this);
form.append(" TRACE ON");
tracer = 1;
} else if (cmdadr == -8) {
form.addCommand(reentry);
form.setCommandListener(this);
form.append(" TRACE OFF");
tracer = 0;
} else if (cmdadr == -9) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
form.append(rl_field);
form.addCommand(setvalue);
form.setCommandListener(this);
} else if (cmdadr == -10) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
form.addCommand(reentry); // EJECT: -> reentry
form.setCommandListener(this);
form.append(" EXIT FROM INIT MENU");
} else {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
form.addCommand(reentry); // EJECT: -> reentry
form.setCommandListener(this);
form.append(" COMMAND NOT AVAILABLE");
}
} else if (command == reentry) {
previouscommand = command;
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); } // CLS at first safe place
form.removeCommand(reentry); // cycle the available commands
form.removeCommand(runcode); // cycle the available commands
// Better do stuff BEFORE showing controls.
pc = 0; // safety: nuke the program counter and the immediate instruction
instruction[(int) (0)] = 0;
form.setCommandListener(this);
form.addCommand(submit); // reentry -> submit
form.append(cmdfield); // REDRAW EVERYTHING
form.append(oprfield);
form.append(d1_field);
form.append(d2_field);
form.setCommandListener(this);
cmdfield.setString("0");
oprfield.setString("0");
d1_field.setString("1");
d2_field.setString("1");
} else if (command == setvalue) {
previouscommand = setvalue;
form.removeCommand(setvalue);
if (entryflag == -3) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
ephemeral = longfield.getString();
instr = java.lang.Integer.parseInt(ephemeral);
if ((instr == 67108863) || (datadr1 == EXECMEM)) { /* eject */
entryflag = 0;
form.addCommand(reentry);
form.setCommandListener(this);
form.append(" INSTRUCTION ENTRY DONE");
cmdadr = 0;
opr = 0;
datadr1 = 0;
datadr2 = 0;
} else {
instruction[(int) (datadr1)] = instr;
form.append(longfield);
longfield.setString("0");
form.addCommand(setvalue);
form.setCommandListener(this);
form.append(" ADDRESS: " + datadr1 + ", OPERATION:" + instr + ", ENTER NEXT OPERATION OR 67108863");
datadr1++;
}
} else if (entryflag == -4) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
ephemeral = flofield.getString();
f = java.lang.Long.parseLong(ephemeral);
datum[(int) (datadr1)] = f;
datadr1++;
if (datadr1 > datadr2) {
entryflag = 0;
form.addCommand(reentry);
form.setCommandListener(this);
form.append(" ADDRESS: " + (datadr1 - 1) + ", DATUM:" + f + ", DONE");
cmdadr = 0;
opr = 0;
datadr1 = 0;
datadr2 = 0;
} else {
form.append(flofield);
flofield.setString("0");
form.addCommand(setvalue);
form.setCommandListener(this);
form.append(" ADDRESS: " + (datadr1 - 1) + ", DATUM:" + f + ", ENTER NEXT DATUM");
}
} else if (cmdadr == -1) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
ephemeral = d1_field.getString();
datadr1 = java.lang.Integer.parseInt(ephemeral);
ephemeral = d2_field.getString();
datadr2 = java.lang.Integer.parseInt(ephemeral);
if ((datadr1 < 0) || (datadr2 < 0)) { // fast eject - do nothing
form.append(" CANCELLED ON NEGATIVE RANGE");
} else {
if ((datadr1 == 0) && (datadr2 == 0)) {
/* prlong EVERYTHING */
datadr1 = 1;
datadr2 = DATAMEM - 1;
} else if (datadr2 == 0) {
datadr2 = datadr1; /* i.e. prlong only one datum */
}
/* Normalise ranges: low to high */
if (datadr2 < datadr1) {
k = datadr2;
datadr2 = datadr1;
datadr1 = k;
}
h = datadr1;
k = datadr2;
if (h < 1) { h = 1;}
if (k >= DATAMEM) { k = DATAMEM - 1; }
for (i = h; i <= k; i++) {
instr = instruction[(int) (i)];
// EEPROM.get((INSTRUCTION_BYTE_LENGTH * (i - 0)) + ZERO_OFFSET, instr);
xx = (instr >> 26) & 63; /* 4095:255:24:12 or 8191:63:26:13 */
yy = (instr >> 13) & 8191;
zz = instr & 8191;
opr = xx;
datadr1 = yy;
datadr2 = zz;
ephemeral = " ";
ephemeral = ephemeral + i + ":" + opr;
ephemeral = ephemeral + ":";
ephemeral = ephemeral + datadr1 + ">" + datum[(int) (datadr1)];
if ((datum[(int) (datadr1)] > -1 * DATAMEM) && (datum[(int) (datadr1)] < DATAMEM)) {
j = (int) absvalu((long)(datum[(int) (datadr1)]));
ephemeral = ephemeral + ">" + datum[(int) (j)];
}
ephemeral = ephemeral + ":";
ephemeral = ephemeral + datadr2 + ">" + datum[(int) (datadr2)];
if ((datum[(int) (datadr2)] > -1 * DATAMEM) && (datum[(int) (datadr2)] < DATAMEM)) {
j = (int) absvalu((long)(datum[(int) (datadr2)]));
ephemeral = ephemeral + ">" + datum[(int) (j)];
}
ephemeral = ephemeral + ":";
ephemeral = ephemeral + "DEC:" + instr;
form.append(ephemeral);
}
h = 0;
k = 0;
i = 0;
}
} else if (cmdadr == -2) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
ephemeral = d1_field.getString();
datadr1 = java.lang.Integer.parseInt(ephemeral);
ephemeral = d2_field.getString();
datadr2 = java.lang.Integer.parseInt(ephemeral);
if ((datadr1 < 0) || (datadr2 < 0)) { // fast eject - do nothing
form.append(" CANCELLED ON NEGATIVE RANGE");
} else {
if ((datadr1 == 0) && (datadr2 == 0)) {
/* prlong EVERYTHING */
datadr1 = 1;
datadr2 = DATAMEM - 1;
} else if (datadr2 == 0) {
datadr2 = datadr1; /* i.e. prlong only one datum */
}
/* Normalise ranges: low to high */
if (datadr2 < datadr1) {
k = datadr2;
datadr2 = datadr1;
datadr1 = k;
}
h = datadr1;
k = datadr2;
if (h < 1) { h = 1;}
if (k >= DATAMEM) { k = DATAMEM - 1; }
for (i = h; i <= k; i++) {
ephemeral = " " + i + ":" + datum[(int) (i)];
form.append(ephemeral);
}
h = 0;
k = 0;
i = 0;
}
} else if (cmdadr == -3) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
ephemeral = d1_field.getString();
datadr1 = java.lang.Integer.parseInt(ephemeral);
if ((datadr1 < 0) || (datadr1 > EXECMEM - 1)) { // fast eject - do nothing
form.append(" CANCELLED ON OUT OF RANGE COMMAND ADDRESS");
} else {
form.append(longfield);
longfield.setString("0");
form.addCommand(setvalue);
form.setCommandListener(this);
entryflag = -3;
}
} else if (cmdadr == -4) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
ephemeral = d1_field.getString();
datadr1 = java.lang.Integer.parseInt(ephemeral);
ephemeral = d2_field.getString();
datadr2 = java.lang.Integer.parseInt(ephemeral);
if ((datadr1 < 0) || (datadr2 < 0) || (datadr2 < datadr1)) { // fast eject - do nothing
form.append(" CANCELLED ON NEGATIVE RANGE OR DESCENDING ADDRESSES");
} else {
form.append(flofield);
flofield.setString("0");
form.addCommand(setvalue);
form.setCommandListener(this);
entryflag = -4;
}
} else if (cmdadr == -5) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
ephemeral = d1_field.getString();
datadr1 = java.lang.Integer.parseInt(ephemeral);
ephemeral = d2_field.getString();
datadr2 = java.lang.Integer.parseInt(ephemeral);
if ((datadr1 < 0) || (datadr2 < 0)) { // fast eject - do nothing
form.append(" CANCELLED ON NEGATIVE RANGE");
} else {
if ((datadr1 == 0) && (datadr2 == 0)) {
/* clear EVERYTHING */
datadr1 = 1;
datadr2 = DATAMEM - 1;
} else if (datadr2 == 0) {
datadr2 = datadr1; /* clear one single instruction */
}
/* Normalise ranges: low to high */
if (datadr2 < datadr1) {
k = datadr2;
datadr2 = datadr1;
datadr1 = k;
}
h = datadr1;
k = datadr2;
if (h < 1) { h = 1;} /* Do not clear address 0, it is reserved. */
if (k >= EXECMEM) { k = EXECMEM - 1; } /* out-of-range-correction */
instr = 0; /* Just to make sure it "understands" the size as 32bit. */
for (i = h; i <= k; i++) {
instruction[(int) (i)] = instr;
}
form.append(" INSTRUCTIONS CLEARED");
h = 0;
k = 0;
i = 0;
}
} else if (cmdadr == -6) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
ephemeral = d1_field.getString();
datadr1 = java.lang.Integer.parseInt(ephemeral);
ephemeral = d2_field.getString();
datadr2 = java.lang.Integer.parseInt(ephemeral);
if ((datadr1 < 0) || (datadr2 < 0)) { // fast eject - do nothing
form.append(" CANCELLED ON NEGATIVE RANGE");
} else {
if ((datadr1 == 0) && (datadr2 == 0)) {
/* clear EVERYTHING */
datadr1 = 1;
datadr2 = DATAMEM - 1;
} else if (datadr2 == 0) {
datadr2 = datadr1; /* i.e. clear only one datum */
}
/* Normalise ranges: low to high */
if (datadr2 < datadr1) {
k = datadr2;
datadr2 = datadr1;
datadr1 = k;
}
h = datadr1;
k = datadr2;
if (h < 1) { h = 1;}
if (k >= DATAMEM) { k = DATAMEM - 1; }
for (i = h; i <= k; i++) {
datum[(int) (i)] = 0;
}
form.append(" DATA CLEARED");
h = 0;
k = 0;
i = 0;
}
} else if (cmdadr == -9) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
ephemeral = "OLD RUNLIMIT WAS " + runlimit;
form.append(ephemeral);
ephemeral = rl_field.getString();
runlimit = java.lang.Integer.parseInt(ephemeral);
form.append(" NEW RUNLIMIT SET TO " + ephemeral);
}
if (entryflag == 0) {
form.addCommand(reentry); // setvalue -> reentry
form.setCommandListener(this);
} else {
form.addCommand(setvalue);
form.setCommandListener(this);
form.setCommandListener(this);
}
} else if (command == runcode) {
for (int delel = form.size() - 1; delel >=0; delel--) { form.delete(delel); }
previouscommand = command;
form.removeCommand(runcode);
form.removeCommand(submit);
form.append(" RUNNING JOB...");
form.addCommand(reentry); // runcode -> reentry
form.setCommandListener(this);
while (pc < EXECMEM) {
if (runlimit == 1) {
rlstring = "TERMINATED WITH RUNLIMIT EXHAUSTED, PC=" + pc + " STOPPED";
break;
} else if (runlimit > 1) {
runlimit--;
if (((runlimit - 1) % 1000) == 0) {
form.append(" RUNLIMIT = " + runlimit);
/* Give an indication of progress without annoying too often. */
}
rlstring = "";
}
datum[(int) (0)] = 0; /* Useful for unconditional jumps. */
if (pc < 0) {
pc = 0;
}
// System.out.println("X CMDADR = " + cmdadr + " PC = " + pc + " OPR=" + opr + " DATADR1=" + datadr1 + " DATADR2=" + datadr2 );
instr = instruction[(int) (pc)];
// System.out.println("DEC INSTRUCTION:" + instr);
/* 63 operations possible, on 8191 places of data for each address; 26,13 */
/* or: 255 operations, on 4095 data places for each address; 24,12 */
opr = (instr >> 26) & 63;
datadr1 = (instr >> 13) & 8191;
datadr2 = instr & 8191;
/* Is an instruction modifier active? If yes, change each dataddr. */
/* This is due to IADR, indirect addressing, see below opcode 2. */
if ((h > 0) && (k > 0)) {
datadr1 = h;
datadr2 = k;
h = 0;
k = 0;
}
// System.out.println("Y CMDADR = " + cmdadr + " PC = " + pc + " OPR=" + opr + " DATADR1=" + datadr1 + " DATADR2=" + datadr2 );
/* TRACE EXECUTION OF EACH PRESENT INSTRUCTION */
if (tracer != 0) {
trace1s = " ";
trace1s = trace1s + pc + ":" + opr;
trace1s = trace1s + ":";
trace1s = trace1s + datadr1 + ">" + datum[(int) (datadr1)];
if ((datum[(int) (datadr1)] > -1 * DATAMEM) && (datum[(int) (datadr1)] < DATAMEM)) {
j = (int) absvalu((long)(datum[(int) (datadr1)]));
trace1s = trace1s + ">" + datum[(int) (j)];
}
trace1s = trace1s + ":";
trace1s = trace1s + datadr2 + ">" + datum[(int) (datadr2)];
if ((datum[(int) (datadr2)] > -1 * DATAMEM) && (datum[(int) (datadr2)] < DATAMEM)) {
j = (int) absvalu((long)(datum[(int) (datadr2)]));
trace1s = trace1s + ">" + datum[(int) (j)];
}
trace1s = trace1s + ":";
trace1s = trace1s + "DEC:" + instr;
} /* end of instruction tracing */
/* ---------- DECODE ---------- */
/* Quite simply: "do different things depending on what operation (opr) */
/* is presently indicated by the program counter (pc). */
/* There are two instructions which deal with program CONTROL, and */
/* all other instructions deal with reading, writing and storing values */
/* as well as with mathematical operations, which are indeed the focus. */
/* The one is to jump if at a certain address the value is (close to) */
/* zero or negative - and this is the ONLY branch instruction, and thus */
/* loops are to be implemented by "jumping backwards" and "reducing the */
/* addressed value" - and the other instruction sets datadr1 and datadr2 */
/* to be overwritten by certain values upon the next instruction; this */
/* should allow rather flexible programming. - This section "DECODE" it */
/* is where you may really adjust this whole system to your taste: */
/* shuffle opr-values, reduce or extend or modify the instructions, etc. */
/* WHATEVER IS NOT MATCHED: NO OPERATION [NOP)] / RESERVED */
/* This particularly applies to "Operation 0", so all starts with 1. */
if (opr == 0) {
/* NOOP -- NO OPERATION: Do nothing. */
/* Any non-implemented opcode will work as NOP. */
/* This is also nice if you want to temporarily de-activate certain code. */
} else if (opr == 1) {
/* JUMP */
/* JUMP IF THE FIRST ADDRESS CONTAINS (NEARLY) ZERO OR A NEGATIVE NUMBER*/
/* "Nearly" zero, because these are longs and repeated long operations */
/* may render the results imprecise. */
/* This can very neatly be translated longo a high language's IF & WHILE. */
/* Anyway, welcome to "spaghetti programming". You will use this sole */
/* condition until you learn to LOVE IT! */
if (datum[(int) (datadr1)] <= TOLERANCE) {
/* pc = (long) absvalu((long)(datum[(int) (datadr2)])); */ /* However, such a default is */
/* NOT a good idea, actually: with a default COMPUTED GOTO, you */
/* normally straight GOTO HELL, and have NO adequate way to trace it. */
/* Instead, let the default be OBVIOUS: */
pc = datadr2;
/* On purpose NOT "computed", but IADR still allows it. */
/* BEWARE: the program counter adjustment below needed to be RESET, */
/* otherwise it was sending you ONE AFTER your desired jump address! */
} else { pc++; } /* without this, it gets stuck! */
/* This pc adjustment above makes jumps NOT return to immediate mode: */
/* pc is set to, essentially, an long indicated by the long value */
/* at an address. But a return to immediate mode is only possible if */
/* pc stays 0. This is why a jump can serve as an "entry" to exection. */
} else if (opr == 2) {
/* IADR -- INDIRECT ADDRESSING: */
/* SUBSTITUTE datadr1 AND datadr2 IN THE NEXT INSTRUCTION BY h AND k. */
/* Whatever the next operation is, datum[(int) (datadr1)] shall give */
/* the next datadr1, and datum[(int) (datadr2)] shall give the next datadr2. */
/* This shall serve for a rather powerful "indirect addressing" */
/* whenever such is needed, in a flexible manner. */
h = (int) absvalu((long)(datum[(int) (datadr1)]));
k = (int) absvalu((long)(datum[(int) (datadr2)]));
/* Thereby, h & k are "charged" and will trigger a modification of */
/* the next instruction, substituting its addresses one time. */
/* You can obviously cancel this with a NOP. */
/* Make sure the addresses are within the allowed address range. */
if (h < 1) {
h = 1;
}
if (k < 1) {
k = 1;
}
if (h >= DATAMEM) {
h = DATAMEM - 1;
}
if (k >= DATAMEM) {
k = DATAMEM - 1;
}
/* ----------- FROM NOW ON FOLLOW COMMANDS FOR SETTING VALUES ----------- */
} else if (opr == 3) {
/* OUTP -- write 0 for OUTPUT if you have a numeric display. */
/* This instruction will prlong all data in a range, unless the second */
/* address is seither the same as the first address or 0, indicating */
/* that only the first address is to be prlonged. */
/* NO NERVE FOR THIS MIDLET TRASH, USE IT AS A "PUNCH CARD MACHINE"! */
} else if (opr == 4) {
/* INPT -- write 1 for INPUT if you have a numeric display. */
/* This instruction will read a range of numbers, unless */
/* the second address is the same as the first address or 0, */
/* indicating that only a single number is to be read. */
/* NO NERVE FOR THIS MIDLET TRASH, USE IT AS A "PUNCH CARD MACHINE"! */
} else if (opr == 5) {
/* SADR -- SET ADDRESS AS VALUE: */
/* This can also used to let an address be treated as a value in some */
/* future instruction - IADR (opcode 2) can help reversing the process. */
datum[(int) (datadr1)] = datadr2;
/* obviously, if datadr2 == datadr1, this will make an address */
/* "hold itself" */
} else if (opr == 6) {
/* SVAL -- SET VALUE: This is the "normal 'equal'" in other languages. */
/* Did not call it EQUL or thelike, to help visually differentiate */
/* values and addresses. */
datum[(int) (datadr1)] = datum[(int) (datadr2)];
} else if (opr == 7) {
/* HOW IxAS WORKS: */
/* datadr1 contains an address X, i.e. it polongs to it; */
/* X is at first expressed as a long to be converted to an long. */
/* datum[(int) (X)] shall either be set to an address or a value that is defined */
/* in datadr2, i.e. datadr2 itself or the datum at datadr2, respectively. */
/* In other words, datum[(int) (datum[(int) (datadr1)])] = datadr2, from now on */
/* Indirect Address Assignment or IAAS, or Indirect Value Assignemnt */
/* IVAS signifying datum[(int) (datum[(int) (datadr1)])] = datum[(int) (datadr2)]. These may look */
/* pretty strange, but they appeared practical for certain loops. */
/* IAAS */
i = (int) absvalu((long)(datum[(int) (datadr1)]));
datum[(int) (i)] = datadr2;
} else if (opr == 8) {
/* IVAS -- see above. */
i = (int) absvalu((long)(datum[(int) (datadr1)]));
datum[(int) (i)] = datum[(int) (datadr2)];
/* ---- FROM NOW ON FOLLOW COMMANDS FOR SINGLE NUMERIC MANIPULATION ----- */
} else if (opr == 9) {
/* PLUS -- PLUS FOR SINGLE NUMBERS, NOT RANGE. */
datum[(int) (datadr1)] = datum[(int) (datadr1)] + datum[(int) (datadr2)];
} else if (opr == 10) {
/* MINS -- MINUS FOR SINGLE NUMBERS, NOT RANGE. */
datum[(int) (datadr1)] = datum[(int) (datadr1)] - datum[(int) (datadr2)];
} else if (opr == 11) {
/* MULS -- MULTIPLY SINGLE NUMBERS, NOT RANGE. */
datum[(int) (datadr1)] = datum[(int) (datadr1)] * datum[(int) (datadr2)] / PRECISION;
} else if (opr == 12) {
/* DIVS -- DIVIDE SINGLE NUMBERS, NOT RANGE. */
/* In case of a division by 0, there shall be no hysteria. Just give 0. */
/* This makes loops much easier than "having to look out for the */
/* mathematical booby-trap" all the time. Here this is done GENERALLY. */
if (absvalu(datum[(int) (datadr2)]) != 0) {
datum[(int) (datadr1)] = datum[(int) (datadr1)] * PRECISION / datum[(int) (datadr2)];
} else {
datum[(int) (datadr1)] = 0;
}
} else if (opr == 13) {
/* POXY -- Power Of X: Y, that is, X ^ Y, BASED ON |X| WITH SIGN EX POST. */