#include "vdp2.h" #include "vdp1.h" #include "vram.hpp" void palette_data() { vdp2.cram.u16[3] = rgb15( 0, 0, 0); vdp2.cram.u16[2] = rgb15(10, 10, 10); vdp2.cram.u16[1] = rgb15(21, 21, 21); vdp2.cram.u16[0] = rgb15(31, 31, 31); vdp2.cram.u16[16 + 3] = rgb15( 0, 0, 0); vdp2.cram.u16[16 + 2] = rgb15(21, 21, 21); vdp2.cram.u16[16 + 1] = rgb15(31, 31, 31); vdp2.cram.u16[16 + 0] = 0; // transparent } static void _2bpp_4bpp_vram_copy(uint32_t * vram, const start_size_t& buf) { for (uint32_t ix = 0; ix < buf.size / 4; ix += 1) { const uint32_t pixels = reinterpret_cast(buf.start)[ix]; const uint32_t px0 = pixels >> 16 & 0xffff; const uint32_t px1 = pixels >> 0 & 0xffff; #define lshift(n) ((7 - n) * 2) #define rshift(n) ((7 - n) * 4) #define px(p, n) (((p >> lshift(n)) & 0b11) << rshift(n)) #define p0(n) (px(px0, n)) #define p1(n) (px(px1, n)) vram[ix * 2 + 0] = p0(7) | p0(6) | p0(5) | p0(4) | p0(3) | p0(2) | p0(1) | p0(0); vram[ix * 2 + 1] = p1(7) | p1(6) | p1(5) | p1(4) | p1(3) | p1(2) | p1(1) | p1(0); #undef p1 #undef p0 #undef px #undef lshift #undef rshift } } uint32_t character_pattern_table(const start_size_t& buf, const uint32_t top) { // round to nearest multiple of 16 const uint32_t table_size = ((buf.size * 2) + 0x10 - 1) & (-0x10); const uint32_t base_address = top - table_size; uint32_t * vram = &vdp1.vram.u32[(base_address / 4)]; _2bpp_4bpp_vram_copy(vram, buf); return base_address; } uint32_t cell_data(const start_size_t& buf, const uint32_t top) { // round to nearest multiple of 32 const uint32_t table_size = ((buf.size * 2) + 0x20 - 1) & (-0x20); const uint32_t base_address = top - table_size; // in bytes uint32_t * vram = &vdp2.vram.u32[(base_address / 4)]; _2bpp_4bpp_vram_copy(vram, buf); return base_address; }