dreamcast/example/maple_wink.cpp
Zack Buhman 511d99563d maple_bus_commands: zero-sized structs should be zero sized
From the GCC manual.

> GCC permits a C structure to have no members:

struct empty {
};

> The structure has size zero. In C++, empty structures are part of the
> language. G++ treats empty structures as if they had a single member of type
> char.

I was not aware of the different behavior in C++.

This fixes every maple example--most were broken for multiple reasons, including
this one.

This also enables SH4 caching. This includes linking code/data into the P1
area (previously this was not the case).

The maple examples (which indeed involve much use of DMA) require much work to
successfully work with the operand and copyback caches. The vibration example
currently is the most complete, though I should consider more on how I want to
structure maple response operand cache invalidation more generally.
2024-02-02 22:05:10 +08:00

59 lines
1.6 KiB
C++

#include <cstdint>
#include "maple/maple.hpp"
#include "maple/maple_bus_bits.hpp"
#include "vga.hpp"
#include "align.hpp"
#include "sh7091/serial.hpp"
extern uint32_t _binary_wink_data_start __asm("_binary_wink_data_start");
void make_wink(uint32_t * buf)
{
const uint8_t * src = reinterpret_cast<const uint8_t *>(&_binary_wink_data_start);
uint8_t * dst = reinterpret_cast<uint8_t *>(buf);
uint32_t ix = 0;
dst[ix] = 0;
for (int i = 0; i < 48 * 32; i++) {
dst[ix] |= ((src[i] & 1) << (7 - (i % 8)));
if (i % 8 == 7) {
ix++;
dst[ix] = 0;
}
}
}
constexpr uint32_t width = 48;
constexpr uint32_t height = 32;
constexpr uint32_t pixels_per_byte = 8;
constexpr uint32_t wink_size = width * height / pixels_per_byte;
void main()
{
uint32_t wink_buf[wink_size / 4];
make_wink(wink_buf);
uint32_t _command_buf[(1024 + 32) / 4];
uint32_t _receive_buf[(1024 + 32) / 4];
uint32_t * command_buf = align_32byte(_command_buf);
uint32_t * receive_buf = align_32byte(_receive_buf);
const uint32_t size = maple::init_block_write(command_buf, receive_buf,
host_instruction::port_select::a,
ap::de::expansion_device | ap::port_select::a | ap::lm_bus::_0,
wink_buf,
wink_size);
maple::dma_start(command_buf, size);
for (int i = 0; i < 1; i++) {
serial::integer<uint32_t>(receive_buf[i]);
}
vga();
v_sync_in();
vga_fill_framebuffer();
while(1);
}