home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / COMM / MISC / PHONRING.ZIP / PHONRING.ASM next >
Encoding:
Assembly Source File  |  1991-03-16  |  7.4 KB  |  305 lines

  1. PAGE    58,132
  2. TITLE    PHONRING    3-16-91    [3-16-91]
  3.  
  4. ;v0.1 Obtained as a DEBUG script from Fido's Technical Echo.
  5. ;v0.2 Toad Hall Disassembly, tweak
  6. ;
  7. ;David Kirschbaum
  8. ;Toad Hall
  9. ;kirsch@usasoc.soc.mil
  10.  
  11. BACKWARDS    EQU    0
  12.  
  13. LF    EQU    0AH
  14. CR    EQU    0DH
  15. ;
  16. CSEG    SEGMENT
  17.     ASSUME DS:CSEG, SS:CSEG ,CS:CSEG ,ES:CSEG
  18.     org    2CH            ;v0.2
  19. envseg    label    word            ;our environment seg        v0.2
  20.  
  21.     ORG    100H
  22.  
  23. PhonRing    proc    near
  24.     JMP    Install_1EB
  25.  
  26. oldInt8_103    dd    0        ;saved Int 8 vector
  27. wcommnr_107    dw    0        ;port number (0..3)
  28. wport109    DW    0        ;port address (base+6)
  29. bhotkey10B    DB    0        ;1 if hotkey pressed
  30. bflag10C    DB    0        ;1 if buzzer is on
  31. bstat10D    DB    0        ;save Port 61H status
  32. ctrlrbytes_10E    DB    51H,0DH        ;constants for stuffing ctrlr
  33. freeseg_110    DW    Install_1EB    ;first free segment        v0.2
  34.  
  35. PhonRing    endp
  36.  
  37. ;Every clock tick
  38. NewInt8_112    proc    far
  39.     PUSHF
  40.     PUSH    AX
  41.     PUSH    DX
  42.     MOV    AH,2            ;Get shift status
  43.     INT    16H            ;via BIOS
  44.     TEST    AL,8            ;Alt depressed?
  45.     JZ    Check_ScrollLock_125    ;nope
  46.     TEST    AL,1            ;Right shift depressed?
  47.     JZ    Check_ScrollLock_125    ;nope
  48.     TEST    AL,2            ;Left shift depressed?
  49.     JNZ    Uninstall_15B        ;yep, that's our uninstall combo
  50.  
  51. ;Scroll Lock depressed activates our demon
  52. Check_ScrollLock_125:
  53.     AND    AL,10H            ;mask to max bit 4
  54.     SHR    AL,1            ;looking for the bit 4
  55.     SHR    AL,1            ;(scroll lock)
  56.     SHR    AL,1
  57.     SHR    AL,1
  58.     MOV    CS:bhotkey10B,AL    ;save scroll lock bit as hotkey flag
  59.  
  60.     CMP    CS:bflag10C,1        ;have we been buzzing?
  61.     JNZ    Skp13E            ;nope
  62.      CALL    Buzzer_Off_1CB        ;yep, turn the buzzer off
  63. Skp13E:    CMP    CS:bhotkey10B,1        ;hotkey pressed?
  64.                     ;Scroll Lock *off* enables us
  65.     JZ    Jmp_OldInt8        ;yep, on to old Int 8
  66.  
  67.     MOV    DX,CS:wport109        ;our comm port status address
  68.     IN    AL,DX            ;read the port status
  69.     TEST    AL,40H            ;ringing?
  70.     JZ    Jmp_OldInt8        ;nope
  71.      CALL    Buzzer_On_1B6        ;yep, clear that ring status,
  72.                     ;buzzer on
  73. Jmp_OldInt8:
  74.     POP    DX
  75.     POP    AX
  76.     POPF
  77.     JMP    DWORD PTR CS:oldInt8_103    ;on to old Int 8 code
  78.  
  79. ;Uninstall ourselves after Hotkey combination
  80. Uninstall_15B:
  81.     PUSH    BX
  82.     PUSH    CX
  83.     PUSH    DS
  84.     PUSH    ES
  85.     CALL    Buzzer_Off_1CB            ;buzzer off
  86.  
  87. ;We have to see if we're the last program in memory
  88. ;before we can release ourselves and terminate.
  89.  
  90.     MOV    AX,CS:freeseg_110    ;first free seg beyond our program
  91.     MOV    BL,10H
  92.     DIV    BL
  93. ;v0.2    CMP    AH,0
  94.     or    ah,ah            ;msb clear?            v0.2
  95.     JZ    Skp170            ;yep
  96.      INC    AX            ;nope, bump AL
  97. Skp170:    XOR    AH,AH            ;clear msb
  98. ;v0.2    PUSH    CS
  99. ;v0.2    POP    BX
  100.     mov    bx,CS            ;larger, but faster        v0.2
  101.     ADD    BX,AX            ;our CSEG, + that AL value
  102.     MOV    DS,BX            ;make it DSEG
  103.     CMP    BYTE PTR DS:0,5AH    ;'Z'    memory free??
  104.     JNZ    Pop_Jmp8_1B0        ;nope, on to old Int 8
  105.  
  106. ;Anyone else stolen Int 8's vector since us?
  107. ;v0.2    MOV    AL,8
  108. ;v0.2    MOV    AH,35H    ;'5'
  109.     mov    ax,3508H        ;Get Int 8 vector        v0.2
  110.     INT    21H
  111.     MOV    BX,ES            ;save segment
  112. ;v0.2    PUSH    CS
  113. ;v0.2    POP    AX
  114.     mov    ax,CS
  115.     CMP    AX,BX            ;is Int 8 vector pointing to US?
  116.     JNZ    Pop_Jmp8_1B0        ;nope, on to old Int 8
  117.  
  118. ;It's safe to put everything back and terminate
  119.     CLI
  120. ;v0.2    MOV    DS,word ptr CS:oldInt8_103 + 2
  121. ;v0.2    MOV    DX,word ptr CS:oldInt8_103
  122. ;v0.2    MOV    AH,25H    ;'%'
  123. ;v0.2    MOV    AL,8
  124.     lds    dx,CS:oldInt8_103    ;old Int 8 vector        v0.2
  125.     mov    ax,2508H        ;set Int 8 vector back        v0.2
  126.     INT    21H
  127.  
  128.     STI
  129.     MOV    AH,49H            ;free allocated memory
  130.     PUSH    CS
  131.     POP    ES
  132.     INT    21H
  133.     CALL    Buzzer_On_1B6        ;turn buzzer on
  134.     MOV    CX,0FFFFH        ;a delay value
  135. Delay_1AB:
  136.     LOOP    Delay_1AB        ;delay a bit
  137.     CALL    Buzzer_Off_1CB        ;buzzer off
  138. Pop_Jmp8_1B0:
  139.     POP    ES
  140.     POP    DS
  141.     POP    CX
  142.     POP    BX
  143.     JMP    SHORT    Jmp_OldInt8    ;on to orig Int 8 code
  144.  
  145. NewInt8_112    endp
  146.  
  147.  
  148. Buzzer_On_1B6    proc    near
  149.     IN    AL,61H            ;read chip
  150.     MOV    CS:bstat10D,AL        ;save status
  151.     MOV    CS:bflag10C,1        ;flag buzzer on
  152.     MOV    DX,word ptr CS:ctrlrbytes_10E    ;lsb, msb to reset cntrlr ?
  153.     CALL    Reset_Ctrlr_1D8        ;reset interrupt controller?
  154.     RET    ;_NEAR
  155. Buzzer_On_1B6    endp
  156.  
  157.  
  158. Buzzer_Off_1CB    proc    near
  159. ;Turns buzzer off
  160.     MOV    CS:bflag10C,0        ;flag buzzer off
  161.     MOV    AL,CS:bstat10D        ;get old value
  162.     OUT    61H,AL            ;reset chip
  163.     RET    ;_NEAR
  164. Buzzer_Off_1CB    endp
  165.  
  166.  
  167. ;Reset int controller? Internal modem? Sound chip?
  168. Reset_Ctrlr_1D8    proc    near
  169.     MOV    AL,0B6H
  170.     OUT    43H,AL
  171.     MOV    AX,DX
  172.     OUT    42H,AL            ;lsb
  173.     MOV    AL,AH
  174.     OUT    42H,AL            ;msb
  175.     IN    AL,61H
  176.     OR    AL,3
  177.     OUT    61H,AL            ;reset
  178.     RET    ;_NEAR
  179. Reset_Ctrlr_1D8    endp
  180.  
  181.  
  182. Install_1EB    proc    near
  183.  
  184.     CALL    Buzzer_On_1B6        ;clear modem status of any ring,
  185.                     ;buzzer on
  186.     MOV    CX,0FFFFH        ;delay value
  187. Delay_1F1:
  188.     LOOP    Delay_1F1        ;delay a bit
  189.  
  190.     CALL    Buzzer_Off_1CB        ;turn buzzer off
  191.  
  192.     MOV    SI,80H            ;PSP cmdline
  193.     CLD
  194.     LODSB                ;cmdline length
  195.     CMP    AL,2            ;min 2 chars
  196.     JB    Usage_Term_21A        ;not enough, usage, die
  197.  
  198. CmdLup_1FF:
  199.     LODSB
  200.     CMP    AL,0DH            ;CR terminates cmdline
  201.     JZ    Usage_Term_21A        ;usage, die
  202.  
  203.     CMP    AL,20H    ;' '
  204.     JZ    CmdLup_1FF        ;gobble spaces
  205.     CMP    AL,'1'
  206.     JB    CmdLup_1FF        ;below legals
  207.     CMP    AL,'4'
  208.     JA    CmdLup_1FF        ;above legals
  209.     SUB    AL,'1'            ;deasciify
  210.     XOR    AH,AH            ;clear msb
  211.     MOV    CS:wcommnr_107,AX    ;save port nr as word
  212.     JMP    SHORT    L0223
  213.  
  214. Usage_Term_21A:
  215.     MOV    DX,OFFSET usage$283    ;Intro msg, usage
  216. Msg_Term:                ;common code            v0.2
  217.     MOV    AH,9            ;display msg
  218.     INT    21H
  219.     INT    20H            ;terminate
  220.  
  221. L0223:    MOV    SI,wcommnr_107        ;port nr
  222.     SHL    SI,1            ;*2 for words
  223.     MOV    AX,40H            ;BIOS data area
  224.     MOV    DS,AX            ;into DS
  225.     MOV    DX,[SI]            ;snarf current COMx port address
  226.     PUSH    CS
  227.     POP    DS            ;restore DS
  228. ;v0.2    Old code
  229. ;v0.2    CMP    DX,0
  230. ;    JZ    PortProb_240        ;yep, not assigned
  231. ;
  232. ;    ADD    DX,6            ;bump to status port???
  233. ;    MOV    wport109,DX        ;save as port address
  234. ;    JMP    SHORT    GoTsr_249
  235. ;
  236. ;PortProb_240:
  237. ;v0.2    New code:
  238.     or    dx,dx            ;port not assigned?        v0.2
  239.     jnz    GoTsr_249        ;nope, assigned, continue    v0.2
  240.                     ;else fall thru to...        v0.2
  241. ;v0.2    MOV    AH,9            ;display msg
  242.     MOV    DX,OFFSET initprob$41A    ;'Problem initializing port'
  243. ;v0.2    INT    21H
  244. ;v0.2    INT    20H            ;terminate
  245.     jmp    Msg_Term        ;display msg, terminate        v0.2
  246.  
  247. GoTsr_249:
  248. ;v0.2    New code:
  249.     add    dx,6            ;bump to status port        v0.2
  250.     mov    wport109,dx        ;save as port address        v0.2
  251.  
  252. ;v0.2    MOV    AL,8
  253. ;v0.2    MOV    AH,35H
  254.     mov    ax,3508H        ;get Int 8 vector        v0.2
  255.     INT    21H
  256.     MOV    word ptr CS:oldInt8_103 +2,ES    ;save seg
  257.     MOV    word ptr CS:oldInt8_103,BX    ;and offset
  258.     MOV    DX,OFFSET NewInt8_112        ;our new Int 8 svc
  259. ;v0.2    MOV    AL,8
  260. ;v0.2    MOV    AH,25H    ;'%'
  261.     mov    ax,2508H        ;set new Int 8 vector
  262.     INT    21H
  263.  
  264. ;v0.2    MOV    BX,OFFSET portnr_416    ;'com1' string
  265. ;v0.2    MOV    AX,wcommnr_107        ;our port value
  266. ;v0.2    ADD    [BX],AL            ;bump to 'com2', etc.
  267.     mov    al,byte ptr wcommnr_107    ;our port value            v0.2
  268.     add    portnr_416,al        ;bump 'com1' to 'com%'        v0.2
  269.  
  270.     MOV    DX,OFFSET msg3DE    ;'PhonRing resident..'
  271.     MOV    AH,9            ;display msg
  272.     INT    21H
  273. ;v0.2    MOV    AX,DS:2CH    ;','
  274. ;v0.2    MOV    ES,AX
  275.     mov    ES,envseg        ;PSP environment seg        v0.2
  276.     MOV    AH,49H            ;free environment
  277.     INT    21H
  278.     MOV    DX,OFFSET Install_1EB    ;use install code as buffer
  279. ;v0.2    MOV    freeseg_110,DX        ;pointer to first free seg
  280.     INT    27H            ;release memory from DX, go TSR
  281.  
  282. Install_1EB    endp
  283.  
  284. usage$283    DB    CR,LF
  285. ;DB ' Phonring.com  v0.1  03/10/91   '
  286. db ' Phonring v0.2  03/15/91   '        ;v0.2
  287. db 'Monitor phone-ring via modem and beep speaker',CR,LF
  288. DB '  (c) Copyright 1991 by Bruce Desmond (1:203/6.9) - All rights reserved.'
  289. db CR,LF,CR,LF
  290. DB ' Syntax:  Phonring.com  [port#] ',CR,LF,CR,LF
  291.  
  292. DB ' [port#] = # of serial port with modem/phone line. 1,2,3,4 are valid.'
  293. db CR,LF,CR,LF
  294. DB ' Scroll-lock: on=disable off=enable    '
  295. db 'Alt+LShift+RShift unloads if possible.',CR,LF,'$'
  296.  
  297. msg3DE    DB    CR,LF
  298.     DB    9,'PhonRing resident and watching for phone rings on com'
  299. portnr_416    DB    '1'
  300.         db    CR,LF,'$'
  301. initprob$41A    DB    CR,LF,9,'Error: Problem initializing modem',CR,LF,'$'
  302.  
  303. CSEG    ENDS
  304.     END    PhonRing
  305.