Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MegaDrive performance tuning #8

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions higan/md/GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
components += m68k z80 sn76489
components += sn76489

objects += md-interface
objects += md-cpu md-apu md-vdp md-psg md-ym2612
objects += md-mcd
#objects += md-mcd
objects += md-system md-cartridge md-expansion
objects += md-controller

Expand All @@ -12,7 +12,7 @@ obj/md-apu.o: md/apu/apu.cpp
obj/md-vdp.o: md/vdp/vdp.cpp
obj/md-psg.o: md/psg/psg.cpp
obj/md-ym2612.o: md/ym2612/ym2612.cpp
obj/md-mcd.o: md/mcd/mcd.cpp
#obj/md-mcd.o: md/mcd/mcd.cpp
obj/md-system.o: md/system/system.cpp
obj/md-cartridge.o: md/cartridge/cartridge.cpp
obj/md-expansion.o: md/expansion/expansion.cpp
Expand Down
277 changes: 277 additions & 0 deletions higan/md/apu/algorithms.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,277 @@
auto APU::ADD(uint8 x, uint8 y, bool c) -> uint8 {
uint9 z = x + y + c;

CF = z.bit(8);
NF = 0;
VF = uint8(~(x ^ y) & (x ^ z)).bit(7);
XF = z.bit(3);
HF = uint8(x ^ y ^ z).bit(4);
YF = z.bit(5);
ZF = uint8(z) == 0;
SF = z.bit(7);

return z;
}

auto APU::AND(uint8 x, uint8 y) -> uint8 {
uint8 z = x & y;

CF = 0;
NF = 0;
PF = parity(z);
XF = z.bit(3);
HF = 1;
YF = z.bit(5);
ZF = z == 0;
SF = z.bit(7);

return z;
}

auto APU::BIT(uint3 bit, uint8 x) -> uint8 {
uint8 z = x & 1 << bit;

NF = 0;
PF = parity(z);
XF = x.bit(3);
HF = 1;
YF = x.bit(5);
ZF = z == 0;
SF = z.bit(7);

return x;
}

auto APU::CP(uint8 x, uint8 y) -> void {
uint9 z = x - y;

CF = z.bit(8);
NF = 1;
VF = uint8((x ^ y) & (x ^ z)).bit(7);
XF = y.bit(3);
HF = uint8(x ^ y ^ z).bit(4);
YF = y.bit(5);
ZF = uint8(z) == 0;
SF = z.bit(7);
}

auto APU::DEC(uint8 x) -> uint8 {
uint8 z = x - 1;

NF = 1;
VF = z == 0x7f;
XF = z.bit(3);
HF = z.bit(0,3) == 0x0f;
YF = z.bit(5);
ZF = z == 0;
SF = z.bit(7);

return z;
}

auto APU::IN(uint8 x) -> uint8 {
NF = 0;
PF = parity(x);
XF = x.bit(3);
HF = 0;
YF = x.bit(5);
ZF = x == 0;
SF = x.bit(7);

return x;
}

auto APU::INC(uint8 x) -> uint8 {
uint8 z = x + 1;

NF = 0;
VF = z == 0x80;
XF = z.bit(3);
HF = z.bit(0,3) == 0x00;
YF = z.bit(5);
ZF = z == 0;
SF = z.bit(7);

return z;
}

auto APU::OR(uint8 x, uint8 y) -> uint8 {
uint8 z = x | y;

CF = 0;
NF = 0;
PF = parity(z);
XF = z.bit(3);
HF = 0;
YF = z.bit(5);
ZF = z == 0;
SF = z.bit(7);

return z;
}

auto APU::RES(uint3 bit, uint8 x) -> uint8 {
x &= ~(1 << bit);
return x;
}

auto APU::RL(uint8 x) -> uint8 {
bool c = x.bit(7);
x = x << 1 | CF;

CF = c;
NF = 0;
PF = parity(x);
XF = x.bit(3);
HF = 0;
YF = x.bit(5);
ZF = x == 0;
SF = x.bit(7);

return x;
}

auto APU::RLC(uint8 x) -> uint8 {
x = x << 1 | x >> 7;

CF = x.bit(0);
NF = 0;
PF = parity(x);
XF = x.bit(3);
HF = 0;
YF = x.bit(5);
ZF = x == 0;
SF = x.bit(7);

return x;
}

auto APU::RR(uint8 x) -> uint8 {
bool c = x.bit(0);
x = x >> 1 | CF << 7;

CF = c;
NF = 0;
PF = parity(x);
XF = x.bit(3);
HF = 0;
YF = x.bit(5);
ZF = x == 0;
SF = x.bit(7);

return x;
}

auto APU::RRC(uint8 x) -> uint8 {
x = x >> 1 | x << 7;

CF = x.bit(7);
NF = 0;
PF = parity(x);
XF = x.bit(3);
HF = 0;
YF = x.bit(5);
ZF = x == 0;
SF = x.bit(7);

return x;
}

auto APU::SET(uint3 bit, uint8 x) -> uint8 {
x |= (1 << bit);
return x;
}

auto APU::SLA(uint8 x) -> uint8 {
bool c = x.bit(7);
x = x << 1;

CF = c;
NF = 0;
PF = parity(x);
XF = x.bit(3);
HF = 0;
YF = x.bit(5);
ZF = x == 0;
SF = x.bit(7);

return x;
}

auto APU::SLL(uint8 x) -> uint8 {
bool c = x.bit(7);
x = x << 1 | 1;

CF = c;
NF = 0;
PF = parity(x);
XF = x.bit(3);
HF = 0;
YF = x.bit(5);
ZF = x == 0;
SF = x.bit(7);

return x;
}

auto APU::SRA(uint8 x) -> uint8 {
bool c = x.bit(0);
x = (int8)x >> 1;

CF = c;
NF = 0;
PF = parity(x);
XF = x.bit(3);
HF = 0;
YF = x.bit(5);
ZF = x == 0;
SF = x.bit(7);

return x;
}

auto APU::SRL(uint8 x) -> uint8 {
bool c = x.bit(0);
x = x >> 1;

CF = c;
NF = 0;
PF = parity(x);
XF = x.bit(3);
HF = 0;
YF = x.bit(5);
ZF = x == 0;
SF = x.bit(7);

return x;
}

auto APU::SUB(uint8 x, uint8 y, bool c) -> uint8 {
uint9 z = x - y - c;

CF = z.bit(8);
NF = 1;
VF = uint8((x ^ y) & (x ^ z)).bit(7);
XF = z.bit(3);
HF = uint8(x ^ y ^ z).bit(4);
YF = z.bit(5);
ZF = uint8(z) == 0;
SF = z.bit(7);

return z;
}

auto APU::XOR(uint8 x, uint8 y) -> uint8 {
uint8 z = x ^ y;

CF = 0;
NF = 0;
PF = parity(z);
XF = z.bit(3);
HF = 0;
YF = z.bit(5);
ZF = z == 0;
SF = z.bit(7);

return z;
}
Loading