;KEYSCAN
;.rep_wait=$+1
; ld a,0
; dec a
; ret m
; ld (.rep_wait),a
; ret
;--------------------------------------------------
keyqueueput_codenolang
GETKEY
.KEY_MODE_NONE = 0x00
.KEY_MODE_SHIFT = 0x01
.KEY_MODE_ALT = 0x02
.KEY_MODE_CTRL = 0x04
.KEY_MODE_RUS = 0x08
.KEY_MODE_UP = 0x10
.KEY_MODE_E0 = 0x20
.KEY_MODE_CAPS = 0x40
.KEY_MODE_NUML = 0x80
.bKEY_MODE_SHIFT = 0x00
.bKEY_MODE_ALT = 0x01
.bKEY_MODE_CTRL = 0x02
.bKEY_MODE_RUS = 0x03
.bKEY_MODE_UP = 0x04
.bKEY_MODE_E0 = 0x05
.bKEY_MODE_CAPS = 0x06
.bKEY_MODE_NUML = 0x07
;out: ha=key (NOKEY=none), bc=keynolang keeps de,l
;H0=1 for control codes, H0=0 for symbols
;TODO где-то в H добавить биты регистра клавиатуры
ld hl,(KEY_PUTREDRAW.redrawkey)
ld a,l
or a
jr z,.noredraw
ld bc,0x0000
ld (KEY_PUTREDRAW.redrawkey),bc
ld c,a
ld b,h
ret
.noredraw
.mode=$+1
ld hl,0x0000
ld bc,0xdef7
out (c),c
ld b,0xbe
in a,(c)
jr nz,.not_zero
ld a,(KEYSCAN.rep_wait)
or a
jr nz,.zero_ret
ld bc,(KEY_PUTREDRAW.rep_key)
ld a,c
or a
jr z,.zero_ret
ld a,1;3
ld (KEYSCAN.rep_wait),a
ld a,b
jp nz,.retsymb1
.zero_ret
xor a
ld h,a
ld b,h
ld c,a
ret
.not_zero
ld de,0
ld (KEY_PUTREDRAW.rep_key),de
cp 0xff
jr nz,.decode
ld b,0xde ;переполнено
ld a,0x0c ;сбросить буфер
out (c),a
ld b,0xbe
ld a,1
out (c),a
xor a
ld (.mode),a
jr .zero_ret
.decode
bit .bKEY_MODE_UP,l
jp nz,.keypressmode
cp 0xe0
jr c,.iskeycode
jr z,.isE0
ld a,.KEY_MODE_UP
.savemode_or
or l
.savemode
ld (.mode),a
jr .noredraw
.isE0
ld a,.KEY_MODE_E0
jr .savemode_or
.iskeycode
add 0xff&.scodes
ld e,a
ld a,0
adc 0xff&(.scodes>>8)
ld d,a
ld a,(de)
or a
jr z,.zero_ret ;кнопка не поддерживается
;bit .bKEY_MODE_CTRL,l
;jr nz,.zero_ret ;Ctrl+F1 - это не F1
cp 64
jr nc,.not_simbol
ld b,a
bit .bKEY_MODE_CTRL,l
jr nz,.ctrl_mod
cp 27
ld a,.KEY_MODE_SHIFT
jr nc,.base_noneed_caps
bit .bKEY_MODE_ALT,l
jr z,.no_alt_mod
ld a,b
;jr .retsymb
add a,0xff&.alt_decode
ld e,a
adc a,0xff&(.alt_decode>>8)
jr .ctrl_mod_ok
;.no_alt_mod
;bit .bKEY_MODE_CTRL,l
;jr z,.no_ctrl_mod
.ctrl_mod
ld a,b
add a,0xff&.ctrl_decode
ld e,a
adc a,0xff&(.ctrl_decode>>8)
.ctrl_mod_ok
sub e
ld d,a
ld a,(de)
ld c,a
jr .retsymb
.no_alt_mod
.no_ctrl_mod
ld a,.KEY_MODE_SHIFT|.KEY_MODE_CAPS
.base_noneed_caps
and l
ld a,0
jp pe,.base_not_sh
ld a,.mod_sh-.mod_base
.base_not_sh
add a,b
add 0xff&.char_decode
ld e,a
ld a,0
adc 0xff&(.char_decode>>8)
ld d,a
ld a,(de)
ld c,a
bit .bKEY_MODE_E0,l
jr nz,.retsymb
bit .bKEY_MODE_RUS,l
jr nz,.rus_decode
.retsymb
ld b,a
ld (KEY_PUTREDRAW.rep_key),bc
ex af,af' ;'
ld a,35
ld (KEYSCAN.rep_wait),a
ex af,af' ;'
.retsymb1
ld b,0
ld h,b
res .bKEY_MODE_E0,l
ld (.mode),hl
ret
.rus_decode
ld a,b
cp 33
ld a,.KEY_MODE_SHIFT
jr nc,.rus_noneed_caps
ld a,.KEY_MODE_SHIFT|.KEY_MODE_CAPS
.rus_noneed_caps
and l
ld a,0
jp pe,.rus_not_sh
ld a,.mod_sh-.mod_base
.rus_not_sh
add a,b
add a,0xff&.char_decode_ru
ld e,a
ld a,0
adc a,0xff&(.char_decode_ru>>8)
ld d,a
ld a,(de)
jr .retsymb
.not_simbol
ld b,a
cp 128
jr c,.is_mode_key
cp 139
jr nc,.unmod_no_lock
bit .bKEY_MODE_E0,l
jr nz,.unmod_no_lock
bit .bKEY_MODE_NUML,l
jr nz,.unmod_no_lock
add .unmod_sh-.unmod
.unmod_no_lock
add a,0xff&.unmod_decode
ld e,a
ld a,0
adc a,0xff&(.unmod_decode>>8)
ld d,a
ld a,(de)
ld c,a
cp key_enter
jr z,.modify_enter
bit .bKEY_MODE_SHIFT,l
jp nz,.zero_ret ;Shift+F1 - это не F1
jr .retsymb
.modify_enter
bit .bKEY_MODE_SHIFT,l
jr z,.retsymb
ld a,0x7f
in a,(0xfe)
rra
ld c,a ;c0=ss
ld a,0xbf
in a,(0xfe)
or c
rra ;NC: ssEnter pressed
jp nc,.zero_ret
ld a,key_csenter
ld c,a
jr .retsymb
.is_mode_key
cp 64
jr nz,.not_shift_key
ld a,l
or .KEY_MODE_SHIFT
and ~.KEY_MODE_E0
bit .bKEY_MODE_ALT,a
jp z,.savemode
.chruslat
xor .KEY_MODE_RUS
jp .savemode
.not_shift_key
cp 66
jr nz,.not_alt_key
ld a,l
or .KEY_MODE_ALT
and ~.KEY_MODE_E0
bit .bKEY_MODE_SHIFT,a
jp z,.savemode
jr .chruslat
.not_alt_key
cp 68
jr nz,.not_ctrl_key
ld a,l
or .KEY_MODE_CTRL
and ~.KEY_MODE_E0
jp .savemode
.not_ctrl_key
ld a,l
and ~.KEY_MODE_E0
jp .savemode
.keypressmode
cp 0xe0
jp z,.noredraw
ld h,~(.KEY_MODE_UP|.KEY_MODE_E0|.KEY_MODE_SHIFT)
cp 0x12
jr z,.keypressend
cp 0x59
jr z,.keypressend
ld h,~(.KEY_MODE_UP|.KEY_MODE_E0|.KEY_MODE_ALT)
cp 0x11
jr z,.keypressend
ld h,~(.KEY_MODE_UP|.KEY_MODE_E0|.KEY_MODE_CTRL)
cp 0x14
jr z,.keypressend
ld h,~(.KEY_MODE_UP|.KEY_MODE_E0)
ld e,.KEY_MODE_CAPS
cp 0x58
jr z,.keypressm_xor
ld e,.KEY_MODE_NUML
cp 0x77
jr nz,.keypressend
.keypressm_xor
ld a,l
and h
xor e
jr .keypressend1
.keypressend
ld a,h
and l
.keypressend1
ld (.mode),a
jp .noredraw
.scodes
;0x0 0x1 0x2 0x3 0x4 0x5 0x6 0x7 0x8 0x9 0xa 0xb 0xc 0xd 0xe 0xf
; ,Esc,'1','2','3','4','5','6','7','8','9','0', , , BS,Tab
defb 0,141, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 0, 0,139,140 ;0x00
;'q','w','e','r','t','y','u','i','o','p','[',']',Ent,LCt,'a','s'
defb 17, 23, 5, 18, 20, 25, 21, 9, 15, 16, 27, 28,156, 68, 1, 19 ;0x10
;'d','f','g','h','j','k','L',';',"'",'~',LSh, ,'z','x','c','v'
defb 4, 6, 7, 8, 10, 11, 12, 29, 30, 33, 64, 0, 26, 24, 3, 22 ;0x20
;'b','n','m',',','.', ,RSh,'*',LAl,' ', , F1, F2, F3, F4, F5
defb 2, 14, 13, 31, 32, 0, 64,153, 66,142, 0,143,144,145,146,147 ;0x30
; F6, F7, F8, F9,F10, , ,'7','8','9','-','4','5','6','+','1'
defb 148,149,150,151,152, 0, 0,136,130,132,154,128,138,129,155,137 ;0x40
;'2','3','0','.', , , , , , , , , , , ,
defb 131,133,134,135, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;0x50
; , , , , , , , , , , , , , , ,
defb 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;0x60
; , , , , , , , , , , , , , , ,
defb 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ;0x70
.mod_base
; 11111111112222222 2223 333 333333444444 44
;12345678901234567890123456 7890 123 456789012345 67
.char_decode=$-1
defb "abcdefghijklmnopqrstuvwxyz","[];\',.`","1234567890-=\\/"
.mod_sh
defb "ABCDEFGHIJKLMNOPQRSTUVWXYZ","{}:\"<>~","!@#$%^&*()_+|?"
.mod_ru
.char_decode_ru=$-1
defb "фисвуапршолдьтщзйкыегмцчня","хъжэбюё","1234567890-=\\."
.mod_ru_sh
defb "ФИСВУАПРШОЛДЬТЩЗЙКЫЕГМЦЧНЯ","ХЪЖЭБЮЁ","!\"№;%:?*()_+/,"
.unmod
.unmod_decode=$-128
defb key_left,key_right,key_up,key_down ;128
defb key_pgup,key_pgdown,key_ins,key_del ;132
defb key_home,key_end,0,key_backspace ;136
defb key_tab,key_esc,' ',key_F1 ;140
defb key_F2,key_F3,key_F4,key_F5 ;144
defb key_F6,key_F7,key_F8,key_F9 ;148
defb key_F10,'*','-','+',key_enter ;152
.unmod_sh
defb "4682930.715"
.ctrl_decode=$-1
defb ssA,ssB,ssC,ssD,ssE,ssF,ssG,ssH,ssI,ssJ,ssK,ssL,ssM
defb ssN,ssO,ssP,ssQ,ssR,ssS,ssT,ssU,ssV,ssW,ssX,ssY,ssZ
db "{}:\"<>~",ss1,ss2,ss3,ss4,ss5,ss6,ss7,ss8,ss9,ss0,"_+|?"
.alt_decode=$-1
defb extA,extB,extC,extD,extE,extF,extG,extH,extI,extJ,extK,extL,extM
defb extN,extO,extP,extQ,extR,extS,extT,extU,extV,extW,extX,extY,extZ
db "{}:\"<>~",ext1,ext2,ext3,ext4,ext5,ext6,ext7,ext8,ext9,ext0,"_+|?"