From 39cd149625f5d483f13a91d51097d95389aa5752 Mon Sep 17 00:00:00 2001 From: Burer Date: Wed, 24 Dec 2025 19:10:11 +0200 Subject: [PATCH 1/7] Piano refacoring, part 1 --- programs/media/piano/Tupfile.lua | 5 +- programs/media/piano/build.bat | 4 - programs/media/piano/piano.asm | 1251 ++++++++++-------------------- 3 files changed, 405 insertions(+), 855 deletions(-) delete mode 100644 programs/media/piano/build.bat diff --git a/programs/media/piano/Tupfile.lua b/programs/media/piano/Tupfile.lua index c5cb89def..bd6da2fad 100644 --- a/programs/media/piano/Tupfile.lua +++ b/programs/media/piano/Tupfile.lua @@ -1,7 +1,4 @@ if tup.getconfig("NO_FASM") ~= "" then return end HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR") tup.include(HELPERDIR .. "/use_fasm.lua") -add_include(tup.getvariantdir()) - -tup.rule("echo lang fix " .. ((tup.getconfig("LANG") == "") and "en_US" or tup.getconfig("LANG")) .. " > %o", {"lang.inc"}) -tup.rule({"piano.asm", extra_inputs = {"lang.inc"}}, FASM .. " %f %o " .. tup.getconfig("KPACK_CMD"), "piano") +tup.rule("piano.asm", FASM .. " -dlang=" .. tup.getconfig("LANG") .. " %f %o" .. tup.getconfig("KPACK_CMD"), "%B") diff --git a/programs/media/piano/build.bat b/programs/media/piano/build.bat deleted file mode 100644 index 38e19f7b2..000000000 --- a/programs/media/piano/build.bat +++ /dev/null @@ -1,4 +0,0 @@ -@echo lang fix en_US >lang.inc -@fasm piano.asm piano -@erase lang.inc -@pause diff --git a/programs/media/piano/piano.asm b/programs/media/piano/piano.asm index cdfadbfde..fe461352c 100644 --- a/programs/media/piano/piano.asm +++ b/programs/media/piano/piano.asm @@ -1,913 +1,470 @@ -; ⮩ ਬ ணࠬ KolibriOS -; 稢 ⮩ +; SPDX-License-Identifier: GPL-2.0-only ; -;--------------------------------------------------------------------- +; Piano - Toy Piano +; Copyright (C) 2019-2025 KolibriOS team +; +; Contributor ??? - Initial code +; Contributor Antonio - Refactoring and new functionality +; Contributor Burer - Refactoring and Spanish translation +; Contributor qullarwee - New keyboard layout - use32 - org 0 +; ==================================================================== - db 'MENUET01' - dd 1 - dd START - dd I_END - dd MEM - dd STACKTOP - dd 0 - dd 0 +use32 +org 0 -include "lang.inc" ; Language support for locales: ru_RU (CP866), en_US. -include "../../macros.inc" +; ==================================================================== + +db 'MENUET01' +dd 1 +dd START +dd I_END +dd MEM +dd STACKTOP +dd 0 +dd 0 + +; ==================================================================== + +include '../../macros.inc' include "../../KOSfuncs.inc" +include "../../encoding.inc" +; ==================================================================== START: -red: ; ᮢ - - call draw_window ; 뢠 楤 ᮢ + mcall SF_KEYBOARD, SSF_SET_INPUT_MODE, 1 + jmp redraw +; ==================================================================== still: - mcall SF_WAIT_EVENT - cmp eax,2 ; ? - je key ; ᫨ - key - cmp eax,3 ; ? - je button ; ᫨ - button - cmp eax,1 ; ᮢ ? - je red ; ᫨ - red + mcall SF_WAIT_EVENT - jmp still ; ᫨ 㣮 ᮡ⨥ - 砫 横 + cmp al, 1 + je redraw + cmp al, 2 + je key + cmp al, 3 + je button + jmp still +; ==================================================================== -;--------------------------------------------------------------------- +key: + mcall SF_GET_KEY - key: ; - mcall SF_GET_KEY ; ᨬ ( ah) + ; drop keys release + test ah, 0x80 + jnz still + ; open help window on Escape + cmp ah, KEY_ESC + je .help - cmp ah, 0x41 ; A - if Caps Lock ON - jnz @f - jmp _07 - @@: - cmp ah, 0x5a ; Z - jnz @f - jmp _08 - @@: - cmp ah, 0x53 ; S - jnz @f - jmp _09 - @@: - cmp ah, 0x58 ; X - jnz @f - jmp _0a - @@: - cmp ah, 0x44 ; D - jnz @f - jmp _0b - @@: - cmp ah, 0x43 ; C - jnz @f - jmp _0c - @@: - cmp ah, 0x56 ; V - jnz @f - _01: - mov ah, 0x01 - jmp p - @@: - cmp ah, 0x47 ; G - jnz @f - _02: - mov ah, 0x02 - jmp p - @@: - cmp ah, 0x42 ; B - jnz @f - _03: - mov ah, 0x03 - jmp p - @@: - cmp ah, 0x48 ; H - jnz @f - _04: - mov ah, 0x04 - jmp p - @@: - cmp ah, 0x4e ; N - jnz @f - _05: - mov ah, 0x05 - jmp p - @@: - cmp ah, 0x4d ; M - jnz @f - _06: - mov ah, 0x06 - jmp p - @@: - cmp ah, 0x4b ; K - jnz @f - _07: - mov ah, 0x07 - jmp p - @@: - cmp ah, 0x3c ; < - jnz @f - _08: - mov ah, 0x08 - jmp p - @@: - cmp ah, 0x4c ; L - jnz @f - _09: - mov ah, 0x09 - jmp p - @@: - cmp ah, 0x3e ; > - jnz @f - _0a: - mov ah, 0x0a - jmp p - @@: - cmp ah, 0x3a ; : - jnz @f - _0b: - mov ah, 0x0b - jmp p - @@: - cmp ah, 0x3f ; ? - jnz @f - _0c: - mov ah, 0x0c - jmp p - @@: - cmp ah, 0x22 ; " - jnz @f - jmp _11 - @@: - cmp ah, 0x21 ; key !------- - jnz @f - jmp _0c - @@: - cmp ah, 0x51 ; key Q - jnz @f - _11: - mov ah, 0x11 - jmp p - @@: - cmp ah, 0x40 ; key @ - jnz @f - _12: - mov ah, 0x12 - jmp p - @@: - cmp ah, 0x57 ; key W - jnz @f - _13: - mov ah, 0x13 - jmp p - @@: - cmp ah, 0x23 ; key # - jnz @f - _14: - mov ah, 0x14 - jmp p - @@: - cmp ah, 0x45 ; key E - jnz @f - _15: - mov ah, 0x15 - jmp p - @@: - cmp ah, 0x52 ; key R - jnz @f - _16: - mov ah, 0x16 - jmp p - @@: - cmp ah, 0x25 ; key % - jnz @f - jmp _17 - @@: - cmp ah, 0x54 ; key T - jnz @f - jmp _18 - @@: - cmp ah, 0x5e ; key ^ - jnz @f - jmp _19 - @@: - cmp ah, 0x59 ; key Y - jnz @f - jmp _1a - @@: - cmp ah, 0x26 ; key & - jnz @f - jmp _1b - @@: - cmp ah, 0x55 ; key U - jnz @f - jmp _1c - @@: - cmp ah, 0x49 ; key I - jnz @f - jmp _21 - @@: - cmp ah, 0x28 ; key ( - jnz @f - jmp _22 - @@: - cmp ah, 0x4f ; key O - jnz @f - jmp _23 - @@: - cmp ah, 0x29 ; key ) - jnz @f - jmp _24 - @@: - cmp ah, 0x50 ; key P - jnz @f - jmp _25 - @@: - cmp ah, 0x7b ; key { - jnz @f - jmp _26 - @@: - cmp ah, 0x2b ; key + - jnz @f - jmp _27 - @@: - cmp ah, 0x7d ; key } - jnz @f - jmp _28 - @@: - cmp ah, 0x7c ; key | - jnz @f - jmp _29 - @@: - cmp ah, 0x61 ; a - if Caps Lock OFF - jnz @f - _17: - mov ah, 0x17 - jmp p - @@: - cmp ah, 0x7a ; z - jnz @f - _18: - mov ah, 0x18 - jmp p - @@: - cmp ah, 0x73 ; s - jnz @f - _19: - mov ah, 0x19 - jmp p - @@: - cmp ah, 0x78 ; x - jnz @f - _1a: - mov ah, 0x1a - jmp p - @@: - cmp ah, 0x64 ; d - jnz @f - _1b: - mov ah, 0x1b - jmp p - @@: - cmp ah, 0x63 ; c - jnz @f - _1c: - mov ah, 0x1c - jmp p - @@: - cmp ah, 0x76 ; v - jnz @f - _21: - mov ah, 0x21 - jmp p - @@: - cmp ah, 0x67 ; g - jnz @f - _22: - mov ah, 0x22 - jmp p - @@: - cmp ah, 0x62 ; b - jnz @f - _23: - mov ah, 0x23 - jmp p - @@: - cmp ah, 0x68 ; h - jnz @f - _24: - mov ah, 0x24 - jmp p - @@: - cmp ah, 0x6e ; n - jnz @f - _25: - mov ah, 0x25 - jmp p - @@: - cmp ah, 0x6d ; m - jnz @f - _26: - mov ah, 0x26 - jmp p - @@: - cmp ah, 0x6b ; k - jnz @f - _27: - mov ah, 0x27 - jmp p - @@: - cmp ah, 0x2c ; , - jnz @f - _28: - mov ah, 0x28 - jmp p - @@: - cmp ah, 0x6c ; l - jnz @f - _29: - mov ah, 0x29 - jmp p - @@: - cmp ah, 0x2e ; . - jnz @f - _2a: - mov ah, 0x2a - jmp p - @@: - cmp ah, 0x3b ; ; - jnz @f - _2b: - mov ah, 0x2b - jmp p - @@: - cmp ah, 0x2f ; / - jnz @f - _2c: - mov ah, 0x2c - jmp p - @@: - cmp ah, 0x27 ; ' - jnz @f - _31: - mov ah, 0x31 - jmp p - @@: - cmp ah, 0x60 ; key ` - jnz @f - jmp _2c - @@: - cmp ah, 0x09 ; key tab - jnz @f - jmp _31 - @@: - cmp ah, 0x31 ; key 1 - jnz @f - _32: - mov ah, 0x32 - jmp p - @@: - cmp ah, 0x71 ; key q - jnz @f - _33: - mov ah, 0x33 - jmp p - @@: - cmp ah, 0x32 ; key 2 - jnz @f - _34: - mov ah, 0x34 - jmp p - @@: - cmp ah, 0x77 ; key w - jnz @f - _35: - mov ah, 0x35 - jmp p - @@: - cmp ah, 0x65 ; key e - jnz @f - _36: - mov ah, 0x36 - jmp p - @@: - cmp ah, 0x34 ; key 4 - jnz @f - _37: - mov ah, 0x37 - jmp p - @@: - cmp ah, 0x72 ; key r - jnz @f - _38: - mov ah, 0x38 - jmp p - @@: - cmp ah, 0x35 ; key 5 - jnz @f - _39: - mov ah, 0x39 - jmp p - @@: - cmp ah, 0x74 ; key t - jnz @f - _3a: - mov ah, 0x3a - jmp p - @@: - cmp ah, 0x36 ; key 6 - jnz @f - _3b: - mov ah, 0x3b - jmp p - @@: - cmp ah, 0x79 ; key y - jnz @f - _3c: - mov ah, 0x3c - jmp p - @@: - cmp ah, 0x75 ; key u - jnz @f - _41: - mov ah, 0x41 - jmp p - @@: - cmp ah, 0x38 ; key 8 - jnz @f - mov ah, 0x42 - jmp p - @@: - cmp ah, 0x69 ; key i - jnz @f - mov ah, 0x43 - jmp p - @@: - cmp ah, 0x39 ; key 9 - jnz @f - mov ah, 0x44 - jmp p - @@: - cmp ah, 0x6f ; key o - jnz @f - mov ah, 0x45 - jmp p - @@: - cmp ah, 0x70 ; key p - jnz @f - mov ah, 0x46 - jmp p - @@: - cmp ah, 0x2d ; key - - jnz @f - mov ah, 0x47 - jmp p - @@: - cmp ah, 0x5b ; key [ - jnz @f - mov ah, 0x48 - jmp p - @@: - cmp ah, 0x3d ; key = - jnz @f - mov ah, 0x49 - jmp p - @@: - cmp ah, 0x5d ; key ] - jnz @f - mov ah, 0x4a - jmp p - @@: - cmp ah, 0x5c ; key \ - jnz @f - mov ah, 0x4b - jmp p - @@: - cmp ah, 0x08 ; key backspace - jnz @f - mov ah, 0x4c - jmp p - @@: - cmp ah, 0x0d ; key enter - jnz @f - mov ah, 0x51 - jmp p - @@: - cmp ah, 0x66 ; key f - jnz @f - mov ah, 0x01 - jmp p - @@: - cmp ah, 0x6a ; key j - jnz @f - mov ah, 0x05 - jmp p - @@: - cmp ah, 0x33 ; key 3 - jnz @f - mov ah, 0x08 - jmp p - @@: - cmp ah, 0x37 ; key 7 - jnz @f - jmp _11 - @@: - cmp ah, 0x30 ; key 0 - jnz @f - jmp _15 - @@: - cmp ah, 0xb4 ; key home - jnz @f - mov ah, 0x10 - jmp p - @@: - cmp ah, 0xb5 ; key end - jnz @f - _70: - mov ah, 0xfc - jmp p - @@: - cmp ah, 0xb8 ; key Page Up - jnz @f - mov ah, 0x20 - jmp p - @@: - cmp ah, 0xb7 ; key Page Down - jnz @f - jmp _70 - @@: - cmp ah, 0xff ; key F12 - jnz @f - mov ah, 0x00 - jmp p - @@: - cmp ah, 0xb6 ; key Del - jnz @f - jmp _70 - @@: + ; check if Shift is pressed + ; increase note_id by 0x40 + mov bl, ah + mcall SF_KEYBOARD, SSF_GET_CONTROL_KEYS + xor dl, dl + test al, KEY_SHIFT + jz .key_map_setup + mov dl, INC_SHIFT - p: - mov [M+1], ah ; ᨬ + ; loop to find note_id by key_scancode + .key_map_setup: - ; 㭪 55-55: ⥬ ("PlayNote") - ; esi - + mov edi, key_note_map - mov eax,SF_SPEAKER_PLAY - mov ebx,eax - mov esi,M - int 0x40 + .key_note_loop: - ; ⪮: - ;mcall SF_SPEAKER_PLAY, , , , Music + cmp edi, key_note_map_end + jae still + cmp bl, [edi] + jne .key_note_next + mov ah, [edi + 1] + add ah, dl + jmp play - jmp still ; 砫 横 + .key_note_next: + add edi, KM_SIZE + jmp .key_note_loop -;--------------------------------------------------------------------- + ; help window thread creation + .help: - button: - mcall SF_GET_BUTTON + cmp [hp_tid], 0 + jne still + mcall SF_CREATE_THREAD, 1, help_thread, help_stack_top + cmp eax, -1 + je still + mov [hp_tid], eax + jmp still - cmp ah, 0xa1 ; button 1 - jnz @f - jmp _01 - @@: - cmp ah, 0x02 ; button 2 - jnz @f - jmp _02 - @@: - cmp ah, 0x03 ; button 3 - jnz @f - jmp _03 - @@: - cmp ah, 0x04 - jnz @f - jmp _04 - @@: - cmp ah, 0x05 - jnz @f - jmp _05 - @@: - cmp ah, 0x06 - jnz @f - jmp _06 - @@: - cmp ah, 0x07 - jnz @f - jmp _07 - @@: - cmp ah, 0x08 ; button 8 - jnz @f - jmp _08 - @@: - cmp ah, 0x09 - jnz @f - jmp _09 - @@: - cmp ah, 0x0a ; button 10 - jnz @f - jmp _0a - @@: - cmp ah, 0x0b - jnz @f - jmp _0b - @@: - cmp ah, 0x0c ; button 12 - jnz @f - jmp _0c - @@: +button: - cmp ah, 0x11 - jnz @f - jmp _11 - @@: - cmp ah, 0x12 - jnz @f - jmp _12 - @@: - cmp ah, 0x13 - jnz @f - jmp _13 - @@: - cmp ah, 0x14 - jnz @f - jmp _14 - @@: - cmp ah, 0x15 - jnz @f - jmp _15 - @@: - cmp ah, 0x16 - jnz @f - jmp _16 - @@: - cmp ah, 0x17 - jnz @f - jmp _17 - @@: - cmp ah, 0x18 - jnz @f - jmp _18 - @@: - cmp ah, 0x19 - jnz @f - jmp _19 - @@: - cmp ah, 0x1a - jnz @f - jmp _1a - @@: - cmp ah, 0x1b - jnz @f - jmp _1b - @@: - cmp ah, 0x1c - jnz @f - jmp _1c - @@: + mcall SF_GET_BUTTON - cmp ah, 0x21 ; button 1 - jnz @f - jmp _21 - @@: - cmp ah, 0x22 - jnz @f - jmp _22 - @@: - cmp ah, 0x23 ; button 3 - jnz @f - jmp _23 - @@: - cmp ah, 0x24 - jnz @f - jmp _24 - @@: - cmp ah, 0x25 ; button 5 - jnz @f - jmp _25 - @@: - cmp ah, 0x26 - jnz @f - jmp _26 - @@: - cmp ah, 0x27 ; button 7 - jnz @f - jmp _27 - @@: - cmp ah, 0x28 - jnz @f - jmp _28 - @@: - cmp ah, 0x29 ; button 9 - jnz @f - jmp _29 - @@: - cmp ah, 0x2a - jnz @f - jmp _2a - @@: - cmp ah, 0x2b ; button 11 - jnz @f - jmp _2b - @@: - cmp ah, 0x2c - jnz @f - jmp _2c - @@: - cmp ah, 0x31 - jnz @f - jmp _31 + cmp ah, 1 + je .exit - @@: - cmp ah, 0x32 - jnz @f - jmp _32 - @@: - cmp ah, 0x33 - jnz @f - jmp _33 - @@: - cmp ah, 0x34 - jnz @f - jmp _34 - @@: - cmp ah, 0x35 - jnz @f - jmp _35 - @@: - cmp ah, 0x36 - jnz @f - jmp _36 - @@: - cmp ah, 0x37 - jnz @f - jmp _37 - @@: - cmp ah, 0x38 - jnz @f - jmp _38 - @@: - cmp ah, 0x39 - jnz @f - jmp _39 - @@: - cmp ah, 0x3a - jnz @f - jmp _3a - @@: - cmp ah, 0x3b - jnz @f - jmp _3b - @@: - cmp ah, 0x3c - jnz @f - jmp _3c - @@: - cmp ah, 0x41 - jnz @f - jmp _41 - @@: + ; note_id is always button_id - 0x10 + sub ah, 0x10 + jmp play - cmp ah, 1 ; ᫨ ஬ 1, - jne still ; + .exit: + mcall SF_TERMINATE_PROCESS - .exit: - mcall SF_TERMINATE_PROCESS ; ணࠬ +; ======================================================================= +play: -;--------------------------------------------------------------------- -;--- ---------------------------------- -;--------------------------------------------------------------------- + mov [melody + 1], ah + mcall SF_SPEAKER_PLAY, SF_SPEAKER_PLAY, , , , melody -WHITE_W=48 ; While key width -BLACK_W=30 ; Black key width -BLACK_X=34 ; Black key X offset + jmp still -draw_window: +; ======================================================================= - mcall SF_REDRAW, SSF_BEGIN_DRAW ; ᮮ 砫 ᮢ +redraw: - mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc,sizeof.system_colors + mcall SF_REDRAW, SSF_BEGIN_DRAW + mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc, sizeof.system_colors + mcall , SSF_GET_SKIN_HEIGHT, + mov ecx, eax + add ecx, WN_MAIN.Y shl 16 + WN_MAIN.H + mov edx, [sc.work] + or edx, 0x34000000 + mcall SF_CREATE_WINDOW, , , , , cp_main - mov edx, [sc.work] ; 梥 䮭 - or edx, 0x33000000 ; ⨯ 3 - mcall SF_CREATE_WINDOW, <20,WHITE_W*15+9>, <200,250>, , ,caption + ; white buttons rows + mov eax, SF_DEFINE_BUTTON ; constant syscall number + mov ebx, BT_WHITE.X shl 16 + BT_WHITE.W ; packed , x starts at 0 + mov ecx, BT_WHITE.Y shl 16 + BT_WHITE.H ; packed , constant + mov edi, white_top_buttons + mov ebp, white_bottom_buttons - mcall SF_DEFINE_BUTTON, , <0,100>, 0x21, 0xff7a74 - mcall , , <0,100>, 0x23, 0x907040 - mcall , , , 0x25, 0xa08050 - mcall , , , 0x26, 0xb09060 - mcall , , , 0x28, 0xc0a070 - mcall , , , 0x2a, 0xd0b080 - mcall , , , 0x2c, 0xe0c090 - mcall , , , 0x31, 0xffa97c - mcall , , , 0x33, 0xaf8d8d - mcall , , , 0x35, 0xbf9d9d - mcall , , , 0x36, 0xcfadad - mcall , , , 0x38, 0xdfbdbd - mcall , , , 0x3a, 0xefcdcd - mcall , , , 0x3c, 0xffdddd - mcall , , , 0x41, 0xffe558 + .white_buttons_loop: - mcall , , <0,50>, 0x22, 0x221100 - mcall , , , 0x24, - mcall , , , 0x27, - mcall , , , 0x29, - mcall , , , 0x2b, - mcall , , , 0x32, - mcall , , , 0x34, - mcall , , , 0x37, - mcall , , , 0x39, - mcall , , , 0x3b, + cmp edi, white_top_buttons_end + jae .black_buttons_setup - mcall , , <100,100>, 0xa1, 0x702050 - mcall , , , 0x03, 0x683638 - mcall , , , 0x05, 0x784648 - mcall , , , 0x06, 0x885658 - mcall , , , 0x08, 0x986668 - mcall , , , 0x0a, 0xa87678 - mcall , , , 0x0c, 0xb88688 - mcall , , , 0x11, 0x880040 - mcall , , , 0x13, 0x90622b - mcall , , , 0x15, 0xa0723b - mcall , , , 0x16, 0xb0824b - mcall , , , 0x18, 0xc0925b - mcall , , , 0x1a, 0xd0a26b - mcall , , , 0x1c, 0xe0b27b - mcall , , , 0x21, 0xff7a74 + mov edx, [edi] + mov esi, [edi + 4] + mcall - mcall , , <100,50>, 0x02, 0x221100 - mcall , , , 0x04, - mcall , , , 0x07, - mcall , , , 0x09, - mcall , , , 0x0b, - mcall , , , 0x12, - mcall , , , 0x14, - mcall , , , 0x17, - mcall , , , 0x19, - mcall , , , 0x1b, + mov ecx, (BT_WHITE.Y + BT_WHITE.H) shl 16 + BT_WHITE.H + mov edx, [ebp] + mov esi, [ebp + 4] + mcall + mov ecx, BT_WHITE.Y shl 16 + BT_WHITE.H + add ebx, BT_WHITE.W shl 16 + add edi, DT_SIZE + add ebp, DT_SIZE + jmp .white_buttons_loop - ; 뢮 ⥪⮢ ப - mov ecx, [sc.work_text] ; 梥 䮭 - or ecx, 0x90000000 ; ⨯ ப - mcall SF_DRAW_TEXT, <50, 205>, , message - mcall , <10, 235>, , message1 - mcall , <10, 260>, , message2 - mcall , <10, 285>, , message3 - mcall , <10, 310>, , message4 - mcall , <16, 185>, , t_notes + ; black buttons rows + .black_buttons_setup: - mcall SF_REDRAW, SSF_END_DRAW ; 稫 ᮢ + mov esi, 0x00221100 ; constant color + mov edi, black_buttons - ret + .black_buttons_loop: + cmp edi, black_buttons_end + jae .black_buttons_loop_end -;--------------------------------------------------------------------- -;--- ---------------------------------------------- -;--------------------------------------------------------------------- + movzx ebx, byte [edi] + imul ebx, BT_WHITE.W + add ebx, BT_BLACK.X + shl ebx, 16 + mov bx, BT_BLACK.W + movzx edx, byte [edi + 1] -; ன M (Music) ⨥ + mov ecx, (BT_WHITE.Y + BT_BLACK.Y) shl 16 + BT_BLACK.H ; top row + add edx, 0x20 + mcall -M: - db 0x90, 0x30, 0 + mov ecx, (BT_WHITE.Y + BT_WHITE.H + BT_BLACK.Y) shl 16 + BT_BLACK.H ; bottom row + sub edx, 0x20 + mcall + add edi, BL_SIZE + jmp .black_buttons_loop -sc system_colors + .black_buttons_loop_end: + + ; notes labels + mcall SF_DRAW_TEXT, , 0x90FFFFFF, lb_notes + + mcall SF_REDRAW, SSF_END_DRAW + + jmp still + +; ======================================================================= + +help_thread: + + jmp .help_redraw + + .help_still: + + mcall SF_WAIT_EVENT + + cmp al, 1 + je .help_redraw + cmp al, 3 + je .help_button + + jmp .help_still + + .help_button: + + mcall SF_GET_BUTTON + cmp ah, 1 + jne .help_still + + mov dword [hp_tid], 0 + mcall SF_TERMINATE_PROCESS + + .help_redraw: + + mcall SF_REDRAW, SSF_BEGIN_DRAW + mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc, sizeof.system_colors + mcall , SSF_GET_SKIN_HEIGHT, + + mov ecx, eax + add ecx, WN_HELP.Y shl 16 + WN_HELP.H + mov edx, [sc.work] + or edx, 0x34000000 + mcall SF_CREATE_WINDOW, , , , , cp_help + + mov eax, SF_DRAW_TEXT + mov ecx, [sc.work_text] + or ecx, 0x90000000 + mov ebx, RT_HELP.X shl 16 + RT_HELP.Y + mov edi, help_texts + + ; draw all help text in rows + .help_text_loop: + + cmp edi, help_texts_end + jae .help_text_loop_done + + mov edx, [edi] + mcall + + add ebx, RT_HELP.H + add edi, 4 + jmp .help_text_loop + + .help_text_loop_done: + + mcall SF_REDRAW, SSF_END_DRAW + jmp help_thread.help_still + +; ======================================================================= + +sc system_colors + +WN_MAIN RECT 32, 32, BT_WHITE.W * 15 + 10, BT_WHITE.H * 2 + 9 + +BT_WHITE RECT 0, 4, 48, 100 +BT_BLACK RECT 33, 0, 30, 50 + +RT_HELP RECT 8, 8, 0, 24 + +KEY_ESC = 0x01 +KEY_SHIFT = 0x03 +INC_SHIFT = 0x40 + +; ======================================================================= if lang eq ru_RU - message db 'ࠢ: 񫪭 2 ࠧ .',0 - message1 db ' ᪮ ᪫ - ',0 - message2 db ' ஥ ( !)',0 - message3 db ' "" - V,Tab,U,Enter',0 - message4 db ' 祭 Caps Lock - V,Q,I.',0 - t_notes db ' ',0 - caption db '᪮ ',0 -else ; Default to en_US - message db 'Click twice on the window header to see help.',0 - message1 db 'Press any key in English keyboard layout - ',0 - message2 db 'so you will hear the sound from the PC-speaker (Beeper)',0 - message3 db 'Note "C" is the key V,Tab,U,Enter',0 - message4 db 'and when Caps Lock is on then the keys V,Q,I.',0 - t_notes db 'C D E F G A B C ',0 - caption db 'Toy piano',0 + + cp_main cp866 "Детское Пианино [Escape - Открыть Справку]", 0 + cp_help cp866 "Детское Пианино - Справка", 0 + lb_help1 cp866 "Клавиши от 1 до = и от Q до ] - верхний ряд.", 0 + lb_help2 cp866 "Клавиши от A до Enter и от Z до /, \ и Backspace - нижний ряд.", 0 + lb_help3 cp866 "Удерживайте Shift для повышения октавы на 4.", 0 + lb_help4 cp866 "Должен звучать встроенный динамик ПК (не колонки).", 0 + lb_notes cp866 "ДО РЕ МИ ФА СОЛЬ ЛЯ СИ ДО", 0 + + WN_HELP RECT 64, 64, 521, 106 + RT_NOTES RECT 16, 183, 0, 0 + +else if lang eq es_ES + + cp_main db "Piano de Juguete [Escape - Abrir Ayuda]", 0 + cp_help db "Piano de Juguete - Ayuda", 0 + lb_help1 db "Teclas de 1 a = y de Q a ] - fila superior.", 0 + lb_help2 db "Teclas de A a Enter y de Z a /, \ y Backspace - fila inferior.", 0 + lb_help3 db "Mantenga Shift para subir 4 octavas.", 0 + lb_help4 db "Deberias oir el altavoz interno del PC (no los externos).", 0 + lb_notes db "DO RE MI FA SOL LA SI DO", 0 + + WN_HELP RECT 64, 64, 521, 106 + RT_NOTES RECT 16, 183, 0, 0 + +else + + cp_main db "Toy Piano [Escape - Open Help]", 0 + cp_help db "Toy Piano - Help", 0 + lb_help1 db "Keys from 1 to = and from Q to ] - top row.", 0 + lb_help2 db "Keys from A to Enter and from Z to /, \ and Backspace - bottom row.", 0 + lb_help3 db "Hold Shift to raise the octave by 4.", 0 + lb_help4 db "You should hear the built-in PC speaker (not external speakers).", 0 + lb_notes db "C D E F G A B C", 0 + + WN_HELP RECT 64, 64, 561, 106 + RT_NOTES RECT 20, 183, 0, 0 + end if -;--------------------------------------------------------------------- +; ======================================================================= + +DT_SIZE = 8 ; white buttons entry size +BL_SIZE = 2 ; black buttons entry size + +; button id and color +white_top_buttons: + dd 0x31, 0xFF7A74 + dd 0x33, 0x907040 + dd 0x35, 0xA08050 + dd 0x36, 0xB09060 + dd 0x38, 0xC0A070 + dd 0x3A, 0xD0B080 + dd 0x3C, 0xE0C090 + dd 0x41, 0xFFA97C + dd 0x43, 0xAF8D8D + dd 0x45, 0xBF9D9D + dd 0x46, 0xCFADAD + dd 0x48, 0xDFBDBD + dd 0x4A, 0xEFCDCD + dd 0x4C, 0xFFDDDD + dd 0x51, 0xFFE558 +white_top_buttons_end: + +; button id and color +white_bottom_buttons: + dd 0x11, 0x702050 + dd 0x13, 0x683638 + dd 0x15, 0x784648 + dd 0x16, 0x885658 + dd 0x18, 0x986668 + dd 0x1A, 0xA87678 + dd 0x1C, 0xB88688 + dd 0x21, 0x880040 + dd 0x23, 0x90622B + dd 0x25, 0xA0723B + dd 0x26, 0xB0824B + dd 0x28, 0xC0925B + dd 0x2A, 0xD0A26B + dd 0x2C, 0xE0B27B + dd 0x31, 0xFF7A74 +white_bottom_buttons_end: + +; parent white button id and button id +black_buttons: + db 0x00, 0x12 + db 0x01, 0x14 + db 0x03, 0x17 + db 0x04, 0x19 + db 0x05, 0x1B + db 0x07, 0x22 + db 0x08, 0x24 + db 0x0A, 0x27 + db 0x0B, 0x29 + db 0x0C, 0x2B +black_buttons_end: + +; corrensponding help string label +help_texts: + dd lb_help1 + dd lb_help2 + dd lb_help3 + dd lb_help4 +help_texts_end: + +; ======================================================================= + +KM_SIZE = 2 ; key map entry size + +; key scancode and note id +key_note_map: + db 0x02, 0x31 ; '1' -> note 0x31 + db 0x03, 0x32 ; '2' -> note 0x32 + db 0x04, 0x33 ; '3' -> note 0x33 + db 0x05, 0x34 ; '4' -> note 0x34 + db 0x06, 0x35 ; '5' -> note 0x35 + db 0x07, 0x36 ; '6' -> note 0x36 + db 0x08, 0x37 ; '7' -> note 0x37 + db 0x09, 0x38 ; '8' -> note 0x38 + db 0x0A, 0x39 ; '9' -> note 0x39 + db 0x0B, 0x3A ; '0' -> note 0x3A + db 0x0C, 0x3B ; '-' -> note 0x3B + db 0x0D, 0x3C ; '=' -> note 0x3C + + db 0x10, 0x41 ; 'q' -> note 0x41 + db 0x11, 0x42 ; 'w' -> note 0x42 + db 0x12, 0x43 ; 'e' -> note 0x43 + db 0x13, 0x44 ; 'r' -> note 0x44 + db 0x14, 0x45 ; 't' -> note 0x45 + db 0x15, 0x46 ; 'y' -> note 0x46 + db 0x16, 0x47 ; 'u' -> note 0x47 + db 0x17, 0x48 ; 'i' -> note 0x48 + db 0x18, 0x49 ; 'o' -> note 0x49 + db 0x19, 0x4A ; 'p' -> note 0x4A + db 0x1A, 0x4B ; '[' -> note 0x4B + db 0x1B, 0x4C ; ']' -> note 0x4C + + db 0x1E, 0x11 ; 'a' -> note 0x11 + db 0x1F, 0x12 ; 's' -> note 0x12 + db 0x20, 0x13 ; 'd' -> note 0x13 + db 0x21, 0x14 ; 'f' -> note 0x14 + db 0x22, 0x15 ; 'g' -> note 0x15 + db 0x23, 0x16 ; 'h' -> note 0x16 + db 0x24, 0x17 ; 'j' -> note 0x17 + db 0x25, 0x18 ; 'k' -> note 0x18 + db 0x26, 0x19 ; 'l' -> note 0x19 + db 0x27, 0x1A ; ';' -> note 0x1A + db 0x28, 0x1B ; ''' -> note 0x1B + db 0x1C, 0x1C ; Enter -> note 0x1C + + db 0x2C, 0x21 ; 'z' -> note 0x21 + db 0x2D, 0x22 ; 'x' -> note 0x22 + db 0x2E, 0x23 ; 'c' -> note 0x23 + db 0x2F, 0x24 ; 'v' -> note 0x24 + db 0x30, 0x25 ; 'b' -> note 0x25 + db 0x31, 0x26 ; 'n' -> note 0x26 + db 0x32, 0x27 ; 'm' -> note 0x27 + db 0x33, 0x28 ; ',' -> note 0x28 + db 0x34, 0x29 ; '.' -> note 0x29 + db 0x35, 0x2A ; '/' -> note 0x2A + db 0x2B, 0x2B ; '\' -> note 0x2B + db 0x0E, 0x2C ; Backspace -> note 0x2C +key_note_map_end: + +; ======================================================================= + +melody db 0x90, 0x30, 0 +hp_tid dd 0 + +; ======================================================================= I_END: - rb 4096 -align 16 +help_stack: + rb 512 +help_stack_top: + rb 1024 + align 512 STACKTOP: MEM: -- 2.49.1 From 498ec0d2765e379719fe312c8220a3b5737f6309 Mon Sep 17 00:00:00 2001 From: Burer Date: Fri, 26 Dec 2025 20:58:46 +0200 Subject: [PATCH 2/7] apps/piano: refactoring, part 2 - Fixed bugs in keys and buttons reading and audio play - Refactored data tables and removed loops - Used more constants for everything - Changes Spanish encoding to CP850 - Shifted notes on keys by -0x10 to match buttons - Configured events mask for help thread - Shift now works for buttons also - Help window have relative coordinates from main window - Maybe something else that I already forgot Co-authored-by: Doczom --- programs/media/piano/piano.asm | 381 ++++++++++++++++++--------------- 1 file changed, 205 insertions(+), 176 deletions(-) diff --git a/programs/media/piano/piano.asm b/programs/media/piano/piano.asm index fe461352c..6871ea9cc 100644 --- a/programs/media/piano/piano.asm +++ b/programs/media/piano/piano.asm @@ -6,6 +6,7 @@ ; Contributor ??? - Initial code ; Contributor Antonio - Refactoring and new functionality ; Contributor Burer - Refactoring and Spanish translation +; Contributor Doczom - Refactoring and bugfixes ; Contributor qullarwee - New keyboard layout ; ==================================================================== @@ -15,7 +16,7 @@ org 0 ; ==================================================================== -db 'MENUET01' +db "MENUET01" dd 1 dd START dd I_END @@ -26,28 +27,26 @@ dd 0 ; ==================================================================== -include '../../macros.inc' +include "../../macros.inc" include "../../KOSfuncs.inc" include "../../encoding.inc" ; ==================================================================== START: - mcall SF_KEYBOARD, SSF_SET_INPUT_MODE, 1 jmp redraw ; ==================================================================== still: - mcall SF_WAIT_EVENT - cmp al, 1 + cmp al, EV_REDRAW je redraw - cmp al, 2 + cmp al, EV_KEY je key - cmp al, 3 + cmp al, EV_BUTTON je button jmp still @@ -55,7 +54,6 @@ still: ; ==================================================================== key: - mcall SF_GET_KEY ; drop keys release @@ -68,46 +66,50 @@ key: ; check if Shift is pressed ; increase note_id by 0x40 - mov bl, ah + movzx ecx, ah mcall SF_KEYBOARD, SSF_GET_CONTROL_KEYS - xor dl, dl + xor edx, edx + test al, KEY_SHIFT - jz .key_map_setup + jz .key_map_play + mov dl, INC_SHIFT - ; loop to find note_id by key_scancode - .key_map_setup: - - mov edi, key_note_map - - .key_note_loop: - - cmp edi, key_note_map_end + ; play note if valid key pressed + .key_map_play: + cmp cl, key_note_map.count jae still - cmp bl, [edi] - jne .key_note_next - mov ah, [edi + 1] + + mov ah, [key_note_map + ecx] + cmp ah, BAD_NOTE + je still + add ah, dl jmp play - .key_note_next: - - add edi, KM_SIZE - jmp .key_note_loop - ; help window thread creation .help: - - cmp [hp_tid], 0 + cmp [hw_tid], 0 jne still + + sub esp, 1024 + mov ebx, esp + mcall SF_THREAD_INFO, ebx, -1 + mov eax, [esp + process_information.box.left] + mov edx, [esp + process_information.box.top] + add esp, 1024 + shl eax, 16 + mov ax, dx + mov [mw_pos], eax + mcall SF_CREATE_THREAD, 1, help_thread, help_stack_top cmp eax, -1 je still - mov [hp_tid], eax + + mov [hw_tid], eax jmp still button: - mcall SF_GET_BUTTON cmp ah, 1 @@ -115,24 +117,33 @@ button: ; note_id is always button_id - 0x10 sub ah, 0x10 - jmp play + mov dl, ah - .exit: - mcall SF_TERMINATE_PROCESS + ; check if Shift is pressed + ; increase note_id by 0x40 + mcall SF_KEYBOARD, SSF_GET_CONTROL_KEYS + test al, KEY_SHIFT + jz .no_shift + add dl, INC_SHIFT + + .no_shift: + mov ah, dl + jmp play + +.exit: + mcall SF_TERMINATE_PROCESS ; ======================================================================= play: - mov [melody + 1], ah - mcall SF_SPEAKER_PLAY, SF_SPEAKER_PLAY, , , , melody + mcall SF_SPEAKER_PLAY, SF_SPEAKER_PLAY, , , melody jmp still ; ======================================================================= redraw: - mcall SF_REDRAW, SSF_BEGIN_DRAW mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc, sizeof.system_colors mcall , SSF_GET_SKIN_HEIGHT, @@ -140,34 +151,35 @@ redraw: mov ecx, eax add ecx, WN_MAIN.Y shl 16 + WN_MAIN.H mov edx, [sc.work] - or edx, 0x34000000 + or edx, 0x34000000 ; skin, no resize, caption, client area mcall SF_CREATE_WINDOW, , , , , cp_main ; white buttons rows mov eax, SF_DEFINE_BUTTON ; constant syscall number mov ebx, BT_WHITE.X shl 16 + BT_WHITE.W ; packed , x starts at 0 mov ecx, BT_WHITE.Y shl 16 + BT_WHITE.H ; packed , constant - mov edi, white_top_buttons - mov ebp, white_bottom_buttons + mov edi, white_button_colors + mov ebp, white_button_ids .white_buttons_loop: - - cmp edi, white_top_buttons_end + cmp edi, end_white_button_colors jae .black_buttons_setup - mov edx, [edi] - mov esi, [edi + 4] + movzx edx, byte[ebp] + mov esi, [edi] mcall mov ecx, (BT_WHITE.Y + BT_WHITE.H) shl 16 + BT_WHITE.H - mov edx, [ebp] - mov esi, [ebp + 4] + movzx edx, byte[ebp + 1] + mov esi, [edi + 4] mcall mov ecx, BT_WHITE.Y shl 16 + BT_WHITE.H add ebx, BT_WHITE.W shl 16 - add edi, DT_SIZE - add ebp, DT_SIZE + + add edi, WT_SIZE + add ebp, 2 + jmp .white_buttons_loop ; black buttons rows @@ -177,7 +189,6 @@ redraw: mov edi, black_buttons .black_buttons_loop: - cmp edi, black_buttons_end jae .black_buttons_loop_end @@ -206,76 +217,83 @@ redraw: mcall SF_DRAW_TEXT, , 0x90FFFFFF, lb_notes mcall SF_REDRAW, SSF_END_DRAW - jmp still ; ======================================================================= help_thread: + mcall SF_SET_EVENTS_MASK, EVM_REDRAW + EVM_BUTTON + jmp .redraw - jmp .help_redraw - - .help_still: - + .still: mcall SF_WAIT_EVENT - cmp al, 1 - je .help_redraw - cmp al, 3 - je .help_button + cmp al, EV_REDRAW + je .redraw + cmp al, EV_BUTTON + je .button - jmp .help_still - - .help_button: + jmp .still + .button: mcall SF_GET_BUTTON cmp ah, 1 - jne .help_still + jne .still - mov dword [hp_tid], 0 + mov dword [hw_tid], 0 mcall SF_TERMINATE_PROCESS - .help_redraw: - + .redraw: mcall SF_REDRAW, SSF_BEGIN_DRAW mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc, sizeof.system_colors mcall , SSF_GET_SKIN_HEIGHT, - mov ecx, eax - add ecx, WN_HELP.Y shl 16 + WN_HELP.H + mov ebp, eax + mov ebx, [mw_pos] + mov ecx, ebx + shr ebx, 16 + and ecx, 0xFFFF + + add ebx, WN_HELP.X + shl ebx, 16 + mov bx, WN_HELP.W + + add ecx, WN_HELP.Y + add ecx, ebp + shl ecx, 16 + mov cx, WN_HELP.H + mov edx, [sc.work] - or edx, 0x34000000 - mcall SF_CREATE_WINDOW, , , , , cp_help + or edx, 0x34000000 ; skin, no resize, caption, client area + mcall SF_CREATE_WINDOW, , , , , cp_help mov eax, SF_DRAW_TEXT mov ecx, [sc.work_text] - or ecx, 0x90000000 + or ecx, 0x90000000 ; null terminator, 8x16 OLE mov ebx, RT_HELP.X shl 16 + RT_HELP.Y mov edi, help_texts ; draw all help text in rows .help_text_loop: - cmp edi, help_texts_end jae .help_text_loop_done mov edx, [edi] - mcall + mcall ; draw text add ebx, RT_HELP.H add edi, 4 jmp .help_text_loop .help_text_loop_done: - mcall SF_REDRAW, SSF_END_DRAW - jmp help_thread.help_still + jmp .still ; ======================================================================= sc system_colors -WN_MAIN RECT 32, 32, BT_WHITE.W * 15 + 10, BT_WHITE.H * 2 + 9 +WN_MAIN RECT 32, 32, BT_WHITE.W * 15 + 10, BT_WHITE.H * 2 + (5 + 4) BT_WHITE RECT 0, 4, 48, 100 BT_BLACK RECT 33, 0, 30, 50 @@ -298,20 +316,20 @@ if lang eq ru_RU lb_help4 cp866 "Должен звучать встроенный динамик ПК (не колонки).", 0 lb_notes cp866 "ДО РЕ МИ ФА СОЛЬ ЛЯ СИ ДО", 0 - WN_HELP RECT 64, 64, 521, 106 + WN_HELP RECT 14, 13, 521, 106 RT_NOTES RECT 16, 183, 0, 0 else if lang eq es_ES - cp_main db "Piano de Juguete [Escape - Abrir Ayuda]", 0 - cp_help db "Piano de Juguete - Ayuda", 0 - lb_help1 db "Teclas de 1 a = y de Q a ] - fila superior.", 0 - lb_help2 db "Teclas de A a Enter y de Z a /, \ y Backspace - fila inferior.", 0 - lb_help3 db "Mantenga Shift para subir 4 octavas.", 0 - lb_help4 db "Deberias oir el altavoz interno del PC (no los externos).", 0 - lb_notes db "DO RE MI FA SOL LA SI DO", 0 + cp_main cp850 "Piano de Juguete [Escape - Abrir Ayuda]", 0 + cp_help cp850 "Piano de Juguete - Ayuda", 0 + lb_help1 cp850 "Teclas de 1 a = y de Q a ] - fila superior.", 0 + lb_help2 cp850 "Teclas de A a Enter y de Z a /, \ y Backspace - fila inferior.", 0 + lb_help3 cp850 "Mantenga Shift para subir 4 octavas.", 0 + lb_help4 cp850 "Deberias oir el altavoz interno del PC (no los externos).", 0 + lb_notes cp850 "DO RE MI FA SOL LA SI DO", 0 - WN_HELP RECT 64, 64, 521, 106 + WN_HELP RECT 14, 13, 521, 106 RT_NOTES RECT 16, 183, 0, 0 else @@ -324,55 +342,59 @@ else lb_help4 db "You should hear the built-in PC speaker (not external speakers).", 0 lb_notes db "C D E F G A B C", 0 - WN_HELP RECT 64, 64, 561, 106 + WN_HELP RECT 14, 13, 561, 106 RT_NOTES RECT 20, 183, 0, 0 end if ; ======================================================================= -DT_SIZE = 8 ; white buttons entry size -BL_SIZE = 2 ; black buttons entry size +WT_SIZE = 8 ; white buttons entry size +BL_SIZE = 2 ; black buttons entry size -; button id and color -white_top_buttons: - dd 0x31, 0xFF7A74 - dd 0x33, 0x907040 - dd 0x35, 0xA08050 - dd 0x36, 0xB09060 - dd 0x38, 0xC0A070 - dd 0x3A, 0xD0B080 - dd 0x3C, 0xE0C090 - dd 0x41, 0xFFA97C - dd 0x43, 0xAF8D8D - dd 0x45, 0xBF9D9D - dd 0x46, 0xCFADAD - dd 0x48, 0xDFBDBD - dd 0x4A, 0xEFCDCD - dd 0x4C, 0xFFDDDD - dd 0x51, 0xFFE558 -white_top_buttons_end: +; white button colors +white_button_colors: ; 1 top, 1 bottom, 2 top, 2 bottom, N top, N bottom + dd 0xFF7A74, 0x702050 + dd 0x907040, 0x683638 + dd 0xA08050, 0x784648 + dd 0xB09060, 0x885658 + dd 0xC0A070, 0x986668 + dd 0xD0B080, 0xA87678 + dd 0xE0C090, 0xB88688 -; button id and color -white_bottom_buttons: - dd 0x11, 0x702050 - dd 0x13, 0x683638 - dd 0x15, 0x784648 - dd 0x16, 0x885658 - dd 0x18, 0x986668 - dd 0x1A, 0xA87678 - dd 0x1C, 0xB88688 - dd 0x21, 0x880040 - dd 0x23, 0x90622B - dd 0x25, 0xA0723B - dd 0x26, 0xB0824B - dd 0x28, 0xC0925B - dd 0x2A, 0xD0A26B - dd 0x2C, 0xE0B27B - dd 0x31, 0xFF7A74 -white_bottom_buttons_end: + dd 0xFFA97C, 0x880040 + dd 0xAF8D8D, 0x90622B + dd 0xBF9D9D, 0xA0723B + dd 0xCFADAD, 0xB0824B + dd 0xDFBDBD, 0xC0925B + dd 0xEFCDCD, 0xD0A26B + dd 0xFFDDDD, 0xE0B27B -; parent white button id and button id + dd 0xFFE558, 0xFF7A74 +end_white_button_colors: + +; white button ids +white_button_ids: ; 1 top, 1 bottom, 2 top, 2 bottom, N top, N bottom + db 0x31, 0x11 + db 0x33, 0x13 + db 0x35, 0x15 + db 0x36, 0x16 + db 0x38, 0x18 + db 0x3A, 0x1A + db 0x3C, 0x1C + + db 0x41, 0x21 + db 0x43, 0x23 + db 0x45, 0x25 + db 0x46, 0x26 + db 0x48, 0x28 + db 0x4A, 0x2A + db 0x4C, 0x2C + + db 0x51, 0x31 ; ? +end_white_button_ids: + +; parent white button index in row and black button ids black_buttons: db 0x00, 0x12 db 0x01, 0x14 @@ -386,7 +408,7 @@ black_buttons: db 0x0C, 0x2B black_buttons_end: -; corrensponding help string label +; help string labels help_texts: dd lb_help1 dd lb_help2 @@ -396,67 +418,74 @@ help_texts_end: ; ======================================================================= -KM_SIZE = 2 ; key map entry size +BAD_NOTE = 0xFF ; key scancode and note id key_note_map: - db 0x02, 0x31 ; '1' -> note 0x31 - db 0x03, 0x32 ; '2' -> note 0x32 - db 0x04, 0x33 ; '3' -> note 0x33 - db 0x05, 0x34 ; '4' -> note 0x34 - db 0x06, 0x35 ; '5' -> note 0x35 - db 0x07, 0x36 ; '6' -> note 0x36 - db 0x08, 0x37 ; '7' -> note 0x37 - db 0x09, 0x38 ; '8' -> note 0x38 - db 0x0A, 0x39 ; '9' -> note 0x39 - db 0x0B, 0x3A ; '0' -> note 0x3A - db 0x0C, 0x3B ; '-' -> note 0x3B - db 0x0D, 0x3C ; '=' -> note 0x3C + db BAD_NOTE ;db 0x00, 0xFF + db BAD_NOTE ;db 0x01, 0xFF + db 0x21 ;db 0x02, 0x31 ; '1' -> note 0x31 + db 0x22 ;db 0x03, 0x32 ; '2' -> note 0x32 + db 0x23 ;db 0x04, 0x33 ; '3' -> note 0x33 + db 0x24 ;db 0x05, 0x34 ; '4' -> note 0x34 + db 0x25 ;db 0x06, 0x35 ; '5' -> note 0x35 + db 0x26 ;db 0x07, 0x36 ; '6' -> note 0x36 + db 0x27 ;db 0x08, 0x37 ; '7' -> note 0x37 + db 0x28 ;db 0x09, 0x38 ; '8' -> note 0x38 + db 0x29 ;db 0x0A, 0x39 ; '9' -> note 0x39 + db 0x2A ;db 0x0B, 0x3A ; '0' -> note 0x3A + db 0x2B ;db 0x0C, 0x3B ; '-' -> note 0x3B + db 0x2C ;db 0x0D, 0x3C ; '=' -> note 0x3C + db 0x1C ;db 0x0E, 0x2C ; Backspace -> note 0x2C + db BAD_NOTE ;db 0x0F, 0xFF - db 0x10, 0x41 ; 'q' -> note 0x41 - db 0x11, 0x42 ; 'w' -> note 0x42 - db 0x12, 0x43 ; 'e' -> note 0x43 - db 0x13, 0x44 ; 'r' -> note 0x44 - db 0x14, 0x45 ; 't' -> note 0x45 - db 0x15, 0x46 ; 'y' -> note 0x46 - db 0x16, 0x47 ; 'u' -> note 0x47 - db 0x17, 0x48 ; 'i' -> note 0x48 - db 0x18, 0x49 ; 'o' -> note 0x49 - db 0x19, 0x4A ; 'p' -> note 0x4A - db 0x1A, 0x4B ; '[' -> note 0x4B - db 0x1B, 0x4C ; ']' -> note 0x4C + db 0x31 ;db 0x10, 0x41 ; 'q' -> note 0x41 + db 0x32 ;db 0x11, 0x42 ; 'w' -> note 0x42 + db 0x33 ;db 0x12, 0x43 ; 'e' -> note 0x43 + db 0x34 ;db 0x13, 0x44 ; 'r' -> note 0x44 + db 0x35 ;db 0x14, 0x45 ; 't' -> note 0x45 + db 0x36 ;db 0x15, 0x46 ; 'y' -> note 0x46 + db 0x37 ;db 0x16, 0x47 ; 'u' -> note 0x47 + db 0x38 ;db 0x17, 0x48 ; 'i' -> note 0x48 + db 0x39 ;db 0x18, 0x49 ; 'o' -> note 0x49 + db 0x3A ;db 0x19, 0x4A ; 'p' -> note 0x4A + db 0x3B ;db 0x1A, 0x4B ; '[' -> note 0x4B + db 0x3C ;db 0x1B, 0x4C ; ']' -> note 0x4C + db 0x0C ;db 0x1C, 0x1C ; Enter -> note 0x1C + db BAD_NOTE ;db 0x1D, 0xFF - db 0x1E, 0x11 ; 'a' -> note 0x11 - db 0x1F, 0x12 ; 's' -> note 0x12 - db 0x20, 0x13 ; 'd' -> note 0x13 - db 0x21, 0x14 ; 'f' -> note 0x14 - db 0x22, 0x15 ; 'g' -> note 0x15 - db 0x23, 0x16 ; 'h' -> note 0x16 - db 0x24, 0x17 ; 'j' -> note 0x17 - db 0x25, 0x18 ; 'k' -> note 0x18 - db 0x26, 0x19 ; 'l' -> note 0x19 - db 0x27, 0x1A ; ';' -> note 0x1A - db 0x28, 0x1B ; ''' -> note 0x1B - db 0x1C, 0x1C ; Enter -> note 0x1C + db 0x01 ;db 0x1E, 0x11 ; 'a' -> note 0x11 + db 0x02 ;db 0x1F, 0x12 ; 's' -> note 0x12 + db 0x03 ;db 0x20, 0x13 ; 'd' -> note 0x13 + db 0x04 ;db 0x21, 0x14 ; 'f' -> note 0x14 + db 0x05 ;db 0x22, 0x15 ; 'g' -> note 0x15 + db 0x06 ;db 0x23, 0x16 ; 'h' -> note 0x16 + db 0x07 ;db 0x24, 0x17 ; 'j' -> note 0x17 + db 0x08 ;db 0x25, 0x18 ; 'k' -> note 0x18 + db 0x09 ;db 0x26, 0x19 ; 'l' -> note 0x19 + db 0x0A ;db 0x27, 0x1A ; ';' -> note 0x1A + db 0x0B ;db 0x28, 0x1B ; ''' -> note 0x1B + db BAD_NOTE ;db 0x29, 0xFF + db BAD_NOTE ;db 0x2A, 0xFF - db 0x2C, 0x21 ; 'z' -> note 0x21 - db 0x2D, 0x22 ; 'x' -> note 0x22 - db 0x2E, 0x23 ; 'c' -> note 0x23 - db 0x2F, 0x24 ; 'v' -> note 0x24 - db 0x30, 0x25 ; 'b' -> note 0x25 - db 0x31, 0x26 ; 'n' -> note 0x26 - db 0x32, 0x27 ; 'm' -> note 0x27 - db 0x33, 0x28 ; ',' -> note 0x28 - db 0x34, 0x29 ; '.' -> note 0x29 - db 0x35, 0x2A ; '/' -> note 0x2A - db 0x2B, 0x2B ; '\' -> note 0x2B - db 0x0E, 0x2C ; Backspace -> note 0x2C -key_note_map_end: + db 0x1B ;db 0x2B, 0x2B ; '\' -> note 0x2B + db 0x11 ;db 0x2C, 0x21 ; 'z' -> note 0x21 + db 0x12 ;db 0x2D, 0x22 ; 'x' -> note 0x22 + db 0x13 ;db 0x2E, 0x23 ; 'c' -> note 0x23 + db 0x14 ;db 0x2F, 0x24 ; 'v' -> note 0x24 + db 0x15 ;db 0x30, 0x25 ; 'b' -> note 0x25 + db 0x16 ;db 0x31, 0x26 ; 'n' -> note 0x26 + db 0x17 ;db 0x32, 0x27 ; 'm' -> note 0x27 + db 0x18 ;db 0x33, 0x28 ; ',' -> note 0x28 + db 0x19 ;db 0x34, 0x29 ; '.' -> note 0x29 + db 0x1A ;db 0x35, 0x2A ; '/' -> note 0x2A +.count = $ - key_note_map ; ======================================================================= melody db 0x90, 0x30, 0 -hp_tid dd 0 +mw_pos dd 0 +hw_tid dd 0 ; ======================================================================= -- 2.49.1 From cb27e64b63f081ba3e4579ba3aa1799a3665cba5 Mon Sep 17 00:00:00 2001 From: Burer Date: Wed, 28 Jan 2026 17:36:32 +0200 Subject: [PATCH 3/7] apps/piano: add keymap configuration via separate binary file --- data/Tupfile.lua | 1 + programs/media/piano/Tupfile.lua | 1 + programs/media/piano/keymap.asm | 79 ++++++++++++ programs/media/piano/piano.asm | 201 ++++++++++++++++++++----------- 4 files changed, 211 insertions(+), 71 deletions(-) create mode 100644 programs/media/piano/keymap.asm diff --git a/data/Tupfile.lua b/data/Tupfile.lua index b5dce6c1c..60ba6b2ae 100644 --- a/data/Tupfile.lua +++ b/data/Tupfile.lua @@ -532,6 +532,7 @@ tup.append_table(img_files, { {"MEDIA/MP3INFO", VAR_PROGS .. "/media/mp3info/mp3info"}, {"MEDIA/PALITRA", VAR_PROGS .. "/media/palitra/trunk/palitra"}, {"MEDIA/PIANO", VAR_PROGS .. "/media/piano/piano"}, + {"MEDIA/PIANO.MAP", VAR_PROGS .. "/media/piano/piano.map"}, {"MEDIA/STARTMUS", VAR_PROGS .. "/media/startmus/trunk/STARTMUS"}, {"NETWORK/PING", VAR_PROGS .. "/network/ping/ping"}, {"NETWORK/NETCFG", VAR_PROGS .. "/network/netcfg/netcfg"}, diff --git a/programs/media/piano/Tupfile.lua b/programs/media/piano/Tupfile.lua index bd6da2fad..8d144d4c4 100644 --- a/programs/media/piano/Tupfile.lua +++ b/programs/media/piano/Tupfile.lua @@ -1,4 +1,5 @@ if tup.getconfig("NO_FASM") ~= "" then return end HELPERDIR = (tup.getconfig("HELPERDIR") == "") and "../.." or tup.getconfig("HELPERDIR") tup.include(HELPERDIR .. "/use_fasm.lua") +tup.rule("keymap.asm", FASM .. " %f %o", "piano.map") tup.rule("piano.asm", FASM .. " -dlang=" .. tup.getconfig("LANG") .. " %f %o" .. tup.getconfig("KPACK_CMD"), "%B") diff --git a/programs/media/piano/keymap.asm b/programs/media/piano/keymap.asm new file mode 100644 index 000000000..bf99e9f83 --- /dev/null +++ b/programs/media/piano/keymap.asm @@ -0,0 +1,79 @@ +; SPDX-License-Identifier: GPL-2.0-only +; +; Piano - Default Keymap (256 bytes) +; Copyright (C) 2025 KolibriOS team +; +; Contributor Burer - Main code +; Contributor Doczom - Idea + +; ==================================================================== + +format binary as "" +org 0 + +; ==================================================================== + +BAD_NOTE = 0xFF + +; ==================================================================== + +keymap: + db BAD_NOTE ; 0x00 + db BAD_NOTE ; 0x01 + db 0x21 ; 0x02 '1' -> note 0x31 + db 0x22 ; 0x03 '2' -> note 0x32 + db 0x23 ; 0x04 '3' -> note 0x33 + db 0x24 ; 0x05 '4' -> note 0x34 + db 0x25 ; 0x06 '5' -> note 0x35 + db 0x26 ; 0x07 '6' -> note 0x36 + db 0x27 ; 0x08 '7' -> note 0x37 + db 0x28 ; 0x09 '8' -> note 0x38 + db 0x29 ; 0x0A '9' -> note 0x39 + db 0x2A ; 0x0B '0' -> note 0x3A + db 0x2B ; 0x0C '-' -> note 0x3B + db 0x2C ; 0x0D '=' -> note 0x3C + db 0x1C ; 0x0E Backspace -> note 0x2C + db BAD_NOTE ; 0x0F + + db 0x31 ; 0x10 'q' -> note 0x41 + db 0x32 ; 0x11 'w' -> note 0x42 + db 0x33 ; 0x12 'e' -> note 0x43 + db 0x34 ; 0x13 'r' -> note 0x44 + db 0x35 ; 0x14 't' -> note 0x45 + db 0x36 ; 0x15 'y' -> note 0x46 + db 0x37 ; 0x16 'u' -> note 0x47 + db 0x38 ; 0x17 'i' -> note 0x48 + db 0x39 ; 0x18 'o' -> note 0x49 + db 0x3A ; 0x19 'p' -> note 0x4A + db 0x3B ; 0x1A '[' -> note 0x4B + db 0x3C ; 0x1B ']' -> note 0x4C + db 0x0C ; 0x1C Enter -> note 0x1C + db BAD_NOTE ; 0x1D + + db 0x01 ; 0x1E 'a' -> note 0x11 + db 0x02 ; 0x1F 's' -> note 0x12 + db 0x03 ; 0x20 'd' -> note 0x13 + db 0x04 ; 0x21 'f' -> note 0x14 + db 0x05 ; 0x22 'g' -> note 0x15 + db 0x06 ; 0x23 'h' -> note 0x16 + db 0x07 ; 0x24 'j' -> note 0x17 + db 0x08 ; 0x25 'k' -> note 0x18 + db 0x09 ; 0x26 'l' -> note 0x19 + db 0x0A ; 0x27 ';' -> note 0x1A + db 0x0B ; 0x28 ''' -> note 0x1B + db BAD_NOTE ; 0x29 + db BAD_NOTE ; 0x2A + + db 0x1B ; 0x2B '\' -> note 0x2B + db 0x11 ; 0x2C 'z' -> note 0x21 + db 0x12 ; 0x2D 'x' -> note 0x22 + db 0x13 ; 0x2E 'c' -> note 0x23 + db 0x14 ; 0x2F 'v' -> note 0x24 + db 0x15 ; 0x30 'b' -> note 0x25 + db 0x16 ; 0x31 'n' -> note 0x26 + db 0x17 ; 0x32 'm' -> note 0x27 + db 0x18 ; 0x33 ',' -> note 0x28 + db 0x19 ; 0x34 '.' -> note 0x29 + db 0x1A ; 0x35 '/' -> note 0x2A + + times 256-($-keymap) db BAD_NOTE diff --git a/programs/media/piano/piano.asm b/programs/media/piano/piano.asm index 6871ea9cc..1abd50fa0 100644 --- a/programs/media/piano/piano.asm +++ b/programs/media/piano/piano.asm @@ -35,6 +35,7 @@ include "../../encoding.inc" START: mcall SF_KEYBOARD, SSF_SET_INPUT_MODE, 1 + call load_keymap jmp redraw ; ==================================================================== @@ -64,8 +65,7 @@ key: cmp ah, KEY_ESC je .help - ; check if Shift is pressed - ; increase note_id by 0x40 + ; if Shift is pressed - increase note_id by 0x40 movzx ecx, ah mcall SF_KEYBOARD, SSF_GET_CONTROL_KEYS xor edx, edx @@ -77,10 +77,7 @@ key: ; play note if valid key pressed .key_map_play: - cmp cl, key_note_map.count - jae still - - mov ah, [key_note_map + ecx] + mov ah, [keymap + ecx] cmp ah, BAD_NOTE je still @@ -119,8 +116,7 @@ button: sub ah, 0x10 mov dl, ah - ; check if Shift is pressed - ; increase note_id by 0x40 + ; if Shift is pressed - increase note_id by 0x40 mcall SF_KEYBOARD, SSF_GET_CONTROL_KEYS test al, KEY_SHIFT jz .no_shift @@ -143,6 +139,29 @@ play: ; ======================================================================= +load_keymap: + call load_default_keymap + + mcall SF_FILE, keymap_file + test eax, eax + jnz .notify + cmp ebx, 256 + je .done + .notify: + call load_default_keymap + mcall SF_FILE, notify_info + .done: + ret + +load_default_keymap: + mov esi, default_keymap + mov edi, keymap + mov ecx, 256 + rep movsb + ret + +; ======================================================================= + redraw: mcall SF_REDRAW, SSF_BEGIN_DRAW mcall SF_STYLE_SETTINGS, SSF_GET_COLORS, sc, sizeof.system_colors @@ -310,39 +329,57 @@ if lang eq ru_RU cp_main cp866 "Детское Пианино [Escape - Открыть Справку]", 0 cp_help cp866 "Детское Пианино - Справка", 0 + lb_help1 cp866 "Клавиши от 1 до = и от Q до ] - верхний ряд.", 0 lb_help2 cp866 "Клавиши от A до Enter и от Z до /, \ и Backspace - нижний ряд.", 0 lb_help3 cp866 "Удерживайте Shift для повышения октавы на 4.", 0 - lb_help4 cp866 "Должен звучать встроенный динамик ПК (не колонки).", 0 + lb_help4 cp866 "Раскладку клавиатуры можно изменить через файл piano.map.", 0 + lb_help5 cp866 "Он должен содержать 256 байт, каждый индекс - скан-код, а значение - нота.", 0 + lb_help6 cp866 "Должен звучать встроенный динамик ПК (не колонки).", 0 + lb_notes cp866 "ДО РЕ МИ ФА СОЛЬ ЛЯ СИ ДО", 0 - WN_HELP RECT 14, 13, 521, 106 + nf_map cp866 "'Детское Пианино\npiano.map отсутствует или повреждён, используется раскладка по умолчанию' -tW", 0 + + WN_HELP RECT 14, 13, 617, 178 RT_NOTES RECT 16, 183, 0, 0 else if lang eq es_ES cp_main cp850 "Piano de Juguete [Escape - Abrir Ayuda]", 0 cp_help cp850 "Piano de Juguete - Ayuda", 0 + lb_help1 cp850 "Teclas de 1 a = y de Q a ] - fila superior.", 0 lb_help2 cp850 "Teclas de A a Enter y de Z a /, \ y Backspace - fila inferior.", 0 lb_help3 cp850 "Mantenga Shift para subir 4 octavas.", 0 - lb_help4 cp850 "Deberias oir el altavoz interno del PC (no los externos).", 0 + lb_help4 cp850 "La distribución del teclado se puede cambiar mediante el archivo piano.map.", 0 + lb_help5 cp850 "Debe contener 256 bytes: cada índice es un código de escaneo y el valor es una nota.", 0 + lb_help6 cp850 "Deberias oir el altavoz interno del PC (no los externos).", 0 + lb_notes cp850 "DO RE MI FA SOL LA SI DO", 0 - WN_HELP RECT 14, 13, 521, 106 + nf_map cp850 "'Piano de Juguete\nFalta piano.map o es inválido; se usa el mapa de teclas predeterminado' -tW", 0 + + WN_HELP RECT 14, 13, 697, 178 RT_NOTES RECT 16, 183, 0, 0 else cp_main db "Toy Piano [Escape - Open Help]", 0 cp_help db "Toy Piano - Help", 0 + lb_help1 db "Keys from 1 to = and from Q to ] - top row.", 0 lb_help2 db "Keys from A to Enter and from Z to /, \ and Backspace - bottom row.", 0 lb_help3 db "Hold Shift to raise the octave by 4.", 0 - lb_help4 db "You should hear the built-in PC speaker (not external speakers).", 0 + lb_help4 db "Keyboard layout can be changed via the piano.map file.", 0 + lb_help5 db "It must contain 256 bytes - each index is scancode, and value is note.", 0 + lb_help6 db "You should hear the built-in PC speaker (not external speakers).", 0 + lb_notes db "C D E F G A B C", 0 - WN_HELP RECT 14, 13, 561, 106 + nf_map db "'Toy Piano\npiano.map is missing or invalid, using default keymap' -tW", 0 + + WN_HELP RECT 14, 13, 585, 178 RT_NOTES RECT 20, 183, 0, 0 end if @@ -414,81 +451,103 @@ help_texts: dd lb_help2 dd lb_help3 dd lb_help4 + dd lb_help5 + dd lb_help6 help_texts_end: ; ======================================================================= BAD_NOTE = 0xFF -; key scancode and note id -key_note_map: - db BAD_NOTE ;db 0x00, 0xFF - db BAD_NOTE ;db 0x01, 0xFF - db 0x21 ;db 0x02, 0x31 ; '1' -> note 0x31 - db 0x22 ;db 0x03, 0x32 ; '2' -> note 0x32 - db 0x23 ;db 0x04, 0x33 ; '3' -> note 0x33 - db 0x24 ;db 0x05, 0x34 ; '4' -> note 0x34 - db 0x25 ;db 0x06, 0x35 ; '5' -> note 0x35 - db 0x26 ;db 0x07, 0x36 ; '6' -> note 0x36 - db 0x27 ;db 0x08, 0x37 ; '7' -> note 0x37 - db 0x28 ;db 0x09, 0x38 ; '8' -> note 0x38 - db 0x29 ;db 0x0A, 0x39 ; '9' -> note 0x39 - db 0x2A ;db 0x0B, 0x3A ; '0' -> note 0x3A - db 0x2B ;db 0x0C, 0x3B ; '-' -> note 0x3B - db 0x2C ;db 0x0D, 0x3C ; '=' -> note 0x3C - db 0x1C ;db 0x0E, 0x2C ; Backspace -> note 0x2C - db BAD_NOTE ;db 0x0F, 0xFF +default_keymap: + db BAD_NOTE ; 0x00 + db BAD_NOTE ; 0x01 + db 0x21 ; 0x02 '1' -> note 0x31 + db 0x22 ; 0x03 '2' -> note 0x32 + db 0x23 ; 0x04 '3' -> note 0x33 + db 0x24 ; 0x05 '4' -> note 0x34 + db 0x25 ; 0x06 '5' -> note 0x35 + db 0x26 ; 0x07 '6' -> note 0x36 + db 0x27 ; 0x08 '7' -> note 0x37 + db 0x28 ; 0x09 '8' -> note 0x38 + db 0x29 ; 0x0A '9' -> note 0x39 + db 0x2A ; 0x0B '0' -> note 0x3A + db 0x2B ; 0x0C '-' -> note 0x3B + db 0x2C ; 0x0D '=' -> note 0x3C + db 0x1C ; 0x0E Backspace -> note 0x2C + db BAD_NOTE ; 0x0F - db 0x31 ;db 0x10, 0x41 ; 'q' -> note 0x41 - db 0x32 ;db 0x11, 0x42 ; 'w' -> note 0x42 - db 0x33 ;db 0x12, 0x43 ; 'e' -> note 0x43 - db 0x34 ;db 0x13, 0x44 ; 'r' -> note 0x44 - db 0x35 ;db 0x14, 0x45 ; 't' -> note 0x45 - db 0x36 ;db 0x15, 0x46 ; 'y' -> note 0x46 - db 0x37 ;db 0x16, 0x47 ; 'u' -> note 0x47 - db 0x38 ;db 0x17, 0x48 ; 'i' -> note 0x48 - db 0x39 ;db 0x18, 0x49 ; 'o' -> note 0x49 - db 0x3A ;db 0x19, 0x4A ; 'p' -> note 0x4A - db 0x3B ;db 0x1A, 0x4B ; '[' -> note 0x4B - db 0x3C ;db 0x1B, 0x4C ; ']' -> note 0x4C - db 0x0C ;db 0x1C, 0x1C ; Enter -> note 0x1C - db BAD_NOTE ;db 0x1D, 0xFF + db 0x31 ; 0x10 'q' -> note 0x41 + db 0x32 ; 0x11 'w' -> note 0x42 + db 0x33 ; 0x12 'e' -> note 0x43 + db 0x34 ; 0x13 'r' -> note 0x44 + db 0x35 ; 0x14 't' -> note 0x45 + db 0x36 ; 0x15 'y' -> note 0x46 + db 0x37 ; 0x16 'u' -> note 0x47 + db 0x38 ; 0x17 'i' -> note 0x48 + db 0x39 ; 0x18 'o' -> note 0x49 + db 0x3A ; 0x19 'p' -> note 0x4A + db 0x3B ; 0x1A '[' -> note 0x4B + db 0x3C ; 0x1B ']' -> note 0x4C + db 0x0C ; 0x1C Enter -> note 0x1C + db BAD_NOTE ; 0x1D - db 0x01 ;db 0x1E, 0x11 ; 'a' -> note 0x11 - db 0x02 ;db 0x1F, 0x12 ; 's' -> note 0x12 - db 0x03 ;db 0x20, 0x13 ; 'd' -> note 0x13 - db 0x04 ;db 0x21, 0x14 ; 'f' -> note 0x14 - db 0x05 ;db 0x22, 0x15 ; 'g' -> note 0x15 - db 0x06 ;db 0x23, 0x16 ; 'h' -> note 0x16 - db 0x07 ;db 0x24, 0x17 ; 'j' -> note 0x17 - db 0x08 ;db 0x25, 0x18 ; 'k' -> note 0x18 - db 0x09 ;db 0x26, 0x19 ; 'l' -> note 0x19 - db 0x0A ;db 0x27, 0x1A ; ';' -> note 0x1A - db 0x0B ;db 0x28, 0x1B ; ''' -> note 0x1B - db BAD_NOTE ;db 0x29, 0xFF - db BAD_NOTE ;db 0x2A, 0xFF + db 0x01 ; 0x1E 'a' -> note 0x11 + db 0x02 ; 0x1F 's' -> note 0x12 + db 0x03 ; 0x20 'd' -> note 0x13 + db 0x04 ; 0x21 'f' -> note 0x14 + db 0x05 ; 0x22 'g' -> note 0x15 + db 0x06 ; 0x23 'h' -> note 0x16 + db 0x07 ; 0x24 'j' -> note 0x17 + db 0x08 ; 0x25 'k' -> note 0x18 + db 0x09 ; 0x26 'l' -> note 0x19 + db 0x0A ; 0x27 ';' -> note 0x1A + db 0x0B ; 0x28 ''' -> note 0x1B + db BAD_NOTE ; 0x29 + db BAD_NOTE ; 0x2A - db 0x1B ;db 0x2B, 0x2B ; '\' -> note 0x2B - db 0x11 ;db 0x2C, 0x21 ; 'z' -> note 0x21 - db 0x12 ;db 0x2D, 0x22 ; 'x' -> note 0x22 - db 0x13 ;db 0x2E, 0x23 ; 'c' -> note 0x23 - db 0x14 ;db 0x2F, 0x24 ; 'v' -> note 0x24 - db 0x15 ;db 0x30, 0x25 ; 'b' -> note 0x25 - db 0x16 ;db 0x31, 0x26 ; 'n' -> note 0x26 - db 0x17 ;db 0x32, 0x27 ; 'm' -> note 0x27 - db 0x18 ;db 0x33, 0x28 ; ',' -> note 0x28 - db 0x19 ;db 0x34, 0x29 ; '.' -> note 0x29 - db 0x1A ;db 0x35, 0x2A ; '/' -> note 0x2A -.count = $ - key_note_map + db 0x1B ; 0x2B '\' -> note 0x2B + db 0x11 ; 0x2C 'z' -> note 0x21 + db 0x12 ; 0x2D 'x' -> note 0x22 + db 0x13 ; 0x2E 'c' -> note 0x23 + db 0x14 ; 0x2F 'v' -> note 0x24 + db 0x15 ; 0x30 'b' -> note 0x25 + db 0x16 ; 0x31 'n' -> note 0x26 + db 0x17 ; 0x32 'm' -> note 0x27 + db 0x18 ; 0x33 ',' -> note 0x28 + db 0x19 ; 0x34 '.' -> note 0x29 + db 0x1A ; 0x35 '/' -> note 0x2A + + times 256-($-default_keymap) db BAD_NOTE + +keymap_file: + dd SSF_READ_FILE + dd 0 + dd 0 + dd 256 + dd keymap + db 'piano.map', 0 ; ======================================================================= melody db 0x90, 0x30, 0 +keymap rb 256 + mw_pos dd 0 hw_tid dd 0 ; ======================================================================= +notify_info: + dd SSF_START_APP + dd 0 + dd nf_map + dd 0 + dd 0 + db '/sys/@notify', 0 + +; ======================================================================= + I_END: help_stack: rb 512 -- 2.49.1 From 38b47500cee85fbd0d5f9cff42b70431968aac8f Mon Sep 17 00:00:00 2001 From: Burer Date: Sun, 1 Mar 2026 09:27:37 +0200 Subject: [PATCH 4/7] apps/piano: tweak copyright header Co-authored-by: Doczom Co-authored-by: qullarwee --- .asm-lsp.toml | 3 +++ programs/media/piano/keymap.asm | 3 --- programs/media/piano/piano.asm | 6 +----- 3 files changed, 4 insertions(+), 8 deletions(-) create mode 100644 .asm-lsp.toml diff --git a/.asm-lsp.toml b/.asm-lsp.toml new file mode 100644 index 000000000..1dfab1cb4 --- /dev/null +++ b/.asm-lsp.toml @@ -0,0 +1,3 @@ +[default_config] +assembler = "fasm" +instruction_set = "x86" diff --git a/programs/media/piano/keymap.asm b/programs/media/piano/keymap.asm index bf99e9f83..34e426cdd 100644 --- a/programs/media/piano/keymap.asm +++ b/programs/media/piano/keymap.asm @@ -2,9 +2,6 @@ ; ; Piano - Default Keymap (256 bytes) ; Copyright (C) 2025 KolibriOS team -; -; Contributor Burer - Main code -; Contributor Doczom - Idea ; ==================================================================== diff --git a/programs/media/piano/piano.asm b/programs/media/piano/piano.asm index 1abd50fa0..35afd6acc 100644 --- a/programs/media/piano/piano.asm +++ b/programs/media/piano/piano.asm @@ -3,11 +3,7 @@ ; Piano - Toy Piano ; Copyright (C) 2019-2025 KolibriOS team ; -; Contributor ??? - Initial code -; Contributor Antonio - Refactoring and new functionality -; Contributor Burer - Refactoring and Spanish translation -; Contributor Doczom - Refactoring and bugfixes -; Contributor qullarwee - New keyboard layout +; Authors: Antonio and Leency ; ==================================================================== -- 2.49.1 From bdd6c71734afc260ac581e1d21f8475019693398 Mon Sep 17 00:00:00 2001 From: Burer Date: Sun, 1 Mar 2026 09:31:39 +0200 Subject: [PATCH 5/7] apps/piano: cleanup to previous --- .asm-lsp.toml | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 .asm-lsp.toml diff --git a/.asm-lsp.toml b/.asm-lsp.toml deleted file mode 100644 index 1dfab1cb4..000000000 --- a/.asm-lsp.toml +++ /dev/null @@ -1,3 +0,0 @@ -[default_config] -assembler = "fasm" -instruction_set = "x86" -- 2.49.1 From d603bbe3d98faf0c3e66f53a8c6d02252a9a2572 Mon Sep 17 00:00:00 2001 From: Burer Date: Sat, 7 Mar 2026 11:04:40 +0200 Subject: [PATCH 6/7] apps/piano: fix CWD path, refactor code --- programs/media/piano/piano.asm | 86 +++++++++++++++++++++------------- 1 file changed, 54 insertions(+), 32 deletions(-) diff --git a/programs/media/piano/piano.asm b/programs/media/piano/piano.asm index 35afd6acc..4003ff9c9 100644 --- a/programs/media/piano/piano.asm +++ b/programs/media/piano/piano.asm @@ -19,7 +19,7 @@ dd I_END dd MEM dd STACKTOP dd 0 -dd 0 +dd app_path_buf ; ==================================================================== @@ -31,6 +31,7 @@ include "../../encoding.inc" START: mcall SF_KEYBOARD, SSF_SET_INPUT_MODE, 1 + call build_keymap_path call load_keymap jmp redraw @@ -135,27 +136,44 @@ play: ; ======================================================================= -load_keymap: - call load_default_keymap +build_keymap_path: + ; build path: app_dir + 'piano.map' + lea esi, [app_path_buf + 2] + lea edi, [app_path_buf] + .copy: + lodsb + stosb + test al, al + jnz .copy + ; edi is one past '\0'; scan backward to the last '/' + .find_slash: + dec edi + cmp byte [edi], '/' + jne .find_slash + inc edi - mcall SF_FILE, keymap_file + ; add 'piano.map' to the path + mov eax, 'pian' + stosd + mov eax, 'o.ma' + stosd + mov eax, 'p' + stosd + ret + +; ======================================================================= + +load_keymap: + mcall SF_FILE, keymap_info test eax, eax jnz .notify cmp ebx, 256 je .done .notify: - call load_default_keymap mcall SF_FILE, notify_info .done: ret -load_default_keymap: - mov esi, default_keymap - mov edi, keymap - mov ecx, 256 - rep movsb - ret - ; ======================================================================= redraw: @@ -290,10 +308,10 @@ help_thread: ; draw all help text in rows .help_text_loop: - cmp edi, help_texts_end - jae .help_text_loop_done - mov edx, [edi] + test edx, edx + jz .help_text_loop_done + mcall ; draw text add ebx, RT_HELP.H @@ -308,6 +326,9 @@ help_thread: sc system_colors +mw_pos dd 0 +hw_tid dd 0 + WN_MAIN RECT 32, 32, BT_WHITE.W * 15 + 10, BT_WHITE.H * 2 + (5 + 4) BT_WHITE RECT 0, 4, 48, 100 @@ -449,13 +470,15 @@ help_texts: dd lb_help4 dd lb_help5 dd lb_help6 -help_texts_end: + dd 0 ; ======================================================================= BAD_NOTE = 0xFF -default_keymap: +melody db 0x90, 0x30, 0 + +keymap: db BAD_NOTE ; 0x00 db BAD_NOTE ; 0x01 db 0x21 ; 0x02 '1' -> note 0x31 @@ -514,23 +537,9 @@ default_keymap: db 0x19 ; 0x34 '.' -> note 0x29 db 0x1A ; 0x35 '/' -> note 0x2A - times 256-($-default_keymap) db BAD_NOTE + times 256-($-keymap) db BAD_NOTE -keymap_file: - dd SSF_READ_FILE - dd 0 - dd 0 - dd 256 - dd keymap - db 'piano.map', 0 -; ======================================================================= - -melody db 0x90, 0x30, 0 -keymap rb 256 - -mw_pos dd 0 -hw_tid dd 0 ; ======================================================================= @@ -544,11 +553,24 @@ notify_info: ; ======================================================================= +keymap_info: + dd SSF_READ_FILE + dd 0 + dd 0 + dd 256 + dd keymap + +; ======================================================================= + I_END: + +app_path rb 1024 ; = keymap_info + 20: acts as SF_FILE path field + help_stack: rb 512 help_stack_top: rb 1024 align 512 + STACKTOP: MEM: -- 2.49.1 From 2a5f73351bba11b07610e489f5242eecf94f5b57 Mon Sep 17 00:00:00 2001 From: Burer Date: Sat, 7 Mar 2026 11:08:26 +0200 Subject: [PATCH 7/7] apps/piano: fix to previous --- programs/media/piano/piano.asm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/programs/media/piano/piano.asm b/programs/media/piano/piano.asm index 4003ff9c9..32c8a3ed4 100644 --- a/programs/media/piano/piano.asm +++ b/programs/media/piano/piano.asm @@ -19,7 +19,7 @@ dd I_END dd MEM dd STACKTOP dd 0 -dd app_path_buf +dd app_path ; ==================================================================== @@ -138,8 +138,8 @@ play: build_keymap_path: ; build path: app_dir + 'piano.map' - lea esi, [app_path_buf + 2] - lea edi, [app_path_buf] + lea esi, [app_path + 2] + lea edi, [app_path] .copy: lodsb stosb -- 2.49.1