1
0
mirror of https://github.com/pevans/erc-c.git synced 2025-01-04 22:30:18 +00:00

Better documentation; use a macro to define modes

This commit is contained in:
Peter Evans 2017-12-06 16:54:14 -06:00
parent eb865243bb
commit d0dad61db8

View File

@ -85,10 +85,24 @@ mos6502_get_address_resolver(vm_8bit opcode)
vm_16bit addr; \ vm_16bit addr; \
addr = mos6502_next_byte(cpu) addr = mos6502_next_byte(cpu)
/*
* This will both define the `eff_addr` variable (which is the effective
* address) and assign that value to the `last_addr` field of the cpu.
*/
#define EFF_ADDR(addr) \ #define EFF_ADDR(addr) \
vm_16bit eff_addr = addr; \ vm_16bit eff_addr = addr; \
cpu->last_addr = eff_addr cpu->last_addr = eff_addr
/*
* A tiny convenience macro to help us define address resolver
* functions.
*/
#define DEFINE_ADDR(mode) \
vm_8bit mos6502_resolve_##mode (mos6502 *cpu)
/*
* Return the address mode for a given opcode.
*/
int int
mos6502_addr_mode(vm_8bit opcode) mos6502_addr_mode(vm_8bit opcode)
{ {
@ -100,8 +114,7 @@ mos6502_addr_mode(vm_8bit opcode)
* register. (It's probably the simplest resolution mode for us to * register. (It's probably the simplest resolution mode for us to
* execute.) * execute.)
*/ */
vm_8bit DEFINE_ADDR(acc)
mos6502_resolve_acc(mos6502 *cpu)
{ {
EFF_ADDR(0); EFF_ADDR(0);
return cpu->A; return cpu->A;
@ -112,8 +125,7 @@ mos6502_resolve_acc(mos6502 *cpu)
* in memory at which our looked-for value resides, so we consume those * in memory at which our looked-for value resides, so we consume those
* bytes and return the value located therein. * bytes and return the value located therein.
*/ */
vm_8bit DEFINE_ADDR(abs)
mos6502_resolve_abs(mos6502 *cpu)
{ {
ADDR_HILO(cpu); ADDR_HILO(cpu);
EFF_ADDR(addr); EFF_ADDR(addr);
@ -126,8 +138,7 @@ mos6502_resolve_abs(mos6502 *cpu)
* value to what we read -- plus one if we have the carry bit set. This * value to what we read -- plus one if we have the carry bit set. This
* is a mode you would use if you were scanning a table, for instance. * is a mode you would use if you were scanning a table, for instance.
*/ */
vm_8bit DEFINE_ADDR(abx)
mos6502_resolve_abx(mos6502 *cpu)
{ {
ADDR_HILO(cpu); ADDR_HILO(cpu);
CARRY_BIT(); CARRY_BIT();
@ -140,8 +151,7 @@ mos6502_resolve_abx(mos6502 *cpu)
* Very much the mirror opposite of the ABX address mode; the only * Very much the mirror opposite of the ABX address mode; the only
* difference is we use the Y register, not the X. * difference is we use the Y register, not the X.
*/ */
vm_8bit DEFINE_ADDR(aby)
mos6502_resolve_aby(mos6502 *cpu)
{ {
ADDR_HILO(cpu); ADDR_HILO(cpu);
CARRY_BIT(); CARRY_BIT();
@ -156,8 +166,7 @@ mos6502_resolve_aby(mos6502 *cpu)
* you wanted to say "foo + 5"; 5 would be the operand we return from * you wanted to say "foo + 5"; 5 would be the operand we return from
* here. * here.
*/ */
vm_8bit DEFINE_ADDR(imm)
mos6502_resolve_imm(mos6502 *cpu)
{ {
EFF_ADDR(0); EFF_ADDR(0);
return mos6502_next_byte(cpu); return mos6502_next_byte(cpu);
@ -169,8 +178,7 @@ mos6502_resolve_imm(mos6502 *cpu)
* two bytes, then dereference the two bytes found at that point, and * two bytes, then dereference the two bytes found at that point, and
* _that_ is what our value will be. * _that_ is what our value will be.
*/ */
vm_8bit DEFINE_ADDR(ind)
mos6502_resolve_ind(mos6502 *cpu)
{ {
vm_8bit ind_hi, ind_lo; vm_8bit ind_hi, ind_lo;
@ -190,8 +198,7 @@ mos6502_resolve_ind(mos6502 *cpu)
* X to it, which is the address of what we next dereference. Carry does * X to it, which is the address of what we next dereference. Carry does
* not factor into the arithmetic. * not factor into the arithmetic.
*/ */
vm_8bit DEFINE_ADDR(idx)
mos6502_resolve_idx(mos6502 *cpu)
{ {
ADDR_LO(cpu); ADDR_LO(cpu);
EFF_ADDR(addr + cpu->X); EFF_ADDR(addr + cpu->X);
@ -207,8 +214,7 @@ mos6502_resolve_idx(mos6502 *cpu)
* The ensuing address will then have Y added to it, and then * The ensuing address will then have Y added to it, and then
* dereferenced for the final time. Carry _is_ factored in here. * dereferenced for the final time. Carry _is_ factored in here.
*/ */
vm_8bit DEFINE_ADDR(idy)
mos6502_resolve_idy(mos6502 *cpu)
{ {
ADDR_LO(cpu); ADDR_LO(cpu);
CARRY_BIT(); CARRY_BIT();
@ -223,8 +229,7 @@ mos6502_resolve_idy(mos6502 *cpu)
* means if addr > 127, then we treat the operand as though it * means if addr > 127, then we treat the operand as though it
* were negative. * were negative.
*/ */
vm_8bit DEFINE_ADDR(rel)
mos6502_resolve_rel(mos6502 *cpu)
{ {
vm_16bit orig_pc; vm_16bit orig_pc;
@ -249,8 +254,7 @@ mos6502_resolve_rel(mos6502 *cpu)
* that (which is, by convention, always going to be an address in the * that (which is, by convention, always going to be an address in the
* zero page of memory). * zero page of memory).
*/ */
vm_8bit DEFINE_ADDR(zpg)
mos6502_resolve_zpg(mos6502 *cpu)
{ {
ADDR_LO(cpu); ADDR_LO(cpu);
EFF_ADDR(addr); EFF_ADDR(addr);
@ -262,8 +266,7 @@ mos6502_resolve_zpg(mos6502 *cpu)
* In zero-page x-indexed mode, we read the next byte; add X to that; * In zero-page x-indexed mode, we read the next byte; add X to that;
* and dereference the result. Carry is not a factor here. * and dereference the result. Carry is not a factor here.
*/ */
vm_8bit DEFINE_ADDR(zpx)
mos6502_resolve_zpx(mos6502 *cpu)
{ {
ADDR_LO(cpu); ADDR_LO(cpu);
EFF_ADDR(addr + cpu->X); EFF_ADDR(addr + cpu->X);
@ -276,8 +279,7 @@ mos6502_resolve_zpx(mos6502 *cpu)
* zero-page x-indexed mode. We simply use the Y register and not the X, * zero-page x-indexed mode. We simply use the Y register and not the X,
* and here as well, we do not factor in the carry bit. * and here as well, we do not factor in the carry bit.
*/ */
vm_8bit DEFINE_ADDR(zpy)
mos6502_resolve_zpy(mos6502 *cpu)
{ {
ADDR_LO(cpu); ADDR_LO(cpu);
EFF_ADDR(addr + cpu->Y); EFF_ADDR(addr + cpu->Y);