summaryrefslogtreecommitdiff
path: root/sem2/lab5/DumpTSR.asm
diff options
context:
space:
mode:
authorAndrew <saintruler@gmail.com>2020-10-22 21:03:24 +0400
committerAndrew <saintruler@gmail.com>2020-10-22 21:03:24 +0400
commit143f34d941f32e0808fc9344d4c4126ff530d64a (patch)
treec79fcf309ad00e52100c0da544d96d3cc6ab6617 /sem2/lab5/DumpTSR.asm
Добавил решения второго семестра
Diffstat (limited to 'sem2/lab5/DumpTSR.asm')
-rw-r--r--sem2/lab5/DumpTSR.asm291
1 files changed, 291 insertions, 0 deletions
diff --git a/sem2/lab5/DumpTSR.asm b/sem2/lab5/DumpTSR.asm
new file mode 100644
index 0000000..fd3fad9
--- /dev/null
+++ b/sem2/lab5/DumpTSR.asm
@@ -0,0 +1,291 @@
+.MODEL Tiny
+.286
+.CODE
+ORG 100h
+
+LOCALS ; , @@
+
+TSRKeyCode = 2000h ; Alt+D
+
+Start:
+
+ jmp SetIntVec ;
+
+; 9 ( )
+Handler9:
+ pushf ; ( )
+ call dword ptr cs:OldInt9 ; 9
+ ;
+ pusha ;
+ cmp byte ptr cs:BusyFlag,0 ; ( , - , Alt+D )
+ jne @@Exit9 ; ,
+ mov ah,11h ; ( )
+ int 16h ; - - ( )
+ jz @@Exit9 ; ,
+ cmp ax,TSRKeyCode ;
+ jne @@Exit9 ; ,
+ sti ; ( ... , )
+ mov ah,10h
+ int 16h ;
+ mov byte ptr cs:BusyFlag,1 ;
+ ; /
+ push ds
+ push es ; DS, ES
+ call MainTSRProc ;
+ pop es
+ pop ds ; ES, DS
+ mov byte ptr cs:BusyFlag,0 ; 0 ( , - , Alt+D )
+ @@Exit9:
+ popa ;
+ iret ;
+
+;
+MainTSRProc proc
+ ;
+ mov ah,0Fh
+ int 10h ; AL , BH
+ cmp al,3 ; 3 ( 8025)
+ je @@OkVideoMode ; ,
+ ;
+ mov al,7
+ int 29h ; ( )
+ ret ;
+ ; , ,
+ @@OkVideoMode:
+ mov cs:[VideoPage],bh ;
+ mov ah,3
+ int 10h ; CX
+ mov cs:[OldCurSize],cx ;
+ mov bp,sp
+ mov ax,[bp+2+4+16] ; (2 - , 4 - ds,es, 16 - pusha)
+ mov cs:[DumpAddr],ax
+ mov ax,[bp+2+4+16+2] ;
+ mov cs:[DumpAddr+2],ax
+ ;
+ xor ax,ax
+ mov ds,ax ; DS = 0
+ mov si,ds:[44Eh] ; SI = , ( )
+ mov cs:[VideoOffset],si ;
+ mov ax,0B800h
+ mov ds,ax ; DS =
+ push cs
+ pop es ; ES =
+ lea di,ScreenBuffer ; DI = ( )
+ mov cx,80*25
+ cld ;
+ rep movsw ; (CX DS:SI ES:DI)
+ ;
+ mov ah,1
+ mov ch,20h ;
+ int 10h ;
+ ;
+ push ds
+ pop es ;
+ push cs
+ pop ds ; DS =
+ mov di,[VideoOffset] ; DI =
+ mov ax,1BC9h ; (AH)
+ stosw ; (AX) (ES:DI, DI=DI+2)
+ mov al,205 ;
+ mov cx,78
+ rep stosw ; 78
+ mov al,187 ;
+ stosw
+ mov cx,23
+ @@Vert: mov al,186 ;
+ cmp cl,3
+ jne @@1
+ mov al,199 ; 3-
+ @@1: stosw
+ mov al,' ' ;
+ cmp cl,3
+ jne @@2
+ mov al,196 ; 3-
+ @@2: push cx
+ mov cx,78
+ rep stosw
+ pop cx
+ mov al,186 ;
+ cmp cl,3
+ jne @@3
+ mov al,182 ; 3-
+ @@3: stosw
+ loop @@Vert
+ mov al,200 ;
+ stosw
+ mov al,205 ;
+ mov cx,78
+ rep stosw ; 78
+ mov al,188 ;
+ stosw
+ ;
+ mov ah,1Eh ;
+ lea si,HelpText1
+ mov di,(22*80 + 6)*2
+ call ShowText ;
+ mov di,(23*80 + 3)*2
+ call ShowText ; (SI HelpText2, .. HelpText1)
+ ;
+ @@MainLoop:
+ call ShowDump ;
+ mov ah,10h
+ int 16h ;
+ cmp ax,4BE0h ;
+ jne @@R
+ dec [DumpAddr] ; 1
+ @@R: cmp ax,4DE0h ;
+ jne @@CL
+ inc [DumpAddr] ; 1
+ @@CL: cmp ax,73E0h ; Ctrl+
+ jne @@CR
+ sub [DumpAddr],100h ; 100h
+ @@CR: cmp ax,74E0h ; Ctrl+
+ jne @@U
+ add [DumpAddr],100h ; 100h
+ @@U: cmp ax,48E0h ;
+ jne @@D
+ dec [DumpAddr+2] ; 1
+ @@D: cmp ax,50E0h ;
+ jne @@PU
+ inc [DumpAddr+2] ; 1
+ @@PU: cmp ax,49E0h ; Page Up
+ jne @@PD
+ sub [DumpAddr+2],100h ; 100h
+ @@PD: cmp ax,51E0h ; Page Down
+ jne @@E
+ add [DumpAddr+2],100h ; 100h
+ @@E: cmp ax,11Bh ; Esc
+ jne @@MainLoop
+ ;
+ lea si,ScreenBuffer ; SI =
+ mov di,[VideoOffset] ; DI =
+ mov cx,80*25
+ rep movsw ; : (CX DS:SI ES:DI)
+ ;
+ mov ah,1
+ mov bh,[VideoPage] ;
+ mov cx,[OldCurSize] ;
+ int 10h ;
+ ret
+MainTSRProc endp
+
+; DS:SI AH ES:DI
+ShowText proc
+ @@Char: lodsb ;
+ test al,al ;
+ jz @@Ret ; ,
+ stosw ;
+ jmp @@Char ;
+ @@Ret: ret
+ShowText endp
+
+; AL AH 16- ES:DI
+ShowByte proc
+ push ax
+ shr al,4 ;
+ cmp al,9
+ jbe @@1
+ add al,'A'-('9'+1)
+ @@1: add al,'0' ; 16-
+ stosw ;
+ pop ax
+ and al,0Fh ;
+ cmp al,9
+ jbe @@2
+ add al,'A'-('9'+1)
+ @@2: add al,'0' ; 16-
+ stosw ;
+ ret
+ShowByte endp
+
+; DX AH 16- ES:DI
+ShowWord proc
+ mov al,dh
+ call ShowByte
+ mov al,dl
+ call ShowByte
+ ret
+ShowWord endp
+
+ShowDump proc
+ push ds
+ lds si,dword ptr [DumpAddr] ; DS:SI =
+ mov di, (1*80 + 2)*2 ;
+
+ mov cx,20 ; 20
+ @@1: push cx
+ mov ah,1Bh ; -
+ mov dx,ds
+ call ShowWord ;
+ mov al,':'
+ stosw ;
+ mov dx,si
+ call ShowWord ;
+
+ mov cx,16 ; 16
+ mov ax,1320h ; -
+ stosw ;
+ @@2: mov al,' '
+ stosw ;
+ lodsb ; DS:SI (SI=SI+1)
+ call ShowByte ; 16-
+ loop @@2
+
+ mov al,' '
+ stosw
+ stosw ; 2
+ mov cx,16 ; 16
+ sub si,cx ; 16
+ mov ah,12h ; -
+ @@3: lodsb ; DS:SI (SI=SI+1)
+ stosw ;
+ loop @@3
+
+ pop cx
+ add di,160-(9+1+3*16+2+16)*2 ;
+ loop @@1
+ pop ds
+ ret
+ShowDump endp
+
+BusyFlag db 0 ; (0 - , 1 - )
+HelpText1 db 27,'/',26,' - one byte offset scroll, Ctrl',27,'/Ctrl',26,' - 100h bytes offset scroll',0
+HelpText2 db 24,'/',25,' - one segment scroll, PageUp/PageDn - 100h segments scroll, Esc - exit',0
+
+TSRCodeEnd = $ ; ( )
+
+OldInt9 dw ?,? ; 9
+DumpAddr dw ?,? ;
+OldCurSize dw ? ;
+VideoOffset dw ? ; ( )
+VideoPage db ? ;
+ScreenBuffer dw 80*25 dup (?) ;
+
+TSREnd = $ ;
+ORG TSRCodeEnd ; ( , )
+
+;
+SetIntVec:
+ mov ax,3509h ; 9 ( )
+ int 21h ;
+ mov OldInt9[0],bx ;
+ mov OldInt9[2],es ;
+ mov ah,25h ; - (AL=9 35h)
+ lea dx,Handler9 ; DS:DX =
+ int 21h ;
+
+ mov ah,49h ;
+ mov es,ds:[2Ch] ;
+ int 21h ; ( )
+
+ mov ah,9 ; ( '$')
+ lea dx,MsgInstalled ;
+ int 21h ;
+
+ lea dx,TSREnd ;
+ int 27h ; ,
+
+MsgInstalled db 'DumpTSR is successfully installed!',13,10
+ db 'Press <Alt>+<D> to activate.',13,10,'$'
+
+END Start