-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathez80.alm
1518 lines (1470 loc) · 36.3 KB
/
ez80.alm
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
define @ez80 @ez80
element @ez80.dummy
@ez80.unique = 0
element @ez80.breg
element b?: @ez80.breg * 003o + 030o
element nz?: @ez80.breg * 010o + 001o
element z?: @ez80.breg * 010o + 011o
element nc?: @ez80.breg * 010o + 021o
element c?: @ez80.breg * 003o + 031o
element po?: @ez80.breg * 010o + 041o
element pe?: @ez80.breg * 010o + 051o
nv? = po?
v? = pe?
element p?: @ez80.breg * 010o + 061o
element m?: @ez80.breg * 010o + 071o
element d?: @ez80.breg * 003o + 032o
element e?: @ez80.breg * 003o + 033o
element h?: @ez80.breg * 003o + 034o
element ixh?: @ez80.breg * 335o + 034o
element iyh?: @ez80.breg * 375o + 034o
element l?: @ez80.breg * 003o + 035o
element ixl?: @ez80.breg * 335o + 035o
element iyl?: @ez80.breg * 375o + 035o
element f?: @ez80.breg * 002o + 036o
element a?: @ez80.breg * 003o + 037o
element @ez80.irmb
element i?: @ez80.irmb * 107o + 127o
element r?: @ez80.irmb * 117o + 137o
element mb?: @ez80.irmb * 155o + 156o
element @ez80.wreg
element bc?: @ez80.wreg * 007o + 000o
element de?: @ez80.wreg * 007o + 020o
element hl?: @ez80.wreg * 007o + 040o
element ix?: @ez80.wreg * 335o + 040o
element iy?: @ez80.wreg * 375o + 040o
element sp?: @ez80.wreg * 006o + 060o
element af?: @ez80.wreg * 001o + 060o
element af'? ;'
calminstruction assume? value&
match =adl? == value, value
jno chain
compute value, value
check value and not 1
jyes errassume
compute @ez80.l, value * 11o
compute @ez80.il, value * 22o
compute @ez80.ws, value + word?
compute @ez80.adl, value
exit
errassume:
err 'invalid assume adl, expected 0 or 1'
exit
chain:
execute =assume? value
end calminstruction
assume? adl = 1
?long? = 3
iterate <name,size,cond>, w,word,no, l,long,yes
calminstruction d#name? data*&
proxy current
local count, sequence, duplicate
check @ez80.adl
j#cond repeatend
execute =emit? =size?: data
exit
loop:
arrange count, current, 0
arrange sequence,
arrange data,
match count =dup? sequence, current, ()
match sequence =, data, sequence, ()
match current =, count, count, ()
jno splitend
splitloop:
match ?, current
jyes splitreserve
execute =@ez80.=word =size?, @current
jump splitnext
splitreserve:
execute =rl? 1
splitnext:
match current =, count, count, ()
jyes splitloop
splitend:
compute count, count
check count
jno repeatend
repeatloop:
match ?, current
arrange duplicate, sequence
match ( duplicate ), sequence
repeatsplitloop:
split current, duplicate
match ?, current
jyes repeatreserve
execute =@ez80.=word =size?, @current
jump repeatnext
repeatreserve:
execute =rl? 1
repeatnext:
jyes repeatsplitloop
compute count, count - 1
check count
jyes repeatloop
repeatend:
match current, data
jyes loop
end calminstruction
calminstruction r#name? count*
execute =emit? =size?: count =dup ?
end calminstruction
iterate type, d, r
calminstruction (label) type#name? parameters&
execute =label label: =size?
execute =type#=name parameters
end calminstruction
end iterate
end iterate
calminstruction @ez80.word size*, value*
emit size, value
end calminstruction
calminstruction @ez80.calminstruction name&
local suffix, parameters, instructions
once arrange instructions, @ez80.instructions
match name suffix, name
arrange name, name=?
check definite name
jyes definite
publish name, @ez80.dummy
definite:
arrange parameters,
match suffix= parameters, suffix
match ., suffix
jyes nosuffix
arrange name, name#suffix
nosuffix:
publish :instructions, name
execute =calminstruction name parameters
end calminstruction
macro ?! isreg: metadata 1 element 1 eq @ez80
local size, value
macro calminstruction?.isindirect? argument*
unique done
local isindirect
match ( isindirect ), argument
bno done
match isindirect, isindirect, ()
label done
end macro
macro calminstruction?.indexprefix? argument*
unique done
local index
compute index, argument metadata 1 scale 1
check index > 300o
bno done
emit 1, index
label done
end macro
macro calminstruction?.indexoffset? argument*
unique errrange, index, done
local offset
compute offset, argument scale 0
byes index
check offset
bno done
err 'invalid offset'
exit
label errrange
err 'offset out of range'
exit
label index
check offset >= -200o & offset < 200o
bno errrange
emit 1, offset
label done
end macro
macro calminstruction?.regsize? result*, reg*
unique word, done
check reg isreg.wreg
byes word
compute result, byte?
branch done
label word
compute result, @ez80.ws
label done
end macro
iterate <suffixsize,suffixname,suffixencoding,suffixadjustment, wordsize>, \
2, , , ,=@ez80.=ws, \
3, s?, 100o, il,=@ez80.=ws, \
3, l?, 111o, il,=@ez80.=ws, \
3, is?, 100o, l , =word?, \
3, il?, 122o, l , =long?, \
3, sis?, 100o, , =word?, \
3, lis?, 111o, , =word?, \
3, sil?, 122o, , =long?, \
3, lil?, 133o, , =long?
match adjustment, suffixadjustment
macro calminstruction?.emitsuffix?
emit 1, suffixencoding or @ez80.adjustment
end macro
else match encoding, suffixencoding
macro calminstruction?.emitsuffix?
emit 1, suffixencoding
end macro
else
macro calminstruction?.emitsuffix?
end macro
end match
iterate <name*, encoding*>, \
nop ,< 000o>, \
rlca ,< 007o>, \
rrca ,< 017o>, \
rla ,< 027o>, \
rra ,< 037o>, \
daa ,< 047o>, \
cpl ,< 057o>, \
scf ,< 067o>, \
ccf ,< 077o>, \
halt ,< 166o>, \
exx ,< 331o>, \
di ,< 363o>, \
ei ,< 373o>, \
neg ,<355o, 104o>, \
retn ,<355o, 105o>, \
reti ,<355o, 115o>, \
rrd ,<355o, 147o>, \
rld ,<355o, 157o>, \
slp ,<355o, 166o>, \
stmix ,<355o, 175o>, \
rsmix ,<355o, 176o>, \
inim ,<355o, 202o>, \
otim ,<355o, 203o>, \
ini2 ,<355o, 204o>, \
indm ,<355o, 212o>, \
otdm ,<355o, 213o>, \
ind2 ,<355o, 214o>, \
inimr ,<355o, 222o>, \
otimr ,<355o, 223o>, \
ini2r ,<355o, 224o>, \
indmr ,<355o, 232o>, \
otdmr ,<355o, 233o>, \
ind2r ,<355o, 234o>, \
ldi ,<355o, 240o>, \
cpi ,<355o, 241o>, \
ini ,<355o, 242o>, \
outi ,<355o, 243o>, \
outi2 ,<355o, 244o>, \
ldd ,<355o, 250o>, \
cpd ,<355o, 251o>, \
ind ,<355o, 252o>, \
outd ,<355o, 253o>, \
outd2 ,<355o, 254o>, \
ldir ,<355o, 260o>, \
cpir ,<355o, 261o>, \
inir ,<355o, 262o>, \
otir ,<355o, 263o>, \
oti2r ,<355o, 264o>, \
lddr ,<355o, 270o>, \
cpdr ,<355o, 271o>, \
indr ,<355o, 272o>, \
otdr ,<355o, 273o>, \
otd2r ,<355o, 274o>, \
inirx ,<355o, 302o>, \
otirx ,<355o, 303o>, \
indrx ,<355o, 312o>, \
otdrx ,<355o, 313o>
virtual
match suffix, suffixencoding
emit 1: suffix
end match
emit 1: encoding
size = $ - $$
load value: size from $$
end virtual
repeat 1, size: size, value: value
match adjustment, suffixadjustment
@ez80.calminstruction name.suffixname
emit size, value or @ez80.adjustment
end calminstruction
else
@ez80.calminstruction name.suffixname
emit size, value
end calminstruction
end match
end repeat
end iterate
iterate name, inc, dec
repeat 1, wordencoding: % shl 3 - 005o, byteencoding: % + 003o, \
indirectencoding: % + 063o
@ez80.calminstruction name.suffixname lhs*
isindirect lhs
compute lhs, lhs
jyes indirect
emitsuffix
indexprefix lhs
check lhs isreg.wreg & lhs metadata 1 scale 1 and 004o
jno byte
emit 1, lhs metadata 1 scale 0 + wordencoding
exit
byte:
check lhs isreg.breg & lhs metadata 1 scale 1 and 001o
jno errarguments
emit 1, lhs metadata 1 scale 0 shl 3 and 070o or byteencoding
exit
indirect:
check lhs relativeto lhs element 1 & lhs isreg.wreg & \
lhs metadata 1 scale 0 = 040o
jno errarguments
emitsuffix
indexprefix lhs
emit 1, indirectencoding
indexoffset lhs
exit
errarguments:
err 'invalid arguments'
end calminstruction
end repeat
end iterate
@ez80.calminstruction ex.suffixname lhs*, rhs*
local lhsvalue, rhsvalue
isindirect lhs
jyes memory
isindirect rhs
jyes swap
compute lhsvalue, lhs
compute rhsvalue, rhs
check (lhsvalue eq de? & rhsvalue eq hl?) | \
(rhsvalue eq de? & lhsvalue eq hl?)
jno notdehl
emitsuffix
emit 1, 353o
exit
notdehl:
check (lhsvalue eq af? & rhsvalue eq af'?) | \
(rhsvalue eq af? & lhsvalue eq af'?)
jno errarguments
emitsuffix
emit 1, 010o
exit
swap:
compute rhsvalue, lhs
compute lhsvalue, rhs
jump swapped
memory:
isindirect rhs
jyes errindirection
compute lhsvalue, lhs
compute rhsvalue, rhs
swapped:
check lhsvalue eq sp? & rhsvalue eq rhsvalue element 1 & \
rhsvalue metadata 1 scale 0 = 040o
jno errarguments
emitsuffix
indexprefix rhsvalue
emit 1, 343o
exit
errindirection:
err 'invalid indirection'
exit
errarguments:
err 'invalid arguments'
end calminstruction
@ez80.calminstruction djnz.suffixname lhs*
local offset
isindirect lhs
jyes errindirection
compute offset, lhs - $ - suffixsize
emitsuffix
emit 1, 020o
emit 1, offset
check -200o <= offset & offset < 200o
jno errrange
exit
errindirection:
err 'invalid indirection'
exit
errrange:
err 'offset out of range'
end calminstruction
@ez80.calminstruction jr.suffixname lhs*, rhs
local offset
isindirect lhs
jyes errindirection
match , rhs
jyes unconditional
isindirect rhs
jyes errindirection
compute lhs, lhs
check lhs eq lhs element 1 & lhs isreg.breg & \
lhs metadata 1 scale 0 and 047o = 001o
jno errcondition
compute offset, rhs - $ - suffixsize
emitsuffix
emit 1, lhs metadata 1 scale 0 and 030o or 040o
emit 1, offset
check -200o <= offset & offset < 200o
jno errrange
exit
unconditional:
compute offset, lhs - $ - suffixsize
emitsuffix
emit 1, 030o
emit 1, offset
check -200o <= offset & offset < 200o
jno errrange
exit
errindirection:
err 'invalid indirection'
exit
errcondition:
err 'invalid condition'
exit
errrange:
err 'offset out of range'
end calminstruction
@ez80.calminstruction jq.suffixname lhs*, rhs
local after, offset, address
proxy rhs
compute after, @ez80.unique
compute @ez80.unique, after + 1
arrange after, =@ez80.=unique#after
match , rhs
jno conditional
arrange rhs, lhs
arrange lhs,
conditional:
isindirect rhs
jyes errindirection
check rhs relativeto after
jno far
compute offset, rhs - after
check offset & offset <> -suffixsize | definite rhs
jno after
check -200o <= offset & offset < 200o
jno far
match , lhs
jyes nearunconditional
compute lhs, lhs
check lhs eq lhs element 1 & lhs isreg.breg & \
lhs metadata 1 scale 0 and 047o = 001o
jno farconditional
emitsuffix
emit 1, lhs metadata 1 scale 0 and 030o or 040o
emit 1, offset
jump after
nearunconditional:
emitsuffix
emit 1, 030o
emit 1, offset
jump after
far:
match , lhs
jyes farunconditional
compute lhs, lhs
farconditional:
check lhs eq lhs element 1 & lhs isreg.breg & \
lhs metadata 1 scale 0 and 007o = 001o
jno errcondition
emitsuffix
emit 1, lhs metadata 1 scale 0 and 070o or 302o
execute =@ez80.=word wordsize, @rhs
jump after
farunconditional:
emitsuffix
emit 1, 303o
execute =@ez80.=word wordsize, @rhs
after:
compute address, $?
publish after:, address
exit
errindirection:
err 'invalid indirection'
exit
errcondition:
err 'invalid condition'
end calminstruction
@ez80.calminstruction ld.suffixname lhs*, rhs*
local opcode, prefix
proxy lhs, rhs
isindirect lhs
compute lhs, +lhs
jyes isstore
isindirect rhs
compute rhs, +rhs
jyes isload
check lhs eq lhs element 1
jno errarguments
check lhs isreg.breg
jno notbyte
check rhs eq rhs element 1 & rhs isreg.breg & \
lhs metadata 1 scale 1 and rhs metadata 1 scale 1 and 001o & \
(lhs metadata 1 scale 0 xor rhs metadata 1 scale 0 and 006o | \
lhs metadata 1 scale 1 = rhs metadata 1 scale 1) & \
(~lhs eq rhs | lhs metadata 1 scale 0 > 033o)
jno notgetsetbyte
emitsuffix
compute prefix, lhs metadata 1 scale 1
check prefix > 300o
jyes byteindex
compute prefix, rhs metadata 1 scale 1
check prefix > 300o
jno notbyteindex
byteindex:
emit 1, prefix
notbyteindex:
emit 1, lhs metadata 1 scale 0 shl 3 and 070o + \
rhs metadata 1 scale 0 and 007o or 100o
exit
notgetsetbyte:
check lhs eq a? & rhs eq rhs element 1 & rhs isreg.irmb
jno notgetirmb
emitsuffix
emit 1, 355o
emit 1, rhs metadata 1 scale 0
exit
notgetirmb:
check lhs metadata 1 scale 1 and 001o
jno errarguments
emitsuffix
indexprefix lhs
emit 1, lhs metadata 1 scale 0 shl 3 and 070o or 006o
emit 1, rhs
exit
notbyte:
check lhs isreg.wreg & lhs metadata 1 scale 1 and 004o
jno notword
check lhs eq sp? & rhs eq rhs element 1 & rhs isreg.wreg & \
rhs metadata 1 scale 0 = 040o
jno notsetsp
emitsuffix
indexprefix rhs
emit 1, 371o
exit
notsetsp:
check lhs eq hl? & rhs eq i?
jno setwordimmediate
emitsuffix
emit 1, 355o
emit 1, 327o
exit
setwordimmediate:
emitsuffix
indexprefix lhs
emit 1, lhs metadata 1 scale 0 or 001o
execute =@ez80.=word wordsize, @rhs
exit
notword:
check lhs isreg.irmb & rhs eq a?
jno notsetirmb
emitsuffix
emit 1, 355o
emit 1, lhs metadata 1 scale 1
exit
notsetirmb:
check lhs eq i? & rhs eq hl?
jno errarguments
emitsuffix
emit 1, 355o
emit 1, 307o
exit
isstore:
isindirect rhs
jyes errindirection
compute rhs, +rhs
check lhs relativeto lhs element 1 & lhs isreg.wreg
jno notstoretowordregister
check lhs metadata 1 scale 0 = 040o
jno notstoretowordaccumulator
check rhs eq rhs element 1 & rhs isreg.breg & \
rhs metadata 1 scale 1 = 003o
jno notstoretowordaccumulatorfrombyte
emitsuffix
indexprefix lhs
emit 1, rhs metadata 1 scale 0 and 007o or 160o
indexoffset lhs
exit
notstoretowordaccumulatorfrombyte:
check rhs eq rhs element 1 & rhs isreg.wreg & \
rhs metadata 1 scale 1 and 005o = 005o
jno storetowordaccumulatorfrombyte
compute opcode, rhs metadata 1 scale 0 or 017o
check rhs metadata 1 scale 1 > 300o
jno storetowordaccumulator
check lhs metadata 1 scale 1 xor rhs metadata 1 scale 1 and 040o
jno notstorematchingindex
compute opcode, opcode + 017o
jump storetowordaccumulator
notstorematchingindex:
compute opcode, opcode + 020o
storetowordaccumulator:
check lhs metadata 1 scale 1 > 300o
jno notstoretoindex
emitsuffix
indexprefix lhs
emit 1, opcode
indexoffset lhs
exit
notstoretoindex:
check lhs scale 0
jyes errarguments
emitsuffix
emit 1, 355o
emit 1, opcode
exit
storetowordaccumulatorfrombyte:
emitsuffix
indexprefix lhs
emit 1, 066o
indexoffset lhs
emit 1, rhs
exit
notstoretowordaccumulator:
check lhs metadata 1 scale 0 < 040o & rhs eq a?
jno errarguments
emitsuffix
emit 1, lhs metadata 1 scale 0 or 002o
exit
notstoretowordregister:
check rhs eq a?
jno notstorefroma
emitsuffix
emit 1, 062o
execute =@ez80.=word wordsize, @lhs
exit
notstorefroma:
check rhs eq rhs element 1 & rhs isreg.wreg & \
rhs metadata 1 scale 1 and 004o
jno errarguments
check rhs metadata 1 scale 0 = 040o
jno notstorefromindex
emitsuffix
indexprefix rhs
emit 1, 042o
execute =@ez80.=word wordsize, @lhs
exit
notstorefromindex:
emitsuffix
emit 1, 355o
emit 1, rhs metadata 1 scale 0 or 103o
execute =@ez80.=word wordsize, @lhs
exit
isload:
check lhs eq lhs element 1
jno errarguments
check rhs relativeto rhs element 1 & rhs isreg.wreg
jno notloadwordregister
check rhs metadata 1 scale 0 = 040o
jno loadotherwordregister
check lhs isreg.breg & lhs metadata 1 scale 1 = 003o
jno notloadbyte
emitsuffix
indexprefix rhs
emit 1, lhs metadata 1 scale 0 shl 3 and 070o or 106o
indexoffset rhs
exit
notloadbyte:
check lhs isreg.wreg & lhs metadata 1 scale 1 and 005o = 005o
jno errarguments
compute opcode, lhs metadata 1 scale 0 or 007o
check lhs metadata 1 scale 1 > 300o
jno notloadindex
check lhs metadata 1 scale 1 xor rhs metadata 1 scale 1 and 040o
jno loadsameindex
compute opcode, opcode + 012o
jump notloadindex
loadsameindex:
compute opcode, opcode + 020o
notloadindex:
compute prefix, rhs metadata 1 scale 1
emitsuffix
check prefix > 300o
jno notloadfromindex
emit 1, prefix
emit 1, opcode
; assume yes
indexoffset rhs
exit
notloadfromindex:
check rhs scale 0
jyes errarguments
emit 1, 355o
emit 1, opcode
exit
loadotherwordregister:
check lhs eq a? & rhs metadata 1 scale 0 < 040o
jno errarguments
emitsuffix
emit 1, rhs metadata 1 scale 0 or 012o
exit
notloadwordregister:
check lhs eq a?
jno notloadaimmediate
emitsuffix
emit 1, 072o
execute =@ez80.=word wordsize, @rhs
exit
notloadaimmediate:
check lhs isreg.wreg & lhs metadata 1 scale 1 and 004o
jno errarguments
check lhs metadata 1 scale 0 = 040o
jno loadotherwordimmediate
emitsuffix
indexprefix lhs
emit 1, 052o
execute =@ez80.=word wordsize, @rhs
exit
loadotherwordimmediate:
emitsuffix
emit 1, 355o
emit 1, lhs metadata 1 scale 0 or 113o
execute =@ez80.=word wordsize, @rhs
exit
errindirection:
err 'invalid indirection'
exit
errarguments:
err 'invalid arguments'
end calminstruction
iterate <name,first,second>, ldp,lhs,rhs, ldrp,rhs,lhs
calminstruction calminstruction?.loadpair? lhs*, rhs*
execute =execute ===ld?.=suffixname first
execute =execute ===ld?.=suffixname second
end calminstruction
@ez80.calminstruction name.suffixname lhs*, mhs*, rhs*
proxy lhs, mhs, rhs, hs, ls, hi, lo
isindirect mhs
jyes errindirection
compute mhs, +mhs
isindirect lhs
compute lhs, +lhs
jyes isstore
isindirect rhs
compute rhs, +rhs
jyes isload
regsize hs, lhs
regsize ls, mhs
execute =virtual?
execute =emit? @hs + @ls, @rhs
execute =load? @hi: @hs =from? =$$? + @ls
execute =load? @lo: @ls =from? =$$?
execute =end? =virtual?
loadpair <@mhs, @lo>, <@lhs, @hi>
exit
isstore:
isindirect rhs
jyes errindirection
compute rhs, +rhs
regsize ls, rhs
loadpair <(@lhs), @rhs>, <(@lhs + @ls), @mhs>
exit
isload:
regsize ls, mhs
loadpair <@mhs, (@rhs)>, <@lhs, (@rhs + @ls)>
exit
errindirection:
err 'invalid indirection'
exit
end calminstruction
purge calminstruction?.loadpair?
end iterate
@ez80.calminstruction add.suffixname lhs*, rhs
match , rhs
jyes implicit
isindirect lhs
jyes errindirection
compute lhs, lhs
check lhs eq a?
jyes byte
isindirect rhs
jyes errindirection
compute rhs, rhs
check lhs eq lhs element 1 & lhs isreg.wreg & \
rhs eq rhs element 1 & lhs isreg.wreg & \
lhs metadata 1 scale 0 = 040o & rhs metadata 1 scale 1 and 004o & \
(lhs metadata 1 scale 0 <> rhs metadata 1 scale 0 | \
lhs metadata 1 scale 1 = rhs metadata 1 scale 1)
jno errarguments
emitsuffix
indexprefix lhs
emit 1, rhs metadata 1 scale 0 or 011o
exit
implicit:
arrange rhs, lhs
byte:
isindirect rhs
compute rhs, +rhs
jyes indirect
check rhs eq rhs element 1 & rhs isreg.breg & \
rhs metadata 1 scale 1 and 001o
jno immediate
emitsuffix
indexprefix rhs
emit 1, rhs metadata 1 scale 0 and 007o or 200o
exit
indirect:
check rhs relativeto rhs element 1 & rhs isreg.wreg & \
rhs metadata 1 scale 0 = 040o
jno errarguments
emitsuffix
indexprefix rhs
emit 1, 206o
indexoffset rhs
exit
immediate:
emitsuffix
emit 1, 306o
emit 1, rhs
exit
errindirection:
err 'invalid indirection'
exit
errarguments:
err 'invalid arguments'
end calminstruction
iterate name, adc, sbc
repeat 1, byteencoding: 170o + % shl 4, \
indirectencoding: 176o + % shl 4, \
wordencoding: 122o - % shl 3, \
immediateencoding: 276o + % shl 4
@ez80.calminstruction name.suffixname lhs*, rhs
match , rhs
jyes implicit
isindirect lhs
jyes errindirection
compute lhs, lhs
check lhs eq a?
jyes byte
isindirect rhs
jyes errindirection
compute rhs, rhs
check lhs eq hl? & rhs eq rhs element 1 & rhs isreg.wreg & \
rhs metadata 1 scale 1 and 002o
jno errarguments
emitsuffix
emit 1, 355o
emit 1, rhs metadata 1 scale 0 or wordencoding
exit
implicit:
arrange rhs, lhs
byte:
isindirect rhs
compute rhs, +rhs
jyes indirect
check rhs eq rhs element 1 & rhs isreg.breg & \
rhs metadata 1 scale 1 and 001o
jno immediate
emitsuffix
indexprefix rhs
emit 1, rhs metadata 1 scale 0 and 007o or byteencoding
exit
indirect:
check rhs relativeto rhs element 1 & rhs isreg.wreg & \
rhs metadata 1 scale 0 = 040o
jno errarguments
emitsuffix
indexprefix rhs
emit 1, indirectencoding
indexoffset rhs
exit
immediate:
emitsuffix
emit 1, immediateencoding
emit 1, rhs
exit
errindirection:
err 'invalid indirection'
exit
errarguments:
err 'invalid arguments'
end calminstruction
end repeat
end iterate
iterate <name*,encoding*>, sub,220o, and,240o, xor,250o, or,260o, cp,270o
repeat 1, indirectencoding: encoding or 006o, \
immediateencoding: encoding or 106o
@ez80.calminstruction name.suffixname lhs*, rhs
match , rhs
jyes implicit
isindirect lhs
jyes errindirection
check lhs eq a?
jno errarguments
arrange lhs, rhs
implicit:
isindirect lhs
compute lhs, +lhs
jyes indirect
check lhs relativeto lhs element 1 & lhs isreg.breg & \
lhs metadata 1 scale 1 and 001o
jno immediate
emitsuffix
indexprefix lhs
emit 1, lhs metadata 1 scale 0 and 007o or encoding
exit
indirect:
check lhs relativeto lhs element 1 & lhs isreg.wreg & \
lhs metadata 1 scale 0 = 040o
jno errarguments
emitsuffix
indexprefix lhs
emit 1, indirectencoding
indexoffset lhs
exit
immediate:
emitsuffix
emit 1, immediateencoding
emit 1, lhs
exit
errindirection:
err 'invalid indirection'
exit
errarguments:
err 'invalid arguments'
end calminstruction
end repeat
end iterate
@ez80.calminstruction tst.suffixname lhs*, rhs
match , rhs
jyes implicit
isindirect lhs
jyes errindirection
check lhs eq a?
jno errarguments
arrange lhs, rhs
implicit:
isindirect lhs
jyes indirect
compute lhs, +lhs
check lhs eq lhs element 1 & lhs isreg.breg & \
lhs metadata 1 scale 1 = 003o
jno immediate
emitsuffix
indexprefix lhs
emit 1, 355o
emit 1, lhs metadata 1 scale 0 shl 3 and 070o or 004o
exit
indirect:
check lhs eq hl?
jno errarguments
emitsuffix
emit 1, 355o
emit 1, 064o
exit
immediate:
emitsuffix
emit 1, 355o
emit 1, 144o
emit 1, lhs
exit
errindirection:
err 'invalid indirection'
exit
errarguments:
err 'invalid arguments'
end calminstruction
@ez80.calminstruction ret.suffixname lhs
match , lhs
jyes unconditional
isindirect lhs
jyes errindirection
compute lhs, lhs
check lhs eq lhs element 1 & lhs isreg.breg & \
lhs metadata 1 scale 0 and 007o = 001o
jno errarguments
emitsuffix
emit 1, lhs metadata 1 scale 0 and 070o or 300o
exit
unconditional:
emitsuffix
emit 1, 311o
exit