home *** CD-ROM | disk | FTP | other *** search
- ;******** Dummy block device **********
-
- TITLE Poke memory locations
-
- ; Called as a driver, this program always fails to install, i e it consumes no
- ; memory. Alternatively, it may be called upon as a normal program.
- ; Usage: A>POKE outaddr val [val ...] [outaddr val ...] [; comment]
- ; or: DEVICE=POKE.COM outaddr val [val ...] [outaddr val ...] [comment]
- ; outaddr may be either seg:addr (memory address) or Oaddr (I/O address).
- ; All values are in hex, and val is considered a byte if its written as
- ; 2 or less digits, or word if its written as 3 or more digits.
- ; val may also be seg@ofs [Ln] to copy data
-
- ; Example use:
- ;
- ; DEVICE=POKE.COM 40:17 0 ; Switch off Num Lock bit (among others)
- ; C:>POKE 50:0 1 ; Disable PrintScreen function
- ; C:>POKE 40:4 3E8 ; Install COM3 BIOS address
- ; C:>POKE 40:78 2 ; Change LPT1 timeout
-
- ; Released to the Public Domain by Dan Norstedt 1991
-
- ; Version 1.0
-
- CODE SEGMENT BYTE
-
- ASSUME CS:CODE,DS:NOTHING
-
- ORG 100H
-
- STACOM: JMP Short INITCO
- ;-----------------------------------------------
- ;
- ; A D J M E M - Dummy block device driver
- ;
- ; DW -1 ; Header
- MEMDEV EQU $-2
- DW -1
- DW 0000000000000000B ; No options
- DW STRAT-100H
- DW ENTRY-100H
- DB 0 ; No devices to install
-
- ;---------------------------------------------------
- ;
- ; Device entry point
- ;
- CMDLEN = 0 ;Length of this command
- UNIT = 1 ;Sub unit specifier
- CMD = 2 ;Command code
- STATUS = 3 ;Status
- MEDIA = 13 ;Media descriptor
- TRANS = 14 ;Transfer address
- COUNT = 18 ;Count of blocks or characters
- STABLK = 20 ;First block to transfer
-
- PTRSAV DD 0 ; Storage for device driver packet
- INIFLG DB 1 ; Flag set only for first entry
-
- INITCO: MOV SI,81H ; Normal program entry
- MOV BL,[SI-1]
- MOV BH,0
- MOV [SI+BX],BH ; Make command line ASCIIZ
- PUSH CS
- CALL Near Ptr MAIN ; Process
- MOV AH,4CH
- INT 21H ; Terminate
-
- STRAT PROC FAR
- SHR BYTE PTR CS:[INIFLG-100H],1 ; First entry?
- JNC STRATI
- MOV WORD PTR CS:[MEMDEV-100H],-1 ; Yes, patch device header link
- STRATI: MOV WORD PTR CS:[PTRSAV-100H],BX
- MOV WORD PTR CS:[PTRSAV-100H+2],ES ; Save packet address
- RET
- STRAT ENDP
-
- ENTRY PROC FAR
- PUSH BX
- PUSH DS
- LDS BX,CS:[PTRSAV-100H] ; Get pointer to I/O packet
- CMP BYTE PTR [BX].CMD,0 ; Command init ?
- JZ INIT ; Yes, do that
- MOV WORD PTR [BX].STATUS,8103H ; No, mark error unknown command
- POP DS
- POP BX
- RET ; Restore regs and return
- ENTRY ENDP
-
- INIT PROC FAR
- PUSH AX ; Save regs
- PUSH DX
- PUSH SI
- LDS SI,DWORD PTR [BX].COUNT ; Find address of command line
- INITLO: LODSB ; i e skip over "POKE.COM" name
- CMP AL,20H
- JA INITLO
- DEC SI ; Save remaining register
- PUSH BP
- PUSH DI
- PUSH CX
- PUSH CS ; Make up for a far return
- CALL STADRV
- POP CX
- POP DI
- POP BP
- POP SI
- LDS BX,CS:[PTRSAV-100H] ; Reload pointer
- MOV BYTE PTR [BX].MEDIA,0 ; Set no of units to 0
- MOV WORD PTR [BX].TRANS,0 ; Set end address to CS:0
- MOV [BX].TRANS+2,CS ; to skip install
- MOV WORD PTR [BX].STATUS,00000001B ; Mark operation complete
- POP DX
- POP AX
- POP DS
- POP BX
- RET ; Restore regs and return
- INIT ENDP
-
- STADRV: MOV AX,CS ; This is not a real procedure, just
- SUB AX,10H ; a way to set up proper CS:IP for
- PUSH AX ; the main routine
- MOV AX,Offset MAIN
- PUSH AX
- STADRX PROC FAR
- RETF
- STADRX ENDP
-
- ;------------------------------------------- Real part of program starts here
-
- OUTFLG DB 0 ; Output mode flag
-
- ; Get hex number, returns carry for end of string
- GETHEX PROC NEAR
- XOR DX,DX ; Clear return value
- XOR CX,CX ; Clear digit count
- GETSPC: LODSB
- CMP AL,20H
- JZ GETSPC ; Skip over leading space
- JB GETEXI ; Error exit, line ends
- CMP AL,';'
- JZ GETCOM ; Error exit, logical line ends
- GETNXT: MOV AH,AL ; Save current char
- SUB AL,'0'
- CMP AL,9
- JBE GETDIG ; Decimal digit
- AND AL,0DFH ; Convert to 'UPPER' case
- SUB AL,'A'-'0'
- SUB AL,6
- JNC GETRAH ; Not A-F, exit
- GETDIG: AND AL,0FH
- SHL DX,1
- SHL DX,1
- SHL DX,1
- SHL DX,1
- OR DL,AL ; Add digit to result
- INC CX ; Increment digit count
- LODSB
- CMP AL,';'
- JZ GETEXZ ; Exit on digit end, return EOL
- CMP AL,20H
- JA GETNXT ; Possibly more digits
- JZ GETEXQ
- GETEXZ: XOR AL,AL
- GETEXI: DEC SI ; Stay put at end of line
- GETEXQ: RET
-
- GETCOM: DEC SI
- ADD AL,-';' ; Set carry and clear AL
- RET
- GETRAH: MOV AL,AH ; Return current char as normal exit
- RET
- GETHEX ENDP
-
- OUTBYT: CMP CS:[OUTFLG],0 ; Test output mode (memory/IO)
- JNZ OUTPUT
- STOSB ; Memory mode
- RET
-
- OUTPUT: PUSH DX
- MOV DX,DI
- OUT DX,AL ; IO mode
- POP DX
- RET
-
- MAIN PROC FAR
- CLD
- CALL GETHEX ; Get first hex digit
- JC wrong
- CLI ; Assume pokes need a critical section
- POKLOP: MOV CS:[OUTFLG],0 ; Assume memory output mode
- CMP AL,'o'
- JZ OUTCMD
- CMP AL,'O' ; Got an 'O'?
- JNZ GOTSEG
- OUTCMD: INC CS:[OUTFLG] ; Change to IO mode
- JMP Short GETADR
- GOTSEG: CMP AL,':'
- JNZ wrong
- JCXZ wrong
- MOV ES,DX ; Got '<digits>:'
- GETADR: CALL GETHEX ; Get offset/IO_address
- JC wrong
- JCXZ wrong
- MOV DI,DX ; Save offset/IO_address
- GETDAT: CALL GETHEX
- JC DONE
- CMP AL,20H
- JBE STORE ; Got value to store
- CMP AL,'@'
- JNZ POKLOP ; Got nothing, test for new address
- JCXZ wrong
- MOV BX,DX ; Got '<digits>@'
- CALL GETHEX ; Get offset
- JC wrong
- JCXZ wrong
- MOV BP,DX ; Save source offset for memory copy
- MOV DX,1 ; Assume length 1 byte if unspecified
- DB 3CH ;CMP AL,nn (i e SKIP)
- FINDNX: LODSB
- CMP AL,20H
- JZ FINDNX ; Skip spaces
- CMP AL,'L' ; Found Length specifier?
- JZ GETLEN
- CMP AL,'l'
- JNZ STOREI
- GETLEN: CALL GETHEX ; Get length
- JC wrong
- JCXZ wrong
- STOREI: MOV CX,DX ; Get count
- PUSH DS
- PUSH SI
- MOV DS,BX ; Set up source address
- MOV SI,BP
- STOREL: LODSB ; Get byte
- CALL OUTBYT ; Store byte
- LOOP STOREL ; Loop until done
- POP SI
- POP DS
- JMP GETDAT
-
- STORE: JCXZ wrong
- XCHG AX,DX ; Get value to store
- CMP CX,2
- JBE STOREB ; Byte value only
- CALL OUTBYT ; Store LSB of word value
- XCHG AL,AH ; Set up for MSB store
- STOREB: CALL OUTBYT ; Save last byte
- JMP GETDAT
-
- WRONG: STI
- PUSH CS
- POP DS
- MOV DX,Offset USETXT ; Error message
- MOV AH,9
- INT 21H
- DONE: STI
- RET
- MAIN ENDP
-
- USETXT:
- DB 'Usage: A>POKE outaddr val [val ...] [outaddr val ...] [; comment]',13,10
- DB 'or: DEVICE=POKE.COM outaddr ...',13,10
- DB 'outaddr may be either seg:addr (memory address) or Oaddr (I/O address).'
- DB 13,10
- DB 'All values are in hex, and val is considered a byte if its written as'
- DB 13,10
- DB '2 or less digits, or word if its written as 3 or more digits.',13,10
- DB 'val may also be seg@ofs [Ln] to copy data',13,10
- DB 13,10
- DB 'Example use:',13,10
- DB 13,10
- DB 9,'DEVICE=POKE.COM 40:17 0',9,'; Switch off Num Lock bit (among others)'
- DB 13,10
- DB 9,'C:>POKE 50:0 1',9,9,'; Disable PrintScreen function',13,10
- DB 9,'C:>POKE 40:4 3E8',9,'; Install COM3 BIOS address',13,10
- DB 9,'C:>POKE 40:78 2',9,9,'; Change LPT1 timeout',13,10,'$'
-
- CODE ENDS
- END STACOM
-