.model USE16 small .386 ; ; This implementation is a mix of 8086 and 386 assembly. It runs under ; MSDOS on an Ibm PC (386 or better) and a color VGA monitor is assumed. ; ; Usage: ; dump filename ; ; ESC gets you out, PGUP/PGDOWN shift you to other pages to view ; ; Time spent: 1 hr, 45 minutes ; David Lindauer, gclind01@ulkyvx.louisville.edu ; ; DOS functions DOSSTRING = 9 DOSOPEN = 3dh DOSCLOSE = 3eh DOSREAD = 3fh DOSMFP = 42h MFPBEGIN = 0 MFPEND = 2 DOSEXIT = 4ch DOSINT = 21h ; ; ASCII chars CR = 13 LF = 10 ; ; VIDEO BIOS ; VMODE = 3 VIDEOBIOS = 10h BYTESPERROW = 160 ; ; KEYBOARD BIOS ; KEYGET = 0 KEYBIOS = 16h ; ; Screen defs ; NUMBYTES = 384 ROWS = 24 COLS = 16 ; ; Keys we trap ; ESCAPE = 011bh PGUP = 4900h PGDOWN = 5100h ; ; PRgram PSP defs ; psp segment USE16 public word 'PSP' AT 0 org 80h count db ? cline db 07fh DUP (?) psp ends ; ; Video display ; screen segment USE16 public word 'SCREEN' AT 0b800h screen ends .stack .data filepos dd 0 ; Position in file filend dd 0 ; Length of file handle dw 0 ; File handle rowpos dw 0 ; Screen row * 160 colpos dw 0 ; Screen col * 2 buffer db NUMBYTES DUP (0) ; File buffer error_fnf db "File Not Found",CR, LF, '$' error_read db "error on file read", CR, LF, '$' error_mfp db "Error on file seek", CR,LF,'$' filename db 40 DUP (?) .code assume ds:psp,es:dgroup ; ; Skip through spaces in the command line ; skipspace proc lodsb cmp al,' ' jz skipspace dec si ret skipspace endp ; ; Take the first command line arg and move it to the filename buffer ; movetospace proc cmp byte ptr [si],' ' jz short mts_done cmp byte ptr [si],',' jz short mts_done cmp byte ptr [si],0 jz short mts_done movsb jmp movetospace mts_done: mov byte ptr es:[di],0 ret movetospace endp assume ds:dgroup,fs:screen ; ; Use BIOS to clear screen ; clearscreen proc mov ax,VMODE int VIDEOBIOS ret clearscreen endp ; ; Errors close file and clear screen and print error message ; error proc push dx call close pop dx error1: call clearscreen mov ah,DOSSTRING int DOSINT mov ah,DOSEXIT int DOSINT error endp ; ; Open the file and get its length ; open proc mov ah,DOSOPEN mov al,0 mov dx,offset filename int DOSINT jc op_error mov [handle],ax sub dx,dx sub cx,cx mov bx,ax mov ah,DOSMFP mov al,MFPEND mov bx,[handle] int DOSINT jc op_error2 shl edx,16 mov dx,ax mov [filend],edx ret op_error: mov dx,offset error_fnf jmp error1 op_error2: mov dx,offset error_mfp jmp error open endp ; ; Close the file ; close proc mov ah,DOSCLOSE mov bx,[handle] int DOSINT ret close endp ; ; Position the file pointer and read from the file ; read proc mov di,offset buffer mov cx,NUMBYTES sub al,al rep stosb mov edx,[filepos] mov ecx,edx shr ecx,16 mov ah,DOSMFP mov al,MFPBEGIN mov bx,[handle] int DOSINT jc read_error mov cx,NUMBYTES mov dx,offset buffer mov ah,DOSREAD mov bx,[handle] int DOSINT jc read_error ret read_error: mov dx,offset error_read jmp error read endp ; ; Misc number prints ; printhword proc push eax shr eax,16 call printbyte pop eax push eax mov al,ah call printbyte pop eax printbyte: push ax shr al,4 call printnib pop ax printnib: and al,0fh add al,'0' cmp al,'9' jbe printchar add al,7 printchar: mov di,[rowpos] add di,[colpos] mov fs:[di],al add [colpos],2 ret printhword endp ; ; Print a space ; printspace proc mov al,' ' jmp printchar printspace endp ; ; Show the data buffer on the screen in the specified format ; show proc call clearscreen mov [rowpos],-BYTESPERROW mov cx,ROWS mov si,offset buffer sl3: push cx add [rowpos],BYTESPERROW mov [colpos],0 movzx eax,si sub ax,offset buffer add eax,[filepos] call printhword mov al,':' call printchar call printspace call printspace push si mov cx,COLS sl1: lodsb call printbyte call printspace loop sl1 call printspace call printspace pop si mov cx,16 sl2: lodsb call printchar loop sl2 pop cx loop sl3 ret show endp ; ; Look for one of the keys we use ; getkey proc mov ah,KEYGET int KEYBIOS cmp ax,ESCAPE jz gotkey cmp ax,PGUP jz gotkey cmp ax,PGDOWN jnz getkey gotkey: ret getkey endp ; ; Main user interface routine ; Responsible for handling keys, reading data from file, showing it on screen ; ui proc mov [filepos],0 uilp: call read call show uilp2: call getkey cmp ax,ESCAPE jz uiend cmp ax,PGUP jnz pgdwn cmp [filepos],0 jz uilp2 mov edx,[filepos] sub edx,NUMBYTES mov [filepos],edx jmp uilp pgdwn: mov edx,[filepos] add edx,NUMBYTES cmp edx,[filend] jnc uilp2 mov [filepos],edx jmp uilp uiend: ret ui endp ; ; Main program - calls other routines as necessary ; start proc assume ds:psp mov ax,dgroup mov es,ax mov di,offset filename movzx ecx,[count] mov esi,offset cline mov byte ptr [esi + ecx],0 cld call skipspace call movetospace assume ds:dgroup mov ax,dgroup mov ds,ax mov ax,screen mov fs,ax call open call ui call close call clearscreen mov ah,DOSEXIT int DOSINT start endp end start