home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / MISC / POKE_10.ZIP / POKE.ASM < prev    next >
Encoding:
Assembly Source File  |  1991-12-27  |  6.9 KB  |  281 lines

  1. ;******** Dummy block device **********
  2.  
  3. TITLE    Poke memory locations
  4.  
  5. ; Called as a driver, this program always fails to install, i e it consumes no
  6. ; memory. Alternatively, it may be called upon as a normal program.
  7. ; Usage: A>POKE outaddr val [val ...] [outaddr val ...] [; comment]
  8. ; or:    DEVICE=POKE.COM outaddr val [val ...] [outaddr val ...] [comment]
  9. ; outaddr may be either seg:addr (memory address) or Oaddr (I/O address).
  10. ; All values are in hex, and val is considered a byte if its written as
  11. ; 2 or less digits, or word if its written as 3 or more digits.
  12. ; val may also be seg@ofs [Ln] to copy data
  13.  
  14. ; Example use:
  15. ;
  16. ;    DEVICE=POKE.COM 40:17 0    ; Switch off Num Lock bit (among others)
  17. ;    C:>POKE 50:0 1        ; Disable PrintScreen function
  18. ;    C:>POKE 40:4 3E8    ; Install COM3 BIOS address
  19. ;    C:>POKE 40:78 2        ; Change LPT1 timeout
  20.  
  21. ; Released to the Public Domain by Dan Norstedt 1991
  22.  
  23. ; Version 1.0
  24.  
  25. CODE    SEGMENT    BYTE
  26.  
  27.     ASSUME CS:CODE,DS:NOTHING
  28.  
  29.     ORG    100H
  30.  
  31. STACOM: JMP    Short INITCO
  32. ;-----------------------------------------------
  33. ;
  34. ;    A D J M E M - Dummy block device driver
  35. ;
  36. ;    DW    -1            ; Header
  37. MEMDEV    EQU    $-2
  38.     DW    -1
  39.     DW    0000000000000000B    ; No options
  40.     DW    STRAT-100H
  41.     DW    ENTRY-100H
  42.     DB    0            ; No devices to install
  43.  
  44. ;---------------------------------------------------
  45. ;
  46. ;    Device entry point
  47. ;
  48. CMDLEN    =    0    ;Length of this command
  49. UNIT    =    1    ;Sub unit specifier
  50. CMD    =    2    ;Command code
  51. STATUS    =    3    ;Status
  52. MEDIA    =    13    ;Media descriptor
  53. TRANS    =    14    ;Transfer address
  54. COUNT    =    18    ;Count of blocks or characters
  55. STABLK    =    20    ;First block to transfer
  56.  
  57. PTRSAV    DD    0        ; Storage for device driver packet
  58. INIFLG    DB    1        ; Flag set only for first entry
  59.  
  60. INITCO:    MOV    SI,81H        ; Normal program entry
  61.     MOV    BL,[SI-1]
  62.     MOV    BH,0
  63.     MOV    [SI+BX],BH    ; Make command line ASCIIZ
  64.     PUSH    CS
  65.     CALL    Near Ptr MAIN    ; Process
  66.     MOV    AH,4CH
  67.     INT    21H        ; Terminate
  68.  
  69. STRAT    PROC    FAR
  70.     SHR    BYTE PTR CS:[INIFLG-100H],1 ; First entry?
  71.     JNC    STRATI
  72.     MOV    WORD PTR CS:[MEMDEV-100H],-1 ; Yes, patch device header link
  73. STRATI:    MOV    WORD PTR CS:[PTRSAV-100H],BX
  74.     MOV    WORD PTR CS:[PTRSAV-100H+2],ES ; Save packet address
  75.     RET
  76. STRAT    ENDP
  77.  
  78. ENTRY    PROC    FAR
  79.     PUSH    BX
  80.     PUSH    DS
  81.     LDS    BX,CS:[PTRSAV-100H]     ; Get pointer to I/O packet
  82.     CMP    BYTE PTR [BX].CMD,0    ; Command init ?
  83.     JZ    INIT            ; Yes, do that
  84.     MOV    WORD PTR [BX].STATUS,8103H ; No, mark error unknown command
  85.     POP    DS
  86.     POP    BX
  87.     RET                ; Restore regs and return
  88. ENTRY    ENDP
  89.  
  90. INIT    PROC    FAR
  91.     PUSH    AX            ; Save regs
  92.     PUSH    DX
  93.     PUSH    SI
  94.     LDS    SI,DWORD PTR [BX].COUNT    ; Find address of command line
  95. INITLO:    LODSB                ;  i e skip over "POKE.COM" name
  96.     CMP    AL,20H
  97.     JA    INITLO
  98.     DEC    SI            ; Save remaining register
  99.     PUSH    BP
  100.     PUSH    DI
  101.     PUSH    CX
  102.     PUSH    CS            ; Make up for a far return
  103.     CALL    STADRV
  104.     POP    CX
  105.     POP    DI
  106.     POP    BP
  107.     POP    SI
  108.     LDS    BX,CS:[PTRSAV-100H]    ; Reload pointer
  109.     MOV    BYTE PTR [BX].MEDIA,0    ; Set no of units to 0
  110.     MOV    WORD PTR [BX].TRANS,0    ; Set end address to CS:0 
  111.     MOV    [BX].TRANS+2,CS        ;  to skip install
  112.     MOV    WORD PTR [BX].STATUS,00000001B    ; Mark operation complete
  113.     POP    DX
  114.     POP    AX
  115.     POP    DS
  116.     POP    BX
  117.     RET                ; Restore regs and return
  118. INIT    ENDP
  119.  
  120. STADRV:    MOV    AX,CS            ; This is not a real procedure, just
  121.     SUB    AX,10H            ;  a way to set up proper CS:IP for 
  122.     PUSH    AX            ;   the main routine
  123.     MOV    AX,Offset MAIN
  124.     PUSH    AX
  125. STADRX    PROC    FAR
  126.     RETF
  127. STADRX    ENDP
  128.  
  129. ;------------------------------------------- Real part of program starts here
  130.  
  131. OUTFLG    DB    0            ; Output mode flag
  132.  
  133. ; Get hex number, returns carry for end of string
  134. GETHEX    PROC    NEAR
  135.     XOR    DX,DX            ; Clear return value
  136.     XOR    CX,CX            ; Clear digit count
  137. GETSPC:    LODSB
  138.     CMP    AL,20H
  139.     JZ    GETSPC            ; Skip over leading space
  140.     JB    GETEXI            ; Error exit, line ends
  141.     CMP    AL,';'
  142.     JZ    GETCOM            ; Error exit, logical line ends
  143. GETNXT:    MOV    AH,AL            ; Save current char
  144.     SUB    AL,'0'
  145.     CMP    AL,9
  146.     JBE    GETDIG            ; Decimal digit
  147.     AND    AL,0DFH            ; Convert to 'UPPER' case
  148.     SUB    AL,'A'-'0'
  149.     SUB    AL,6
  150.     JNC    GETRAH            ; Not A-F, exit
  151. GETDIG:    AND    AL,0FH
  152.     SHL    DX,1
  153.     SHL    DX,1
  154.     SHL    DX,1
  155.     SHL    DX,1
  156.     OR    DL,AL            ; Add digit to result
  157.     INC    CX            ; Increment digit count
  158.     LODSB
  159.     CMP    AL,';'
  160.     JZ    GETEXZ            ; Exit on digit end, return EOL
  161.     CMP    AL,20H
  162.     JA    GETNXT            ; Possibly more digits
  163.     JZ    GETEXQ
  164. GETEXZ:    XOR    AL,AL
  165. GETEXI:    DEC    SI            ; Stay put at end of line
  166. GETEXQ:    RET
  167.  
  168. GETCOM:    DEC    SI
  169.     ADD    AL,-';'            ; Set carry and clear AL
  170.     RET
  171. GETRAH:    MOV    AL,AH            ; Return current char as normal exit
  172.     RET
  173. GETHEX    ENDP
  174.  
  175. OUTBYT:    CMP    CS:[OUTFLG],0        ; Test output mode (memory/IO) 
  176.     JNZ    OUTPUT
  177.     STOSB                ; Memory mode
  178.     RET
  179.  
  180. OUTPUT:    PUSH    DX
  181.     MOV    DX,DI
  182.     OUT    DX,AL            ; IO mode
  183.     POP    DX
  184.     RET
  185.  
  186. MAIN    PROC    FAR
  187.     CLD
  188.     CALL    GETHEX            ; Get first hex digit
  189.     JC    wrong
  190.     CLI                ; Assume pokes need a critical section
  191. POKLOP:    MOV    CS:[OUTFLG],0        ; Assume memory output mode
  192.     CMP    AL,'o'
  193.     JZ    OUTCMD
  194.     CMP    AL,'O'            ; Got an 'O'?
  195.     JNZ    GOTSEG
  196. OUTCMD:    INC    CS:[OUTFLG]        ; Change to IO mode
  197.     JMP    Short GETADR
  198. GOTSEG:    CMP    AL,':'
  199.     JNZ    wrong
  200.     JCXZ    wrong
  201.     MOV    ES,DX            ; Got '<digits>:'
  202. GETADR:    CALL    GETHEX            ; Get offset/IO_address
  203.     JC    wrong
  204.     JCXZ    wrong
  205.     MOV    DI,DX            ; Save offset/IO_address
  206. GETDAT:    CALL    GETHEX
  207.     JC    DONE
  208.     CMP    AL,20H
  209.     JBE    STORE            ; Got value to store
  210.     CMP    AL,'@'
  211.     JNZ    POKLOP            ; Got nothing, test for new address
  212.     JCXZ    wrong
  213.     MOV    BX,DX            ; Got '<digits>@'
  214.     CALL    GETHEX            ; Get offset
  215.     JC    wrong
  216.     JCXZ    wrong
  217.     MOV    BP,DX            ; Save source offset for memory copy
  218.     MOV    DX,1            ; Assume length 1 byte if unspecified
  219.     DB 3CH    ;CMP AL,nn (i e SKIP)
  220. FINDNX:    LODSB
  221.     CMP    AL,20H
  222.     JZ    FINDNX            ; Skip spaces
  223.     CMP    AL,'L'            ; Found Length specifier?
  224.     JZ    GETLEN
  225.     CMP    AL,'l'
  226.     JNZ    STOREI
  227. GETLEN:    CALL    GETHEX            ; Get length
  228.     JC    wrong
  229.     JCXZ    wrong
  230. STOREI:    MOV    CX,DX            ; Get count
  231.     PUSH    DS
  232.     PUSH    SI
  233.     MOV    DS,BX            ; Set up source address
  234.     MOV    SI,BP
  235. STOREL:    LODSB                ; Get byte
  236.     CALL    OUTBYT            ; Store byte
  237.     LOOP    STOREL            ; Loop until done
  238.     POP    SI
  239.     POP    DS
  240.     JMP    GETDAT
  241.  
  242. STORE:    JCXZ    wrong
  243.     XCHG    AX,DX            ; Get value to store
  244.     CMP    CX,2
  245.     JBE    STOREB            ; Byte value only
  246.     CALL    OUTBYT            ; Store LSB of word value
  247.     XCHG    AL,AH            ; Set up for MSB store
  248. STOREB:    CALL    OUTBYT            ; Save last byte
  249.     JMP    GETDAT
  250.  
  251. WRONG:    STI
  252.     PUSH    CS
  253.     POP    DS
  254.     MOV    DX,Offset USETXT    ; Error message
  255.     MOV    AH,9
  256.     INT    21H
  257. DONE:    STI
  258.     RET
  259. MAIN    ENDP
  260.  
  261. USETXT:
  262.  DB 'Usage: A>POKE outaddr val [val ...] [outaddr val ...] [; comment]',13,10
  263.  DB 'or:    DEVICE=POKE.COM outaddr ...',13,10
  264.  DB 'outaddr may be either seg:addr (memory address) or Oaddr (I/O address).'
  265.  DB                                    13,10
  266.  DB 'All values are in hex, and val is considered a byte if its written as'
  267.  DB                                    13,10
  268.  DB '2 or less digits, or word if its written as 3 or more digits.',13,10
  269.  DB 'val may also be seg@ofs [Ln] to copy data',13,10
  270.  DB 13,10
  271.  DB 'Example use:',13,10
  272.  DB 13,10
  273.  DB 9,'DEVICE=POKE.COM 40:17 0',9,'; Switch off Num Lock bit (among others)'
  274.  DB                                    13,10
  275.  DB 9,'C:>POKE 50:0 1',9,9,'; Disable PrintScreen function',13,10
  276.  DB 9,'C:>POKE 40:4 3E8',9,'; Install COM3 BIOS address',13,10
  277.  DB 9,'C:>POKE 40:78 2',9,9,'; Change LPT1 timeout',13,10,'$'
  278.  
  279. CODE    ENDS
  280.     END    STACOM
  281.