cpu/disasm: SBC insn, readme: update
This commit is contained in:
parent
18d0128fe0
commit
e662ac1338
17
cpu.c
17
cpu.c
@ -29,6 +29,12 @@ uint8_t cpu_adc(cpu_t*cpu,uint8_t x)
|
||||
return cpu->a+=x;
|
||||
}
|
||||
|
||||
// Increment cpu->a by x (for sequence point)
|
||||
uint8_t cpu_sbc(cpu_t*cpu,uint8_t x)
|
||||
{
|
||||
return cpu->a-=x;
|
||||
}
|
||||
|
||||
// Assign x to cpu->a (for sequence point)
|
||||
uint8_t cpu_assign(cpu_t*cpu,uint8_t x)
|
||||
{
|
||||
@ -112,6 +118,17 @@ void cpu_exec(cpu_t*cpu,ram_t*ram)
|
||||
case 0x61: adc( deref( fetch() + cpu->x ) ); sr_nz(cpu->a); incpc(); break;
|
||||
case 0x71: adc( deref( fetch() + cpu->y ) ); sr_nz(cpu->a); incpc(); break;
|
||||
|
||||
// SBC
|
||||
case 0xE5: sbc( deref( fetch() ) ); sr_nz(cpu->a); incpc(); break;
|
||||
case 0xE9: sbc( fetch() ); sr_nz(cpu->a); incpc(); break;
|
||||
case 0xF5: sbc( deref( fetch() + cpu->x ) ); sr_nz(cpu->a); incpc(); break;
|
||||
case 0xED: sbc( deref( fetch16() ) ); sr_nz(cpu->a); incpc(); break;
|
||||
case 0xFD: sbc( deref( fetch16() + cpu->x ) ); sr_nz(cpu->a); incpc(); break;
|
||||
case 0xF9: sbc( deref( fetch16() + cpu->y ) ); sr_nz(cpu->a); incpc(); break;
|
||||
// TODO Verify these are correct
|
||||
case 0xE1: sbc( deref( deref( fetch() + cpu->x ) ) ); sr_nz(cpu->a); incpc(); break;
|
||||
case 0xF1: sbc( deref( deref( fetch() + cpu->y ) ) ); sr_nz(cpu->a); incpc(); break;
|
||||
|
||||
// INC/DEC
|
||||
case 0xE6: ram->ram[ fetch() ] += 1; incpc(); break;
|
||||
case 0xF6: ram->ram[ fetch() + cpu->x ] += 1; incpc(); break;
|
||||
|
2
cpu.h
2
cpu.h
@ -74,6 +74,7 @@ typedef struct cpu_t
|
||||
|
||||
// Arithmetic micro-insns
|
||||
#define adc(x) (cpu_adc(__cpu,x))
|
||||
#define sbc(x) (cpu_sbc(__cpu,x))
|
||||
// TODO AND is not always for accumulator
|
||||
#define and(x) (__cpu->a &= (x))
|
||||
#define eor(x) (__cpu->a ^= (x))
|
||||
@ -101,5 +102,6 @@ cpu_t*cpu_init(void);
|
||||
void cpu_exec(cpu_t*cpu,ram_t*ram);
|
||||
uint16_t cpu_fetch(cpu_t*cpu);
|
||||
uint8_t cpu_adc(cpu_t*cpu,uint8_t x);
|
||||
uint8_t cpu_sbc(cpu_t*cpu,uint8_t x);
|
||||
uint8_t cpu_assign(cpu_t*cpu,uint8_t x);
|
||||
void cpu_push(cpu_t*cpu,ram_t*ram,uint8_t b);
|
||||
|
11
disasm.c
11
disasm.c
@ -135,6 +135,7 @@ void da_print_disassembly(cpu_t*cpu,ram_t*ram)
|
||||
case 0x98: p1( "tya" ); end();
|
||||
|
||||
// Arithmetic
|
||||
// ADC
|
||||
case 0x65: p2( "adc zp $%02X", imm_pk(1) ); end();
|
||||
case 0x69: p2( "adc #$%02X", imm_pk(1) ); end();
|
||||
case 0x75: p2( "adc zp $%02X,x", imm_pk(1) ); end();
|
||||
@ -145,6 +146,16 @@ void da_print_disassembly(cpu_t*cpu,ram_t*ram)
|
||||
case 0x61: p2( "adc ind ($%02X,x)", imm_pk(1) ); end();
|
||||
case 0x71: p2( "adc ind ($%02X),y", imm_pk(1) ); end();
|
||||
|
||||
// SBC
|
||||
case 0xE5: p2( "sbc zp $%02X", imm_pk(1) ); end();
|
||||
case 0xE9: p2( "sbc #$%02X", imm_pk(1) ); end();
|
||||
case 0xF5: p2( "sbc zp $%02X,x", imm_pk(1) ); end();
|
||||
case 0xED: p3( "sbc abs $%04X", imm16_pk(1) ); end();
|
||||
case 0xFD: p3( "sbc abs $%04X,x", imm16_pk(1) ); end();
|
||||
case 0xF9: p3( "sbc abs $%04X,y", imm16_pk(1) ); end();
|
||||
case 0xE1: p2( "sbc ind ($%02X,x)", imm_pk(1) ); end();
|
||||
case 0xF1: p2( "sbc ind ($%02X),y", imm_pk(1) ); end();
|
||||
|
||||
// INC/DEC
|
||||
case 0xE6: p2( "inc zp $%02X", imm_pk(1) ); end();
|
||||
case 0xF6: p2( "inc zp $%02X,x", imm_pk(1) ); end();
|
||||
|
6
disasm.h
6
disasm.h
@ -1,6 +1,6 @@
|
||||
#pragma once
|
||||
#include<ncurses.h>
|
||||
#include<yaml.h>
|
||||
//#include<yaml.h>
|
||||
#include<stdio.h>
|
||||
#include<stdlib.h>
|
||||
#include<string.h>
|
||||
@ -22,7 +22,7 @@
|
||||
// bytes: 1
|
||||
// ...
|
||||
|
||||
yaml_parser_t parser;
|
||||
yaml_event_t event;
|
||||
//yaml_parser_t parser;
|
||||
//yaml_event_t event;
|
||||
|
||||
void da_print_disassembly(cpu_t*cpu,ram_t*ram);
|
||||
|
18
readme.md
18
readme.md
@ -8,7 +8,21 @@ A 6502 CPU emulator/simulator with ncurses UI.
|
||||
|
||||
#### Usage
|
||||
|
||||
`65 FILE.NES`
|
||||
`./65 FILE.NES`
|
||||
|
||||
#### Building
|
||||
|
||||
Dependencies:
|
||||
|
||||
ncurses / pdcurses (on Windows)
|
||||
|
||||
To build using GNUMake:
|
||||
|
||||
make
|
||||
|
||||
To build using Ruby rake
|
||||
|
||||
rake
|
||||
|
||||
#### Key bindings:
|
||||
|
||||
@ -23,5 +37,7 @@ j.........Scroll down through hexdump
|
||||
|
||||
k.........Scroll up through hexdump
|
||||
|
||||
/.........Search for octet
|
||||
|
||||
q.........Quit program
|
||||
```
|
||||
|
21
test/nes.a65
21
test/nes.a65
@ -7,15 +7,22 @@ reg=$0102
|
||||
*=$8000
|
||||
main:
|
||||
|
||||
lda #$01
|
||||
tay
|
||||
ldx #$00
|
||||
|
||||
ldy #$55
|
||||
tya
|
||||
lda #$00
|
||||
sta $05,x
|
||||
|
||||
ldx #$44
|
||||
txs
|
||||
txa
|
||||
inx
|
||||
|
||||
lda #$10
|
||||
sta $05,x
|
||||
|
||||
lda #$55
|
||||
sta $0100
|
||||
|
||||
lda #$99
|
||||
ldx #$00
|
||||
sbc ($05,x)
|
||||
|
||||
jsr main
|
||||
|
||||
|
BIN
test/sim65
BIN
test/sim65
Binary file not shown.
Loading…
Reference in New Issue
Block a user