add Emscripten port

This commit is contained in:
Ash Wolf
2019-12-25 23:40:27 +00:00
parent e5f62ceb53
commit 015f6c94d4
11 changed files with 364 additions and 9 deletions

View File

@@ -282,6 +282,12 @@ void Emulator::configure() {
reset();
}
uint8_t *Emulator::getROMBuffer() {
return ROM;
}
size_t Emulator::getROMSize() {
return sizeof(ROM);
}
void Emulator::loadROM(uint8_t *buffer, size_t size) {
memcpy(ROM, buffer, min(size, sizeof(ROM)));
}
@@ -463,7 +469,7 @@ int Emulator::getLCDOffsetY() const { return 0; }
int Emulator::getLCDWidth() const { return 320; }
int Emulator::getLCDHeight() const { return 200; }
void Emulator::readLCDIntoBuffer(uint8_t **lines) const {
void Emulator::readLCDIntoBuffer(uint8_t **lines, bool is32BitOutput) const {
if (lcdAddress == 0xC0000000) {
int width = 320, height = 200;
int bpp = 1;
@@ -487,7 +493,13 @@ void Emulator::readLCDIntoBuffer(uint8_t **lines) const {
palValue = (lcdPalette >> (palIdx * 4)) & 0xF;
palValue |= (palValue << 4);
lines[y][x] = palValue ^ 0xFF;
if (is32BitOutput) {
lines[y][x*4] = palValue ^ 0xFF;
lines[y][x*4+1] = palValue ^ 0xFF;
lines[y][x*4+2] = palValue ^ 0xFF;
} else {
lines[y][x] = palValue ^ 0xFF;
}
}
}
}

View File

@@ -61,6 +61,8 @@ private:
public:
Emulator();
uint8_t *getROMBuffer() override;
size_t getROMSize() override;
void loadROM(uint8_t *buffer, size_t size) override;
void executeUntil(int64_t cycles) override;
int32_t getClockSpeed() const override { return CLOCK_SPEED; }
@@ -71,7 +73,7 @@ public:
int getLCDOffsetY() const override;
int getLCDWidth() const override;
int getLCDHeight() const override;
void readLCDIntoBuffer(uint8_t **lines) const override;
void readLCDIntoBuffer(uint8_t **lines, bool is32BitOutput) const override;
void setKeyboardKey(EpocKey key, bool value) override;
void updateTouchInput(int32_t x, int32_t y, bool down) override;
};

View File

@@ -111,6 +111,8 @@ protected:
public:
EmuBase(bool isTVersion) : ARM710(isTVersion) { }
virtual uint8_t *getROMBuffer() = 0;
virtual size_t getROMSize() = 0;
virtual void loadROM(uint8_t *buffer, size_t size) = 0;
virtual void executeUntil(int64_t cycles) = 0;
virtual int32_t getClockSpeed() const = 0;
@@ -121,7 +123,7 @@ public:
virtual int getLCDOffsetY() const = 0;
virtual int getLCDWidth() const = 0;
virtual int getLCDHeight() const = 0;
virtual void readLCDIntoBuffer(uint8_t **lines) const = 0;
virtual void readLCDIntoBuffer(uint8_t **lines, bool is32BitOutput) const = 0;
virtual void setKeyboardKey(EpocKey key, bool value) = 0;
virtual void updateTouchInput(int32_t x, int32_t y, bool down) = 0;

View File

@@ -369,6 +369,12 @@ void Emulator::configure() {
reset();
}
uint8_t *Emulator::getROMBuffer() {
return ROM;
}
size_t Emulator::getROMSize() {
return sizeof(ROM);
}
void Emulator::loadROM(uint8_t *buffer, size_t size) {
memcpy(ROM, buffer, min(size, sizeof(ROM)));
}
@@ -542,7 +548,21 @@ int Emulator::getLCDOffsetY() const { return 5; }
int Emulator::getLCDWidth() const { return 640; }
int Emulator::getLCDHeight() const { return 240; }
void Emulator::readLCDIntoBuffer(uint8_t **lines) const {
// TODO move this elsewhere
static bool initRgbValues = false;
static uint32_t rgbValues[16];
void Emulator::readLCDIntoBuffer(uint8_t **lines, bool is32BitOutput) const {
if (!initRgbValues) {
initRgbValues = true;
for (int i = 0; i < 16; i++) {
int r = (0x99 * i) / 15;
int g = (0xAA * i) / 15;
int b = (0x88 * i) / 15;
rgbValues[15 - i] = r | (g << 8) | (b << 16) | 0xFF000000;
}
}
if ((lcdAddress >> 24) == 0xC0) {
const uint8_t *lcdBuf = &MemoryBlockC0[lcdAddress & MemoryBlockMask];
int width = 640, height = 240;
@@ -565,8 +585,13 @@ void Emulator::readLCDIntoBuffer(uint8_t **lines) const {
int palIdx = (byte >> shift) & mask;
int palValue = palette[palIdx];
palValue |= (palValue << 4);
lines[y][x] = palValue ^ 0xFF;
if (is32BitOutput) {
auto line = (uint32_t *)lines[y];
line[x] = rgbValues[palValue];
} else {
palValue |= (palValue << 4);
lines[y][x] = palValue ^ 0xFF;
}
}
}
}

View File

@@ -62,6 +62,8 @@ private:
public:
Emulator();
uint8_t *getROMBuffer() override;
size_t getROMSize() override;
void loadROM(uint8_t *buffer, size_t size) override;
void executeUntil(int64_t cycles) override;
int32_t getClockSpeed() const override { return CLOCK_SPEED; }
@@ -72,7 +74,7 @@ public:
int getLCDOffsetY() const override;
int getLCDWidth() const override;
int getLCDHeight() const override;
void readLCDIntoBuffer(uint8_t **lines) const override;
void readLCDIntoBuffer(uint8_t **lines, bool is32BitOutput) const override;
void setKeyboardKey(EpocKey key, bool value) override;
void updateTouchInput(int32_t x, int32_t y, bool down) override;
};