forked from ctyler/6502js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assembler.js
2915 lines (2519 loc) · 73.2 KB
/
assembler.js
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
/*
* 6502 assembler and simulator in Javascript
* (C)2006-2010 Stian Soreng - www.6502asm.com
*
* Adapted by Nick Morgan
* https://github.com/skilldrick/6502js
*
* Adapted by Chris Tyler
* https://github.com/ctyler/6502js
*
* Released under the GNU General Public License
* see http://gnu.org/licenses/gpl.html
*/
'use strict';
function SimulatorWidget(node) {
var $node = $(node);
var ui = UI();
var display = Display();
var screen = Screen();
var memory = Memory();
var labels = Labels();
var simulator = Simulator();
var assembler = Assembler();
var speed = document.getElementById("speed");
function initialize() {
stripText();
ui.initialize();
display.initialize();
screen.initialize();
simulator.reset();
$node.find('.assembleButton').click(function() {
assembler.assembleCode();
});
$node.find('.runButton').click(simulator.runBinary);
$node.find('.runButton').click(simulator.stopDebugger);
$node.find('.resetButton').click(simulator.reset);
$node.find('.hexdumpButton').click(assembler.hexdump);
$node.find('.disassembleButton').click(assembler.disassemble);
$node.find('.downloadButton').click(assembler.download);
$node.find('.uploadButton').click(assembler.upload);
$node.find('.debug').change(function() {
var debug = $(this).is(':checked');
if (debug) {
ui.debugOn();
simulator.enableDebugger();
} else {
ui.debugOff();
simulator.stopDebugger();
}
});
$node.find('.monitoring').change(function() {
ui.toggleMonitor();
simulator.toggleMonitor();
});
$node.find('.console').change(function() {
ui.toggleConsole();
simulator.toggleConsole();
});
$node.find('.start, .length').blur(simulator.handleMonitorRangeChange);
$node.find('.stepButton').click(simulator.debugExec);
$node.find('.gotoButton').click(simulator.gotoAddr);
$node.find('.notesButton').click(ui.showNotes);
var editor = $node.find('.code');
editor.on('keypress input', simulator.stop);
editor.on('keypress input', ui.initialize);
editor.keydown(ui.captureTabInEditor);
document.addEventListener('keydown',memory.storeKeydown);
/* $(document).keypress(memory.storeKeypress); */
simulator.handleMonitorRangeChange();
}
function stripText() {
//Remove leading and trailing space in textarea
var text = $node.find('.code').val();
text = text.replace(/^\n+/, '').replace(/\s+$/, '');
$node.find('.code').val(text);
}
function UI() {
var currentState;
var start = {
assemble: true,
run: [false, 'Run'],
reset: false,
hexdump: false,
disassemble: false,
debug: [false, false]
};
var assembled = {
assemble: false,
run: [true, 'Run'],
reset: true,
hexdump: true,
disassemble: true,
debug: [true, false]
};
var running = {
assemble: false,
run: [true, 'Stop'],
reset: true,
hexdump: false,
disassemble: false,
debug: [true, false]
};
var debugging = {
assemble: false,
reset: true,
hexdump: true,
disassemble: true,
debug: [true, true]
};
var postDebugging = {
assemble: false,
reset: true,
hexdump: true,
disassemble: true,
debug: [true, false]
};
function setState(state) {
$node.find('.assembleButton').attr('disabled', !state.assemble);
if (state.run) {
$node.find('.runButton').attr('disabled', !state.run[0]);
$node.find('.runButton').val(state.run[1]);
}
$node.find('.resetButton').attr('disabled', !state.reset);
$node.find('.hexdumpButton').attr('disabled', !state.hexdump);
$node.find('.disassembleButton').attr('disabled', !state.disassemble);
$node.find('.debug').attr('disabled', !state.debug[0]);
$node.find('.debug').attr('checked', state.debug[1]);
$node.find('.stepButton').attr('disabled', !state.debug[1]);
$node.find('.gotoButton').attr('disabled', !state.debug[1]);
currentState = state;
}
function initialize() {
setState(start);
}
function play() {
setState(running);
}
function stop() {
setState(assembled);
}
function debugOn() {
setState(debugging);
}
function debugOff() {
setState(postDebugging);
}
function assembleSuccess() {
setState(assembled);
}
function toggleMonitor() {
$node.find('.monitor').toggle();
}
function toggleConsole() {
var c = document.getElementById('textscreenarea');
if (c.style.display === "none") {
c.style.display = "block";
} else {
c.style.display = "none";
}
}
function showNotes() {
$node.find('.messages code').html($node.find('.notes').html());
}
function captureTabInEditor(e) {
// Tab Key
if (e.keyCode === 9) {
// Prevent focus loss
e.preventDefault();
// Insert tab at caret position (instead of losing focus)
var caretStart = this.selectionStart,
caretEnd = this.selectionEnd,
currentValue = this.value;
this.value = currentValue.substring(0, caretStart) + "\t" + currentValue.substring(caretEnd);
// Move cursor forwards one (after tab)
this.selectionStart = this.selectionEnd = caretStart + 1;
}
}
return {
initialize: initialize,
play: play,
stop: stop,
assembleSuccess: assembleSuccess,
debugOn: debugOn,
debugOff: debugOff,
toggleMonitor: toggleMonitor,
toggleConsole: toggleConsole,
showNotes: showNotes,
captureTabInEditor: captureTabInEditor
};
}
function Display() {
var displayArray = [];
var palette = [
"#000000", "#ffffff", "#880000", "#aaffee",
"#cc44cc", "#00cc55", "#0000aa", "#eeee77",
"#dd8855", "#664400", "#ff7777", "#333333",
"#777777", "#aaff66", "#0088ff", "#bbbbbb"
];
var ctx;
var width;
var height;
var pixelSize;
var numX = 32;
var numY = 32;
function initialize() {
var canvas = $node.find('.screen')[0];
width = canvas.width;
height = canvas.height;
pixelSize = width / numX;
ctx = canvas.getContext('2d');
reset();
}
function reset() {
ctx.fillStyle = "black";
ctx.fillRect(0, 0, width, height);
}
function updatePixel(addr) {
ctx.fillStyle = palette[memory.get(addr) & 0x0f];
var y = Math.floor((addr - 0x200) / 32);
var x = (addr - 0x200) % 32;
ctx.fillRect(x * pixelSize, y * pixelSize, pixelSize, pixelSize);
}
return {
initialize: initialize,
reset: reset,
updatePixel: updatePixel
};
}
function Screen() {
var numX = 80;
var numY = 25;
var screentable = document.getElementById("textscreen");
function initialize() {
for (var x = 0; x < numX; x++) {
for (var y = 0; y < numY; y++) {
screentable.rows[y].cells[x].style.color = "#000000";
screentable.rows[y].cells[x].style.background = "#ffffff";
screentable.rows[y].cells[x].innerHTML = " ";
}
}
}
function reset() {
initialize();
}
function updateChar(addr) {
var y = Math.floor((addr - 0xf000) / numX);
var x = (addr - 0xf000) % numX;
var c = memory.get(addr);
if ((c & 0x7f) < 33 || (c & 0x7f) > 126) {
var s = " "; // unprintable is blank
} else {
var s = String.fromCharCode(c & 0x7f);
}
if (c & 0x80) {
screentable.rows[y].cells[x].style.color = "#ffffff";
screentable.rows[y].cells[x].style.background = "#000000";
} else {
screentable.rows[y].cells[x].style.color = "#000000";
screentable.rows[y].cells[x].style.background = "#ffffff";
}
screentable.rows[y].cells[x].innerHTML = s;
}
return {
initialize: initialize,
reset: reset,
updateChar: updateChar
};
}
function Memory() {
var memArray = new Array(0xfe00);
memArray.push(0x48,0x8a,0x48,0x98,0x48,0xa4,0xf6,0xb9,0x1c,0xfe,0x18,0x65,0xf5,0x85,0xf7,0xb9,0x35,0xfe,0x69,0x00,0x85,0xf8,0x68,0xa8,0x68,0xaa,0x68,0x60,0x00,0x50,0xa0,0xf0,0x40,0x90,0xe0,0x30,0x80,0xd0,0x20,0x70,0xc0,0x10,0x60,0xb0,0x00,0x50,0xa0,0xf0,0x40,0x90,0xe0,0x30,0x80,0xf0,0xf0,0xf0,0xf0,0xf1,0xf1,0xf1,0xf2,0xf2,0xf2,0xf3,0xf3,0xf3,0xf4,0xf4,0xf4,0xf5,0xf5,0xf5,0xf5,0xf6,0xf6,0xf6,0xf7,0xf7,0xc9,0x08,0xf0,0x27,0xc9,0x0a,0xf0,0x3d,0xc9,0x0d,0xf0,0x39,0xc9,0x80,0xf0,0x7c,0xc9,0x81,0xf0,0x3b,0xc9,0x82,0xf0,0x64,0xc9,0x83,0xf0,0x45,0x20,0x00,0xfe,0x84,0xfd,0xa0,0x00,0x91,0xf7,0x20,0x9d,0xfe,0xa4,0xfd,0x60,0x48,0x98,0x48,0x8a,0x48,0x20,0xaf,0xfe,0x20,0x00,0xfe,0xa0,0x00,0xa9,0x20,0x91,0xf7,0xa6,0x50,0xca,0x68,0xaa,0x68,0xa8,0x68,0x60,0x48,0xa9,0x00,0x85,0xf5,0x20,0xca,0xfe,0x68,0x60,0x48,0xe6,0xf5,0xa9,0x50,0xc5,0xf5,0xd0,0x07,0xa9,0x00,0x85,0xf5,0x20,0xca,0xfe,0x68,0x60,0x48,0xc6,0xf5,0x10,0x14,0xa5,0xf6,0xf0,0x0a,0xa9,0x50,0x85,0xf5,0x20,0xda,0xfe,0x18,0x90,0x06,0xa9,0x00,0x85,0xf5,0x85,0xf6,0x68,0x60,0x48,0xe6,0xf6,0xa9,0x19,0xc5,0xf6,0xd0,0x05,0x20,0x2f,0xff,0xc6,0xf6,0x68,0x60,0xc6,0xf6,0x10,0x02,0xe6,0xf6,0x60,0x48,0x98,0x48,0xa9,0x00,0x85,0xf5,0x85,0xf6,0x20,0x00,0xfe,0xa0,0x00,0xa9,0x20,0x91,0xf7,0xc8,0xd0,0xfb,0xe6,0xf8,0xa5,0xf8,0xc9,0xf8,0xd0,0xf1,0x20,0x00,0xfe,0x68,0x98,0x68,0x60,0xa5,0xff,0xf0,0x06,0x48,0xa9,0x00,0x85,0xff,0x68,0x60,0xa0,0x19,0xa2,0x50,0x60,0xb0,0x0c,0x86,0xf5,0x84,0xf6,0x20,0x00,0xfe,0xa4,0xf8,0xa5,0xf7,0x60,0x20,0x00,0xfe,0xa0,0x00,0xb1,0xf7,0xa6,0xf5,0xa4,0xf6,0x60,0x48,0x98,0x48,0xa9,0x00,0x85,0xfb,0xa9,0x50,0x85,0xf9,0xa9,0xf0,0x85,0xfa,0x85,0xfc,0xa0,0x00,0xb1,0xf9,0x91,0xfb,0xc8,0xd0,0xf9,0xe6,0xfa,0xe6,0xfc,0xa9,0xf7,0xc5,0xfa,0xd0,0xef,0xb1,0xf9,0x91,0xfb,0xc8,0xc0,0x80,0xd0,0xf7,0xa0,0x00,0xa9,0x20,0x99,0x80,0xf7,0xc8,0xc0,0x50,0xd0,0xf8,0x68,0xa8,0x68,0x60,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4c,0xe1,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4c,0x05,0xff,0x4c,0x4e,0xfe,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x4c,0x10,0xff,0x4c,0x15,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00);
function set(addr, val) {
// write data if not in the ROM range
if ((addr >= 0x0000) && (addr < 0xfe00)) {
return memArray[addr] = val;
} else {
return False;
}
}
function get(addr) {
if (addr == 0xfe) {
memArray[addr] = Math.floor(Math.random() * 256);
}
return memArray[addr];
}
function getWord(addr) {
return get(addr) + (get(addr + 1) << 8);
}
// Poke a byte, don't touch any registers
function storeByte(addr, value) {
set(addr, value & 0xff);
if ((addr >= 0x200) && (addr <= 0x5ff)) {
display.updatePixel(addr);
}
if ((addr >= 0xf000) && (addr < 0xf000 + 80 * 25)) {
screen.updateChar(addr);
}
}
// Store keycode in ZP $ff
function storeKeydown(e) {
var value = e.key;
var code = 0;
if (value.length == 1) {
code = value.charCodeAt(0);
} else if (value == "ArrowUp") {
code = 0x80;
} else if (value == "ArrowRight") {
code = 0x81;
} else if (value == "ArrowDown") {
code = 0x82;
} else if (value == "ArrowLeft") {
code = 0x83;
} else if (value == "Enter") {
code = 0x0d;
} else if (value == "Backspace") {
code = 0x08;
}
if (code) {
memory.storeByte(0xff, code);
}
}
function format(start, length) {
var html = '';
var n;
for (var x = 0; x < length; x++) {
if ((x & 15) === 0) {
if (x > 0) {
html += "\n";
}
n = (start + x);
html += num2hex(((n >> 8) & 0xff));
html += num2hex((n & 0xff));
html += ": ";
}
html += num2hex(memory.get(start + x));
html += " ";
}
return html;
}
return {
set: set,
get: get,
getWord: getWord,
storeByte: storeByte,
storeKeydown: storeKeydown,
format: format
};
}
function Simulator() {
var regA = 0;
var regX = 0;
var regY = 0;
var regP = 0;
var regPC = 0x600;
var regSP = 0xff;
var codeRunning = false;
var debug = false;
var monitoring = false;
var showConsole = false;
// Set zero and negative processor flags based on result
function setNVflags(value) {
if (value) {
regP &= 0xfd;
} else {
regP |= 0x02;
}
if (value & 0x80) {
regP |= 0x80;
} else {
regP &= 0x7f;
}
}
function setCarryFlagFromBit0(value) {
regP = (regP & 0xfe) | (value & 1);
}
function setCarryFlagFromBit7(value) {
regP = (regP & 0xfe) | ((value >> 7) & 1);
}
function setNVflagsForRegA() {
setNVflags(regA);
}
function setNVflagsForRegX() {
setNVflags(regX);
}
function setNVflagsForRegY() {
setNVflags(regY);
}
var ORA = setNVflagsForRegA;
var AND = setNVflagsForRegA;
var EOR = setNVflagsForRegA;
var ASL = setNVflags;
var LSR = setNVflags;
var ROL = setNVflags;
var ROR = setNVflags;
var LDA = setNVflagsForRegA;
var LDX = setNVflagsForRegX;
var LDY = setNVflagsForRegY;
function BIT(value) {
if (value & 0x80) {
regP |= 0x80;
} else {
regP &= 0x7f;
}
if (value & 0x40) {
regP |= 0x40;
} else {
regP &= ~0x40;
}
if (regA & value) {
regP &= 0xfd;
} else {
regP |= 0x02;
}
}
function CLC() {
regP &= 0xfe;
}
function SEC() {
regP |= 1;
}
function CLV() {
regP &= 0xbf;
}
function setOverflow() {
regP |= 0x40;
}
function DEC(addr) {
var value = memory.get(addr);
value--;
value &= 0xff;
memory.storeByte(addr, value);
setNVflags(value);
}
function INC(addr) {
var value = memory.get(addr);
value++;
value &= 0xff;
memory.storeByte(addr, value);
setNVflags(value);
}
function jumpBranch(offset) {
if (offset > 0x7f) {
regPC = (regPC - (0x100 - offset));
} else {
regPC = (regPC + offset);
}
}
function overflowSet() {
return regP & 0x40;
}
function decimalMode() {
return regP & 8;
}
function carrySet() {
return regP & 1;
}
function negativeSet() {
return regP & 0x80;
}
function zeroSet() {
return regP & 0x02;
}
function doCompare(reg, val) {
if (reg >= val) {
SEC();
} else {
CLC();
}
val = (reg - val);
setNVflags(val);
}
function testSBC(value) {
var tmp, w;
if ((regA ^ value) & 0x80) {
setOverflow();
} else {
CLV();
}
if (decimalMode()) {
tmp = 0xf + (regA & 0xf) - (value & 0xf) + carrySet();
if (tmp < 0x10) {
w = 0;
tmp -= 6;
} else {
w = 0x10;
tmp -= 0x10;
}
w += 0xf0 + (regA & 0xf0) - (value & 0xf0);
if (w < 0x100) {
CLC();
if (overflowSet() && w < 0x80) {
CLV();
}
w -= 0x60;
} else {
SEC();
if (overflowSet() && w >= 0x180) {
CLV();
}
}
w += tmp;
} else {
w = 0xff + regA - value + carrySet();
if (w < 0x100) {
CLC();
if (overflowSet() && w < 0x80) {
CLV();
}
} else {
SEC();
if (overflowSet() && w >= 0x180) {
CLV();
}
}
}
regA = w & 0xff;
setNVflagsForRegA();
}
function testADC(value) {
var tmp;
if ((regA ^ value) & 0x80) {
CLV();
} else {
setOverflow();
}
if (decimalMode()) {
tmp = (regA & 0xf) + (value & 0xf) + carrySet();
if (tmp >= 10) {
tmp = 0x10 | ((tmp + 6) & 0xf);
}
tmp += (regA & 0xf0) + (value & 0xf0);
if (tmp >= 160) {
SEC();
if (overflowSet() && tmp >= 0x180) {
CLV();
}
tmp += 0x60;
} else {
CLC();
if (overflowSet() && tmp < 0x80) {
CLV();
}
}
} else {
tmp = regA + value + carrySet();
if (tmp >= 0x100) {
SEC();
if (overflowSet() && tmp >= 0x180) {
CLV();
}
} else {
CLC();
if (overflowSet() && tmp < 0x80) {
CLV();
}
}
}
regA = tmp & 0xff;
setNVflagsForRegA();
}
var instructions = {
i00: function() {
codeRunning = false;
//BRK
},
i01: function() {
var zp = (popByte() + regX) & 0xff;
var addr = memory.getWord(zp);
var value = memory.get(addr);
regA |= value;
ORA();
},
i05: function() {
var zp = popByte();
regA |= memory.get(zp);
ORA();
},
i06: function() {
var zp = popByte();
var value = memory.get(zp);
setCarryFlagFromBit7(value);
value = (value << 1) & 0xff;
memory.storeByte(zp, value);
ASL(value);
},
i08: function() {
stackPush(regP | 0x30);
//PHP
},
i09: function() {
regA |= popByte();
ORA();
},
i0a: function() {
setCarryFlagFromBit7(regA);
regA = (regA << 1) & 0xff;
ASL(regA);
},
i0d: function() {
regA |= memory.get(popWord());
ORA();
},
i0e: function() {
var addr = popWord();
var value = memory.get(addr);
setCarryFlagFromBit7(value);
value = (value << 1) & 0xff;
memory.storeByte(addr, value);
ASL(value);
},
i10: function() {
var offset = popByte();
if (!negativeSet()) {
jumpBranch(offset);
}
//BPL
},
i11: function() {
var zp = popByte();
var value = memory.getWord(zp) + regY;
regA |= memory.get(value);
ORA();
},
i15: function() {
var addr = (popByte() + regX) & 0xff;
regA |= memory.get(addr);
ORA();
},
i16: function() {
var addr = (popByte() + regX) & 0xff;
var value = memory.get(addr);
setCarryFlagFromBit7(value);
value = (value << 1) & 0xff;
memory.storeByte(addr, value);
ASL(value);
},
i18: function() {
CLC();
},
i19: function() {
var addr = popWord() + regY;
regA |= memory.get(addr);
ORA();
},
i1d: function() {
var addr = popWord() + regX;
regA |= memory.get(addr);
ORA();
},
i1e: function() {
var addr = popWord() + regX;
var value = memory.get(addr);
setCarryFlagFromBit7(value);
value = (value << 1) & 0xff;
memory.storeByte(addr, value);
ASL(value);
},
i20: function() {
var addr = popWord();
var currAddr = regPC - 1;
stackPush(((currAddr >> 8) & 0xff));
stackPush((currAddr & 0xff));
regPC = addr;
//JSR
},
i21: function() {
var zp = (popByte() + regX) & 0xff;
var addr = memory.getWord(zp);
var value = memory.get(addr);
regA &= value;
AND();
},
i24: function() {
var zp = popByte();
var value = memory.get(zp);
BIT(value);
},
i25: function() {
var zp = popByte();
regA &= memory.get(zp);
AND();
},
i26: function() {
var sf = carrySet();
var addr = popByte();
var value = memory.get(addr);
setCarryFlagFromBit7(value);
value = (value << 1) & 0xff;
value |= sf;
memory.storeByte(addr, value);
ROL(value);
},
i28: function() {
regP = stackPop() | 0x30; // There is no B bit!
//PLP
},
i29: function() {
regA &= popByte();
AND();
},
i2a: function() {
var sf = carrySet();
setCarryFlagFromBit7(regA);
regA = (regA << 1) & 0xff;
regA |= sf;
ROL(regA);
},
i2c: function() {
var value = memory.get(popWord());
BIT(value);
},
i2d: function() {
var value = memory.get(popWord());
regA &= value;
AND();
},
i2e: function() {
var sf = carrySet();
var addr = popWord();
var value = memory.get(addr);
setCarryFlagFromBit7(value);
value = (value << 1) & 0xff;
value |= sf;
memory.storeByte(addr, value);
ROL(value);
},
i30: function() {
var offset = popByte();
if (negativeSet()) {
jumpBranch(offset);
}
//BMI
},
i31: function() {
var zp = popByte();
var value = memory.getWord(zp) + regY;
regA &= memory.get(value);
AND();
},
i35: function() {
var addr = (popByte() + regX) & 0xff;
regA &= memory.get(addr);
AND();
},
i36: function() {
var sf = carrySet();
var addr = (popByte() + regX) & 0xff;
var value = memory.get(addr);
setCarryFlagFromBit7(value);
value = (value << 1) & 0xff;
value |= sf;
memory.storeByte(addr, value);
ROL(value);
},
i38: function() {
SEC();
},
i39: function() {
var addr = popWord() + regY;
var value = memory.get(addr);
regA &= value;
AND();
},
i3d: function() {
var addr = popWord() + regX;
var value = memory.get(addr);
regA &= value;
AND();
},
i3e: function() {
var sf = carrySet();
var addr = popWord() + regX;
var value = memory.get(addr);
setCarryFlagFromBit7(value);
value = (value << 1) & 0xff;
value |= sf;
memory.storeByte(addr, value);
ROL(value);
},
i40: function() {
regP = stackPop() | 0x30; // There is no B bit!
regPC = stackPop() | (stackPop() << 8);
//RTI
},
i41: function() {
var zp = (popByte() + regX) & 0xff;
var value = memory.getWord(zp);
regA ^= memory.get(value);
EOR();
},
i45: function() {
var addr = popByte() & 0xff;
var value = memory.get(addr);
regA ^= value;
EOR();
},
i46: function() {
var addr = popByte() & 0xff;
var value = memory.get(addr);
setCarryFlagFromBit0(value);
value = value >> 1;
memory.storeByte(addr, value);
LSR(value);
},
i48: function() {
stackPush(regA);
//PHA
},
i49: function() {
regA ^= popByte();
EOR();
},
i4a: function() {
setCarryFlagFromBit0(regA);
regA = regA >> 1;
LSR(regA);
},
i4c: function() {
regPC = popWord();
//JMP
},
i4d: function() {
var addr = popWord();
var value = memory.get(addr);
regA ^= value;
EOR();
},
i4e: function() {
var addr = popWord();
var value = memory.get(addr);
setCarryFlagFromBit0(value);
value = value >> 1;
memory.storeByte(addr, value);
LSR(value);
},
i50: function() {
var offset = popByte();
if (!overflowSet()) {
jumpBranch(offset);
}
//BVC
},
i51: function() {
var zp = popByte();
var value = memory.getWord(zp) + regY;
regA ^= memory.get(value);
EOR();
},
i55: function() {
var addr = (popByte() + regX) & 0xff;
regA ^= memory.get(addr);
EOR();
},
i56: function() {
var addr = (popByte() + regX) & 0xff;
var value = memory.get(addr);
setCarryFlagFromBit0(value);
value = value >> 1;
memory.storeByte(addr, value);
LSR(value);
},
i58: function() {
regP &= ~0x04;
throw new Error("Interrupts not implemented");
//CLI
},
i59: function() {
var addr = popWord() + regY;
var value = memory.get(addr);
regA ^= value;
EOR();
},
i5d: function() {