-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstructions.lua
1156 lines (929 loc) · 34.4 KB
/
instructions.lua
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
local i = {}
function i.NOP() w("#NOP") end
function i.LD(to, from)
w("#LD")
w("scoreboard players operation " .. to .. " = " .. from)
end
function i.STOP()
w("say STOP not implemented!")
w("#STOP")
end
function i.HALT()
w("#HALT")
w("scoreboard players set HALT registers 1")
end
function i.JP(value)
w("#JP")
w("scoreboard players operation PC registers = " .. value)
end
function i.JPC(condition, value)
w("#JPC")
w("execute if score " .. condition ..
" run scoreboard players operation PC registers = " .. value)
end
function i.JR(value)
w("#JR")
w("scoreboard players operation PC registers += " .. value)
end
function i.JRC(condition, value)
w("#JRC")
w("execute if score " .. condition ..
" run scoreboard players operation PC registers += " .. value)
end
function i.RST(value)
w("#RST")
i.PUSH("PC registers")
w("scoreboard players set PC registers " .. value)
end
function i.CALL(value)
w("#CALL")
i.PUSH("PC registers")
i.JP(value)
end
function i.CALLC(condition, value)
w("#CALLC")
w("execute if score " .. condition ..
" run function craftboy:instructions/205")
w("execute unless score " .. condition ..
" run scoreboard players add PC registers 2")
end
function i.RET()
w("#RET")
i.POP("PC registers")
end
function i.RETI()
w("#RETI")
w("scoreboard players set IME registers 1")
i.POP("PC registers")
end
function i.RETC(condition)
w("#RETC")
w("execute if score " .. condition ..
" run function craftboy:instructions/201")
end
function i.PUSH(value)
w("#PUSH")
i.GET_HI16(value)
i.DEC16("SP registers")
i.WRITE8("SP registers", "out binary")
i.GET_LO16(value)
i.DEC16("SP registers")
i.WRITE8("SP registers", "out binary")
end
function i.PUSH2(value)
w("#PUSH")
i.DEC16("SP registers")
i.WRITE8("SP registers", value[1])
i.DEC16("SP registers")
i.WRITE8("SP registers", value[2])
end
function i.POP(to)
w("#POP")
i.READ8("SP registers")
i.INC16("SP registers")
i.SET_LO16(to, "transfer craftboy")
i.READ8("SP registers")
i.INC16("SP registers")
i.SET_HI16(to, "transfer craftboy")
end
function i.POP2(to)
w("#POP")
i.READ8("SP registers")
i.INC16("SP registers")
i.LD(to[2], "transfer craftboy")
i.READ8("SP registers")
i.INC16("SP registers")
i.LD(to[1], "transfer craftboy")
end
function i.ADD(to, from)
w("#ADD")
i.LD("tmp2_ADD craftboy", to)
i.LD("tmp3_ADD craftboy", from)
w("scoreboard players operation " .. to .. " += " .. from)
-- HFLAG
i.GET_LO16_12("tmp2_ADD craftboy")
i.LD("tmp0_ADD craftboy", "out binary")
i.GET_LO16_12("tmp3_ADD craftboy")
i.LD("tmp1_ADD craftboy", "out binary")
w("scoreboard players operation tmp0_ADD craftboy += tmp1_ADD craftboy")
w("scoreboard players set hflag_ADD craftboy 0")
w(
"execute if score tmp0_ADD craftboy matches 4096.. run scoreboard players set hflag_ADD craftboy 1")
-- CFLAG
w("scoreboard players set cflag_ADD craftboy 0")
w("execute if score " .. to ..
" matches 65536.. run scoreboard players set cflag_ADD craftboy 1")
w("execute if score " .. to ..
" matches 65536.. run scoreboard players remove " .. to .. " 65536")
w("scoreboard players set N flags 0")
w("scoreboard players operation H flags = hflag_ADD craftboy")
w("scoreboard players operation C flags = cflag_ADD craftboy")
end
function i.ADD_SPD(to, from)
w("#ADD")
i.LD("tmp2_ADD_SPD craftboy", to)
i.LD("tmp3_ADD_SPD craftboy", from)
w("scoreboard players operation " .. to .. " += " .. from)
-- HFLAG
i.GET_LO8("tmp2_ADD_SPD craftboy")
i.LD("tmp0_ADD_SPD craftboy", "out binary")
i.GET_LO8("tmp3_ADD_SPD craftboy")
i.LD("tmp1_ADD_SPD craftboy", "out binary")
w(
"scoreboard players operation tmp0_ADD_SPD craftboy += tmp1_ADD_SPD craftboy")
w("scoreboard players set hflag_ADD_SPD craftboy 0")
w(
"execute if score tmp0_ADD_SPD craftboy matches 16.. run scoreboard players set hflag_ADD_SPD craftboy 1")
-- CFLAG
i.GET_LO16("tmp2_ADD_SPD craftboy")
i.LD("tmp4_ADD_SPD craftboy", "out binary")
i.GET_LO16("tmp3_ADD_SPD craftboy")
i.LD("tmp5_ADD_SPD craftboy", "out binary")
w(
"scoreboard players operation tmp4_ADD_SPD craftboy += tmp5_ADD_SPD craftboy")
w("scoreboard players set cflag_ADD_SPD craftboy 0")
w(
"execute if score tmp4_ADD_SPD craftboy matches 256.. run scoreboard players set cflag_ADD_SPD craftboy 1")
w("execute if score " .. to ..
" matches 65536.. run scoreboard players remove " .. to .. " 65536")
w(
"execute if score " .. to .. " matches ..-1 run scoreboard players add " ..
to .. " 65536")
w("scoreboard players set Z flags 0")
w("scoreboard players set N flags 0")
w("scoreboard players operation H flags = hflag_ADD_SPD craftboy")
w("scoreboard players operation C flags = cflag_ADD_SPD craftboy")
end
function i.SUB(to, from)
w("#SUB")
i.LD("tmp2_SUB craftboy", to)
w("scoreboard players operation " .. to .. " -= " .. from)
-- HFLAG
i.GET_LO8(to)
i.LD("tmp0_SUB craftboy", "out binary")
i.GET_LO8(from)
i.LD("tmp1_SUB craftboy", "out binary")
w("scoreboard players set hflag_SUB craftboy 0")
w(
"execute if score tmp1_SUB craftboy > tmp0_SUB craftboy run scoreboard players set hflag_SUB craftboy 1")
-- CFLAG
w("scoreboard players set cflag_SUB craftboy 0")
w("execute if score " .. from ..
" > tmp2_SUB craftboy run scoreboard players set cflag_SUB craftboy 1")
w(
"execute if score " .. to .. " matches ..-1 run scoreboard players add " ..
to .. " 65536")
-- ZFLAG
w("scoreboard players set zflag_SUB craftboy 0")
w("execute if score " .. to ..
" matches 0 run scoreboard players set zflag_SUB craftboy 1")
w("scoreboard players operation Z flags = zflag_SUB craftboy")
w("scoreboard players set N flags 1")
w("scoreboard players operation H flags = hflag_SUB craftboy")
w("scoreboard players operation C flags = cflag_SUB craftboy")
end
function i.INC8(value)
w("#INC8")
w("scoreboard players add " .. value .. " 1")
w("execute if score " .. value ..
" matches 256.. run scoreboard players remove " .. value .. " 256")
-- HFLAG
i.GET_LO8(value)
w("scoreboard players set hflag_INC craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set hflag_INC craftboy 1")
-- ZFLAG
w("scoreboard players set zflag_INC craftboy 0")
w("execute if score " .. value ..
" matches 0 run scoreboard players set zflag_INC craftboy 1")
w("scoreboard players operation Z flags = zflag_INC craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players operation H flags = hflag_INC craftboy")
end
function i.DEC8(value)
w("#DEC8")
w("scoreboard players remove " .. value .. " 1")
w("execute if score " .. value ..
" matches ..-1 run scoreboard players add " .. value .. " 256")
-- HFLAG
i.GET_LO8(value)
w("scoreboard players set hflag_DEC craftboy 0")
w(
"execute if score out binary matches 15 run scoreboard players set hflag_DEC craftboy 1")
-- ZFLAG
w("scoreboard players set zflag_DEC craftboy 0")
w("execute if score " .. value ..
" matches 0 run scoreboard players set zflag_DEC craftboy 1")
w("scoreboard players operation Z flags = zflag_DEC craftboy")
w("scoreboard players set N flags 1")
w("scoreboard players operation H flags = hflag_DEC craftboy")
end
function i.INC16(value)
w("#INC16")
w("scoreboard players add " .. value .. " 1")
w("execute if score " .. value ..
" matches 65536.. run scoreboard players remove " .. value .. " 65536")
end
function i.DEC16(value)
w("#DEC16")
w("scoreboard players remove " .. value .. " 1")
w("execute if score " .. value ..
" matches ..-1 run scoreboard players add " .. value .. " 65536")
end
function i.RLCA()
w("#RLCA")
i.LD("in binary", "A registers")
w("function craftboy:util/binary_split0")
i.LD("tmp_RLCA craftboy", "7_0 binary")
i.LD("7_0 binary", "6_0 binary")
i.LD("6_0 binary", "5_0 binary")
i.LD("5_0 binary", "4_0 binary")
i.LD("4_0 binary", "3_0 binary")
i.LD("3_0 binary", "2_0 binary")
i.LD("2_0 binary", "1_0 binary")
i.LD("1_0 binary", "0_0 binary")
i.LD("0_0 binary", "tmp_RLCA craftboy")
w("function craftboy:util/binary_join0")
i.LD("A registers", "out binary")
w("scoreboard players set Z flags 0")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = tmp_RLCA craftboy")
end
function i.RRCA()
w("#RRCA")
i.LD("in binary", "A registers")
w("function craftboy:util/binary_split0")
i.LD("tmp_RRCA craftboy", "0_0 binary")
i.LD("0_0 binary", "1_0 binary")
i.LD("1_0 binary", "2_0 binary")
i.LD("2_0 binary", "3_0 binary")
i.LD("3_0 binary", "4_0 binary")
i.LD("4_0 binary", "5_0 binary")
i.LD("5_0 binary", "6_0 binary")
i.LD("6_0 binary", "7_0 binary")
i.LD("7_0 binary", "tmp_RRCA craftboy")
w("function craftboy:util/binary_join0")
i.LD("A registers", "out binary")
w("scoreboard players set Z flags 0")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = tmp_RRCA craftboy")
end
function i.RLA()
w("#RLA")
i.LD("tmp_RLA craftboy", "A registers")
i.LD("in binary", "tmp_RLA craftboy")
w("function craftboy:util/binary_split0")
i.LD("cflag_RLA craftboy", "7_0 binary")
i.LD("7_0 binary", "6_0 binary")
i.LD("6_0 binary", "5_0 binary")
i.LD("5_0 binary", "4_0 binary")
i.LD("4_0 binary", "3_0 binary")
i.LD("3_0 binary", "2_0 binary")
i.LD("2_0 binary", "1_0 binary")
i.LD("1_0 binary", "0_0 binary")
i.LD("0_0 binary", "C flags")
w("function craftboy:util/binary_join0")
i.LD("tmp_RLA craftboy", "out binary")
i.LD("A registers", "tmp_RLA craftboy")
w("scoreboard players set Z flags 0")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = cflag_RLA craftboy")
end
function i.RRA()
w("#RRA")
i.LD("tmp_RRA craftboy", "A registers")
i.LD("in binary", "tmp_RRA craftboy")
w("function craftboy:util/binary_split0")
i.LD("cflag_RRA craftboy", "0_0 binary")
i.LD("0_0 binary", "1_0 binary")
i.LD("1_0 binary", "2_0 binary")
i.LD("2_0 binary", "3_0 binary")
i.LD("3_0 binary", "4_0 binary")
i.LD("4_0 binary", "5_0 binary")
i.LD("5_0 binary", "6_0 binary")
i.LD("6_0 binary", "7_0 binary")
i.LD("7_0 binary", "C flags")
w("function craftboy:util/binary_join0")
i.LD("tmp_RRA craftboy", "out binary")
i.LD("A registers", "tmp_RRA craftboy")
w("scoreboard players set Z flags 0")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = cflag_RRA craftboy")
end
function i.DAA()
w("#DAA")
i.LD("tmpA_DAA craftboy", "A registers")
i.LD("in binary", "tmpA_DAA craftboy")
w("function craftboy:util/binary_split0")
w("scoreboard players set 4_0 binary 0")
w("scoreboard players set 5_0 binary 0")
w("scoreboard players set 6_0 binary 0")
w("scoreboard players set 7_0 binary 0")
w("function craftboy:util/binary_join0")
i.LD("tmpA_F_DAA craftboy", "out binary")
w("scoreboard players set tmpOR_DAA craftboy 0")
w("execute if score N flags matches 0 " ..
"if score C flags matches 1 run function craftboy:daa/aplusequalssixzero")
w(
"execute if score tmpOR_DAA craftboy matches 0 if score N flags matches 0 " ..
"if score tmpA_DAA craftboy matches 154.. run function craftboy:daa/aplusequalssixzero")
w("scoreboard players set tmpOR_DAA craftboy 0")
w("execute if score N flags matches 0 " ..
"if score H flags matches 1 run function craftboy:daa/aplusequalssix")
w(
"execute if score tmpOR_DAA craftboy matches 0 if score N flags matches 0 " ..
"if score tmpA_F_DAA craftboy matches 10.. run function craftboy:daa/aplusequalssix")
w(
"execute if score N flags matches 1 if score C flags matches 1 run scoreboard players remove tmpA_DAA craftboy 96")
w(
"execute if score N flags matches 1 if score H flags matches 1 run scoreboard players remove tmpA_DAA craftboy 6")
w(
"execute if score tmpA_DAA craftboy matches 256.. run scoreboard players remove tmpA_DAA craftboy 256")
w(
"execute if score tmpA_DAA craftboy matches ..-1 run scoreboard players add tmpA_DAA craftboy 256")
w("scoreboard players set Z flags 0")
w(
"execute if score tmpA_DAA craftboy matches 0 run scoreboard players set Z flags 1")
i.LD("A registers", "tmpA_DAA craftboy")
w("scoreboard players set H flags 0")
end
function i.CPL()
w("#CPL")
i.LD("in binary", "A registers")
w("function craftboy:util/binary_split0")
i.INV_BIT("0_0 binary")
i.INV_BIT("1_0 binary")
i.INV_BIT("2_0 binary")
i.INV_BIT("3_0 binary")
i.INV_BIT("4_0 binary")
i.INV_BIT("5_0 binary")
i.INV_BIT("6_0 binary")
i.INV_BIT("7_0 binary")
w("function craftboy:util/binary_join0")
i.LD("A registers", "out binary")
w("scoreboard players set N flags 1")
w("scoreboard players set H flags 1")
end
function i.SCF()
w("#SCF")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players set C flags 1")
end
function i.CCF()
w("#CCF")
i.INV_BIT("C flags")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
end
function i.ADD_A(value)
w("#ADD_A")
i.LD("tmp0_ADD_A craftboy", "A registers")
i.LD("tmp_ADD_A craftboy", "A registers")
w("scoreboard players operation tmp_ADD_A craftboy += " .. value)
-- HFLAG
i.GET_LO8("tmp0_ADD_A craftboy")
i.LD("tmp0_ADD_A craftboy", "out binary")
i.GET_LO8(value)
i.LD("tmp1_ADD_A craftboy", "out binary")
w("scoreboard players operation tmp0_ADD_A craftboy += tmp1_ADD_A craftboy")
w("scoreboard players set hflag_ADD_A craftboy 0")
w(
"execute if score tmp0_ADD_A craftboy matches 16.. run scoreboard players set hflag_ADD_A craftboy 1")
-- CFLAG
w("scoreboard players set cflag_ADD_A craftboy 0")
w(
"execute if score tmp_ADD_A craftboy matches 256.. run scoreboard players set cflag_ADD_A craftboy 1")
w(
"execute if score tmp_ADD_A craftboy matches 256.. run scoreboard players remove tmp_ADD_A craftboy 256")
-- ZFLAG
w("scoreboard players set zflag_ADD_A craftboy 0")
w(
"execute if score tmp_ADD_A craftboy matches 0 run scoreboard players set zflag_ADD_A craftboy 1")
w("scoreboard players operation Z flags = zflag_ADD_A craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players operation H flags = hflag_ADD_A craftboy")
w("scoreboard players operation C flags = cflag_ADD_A craftboy")
i.LD("A registers", "tmp_ADD_A craftboy")
end
function i.ADC_A(value)
w("#ADC_A")
i.LD("tmp_ADC_A craftboy", "A registers")
i.LD("tmp2_ADC_A craftboy", "A registers")
w("scoreboard players operation tmp_ADC_A craftboy += " .. value)
w("scoreboard players operation tmp_ADC_A craftboy += C flags")
-- HFLAG
i.GET_LO8("tmp2_ADC_A craftboy")
i.LD("tmp0_ADC_A craftboy", "out binary")
i.GET_LO8(value)
i.LD("tmp1_ADC_A craftboy", "out binary")
w("scoreboard players operation tmp0_ADC_A craftboy += tmp1_ADC_A craftboy")
w("scoreboard players operation tmp0_ADC_A craftboy += C flags")
w("scoreboard players set hflag_ADC_A craftboy 0")
w(
"execute if score tmp0_ADC_A craftboy matches 16.. run scoreboard players set hflag_ADC_A craftboy 1")
-- CFLAG
w("scoreboard players set cflag_ADC_A craftboy 0")
w(
"execute if score tmp_ADC_A craftboy matches 256.. run scoreboard players set cflag_ADC_A craftboy 1")
w(
"execute if score tmp_ADC_A craftboy matches 256.. run scoreboard players remove tmp_ADC_A craftboy 256")
-- ZFLAG
w("scoreboard players set zflag_ADC_A craftboy 0")
w(
"execute if score tmp_ADC_A craftboy matches 0 run scoreboard players set zflag_ADC_A craftboy 1")
w("scoreboard players operation Z flags = zflag_ADC_A craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players operation H flags = hflag_ADC_A craftboy")
w("scoreboard players operation C flags = cflag_ADC_A craftboy")
i.LD("A registers", "tmp_ADC_A craftboy")
end
function i.SUB_A(value)
w("#SUB_A")
i.LD("tmp_SUB_A craftboy", "A registers")
i.LD("tmp2_SUB_A craftboy", "tmp_SUB_A craftboy")
w("scoreboard players operation tmp_SUB_A craftboy -= " .. value)
-- HFLAG
i.GET_LO8("tmp2_SUB_A craftboy")
i.LD("tmp0_SUB craftboy", "out binary")
i.GET_LO8(value)
i.LD("tmp1_SUB craftboy", "out binary")
w("scoreboard players set hflag_SUB craftboy 0")
w(
"execute if score tmp1_SUB craftboy > tmp0_SUB craftboy run scoreboard players set hflag_SUB craftboy 1")
-- CFLAG
w("scoreboard players set cflag_SUB craftboy 0")
w("execute if score " .. value ..
" > tmp2_SUB_A craftboy run scoreboard players set cflag_SUB craftboy 1")
w(
"execute if score tmp_SUB_A craftboy matches ..-1 run scoreboard players add tmp_SUB_A craftboy 256")
-- ZFLAG
w("scoreboard players set zflag_SUB craftboy 0")
w(
"execute if score tmp_SUB_A craftboy matches 0 run scoreboard players set zflag_SUB craftboy 1")
w("scoreboard players operation Z flags = zflag_SUB craftboy")
w("scoreboard players set N flags 1")
w("scoreboard players operation H flags = hflag_SUB craftboy")
w("scoreboard players operation C flags = cflag_SUB craftboy")
i.LD("A registers", "tmp_SUB_A craftboy")
end
function i.SBC_A(value)
w("#SBC_A")
i.LD("tmp_SBC_A craftboy", "A registers")
i.LD("tmp2_SBC_A craftboy", "A registers")
w("scoreboard players operation tmp_SBC_A craftboy -= " .. value)
w("scoreboard players operation tmp_SBC_A craftboy -= C flags")
-- HFLAG
i.GET_LO8("tmp2_SBC_A craftboy")
i.LD("tmp0_SBC craftboy", "out binary")
i.GET_LO8(value)
i.LD("tmp1_SBC craftboy", "out binary")
w("scoreboard players operation tmp1_SBC craftboy += C flags")
w("scoreboard players set hflag_SBC craftboy 0")
w(
"execute if score tmp1_SBC craftboy > tmp0_SBC craftboy run scoreboard players set hflag_SBC craftboy 1")
-- CFLAG
w("scoreboard players set cflag_SBC craftboy 0")
i.LD("tmp3_SBC craftboy", value)
w("scoreboard players operation tmp3_SBC craftboy += C flags")
w(
"execute if score tmp3_SBC craftboy > tmp2_SBC_A craftboy run scoreboard players set cflag_SBC craftboy 1")
w(
"execute if score tmp_SBC_A craftboy matches ..-1 run scoreboard players add tmp_SBC_A craftboy 256")
-- ZFLAG
w("scoreboard players set zflag_SBC craftboy 0")
w(
"execute if score tmp_SBC_A craftboy matches 0 run scoreboard players set zflag_SBC craftboy 1")
w("scoreboard players operation Z flags = zflag_SBC craftboy")
w("scoreboard players set N flags 1")
w("scoreboard players operation H flags = hflag_SBC craftboy")
w("scoreboard players operation C flags = cflag_SBC craftboy")
i.LD("A registers", "tmp_SBC_A craftboy")
end
function i.AND_A(value)
w("#AND_A")
i.LD("in binary", "A registers")
w("function craftboy:util/binary_split0")
i.LD("in binary", value)
w("function craftboy:util/binary_split1")
for b = 0, 7 do
w("scoreboard players operation " .. b .. "_0 binary *= " .. b ..
"_1 binary")
end
w("function craftboy:util/binary_join0")
-- ZFLAG
w("scoreboard players set zflag_AND_A craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set zflag_AND_A craftboy 1")
i.LD("A registers", "out binary")
w("scoreboard players operation Z flags = zflag_AND_A craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 1")
w("scoreboard players set C flags 0")
end
function i.XOR_A(value)
w("#XOR_A")
i.LD("in binary", "A registers")
w("function craftboy:util/binary_split0")
i.LD("in binary", value)
w("function craftboy:util/binary_split1")
for b = 0, 7 do
w("scoreboard players operation " .. b .. "_0 binary -= " .. b ..
"_1 binary")
w("scoreboard players operation " .. b .. "_0 binary *= " .. b ..
"_0 binary")
end
w("function craftboy:util/binary_join0")
-- ZFLAG
w("scoreboard players set zflag_XOR_A craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set zflag_XOR_A craftboy 1")
i.LD("A registers", "out binary")
w("scoreboard players operation Z flags = zflag_XOR_A craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players set C flags 0")
end
function i.OR_A(value)
w("#OR_A")
i.LD("in binary", "A registers")
w("function craftboy:util/binary_split0")
i.LD("in binary", value)
w("function craftboy:util/binary_split1")
for b = 0, 7 do
w("execute if score " .. b ..
"_1 binary matches 1 run scoreboard players set " .. b ..
"_0 binary 1")
end
w("function craftboy:util/binary_join0")
-- ZFLAG
w("scoreboard players set zflag_OR_A craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set zflag_OR_A craftboy 1")
i.LD("A registers", "out binary")
w("scoreboard players operation Z flags = zflag_OR_A craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players set C flags 0")
end
function i.CP_A(value)
w("#CP_A")
i.LD("tmp_SUB_A craftboy", "A registers")
i.LD("tmp2_SUB craftboy", "A registers")
w("scoreboard players operation tmp_SUB_A craftboy -= " .. value)
-- HFLAG
i.GET_LO8("tmp2_SUB craftboy")
i.LD("tmp0_SUB craftboy", "out binary")
i.GET_LO8(value)
i.LD("tmp1_SUB craftboy", "out binary")
w("scoreboard players set hflag_SUB craftboy 0")
w(
"execute if score tmp1_SUB craftboy > tmp0_SUB craftboy run scoreboard players set hflag_SUB craftboy 1")
-- CFLAG
w("scoreboard players set cflag_SUB craftboy 0")
w("execute if score " .. value ..
" > tmp2_SUB craftboy run scoreboard players set cflag_SUB craftboy 1")
w(
"execute if score tmp_SUB_A craftboy matches ..-1 run scoreboard players add tmp_SUB_A craftboy 256")
-- ZFLAG
w("scoreboard players set zflag_SUB craftboy 0")
w(
"execute if score tmp_SUB_A craftboy matches 0 run scoreboard players set zflag_SUB craftboy 1")
w("scoreboard players operation Z flags = zflag_SUB craftboy")
w("scoreboard players set N flags 1")
w("scoreboard players operation H flags = hflag_SUB craftboy")
w("scoreboard players operation C flags = cflag_SUB craftboy")
end
function i.DI()
w("#DI")
w("scoreboard players set IME registers 0")
end
function i.EI()
w("#EI")
w("scoreboard players set SET_IME_0 craftboy 1")
end
function i.RLC(value)
w("#RLC")
i.LD("in binary", value)
w("function craftboy:util/binary_split0")
i.LD("tmp_RLC craftboy", "7_0 binary")
i.LD("7_0 binary", "6_0 binary")
i.LD("6_0 binary", "5_0 binary")
i.LD("5_0 binary", "4_0 binary")
i.LD("4_0 binary", "3_0 binary")
i.LD("3_0 binary", "2_0 binary")
i.LD("2_0 binary", "1_0 binary")
i.LD("1_0 binary", "0_0 binary")
i.LD("0_0 binary", "tmp_RLC craftboy")
w("function craftboy:util/binary_join0")
i.LD(value, "out binary")
-- ZFLAG
w("scoreboard players set zflag_RLC craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set zflag_RLC craftboy 1")
w("scoreboard players operation Z flags = zflag_RLC craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = tmp_RLC craftboy")
end
function i.RRC(value)
w("#RRC")
i.LD("in binary", value)
w("function craftboy:util/binary_split0")
i.LD("tmp_RRC craftboy", "0_0 binary")
i.LD("0_0 binary", "1_0 binary")
i.LD("1_0 binary", "2_0 binary")
i.LD("2_0 binary", "3_0 binary")
i.LD("3_0 binary", "4_0 binary")
i.LD("4_0 binary", "5_0 binary")
i.LD("5_0 binary", "6_0 binary")
i.LD("6_0 binary", "7_0 binary")
i.LD("7_0 binary", "tmp_RRC craftboy")
w("function craftboy:util/binary_join0")
i.LD(value, "out binary")
-- ZFLAG
w("scoreboard players set zflag_RRC craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set zflag_RRC craftboy 1")
w("scoreboard players operation Z flags = zflag_RRC craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = tmp_RRC craftboy")
end
function i.RL(value)
w("#RL")
i.LD("in binary", value)
w("function craftboy:util/binary_split0")
i.LD("tmp_RL craftboy", "7_0 binary")
i.LD("7_0 binary", "6_0 binary")
i.LD("6_0 binary", "5_0 binary")
i.LD("5_0 binary", "4_0 binary")
i.LD("4_0 binary", "3_0 binary")
i.LD("3_0 binary", "2_0 binary")
i.LD("2_0 binary", "1_0 binary")
i.LD("1_0 binary", "0_0 binary")
i.LD("0_0 binary", "C flags")
w("function craftboy:util/binary_join0")
i.LD(value, "out binary")
-- ZFLAG
w("scoreboard players set zflag_RL craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set zflag_RL craftboy 1")
w("scoreboard players operation Z flags = zflag_RL craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = tmp_RL craftboy")
end
function i.RR(value)
w("#RR")
i.LD("in binary", value)
w("function craftboy:util/binary_split0")
i.LD("tmp_RR craftboy", "0_0 binary")
i.LD("0_0 binary", "1_0 binary")
i.LD("1_0 binary", "2_0 binary")
i.LD("2_0 binary", "3_0 binary")
i.LD("3_0 binary", "4_0 binary")
i.LD("4_0 binary", "5_0 binary")
i.LD("5_0 binary", "6_0 binary")
i.LD("6_0 binary", "7_0 binary")
i.LD("7_0 binary", "C flags")
w("function craftboy:util/binary_join0")
i.LD(value, "out binary")
-- ZFLAG
w("scoreboard players set zflag_RR craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set zflag_RR craftboy 1")
w("scoreboard players operation Z flags = zflag_RR craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = tmp_RR craftboy")
end
function i.SLA(value)
w("#SLA")
i.LD("in binary", value)
w("function craftboy:util/binary_split0")
i.LD("cflag_SLA craftboy", "7_0 binary")
i.LD("7_0 binary", "6_0 binary")
i.LD("6_0 binary", "5_0 binary")
i.LD("5_0 binary", "4_0 binary")
i.LD("4_0 binary", "3_0 binary")
i.LD("3_0 binary", "2_0 binary")
i.LD("2_0 binary", "1_0 binary")
i.LD("1_0 binary", "0_0 binary")
w("scoreboard players set 0_0 binary 0")
w("function craftboy:util/binary_join0")
i.LD(value, "out binary")
-- ZFLAG
w("scoreboard players set zflag_SLA craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set zflag_SLA craftboy 1")
w("scoreboard players operation Z flags = zflag_SLA craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = cflag_SLA craftboy")
end
function i.SRA(value)
w("#SRA")
i.LD("in binary", value)
w("function craftboy:util/binary_split0")
i.LD("cflag_SRA craftboy", "0_0 binary")
i.LD("0_0 binary", "1_0 binary")
i.LD("1_0 binary", "2_0 binary")
i.LD("2_0 binary", "3_0 binary")
i.LD("3_0 binary", "4_0 binary")
i.LD("4_0 binary", "5_0 binary")
i.LD("5_0 binary", "6_0 binary")
i.LD("6_0 binary", "7_0 binary")
w("function craftboy:util/binary_join0")
i.LD(value, "out binary")
-- ZFLAG
w("scoreboard players set zflag_SRA craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set zflag_SRA craftboy 1")
w("scoreboard players operation Z flags = zflag_SRA craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = cflag_SRA craftboy")
end
function i.SWAP(value)
w("#SWAP")
i.GET_HI8(value)
i.LD("tmp_SWAP craftboy", "out binary")
i.GET_LO8(value)
i.LD(value, "out binary")
w("scoreboard players operation " .. value .. " *= 16 constants")
w("scoreboard players operation " .. value .. " += tmp_SWAP craftboy")
-- ZFLAG
w("scoreboard players set zflag_SWAP craftboy 0")
w("execute if score " .. value ..
" matches 0 run scoreboard players set zflag_SWAP craftboy 1")
w("scoreboard players operation Z flags = zflag_SWAP craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players set C flags 0")
end
function i.SRL(value)
w("#SRL")
i.LD("in binary", value)
w("function craftboy:util/binary_split0")
i.LD("tmp_SRL craftboy", "0_0 binary")
i.LD("0_0 binary", "1_0 binary")
i.LD("1_0 binary", "2_0 binary")
i.LD("2_0 binary", "3_0 binary")
i.LD("3_0 binary", "4_0 binary")
i.LD("4_0 binary", "5_0 binary")
i.LD("5_0 binary", "6_0 binary")
i.LD("6_0 binary", "7_0 binary")
i.LD("7_0 binary", "0 constants")
w("function craftboy:util/binary_join0")
i.LD(value, "out binary")
-- ZFLAG
w("scoreboard players set zflag_SRL craftboy 0")
w(
"execute if score out binary matches 0 run scoreboard players set zflag_SRL craftboy 1")
w("scoreboard players operation Z flags = zflag_SRL craftboy")
w("scoreboard players set N flags 0")
w("scoreboard players set H flags 0")
w("scoreboard players operation C flags = tmp_SRL craftboy")
end
function i.BIT(index, value)
w("#BIT")
i.GET_BIT(value, index)