; _____________________________________________ ; | | ; | Project: APPLER | ; | File: CONIO.ASM | ; | Compiler: 16-bit TASM (2.5) | ; | | ; | Subject: Keyboard input / screen output | ; | | ; | Author: Emil Dotchevski | ; |_____________________________________________| include GLOBALS.INC include INTERFAC.INC include CONIO.INC CONio segment public assume ds:CONio,cs:CONio,es:ApplerVideo ; --- Get Line Services Proc --- GL_ServSubrt dw GetLine dw GL_Symbol,GL_String,GL_Byte,GL_GetSymb,GL_Left,GL_Right dw GL_Ins,GL_Del,GL_BackSpc,GL_Home,GL_End,GL_ClrBuff,GetCommand GL_Services proc far push bp ds shl bp,1 call cs:GL_ServSubrt[bp] pop ds bp ret GL_Services endp ; --- Screen Services Proc --- SIO_ServSubrt dw ClearScreen,ShowScreen dw SymbPrint,SymbPrintXY,BytePrint,StringPrint,GetSymb,ShowLine,CalcXY dw ShowCursor,HideCursor,SetTextMode,SetScreen SIO_Services proc far push bp ds shl bp,1 call cs:SIO_ServSubrt[bp] pop ds bp ret SIO_Services endp ; --- Pointers Storage --- GL_ParamsAdr label dword GL_ParamsOfs dw ? GL_ParamsSeg dw ? SIO_ParamsAdr label dword SIO_ParamsOfs dw ? SIO_ParamsSeg dw ? RK_ParamsAdr label dword RK_ParamsOfs dw ? RK_ParamsSeg dw ? GL_SetRegs macro lds bp,cs:GL_ParamsAdr endm SIO_SetRegs macro lds bp,cs:SIO_ParamsAdr endm RK_SetRegs macro lds bp,cs:RK_ParamsAdr endm ; --- GET LINE proc --- GL_Commands db 05h,06h,09h,0Ah,0Bh db 01h,02h db 18h,0Ch GL_ComSubrt dw GL_Left,GL_Right,GL_Ins,GL_Del,GL_BackSpc dw GL_Home,GL_End dw GL_Enter,GL_Esc GL_FirstFlag db ? GetLine: push ax bx cx dx di bp ds GL_SetRegs mov cs:GL_FirstFlag,1 mov word ptr ds:[bp].GL_CX,cx call CalcXY mov ds:[bp].GL_X,cl mov ds:[bp].GL_Y,ch mov al,ds:[bp].GL_Length cmp al,ds:[bp].GL_Pos jae GL_Loop0 mov ds:[bp].GL_Pos,al GL_Loop0: test ds:[bp].GL_InsFlag,1 mov al,ds:[bp].GL_OverCurColor jz GL_Cursor mov al,ds:[bp].GL_Length cmp al,ds:[bp].GL_MaxLength mov al,ds:[bp].GL_InsCurColor jb GL_Cursor mov al,ds:[bp].GL_OverCurColor GL_Cursor: SIO_SetRegs mov ds:[bp].CursorColor,al GL_SetRegs xor bx,bx mov bl,ds:[bp].GL_Pos mov ch,ds:[bp].GL_Y mov cl,bl sub cl,ds:[bp].GL_BegPrint add cl,ds:[bp].GL_X call ReadKey mov di,offset GL_Commands mov cx,offset GL_ComSubrt - offset GL_Commands call CalcCommand jc GL_NotCmnd shl di,1 call word ptr cs:GL_ComSubrt[di] mov cs:GL_FirstFlag,0 jnc GL_Loop0 cmp ax,0 clc jz GL_MainRet stc GL_MainRet: pop ds bp di dx cx bx ax ret GL_NotCmnd: cmp al,20h jb GL_CallUser cmp cs:GL_FirstFlag,0 jz GL_CallSymbol cmp ds:[bp].GL_Pos,0 ja GL_CallSymbol call GL_ClrBuff GL_CallSymbol: call GL_Symbol jmp GL_Loop0 GL_CallUser: call ds:[bp].[GL_User] mov cs:GL_FirstFlag,1 jmp GL_Loop0 GL_Symbol: push bx cx dx si di ds es GL_SetRegs test ds:[bp].GL_AllowSpc,1 jnz GL_S_do1 cmp al,20h je GL_Sret GL_S_do1: xor bx,bx mov bl,ds:[bp].GL_Pos test ds:[bp].GL_InsFlag,1 jz GL_S_Over xor cx,cx mov cl,ds:[bp].GL_Length cmp cl,ds:[bp].GL_MaxLength jnb GL_S_Over push ds pop es sub cl,bl inc cx xor dx,dx mov dl,ds:[bp].GL_Length mov si,ds:[bp].GL_Buffer add si,dx mov di,si inc di std rep movsb inc ds:[bp].GL_Length jmp GL_S_1 GL_S_Over: mov cl,ds:[bp].GL_Length cmp bl,cl jb GL_S_1 cmp cl,ds:[bp].GL_MaxLength jnb GL_Sret inc ds:[bp].GL_Length GL_S_1: xor bx,bx mov bl,ds:[bp].GL_Pos add bx,ds:[bp].GL_Buffer mov [bx],al call GL_Right GL_Sret: pop es ds di si dx cx bx ret GL_String: push ax bx bp ds ; Puts a string in the buffer GL_SetRegs GL_Str0: mov al,[bx] cmp al,0 je GL_Str1 call GL_Symbol inc bx jmp GL_Str0 GL_Str1: pop ds bp bx ax ret GL_Byte: push ax ; Overwrite / Insert a byte shr al,4 cmp al,0Ah cmc adc al,30h daa call GL_Symbol pop ax push ax and al,00001111b cmp al,0Ah cmc adc al,30h daa call GL_Symbol pop ax ret GL_Left: push bx cx bp ds ; Moves cursor left GL_SetRegs xor bx,bx mov bl,ds:[bp].GL_Pos cmp bl,0 jna GL_Lret dec bx mov cx,bx sub cl,ds:[bp].GL_BegPrint cmp cl,2 jae GL_Lret cmp ds:[bp].GL_BegPrint,0 jna GL_Lret dec ds:[bp].GL_BegPrint GL_Lret: mov ds:[bp].GL_Pos,bl pop ds bp cx bx clc ret GL_Right: push bx cx bp ds ; Moves cursor right GL_SetRegs xor bx,bx mov bl,ds:[bp].GL_Pos cmp bl,ds:[bp].GL_Length jnb GL_Rret inc bx mov cx,bx mov ch,ds:[bp].GL_MaxPrint sub ch,2 sub cl,ds:[bp].GL_BegPrint cmp cl,ch jb GL_Rret mov cl,ds:[bp].GL_Length sub cl,ds:[bp].GL_BegPrint cmp cl,ds:[bp].GL_MaxPrint jna GL_Rret inc ds:[bp].GL_BegPrint GL_Rret: mov ds:[bp].GL_Pos,bl pop ds bp cx bx clc ret GL_Ins: push bp ds GL_SetRegs xor ds:[bp].GL_InsFlag,1 ; Toggles INS mode pop ds bp clc ret GL_Del: push bx cx si di ds es ; Delete char at cursor GL_SetRegs cmp ds:[bp].GL_Length,0 jz GL_Dret xor bx,bx mov bl,ds:[bp].GL_Pos cmp bl,ds:[bp].GL_Length jae GL_Dret push ds pop es mov si,ds:[bp].GL_Buffer add si,bx mov di,si inc si xor cx,cx mov cl,ds:[bp].GL_Length sub cl,bl cld rep movsb dec ds:[bp].GL_Length mov bl,ds:[bp].GL_Length sub bl,ds:[bp].GL_BegPrint cmp bl,ds:[bp].GL_MaxPrint jae GL_Dret cmp ds:[bp].GL_BegPrint,0 jz GL_Dret dec ds:[bp].GL_BegPrint GL_Dret: pop es ds di si cx bx clc ret GL_BackSpc: push bp ds GL_SetRegs cmp ds:[bp].GL_Pos,0 jna GL_BS_ret call GL_Left call GL_Del GL_BS_ret: pop ds bp clc ret GL_Home: push bx mov bx,0FFh GL_Hloop: call GL_Left dec bx jnz GL_Hloop pop bx clc ret GL_End: push bx mov bx,0FFh GL_Eloop: call GL_Right dec bx jnz GL_Eloop pop bx clc ret GL_Esc: call GL_SetZero mov ax,1 stc ret GL_Enter: call GL_SetZero mov ax,0 stc ret GL_SetZero: push bx xor bx,bx mov bl,ds:[bp].GL_Length add bx,ds:[bp].GL_Buffer mov byte ptr [bx],0 pop bx ret GL_ClrBuff: push ax bp ds GL_SetRegs xor ax,ax mov ds:[bp].GL_Pos,al mov ds:[bp].GL_Length,al mov ds:[bp].GL_BegPrint,al xor cx,cx pop ds bp ax ret GL_GetSymb: push bx bp ds GL_SetRegs mov ds:[bp].GL_Pos,cl mov ds:[bp].GL_BegPrint,ch GL_GS_Loop0: xor bx,bx mov bl,ds:[bp].GL_Pos cmp bl,ds:[bp].GL_Length mov al,0 jae GL_GS_ret pushf add bx,ds:[bp].GL_Buffer mov al,ds:[bx] call GL_Right popf jb GL_GS_0 inc ds:[bp].GL_Pos GL_GS_0: test ds:[bp].GL_GS_SpcFl,1 jz GL_GS_ret cmp al,' ' je GL_GS_Loop0 GL_GS_ret: mov cl,ds:[bp].GL_Pos mov ch,ds:[bp].GL_BegPrint pop ds bp bx ret GL_Ecx dw ? GL_Ecx1 dw ? GL_ComSymb db 'abcdefghijklmnopqrstuvwxyz?[.' GL_ComSymbC = 29 GetCommand: push si cx dx bp ds ; Scan for commands GL_SetRegs mov dl,ds:[bp