@@ -303,7 +303,21 @@ const OPCODES = {
303
303
cpu . zeroFlag = cpu . Y ;
304
304
}
305
305
} ,
306
- 0xA1 : "" ,
306
+ 0xA1 : {
307
+ name : "LDA (indirect,X)" , // Load Accumulator with Memory (Indirect Indexed Addressing with X)
308
+ t : 6 , // Cycles required
309
+ code : 0xA1 ,
310
+ run : ( cpu ) => {
311
+ const baseAddress = ( cpu . fetch ( ) + cpu . X ) & 0xFF ; // 0x00-0xFF (zeropage)
312
+ const lowByte = cpu . memory . readByte ( baseAddress ) ;
313
+ const highByte = cpu . memory . readByte ( ( baseAddress + 1 ) & 0xFF ) ; // wrap around in zeropage
314
+ const address = ( highByte << 8 ) | lowByte ; // 16-bit address
315
+
316
+ cpu . ACC = cpu . memory . readByte ( address ) ;
317
+ cpu . negativeFlag = cpu . ACC ;
318
+ cpu . zeroFlag = cpu . ACC ;
319
+ } ,
320
+ } ,
307
321
0xA2 : {
308
322
name : "LDX #immediate" , // Load Index X with Memory
309
323
t : 2 ,
@@ -316,7 +330,17 @@ const OPCODES = {
316
330
} ,
317
331
0xA3 : "" , // lax("(d,x)") // illegal
318
332
0xA4 : "" ,
319
- 0xA5 : "" ,
333
+ 0xA5 : {
334
+ name : "LDA zeropage" , // Load Accumulator with Memory from Zeropage
335
+ t : 3 ,
336
+ code : 0xA5 ,
337
+ run : ( cpu ) => {
338
+ const address = cpu . fetch ( ) ;
339
+ cpu . ACC = cpu . memory . readByte ( address ) ;
340
+ cpu . negativeFlag = cpu . ACC ;
341
+ cpu . zeroFlag = cpu . ACC ;
342
+ }
343
+ } ,
320
344
0xA6 : "" ,
321
345
0xA7 : "" , // illegal
322
346
0xA8 : {
@@ -351,23 +375,100 @@ const OPCODES = {
351
375
} ,
352
376
0xAB : "" , // lax("#i") // illegal
353
377
0xAC : "" ,
354
- 0xAD : "" ,
378
+ 0xAD : {
379
+ name : "LDA absolute" , // Load Accumulator Absolute
380
+ t : 4 ,
381
+ code : 0xAD ,
382
+ run : ( cpu ) => {
383
+ const lowByte = cpu . fetch ( ) ;
384
+ const highByte = cpu . fetch ( ) ;
385
+ const address = ( highByte << 8 ) | lowByte ;
386
+ cpu . ACC = cpu . memory . readByte ( address ) ;
387
+ cpu . negativeFlag = cpu . ACC ;
388
+ cpu . zeroFlag = cpu . ACC ;
389
+ }
390
+ } ,
355
391
0xAE : "" ,
356
392
0xAF : "" , // lax("a") // illegal
357
393
0xB0 : "" , // bcs("*+d")
358
- 0xB1 : "" , // lda("(d),y")
394
+ 0xB1 : {
395
+ name : "LDA (indirect),Y" , // Load Accumulator with Memory (Indirect) and Indexed Addressing with Y
396
+ t : 5 , // 5 (+1)
397
+ code : 0xB1 ,
398
+ run : ( cpu ) => {
399
+ const baseAddress = cpu . fetch ( ) ;
400
+ const lowByte = cpu . memory . readByte ( baseAddress ) ;
401
+ const highByte = cpu . memory . readByte ( ( baseAddress + 1 ) & 0xFF ) ; // wrap around in zeropage
402
+ const address = ( highByte << 8 ) | lowByte + cpu . Y ; // 16-bit address
403
+
404
+ // Check if the address crosses a page boundary
405
+ if ( ( address & 0xFF00 ) !== ( ( highByte << 8 ) & 0xFF00 ) ) {
406
+ cpu . cycles += 1 ; // Add an extra cycle if a page boundary is crossed
407
+ }
408
+
409
+
410
+ cpu . ACC = cpu . memory . readByte ( address ) ;
411
+ cpu . negativeFlag = cpu . ACC ;
412
+ cpu . zeroFlag = cpu . ACC ;
413
+ } ,
414
+ } ,
359
415
0xB2 : "" , // stp_implied() // illegal
360
416
0xB3 : "" , // lax("(d),y") // illegal
361
417
0xB4 : "" ,
362
- 0xB5 : "" ,
418
+ 0xB5 : {
419
+ name : "LDA zeropage,X" , // Load Accumulator with X-Indexed Zero Page
420
+ t : 4 ,
421
+ code : 0xB5 ,
422
+ run : ( cpu ) => {
423
+ const baseAddress = cpu . fetch ( ) ;
424
+ const address = ( baseAddress + cpu . X ) & 0xFF ;
425
+ cpu . ACC = cpu . memory . readByte ( address ) ;
426
+ cpu . negativeFlag = cpu . ACC ;
427
+ cpu . zeroFlag = cpu . ACC ;
428
+ }
429
+ } ,
363
430
0xB6 : "" ,
364
431
0xB7 : "" , // lax("d,y") // illegal
365
432
0xB8 : "" , // clv_implied()
366
- 0xB9 : "" , // lda("a,y")
433
+ 0xB9 : {
434
+ name : "LDA absolute,Y" , // Load Accumulator with Memory (Absolute Addressing with Y offset)
435
+ t : 4 , // 4 (+1)
436
+ code : 0xB9 ,
437
+ run : ( cpu ) => {
438
+ const lowByte = cpu . fetch ( ) ;
439
+ const highByte = cpu . fetch ( ) ;
440
+ const address = ( ( highByte << 8 ) | lowByte ) + cpu . Y ; // Combine bytes and add Y register value
441
+ // Check if address crosses a page boundary
442
+ if ( ( address & 0xFF00 ) !== ( ( highByte << 8 ) & 0xFF00 ) ) {
443
+ cpu . cycles += 1 ; // Add an extra cycle if a page boundary is crossed
444
+ }
445
+
446
+ cpu . ACC = cpu . memory . readByte ( address ) ;
447
+ cpu . negativeFlag = cpu . ACC ;
448
+ cpu . zeroFlag = cpu . ACC ;
449
+ }
450
+ } ,
367
451
0xBA : "" , // tsx_implied()
368
452
0xBB : "" , // las("a,y") // illegal
369
453
0xBC : "" , // ldy("a,x")
370
- 0xBD : "" , // lda("a,x")
454
+ 0xBD : {
455
+ name : "LDA absolute,X" , // Load Accumulator with Memory (Absolute Addressing with X offset)
456
+ t : 4 , // 4 (+1)
457
+ code : 0xBD ,
458
+ run : ( cpu ) => {
459
+ const lowByte = cpu . fetch ( ) ;
460
+ const highByte = cpu . fetch ( ) ;
461
+ const address = ( ( highByte << 8 ) | lowByte ) + cpu . X ; // Combine bytes and add X register value
462
+ // Check if address crosses a page boundary
463
+ if ( ( address & 0xFF00 ) !== ( ( highByte << 8 ) & 0xFF00 ) ) {
464
+ cpu . cycles += 1 ; // Add an extra cycle if a page boundary is crossed
465
+ }
466
+
467
+ cpu . ACC = cpu . memory . readByte ( address ) ;
468
+ cpu . negativeFlag = cpu . ACC ;
469
+ cpu . zeroFlag = cpu . ACC ;
470
+ }
471
+ } ,
371
472
0xBE : "" , // ldx("a,y")
372
473
0xBF : "" , // lax("a,y") // illegal
373
474
0xC0 : "" , // cpy("#i")
0 commit comments