Skip to content

Commit

Permalink
tilem: toltec fixes
Browse files Browse the repository at this point in the history
 - Clear FB
 - Use default path isntead of cmd line param
 - Use correct black and white values for the screen
  • Loading branch information
timower committed May 2, 2021
1 parent 3dc71d3 commit 8dc94a3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 23 deletions.
5 changes: 3 additions & 2 deletions apps/rocket/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,10 @@ class HideableRenderObject : public SingleChildRenderObject<Hideable<Child>> {
if (!this->widget->child.has_value()) {
if (this->widget->background != nullptr) {
const auto offset =
(rect.size() - this->widget->background->rect().size()) / 2;
rect.align(this->widget->background->rect().size(), 0.5f, 0.5f)
.topLeft;
copy(canvas,
offset.toPoint(),
offset,
*this->widget->background,
this->widget->background->rect());
return UpdateRegion{ rect };
Expand Down
2 changes: 1 addition & 1 deletion apps/tilem/draft/tilem.draft
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

name=TilEm
desc=TI-84+ emulator
call=/opt/bin/tilem /home/root/ti84plus.rom
call=/opt/bin/tilem
term=:
imgFile=tilem
19 changes: 10 additions & 9 deletions apps/tilem/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ using namespace rmlib::input;
namespace {

constexpr auto calc_save_extension = ".sav";
constexpr auto calc_default_rom = "ti84p.rom";
constexpr auto calc_default_rom = "/home/root/ti84plus.rom";

const auto FPS = 100;
const auto TPS = std::chrono::milliseconds(1000) / FPS;
Expand Down Expand Up @@ -370,7 +370,7 @@ class ScreenRenderObject : public LeafRenderObject<Screen> {
float subX = 0;
for (int x = rect.topLeft.x; x <= rect.bottomRight.x; x++) {
const uint8_t data = lcdRow[int(subX)];
const uint8_t pixel = data ? 0 : 0xff;
const uint16_t pixel = data ? black : white;

*canvasPtr = pixel;

Expand Down Expand Up @@ -506,21 +506,22 @@ class CalcState : public StateBase<Calculator> {
auto header(AppContext& context, int width) const {
constexpr auto fontSize = 48;
// TODO: expand option
return Cleared(Border(
Row(Sized(Text("Tilem", fontSize), width - fontSize - 2, std::nullopt),
return Border(
Row(Sized(Text("TilEm", fontSize), width - fontSize - 2, std::nullopt),
closeButton(context, fontSize)),
Insets::all(1)));
Insets::all(1));
}

auto build(AppContext& context, const BuildContext& buildCtx) const {

constexpr auto scale = 6.5;
constexpr auto width = scale * 96;
constexpr auto height = scale * 64;
return Center(Border(Column(header(context, width),
Sized(Screen(mCalc), width, height),
Sized(Keypad(mCalc), width, std::nullopt)),
Insets::all(1)));
return Cleared(
Center(Border(Column(header(context, width),
Sized(Screen(mCalc), width, height),
Sized(Keypad(mCalc), width, std::nullopt)),
Insets::all(1))));
}

~CalcState() {
Expand Down
30 changes: 19 additions & 11 deletions libs/rMlib/FrameBuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,12 @@ updateEmulatedCanvas(const Canvas& canvas, Rect region) {
std::cout << "Update: " << region << "\n";
auto* surface = SDL_GetWindowSurface(window);

const auto getGrey = [&canvas](int x, int y) {
const auto getPixel = [&canvas](int x, int y) {
const auto rgb = *canvas.getPtr<uint16_t>(x, y);
const auto r = rgb & 0x1f;
return r << 3;
const auto b = (rgb & 0x1f) << 3;
const auto g = ((rgb >> 5) & 0x3f) << 2;
const auto r = ((rgb >> 11) & 0x1f) << 3;
return std::array{ r, g, b };
};

static int color = 0;
Expand All @@ -135,18 +137,24 @@ updateEmulatedCanvas(const Canvas& canvas, Rect region) {
for (int y = surfStart.y; y <= surfEnd.y; y++) {
for (int x = surfStart.x; x <= surfEnd.x; x++) {

auto pixel = getGrey(x * EMULATE_SCALE, y * EMULATE_SCALE);
auto pixel = getPixel(x * EMULATE_SCALE, y * EMULATE_SCALE);
#if EMULATE_SCALE > 1
pixel += getGrey(x * EMULATE_SCALE + 1, y * EMULATE_SCALE);
pixel += getGrey(x * EMULATE_SCALE, y * EMULATE_SCALE + 1);
pixel += getGrey(x * EMULATE_SCALE + 1, y * EMULATE_SCALE + 1);
pixel /= 4;
const auto pixel1 = getPixel(x * EMULATE_SCALE + 1, y * EMULATE_SCALE);
const auto pixel2 = getPixel(x * EMULATE_SCALE, y * EMULATE_SCALE + 1);
const auto pixel3 =
getPixel(x * EMULATE_SCALE + 1, y * EMULATE_SCALE + 1);

pixel = {
(pixel[0] + pixel1[0] + pixel2[0] + pixel3[0]) / 4,
(pixel[1] + pixel1[1] + pixel2[1] + pixel3[1]) / 4,
(pixel[2] + pixel1[2] + pixel2[2] + pixel3[2]) / 4,
};
#endif

// assume rgb565
int r = pixel;
int g = pixel;
int b = pixel;
int r = pixel[0];
int g = pixel[1];
int b = pixel[2];

if (y == surfStart.y || y == surfEnd.y || x == surfStart.x ||
x == surfEnd.x) {
Expand Down

0 comments on commit 8dc94a3

Please sign in to comment.