home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-386-Vol-2of3.iso / b / batdoor.zip / MORE_R.ZIP / MORE_R.ASM next >
Assembly Source File  |  1986-11-20  |  11KB  |  253 lines

  1. ;
  2. ; MORE_R: A remote MORE for DOORS users.
  3. ;
  4. ; Courtesy of: The BBS of Excellence (312)398-2872
  5. ;
  6. ; To make this program work under COM2: change DataReg to 2F8h
  7. ; and LineReg to 2FDh
  8. ;
  9. cseg    segment  byte public 'CODE'
  10.         assume   cs:cseg,ds:cseg,es:cseg
  11.         org      100h
  12. MORE_R  proc     near
  13.         jmp      MainCode   ; Skip over constant
  14. ;
  15. CInd     db      0          ; Indicator for "Continuous".
  16. CR_Counter dw    0          ; Carriage return counter
  17. Handle   dw      ?          ; Save area for file "handle"
  18. ASCIIZ   dw      ?          ; Addr of ASCIIZ
  19. DataReg  dw      3F8h       ; for COM1: 2F8h = COM2:
  20. LineReg  dw      3FDh       ; for COM1: 2fDh for COM2:
  21. ErrorMsg db      'Unable to open ',0
  22. MoreMsg  db      10,'More? [Y]es, [N]o, [C]ontinuous, [C/R=Yes]',0
  23. WaitMsg  db      13,10,'==[Press any key to continue]==',13,10,0
  24. DataArea db      257 dup(0)
  25. BadForm  db      13,7,10,'Format MUST be "TYPE_R drive:/subdir/filename"',13,10,0
  26. ;
  27. MainCode:
  28.         Call     ValidateEntry  ; Validate the Command line entry format
  29.         Call     OpenFile       ; Go Open the file
  30.         Call     ClearLine      ; Clear out the data in the line
  31.         Call     DisplayFile    ; Display the file
  32.         Call     CloseFile      ; Close the file
  33.         Int      20h            ; Terminate program
  34. MORE_R  endp
  35.  
  36. ValidateEntry  Proc    Near
  37.            mov     SI,80h          ; point to the command buffer
  38.            Xor     CX,CX           ; Init the loop counter
  39.            Mov     CL,[SI]         ; Get the input length
  40.            Cmp     CL,0            ; Was there no input ?
  41.            JZ      BadEntry        ; True...then abort
  42. SkipLoop:
  43.            Inc     SI              ; Point to the next byte
  44.            Mov     DL,[SI]         ; Get the character
  45.            Cmp     DL,' '          ; Is it Blank ?
  46.            Jnz     ByteFound       ; No...continue
  47.            Loop    SkipLoop        ; Else, keep on looking
  48. ByteFound:
  49.            Mov     ASCIIZ,SI       ; Save the pointer
  50.            Cmp     DL,97           ; Is it in lower case ?
  51.            Jb      UpperCase       ; No..don't change it
  52.            Sub     DL,32           ; Make it upper case
  53. UpperCase:
  54.            Cmp     DL,'A'          ; Is it Alpha ?
  55.            Jb      BadEntry        ; No...Abort
  56.            Cmp     DL,'E'          ; Is it too high ?
  57.            Ja      BadEntry        ; Yes..Abort
  58.            Inc     SI              ; Point to the colon
  59.            Mov     DL,[SI]         ; Get the character
  60.            Cmp     DL,':'          ; Is it a Colon ?
  61.            Jnz     BadEntry        ; No..Abort
  62.            Inc     SI              ; Point to the Slash
  63.            Mov     DL,[SI]         ; Get the character
  64.            Cmp     DL,'\'          ; Is it a slash ?
  65.            Jnz     BadEntry        ; No...Abort
  66. ;
  67. LoopToEnd:
  68.            Inc     SI              ; Skip to the next character
  69.            Mov     DL,[SI]         ; Get the character
  70.            Cmp     DL,13           ; End of the line ?
  71.            Jnz     LoopToEnd       ; No...keep on scanning
  72.            Xor     AL,AL           ; Init the work area
  73.            Mov     [SI],AL         ; Add an end-of-ASCIIZ indicator
  74.            Jmp     ExitValidation  ; Exit this routine
  75. BadEntry:
  76.           Lea      SI,BadForm      ; Point to the error message
  77.           Call     SendMsg         ; Send it
  78.           Int      20h        ; Abort processing
  79. ExitValidation:
  80.            Ret
  81. ValidateEntry    Endp
  82. ClearLine Proc Near
  83.            Mov     DX,DataReg      ; Point to the data
  84.            IN      AL,DX           ; Read a byte
  85.            IN      AL,DX           ; And the next one
  86. ClearLineLoop:
  87.            Mov     DX,LineReg      ; Get the Line Register address xFDh
  88.            In      AL,DX           ; Get the Line status
  89.            And     AL,1Fh          ; Isolate DR/OR/PE/FE/or BI active
  90.            OR      AL,AL           ; Are they there?
  91.            Jz      ExitReset       ; No...Exit to caller
  92.            Mov     DX,DataReg      ; Point to the data register
  93.            In      AL,DX           ; Reset data area
  94.            Jmp     ClearLineLoop   ; Keep clearing any data
  95. ExitReset:
  96. ClearLine Endp
  97. OpenFile  Proc   Near
  98.           Mov    DX,ASCIIZ  ; Point to the ASCIIZ string
  99.           Xor    AL,AL      ; No file protection
  100.           Mov    AH,61      ; Set up the command
  101.           Int    21h        ; Do the Open
  102.           Jc     CantOpen   ; If unable to open, tell the user
  103.           Mov    Handle,AX  ; Save the "handle"
  104.           Jmp    ExitOpen   ; Exit this routine
  105. CantOpen:
  106.           Lea    SI,ErrorMsg  ; Point to the error message
  107.           Call   SendMsg    ; Display the message
  108.           Int    20h        ; Terminate processing
  109. ExitOpen:
  110.           Ret               ; Return to the caller
  111. OpenFile  Endp
  112.  
  113. CloseFile Proc   Near
  114.           Mov    DX,Handle  ; Get the file handle
  115.           Xor    AX,AX      ; Init the work register
  116.           Mov    AH,62      ; Set up the command
  117.           Int    21h        ; Execute it
  118.           Ret               ; Return to caller
  119. CloseFile Endp
  120.  
  121. DisplayFile Proc Near
  122. DisplayLoop:
  123.           Call   ReadFile   ; Read some data
  124.           Or     AX,AX      ; End of file ?
  125.           Jz     ExitDisplay ; Yes...terminate
  126.           Lea    SI,DataArea ; Point to the data
  127.           Call   SendMsg     ; Display the data
  128.           Jmp    DisplayLoop ; Keep on displaying
  129. ExitDisplay:
  130.           Lea    SI,WaitMsg  ; Pause after last line
  131.           Call   SendMsg     ; Display message
  132.           Call   ReadByte    ; Wait for any response
  133.           Ret                ; Return to caller
  134. DisplayFile Endp
  135.  
  136. ReadFile  Proc   Near
  137.           Mov    BX,Handle  ; Get the file handle name
  138.           Lea    DX,DataArea  ; Point to the file area
  139.           Mov    CX,256     ; Read 256 bytes
  140.           Xor    AX,AX      ; Init the work register
  141.           Mov    AH,63      ; Set up the command
  142.           Int    21h        ; Execute it
  143.           Ret
  144. ReadFile  Endp
  145.  
  146. SendMsg   Proc   Near
  147. LineLoop:
  148.           Mov    AL,[SI]    ; Get the Character
  149.           Cmp    AL,0       ; End of the Line ?
  150.           Jz     ExitLine   ; Yes...exit
  151.           Cmp    AL,1Ah     ; End of file ?
  152.           Jz     ExitLine   ; Yes..exit
  153.           Call   SendByte   ; Else display the character
  154.           Inc    SI         ; Point to the next character
  155.           Jmp    LineLoop   ; And continue
  156. ExitLine:
  157.           Ret
  158. SendMsg   Endp
  159.  
  160. SendByte  Proc   Near
  161.           Push   AX              ; Save the byte
  162. WaitLineLoop:
  163.           Mov    DX,LineReg      ; Get the Line Register address xFDh
  164.           In     AL,DX           ; Get the Line status
  165.           And    AL,20h          ; Is the Xmit buffer empty ?
  166.           Cmp    AL,20h          ; Is it?
  167.           Jne    WaitLineLoop    ; No...Exit to caller
  168.           Pop    AX              ; Restore the byte
  169.           Mov    DX,DataReg ; Point to output port
  170.           Out    DX,AL      ; Output the character
  171.           Mov    DL,AL      ; Get the character
  172.           Mov    AH,2       ; Setup to output to video
  173.           Int    21h        ; Do it....
  174.           Cmp    AL,13      ; Is this a carriage return ?
  175.           Jnz    ExitByte   ; No...forget it
  176.           Mov    AL,CInd    ; Get the indicator
  177.           Or     AL,AL      ; Is it set ?
  178.           Jnz    ExitByte   ; Yes.. don't count
  179.           Mov    AX,CR_Counter  ; Get the number of C/R's
  180.           Inc    AX         ; Add 1 to the total
  181.           Mov    CR_Counter,AX  ;  save the total
  182.           Cmp    AX,24      ; Is this the 24th line ?
  183.           Jb     ExitByte   ; No...forget it
  184.           Xor    AX,AX      ; Init the counter
  185.           Mov    CR_Counter,AX  ; reset to zero
  186.           Push   SI         ; Save the pointer
  187.           Lea    SI,MoreMsg ; Get the request msg
  188.           Call   SendMsg    ; Display it
  189.           Pop    SI         ; restore the pointer
  190. WaitForReply:
  191.           Call   ReadByte   ; Get the response
  192.           Cmp    AL,'Y'     ; Continue?
  193.           Jz     ExitCR     ; Yes..exit with a C/R
  194.           Cmp    AL,13      ; Carriage return ?
  195.           Jz     ExitCR     ; Yes...exit with a C/R
  196.           Cmp    AL,'N'     ; No?
  197.           Jz     No_Response
  198.           Cmp    AL,'C'     ; Continuous ?
  199.           Jz     Cont       ; Yes..go set it up
  200.           Mov    AL,7       ; Get the bell
  201.           Call   Out        ; Make a noise
  202.           Jmp    WaitForReply ; Wait for good input
  203. Cont:
  204.           Mov    AL,1       ; Set up an indicator
  205.           Mov    CIND,AL    ; And save it
  206.           Jmp    ExitCR     ; Return to caller wit C/R          
  207. No_Response:
  208.           Lea    SI,WaitMsg ; tell Wait for a key to be pressed
  209.           Call   Sendmsg    ; Send that message
  210.           Call   ReadByte   ; Wait for a key pressed
  211.           Call   CloseFile  ; Close the file
  212.           Int    20h        ; Terminate processing
  213. ExitCR:
  214.           Mov    AL,13      ; C/R byte
  215.           Call   Out        ; Output it
  216. ExitByte:
  217.           Ret
  218. SendByte  Endp
  219.  
  220. ReadByte  Proc  Near
  221. Read_Byte_Wait:
  222.           Mov   DX,LineReg  ; Get the line register address
  223.           IN    AL,DX       ; Get the line status
  224.           AND   AL,01h      ; Isolate data ready bit
  225.           Cmp   AL,01H      ; Is there data ready?
  226.           Jz    Get_Remote_Byte  ; Yes..go read it
  227.           Mov   AH,1        ; Set up the status command
  228.           Int   16h         ; Check keyboard status
  229.           Jz    Read_Byte_Wait  ; If none pressed, wait
  230.           Xor   AH,AH       ; Init work reg for read
  231.           Int   16h         ; read the key
  232.           Jmp   WaitExit    ; Exit this routine
  233. Get_Remote_Byte:
  234.           Mov   DX,DataReg  ; Point to the data register
  235.           In    AL,DX       ; Get the byte
  236. WaitExit:
  237.           Cmp   AL,91       ; Is it upper case ?
  238.           Jb    FinalExit   ; Yes..don't translate
  239.           Sub   AL,32       ; Make Upper case
  240. FinalExit:
  241.           Ret
  242. ReadByte  Endp
  243. Out      Proc  near
  244.           Mov    DL,AL       ; Get the "beep" to output
  245.           Mov    AH,2       ; Set up routine
  246.           Int    21h        ; Sound off
  247.           Mov    DX,DataReg ; Get the modem register
  248.           Out    DX,AL      ; Output to the COMx: port
  249.           Ret               ; Return  to caller
  250. Out       Endp
  251. CSEG      Ends
  252.           End     MORE_R
  253.