FASM汇编器,同时点击两个shift键并制作大写字母

问题描述 投票:0回答:1

我在 FASM 汇编器中有这样一个程序,当我同时单击左移和右移时输入字母 dfghjkl 时,我想让它们大写,目前它的工作方式是即使我单击右移它们会变成大写,只有当我同时单击时我才需要它们。

format MZ
stack stk:256
entry text:main

macro delay time
{
local ext,iter,end
      push cx
      mov cx, time
ext:
     in al,60h
     cmp al,01h
     je end
     push cx
     mov cx, 0FFFFh
iter:

     loop iter
     pop cx
     loop ext
     pop cx
end:
    pop cx


}
segment data_16 use16
_stare08 dw ?
         dw ?
_stare09 dw ?
_program dw ?
params   dw ?
         dw ?
mark_08  dw 0
time_08  db 0


mark_09 dw 320
znakim db 'dfghjkl'
znakid db 'DFGHJKL'
atryb db 71h
flagashift db 0      ;lewyshift-->2ah
flagashiftp db 0


segment text use16
moje08:
        push ax
        push bx
        push es
        test [time_08],03
        jnz skip
        mov ax,0B800h
        mov es,ax
        mov al,21h
        mov ah,71h
        mov bx,[mark_08]
        mov [es:bx],ax
        add [mark_08],2
skip:
        inc [time_08]
        pop es
        pop bx
        pop ax
        jmp dword [ds:_stare08]
moje09:
        push ax
        push bx
        push es
        in AL,60h

        cmp AL,42
        jne sprawdzPrawyShift
        mov byte [ds:flagashift],1
        jmp sprawdzPrawyShift


sprawdzPrawyShift:
    cmp AL, 54
    jne dalej3
    mov byte [ds:flagashiftp], 1

    ; Sprawdzenie, czy zarówno Shift lewy, jak i prawy shift jest wcisniety
    cmp byte [ds:flagashift], 1
    jne dalej3

dalej3:
        cmp AL,170
        jne dalej4
        mov byte [ds:flagashift],0
        mov byte [ds:flagashiftp],0
        jmp dalej4
Nieklik:
        cmp AL, 0BAh
        jne dalej4
        mov byte [ds:flagashiftp], 0
        jmp dalej4

dalej4:
        cmp AL,80h
        ja dalej
        sub AL,2
        cmp AL,09h
        ja dalej1
        inc AL
        cmp AL,80h
        jne xx
        sub AL,80h

xx:     add AL,30h
yy:
        mov AH,[atryb]
        mov BX,[mark_09]
        push ax
        mov ax,0B800h
        mov es,ax
        pop ax
        mov [ES:BX],AX
        add [mark_09],2
        jmp dalej
dalej1:
        sub al,30
        cmp al,6
        ja dalej
        mov ah,0
        mov bx,znakim
        add bx,ax
        mov al,byte [ds:flagashift]
        mov al,byte [ds:flagashiftp]
        test al,0FFh
        jz dalej5
        add bx,7


dalej5:
        mov al,[bx]
        jmp yy

dalej:
        in AL,61h
        or AL,80h
        out 61h,AL
        and AL,7Fh
        out 61h,AL

        mov AL,20h
        out 20h,AL

        pop es
        pop bx
        pop ax
        iret


moje10:
        push ax
        push bx
        push es
        in al,60h
        cmp AL,54
        jne asd
        mov byte [ds:flagashiftp],1
        jmp asd
asd:
        pop es
        pop bx
        pop ax
        iret

main:
        mov ax,data_16
        mov ds,ax
        mov ax,stk
        mov ss,ax
        mov sp,256

        cli
        xor ax,ax
        mov es,ax
        les bx,[es:(8 shl 2)]
        mov [_stare08+2],es
        mov [_stare08],bx
        mov es,ax
        mov word[es:(8 shl 2)],moje08
        mov word[es:(8 shl 2)+2],text

        mov es,ax
        les bx,[es:(9 shl 2)]
        mov [_stare09+2],es
        mov [_stare09],bx
        mov es,ax
        mov word[es:(9 shl 2)],moje09
        mov word[es:(9 shl 2)+2],text
        sti

        delay 60000

        cli
        xor ax,ax
        les cx,dword[ds:_stare08]
        mov ds,ax
        mov [ds:(8 shl 2)],cx
        mov [ds:(8 shl 2)+2],es

        mov ax,data_16
        mov ds,ax
        les cx,dword[ds:_stare09]
        xor ax,ax
        mov ds,ax
        mov [ds:(9 shl 2)],cx
        mov [ds:(9 shl 2)+2],es

        mov ax,data_16
        mov ds,ax
        sti

        mov ah,1
        int 21h
        mov ax,4c00h
        int 21h

        ret

....
segment stk use16
        db 256 dup (?)



    mov ah,1h
    int 21h
    
    mov ax,0003h
    int 10h
    
    mov ax,4c00h
    int 21h

我提供的代码显示了我的尝试。

assembly keyboard x86-16 dosbox fasm
1个回答
0
投票

目前它的工作方式是这样的,即使我单击右移,它们也会变成大写,

每当按下 L-shift 时,您就会执行

mov byte [ds:flagashift], 1
,每当按下 R-shift 时,您就会执行
mov byte [ds:flagashiftp], 1

尽管决定大小写的代码读取为 flagashift,但它也会立即用另一个标志覆盖它!没有办法让它依赖于左shift键。

mov al,byte [ds:flagashift]
mov al,byte [ds:flagashiftp]     <<< is overwriting AL
test al,0FFh
jz dalej5
add bx,7

只有当我同时点击时我才需要它们。

同时按下两个键将转化为它们的标志之和为 2。因此:

mov al, [ds:flagashift]  ; [0,1]
add al, [ds:flagashiftp] ; [0,1]
cmp al, 2
jne dalej5               ; Keep small caps
add bx, 7                ; Capitalize
© www.soinside.com 2019 - 2024. All rights reserved.