yaze 0.2.2
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
inventory.cc
Go to the documentation of this file.
1#include "inventory.h"
2
4#include "app/gfx/bitmap.h"
5#include "app/gfx/snes_tile.h"
6#include "app/rom.h"
7
8namespace yaze {
9namespace zelda3 {
10
11using core::Renderer;
12
13absl::Status Inventory::Create() {
14 data_.reserve(256 * 256);
15 for (int i = 0; i < 256 * 256; i++) {
16 data_.push_back(0xFF);
17 }
19 for (int i = 0; i < 0x500; i += 0x08) {
20 ASSIGN_OR_RETURN(auto t1, rom()->ReadWord(i + kBowItemPos));
21 ASSIGN_OR_RETURN(auto t2, rom()->ReadWord(i + kBowItemPos + 0x02));
22 ASSIGN_OR_RETURN(auto t3, rom()->ReadWord(i + kBowItemPos + 0x04));
23 ASSIGN_OR_RETURN(auto t4, rom()->ReadWord(i + kBowItemPos + 0x06));
24 tiles_.push_back(gfx::GetTilesInfo(t1));
25 tiles_.push_back(gfx::GetTilesInfo(t2));
26 tiles_.push_back(gfx::GetTilesInfo(t3));
27 tiles_.push_back(gfx::GetTilesInfo(t4));
28 }
29 const int offsets[] = {0x00, 0x08, 0x800, 0x808};
30 auto xx = 0;
31 auto yy = 0;
32
33 int i = 0;
34 for (const auto& tile : tiles_) {
35 int offset = offsets[i];
36 for (auto y = 0; y < 0x08; ++y) {
37 for (auto x = 0; x < 0x08; ++x) {
38 int mx = x;
39 int my = y;
40
41 if (tile.horizontal_mirror_ != 0) {
42 mx = 0x07 - x;
43 }
44
45 if (tile.vertical_mirror_ != 0) {
46 my = 0x07 - y;
47 }
48
49 int xpos = ((tile.id_ % 0x10) * 0x08);
50 int ypos = (((tile.id_ / 0x10)) * 0x400);
51 int source = ypos + xpos + (x + (y * 0x80));
52
53 auto destination = xx + yy + offset + (mx + (my * 0x100));
54 data_[destination] = (test_[source] & 0x0F) + tile.palette_ * 0x08;
55 }
56 }
57
58 if (i == 4) {
59 i = 0;
60 xx += 0x10;
61 if (xx >= 0x100) {
62 yy += 0x1000;
63 xx = 0;
64 }
65 } else {
66 i++;
67 }
68 }
69
70 bitmap_.Create(256, 256, 8, data_);
71 RETURN_IF_ERROR(bitmap_.ApplyPalette(palette_));
73 return absl::OkStatus();
74}
75
77 tilesheets_.reserve(6 * 0x2000);
78 for (int i = 0; i < 6 * 0x2000; i++) tilesheets_.push_back(0xFF);
80 std::vector<uint8_t> test;
81 for (int i = 0; i < 0x4000; i++) {
82 test_.push_back(tilesheets_[i]);
83 }
84 for (int i = 0x8000; i < +0x8000 + 0x2000; i++) {
85 test_.push_back(tilesheets_[i]);
86 }
87 tilesheets_bmp_.Create(128, 0x130, 64, test_);
88 auto hud_pal_group = rom()->palette_group().hud;
89 palette_ = hud_pal_group[0];
92 return absl::OkStatus();
93}
94
95} // namespace zelda3
96} // namespace yaze
auto rom()
Definition rom.h:383
void RenderBitmap(gfx::Bitmap *bitmap)
Used to render a bitmap to the screen.
Definition renderer.h:48
absl::Status BuildTileset()
Definition inventory.cc:76
gfx::SnesPalette palette_
Definition inventory.h:33
std::vector< uint8_t > data_
Definition inventory.h:27
gfx::Bitmap tilesheets_bmp_
Definition inventory.h:32
std::vector< uint8_t > test_
Definition inventory.h:31
absl::Status Create()
Definition inventory.cc:13
std::vector< gfx::TileInfo > tiles_
Definition inventory.h:36
std::vector< uint8_t > tilesheets_
Definition inventory.h:30
static Renderer & GetInstance()
Definition renderer.h:26
#define RETURN_IF_ERROR(expression)
Definition macro.h:62
#define ASSIGN_OR_RETURN(type_variable_name, expression)
Definition macro.h:70
TileInfo GetTilesInfo(uint16_t tile)
Definition snes_tile.cc:376
Zelda 3 specific classes and functions.
constexpr int kBowItemPos
Definition inventory.h:14
Main namespace for the application.
Definition controller.cc:18
absl::StatusOr< std::vector< uint8_t > > Load2BppGraphics(const Rom &rom)
Loads 2bpp graphics from Rom data.
Definition rom.cc:39