TITLE PGM19_1.ASM: DISPLAY FILE
; From Textbook
.MODEL  SMALL
.STACK 100H
.DATA
PROMPT    DB 'FILENAME:$'
FILENAME  DB  30 DUP (0)
BUFFER    DB  512 DUP(0)
HANDLE    DW  ?
OPENERR   DB  13,10,'OPEN ERROR-CODE'
ERRCODE   DB  30H,'?'
.CODE
MAIN PROC
   MOV AX,@DATA
   MOV DS,AX
   MOV ES,AX
   CALL GET_NAME
   LEA DX,FILENAME
   MOV AL,0
   CALL OPEN
   JC OPEN_ERROR
   MOV HANDLE,AX
READ_LOOP:
   LEA  DX,BUFFER
   MOV  BX,HANDLE
   CALL READ
   OR AX,AX
   JE EXIT
   MOV CX,AX
   CALL PLAY
   JMP READ_LOOP
OPEN_ERROR:
   LEA DX,OPENERR
   ADD ERRCODE,AL
   MOV AH,9
   INT 21H
EXIT:
   MOV BX, HANDLE
   CALL CLOSE
   MOV AH,4CH
   INT 21H
MAIN ENDP


GET_NAME PROC NEAR
;reads and stores filename
;input none
;output:filename stored as ASCII string
   PUSH AX
   PUSH DX
   PUSH DI
   MOV  AH,9
   LEA  DX,PROMPT
   INT  21H
   CLD
   LEA DI,FILENAME
   MOV AH,1
READ_NAME:
   INT 21H
   CMP AL,13
   JE DONE
   STOSB
   JMP READ_NAME
DONE:
   MOV AL,0
   STOSB
   POP DI
   POP DX
   POP AX
   RET
GET_NAME ENDP
OPEN PROC NEAR
;opens file
   MOV AH,3DH
   MOV AL,0
   INT 21H
   RET
OPEN ENDP

READ PROC NEAR
;reads a file sector
   PUSH CX
   MOV AH,3FH
   MOV CX,512
   INT 21H
   POP CX
   RET
READ ENDP

PLAY PROC NEAR
;displays memory om screen
  PUSH BX
  MOV AH,40H
  MOV BX,1
  INT 21H
  POP BX
  RET
PLAY ENDP

CLOSE PROC NEAR
;closes a file
   MOV AH,3EH
   INT 21H
   RET
CLOSE ENDP


  END MAIN

