;-TREE.ASM-V0.4-------------------------------------------------------------- ; x86 - Dos - Assembly Language Programming ; ; ; ; Written by: John A Lyons ; ; Email : sysop@megablast.8k.com ; ; Page : http://www.asmsource.8k.com/ ; ; Compiler : Tasm v4 (Borland Turbo Assembler), available from above page. ; ; Date : 16-Dec-2000 ; ; Purpose : Displays the directory tree, including various statistics. ; ; Work still in Progress. ; ; ; ;---------------------------------------------------------------------------- cseg segment assume cs:cseg, ds:cseg org 100H jumps treesize equ 32 begin: lea sp,stk+200h mov ah,4ah mov bx,(offset stk - offset begin + 30fh )/16 int 21h mov ax,3 int 10h mov ah,47h mov dl,0 push cs pop ds lea si,current1 int 21h mov ah,19h int 21h mov cs:[current],al mov cs:[olddrive],0ffh cmp cs:[80h],byte ptr 0 je noinfo mov al,cs:[current] mov cs:[olddrive],al lea si,current1 lea di,olddir inf1: mov ah,cs:[si] mov cs:[di],ah inc di inc si or ah,ah jnz inf1 mov di,82h cmp cs:[83h],byte ptr ":" jne nonewd mov ah,cs:[82h] cmp ah,'a' ja smalle sub ah,"A" jmp sok smalle: sub ah,"a" sok: mov cs:[current],ah mov dl,ah mov ah,0eh int 21h mov di,84h nonewd: cmp cs:[di],byte ptr 0dh je nodir11 nodir11: mov ah,47h mov dl,0 push cs pop ds lea si,current1 int 21h noinfo: mov ah,48h mov bx,1000h int 21h jc nogo mov cs:[viewmem],ax mov ah,48h mov bx,-1 int 21h sub bx,4 mov ax,bx shr ax,1 mov cs:[maxmem],bx mov ah,48h int 21h jc nogo2 mov cs:[treemem],ax mov cs:[treemem2],ax mov cs:[mytreemem],ax mov ds,ax mov ds:[0],word ptr 0 mov cs:[treeloc],0 mov di,160 add cs:[current],'A' call tree mov ds,cs:[treemem] mov ds:[0],byte ptr 0ffh mov cs:[col],2bh mov di,100 lea si,mmax call mess mov ax,cs:[maxmem] xor dx,dx call ndwrd call waitkey ; mov ds,cs:[treemem2] ; mov ax,ds:[16] ; mov dx,ds:[18] ; call shrink ; mov bx,cs:[files] ; shl bx,10 ; add ax,bx ; jnc tok3a ; inc dx ;tok3a: ; add ds:[21],ax ; jnc tok3 ; inc dx ;tok3: ; add ds:[23],dx mov ax,3 int 10h call showtree mov ax,3 int 10h mov es,cs:[treemem] mov ah,49h int 21h nogo2: mov es,cs:[viewmem] mov ah,49h int 21h nogo: cmp cs:[olddrive],0ffh je nochb mov ah,0eh mov dl,cs:[olddrive] int 21h nochb: mov ah,4ch int 21h col db 0 video dw 0b800h mhello1 db 'Skelton Routines',0 treemem dw 0 treemem2 dw 0 treeloc dw 0 maxmem dw 0 mmax db "Max ",0 olddrive db 0 olddir db 64 dup (0) mess proc push ax push es mov es,cs:[video] mov ah,cs:[col] or ah,ah jz gomessc conmess: mov al,cs:[si] or al,al jz endmess mov es:[di],ax inc si add di,2 jmp conmess endmess: pop es pop ax ret gomessc: mov al,cs:[si] or al,al jz endmess mov es:[di],al inc si add di,2 jmp gomessc dmess: push ax push es mov es,cs:[video] mov ah,cs:[col] conmess7: mov al,ds:[si] or al,al jz endmess7 mov es:[di],ax inc si add di,2 jmp conmess7 endmess7: pop es pop ax ret mess endp cmess proc push ax push si mov ax,si cma1: cmp cs:[si],byte ptr 0 jz cma1a inc si jmp cma1 cma1a: sub si,ax mov ax,si pop si sub cx,ax jnc cma2 xor cx,cx cma2: shr cx,1 push cx call clear messoffset: call mess pop cx push cx call clear pop cx pop ax ret cmess2: push cx mov cl,byte ptr cs:[windsiz+1] xor ch,ch ; shr cl,1 dec cl call cmess pop cx ret cmess endp DWRD PROC far push es PUSH AX PUSH BX PUSH CX PUSH DX push si push di call sl_putul mov ax,10 sub ax,cx mov dx,ax xor ah,ah mov al,cl mov bl,3 dec al div bl mov cs:[ctemp],ah sub dl,al xor dh,dh shl dx,1 add di,dx call numshow pop di pop si POP DX POP CX POP BX POP AX pop es RET numbspace db 16 dup(0),0 DWRD ENDP nDWRD PROC NEAR push es mov es,cs:[video] PUSH AX PUSH BX PUSH CX PUSH DX push si call sl_putul xor ah,ah mov al,cl mov bl,3 dec al div bl mov cs:[ctemp],ah call numshow pop si POP DX POP CX POP BX POP AX pop es RET nDWRD ENDP cDWRD PROC NEAR push es push si push ax push bx push dx mov cs:[clen],cx call sl_putul push cx xor ah,ah mov al,cl mov bl,3 dec al div bl mov cs:[ctemp],ah xor ah,ah add ax,cx mov cx,cs:[clen] cmp cx,ax jbe putu9 sub cx,ax call clear putu9: pop cx call numshow ;putu6: pop dx pop bx pop ax pop si pop es ret clen dw 0 ctemp db 0 cDWRD ENDP dwrd3 proc near PUSH AX PUSH BX PUSH DX push si PUSH CX call sl_putul xor bx,bx d3x: mov al,cs:[si] or al,al jz d3z mov es:[di],al inc di inc si inc bx loop d3x d3z: POP CX add cx,bx pop si POP DX POP BX POP AX ret dwrd3 endp numshow proc near mov es,cs:[video] or cl,cl jz dputu6 mov bl,4 cmp cl,3 jbe dputul2 mov bl,cs:[ctemp] dputul2: mov ah,cs:[col] or ah,ah jz nocols2 dputul1: mov al,cs:[si] mov es:[di],ax add di,2 inc si dec cl or cl,cl jz dputu6 or bl,bl jnz dputu5 mov al,',' mov es:[di],ax add di,2 mov bl,3 dputu5: dec bl jmp dputul1 dputu6: ret nocols2: ncdputul1: mov al,cs:[si] mov es:[di],al add di,2 inc si dec cl or cl,cl jz ncdputu6 or bl,bl jnz ncdputu5 mov es:[di],byte ptr ',' add di,2 mov bl,3 ncdputu5: dec bl jmp ncdputul1 ncdputu6: ret numshow endp ; ; Putul prints the value in DX:AX as an unsigned dword integer value. ; sl_PutUL proc near lea si,numbspace push ax push bx ;push cx push dx call PutI2 mov cx,si lea si,numbspace sub cx,si pop dx ;pop cx pop bx pop ax ret sl_PutUL endp ; ; PutI2- Recursive routine to actually print the value in AX as an integer. ; Puti2 proc near call Div10 cmp ax, dx ;See if dx:ax=0 jnz NotDone or ax, ax jz Done NotDone: push bx call Puti2 pop bx Done: add bl,'0' mov cs:[si],bl inc si ret PutI2 endp ; ; Div10- Divides DX:AX by 10 leaving the remainder in BL and the quotient ; in DX:AX. ; Div10 proc near mov cx, 10 mov bx, ax xchg ax, dx xor dx, dx div cx xchg bx, ax div cx xchg dx, bx ret Div10 endp window1 proc near add di,cs:[screenwidth] push di mov al,cs:[si] stosw mov al,cs:[si+1] xor ch,ch mov cl,dl sub cl,2 rep stosw mov al,cs:[si+2] stosw cmp cs:[shadow],1 jne win1a mov es:[di+1],byte ptr 07h mov es:[di+3],byte ptr 07h win1a: add si,3 pop di ret window1 endp window2 proc near push di call window1 pop di xor ch,ch mov cl,dl shl cx,1 add di,cs:[screenwidth] ret window2 endp windowb proc near ;dh -len box1: ;dl -height mov cs:[windsiz],dx push dx push ax mov ax,cs:[screenwidth] shr ax,1 sub ax,2 and dh,254 sub al,dh add di,ax pop ax pop dx mov cs:[shadow],1 jmp box1c box1nc: mov cs:[shadow],0 box1c: mov cs:[windsiz],dx mov cs:[wpos1],di push si windtype: lea si,wind1 winbeg: mov es,cs:[video] push di push ax add dx,202h xchg dh,dl mov ah,ch sub di,cs:[screenwidth] push word ptr cs:[shadow] mov cs:[shadow],0 call window1 pop word ptr cs:[shadow] win1: call window2 sub si,3 dec dh cmp dh,2 jne win1 add si,3 call window2 add di,cs:[screenwidth] add di,2 cmp cs:[shadow],0 je win22 add di,3 xor ch,ch mov cl,dl win21: mov es:[di],byte ptr 7 add di,2 loop win21 win22: pop ax pop di pop si ret wind1 db 'ÉÍ»º ºÈͼ' wind2 db 'ÚÄ¿³ ³ÀÄÙ' shadow db 0 windsiz dw 0 windpos dw 0 wpos1 dw 0 windowb endp box2nc proc near lea si,wind2 lea bp,windtype inc bp mov cs:[bp],word ptr si call box1nc lea si,wind1 mov cs:[bp],word ptr si ret box2nc endp grabmem proc near mov ah,48h mov cs:[gmem],bx int 21h jnc nogr1 nogr1: ret mnomem db 'Not enough Mem',0 mmem2 db' MCB destroyed',0 gmem dw 0 gmax dw 0 grabmem endp clear proc near push es mov es,cs:[video] or cx,cx jz nocl3a cmp cx,4000 ja nocl3a push ax mov al,20h mov ah,cs:[col] or ah,ah jz nocols4 clear22: mov es:[di],ax add di,2 loop clear22 allcols1: pop ax nocl3a: pop es ret nocols4: mov es:[di],al add di,2 loop nocols4 jmp allcols1 clear2: mov es:[di],ax add di,2 loop clear2 ret clear endp fuckmem proc near push es mov es,ax mov ah,49h int 21h pop es ret fuckmem endp hide proc near push ds push di push cx push dx mov ax,cs:[screenwidth] shr ax,1 sub ax,2 sub al,dh add di,ax jmp skiphide2 hide2: push ds push di push cx push dx skiphide2: xor ah,ah mov al,dh shl ax,1 add ax,4 xor dh,dh add dx,4 mul dx add ax,4 mov cx,8 div cx ;shr ax,3 inc ax mov bx,ax mov ah,48h int 21h jnc bbp6 mov ax,cs:[video] add ax,100h bbp6: mov cs:[shide],ax pop dx push dx mov ds,ax xor si,si mov ds:[si],di mov ds:[si+2],dx mov cl,dh xor ch,ch shl cx,1 add cx,4 add dl,4 add si,4 kil2: push di push cx kil1: mov ax,es:[di] mov ds:[si],ax add si,2 add di,2 loop kil1 pop cx pop di add di,cs:[screenwidth] dec dl or dl,dl jnz kil2 bbp1: pop dx pop cx pop di pop ds ret shide dw 0 hide endp show proc near push ds call waitretrace mov es,cs:[video] mov ds,cs:[shide] xor si,si mov di,ds:[si] mov dx,ds:[si+2] mov cl,dh xor ch,ch shl cx,1 add cx,04h add dl,4 add si,4 push dx mov bh,dh kol2: mov dh,bh push di push cx kol1: mov ax,ds:[si] mov es:[di],ax add si,2 add di,2 loop kol1 pop cx pop di add di,cs:[screenwidth] dec dl or dl,dl jnz kol2 bbp2: mov ax,cs:[shide] call fuckmem pop ax pop ds ret show endp waitkey proc near push di startkeychk: ;cmp cs:[subprog],0 ;jne noalti1 ;call checkalt ;cmp al,255 ;jne noalti1 ;mov al,1 ;pop di ;ret noalti1: mov ah,1 int 16h jz startkeychk in al,60h push es push di mov es,cs:[keyseg] mov di,es:[1ah] mov es:[1ch],di mov ah,es:[di] pop di pop es cmp al,0 je startkeychk in al,60h push ax mov ah,2 int 16h mov cs:[keyflag],al pop ax pop di ret keyseg dw 40h keyflag db 0 waitkey endp iskey proc near push es push di mov ah,1 int 16h jz nokey1 or ax,ax jz iskey3 ;mov es,cs:[video] ;mov es:[0],al ;mov es:[1],byte ptr 4fh ;mov es:[2],ah ;mov es:[3],byte ptr 4fh mov es,cs:[keyseg] mov di,es:[1ah] mov es:[1ch],di mov al,ah jmp nokey2 iskey3: in al,60h push es mov es,cs:[keyseg] mov di,es:[1ah] mov es:[1ch],di mov ah,es:[di] pop es cmp al,0 je nokey1 in al,60h clc jmp nokey2 nokey1: mov es,cs:[keyseg] mov di,es:[1ah] cmp di,es:[1ch] je nokey3 mov ah,1 int 16h jmp iskey3 nokey3: stc nokey2: pop di pop es ret iskey endp waitretrace proc near push ax push dx mov dx,03dah xvert: in al,dx and al,8 jz xvert xvert1: in al,dx and al,8 jnz xvert1 pop dx pop ax ret waitretrace endp hex4 proc near push es mov es,cs:[video] jmp hex4a hex4b: push es hex4a: push ax push ax mov al,ah call hex2 pop ax call hex2 pop ax pop es ret hex4 endp hex2 proc near push ax and al,011110000b shr al,4 call hex1 pop ax push ax and al,01111b call hex1 pop ax ret hex2 endp hex1 proc near push es mov es,cs:[video] mov ah,cs:[col] cmp al,10 jb hnum1 add al,'A'-10 jmp hnum2 hnum1: add al,'0' hnum2: mov es:[di],ax add di,2 pop es ret hex1 endp getsinfo proc near MOV AX,1130H XOR BH,BH INT 10H DEC DL MOV CS:[screensize],Dl mov ah,0fh int 10h mov al,ah xor ah,ah shl ax,1 mov cs:[screenwidth],ax ret screenwidth dw 160 screensize db 0,0 getsinfo endp tree proc near ;----------------------------- call topsetup mov ah,1ah xor dx,dx mov ds,cs:[viewmem] int 21h mov cs:[dsize],0 mov cs:[dsize+2],0 mov cs:[fileno2],0 push cs pop ds mov ax,4e00h mov cx,0110111b ÿ lea dx,allfiles int 21h jc nofiles mov ds,cs:[viewmem] rego: test ds:[15h],byte ptr 16 jz nodir cmp ds:[1eh],byte ptr "." je nexty mov ax,cs:[files] cmp ax,cs:[maxmem] jae nonono add cs:[treemem],2 push cs:[mytreemem] mov ax,cs:[treemem] mov cs:[mytreemem],ax push di push bp mov es,ax;cs:[mytreemem] xor bp,bp mov si,1eh lea di,dir mov cx,14 regt: mov ah,ds:[si] mov cs:[di],ah mov es:[bp],ah or ah,ah jz regte inc di inc bp inc si loop regt regte: pop bp pop di mov cs:[col],4fh push cs:[sizep] push di lea si,dir call mess mov cs:[sizep],di pop di mov ah,3bh ;--------------------- push cs pop ds lea dx,dir int 21h push cs:[dsize] push cs:[dsize+2] add cs:[viewmem],100h add di,180 push cs:[tsize] push cs:[tsize+2] push cs:[tsize+4] push cs:[fileno2] mov cs:[tsize],0 mov cs:[tsize+2],0 mov cs:[tsize+4],0 inc cs:[depth] call tree ;****** dec cs:[depth] mov ax,cs:[tsize] mov dx,cs:[tsize+2] mov bx,cs:[tsize+4] pop cs:[fileno2] pop cs:[tsize+4] pop cs:[tsize+2] pop cs:[tsize] add cs:[tsize],ax jnc tok inc dx tok: add cs:[tsize+2],dx jnc toka inc bx toka: add cs:[tsize+4],bx pop cs:[dsize+2] pop cs:[dsize] pop cs:[sizep] sub di,20 sub cs:[viewmem],100h mov ds,cs:[viewmem] mov ah,1ah xor dx,dx int 21h mov ah,3bh push cs pop ds lea dx,cddown int 21h mov ds,cs:[viewmem] pop cs:[mytreemem] jmp nexty nodir: inc cs:[fileno] inc cs:[fileno2] mov ax,ds:[1ah] mov dx,ds:[1ch] add cs:[dsize],ax jnc file1 inc dx file1: add cs:[dsize+2],dx nexty: mov ah,4fh int 21h jnc rego nofiles: mov ax,cs:[dsize] mov dx,cs:[dsize+2] mov es,cs:[mytreemem] mov es:[16],ax mov es:[18],dx ; call shrink add cs:[tsize],ax jnc tok22 inc dx tok22: add cs:[tsize+2],dx jnc tok22a inc cs:[tsize+4] tok22a: mov ax,cs:[tsize] mov dx,cs:[tsize+2] mov bx,cs:[tsize+4] mov es:[21],ax mov es:[23],dx mov es:[25],bx mov ax,cs:[fileno2] mov es:[27],ax mov al,cs:[depth] mov es:[20],al inc cs:[files] mov di,28 mov cs:[col],2ah mov ax,cs:[files] xor dx,dx call ndwrd add di,14 mov ax,cs:[fileno] call ndwrd nonono: ret allfiles db "*.*",0 cddown db "..",0 viewmem dw 0 dir db 16 dup(0) dsize dw 0,0 tsize dw 0,0,0 sizep dw 0 files dw 0 depth db 0 mytreemem dw 0 fileno2 dw 0 tree endp line proc near push ax push cx push di push es mov es,cs:[video] mov ah,cs:[col] xor al,al mov cx,80 line2: mov es:[di],ax add di,2 loop line2 pop es pop di pop cx pop ax ret line endp shrink proc near push cx mov cl,20 shr1: clc rcr bx,1 rcr dx,1 rcr ax,1 rcr cs:[rem],1 dec cl or cl,cl jnz shr1 pop cx push ax push dx mov ax,cs:[rem] xor dx,dx mov bx,655 div bx mov bx,ax pop dx pop ax ret rem dw 0 shrink endp topsetup proc near mov cs:[col],2fh mov di,0 call line lea si,mtree call mess add di,10 mov cs:[col],2ah mov ax,cs:[files] xor dx,dx call ndwrd lea si,mdir call mess mov ax,cs:[fileno] call ndwrd lea si,mfile call mess ret topsetup endp showtree proc near call topsetup showit: mov cs:[col],27h lea si,mlevel mov di,100 call mess mov al,cs:[level] xor ah,ah xor dx,dx call ndwrd mov di,160 mov cx,24 mov cs:[col],19h sl1: call line add di,160 loop sl1 mov ax,cs:[start] shl ax,1 add ax,cs:[treemem2] mov ds,ax call waitretrace mov cx,cs:[files] cmp cx,24 jbe shok1 mov cx,24 shok1: mov cs:[lineno],0 mov cs:[checkno],0 xor si,si mov di,160 show1: mov ax,cs:[checkno] cmp ax,cs:[files] jae rewait inc cs:[checkno] push cx push si push di xor si,si mov es,cs:[video] mov cs:[col],19h mov al,ds:[20] cmp al,0ffh jne nore1 je rewait pop di pop si pop cx nore1: mov ah,cs:[level] or ah,ah jz nocheck cmp al,ah jbe nocheck pop di pop si mov ax,ds add ax,2 mov ds,ax pop cx jmp show1 nocheck: mov bh,al push di or al,al jz goend dec al xor ah,ah shl ax,3 add di,ax nol1: push si lea si,link call mess pop si cmp ds:[20+32],bh jne nolinkb mov es:[di-8],byte ptr "Ã" jmp goend ;forward nolinkb: cmp cs:[level],0 jne nolink mov dx,cs:[files] sub dx,cs:[start] sub dx,cs:[lineno] or dx,dx je goend push ds push di xor cx,cx regodo: mov ax,ds add ax,2 mov ds,ax cmp ds:[20],bh jb endpage je nogodo inc cx jmp regodo nogodo: or cx,cx je endpage mov es:[di-8],byte ptr "Ã" cmp cx,23 jbe l2dd mov cx,dx playdo: add di,160 mov es:[di-8],byte ptr "³" dec dx or dx,dx je endpage loop playdo endpage: pop di pop ds goend: ;backward cmp es:[di-168],byte ptr "³" je nolink push ds push di mov dx,cs:[start] add dx,cs:[lineno] xor cx,cx l2: mov ax,ds sub ax,2 mov ds,ax cmp ds:[20],bh jb nol2 je l2d inc cx dec dx or dx,dx jnz l2 or cx,cx je l2b dec cx l2d: mov dx,cs:[lineno] or dx,dx je l2b cmp cx,dx jbe l2dd mov cx,dx l2dd: or cx,cx jz l2b l2c: sub di,160 mov es:[di-8],byte ptr "³" loop l2c l2b: nol2: pop di pop ds nolink: cmp ds:[si],byte ptr 0 jne noli1 mov cs:[col],1ch lea si,current call mess jmp isli1 noli1: mov cs:[col],1fh call dmess isli1: test byte ptr cs:[tag],7 jz nobrac mov cs:[col],1eh lea si,bra1 call mess test byte ptr cs:[tag],4 jz noshowd lea si,md1 call mess mov ax,ds:[16] mov dx,ds:[18] mov cs:[col],1ah call ndwrd lea si,mkb call mess noshowd: test byte ptr cs:[tag],2 ;file no jz noshowf mov cs:[col],1eh lea si,mcom call mess mov cs:[col],17h mov ax,ds:[27] xor dx,dx call ndwrd lea si,mfile call mess sub di,2 noshowf: ;show total test byte ptr cs:[tag],1 jz noshowt mov cs:[col],17h mov cs:[col],1eh lea si,md2 call mess mov ax,ds:[21] mov dx,ds:[23] mov bx,ds:[25] call shrink push bx mov cs:[col],1bh call ndwrd lea si,mdot call mess pop ax xor dx,dx call ndwrd lea si,mmb call mess noshowt: mov cs:[col],1eh lea si,bra2 call mess nobrac: pop di pop di add di,160 inc cs:[lineno] pop si mov ax,ds add ax,2 mov ds,ax pop cx loop show1 rewait: call waitkey cmp al,1 je endshow mov di,150 call hex2 mov bx,cs:[files] mov cx,cs:[start] cmp al,50h ;down jne loki1 cmp bx,24 jl rewait sub bx,24 cmp bx,cx jle rewait inc cs:[start] jmp lend loki1: cmp al,48h ;up jne loki2 cmp cx,0 je rewait dec cs:[start] jmp lend loki2: cmp al,49h ;pgup jne loki3 cmp cx,0 je rewait cmp cx,24 jae pgup1 mov cs:[start],0 jmp lend pgup1: sub cs:[start],23 jmp lend loki3: cmp al,51h ;pgdown jne loki4 sub bx,cx cmp bx,23 jle rewait cmp bx,23+23 jge pgdo1 mov bx,cs:[files] sub bx,24 mov cs:[start],bx jmp lend pgdo1: add cs:[start],23 jmp lend loki4: cmp al,4bh ; left jne loki5 cmp cs:[level],0 je rewait dec cs:[level] loki5: cmp al,4dh ;right jne loki6 inc cs:[level] jmp lend loki6: cmp al,14h ;Total jne loki7 xor byte ptr cs:[tag],1 jmp lend loki7: cmp al,21h ;files jne loki8 xor byte ptr cs:[tag],2 jmp lend loki8: cmp al,20h ;dirs jne loki9 xor byte ptr cs:[tag],4 jmp lend loki9: lend: jmp showit endshow: ret level db 0 checkno dw 0 lineno dw 0 mlevel db "Level ",0 link2 db "ÈÍÍÍ",0 ; ALT 200,205 link db "ÀÄÄÄ",0 start dw 0 mdir db " dirs, ",0 mfile db " files ",0 mtree db "Tree V0.4",0 md1 db "d=",0 md2 db " ,T=",0 bra1 db " (",0 bra2 db ")",0 mkb db "b",0 mmb db "mb ",0 mdot db ".",0 mcom db ",",0 current db "A:\" current1 db 64 dup(0) fileno dw 0 tdate db ??date,0 ttime db ??time,0 tag db 0ffh showtree endp stk equ $ cseg ends end begin