diff --git a/example/modifier_volume_cube.cpp b/example/modifier_volume_cube.cpp index dac4e24..d1a7649 100644 --- a/example/modifier_volume_cube.cpp +++ b/example/modifier_volume_cube.cpp @@ -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(); diff --git a/font/ter_u20n/ter_u20n.data b/font/ter_u20n/ter_u20n.data deleted file mode 100644 index 27fd7c2..0000000 Binary files a/font/ter_u20n/ter_u20n.data and /dev/null differ diff --git a/font/terminus/ter_u20n.data b/font/terminus/ter_u20n.data new file mode 100644 index 0000000..caf14f0 Binary files /dev/null and b/font/terminus/ter_u20n.data differ diff --git a/font/terminus/ter_u20n.data.h b/font/terminus/ter_u20n.data.h new file mode 100644 index 0000000..5b6f96a --- /dev/null +++ b/font/terminus/ter_u20n.data.h @@ -0,0 +1,15 @@ +#pragma once + +#include + +#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 diff --git a/text_editor/keyboard.cpp b/text_editor/keyboard.cpp index a7ba512..95a0297 100644 --- a/text_editor/keyboard.cpp +++ b/text_editor/keyboard.cpp @@ -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(false); + } using command_type = maple::get_condition; using response_type = maple::data_transfer; - auto writer = maple::host_command_writer(send_buf, recv_buf); - auto [host_command, host_response] - = writer.append_command_all_ports(); + = writer.append_command_all_ports(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(bus_data.command_code); + serial::integer(data_fields.function_type); continue; } if ((std::byteswap(data_fields.function_type) & function_type::keyboard) == 0) { diff --git a/text_editor/render.cpp b/text_editor/render.cpp index e37a8f0..4937440 100644 --- a/text_editor/render.cpp +++ b/text_editor/render.cpp @@ -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(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(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(para_control::para_type::end_of_list); } diff --git a/text_editor/text_editor.cpp b/text_editor/text_editor.cpp index 8b1d783..095d955 100644 --- a/text_editor/text_editor.cpp +++ b/text_editor/text_editor.cpp @@ -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(sh7091.CCN.EXPEVT); + serial::string("intevt "); + serial::integer(sh7091.CCN.INTEVT); + serial::string("tra "); + serial::integer(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(&texture_memory64[texture_memory_alloc::texture.start / 4]); - - twiddle::texture3<4, 1>(texture, reinterpret_cast(src), - stride, - curve_end_ix); + serial::string("vbr400"); + serial::string("expevt "); + serial::integer(sh7091.CCN.EXPEVT); + serial::string("intevt "); + serial::integer(sh7091.CCN.INTEVT); + serial::string("tra "); + serial::integer(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(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(sh7091.CCN.EXPEVT); + serial::string("intevt "); + serial::integer(sh7091.CCN.INTEVT); + serial::string("tra "); + serial::integer(sh7091.CCN.TRA); + + serial::string("istnrm: "); + serial::integer(system.ISTNRM); + serial::string("isterr: "); + serial::integer(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(&__vbr_link_start) - 0x100; + serial::string("vbr "); + serial::integer(vbr); + serial::string("vbr100 "); + serial::integer(reinterpret_cast(&vbr100)); + + asm volatile ("ldc %0,vbr" + : + : "r" (vbr)); + + uint32_t sr; + asm volatile ("stc sr,%0" + : "=r" (sr)); + serial::string("sr "); + serial::integer(sr); + + sr &= ~sh::sr::bl; // BL + sr &= ~sh::sr::imask(15); // imask + + serial::string("sr "); + serial::integer(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(out_addr) >> 24) & 0b11100); + sh7091.CCN.QACR1 = ((reinterpret_cast(out_addr) >> 24) & 0b11100); + + volatile uint32_t * base = &store_queue[(out_addr & 0x03ffffc0) / 4]; + const uint32_t * src32 = reinterpret_cast(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(&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(&_binary_ter_u20n_data_start); - auto glyphs = reinterpret_cast(&font[1]); - auto texture = reinterpret_cast(&glyphs[font->glyph_count]); + const struct font * font = reinterpret_cast(&_binary_font_terminus_ter_u20n_data_start); + const struct glyph * glyphs = reinterpret_cast(&font[1]); + const void * texture = reinterpret_cast(&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_alloc, - 640 / 32, - 480 / 32); + 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, + 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; diff --git a/text_editor/text_editor.mk b/text_editor/text_editor.mk index ff9bced..8e7d879 100644 --- a/text_editor/text_editor.mk +++ b/text_editor/text_editor.mk @@ -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 diff --git a/text_editor/transform.cpp b/text_editor/transform.cpp index d3ba0ec..c36af0e 100644 --- a/text_editor/transform.cpp +++ b/text_editor/transform.cpp @@ -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() = @@ -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);