"Fossies" - the Fresh Open Source Software Archive

Member "dosemu-1.4.0/src/commands/mgarrot.S" (4 May 2007, 6646 Bytes) of package /linux/misc/old/dosemu-1.4.0.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) PowerPC Assembler source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file.

    1 # 
    2 # All modifications in this file to the original code are
    3 # (C) Copyright 1992, ..., 2007 the "DOSEMU-Development-Team".
    4 #
    5 # for details see file COPYING.DOSEMU in the DOSEMU distribution
    6 #
    7 
    8 
    9 # This is MGARROT v0.1 
   10 #
   11 # (c) Ed Sirett 1995.  (ed@cityscape.co.uk)
   12 # Licensing agreements follow exactly those that apply to the 
   13 # dosemu (Linux Dos Emulator) source.
   14 #
   15 # This is designed to operate with the Linux Dos Emulator.
   16 #
   17 # The purpose of this program is to check the values returned from the mouse
   18 # and thus to dectect when the mouse is taking a break.
   19 # When we are sure the mouse is taking a break we invoke a 
   20 # dosemu internal function which will give up CPU time to the rest of the
   21 # system for a moment (but half eternity for most CPU's). 
   22 # 
   23 # This program must be loaded *after* your mouse device driver is loaded.
   24 # 
   25 
   26 #include "macros86.h"
   27 
   28 .code16
   29 .text
   30     .globl  _start16
   31 _start16:
   32 
   33 DosInt      = 0x21#         
   34 MouseInt    = 0x33#
   35 EmuInt      = 0xe6#
   36 PrintFun    = 0x09#   AH= for print line function.
   37 PollFun     = 0x03#        AX= for mouse get buttons and posn.
   38 MGarrot     = 0x28#        AX= for emu mouse helper.
   39 InqSubFun       = 0x01#     BX= for emu get hogthreshold.
   40 WaitSubFun      = 0x00#     BX= for emu wait a bit.
   41 SaveMouse       = 0x3533#     ES:BX is old mouse handler
   42 SetMouse        = 0x2533#     new mouse handler is DS:DX
   43 ExitFailure     = 0x4C01#   Function for exit with RC=1
   44 FreeFun     = 0x4900#   Function for deallocate memory.
   45 TSRFun      = 0x3100#     Function for go TSR with DX paragraphs retained.
   46 
   47     jmp check_start # 'jmp near check_start', Go to the initializtion section.
   48 
   49 # Storage for the far pointer to the mouse driver.
   50 MouseDriver:    .word 0      # Offset Storage
   51 MouseDriverSeg: .word 0          # Segment Storage
   52 OldXPos:       .word 0           # Saved values of X and Y mouse pos.
   53 OldYPos:       .word 0       # 
   54 Trigger:       .word 0           # The number of times we have got consequetive 
   55 HogValue:      .word 0           # calls to the mouse Poll function.
   56 MouseFunction: .word 0           # Saved value of AX before call to MouseDriver
   57 
   58 
   59 # This routine receives calls from the mouse interrupt (0x33)
   60 OurMouseISR:
   61         movw  %ax,%cs:MouseFunction  # Save AX for future reference.
   62 # Call the old interrupt handler (mouse driver). Now this has to be done 
   63 # as if we were interrupting to the old handler so we must push the flags
   64 # (they will be popped by the IRET in the handler). CLI is in force
   65 # and will continue to be so.
   66         pushf
   67         lcall   INDIRECT_PTR(%cs:MouseDriver)
   68 # Save DS and set it to our CS
   69         pushw %ds    # save the old DS 
   70         pushw %cs      # This PUSH/POP needed since no MOV DS,CS
   71         popw  %ds    # DS now same as CS
   72 # Because some programs call various other functions as much as #3
   73 # we just ignore them. 
   74 # We are only interested in looking at the returned values if the 
   75 # mouse function was 3 (Get Buttons and Position)
   76         cmpw $PollFun,MouseFunction # Is it the Polling function.
   77         jne Done    # It is not so we go home.
   78 # Firstly the mouse buttons must be all up. 
   79         test %bx,%bx         # If the buttons are not all up  
   80         jne Reset   # we have to start over again.
   81 # Has the mouse moved?
   82         cmpw %cx,OldXPos # Test the X position
   83         jne Reset     # Start over again if it has
   84         cmpw %dx,OldYPos # Test Y Likewise
   85         jne Reset     #
   86         incw Trigger    # Increment the trigger value.
   87         pushw %ax              # Save AX register
   88         movw HogValue, %ax# and load it with the Hogthreshold value.
   89         cmp Trigger,% ax# Have we reached the threshold?
   90         jge TakeABreak    # OK we have reached the value. 
   91         popw %ax          # We haven't so restore AX and go home.
   92         jmp Done      #
   93 TakeABreak:     pushw %bx         # Save BX also.
   94         movw $WaitSubFun, %bx # Request dosemu to  give us a break#
   95         movw $MGarrot, %ax    # 
   96         int $EmuInt   # Take a nap.
   97         popw %bx          # Restore saved regs.    
   98         popw %ax          # 
   99         jmp ResetTrigger  # Reset trigger value only.
  100 Reset:      movw %cx,OldXPos  # Reset by
  101         movw %dx,OldYPos  # saving current Mouse position
  102 ResetTrigger:   movw $0, Trigger  # Start counting (again).                         
  103 Done:       popw %ds             # restore the old DS.
  104         iret
  105 #---------------------------------------------------------------------------
  106 GoTSR:      int $DosInt#   Do the TSR call function.
  107 EndOfTsrSection:
  108  
  109 #===========================================================================
  110 NoDosEmuMsg:   .ascii "Not running under the Linux Dos Emulator - Mouse Garrot not installed.$"
  111 NoHogValue:    .ascii "Hogthreshold Value is 0 in dosemu.conf  - Mouse Garrot no installed.$"
  112 InstallMsg:    .ascii "Mouse Garrot v 0.1 installed.$"
  113 
  114 /* In the Setup section we do the following: 
  115 #  1) Check that we are running in dosemu not some other real or emulated 
  116 #  environment. 
  117 #  2) Obtain the hogthreshold for dosemu and check that it is >0. 
  118 #  3) Install our mouse-interrupt handler.
  119 #  4) Issue message.
  120 #  5) Go TSR.
  121 */
  122 Start:
  123     movw $MGarrot,%ax#    Setup to ask dosemu what is the hogthreshold
  124     movw $InqSubFun,%bx#  dosemu will set *both* AX and BX to the value
  125     int $EmuInt#        that way we can be sure that dosemu has responded.
  126 # Check for dosemu.
  127     movw $NoDosEmuMsg, %dx
  128 # Move message in case of failure.
  129     cmp %bx,%ax     # If AX<>BX then no dosemu.
  130     jne RunDown
  131     movw %ax, HogValue     # Save the actual hog value.
  132         movw $NoHogValue, %dx  # Move message in case of failure.
  133         test %ax,%ax           # Complain if dosemu not configured with hog value.
  134     jz  RunDown         # 
  135 # To save the old handler we can use DOS function 35
  136         movw $SaveMouse,%ax
  137         int $DosInt            # Now ES:BX holds the mouse driver.
  138         movw %bx, MouseDriver  # Save for future reference.
  139         movw %es, MouseDriverSeg# 
  140 # Now set the handler to us.
  141     movw $SetMouse, %ax    # Set the handler to DS:DX (DS already correct)
  142     movw $OurMouseISR, %dx
  143     int $DosInt    # 
  144 # Time to tell the user that all is well
  145     movb $PrintFun,%ah
  146     movw $InstallMsg,%dx
  147     int $DosInt#
  148 # Deallocate Program's environment block.
  149     movw 0x2C,%ax    #  Apparently the environment block is stored
  150         movw %ax, %es        # at this location which is now in ES.
  151     movw $FreeFun, %ax   # 
  152     int $DosInt   # 
  153 # Now we are about to go TSR but we need to retain the TSR code.
  154     movw    $TSRFun, %ax      # 
  155     movw    $EndOfTsrSection, %dx
  156     addw    $15,%dx
  157     shrw    $4,%dx  # Number of Paras to retain.
  158     jmp GoTSR   # I have a suspicion that we have to go TSR from
  159               # within the memory that will be retained.
  160               # Hence this jump to within the retained part.
  161 #============================================================================
  162 RunDown: movb $PrintFun, %ah # 
  163      int $DosInt#
  164      movw $ExitFailure, %ax
  165      int $DosInt#
  166 
  167 check_start:
  168 #include "detect.h"
  169     jmp Start