dreamcast/sh7091/serial.cpp
Zack Buhman a71ac1c4b1 suzanne_profile: remove tearing
Though I did spend much time thinking about this, my idea was not correct.

The "tearing" and "previous frame is being shown while it is being drawn" is
simply because that's exactly what the logic in holly/core.cpp did.

This is no longer the case--by the time the newly-created core_flip function is
called, the core render is complete, and we should switch the FB_R_SOF1 to the
current framebuffer, not the one that is going to be written on next frame.

This also modifies alt.lds so that (non-startup) code now runs in the P1 area,
with operand/instruction/copyback caches enabled. This caused a 10x speed
increase in my testing.
2024-02-02 13:11:32 +08:00

77 lines
1.6 KiB
C++

#include <cstdint>
#include "sh7091.hpp"
#include "sh7091_bits.hpp"
#include "string.hpp"
namespace serial {
void init()
{
using namespace scif;
sh7091.SCIF.SCSCR2 = 0;
sh7091.SCIF.SCSMR2 = 0;
sh7091.SCIF.SCBRR2 = 1; // 520833.3
sh7091.SCIF.SCFCR2 = scfcr2::tfrst::reset_operation_enabled
| scfcr2::rfrst::reset_operation_enabled;
// tx/rx trigger on 1 byte
sh7091.SCIF.SCFCR2 = 0;
sh7091.SCIF.SCSPTR2 = 0;
sh7091.SCIF.SCLSR2 = 0;
sh7091.SCIF.SCSCR2 = scscr2::te::transmission_enabled
| scscr2::re::reception_enabled;
}
void character(const char c)
{
using namespace scif;
// wait for transmit fifo to become empty
while ((sh7091.SCIF.SCFSR2 & scfsr2::tdfe::bit_mask) == 0);
for (int i = 0; i < 10000; i++) {
asm volatile ("nop;");
}
sh7091.SCIF.SCFTDR2 = static_cast<uint8_t>(c);
}
void string(const char * s)
{
while (*s != '\0') {
character(*s++);
}
}
template <typename T>
void integer(const T n, const char end)
{
constexpr uint32_t length = (sizeof (T)) * 2;
char num_buf[length + 1];
string::hex<char>(num_buf, length, n);
num_buf[length] = 0;
string("0x");
string(num_buf);
character(end);
}
template <typename T>
void integer(const T n)
{
return integer(n, '\n');
}
template void integer<uint32_t>(uint32_t param);
template void integer<uint16_t>(uint16_t param);
template void integer<uint8_t>(uint8_t param);
template void integer<uint32_t>(uint32_t param, char end);
template void integer<uint16_t>(uint16_t param, char end);
template void integer<uint8_t>(uint8_t param, char end);
}