Skip to content

Commit

Permalink
fixes for OpenDingux first OPK release
Browse files Browse the repository at this point in the history
  • Loading branch information
Jakz committed Dec 26, 2019
1 parent 08ea5a4 commit 7f53689
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
5 changes: 3 additions & 2 deletions data/default.gcw0.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Name=retro-8
Comment=PICO-8 Emulator
Terminal=false
StartupNotify=true
Exec=retro8
Exec=retro8 %f
Icon=icon
Categories=emulator;
Categories=emulators;
X-OD-Filter=.png,.p8
Binary file modified data/pico8_font.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions projects/build_opk.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
rm -rf opk
mkdir -p opk
cp opendingux/retro8 opk
cp vs2017/retro8/api.lua opk
cp ../data/default.gcw0.desktop opk
cp ../data/pico8_font.png opk
cp ../data/icon.png opk
mksquashfs opk retro8.opk -all-root -noappend -no-exports -no-xattrs -no-progress > /dev/null
# rm -rf opk
10 changes: 6 additions & 4 deletions src/views/view_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ _gameView(new GameView(this)), _menuView(new MenuView(this))
void ui::ViewManager::deinit()
{
SDL_DestroyTexture(_font);

SDL::deinit();
}

bool ui::ViewManager::loadData()
{
SDL_Surface* font = IMG_Load("pico8_font.png");
assert(font);

machine.font().load(font);

_font = SDL_CreateTextureFromSurface(_renderer, font);

SDL_SetTextureBlendMode(_font, SDL_BLENDMODE_BLEND);
Expand Down Expand Up @@ -68,7 +70,7 @@ void ui::ViewManager::text(const std::string& text, int32_t x, int32_t y)
}

void ViewManager::text(const std::string& text, int32_t x, int32_t y, SDL_Color color, TextAlign align, float scale)
{
{
constexpr int32_t GLYPHS_PER_ROW = 16;

const int32_t width = text.size() * 4 * scale;
Expand Down Expand Up @@ -101,4 +103,4 @@ void ViewManager::backToGame()
{
_gameView->resume();
_view = _gameView;
}
}
4 changes: 2 additions & 2 deletions src/vm/gfx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ void ColorTable::init(SDL_PixelFormat* format)

void Font::load(SDL_Surface* surface)
{
assert(surface->w == SPRITE_WIDTH * FONT_GLYPHS_COLUMNS && surface->h == SPRITE_HEIGHT * FONT_GLYPHS_ROWS);
//assert(surface->w == SPRITE_WIDTH * FONT_GLYPHS_COLUMNS && surface->h == SPRITE_HEIGHT * FONT_GLYPHS_ROWS);

for (size_t gy = 0; gy < FONT_GLYPHS_ROWS; ++gy)
for (size_t gx = 0; gx < FONT_GLYPHS_COLUMNS; ++gx)
Expand All @@ -36,4 +36,4 @@ void Font::load(SDL_Surface* surface)
glyph.set(sx, sy, static_cast<const uint8_t*>(surface->pixels)[index] ? color_t::WHITE : color_t::BLACK);
}
}
}
}
6 changes: 3 additions & 3 deletions src/vm/machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,15 +32,15 @@ namespace retro8
lua::Code _code;
SDL_Surface* _output;



private:
void circHelper(coord_t xc, coord_t yc, coord_t x, coord_t y, color_t col);
void circFillHelper(coord_t xc, coord_t yc, coord_t x, coord_t y, color_t col);


public:
Machine() : _sound(_memory)
Machine() : _sound(_memory)
{
}

Expand Down Expand Up @@ -79,4 +79,4 @@ namespace retro8
lua::Code& code() { return _code; }
sfx::APU& sound() { return _sound; }
};
}
}
11 changes: 6 additions & 5 deletions src/vm/memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <SDL.h>
#include <array>
#include <random>
#include <cstring>

namespace retro8
{
Expand All @@ -31,7 +32,7 @@ namespace retro8

static constexpr address_t TILE_MAP_LOW = 0x1000;
static constexpr address_t TILE_MAP_HIGH = 0x2000;

static constexpr int32_t CART_DATA_LENGTH = 0x4300;
};

Expand Down Expand Up @@ -69,7 +70,7 @@ namespace retro8
gfx::cursor_t* cursor() { return as<gfx::cursor_t>(address::CURSOR); }
gfx::camera_t* camera() { return as<gfx::camera_t>(address::CAMERA); }
gfx::clip_rect_t* clipRect() { return as<gfx::clip_rect_t>(address::CLIP_RECT); }

gfx::color_byte_t* spriteSheet(coord_t x, coord_t y) { return spriteSheet() + x / gfx::PIXEL_TO_BYTE_RATIO + y * gfx::SPRITE_SHEET_PITCH; }
gfx::color_byte_t* spriteSheet() { return as<gfx::color_byte_t>(address::SPRITE_SHEET); }
gfx::color_byte_t* screenData() { return as<gfx::color_byte_t>(address::SCREEN_DATA); }
Expand Down Expand Up @@ -100,13 +101,13 @@ namespace retro8
return addr;
}

gfx::sprite_t* spriteAt(sprite_index_t index) {
return reinterpret_cast<gfx::sprite_t*>(&memory[address::SPRITE_SHEET
gfx::sprite_t* spriteAt(sprite_index_t index) {
return reinterpret_cast<gfx::sprite_t*>(&memory[address::SPRITE_SHEET
+ (index % gfx::SPRITES_PER_SPRITE_SHEET_ROW) * gfx::SPRITE_BYTES_PER_SPRITE_ROW]
+ (index / gfx::SPRITES_PER_SPRITE_SHEET_ROW) * gfx::SPRITE_SHEET_PITCH * gfx::SPRITE_HEIGHT
); }
gfx::palette_t* paletteAt(palette_index_t index) { return reinterpret_cast<gfx::palette_t*>(&memory[address::PALETTES + index * BYTES_PER_PALETTE]); }

template<typename T> T* as(address_t addr) { return reinterpret_cast<T*>(&memory[addr]); }
};
}
}

0 comments on commit 7f53689

Please sign in to comment.