text_editor: un-rot

This commit is contained in:
Zack Buhman 2025-03-02 22:32:12 -06:00
parent 94c12d690d
commit 4d3e53eebb
9 changed files with 271 additions and 82 deletions

View File

@ -1031,6 +1031,7 @@ void main()
serial::init(0);
interrupt_init();
system.IML6NRM = istnrm::end_of_render_tsp;
//asm volatile ("trapa #0");
transfer_textures();
@ -1060,8 +1061,6 @@ void main()
core_init();
system.IML6NRM = istnrm::end_of_render_tsp;
holly.FPU_SHAD_SCALE = fpu_shad_scale::simple_shadow_enable::intensity_volume_mode
| fpu_shad_scale::scale_factor_for_shadows(128);
video_output::set_mode_vga();

Binary file not shown.

BIN
font/terminus/ter_u20n.data Normal file

Binary file not shown.

View File

@ -0,0 +1,15 @@
#pragma once
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
#endif
extern uint32_t _binary_font_terminus_ter_u20n_data_start __asm("_binary_font_terminus_ter_u20n_data_start");
extern uint32_t _binary_font_terminus_ter_u20n_data_end __asm("_binary_font_terminus_ter_u20n_data_end");
extern uint32_t _binary_font_terminus_ter_u20n_data_size __asm("_binary_font_terminus_ter_u20n_data_size");
#ifdef __cplusplus
}
#endif

View File

@ -11,8 +11,8 @@
void do_device_request()
{
uint32_t send_buf[1024] __attribute__((aligned(32)));
uint32_t recv_buf[1024] __attribute__((aligned(32)));
static uint8_t send_buf[1024] __attribute__((aligned(32)));
static uint8_t recv_buf[1024] __attribute__((aligned(32)));
auto writer = maple::host_command_writer(send_buf, recv_buf);
@ -24,8 +24,9 @@ void do_device_request()
maple::dma_start(send_buf, writer.send_offset,
recv_buf, writer.recv_offset);
maple::dma_wait_complete();
for (uint8_t port = 0; port < 1; port++) {
for (uint8_t port = 0; port < 4; port++) {
auto& bus_data = host_response[port].bus_data;
auto& data_fields = bus_data.data_fields;
if (bus_data.command_code != response_type::command_code) {
@ -51,27 +52,36 @@ void do_device_request()
void keyboard_do_get_condition(ft6::data_transfer::data_format& data)
{
uint32_t send_buf[1024] __attribute__((aligned(32)));
uint32_t recv_buf[1024] __attribute__((aligned(32)));
static uint8_t send_buf[1024] __attribute__((aligned(32)));
static uint8_t recv_buf[1024] __attribute__((aligned(32)));
auto writer = maple::host_command_writer(send_buf, recv_buf);
{
using command_type = maple::device_request;
using response_type = maple::device_status;
writer.append_command_all_ports<command_type, response_type>(false);
}
using command_type = maple::get_condition;
using response_type = maple::data_transfer<ft6::data_transfer::data_format>;
auto writer = maple::host_command_writer(send_buf, recv_buf);
auto [host_command, host_response]
= writer.append_command_all_ports<command_type, response_type>();
= writer.append_command_all_ports<command_type, response_type>(true);
host_command->bus_data.data_fields.function_type = std::byteswap(function_type::keyboard);
maple::dma_start(send_buf, writer.send_offset,
recv_buf, writer.recv_offset);
maple::dma_wait_complete();
for (uint8_t port = 0; port < 1; port++) {
auto& bus_data = host_response[port].bus_data;
auto& data_fields = bus_data.data_fields;
if (bus_data.command_code != response_type::command_code) {
do_device_request();
serial::integer<uint32_t>(bus_data.command_code);
serial::integer<uint32_t>(data_fields.function_type);
continue;
}
if ((std::byteswap(data_fields.function_type) & function_type::keyboard) == 0) {

View File

@ -66,6 +66,7 @@ cursor_advance render_primary_buffer(ta_parameter_writer& parameter,
char_type c = gb.buf[i];
uint32_t ix = get_font_ix(font, c);
auto& glyph = glyphs[ix];
if (x + int_26_6(glyph.metrics.horiAdvance) <= window.box.x1) {
transform_glyph(parameter,
font->texture_width,
@ -107,25 +108,15 @@ void render_cursor(ta_parameter_writer& parameter,
);
}
void render(ta_parameter_writer& parameter,
void render(ta_parameter_writer& writer,
const font * font,
const glyph * glyphs,
const gap_buffer& gb,
const viewport_window& window)
{
cursor_advance cursor = render_primary_buffer(parameter, font, glyphs, gb, window);
cursor_advance cursor = render_primary_buffer(writer, font, glyphs, gb, window);
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
render_cursor(writer, cursor, window);
ta_polygon_converter_transfer(parameter.buf, parameter.offset);
ta_wait_opaque_list();
parameter.offset = 0;
render_cursor(parameter, cursor, window);
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
ta_polygon_converter_transfer(parameter.buf, parameter.offset);
ta_wait_translucent_list();
writer.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
}

View File

@ -7,7 +7,7 @@
#include "holly/video_output.hpp"
#include "holly/region_array.hpp"
#include "holly/background.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "holly/texture_memory_alloc3.hpp"
#include "holly/holly.hpp"
#include "holly/core.hpp"
#include "holly/core_bits.hpp"
@ -15,38 +15,174 @@
#include "holly/ta_global_parameter.hpp"
#include "holly/ta_bits.hpp"
#include "sh7091/sh7091.hpp"
#include "sh7091/sh7091_bits.hpp"
#include "sh7091/serial.hpp"
#include "sh7091/vbr.hpp"
#include "systembus.hpp"
#include "systembus_bits.hpp"
#include "font/font.h"
#include "ter_u20n.hpp"
#include "font/terminus/ter_u20n.data.h"
#include "gap_buffer.hpp"
#include "viewport_window.hpp"
#include "keyboard.hpp"
#include "render.hpp"
void init_texture_memory(const struct opb_size& opb_size)
void vbr100()
{
region_array2(640 / 32, // width
480 / 32, // height
opb_size
);
background_parameter(0xff0000ff);
serial::string("vbr100\n");
serial::string("expevt ");
serial::integer<uint16_t>(sh7091.CCN.EXPEVT);
serial::string("intevt ");
serial::integer<uint16_t>(sh7091.CCN.INTEVT);
serial::string("tra ");
serial::integer<uint16_t>(sh7091.CCN.TRA);
while (1);
}
void inflate_font(const uint32_t * src,
const uint32_t stride,
const uint32_t curve_end_ix)
void vbr400()
{
auto texture = reinterpret_cast<volatile uint16_t *>(&texture_memory64[texture_memory_alloc::texture.start / 4]);
twiddle::texture3<4, 1>(texture, reinterpret_cast<const uint8_t *>(src),
stride,
curve_end_ix);
serial::string("vbr400");
serial::string("expevt ");
serial::integer<uint16_t>(sh7091.CCN.EXPEVT);
serial::string("intevt ");
serial::integer<uint16_t>(sh7091.CCN.INTEVT);
serial::string("tra ");
serial::integer<uint16_t>(sh7091.CCN.TRA);
while (1);
}
uint32_t _ta_parameter_buf[((32 * 10 * 17) + 32) / 4];
static int render_done = 0;
void vbr600()
{
if (sh7091.CCN.EXPEVT == 0 && sh7091.CCN.INTEVT == 0x320) {
uint32_t istnrm = system.ISTNRM;
uint32_t isterr = system.ISTERR;
if (isterr) {
serial::string("isterr: ");
serial::integer<uint32_t>(system.ISTERR);
}
if (istnrm & istnrm::end_of_render_tsp) {
system.ISTNRM = istnrm::end_of_render_tsp
| istnrm::end_of_render_isp
| istnrm::end_of_render_video;
render_done = 1;
return;
}
}
serial::string("vbr600");
serial::string("expevt ");
serial::integer<uint16_t>(sh7091.CCN.EXPEVT);
serial::string("intevt ");
serial::integer<uint16_t>(sh7091.CCN.INTEVT);
serial::string("tra ");
serial::integer<uint16_t>(sh7091.CCN.TRA);
serial::string("istnrm: ");
serial::integer<uint32_t>(system.ISTNRM);
serial::string("isterr: ");
serial::integer<uint32_t>(system.ISTERR);
serial::string("halt\n");
while (1);
}
void interrupt_init()
{
system.IML2NRM = 0;
system.IML2ERR = 0;
system.IML2EXT = 0;
system.IML4NRM = 0;
system.IML4ERR = 0;
system.IML4EXT = 0;
system.IML6NRM = 0;
system.IML6ERR = 0;
system.IML6EXT = 0;
system.ISTERR = 0xffffffff;
system.ISTNRM = 0xffffffff;
sh7091.CCN.INTEVT = 0;
sh7091.CCN.EXPEVT = 0;
uint32_t vbr = reinterpret_cast<uint32_t>(&__vbr_link_start) - 0x100;
serial::string("vbr ");
serial::integer<uint32_t>(vbr);
serial::string("vbr100 ");
serial::integer<uint32_t>(reinterpret_cast<uint32_t>(&vbr100));
asm volatile ("ldc %0,vbr"
:
: "r" (vbr));
uint32_t sr;
asm volatile ("stc sr,%0"
: "=r" (sr));
serial::string("sr ");
serial::integer<uint32_t>(sr);
sr &= ~sh::sr::bl; // BL
sr &= ~sh::sr::imask(15); // imask
serial::string("sr ");
serial::integer<uint32_t>(sr);
asm volatile ("ldc %0,sr"
:
: "r" (sr));
}
void transfer_ta_fifo_texture_memory_32byte(void * dst, const void * src, int length)
{
uint32_t out_addr = (uint32_t)dst;
sh7091.CCN.QACR0 = ((reinterpret_cast<uint32_t>(out_addr) >> 24) & 0b11100);
sh7091.CCN.QACR1 = ((reinterpret_cast<uint32_t>(out_addr) >> 24) & 0b11100);
volatile uint32_t * base = &store_queue[(out_addr & 0x03ffffc0) / 4];
const uint32_t * src32 = reinterpret_cast<const uint32_t *>(src);
length = (length + 31) & ~31; // round up to nearest multiple of 32
while (length > 0) {
base[0] = src32[0];
base[1] = src32[1];
base[2] = src32[2];
base[3] = src32[3];
base[4] = src32[4];
base[5] = src32[5];
base[6] = src32[6];
base[7] = src32[7];
asm volatile ("pref @%0"
: // output
: "r" (&base[0]) // input
: "memory");
length -= 32;
base += 8;
src32 += 8;
}
}
void transfer_texture(const void * src, uint32_t size)
{
system.LMMODE0 = 0; // 64-bit address space
system.LMMODE1 = 0; // 64-bit address space
uint32_t offset = texture_memory_alloc.texture.start;
void * dst = reinterpret_cast<void *>(&ta_fifo_texture_memory[offset / 4]);
transfer_ta_fifo_texture_memory_32byte(dst, src, size);
}
uint32_t ta_parameter_buf[1024 * 1024 / 4] __attribute__((aligned(32)));
struct editor_state {
gap_buffer gb;
@ -58,25 +194,24 @@ char_type buf[buf_size];
constexpr uint32_t offsets_size = 1024;
int32_t offsets[offsets_size];
void transfer_palettes()
{
holly.PAL_RAM_CTRL = pal_ram_ctrl::pixel_format::argb1555;
holly.PALETTE_RAM[0] = 0x0000;
holly.PALETTE_RAM[1] = 0xffff;
}
void main()
{
video_output::set_mode_vga();
serial::init(0);
auto font = reinterpret_cast<const struct font *>(&_binary_ter_u20n_data_start);
auto glyphs = reinterpret_cast<const struct glyph *>(&font[1]);
auto texture = reinterpret_cast<const uint32_t *>(&glyphs[font->glyph_count]);
const struct font * font = reinterpret_cast<const struct font *>(&_binary_font_terminus_ter_u20n_data_start);
const struct glyph * glyphs = reinterpret_cast<const struct glyph *>(&font[1]);
const void * texture = reinterpret_cast<const void *>(&glyphs[font->glyph_count]);
inflate_font(texture,
font->texture_stride,
font->max_z_curve_ix);
holly.PAL_RAM_CTRL = pal_ram_ctrl::pixel_format::argb1555;
holly.PALETTE_RAM[0] = 0x8000;
holly.PALETTE_RAM[1] = 0xffff;
// The address of `ta_parameter_buf` must be a multiple of 32 bytes.
// This is mandatory for ch2-dma to the ta fifo polygon converter.
uint32_t * ta_parameter_buf = align_32byte(_ta_parameter_buf);
transfer_texture(texture, font->max_z_curve_ix);
transfer_palettes();
constexpr uint32_t ta_alloc = ta_alloc_ctrl::pt_opb::no_list
| ta_alloc_ctrl::tm_opb::no_list
@ -84,19 +219,37 @@ void main()
| ta_alloc_ctrl::om_opb::no_list
| ta_alloc_ctrl::o_opb::_16x4byte;
constexpr struct opb_size opb_size = { .opaque = 16 * 4
, .opaque_modifier = 0
, .translucent = 16 * 4
, .translucent_modifier = 0
, .punch_through = 0
const int render_passes = 1;
constexpr struct opb_size opb_size[render_passes] = {
{
.opaque = 16 * 4,
.opaque_modifier = 0,
.translucent = 16 * 4,
.translucent_modifier = 0,
.punch_through = 0
}
};
holly.SOFTRESET = softreset::pipeline_soft_reset
| softreset::ta_soft_reset;
holly.SOFTRESET = 0;
const int framebuffer_width = 640;
const int framebuffer_height = 480;
const int tile_width = framebuffer_width / 32;
const int tile_height = framebuffer_height / 32;
region_array_multipass(tile_width,
tile_height,
opb_size,
render_passes,
texture_memory_alloc.region_array[0].start,
texture_memory_alloc.object_list[0].start);
background_parameter2(texture_memory_alloc.background[0].start,
0xff202040);
core_init();
init_texture_memory(opb_size);
uint32_t frame_ix = 0;
@ -107,24 +260,43 @@ void main()
ft6::data_transfer::data_format keyboards[2] = { 0 };
ta_parameter_writer writer = ta_parameter_writer(ta_parameter_buf);
interrupt_init();
system.IML6NRM = istnrm::end_of_render_tsp;
video_output::set_mode_vga();
while (true) {
keyboard_do_get_condition(keyboards[frame_ix & 1]);
keyboard_debug(keyboards, frame_ix);
keyboard_update(keyboards, frame_ix, state.gb);
ta_polygon_converter_init(opb_size.total(),
ta_polygon_converter_init2(texture_memory_alloc.isp_tsp_parameters[0].start,
texture_memory_alloc.isp_tsp_parameters[0].end,
texture_memory_alloc.object_list[0].start,
texture_memory_alloc.object_list[0].end,
opb_size[0].total(),
ta_alloc,
640 / 32,
480 / 32);
tile_width,
tile_height);
writer.offset = 0;
render(writer, font, glyphs, state.gb, state.window);
ta_polygon_converter_writeback(writer.buf, writer.offset);
ta_polygon_converter_transfer(writer.buf, writer.offset);
ta_wait_translucent_list();
auto parameter = ta_parameter_writer(ta_parameter_buf);
render(parameter, font, glyphs, state.gb, state.window);
core_start_render(frame_ix);
core_wait_end_of_render_video();
render_done = 0;
core_start_render2(texture_memory_alloc.region_array[0].start,
texture_memory_alloc.isp_tsp_parameters[0].start,
texture_memory_alloc.background[0].start,
texture_memory_alloc.framebuffer[frame_ix].start,
framebuffer_width);
while (render_done == 0) {
asm volatile ("nop");
};
while (!spg_status::vsync(holly.SPG_STATUS));
core_flip(frame_ix);
holly.FB_R_SOF1 = texture_memory_alloc.framebuffer[frame_ix].start;
while (spg_status::vsync(holly.SPG_STATUS));
frame_ix = (frame_ix + 1) & 1;

View File

@ -11,7 +11,7 @@ TEXT_EDITOR_OBJ = \
holly/ta_fifo_polygon_converter.o \
maple/maple.o \
sh7091/serial.o \
ter_u20n.data.o \
font/terminus/ter_u20n.data.o \
$(LIBGCC)
text_editor/text_editor.elf: LDSCRIPT = $(LIB)/main.lds

View File

@ -1,7 +1,7 @@
#include "transform.hpp"
#include "holly/isp_tsp.hpp"
#include "holly/texture_memory_alloc.hpp"
#include "holly/texture_memory_alloc3.hpp"
#include "holly/ta_global_parameter.hpp"
#include "holly/ta_vertex_parameter.hpp"
@ -82,7 +82,7 @@ void transform_glyph(ta_parameter_writer& parameter,
const float origin_y)
{
const uint32_t parameter_control_word = para_control::para_type::sprite
| para_control::list_type::opaque
| para_control::list_type::translucent
| obj_control::col_type::packed_color
| obj_control::texture
| obj_control::_16bit_uv;
@ -91,16 +91,16 @@ void transform_glyph(ta_parameter_writer& parameter,
| isp_tsp_instruction_word::culling_mode::no_culling;
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::one
| tsp_instruction_word::dst_alpha_instr::zero
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::src_alpha
| tsp_instruction_word::dst_alpha_instr::inverse_src_alpha
| tsp_instruction_word::fog_control::no_fog
| tsp_instruction_word::texture_u_size::from_int(texture_width)
| tsp_instruction_word::texture_v_size::from_int(texture_height);
const uint32_t texture_address = texture_memory_alloc::texture.start;
const uint32_t texture_control_word = texture_control_word::pixel_format::_4bpp_palette
const uint32_t texture_address = texture_memory_alloc.texture.start;
const uint32_t texture_control_word = texture_control_word::pixel_format::_8bpp_palette
| texture_control_word::scan_order::twiddled
| texture_control_word::palette_selector4(0)
| texture_control_word::palette_selector8(0)
| texture_control_word::texture_address(texture_address / 8);
parameter.append<ta_global_parameter::sprite>() =
@ -121,6 +121,8 @@ void transform_glyph(ta_parameter_writer& parameter,
x *= glyph.bitmap.width;
y *= glyph.bitmap.height;
//x *= texture_width;
//y *= texture_height;
x += origin_x + float_26_6(glyph.metrics.horiBearingX);
y += origin_y - float_26_6(glyph.metrics.horiBearingY);