All pastes #1454259 Raw Edit

Stuff

public text v1 · immutable
#1454259 ·published 2009-06-09 20:11 UTC
rendered paste body
; INPUT : 
; 	DL = scan code
; 	AL = convertion state 
;		bit 0 = SHIFT
;		bit 1 = CAPS LOCK
;		bit 7 = GREEK
; 	i.e. Latin : 0-none=small, 1-SHIFT, 2-CAPS LOCK, 3-SHIFT & CAPS LOCK
;	e.g. Greek & SHIFT & CAPS LOCK = 10000011b = 128 + 1 + 2 = 131 = 83h
;	     Latin & SHIFT = 00000001b = 1
; OUTPUT :
;	AL = 	ASCII code or 0 if special key
;       AH =	undefined
;       ZF =	set (ZR/zero) if special, releasing or invalid key

.MODEL SMALL

.DATA
	latin_sm	DB 27,"1234567890-=",8  ; a' grammh + Esc
			DB 7,"qwertyuiop[]",13  ; b' grammh
			DB 0,"asdfghjkl;'`"     ; g' grammh
			DB 0,"\zxcvbnm,./",0    ; d' grammh
			DB 0,0," ",0, 69 DUP(0) ; space + extras
	latin_CAP	DB 27,"!@#$%^&*()_+",8  ; a' grammh + Esc
			DB 7,"QWERTYUIOP{}",13  ; b' grammh
                        DB 0,"ASDFGHJKL:",22h,"~" ; g' grammh
                        DB 0,"|ZXCVBNM<>?",0    ; d' grammh
			DB 0,0," ",0, 69 DUP(0) ; space + extras
	greek_sm	DB 27,"1234567890-=",8  ; a' grammh + Esc
                        DB 7,";�œ¨«¬Ÿ ¦§[]",13  ; b' grammh
                        DB 0,"˜©›­šž�‘’''`"      ; g' grammh
                        DB 0,"\�―ΰ™�£,./",0    ; d' grammh
			DB 0,0," ",0, 69 DUP(0) ; space + extras
	greek_CAP	DB 27,"!@#$%^&*()_+",8  ; a' grammh + Esc
                        DB 7,":‘„’“‡ˆŽ{}",13  ; b' grammh
                        DB 0,"€‘ƒ”‚†‰Š'",22h,"~" ; g' grammh
                        DB 0,"|…•–—Œ‹<>?",0    ; d' grammh
			DB 0,0," ",0, 69 DUP(0) ; space + extras
.CODE

; use it from any piece of code
PUBLIC scan2a

; choose properly CAPS or small
; INPUT : 
;	AL : SHIFT state
;	DL : char
; OUTPUT : 
;	Zero Flag : 0/not zero/NZ =CAPS, 1/zero/ZR =small
ch_shift PROC NEAR
	CMP DL, 10h	; < 'q' (min)
	JB noletter
	CMP DL, 32h	; > 'm' (max)
	JA noletter
	CMP DL, 19h	; <='p' (min -p)
	JBE letter
	CMP DL, 1Eh	; < 'a' (a-l)
	JB noletter
	CMP DL, 26h	; <='l'
	JBE letter
	CMP DL, 2Ch	; < 'z' (z- max)
	JB noletter
letter: 
	XOR AL, 11b	; CAPS or SHIFT, not both
	JNP SHORT ex_ch
	XOR AL, AL
;	OR AL, 11b
	JMP SHORT ex_ch
noletter:
	AND AL, 1	; SHIFT decides
ex_ch:	
	RET
ch_shift ENDP

; main convertion proc PUBLIC
scan2a PROC NEAR
	PUSH BP 	; standart beginning
	MOV BP,SP
	PUSH DX
	PUSH BX
	PUSH SI
	CMP DL,80h	; depressed key => cancel
	JAE nokey
	CMP DL, 0
	JNE getit
nokey: 
	XOR AL, AL      ; no key => AL=0 && ZF=1/ZR
	JMP SHORT exit

getit:
	MOV DH,0	; prepare for 'table' addressing
	MOV SI, DX
	DEC SI		; eSC = 1 but at [BX][0], i.e. SI--
chlang:	
	TEST AL, 80h	; char set
	JZ latin
greek:
	CALL ch_shift	; SHIFT-ed?
	JZ gr_sm
	LEA BX, greek_CAP ; greek CAPS
	JMP SHORT outp
gr_sm:
	LEA BX, greek_sm  ; greek small
	JMP SHORT outp
latin:
	CALL ch_shift	; SHIFT-ed?
	JZ lat_sm
	LEA BX, latin_CAP ; latin CAPS
	JMP SHORT outp
lat_sm:
	LEA BX, latin_sm  ; latin small
outp:   
	MOV AL, [BX][SI]
	OR AH, 1	  ; ZF=NZ (ZR only for no key)

exit:
	POP SI
	POP BX
	POP DX
	POP BP
	RET
scan2a ENDP

END