Skip to content

Commit

Permalink
Merge pull request #24 from jtothebell/MemoryCompat-Rebased
Browse files Browse the repository at this point in the history
Memory compat rebased
  • Loading branch information
jtothebell authored Sep 27, 2020
2 parents 6faf70b + cdae1cf commit aadaf31
Show file tree
Hide file tree
Showing 34 changed files with 1,700 additions and 546 deletions.
57 changes: 40 additions & 17 deletions platform/3ds/source/3dsHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace fs = std::filesystem;

#include "../../../source/host.h"
#include "../../../source/hostVmShared.h"
#include "../../../source/nibblehelpers.h"
#include "../../../source/PicoRam.h"

#define SCREEN_WIDTH 400;
#define SCREEN_HEIGHT 240;
Expand All @@ -35,8 +37,10 @@ const int __3ds_BottomScreenHeight = SCREEN_2_HEIGHT;
const int PicoScreenWidth = 128;
const int PicoScreenHeight = 128;

const int PicoFbLength = 128 * 64;

StretchOption stretch = StretchAndOverflow;

StretchOption stretch = PixelPerfect;
u64 last_time;
u64 now_time;
u64 frame_time;
Expand All @@ -45,6 +49,9 @@ double targetFrameTimeMs;
u32 currKDown;
u32 currKHeld;

Color* _paletteColors;
Bgr24Col _bgrColors[16];

uint8_t ConvertInputToP8(u32 input){
uint8_t result = 0;
if (input & KEY_LEFT){
Expand Down Expand Up @@ -171,7 +178,7 @@ void audioSetup(){
Host::Host() { }


void Host::oneTimeSetup(){
void Host::oneTimeSetup(Color* paletteColors){
osSetSpeedupEnable(true);

audioSetup();
Expand All @@ -182,6 +189,15 @@ void Host::oneTimeSetup(){
now_time = 0;
frame_time = 0;
targetFrameTimeMs = 0;

_paletteColors = paletteColors;
for(int i = 0; i < 16; i++){
_bgrColors[i] = {
_paletteColors[i].Blue,
_paletteColors[i].Green,
_paletteColors[i].Red
};
}
}

void Host::oneTimeCleanup(){
Expand Down Expand Up @@ -250,7 +266,7 @@ void Host::waitForTargetFps(){
}


void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap, Color* paletteColors){
void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap){
int bgcolor = 0;
uint8_t* fb = gfxGetFramebuffer(GFX_TOP, GFX_LEFT, NULL, NULL);
//clear whole top framebuffer
Expand All @@ -266,17 +282,24 @@ void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap, Color* paletteC
if (stretch == PixelPerfect) {
int xOffset = __3ds_TopScreenWidth / 2 - PicoScreenWidth / 2;
int yOffset = __3ds_TopScreenHeight / 2 - PicoScreenHeight / 2;
//todo: test if it is faster to convert colors to uint24_ts and write one instead of 3 (assuming these are )
for(x = 0; x < 128; x++) {

for(x = 0; x < 64; x++) {
for(y = 0; y < 128; y++) {
uint8_t c = picoFb[x*128 + y];
Color col = paletteColors[screenPaletteMap[c]];
int x1 = x << 1;
int x2 = x1 + 1;
uint8_t lc = getPixelNibble(x1, y, picoFb);
Bgr24Col lcol = _bgrColors[screenPaletteMap[lc]];

int pixIdx = (((x + xOffset)*__3ds_TopScreenHeight)+ ((__3ds_TopScreenHeight - 1) - (y + yOffset)))*3;
int pixIdx = (((x1 + xOffset)*__3ds_TopScreenHeight)+ ((__3ds_TopScreenHeight - 1) - (y + yOffset)));

fb[pixIdx + 0] = col.Blue;
fb[pixIdx + 1] = col.Green;
fb[pixIdx + 2] = col.Red;
((Bgr24Col*)fb)[pixIdx] = lcol;

uint8_t rc = getPixelNibble(x2, y, picoFb);
Bgr24Col rcol = _bgrColors[screenPaletteMap[rc]];

pixIdx = (((x2 + xOffset)*__3ds_TopScreenHeight)+ ((__3ds_TopScreenHeight - 1) - (y + yOffset)));

((Bgr24Col*)fb)[pixIdx] = rcol;
}
}
}
Expand All @@ -291,8 +314,8 @@ void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap, Color* paletteC
for(y = 0; y < __3ds_TopScreenHeight; y++) {
int picoX = (int)(x / ratio);
int picoY = (int)(y / ratio);
uint8_t c = picoFb[picoX*128 + picoY];
Color col = paletteColors[screenPaletteMap[c]];
uint8_t c = getPixelNibble(picoX, picoY, picoFb);
Color col = _paletteColors[screenPaletteMap[c]];

int pixIdx = (((x + xOffset)*__3ds_TopScreenHeight)+ ((__3ds_TopScreenHeight - 1) - (y + yOffset)))*3;

Expand All @@ -315,8 +338,8 @@ void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap, Color* paletteC
for(y = 0; y < __3ds_TopScreenHeight; y++) {
int picoX = (int)(x / ratio);
int picoY = (int)(y / ratio);
uint8_t c = picoFb[picoX*128 + picoY];
Color col = paletteColors[screenPaletteMap[c]];
uint8_t c = getPixelNibble(picoX, picoY, picoFb);
Color col = _paletteColors[screenPaletteMap[c]];

int pixIdx = (((x + xOffset)*__3ds_TopScreenHeight)+ ((__3ds_TopScreenHeight - 1) - (y + yOffset)))*3;

Expand All @@ -335,8 +358,8 @@ void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap, Color* paletteC
for(y = 0; y < overflowHeight; y++) {
int picoX = (int)(x / ratio);
int picoY = (int)((y + __3ds_TopScreenHeight) / ratio);
uint8_t c = picoFb[picoX*128 + picoY];
Color col = paletteColors[screenPaletteMap[c]];
uint8_t c = getPixelNibble(picoX, picoY, picoFb);
Color col = _paletteColors[screenPaletteMap[c]];

int pixIdx = (((x + xOffset)*__3ds_BottomScreenHeight)+ ((__3ds_BottomScreenHeight - 1) - (y + yOffset)))*3;

Expand Down
13 changes: 9 additions & 4 deletions platform/switch/source/SwitchHost.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ namespace fs = std::filesystem;

#include "../../../source/host.h"
#include "../../../source/hostVmShared.h"
#include "../../../source/nibblehelpers.h"

#define FB_WIDTH 1280
#define FB_HEIGHT 720
Expand All @@ -38,6 +39,8 @@ u32 currKHeld;

Framebuffer fb;

Color* _paletteColors;

uint8_t ConvertInputToP8(u32 input){
uint8_t result = 0;
if (input & KEY_LEFT){
Expand Down Expand Up @@ -166,7 +169,7 @@ void audioSetup(){
Host::Host() { }


void Host::oneTimeSetup(){
void Host::oneTimeSetup(Color* paletteColors){

audioSetup();

Expand All @@ -179,6 +182,8 @@ void Host::oneTimeSetup(){
now_time = 0;
frame_time = 0;
targetFrameTimeMs = 0;

_paletteColors = paletteColors;
}

void Host::oneTimeCleanup(){
Expand Down Expand Up @@ -247,7 +252,7 @@ void Host::waitForTargetFps(){
}


void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap, Color* paletteColors){
void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap){
u32 stride;
u32* framebuf = (u32*) framebufferBegin(&fb, &stride);

Expand All @@ -274,9 +279,9 @@ void Host::drawFrame(uint8_t* picoFb, uint8_t* screenPaletteMap, Color* paletteC
{
int picoX = (int)(x / ratio);
int picoY = (int)(y / ratio);
uint8_t c = picoFb[picoX*128 + picoY];
uint8_t c = getPixelNibble(picoX, picoY, picoFb);
//uint8_t c = picoFb[x*128 + y];
Color col = paletteColors[screenPaletteMap[c]];
Color col = _paletteColors[screenPaletteMap[c]];

u32 pos = (yOffset + y) * stride / sizeof(u32) + (xOffset + x);
framebuf[pos] = RGBA8_MAXALPHA(col.Red, col.Green, col.Blue);
Expand Down
Loading

0 comments on commit aadaf31

Please sign in to comment.