@@ -19,53 +19,76 @@ namespace app {
19
19
namespace zelda3 {
20
20
namespace dungeon {
21
21
22
- class DungeonObjectRenderer : public SharedROM {
22
+ class DungeonObjectRenderer {
23
23
public:
24
-
25
24
struct PseudoVram {
26
25
std::vector<gfx::Bitmap> sheets;
27
26
};
28
27
29
28
void CreateVramFromRoomBlockset () {
30
- auto bitmap_manager = rom ()->BitmapManager ();
31
- uint16_t room_id = 0 ;
32
- auto room_blockset = rom ()->room_blockset_ids [room_id];
33
-
34
- for (const auto blockset_id : room_blockset) {
35
- auto blockset = bitmap_manager[(uint16_t )blockset_id];
36
- vram_.sheets .push_back (*blockset.get ());
37
- }
38
-
29
+ // auto bitmap_manager = rom()->BitmapManager();
30
+ // uint16_t room_id = 0;
31
+ // auto room_blockset = rom()->room_blockset_ids[room_id];
32
+
33
+ // for (const auto blockset_id : room_blockset) {
34
+ // auto blockset = bitmap_manager[(uint16_t)blockset_id];
35
+ // vram_.sheets.push_back(*blockset.get());
36
+ // }
39
37
}
40
38
41
- void RenderObjectsAsBitmaps () {
39
+ void RenderObjectsAsBitmaps (ROM& rom) {
40
+ memory_.Initialize (rom.vector ());
41
+ cpu.Init ();
42
+
42
43
auto subtype1_ptr = core::subtype1_tiles;
43
- auto subtype1_routine_ptr =
44
- core::subtype1_tiles + 0x200 ; // Where the draw routines start
44
+ auto subtype1_routine_ptr = core::subtype1_tiles + 0x200 ;
45
+ std::array<uint16_t , 256 > routine_ptrs;
46
+ for (int i = 0 ; i < 256 ; i++) {
47
+ uint16_t actual_ptr = rom.toint16 (subtype1_routine_ptr + (i * 2 ));
48
+ routine_ptrs[i] = actual_ptr;
49
+ std::cout << std::hex << routine_ptrs[i] << std::endl;
50
+ }
51
+
52
+ int i = 0 ;
53
+ for (const auto routine_ptr : routine_ptrs) {
54
+ cpu.PC = routine_ptr - 2 ;
55
+ cpu.PB = 0x00 ;
56
+
57
+ auto cycles_to_run = clock_.GetCycleCount ();
58
+
59
+ while (true ) {
60
+ auto opcode = cpu.FetchByte ();
61
+ // Fetch and execute an instruction
62
+ cpu.ExecuteInstruction (opcode);
63
+
64
+ // Handle any interrupts, if necessary
65
+ cpu.HandleInterrupts ();
66
+
67
+ // Check if the instruction is RTS
68
+ if (opcode == 0x60 ) {
69
+ break ;
70
+ }
71
+ i++;
72
+ if (i > 50 ) {
73
+ break ;
74
+ }
75
+ }
76
+ }
45
77
46
78
auto subtype2_ptr = core::subtype2_tiles;
47
79
auto subtype2_routine_ptr =
48
80
core::subtype2_tiles + 0x80 ; // Where the draw routines start
81
+ std::array<uint16_t , 128 > subtype2_routine_ptrs;
82
+ for (int i = 0 ; i < 128 ; i++) {
83
+ subtype2_routine_ptrs[i] = subtype2_routine_ptr + i * 2 ;
84
+ }
49
85
50
86
auto subtype3_ptr = core::subtype3_tiles;
51
87
auto subtype3_routine_ptr =
52
88
core::subtype3_tiles + 0x100 ; // Where the draw routines start
53
-
54
- auto data = (*rom ()).vector ();
55
- // Construct a copy of the rooms VRAM
56
- // Jump to the routine that draws the object based on the ID
57
- // Run the routine and get the VRAM data using the CPU and PPU
58
- // Render the VRAM data to a bitmap
59
-
60
- memory_.Initialize (data);
61
- cpu.PC = subtype1_routine_ptr;
62
- cpu.JMP (cpu.FetchWord ());
63
- auto dest = cpu.PC + 0x10 ;
64
- while (cpu.PC < dest) {
65
- cpu.ExecuteInstruction (cpu.FetchByte ());
66
- }
67
89
}
68
90
91
+ std::vector<uint8_t > rom_data_;
69
92
emu::MemoryImpl memory_;
70
93
emu::ClockImpl clock_;
71
94
emu::CPU cpu{memory_, clock_};
0 commit comments