1539 ;;KEY.MAC ;;various keyboard routines ;;======================================================================= ;;TITLE Hex4_In.MAC ;====== 1-4 HEX-tal h„mtas via INT 21h/08h (inget eko) ;====== visas via direkt skrivning till bildminnet ;====== och sparas i DX-registret Hex4_In MACRO LOCAL Visa, Siffra, Avsluta, Fel, Next_Char push ax push cx xor bx,bx ;;Nollst„ll tecken_r„knare xor dx,dx ;;Nollst„ll DX-register Next_Char: Fel: mov ah,08h ;;Get KEY int 21h cmp al,0dh ;; avslutar inmatning jz Avsluta cmp al,'0' ;;Ny inm. if lower than '0' jl Fel cmp al,'9' jle Visa ;;Visa if Lower or Equal '9' and al,0dfh ;;gemener -> VERSALER cmp al,'A' ;;Ny inm. if lower than 'A' jl Fel cmp al,'F' jle Visa ;;Visa if lower or equal 'F' jmp Fel Visa: inc bx cmp bx,05h jz Avsluta push dx ;;HEX-value sparas mov dl,al ;;Skriv HEX-tecken mov ah,02h int 21h pop dx ;;HEX-value h„mtas sub al,30h ;;ASCII -> HEX cmp al,0ah ;;V„rdet j„mf med 10 dec jc Siffra ;; Hopp om 0-9 sub al,07h ;;eljest minska med 7 Siffra: cbw ;;Byte -> Word mov cl,04h ;;F”rbered shift 4 ggr sal dx,cl ;;Skifta 4 ggr add dx,ax ;;Spara i DX jmp Next_Char Avsluta: pop cx pop ax ENDM ;;------------------------------------------------------------------------- ;;===== Get_Dec.MAC ;;===== Reads up to 5 decimal characters from keyb and stores them ;;===== in 'buff' get_dec MACRO buff LOCAL Next_char,Error,Show,Fill_Buf,Go_On,Over_fill,Exit push ax push cx push di call Fill_Buf xor bx,bx mov di,OFFSET buffer Next_Char: Error: mov ah,08h int 21h cmp al,0dh jz Exit cmp al,'0' jl Error cmp al,'9' jle Show jmp Error Show: Inc bx cmp bx,06h ;5 characters entered? jz Exit ;Yes, return mov dl,al mov ah,02h int 21h mov [di],al inc di jmp Next_Char Exit: jmp Over_fill fill_buf PROC NEAR mov di,OFFSET buffer mov ax,0000h Go_On: mov byte ptr[di],al inc di inc ah cmp ah,07h jnz Go_On ret fill_buf ENDP Over_fill: pop di pop cx pop ax ENDM ;;------------------------------------------------------------------------- ;;===== Get_Bin.MAC ;;===== Reads up to 16 binary '1':s or '0':s from keyb and stores them ;;===== in 'bin_buf' get_bin MACRO bin_buf,Attr LOCAL Next_char,Error,Show,Fill_Buf,Go_On,Over_fill,Exit push ax push bx push cx push di call Fill_Buf xor bx,bx mov di,OFFSET (bin_buf+1) Next_Char: Error: mov ah,08h int 21h cmp al,0dh jz Exit cmp al,'0' jl Error cmp al,'1' jle Show jmp Error Show: Inc bx cmp bx,11h ;16 characters entered? jz Exit ;Yes, return mov dl,al mov ah,02h int 21h mov [di],al inc di jmp Next_Char Exit: jmp Over_fill fill_buf PROC NEAR mov di,OFFSET bin_buf mov ax,0000h Go_On: mov byte ptr[di],al inc di inc ah cmp ah,18 jnz Go_On ret fill_buf ENDP Over_fill: pop di pop cx pop bx pop ax ENDM ;;------------------------------------------------------------------------- ;; Inkey1.MAC ;;===== v„ntar p† tangentnedtryckning inkey1 MACRO push ax push dx mov ah,00h int 16h pop dx pop ax ENDM ;;-------------------------------------------------------------------------- ;;==== L„ser in textstr„ng readstr MACRO strbuf push ax push dx mov dx,OFFSET strbuf mov ah,0ah int 21h pop dx pop ax ENDM ;;-------------------------------------------------------------------------- ;;Emptbuf.MAC ;;T”mmer tangentbordsbufferten ;;-------------------------------------------------------------------------- emptbuf MACRO push ax push es sub ax,ax mov es,ax mov al,es:[041ch] mov es:[041ah],al pop es pop ax ENDM . 0