gap_buffer: the cursor can jump vertically to adjacent lines
This commit is contained in:
parent
ad5b98b5ea
commit
11b858533e
@ -42,7 +42,7 @@ namespace ft6 {
|
|||||||
constexpr uint32_t _8_asterisk = 0x25;
|
constexpr uint32_t _8_asterisk = 0x25;
|
||||||
constexpr uint32_t _9_parenleft = 0x26;
|
constexpr uint32_t _9_parenleft = 0x26;
|
||||||
constexpr uint32_t _0_parenright = 0x27;
|
constexpr uint32_t _0_parenright = 0x27;
|
||||||
constexpr uint32_t return = 0x28;
|
constexpr uint32_t _return = 0x28;
|
||||||
constexpr uint32_t esc = 0x29;
|
constexpr uint32_t esc = 0x29;
|
||||||
constexpr uint32_t backspace = 0x2a;
|
constexpr uint32_t backspace = 0x2a;
|
||||||
constexpr uint32_t tab = 0x2b;
|
constexpr uint32_t tab = 0x2b;
|
||||||
@ -78,13 +78,13 @@ namespace ft6 {
|
|||||||
constexpr uint32_t insert = 0x49;
|
constexpr uint32_t insert = 0x49;
|
||||||
constexpr uint32_t home = 0x4a;
|
constexpr uint32_t home = 0x4a;
|
||||||
constexpr uint32_t page_up = 0x4b;
|
constexpr uint32_t page_up = 0x4b;
|
||||||
constexpr uint32_t delete = 0x4c;
|
constexpr uint32_t _delete = 0x4c;
|
||||||
constexpr uint32_t end = 0x4d;
|
constexpr uint32_t end = 0x4d;
|
||||||
constexpr uint32_t page_down = 0x4e;
|
constexpr uint32_t page_down = 0x4e;
|
||||||
constexpr uint32_t left = 0x4f;
|
constexpr uint32_t right_arrow = 0x4f;
|
||||||
constexpr uint32_t right = 0x50;
|
constexpr uint32_t left_arrow = 0x50;
|
||||||
constexpr uint32_t down = 0x51;
|
constexpr uint32_t down_arrow = 0x51;
|
||||||
constexpr uint32_t up = 0x52;
|
constexpr uint32_t up_arrow = 0x52;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,84 +1,84 @@
|
|||||||
"code","usage"
|
"code","usage",
|
||||||
"0x00","no_operation"
|
"0x00","no_operation",
|
||||||
"0x01","rollover_error"
|
"0x01","rollover_error",
|
||||||
"0x02","post_fail"
|
"0x02","post_fail",
|
||||||
"0x03","undefined_error"
|
"0x03","undefined_error",
|
||||||
"0x04","a_A"
|
"0x04","a_A",
|
||||||
"0x05","b_B"
|
"0x05","b_B",
|
||||||
"0x06","c_C"
|
"0x06","c_C",
|
||||||
"0x07","d_D"
|
"0x07","d_D",
|
||||||
"0x08","e_E"
|
"0x08","e_E",
|
||||||
"0x09","f_F"
|
"0x09","f_F",
|
||||||
"0x0a","g_G"
|
"0x0a","g_G",
|
||||||
"0x0b","h_H"
|
"0x0b","h_H",
|
||||||
"0x0c","i_I"
|
"0x0c","i_I",
|
||||||
"0x0d","j_J"
|
"0x0d","j_J",
|
||||||
"0x0e","k_K"
|
"0x0e","k_K",
|
||||||
"0x0f","l_L"
|
"0x0f","l_L",
|
||||||
"0x10","m_M"
|
"0x10","m_M",
|
||||||
"0x11","n_N"
|
"0x11","n_N",
|
||||||
"0x12","o_O"
|
"0x12","o_O",
|
||||||
"0x13","p_P"
|
"0x13","p_P",
|
||||||
"0x14","q_Q"
|
"0x14","q_Q",
|
||||||
"0x15","r_R"
|
"0x15","r_R",
|
||||||
"0x16","s_S"
|
"0x16","s_S",
|
||||||
"0x17","t_T"
|
"0x17","t_T",
|
||||||
"0x18","u_U"
|
"0x18","u_U",
|
||||||
"0x19","v_V"
|
"0x19","v_V",
|
||||||
"0x1a","w_W"
|
"0x1a","w_W",
|
||||||
"0x1b","x_X"
|
"0x1b","x_X",
|
||||||
"0x1c","y_Y"
|
"0x1c","y_Y",
|
||||||
"0x1d","z_Z"
|
"0x1d","z_Z",
|
||||||
"0x1e","_1_exclam"
|
"0x1e","_1_exclam",
|
||||||
"0x1f","_2_at"
|
"0x1f","_2_at",
|
||||||
"0x20","_3_numbersign"
|
"0x20","_3_numbersign",
|
||||||
"0x21","_4_dollar"
|
"0x21","_4_dollar",
|
||||||
"0x22","_5_percent"
|
"0x22","_5_percent",
|
||||||
"0x23","_6_asciicircum"
|
"0x23","_6_asciicircum",
|
||||||
"0x24","_7_ampersand"
|
"0x24","_7_ampersand",
|
||||||
"0x25","_8_asterisk"
|
"0x25","_8_asterisk",
|
||||||
"0x26","_9_parenleft"
|
"0x26","_9_parenleft",
|
||||||
"0x27","_0_parenright"
|
"0x27","_0_parenright",
|
||||||
"0x28","return"
|
"0x28","_return",
|
||||||
"0x29","esc"
|
"0x29","esc",
|
||||||
"0x2a","backspace"
|
"0x2a","backspace",
|
||||||
"0x2b","tab"
|
"0x2b","tab",
|
||||||
"0x2c","spacebar"
|
"0x2c","spacebar",
|
||||||
"0x2d","minus_underscore"
|
"0x2d","minus_underscore",
|
||||||
"0x2e","equal_plus"
|
"0x2e","equal_plus","underscore carot"
|
||||||
"0x2f","bracketleft_braceleft"
|
"0x2f","bracketleft_braceleft","at"
|
||||||
"0x30","bracketright_braceright"
|
"0x30","bracketright_braceright","braceleft"
|
||||||
"0x31","backslash_bar"
|
"0x31","backslash_bar",
|
||||||
"0x32","_unknown_"
|
"0x32","_unknown_",
|
||||||
"0x33","semicolon_colon"
|
"0x33","semicolon_colon",
|
||||||
"0x34","apostrophe_quotedbl"
|
"0x34","apostrophe_quotedbl",
|
||||||
"0x35","grave_asciitilde"
|
"0x35","grave_asciitilde",
|
||||||
"0x36","comma_less"
|
"0x36","comma_less",
|
||||||
"0x37","period_greater"
|
"0x37","period_greater",
|
||||||
"0x38","slash_question"
|
"0x38","slash_question",
|
||||||
"0x39","caps_lock"
|
"0x39","caps_lock",
|
||||||
"0x3a","F1"
|
"0x3a","F1",
|
||||||
"0x3b","F2"
|
"0x3b","F2",
|
||||||
"0x3c","F3"
|
"0x3c","F3",
|
||||||
"0x3d","F4"
|
"0x3d","F4",
|
||||||
"0x3e","F5"
|
"0x3e","F5",
|
||||||
"0x3f","F6"
|
"0x3f","F6",
|
||||||
"0x40","F7"
|
"0x40","F7",
|
||||||
"0x41","F8"
|
"0x41","F8",
|
||||||
"0x42","F9"
|
"0x42","F9",
|
||||||
"0x43","F10"
|
"0x43","F10",
|
||||||
"0x44","F11"
|
"0x44","F11",
|
||||||
"0x45","F12"
|
"0x45","F12",
|
||||||
"0x46","print_screen"
|
"0x46","print_screen",
|
||||||
"0x47","scroll_lock"
|
"0x47","scroll_lock",
|
||||||
"0x48","pause"
|
"0x48","pause",
|
||||||
"0x49","insert"
|
"0x49","insert",
|
||||||
"0x4a","home"
|
"0x4a","home",
|
||||||
"0x4b","page_up"
|
"0x4b","page_up",
|
||||||
"0x4c","delete"
|
"0x4c","_delete",
|
||||||
"0x4d","end"
|
"0x4d","end",
|
||||||
"0x4e","page_down"
|
"0x4e","page_down",
|
||||||
"0x4f","left"
|
"0x4f","right_arrow",
|
||||||
"0x50","right"
|
"0x50","left_arrow",
|
||||||
"0x51","down"
|
"0x51","down_arrow",
|
||||||
"0x52","up"
|
"0x52","up_arrow",
|
||||||
|
|
Binary file not shown.
@ -25,9 +25,7 @@ void line_init_from_buf(struct gap_buffer& gb,
|
|||||||
|
|
||||||
gb.line.gap = gb.line.length;
|
gb.line.gap = gb.line.length;
|
||||||
|
|
||||||
serial::string("gbgapend\n");
|
|
||||||
for (int32_t i = gb.gap_end; i < gb.size; i++) {
|
for (int32_t i = gb.gap_end; i < gb.size; i++) {
|
||||||
serial::integer<uint32_t>(i);
|
|
||||||
if (gb.buf[i] == '\n') {
|
if (gb.buf[i] == '\n') {
|
||||||
gb.line.offsets[gb.line.length++] = i;
|
gb.line.offsets[gb.line.length++] = i;
|
||||||
}
|
}
|
||||||
@ -77,6 +75,13 @@ void gap_append(struct gap_buffer& gb, char_type c)
|
|||||||
void gap_pop(struct gap_buffer& gb)
|
void gap_pop(struct gap_buffer& gb)
|
||||||
{
|
{
|
||||||
gb.gap_start--;
|
gb.gap_start--;
|
||||||
|
if (gb.buf[gb.gap_start] == '\n') {
|
||||||
|
for (int32_t i = gb.line.gap; i < gb.line.length; i++) {
|
||||||
|
gb.line.offsets[i - 1] = gb.line.offsets[i];
|
||||||
|
}
|
||||||
|
gb.line.gap -= 1;
|
||||||
|
gb.line.length -= 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -114,3 +119,52 @@ void gap_cursor_pos(struct gap_buffer& gb, int32_t delta)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void gap_cursor_pos_abs(struct gap_buffer& gb, int32_t pos)
|
||||||
|
{
|
||||||
|
if (pos > gb.gap_start) {
|
||||||
|
pos -= (gb.gap_end - gb.gap_start);
|
||||||
|
}
|
||||||
|
gap_cursor_pos(gb, pos - gb.gap_start);
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t gap_column_number(struct gap_buffer& gb)
|
||||||
|
{
|
||||||
|
int32_t line_start = 0;
|
||||||
|
if (gb.line.gap > 0)
|
||||||
|
line_start = gb.line.offsets[gb.line.gap - 1] + 1;
|
||||||
|
return gb.gap_start - line_start;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr inline int32_t min(int32_t a, int32_t b)
|
||||||
|
{
|
||||||
|
return (a < b) ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
constexpr inline int32_t max(int32_t a, int32_t b)
|
||||||
|
{
|
||||||
|
return (a > b) ? a : b;
|
||||||
|
}
|
||||||
|
|
||||||
|
void gap_cursor_pos_line(struct gap_buffer& gb, int32_t delta)
|
||||||
|
{
|
||||||
|
if (delta > 0) {
|
||||||
|
int32_t max_pos_delta = gb.line.length - gb.line.gap;
|
||||||
|
delta = min(max_pos_delta, delta);
|
||||||
|
} else {
|
||||||
|
int32_t min_pos_delta = (-gb.line.gap) - 1;
|
||||||
|
delta = max(min_pos_delta, delta);
|
||||||
|
}
|
||||||
|
if (delta == 0)
|
||||||
|
return;
|
||||||
|
int32_t column = gap_column_number(gb);
|
||||||
|
int32_t offset_ix = (gb.line.gap - 1) + delta;
|
||||||
|
int32_t buf_ix = 0;
|
||||||
|
if (offset_ix >= 0)
|
||||||
|
buf_ix = gb.line.offsets[offset_ix] + 1;
|
||||||
|
while (buf_ix < gb.size && column > 0 && gb.buf[buf_ix] != '\n') {
|
||||||
|
buf_ix += 1;
|
||||||
|
column -= 1;
|
||||||
|
}
|
||||||
|
gap_cursor_pos_abs(gb, buf_ix);
|
||||||
|
}
|
||||||
|
@ -32,3 +32,5 @@ void gap_resize(struct gap_buffer& gb);
|
|||||||
void gap_append(struct gap_buffer& gb, char_type c);
|
void gap_append(struct gap_buffer& gb, char_type c);
|
||||||
void gap_pop(struct gap_buffer& gb);
|
void gap_pop(struct gap_buffer& gb);
|
||||||
void gap_cursor_pos(struct gap_buffer& gb, int32_t delta);
|
void gap_cursor_pos(struct gap_buffer& gb, int32_t delta);
|
||||||
|
int32_t gap_column_number(struct gap_buffer& gb);
|
||||||
|
void gap_cursor_pos_line(struct gap_buffer& gb, int32_t delta);
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
#include "holly/region_array.hpp"
|
#include "holly/region_array.hpp"
|
||||||
#include "twiddle.hpp"
|
#include "twiddle.hpp"
|
||||||
#include "palette.hpp"
|
#include "palette.hpp"
|
||||||
|
#include "string.hpp"
|
||||||
|
|
||||||
#include "sh7091/serial.hpp"
|
#include "sh7091/serial.hpp"
|
||||||
|
|
||||||
@ -27,6 +28,8 @@
|
|||||||
#include "maple/maple_bus_bits.hpp"
|
#include "maple/maple_bus_bits.hpp"
|
||||||
#include "maple/maple_bus_commands.hpp"
|
#include "maple/maple_bus_commands.hpp"
|
||||||
#include "maple/maple_bus_ft0.hpp"
|
#include "maple/maple_bus_ft0.hpp"
|
||||||
|
#include "maple/maple_bus_ft6.hpp"
|
||||||
|
#include "maple/maple_bus_ft6_key_scan_codes.hpp"
|
||||||
|
|
||||||
#include "font/font.hpp"
|
#include "font/font.hpp"
|
||||||
#include "ter_u20n.hpp"
|
#include "ter_u20n.hpp"
|
||||||
@ -61,27 +64,36 @@ void transform(ta_parameter_writer& parameter,
|
|||||||
const uint32_t texture_width, uint32_t texture_height,
|
const uint32_t texture_width, uint32_t texture_height,
|
||||||
const glyph& glyph,
|
const glyph& glyph,
|
||||||
const float origin_x,
|
const float origin_x,
|
||||||
const float origin_y)
|
const float origin_y,
|
||||||
|
const bool invert = false)
|
||||||
{
|
{
|
||||||
const uint32_t parameter_control_word = para_control::para_type::sprite
|
const uint32_t parameter_control_word = para_control::para_type::sprite
|
||||||
| para_control::list_type::opaque
|
| (invert ? para_control::list_type::translucent : para_control::list_type::opaque)
|
||||||
| obj_control::col_type::packed_color
|
| obj_control::col_type::packed_color
|
||||||
| obj_control::texture
|
| obj_control::texture
|
||||||
| obj_control::_16bit_uv;
|
| obj_control::_16bit_uv;
|
||||||
|
|
||||||
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::greater
|
const uint32_t isp_tsp_instruction_word = isp_tsp_instruction_word::depth_compare_mode::always
|
||||||
| isp_tsp_instruction_word::culling_mode::no_culling;
|
| isp_tsp_instruction_word::culling_mode::no_culling;
|
||||||
|
|
||||||
const uint32_t tsp_instruction_word = tsp_instruction_word::src_alpha_instr::src_alpha
|
|
||||||
| tsp_instruction_word::dst_alpha_instr::one
|
uint32_t tsp_instruction_word = tsp_instruction_word::fog_control::no_fog
|
||||||
| tsp_instruction_word::fog_control::no_fog
|
| tsp_instruction_word::texture_u_size::from_int(texture_width)
|
||||||
| tsp_instruction_word::use_alpha
|
| tsp_instruction_word::texture_v_size::from_int(texture_height);
|
||||||
| tsp_instruction_word::texture_u_size::from_int(texture_width)
|
if (invert) {
|
||||||
| tsp_instruction_word::texture_v_size::from_int(texture_height);
|
tsp_instruction_word |= tsp_instruction_word::src_alpha_instr::inverse_other_color
|
||||||
|
| tsp_instruction_word::dst_alpha_instr::inverse_other_color
|
||||||
|
;
|
||||||
|
} else {
|
||||||
|
tsp_instruction_word |= tsp_instruction_word::src_alpha_instr::one
|
||||||
|
| tsp_instruction_word::dst_alpha_instr::zero
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
const uint32_t texture_address = texture_memory_alloc::texture.start;
|
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_control_word = texture_control_word::pixel_format::_4bpp_palette
|
||||||
| texture_control_word::scan_order::twiddled
|
| texture_control_word::scan_order::twiddled
|
||||||
|
| texture_control_word::palette_selector(invert)
|
||||||
| texture_control_word::texture_address(texture_address / 8);
|
| texture_control_word::texture_address(texture_address / 8);
|
||||||
|
|
||||||
parameter.append<ta_global_parameter::polygon_type_0>() =
|
parameter.append<ta_global_parameter::polygon_type_0>() =
|
||||||
@ -180,9 +192,9 @@ struct button_state {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void do_get_condition(uint32_t * command_buf,
|
void do_get_condition_controller(uint32_t * command_buf,
|
||||||
uint32_t * receive_buf,
|
uint32_t * receive_buf,
|
||||||
button_state& buttons)
|
button_state& buttons)
|
||||||
{
|
{
|
||||||
using command_type = get_condition;
|
using command_type = get_condition;
|
||||||
using response_type = data_transfer<ft0::data_transfer::data_format>;
|
using response_type = data_transfer<ft0::data_transfer::data_format>;
|
||||||
@ -191,8 +203,7 @@ void do_get_condition(uint32_t * command_buf,
|
|||||||
.function_type = std::byteswap(function_type::controller)
|
.function_type = std::byteswap(function_type::controller)
|
||||||
};
|
};
|
||||||
|
|
||||||
const uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf,
|
const uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf, data_fields);
|
||||||
data_fields);
|
|
||||||
using host_response_type = struct maple::command_response<response_type::data_fields>;
|
using host_response_type = struct maple::command_response<response_type::data_fields>;
|
||||||
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
|
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
|
||||||
|
|
||||||
@ -204,11 +215,11 @@ void do_get_condition(uint32_t * command_buf,
|
|||||||
for (uint8_t port = 0; port < 4; port++) {
|
for (uint8_t port = 0; port < 4; port++) {
|
||||||
auto& bus_data = host_response[port].bus_data;
|
auto& bus_data = host_response[port].bus_data;
|
||||||
if (bus_data.command_code != response_type::command_code) {
|
if (bus_data.command_code != response_type::command_code) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
auto& data_fields = bus_data.data_fields;
|
auto& data_fields = bus_data.data_fields;
|
||||||
if ((data_fields.function_type & std::byteswap(function_type::controller)) == 0) {
|
if ((data_fields.function_type & std::byteswap(function_type::controller)) == 0) {
|
||||||
return;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
buttons.ra |= ft0::data_transfer::digital_button::ra(data_fields.data.digital_button) == 0;
|
buttons.ra |= ft0::data_transfer::digital_button::ra(data_fields.data.digital_button) == 0;
|
||||||
@ -225,29 +236,72 @@ void do_get_condition(uint32_t * command_buf,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void do_get_condition_keyboard(uint32_t * command_buf,
|
||||||
|
uint32_t * receive_buf,
|
||||||
|
ft6::data_transfer::data_format& data)
|
||||||
|
{
|
||||||
|
using command_type = get_condition;
|
||||||
|
using response_type = data_transfer<ft6::data_transfer::data_format>;
|
||||||
|
|
||||||
|
get_condition::data_fields data_fields = {
|
||||||
|
.function_type = std::byteswap(function_type::keyboard)
|
||||||
|
};
|
||||||
|
|
||||||
|
const uint32_t command_size = maple::init_host_command_all_ports<command_type, response_type>(command_buf, receive_buf, data_fields);
|
||||||
|
using host_response_type = struct maple::command_response<response_type::data_fields>;
|
||||||
|
auto host_response = reinterpret_cast<host_response_type *>(receive_buf);
|
||||||
|
|
||||||
|
maple::dma_start(command_buf, command_size,
|
||||||
|
receive_buf, maple::sizeof_command(host_response));
|
||||||
|
|
||||||
|
for (uint8_t port = 0; port < 4; port++) {
|
||||||
|
auto& bus_data = host_response[port].bus_data;
|
||||||
|
if (bus_data.command_code != response_type::command_code) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
auto& data_fields = bus_data.data_fields;
|
||||||
|
if ((data_fields.function_type & std::byteswap(function_type::keyboard)) == 0) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
data.modifier_key = data_fields.data.modifier_key;
|
||||||
|
data.led_state = data_fields.data.led_state;
|
||||||
|
data.scan_code_array[0] = data_fields.data.scan_code_array[0];
|
||||||
|
data.scan_code_array[1] = data_fields.data.scan_code_array[1];
|
||||||
|
data.scan_code_array[2] = data_fields.data.scan_code_array[2];
|
||||||
|
data.scan_code_array[3] = data_fields.data.scan_code_array[3];
|
||||||
|
data.scan_code_array[4] = data_fields.data.scan_code_array[4];
|
||||||
|
data.scan_code_array[5] = data_fields.data.scan_code_array[5];
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
uint32_t _ta_parameter_buf[((32 * 10 * 17) + 32) / 4];
|
uint32_t _ta_parameter_buf[((32 * 10 * 17) + 32) / 4];
|
||||||
|
|
||||||
struct editor_state {
|
struct editor_state {
|
||||||
struct gap_buffer gb;
|
gap_buffer gb;
|
||||||
};
|
};
|
||||||
|
|
||||||
void render_gap_buffer(ta_parameter_writer& parameter,
|
void render_gap_buffer(ta_parameter_writer& parameter,
|
||||||
const struct font * font,
|
const struct font * font,
|
||||||
const struct glyph * glyphs,
|
const struct glyph * glyphs,
|
||||||
struct gap_buffer& gb)
|
gap_buffer& gb)
|
||||||
{
|
{
|
||||||
int32_t advance = 0;
|
int32_t advance = 0;
|
||||||
int32_t cursor = 0;
|
int32_t cursor = 0;
|
||||||
for (int32_t i = 0; i < gb.size; i++) {
|
for (int32_t i = 0; i <= gb.size; i++) {
|
||||||
char_type c;
|
if (i == gb.gap_start)
|
||||||
|
cursor = advance;
|
||||||
|
if (i == gb.size)
|
||||||
|
break;
|
||||||
|
|
||||||
|
char_type c;
|
||||||
if (i < gb.gap_start || i >= gb.gap_end) {
|
if (i < gb.gap_start || i >= gb.gap_end) {
|
||||||
c = gb.buf[i];
|
c = gb.buf[i];
|
||||||
} else {
|
} else {
|
||||||
c = '_';
|
c = '_';
|
||||||
}
|
}
|
||||||
if (i == gb.gap_start)
|
|
||||||
cursor = advance;
|
|
||||||
|
|
||||||
uint32_t ix;
|
uint32_t ix;
|
||||||
if (c >= font->first_char_code && c <= font->last_char_code) {
|
if (c >= font->first_char_code && c <= font->last_char_code) {
|
||||||
@ -261,7 +315,7 @@ void render_gap_buffer(ta_parameter_writer& parameter,
|
|||||||
font->texture_width,
|
font->texture_width,
|
||||||
font->texture_height,
|
font->texture_height,
|
||||||
glyph,
|
glyph,
|
||||||
50.f + float_26_6(advance), // x
|
10.f + float_26_6(advance), // x
|
||||||
100.f // y
|
100.f // y
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -276,7 +330,7 @@ void render_gap_buffer(ta_parameter_writer& parameter,
|
|||||||
font->texture_width,
|
font->texture_width,
|
||||||
font->texture_height,
|
font->texture_height,
|
||||||
glyph,
|
glyph,
|
||||||
50.f + 10.f * j, // x
|
10.f + 10.f * j, // x
|
||||||
100.f - float_26_6(font->glyph_height) // y
|
100.f - float_26_6(font->glyph_height) // y
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -285,7 +339,7 @@ void render_gap_buffer(ta_parameter_writer& parameter,
|
|||||||
transform(parameter,
|
transform(parameter,
|
||||||
font->texture_width, font->texture_height,
|
font->texture_width, font->texture_height,
|
||||||
glyph,
|
glyph,
|
||||||
50.f + float_26_6(cursor), // x
|
10.f + float_26_6(cursor), // x
|
||||||
100.f + float_26_6(font->glyph_height) // y
|
100.f + float_26_6(font->glyph_height) // y
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -300,16 +354,24 @@ void render_gap_buffer(ta_parameter_writer& parameter,
|
|||||||
transform(parameter,
|
transform(parameter,
|
||||||
font->texture_width, font->texture_height,
|
font->texture_width, font->texture_height,
|
||||||
glyph,
|
glyph,
|
||||||
50.f + 10.f * j, // x
|
10.f + 10.f * j, // x
|
||||||
100.f + float_26_6(font->glyph_height) * 2 // y
|
100.f + float_26_6(font->glyph_height) * 2 // y
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int32_t h_cursor = 0;
|
||||||
|
int32_t v_cursor = 0;
|
||||||
int32_t h_advance = 0;
|
int32_t h_advance = 0;
|
||||||
int32_t v_advance = 0;
|
int32_t v_advance = 0;
|
||||||
for (int32_t i = 0; i < gb.size; i++) {
|
for (int32_t i = 0; i <= gb.size; i++) {
|
||||||
char_type c;
|
if (i == gb.gap_start) {
|
||||||
|
h_cursor = h_advance;
|
||||||
|
v_cursor = v_advance;
|
||||||
|
}
|
||||||
|
if (i == gb.size)
|
||||||
|
break;
|
||||||
|
|
||||||
|
char_type c;
|
||||||
if (i < gb.gap_start || i >= gb.gap_end) {
|
if (i < gb.gap_start || i >= gb.gap_end) {
|
||||||
c = gb.buf[i];
|
c = gb.buf[i];
|
||||||
} else {
|
} else {
|
||||||
@ -339,6 +401,46 @@ void render_gap_buffer(ta_parameter_writer& parameter,
|
|||||||
h_advance += glyph.metrics.horiAdvance;
|
h_advance += glyph.metrics.horiAdvance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
int32_t advance = 0;
|
||||||
|
char buf[10];
|
||||||
|
string::dec(buf, 10, gap_column_number(gb));
|
||||||
|
int j;
|
||||||
|
for (j = 0; j < 9; j++) { if (buf[j] != '0') break; }
|
||||||
|
for (int i = j; i < 10; i++) {
|
||||||
|
uint8_t c = buf[i];
|
||||||
|
int32_t ix;
|
||||||
|
if (c >= font->first_char_code && c <= font->last_char_code) {
|
||||||
|
ix = c - font->first_char_code;
|
||||||
|
} else {
|
||||||
|
ix = '#' - font->first_char_code;
|
||||||
|
}
|
||||||
|
auto& glyph = glyphs[ix];
|
||||||
|
transform(parameter,
|
||||||
|
font->texture_width,
|
||||||
|
font->texture_height,
|
||||||
|
glyph,
|
||||||
|
50.f + float_26_6(advance), // x
|
||||||
|
400.f // y
|
||||||
|
);
|
||||||
|
advance += glyph.metrics.horiAdvance;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
|
||||||
|
|
||||||
|
{
|
||||||
|
auto& glyph = glyphs[' ' - font->first_char_code];
|
||||||
|
transform(parameter,
|
||||||
|
font->texture_width, font->texture_height,
|
||||||
|
glyph,
|
||||||
|
350.f + float_26_6(h_cursor), // x
|
||||||
|
100.f + float_26_6(v_cursor), // y
|
||||||
|
true); // invert
|
||||||
|
}
|
||||||
|
|
||||||
|
parameter.append<ta_global_parameter::end_of_list>() = ta_global_parameter::end_of_list(para_control::para_type::end_of_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_state(button_state& prev, button_state& next, editor_state& state)
|
void update_state(button_state& prev, button_state& next, editor_state& state)
|
||||||
@ -351,6 +453,103 @@ void update_state(button_state& prev, button_state& next, editor_state& state)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void debug_keyboard(ft6::data_transfer::data_format * keyboards, uint32_t frame_ix)
|
||||||
|
{
|
||||||
|
uint32_t this_frame = (frame_ix + 0) & 1;
|
||||||
|
bool difference = false;
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
if (keyboards[0].scan_code_array[i] != keyboards[1].scan_code_array[i]) {
|
||||||
|
difference = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (difference) {
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
serial::integer<uint8_t>(keyboards[this_frame].scan_code_array[i], ' ');
|
||||||
|
}
|
||||||
|
serial::string("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void update_keyboard(ft6::data_transfer::data_format * keyboards, uint32_t frame_ix, gap_buffer& gb)
|
||||||
|
{
|
||||||
|
uint32_t this_frame = (frame_ix + 0) & 1;
|
||||||
|
uint32_t next_frame = (frame_ix + 1) & 1;
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
if (i < 5 && keyboards[this_frame].scan_code_array[i + 1] != ft6::scan_codes::no_operation)
|
||||||
|
continue;
|
||||||
|
bool make = true;
|
||||||
|
for (int j = 0; j < 6; j++) {
|
||||||
|
if (keyboards[next_frame].scan_code_array[j] == keyboards[this_frame].scan_code_array[i]) {
|
||||||
|
make = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (make) {
|
||||||
|
// make
|
||||||
|
uint8_t scan_code = keyboards[this_frame].scan_code_array[i];
|
||||||
|
switch (scan_code) {
|
||||||
|
case ft6::scan_codes::a_A: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::b_B: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::c_C: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::d_D: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::e_E: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::f_F: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::g_G: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::h_H: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::i_I: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::j_J: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::k_K: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::l_L: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::m_M: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::n_N: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::o_O: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::p_P: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::q_Q: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::r_R: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::s_S: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::t_T: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::u_U: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::v_V: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::w_W: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::x_X: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::y_Y: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::z_Z:
|
||||||
|
{
|
||||||
|
char_type code_point = (scan_code - ft6::scan_codes::a_A) + 'a';
|
||||||
|
gap_append(gb, code_point);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ft6::scan_codes::_1_exclam: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::_2_at: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::_3_numbersign: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::_4_dollar: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::_5_percent: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::_6_asciicircum: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::_7_ampersand: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::_8_asterisk: [[fallthrough]];
|
||||||
|
case ft6::scan_codes::_9_parenleft:
|
||||||
|
{
|
||||||
|
char_type code_point = (scan_code - ft6::scan_codes::_1_exclam) + '1';
|
||||||
|
gap_append(gb, code_point);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case ft6::scan_codes::_0_parenright: gap_append(gb, '0'); break;
|
||||||
|
case ft6::scan_codes::_return: gap_append(gb, '\n'); break;
|
||||||
|
case ft6::scan_codes::backspace: gap_pop(gb); break;
|
||||||
|
case ft6::scan_codes::spacebar: gap_append(gb, ' '); break;
|
||||||
|
|
||||||
|
case ft6::scan_codes::left_arrow: gap_cursor_pos(gb, -1); break;
|
||||||
|
case ft6::scan_codes::right_arrow: gap_cursor_pos(gb, 1); break;
|
||||||
|
case ft6::scan_codes::up_arrow: gap_cursor_pos_line(gb, -1); break;
|
||||||
|
case ft6::scan_codes::down_arrow: gap_cursor_pos_line(gb, 1); break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
video_output::set_mode_vga();
|
video_output::set_mode_vga();
|
||||||
@ -362,7 +561,12 @@ void main()
|
|||||||
inflate_font(texture,
|
inflate_font(texture,
|
||||||
font->texture_stride,
|
font->texture_stride,
|
||||||
font->max_z_curve_ix);
|
font->max_z_curve_ix);
|
||||||
palette_data<2>();
|
|
||||||
|
holly.PAL_RAM_CTRL = pal_ram_ctrl::pixel_format::argb1555;
|
||||||
|
holly.PALETTE_RAM[0] = 0x8000;
|
||||||
|
holly.PALETTE_RAM[1] = 0xffff;
|
||||||
|
holly.PALETTE_RAM[16] = 0xffff;
|
||||||
|
holly.PALETTE_RAM[17] = 0x8000;
|
||||||
|
|
||||||
// The address of `ta_parameter_buf` must be a multiple of 32 bytes.
|
// 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.
|
// This is mandatory for ch2-dma to the ta fifo polygon converter.
|
||||||
@ -370,13 +574,13 @@ void main()
|
|||||||
|
|
||||||
constexpr uint32_t ta_alloc = ta_alloc_ctrl::pt_opb::no_list
|
constexpr uint32_t ta_alloc = ta_alloc_ctrl::pt_opb::no_list
|
||||||
| ta_alloc_ctrl::tm_opb::no_list
|
| ta_alloc_ctrl::tm_opb::no_list
|
||||||
| ta_alloc_ctrl::t_opb::no_list
|
| ta_alloc_ctrl::t_opb::_16x4byte
|
||||||
| ta_alloc_ctrl::om_opb::no_list
|
| ta_alloc_ctrl::om_opb::no_list
|
||||||
| ta_alloc_ctrl::o_opb::_16x4byte;
|
| ta_alloc_ctrl::o_opb::_16x4byte;
|
||||||
|
|
||||||
constexpr struct opb_size opb_size = { .opaque = 16 * 4
|
constexpr struct opb_size opb_size = { .opaque = 16 * 4
|
||||||
, .opaque_modifier = 0
|
, .opaque_modifier = 0
|
||||||
, .translucent = 0
|
, .translucent = 16 * 4
|
||||||
, .translucent_modifier = 0
|
, .translucent_modifier = 0
|
||||||
, .punch_through = 0
|
, .punch_through = 0
|
||||||
};
|
};
|
||||||
@ -397,14 +601,22 @@ void main()
|
|||||||
// 01234567
|
// 01234567
|
||||||
char_type buf[64] = "abqb\neggs1\nbarley";
|
char_type buf[64] = "abqb\neggs1\nbarley";
|
||||||
int32_t offsets[64];
|
int32_t offsets[64];
|
||||||
gap_init_from_buf(state.gb, buf, 24, 17);
|
gap_init_from_buf(state.gb, buf, 30, 17);
|
||||||
line_init_from_buf(state.gb, offsets, 64);
|
line_init_from_buf(state.gb, offsets, 64);
|
||||||
gap_cursor_pos(state.gb, (-state.gb.gap_start) + 6);
|
//gap_cursor_pos(state.gb, (-state.gb.gap_start) + 6);
|
||||||
gap_append(state.gb, '\n');
|
//gap_append(state.gb, '\n');
|
||||||
|
|
||||||
|
ft6::data_transfer::data_format keyboards[2] = { 0 };
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
do_get_condition(command_buf, receive_buf, buttons[frame_ix & 1]);
|
(void)buttons;
|
||||||
update_state(buttons[(frame_ix + 1) & 1], buttons[frame_ix & 1], state);
|
//do_get_condition(command_buf, receive_buf, buttons[frame_ix & 1]);
|
||||||
|
//update_state(buttons[(frame_ix + 1) & 1], buttons[frame_ix & 1], state);
|
||||||
|
do_get_condition_keyboard(command_buf, receive_buf, keyboards[frame_ix & 1]);
|
||||||
|
debug_keyboard(keyboards, frame_ix);
|
||||||
|
|
||||||
|
|
||||||
|
update_keyboard(keyboards, frame_ix, state.gb);
|
||||||
|
|
||||||
ta_polygon_converter_init(opb_size.total(),
|
ta_polygon_converter_init(opb_size.total(),
|
||||||
ta_alloc,
|
ta_alloc,
|
||||||
@ -413,9 +625,8 @@ void main()
|
|||||||
|
|
||||||
auto parameter = ta_parameter_writer(ta_parameter_buf);
|
auto parameter = ta_parameter_writer(ta_parameter_buf);
|
||||||
render_gap_buffer(parameter, font, glyphs, state.gb);
|
render_gap_buffer(parameter, font, glyphs, state.gb);
|
||||||
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(ta_parameter_buf, parameter.offset);
|
ta_polygon_converter_transfer(parameter.buf, parameter.offset);
|
||||||
ta_wait_opaque_list();
|
ta_wait_opaque_list();
|
||||||
|
|
||||||
core_start_render(frame_ix);
|
core_start_render(frame_ix);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user