diff --git a/Makefile b/Makefile index 407890d..1b11d99 100644 --- a/Makefile +++ b/Makefile @@ -94,9 +94,15 @@ scsp/sound_cpu__interrupt.elf: scsp/sound_cpu__interrupt.o m68k/interrupt.bin.o res/sperrypc.bitmap.bin: tools/ttf-bitmap ./tools/ttf-bitmap 20 7f res/Bm437_SperryPC_CGA.otb $@ +res/nec.bitmap.bin: tools/ttf-bitmap + ./tools/ttf-bitmap 20 7f res/Bm437_NEC_MultiSpeed.otb $@ + +res/nec_bold.bitmap.bin: tools/ttf-bitmap + ./tools/ttf-bitmap 20 7f res/Bm437_NEC_MultiSpeed_bold.otb $@ + editor/main_saturn.o: common/keyboard.hpp editor/editor.hpp -editor/main_saturn.elf: editor/main_saturn.o res/sperrypc.bitmap.bin.o sh/lib1funcs.o common/keyboard.o saturn/start.o +editor/main_saturn.elf: editor/main_saturn.o res/nec.bitmap.bin.o res/nec_bold.bitmap.bin.o sh/lib1funcs.o common/keyboard.o saturn/start.o # clean clean: clean-sh diff --git a/editor/editor.hpp b/editor/editor.hpp index d5922cd..4e98fdb 100644 --- a/editor/editor.hpp +++ b/editor/editor.hpp @@ -23,7 +23,7 @@ struct cursor { enum struct mode { normal, - mark + mark, }; struct selection { @@ -49,8 +49,11 @@ inline constexpr bool selection::contains(int32_t col, int32_t row) return false; } -template +template struct buffer { + static_assert((C & (C - 1)) == 0); + static_assert(C < 32 || C % 32 == 0); + line row[R]; line * lines[R]; int32_t length; @@ -64,6 +67,7 @@ struct buffer { int32_t cell_height; int32_t top; int32_t left; + int32_t viewport[V][C < 32 ? 1 : C / 32]; } window; struct cursor cursor; struct cursor mark; @@ -130,8 +134,8 @@ struct buffer { inline constexpr void scroll_new_col(const int32_t col); }; -template -inline constexpr buffer::buffer(int32_t width, int32_t height) +template +inline constexpr buffer::buffer(int32_t width, int32_t height) { this->length = 1; this->shadow.length = 1; @@ -148,14 +152,16 @@ inline constexpr buffer::buffer(int32_t width, int32_t height) this->lines[i] = nullptr; this->shadow.lines[i] = nullptr; + /* for (int32_t j = 0; j < C; j++) { this->row[i].buf[j] = 0x7f; } + */ } } -template -inline constexpr line * buffer::allocate() +template +inline constexpr line * buffer::allocate() { line * l; while ((l = &this->row[this->alloc_ix])->length != -1) { @@ -168,30 +174,29 @@ inline constexpr line * buffer::allocate() return l; } -template -inline constexpr void buffer::deallocate(line *& l) +template +inline constexpr void buffer::deallocate(line *& l) { // does not touch alloc_ix - fill(l->buf, 0x7f, l->length); l->length = -1; l->refcount = 0; l = nullptr; } -template -inline constexpr void buffer::decref(line *& l) +template +inline constexpr void buffer::decref(line *& l) { if (l == nullptr) return; else if (l->refcount == 1) - buffer::deallocate(l); + buffer::deallocate(l); else { l->refcount--; l = nullptr; } } -template -inline constexpr line * buffer::dup(line const * const src) +template +inline constexpr line * buffer::dup(line const * const src) { line * dst = this->allocate(); copy(&dst->buf[0], &src->buf[0], src->length); @@ -199,8 +204,8 @@ inline constexpr line * buffer::dup(line const * const src) return dst; } -template -inline constexpr line * buffer::mutref(line *& l) +template +inline constexpr line * buffer::mutref(line *& l) { if (l == nullptr) { l = this->allocate(); @@ -212,29 +217,29 @@ inline constexpr line * buffer::mutref(line *& l) return l; } -template -inline constexpr line * buffer::incref(line * l) +template +inline constexpr line * buffer::incref(line * l) { if (l != nullptr) l->refcount++; return l; } -template -inline constexpr int32_t buffer::line_length(line const * const l) +template +inline constexpr int32_t buffer::line_length(line const * const l) { if (l == nullptr) return 0; else return l->length; } -template -inline constexpr bool buffer::put(const uint8_t c) +template +inline constexpr bool buffer::put(const uint8_t c) { editor::cursor& cur = this->cursor; line * l = mutref(this->lines[cur.row]); // v // 0123 - if (l->length >= C || cur.col >= C || cur.col < 0) + if (cur.col >= C) return false; if (l->length > cur.col) { @@ -252,8 +257,8 @@ inline constexpr bool buffer::put(const uint8_t c) return true; } -template -inline constexpr bool buffer::delete_forward() +template +inline constexpr bool buffer::delete_forward() { if (this->mode == mode::mark) { this->mode = mode::normal; @@ -262,9 +267,6 @@ inline constexpr bool buffer::delete_forward() editor::cursor& cur = this->cursor; - if (cur.col < 0 || cur.col > C) - return false; - if (line_length(this->lines[cur.row]) == 0) { if (this->length == 1) return false; decref(this->lines[cur.row]); @@ -290,8 +292,8 @@ inline constexpr bool buffer::delete_forward() return true; } -template -inline constexpr bool buffer::delete_backward() +template +inline constexpr bool buffer::delete_backward() { if (this->mode == mode::mark) { this->mode = mode::normal; @@ -300,9 +302,6 @@ inline constexpr bool buffer::delete_backward() editor::cursor& cur = this->cursor; - if (cur.col < 0 || cur.col > C) - return false; - if (cur.col == 0) { if (cur.row == 0) return false; // make selection @@ -329,8 +328,8 @@ inline constexpr bool buffer::delete_backward() return true; } -template -inline constexpr void buffer::delete_word_forward() +template +inline constexpr void buffer::delete_word_forward() { mark_set(); cursor_scan_word_forward(); @@ -343,8 +342,8 @@ inline constexpr void buffer::delete_word_forward() this->mode = mode::normal; } -template -inline constexpr void buffer::delete_word_backward() +template +inline constexpr void buffer::delete_word_backward() { mark_set(); cursor_scan_word_backward(); @@ -357,8 +356,8 @@ inline constexpr void buffer::delete_word_backward() this->mode = mode::normal; } -template -inline constexpr bool buffer::cursor_left() +template +inline constexpr bool buffer::cursor_left() { editor::cursor& cur = this->cursor; @@ -380,8 +379,8 @@ inline constexpr bool buffer::cursor_left() return true; } -template -inline constexpr bool buffer::cursor_right() +template +inline constexpr bool buffer::cursor_right() { editor::cursor& cur = this->cursor; @@ -404,8 +403,8 @@ inline constexpr bool buffer::cursor_right() return true; } -template -inline constexpr bool buffer::cursor_up() +template +inline constexpr bool buffer::cursor_up() { editor::cursor& cur = this->cursor; @@ -421,8 +420,8 @@ inline constexpr bool buffer::cursor_up() return true; } -template -inline constexpr bool buffer::cursor_down() +template +inline constexpr bool buffer::cursor_down() { editor::cursor& cur = this->cursor; @@ -438,8 +437,8 @@ inline constexpr bool buffer::cursor_down() return true; } -template -inline constexpr bool buffer::cursor_home() +template +inline constexpr bool buffer::cursor_home() { editor::cursor& cur = this->cursor; cur.col = 0; @@ -447,8 +446,8 @@ inline constexpr bool buffer::cursor_home() return true; } -template -inline constexpr bool buffer::cursor_end() +template +inline constexpr bool buffer::cursor_end() { editor::cursor& cur = this->cursor; @@ -464,16 +463,16 @@ static inline constexpr bool word_boundary(int8_t c) || (c >= '0' && c <= '9')); } -template -inline constexpr uint8_t buffer::cursor_get(const editor::cursor& cur) +template +inline constexpr uint8_t buffer::cursor_get(const editor::cursor& cur) { return this->lines[cur.row] == nullptr ? 0 : (cur.col == this->lines[cur.row]->length ? '\n' : this->lines[cur.row]->buf[cur.col]); } -template -inline constexpr bool buffer::cursor_increment(editor::cursor& cur) +template +inline constexpr bool buffer::cursor_increment(editor::cursor& cur) { if (cur.col >= line_length(this->lines[cur.row])) { if (cur.row + 1 >= this->length) { @@ -488,8 +487,8 @@ inline constexpr bool buffer::cursor_increment(editor::cursor& cur) return true; } -template -inline constexpr void buffer::cursor_scan_word_forward() +template +inline constexpr void buffer::cursor_scan_word_forward() { // copy of this->cursor editor::cursor cur = this->cursor; @@ -508,8 +507,8 @@ inline constexpr void buffer::cursor_scan_word_forward() scroll_new_cursor(cur); } -template -inline constexpr bool buffer::cursor_decrement(editor::cursor& cur) +template +inline constexpr bool buffer::cursor_decrement(editor::cursor& cur) { if (cur.col == 0) { if (cur.row - 1 < 0) { @@ -524,8 +523,8 @@ inline constexpr bool buffer::cursor_decrement(editor::cursor& cur) return true; } -template -inline constexpr void buffer::cursor_scan_word_backward() +template +inline constexpr void buffer::cursor_scan_word_backward() { // copy of this->cursor editor::cursor cur = this->cursor; @@ -545,12 +544,12 @@ inline constexpr void buffer::cursor_scan_word_backward() scroll_new_cursor(cur); } -template -inline constexpr bool buffer::enter() +template +inline constexpr bool buffer::enter() { editor::cursor& cur = this->cursor; - if (cur.row >= R || cur.row < 0) + if (cur.row >= R) return false; if ((this->length - 1) > cur.row) { @@ -570,7 +569,6 @@ inline constexpr bool buffer::enter() old_l = mutref(old_l); old_l->length -= new_l->length; copy(&new_l->buf[0], &old_l->buf[cur.col], new_l->length); - fill(&old_l->buf[cur.col], 0x7f, new_l->length); } } else { // nothing to do, new_l->length is already 0 @@ -587,8 +585,8 @@ inline constexpr bool buffer::enter() return true; } -template -inline constexpr void buffer::line_kill() +template +inline constexpr void buffer::line_kill() { editor::cursor& cur = this->cursor; @@ -608,16 +606,16 @@ inline constexpr void buffer::line_kill() } } -template -inline constexpr void buffer::mark_set() +template +inline constexpr void buffer::mark_set() { this->mark.row = this->cursor.row; this->mark.col = this->cursor.col; this->mode = mode::mark; } -template -inline constexpr selection buffer::mark_get() +template +inline constexpr selection buffer::mark_get() { editor::cursor& cur = this->cursor; editor::cursor& mark = this->mark; @@ -643,8 +641,8 @@ inline constexpr selection buffer::mark_get() return sel; } -template -inline constexpr void buffer::delete_from_line(line *& l, +template +inline constexpr void buffer::delete_from_line(line *& l, const int32_t col_start_ix, const int32_t col_end_ix) { @@ -664,8 +662,8 @@ inline constexpr void buffer::delete_from_line(line *& l, } } -template -inline constexpr void buffer::selection_delete(const selection& sel) +template +inline constexpr void buffer::selection_delete(const selection& sel) { if (sel.min == sel.max) { return; @@ -720,8 +718,8 @@ inline constexpr void buffer::selection_delete(const selection& sel) } } -template -inline constexpr bool buffer::mark_delete() +template +inline constexpr bool buffer::mark_delete() { const selection sel = mark_get(); selection_delete(sel); @@ -732,14 +730,14 @@ inline constexpr bool buffer::mark_delete() return true; } -template -inline constexpr void buffer::quit() +template +inline constexpr void buffer::quit() { this->mode = mode::normal; } -template -inline constexpr void buffer::shadow_clear() +template +inline constexpr void buffer::shadow_clear() { for (int32_t i = 0; i < this->shadow.length; i++) decref(this->shadow.lines[i]); @@ -747,8 +745,8 @@ inline constexpr void buffer::shadow_clear() this->shadow.length = 1; } -template -inline constexpr void buffer::_shadow_cow(line * src, +template +inline constexpr void buffer::_shadow_cow(line * src, const int32_t dst_row_ix, const int32_t col_start_ix, const int32_t col_end_ix) @@ -765,8 +763,8 @@ inline constexpr void buffer::_shadow_cow(line * src, } } -template -inline constexpr bool buffer::shadow_copy() +template +inline constexpr bool buffer::shadow_copy() { if (this->mode != mode::mark) return false; @@ -812,8 +810,8 @@ inline constexpr bool buffer::shadow_copy() return true; } -template -inline constexpr bool buffer::shadow_cut() +template +inline constexpr bool buffer::shadow_cut() { if (this->mode != mode::mark) return false; @@ -826,8 +824,8 @@ inline constexpr bool buffer::shadow_cut() return true; } -template -inline constexpr void buffer::overwrite_line(line *& dst, +template +inline constexpr void buffer::overwrite_line(line *& dst, const int32_t dst_col, line * src, const int32_t src_col) @@ -853,8 +851,8 @@ inline constexpr void buffer::overwrite_line(line *& dst, } } -template -inline constexpr bool buffer::shadow_paste() +template +inline constexpr bool buffer::shadow_paste() { if (this->mode == mode::mark) this->mode = mode::normal; @@ -936,15 +934,15 @@ inline constexpr bool buffer::shadow_paste() return true; } -template -inline constexpr void buffer::scroll_up() +template +inline constexpr void buffer::scroll_up() { if (this->cursor.row < this->window.top) this->window.top = this->cursor.row; } -template -inline constexpr void buffer::scroll_down() +template +inline constexpr void buffer::scroll_down() { // 0: a - // 1: bv - @@ -957,15 +955,15 @@ inline constexpr void buffer::scroll_down() this->window.top = (this->cursor.row - (this->window.cell_height - 1)); } -template -inline constexpr void buffer::scroll_left() +template +inline constexpr void buffer::scroll_left() { if (this->cursor.col < this->window.left) this->window.left = this->cursor.col; } -template -inline constexpr void buffer::scroll_right() +template +inline constexpr void buffer::scroll_right() { // 0: a - // 1: bv - @@ -978,8 +976,8 @@ inline constexpr void buffer::scroll_right() this->window.left = (this->cursor.col - (this->window.cell_width - 1)); } -template -inline constexpr void buffer::scroll_new_cursor(const editor::cursor& oth) +template +inline constexpr void buffer::scroll_new_cursor(const editor::cursor& oth) { editor::cursor& cur = this->cursor; @@ -990,8 +988,8 @@ inline constexpr void buffer::scroll_new_cursor(const editor::cursor& oth) else { cur.col = oth.col; scroll_left(); } } -template -inline constexpr void buffer::scroll_new_col(const int32_t col) +template +inline constexpr void buffer::scroll_new_col(const int32_t col) { editor::cursor& cur = this->cursor; diff --git a/editor/main_saturn.cpp b/editor/main_saturn.cpp index aae7f71..05956bf 100644 --- a/editor/main_saturn.cpp +++ b/editor/main_saturn.cpp @@ -12,9 +12,10 @@ #include "editor.hpp" -extern void * _sperrypc_bitmap_start __asm("_binary_res_sperrypc_bitmap_bin_start"); +extern void * _nec_bitmap_start __asm("_binary_res_nec_bitmap_bin_start"); +extern void * _nec_bold_bitmap_start __asm("_binary_res_nec_bold_bitmap_bin_start"); -using buffer_type = editor::buffer<64, 64>; +using buffer_type = editor::buffer<64, 64, 40>; constexpr int32_t viewport_max_col = 320 / 8; constexpr int32_t viewport_max_row = 240 / 8; @@ -62,12 +63,16 @@ namespace pix_fmt_4bpp void cell_data() { - const uint8_t * buf = reinterpret_cast(&_sperrypc_bitmap_start); + const uint8_t * normal = reinterpret_cast(&_nec_bitmap_start); + const uint8_t * bold = reinterpret_cast(&_nec_bold_bitmap_start); for (int ix = 0; ix <= (0x7f - 0x20); ix++) { for (int y = 0; y < 8; y++) { - uint8_t row = buf[ix * 8 + y]; - vdp2.vram.u32[(ix * 8) + y] = pix_fmt_4bpp::bits(row); + const uint8_t row_n = normal[ix * 8 + y]; + vdp2.vram.u32[ 0 + (ix * 8) + y] = pix_fmt_4bpp::bits(row_n); + + const uint8_t row_b = bold[ix * 8 + y]; + vdp2.vram.u32[96 + (ix * 8) + y] = pix_fmt_4bpp::bits(row_b); } } } diff --git a/editor/test_editor.cpp b/editor/test_editor.cpp index 28b2701..60e5a5c 100644 --- a/editor/test_editor.cpp +++ b/editor/test_editor.cpp @@ -7,7 +7,7 @@ using namespace editor; static void test_allocate() { - buffer<8, 4> b {4, 2}; + buffer<8, 4, 4> b {4, 2}; decltype(b)::line_type * l; assert(b.row[0].length == -1); @@ -62,7 +62,7 @@ static void test_put() { // v // "as" -> "abs" - buffer<8, 4> b {4, 2}; + buffer<8, 4, 4> b {4, 2}; decltype(b)::line_type * l; assert(b.cursor.col == 0); @@ -101,7 +101,7 @@ static void test_put() void test_backspace() { - buffer<8, 4> b {4, 2}; + buffer<8, 4, 4> b {4, 2}; decltype(b)::line_type * l; b.put('a'); @@ -137,7 +137,7 @@ void test_enter() // [0] as // [1] Df // [2] qwer - buffer<8, 4> b {4, 2}; + buffer<8, 4, 4> b {4, 2}; b.cursor.row = 0; b.cursor.col = 0; @@ -191,7 +191,7 @@ void test_enter_backspace1() // ab // cd - buffer<8, 4> b {4, 2}; + buffer<8, 4, 4> b {4, 2}; b.put('a'); b.put('b'); @@ -216,7 +216,7 @@ void test_enter_backspace1() void test_enter_backspace2() { - buffer<8, 4> b {4, 2}; + buffer<8, 4, 4> b {4, 2}; b.put('a'); b.enter(); @@ -231,7 +231,7 @@ void test_enter_backspace2() void test_enter_scroll() { - buffer<8, 4> b {4, 2}; + buffer<8, 4, 4> b {4, 2}; assert(b.window.top == 0); b.put('a'); @@ -253,7 +253,7 @@ void test_enter_scroll() void test_first_enter() { - buffer<8, 4> b {4, 2}; + buffer<8, 4, 4> b {4, 2}; b.enter(); assert(b.length == 2); @@ -266,7 +266,7 @@ void test_enter_backspace3() // // b - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; b.put('a'); b.enter(); @@ -303,7 +303,7 @@ void test_copy() // qwer // j - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; b.put('a'); b.put('s'); @@ -357,7 +357,7 @@ void test_copy() void test_copy_same_line() { - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; // v // asdF @@ -394,7 +394,7 @@ void test_copy_same_line() void test_copy_multi_line_cow() { - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; // v // asdF @@ -422,7 +422,7 @@ void test_copy_multi_line_cow() void test_copy_multi_line_offset() { - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; b.put('a'); b.put('s'); @@ -477,7 +477,7 @@ void test_copy_multi_line_offset() void test_delete_from_line() { - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; b.put('a'); b.put('s'); @@ -499,7 +499,7 @@ void test_delete_from_line() void test_selection_delete() { - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; b.put('s'); b.put('p'); @@ -563,7 +563,7 @@ void test_selection_delete() void test_shadow_paste_oneline() { - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; b.put('q'); b.put('w'); @@ -636,7 +636,7 @@ void test_shadow_paste_oneline() void test_shadow_paste_multiline() { - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; // (qw // er @@ -733,7 +733,7 @@ void test_shadow_paste_multiline() void test_delete_forward() { - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; b.put('a'); b.put('b'); b.put('c'); @@ -765,7 +765,7 @@ void test_delete_forward() void test_delete_word_backward() { - buffer<8, 8> b {4, 2}; + buffer<8, 8, 8> b {4, 2}; b.put('q'); b.put('w'); diff --git a/res/Bm437_NEC_MultiSpeed.otb b/res/Bm437_NEC_MultiSpeed.otb new file mode 100644 index 0000000..4e59d45 Binary files /dev/null and b/res/Bm437_NEC_MultiSpeed.otb differ diff --git a/res/Bm437_NEC_MultiSpeed_bold.otb b/res/Bm437_NEC_MultiSpeed_bold.otb new file mode 100644 index 0000000..5eae614 Binary files /dev/null and b/res/Bm437_NEC_MultiSpeed_bold.otb differ