FASM assembler, clicking two shift keys at the same time and making capital letters

26 views Asked by At

I have such a program in FASM assembler, I would like to make them capitalize when I enter the letters dfghjkl when I click the left shift and right shift at the same time, currently it works in such a way that even when I click the right shift they become capitalized, and I want them only when I click at the same time.

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

The code I provided shows my attempts.

1

There are 1 answers

2
Sep Roland On

currently it works in such a way that even when I click the right shift they become capitalized,

Whenever L-shift is pressed you do mov byte [ds:flagashift], 1, and whenever R-shift is pressed you do mov byte [ds:flagashiftp], 1.
Although the code that decides about capitalization reads flagashift, it also immediately overwrites it with the other flag! There's no way to have it depend on the left shift key that way.

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

and I want them only when I click at the same time.

Both keys pressed at the same time would translate into the sum of their flags being 2. Thus:

mov al, [ds:flagashift]  ; [0,1]
add al, [ds:flagashiftp] ; [0,1]
cmp al, 2
jne dalej5               ; Keep small caps
add bx, 7                ; Capitalize