News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests

Main Menu

memory resident

Started by majid1605, January 12, 2013, 03:13:49 AM

Previous topic - Next topic

dedndave

that TSR won't be applicable
it is meant to fix a specific issue on a specific machine
but - it does show you a "format" for a TSR

FORTRANS

Hi,

   The command prompt (CMD) on Win32 systems do not use
DOS functions.  You would need to find a DOS program that
reports the date.  WordPerfect, Lotus 1-2-3, or the like.  You
might be able to run COMMAND.COM, and then see if DATE
is changed.  It is/was an internal command.  But that would
be a bit of a long shot.

Regards,

Steve

MichaelW

Quote from: nidud on January 12, 2013, 08:50:07 AM
The minimum for a TSR is around 1000 lines of code, so it is somewhat extensive

How did you arrive at this number? The upper end of the TSRs that I have done was around 1500 lines total, with the typical being well under 1000, and the smallest being around 100. Here is a TSR in 100 lines, with a resident size of 384 bytes without freeing the PSP.

;==============================================================================
; ShiftLoc.asm
; Acts as shift lock for upper digit keys (scan codes 2 - 11)
; Toggle with Ctrl + R Shift
;==============================================================================

code    SEGMENT
    ASSUME  cs:code,ds:code
    ORG 100h

entry:
    jmp loadSL

    oldVector   dd  ?       ; old System Services vector
    activeFlag  db  0       ; set when ShiftLoc is active
    slShiftFlag db  0       ; set when ShiftLoc sets BIOS flag

keyIsr:

    push    ax
    push    bx
    push    ds
    push    es
    push    cs
    pop     ds

    ; keyboard intercept ?
    cmp ah, 4fh
    jne jumpOut
    ; set up access to BIOS shift flags byte
    mov bx, 40h
    mov es, bx
    mov bx, 17h
    ; BIOS R Shift flag forced at last call ?
    cmp slShiftFlag, 1
    jne chkRShiftKey
    and BYTE PTR es:[BX], 0feh    ; reset R Shift flag
    mov slShiftFlag,0

  chkRShiftKey:

    cmp al, 36h                   ; R Shift
    jne chkCtrlKey
    test BYTE PTR es:[BX], 4      ; Ctrl flag ?
    jz  chkCtrlKey
    xor activeFlag, 1             ; toggle flag
    jmp jumpOut

  chkCtrlKey:

    cmp al, 1dh                   ; Ctrl
    jne chkActiveFlag
    test BYTE PTR es:[BX], 1      ; R Shift flag ?
    jz  chkActiveFlag
    xor activeFlag, 1             ; toggle flag
    jmp jumpOut

  chkActiveflag:

    cmp activeFlag, 1
    jne jumpOut
    ; scan code 2 - 11 ?
    cmp al, 2
    jb  jumpOut
    cmp al, 11
    ja  jumpOut
    ; test R Shift flag before setting it
    test BYTE PTR es:[BX], 1
    jnz jumpOut
    or  BYTE PTR es:[BX], 1
    mov slShiftFlag, 1

  jumpOut:

    pop es
    pop ds
    pop bx
    pop ax
    jmp DWORD PTR cs:oldVector

  loadSL:

    mov ax, 3515h                 ; get the old Int 15h vector
    int 21h
    mov WORD PTR oldVector,bx     ; and save it
    mov WORD PTR oldVector[2], es
    mov ax, 2515h                 ; set the new vector
    lea dx, keyIsr                ; entry point label
    int 21h
    mov bx, 2Ch                   ; point to correct location in PSP
    mov es, WORD PTR [bx]         ; get environment block segment
    mov ah, 49h                   ; free environment block to minimize
    int 21h                       ; resident size

    lea dx,loadSL                 ; point past end of resident part
    int 27h                       ; TSR without return code

code ENDS

    END entry

Well Microsoft, here's another nice mess you've gotten us into.

FORTRANS

Hi,

   Just to show the TSR at work.  First without PAST2.COM
The partial results from MEM /C.

Memory below 640KB (conventional memory)

  Name                Size in Decimal       Size in Hex
-------------      ---------------------   -------------
  DOS                37024      ( 36.2K)       90A0
  COMMAND             4976      (  4.9K)       1370
  VBEXT              16672      ( 16.3K)       4120
  APPEND              6528      (  6.4K)       1980
  DOSKEY              4480      (  4.4K)       1180
  FREE                 192      (  0.2K)         C0
  FREE                  80      (  0.1K)         50
  FREE                 224      (  0.2K)         E0
  FREE              575200      (561.7K)      8C6E0
       Total FREE:     575696  (562.2K)

   And the reported date by the editor is 13 January 2013.

   Now, after running PAST2.COM, MEM /C shows it loaded into
memory.  (Looks like I didn't get the installed size right in
the code.  Pity.)

Memory below 640KB (conventional memory)

  Name                Size in Decimal       Size in Hex
-------------      ---------------------   -------------
  DOS                37024      ( 36.2K)       90A0
  COMMAND             4976      (  4.9K)       1370
  VBEXT              16672      ( 16.3K)       4120
  APPEND              6528      (  6.4K)       1980
  DOSKEY              4480      (  4.4K)       1180
  PAST2                576      (  0.6K)        240
  FREE                 192      (  0.2K)         C0
  FREE                  80      (  0.1K)         50
  FREE                 224      (  0.2K)         E0
  FREE              574592      (561.1K)      8C480
       Total FREE:     575088  (561.6K)

   And the reported date is 13 January 2003.  Ta Da!

Cheers,

Steve N.

nidud

#34
deleted

avcaballero

A little screensaver in msdos, comments in spanish, sorry

Magnum

Where is the Macros_N.inc file to assemble the examples ?

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

japheth

Here's also a little TSR: http://www.japheth.de/Download/DOS/filemon.zip

It hooks DOS interrupt 21h and logs certain file-related calls onto the "debug terminal" via OutputDebugString(). The Win32 API is accessed with the help of a Win32 dll ( VDD ); hence it works in NTVDM only!

avcaballero

Quote from: Magnum on January 15, 2013, 05:08:44 AM
Where is the Macros_N.inc file to assemble the examples ?
This is what you need. I guess that it does not work well inside a WXP cmd, but yes inside dosbox.

japheth, it is hard to download files from your site...

This is filemon, a character in a comic of humor  :bgrin:



japheth

Quote from: avcaballero on January 15, 2013, 08:23:22 PM
japheth, it is hard to download files from your site...

Is it a physical or psychical problem?

avcaballero

You have sense of humor, eh? ... I can't access because of spyware/malware warning. Surely my antivirus is wrong (my fault with no doubt)... Never mind

majid1605

Thanks guys
what this promlem my code?

.model small
.stack
.code
start:

mouse proc near
mou:
push ax
push dx
push cx
mov al,4
mov bh,0
int 10h

mov bh,0
mov bl,1001b
mov ah,0Bh
int 10h

mov ax,0
int 33h

mov ax,01h
int 33h

;mov dx,101h
;mov cx,161h
lable1:
mov ah,10h
int 16h
cmp ah,50h ;DownArrow key
je lable2
cmp ah,4Dh ;RightArrow key 
je lable3
cmp ah,4Bh ;LeftArrow key 
je lable4
cmp ah,48h ;upArrow key 
jne test_something_else

; Moved up
mov ax,03h
int 33h
dec dx
mov ax,04h
int 33h
cmp dx,0
jne lable1

lable2:; Moved Down
mov ax,03h
int 33h
inc dx
mov ax,04h
int 33h
cmp dx,184
jne lable1

lable3:; Moved right
mov ax,03h
int 33h
inc cx
mov ax,04h
int 33h
cmp dx,0
jne lable1

lable4:; Moved left
mov ax,03h
int 33h
dec cx
mov ax,04h
int 33h
cmp dx,305
jne lable1


test_something_else:
    ;------------ end of program
   
pop cx
pop dx
pop ax
iret
end mou
mouse endp



mov ah,25h
mov al,100
mov dx,offset mouse
int 21h

mov ah,31h
mov dx,offset mou
;mov dx, offset
int 21h

;in al,60h
int 09h
ah,0
int 16h
; cmp al,4Dh ;RightArrow key
int 10h
cmp ah,3Bh ;DownArrow key
jne NotRunMouse

int 64h

NotRunMouse:
mov ax, 4c00h
    int 21h

     end start


I want my code to be amended and just tell me what is my code problems?
The F key to activate the MouseProgram in another program

japheth

Quote from: majid1605 on January 29, 2013, 10:37:39 AM
I want my code to be amended and just tell me what is my code problems?

There are a LOT of problems in your code.

A brief glance reveals that to extend this program is clearly "beyond your league" ( that's how one of the moderators described this phenomenon once, so I guess it's the official term ).

A somewhat experienced ASMer could probably fix the errors and feed you with the result, but you won't learn much then.

My advise: start with something much simpler and then advance carefully.

Magnum

This is working code.

Please study it and understand it because it does what you have been asking for.

Andy


; saver.asm  Com program   Orig. File Creation 6/13/2002   AK
;                                            Minor modification on 1/29/13
; Screen saver (blanks screen)   COM file..
; Only works in 80x25 screen modes (2,3,7) [could easily be adapted/others]
;        Uses F-8 key to activate, un-install by typing name of program again
;
;   **** ADJUSTABLE time interval to pop up
;
;   ;                                                                                                                                                                                                                                   
;       
;
.SEQ               ; store segment sequentially as they appear
.286               ; use 80286+ code
.MODEL tiny        ; TINY model to make it a .COM program

;* Macros *

StAlloc MACRO sizew    ; macro to allocate stack, size "sizew" words
MOV BX,((sizew*2)+15) SHR 4    ; BX = size in paragraphs
MOV AH,48h        ; allocate memory function
INT 21h           ; call DOS
CLI               ; freeze interrupts
MOV SS,AX         ; set stack segment to allocated segment returned in AX
MOV SP,sizew*2-2  ; set stack pointer to end of segment (goes top down)
STI               ; restore interrupts
ENDM

StDeAlloc MACRO    ; macro to deallocate stack
MOV AX,SS
MOV ES,AX
MOV AH,49h        ; call DOS deallocate block function
INT 21h
ENDM

;* Code Segment *

code SEGMENT PARA PUBLIC 'CODE'    ; code segment
ASSUME CS:code, DS:code, ES:code, SS:code  ; assume CS->"code" etc.
ORG 100h                           ; start assembling at offset 0h (default)

;* Program Start *

start:               ; label for start of program
JMP init

;* Procedures *

; Save screen and display (init) screen saver logo

ScreenSaver PROC NEAR

MOV AX,CS
MOV ES,AX
MOV DI,OFFSET ScrData
MOV DS,CS:ScrAddress
XOR SI,SI
CLD
MOV CX,2000
REP MOVSW           ; save screen
MOV CS:SSOn,1

MOV AH,0Fh
INT 10h             ; get current page in BH
MOV AH,03h
INT 10h             ; get old cursor size
MOV CS:OldCursor,CX
MOV AH,01h
MOV CX,0100h
INT 10h             ; hide cursor
CALL RunSaver       ; clear screen
CALL DrawSaver      ; draw logo
RET

ENDP

; Restore screen and deinitialize screen saver

RemoveSaver PROC NEAR

MOV ES,CS:ScrAddress
XOR DI,DI
MOV AX,CS
MOV DS,AX
MOV SI,OFFSET ScrData
CLD
MOV CX,2000
REP MOVSW
MOV CS:SSOn,0
MOV AH,01h
MOV CX,CS:OldCursor
INT 10h           ; restore cursor
RET
ENDP

; Re-hide screen to cover any writing

RunSaver PROC NEAR

MOV ES,CS:ScrAddress
XOR DI,DI
MOV CX,2000
XOR AX,AX
REP STOSW
RET

ENDP

; Find parts of screen that were changed and save to virtual screen

DeltaSaver PROC NEAR

CLD
MOV DS,CS:ScrAddress
XOR SI,SI            ; DS:SI -> physical screen
MOV AX,CS
MOV ES,AX           
MOV DI,OFFSET ScrData  ; ES:DI -> virtual screen
XOR BH,BH            ; row 0

ds_nextrow:

MOV CX,80
CMP BH,CS:Row       
JZ ds_check          ; if row of copyright string handle separately

ds_loop:

LODSW
CMP AX,0             ; check if still zero (as set by screen saver)
JZ ds_again

MOV ES:[DI],AX       ; set to new value

ds_again:

INC DI
INC DI
LOOP ds_loop

ds_new:

INC BH
CMP BH,25
JNZ ds_nextrow
RET

ds_check:

MOV BP,OFFSET Copyright
MOV BL,CS:Color

ds_loop2:

LODSW
CMP AL,ES:[BP]
JNZ ds_delta
CMP AH,BL
JZ ds_ok
ds_delta:
MOV ES:[DI],AX
ds_ok:
INC DI
INC DI
INC BP
LOOP ds_loop2
JMP SHORT ds_new
ENDP

; Draw copyright string

DrawSaver PROC NEAR
MOV AX,WORD PTR CS:Row2
MOV WORD PTR CS:Row,AX  ; now safe to copy incremented data
MOV AH,CS:Row
MOV AL,160
MUL AH
MOV DI,AX
MOV AX,CS
MOV DS,AX
MOV SI,OFFSET CS:Copyright
MOV AH,CS:Color
ds_write:
LODSB
OR AL,AL
JZ ds_donemsg
STOSW
JMP SHORT ds_write
ds_donemsg:
RET
ENDP

; move message and change color

IncSaver PROC NEAR
MOV AX,WORD PTR CS:Row2  ; AL = row, AH = attribute
ADD AX,101h              ; increment both
CMP AL,25
JNZ is_rowset

XOR AL,AL
is_rowset:
CMP AH,16
JNZ is_colset
MOV AH,1
is_colset:
MOV WORD PTR CS:Row2,AX
RET
ENDP

; INT 09h interrupt handler
; checks for hotkey combinations and deinstalls or activates program if found

Int09Handler PROC FAR
PUSHF
CALL CS:OldInt09      ; call old handler
PUSHA
PUSH DS
PUSH ES
MOV AX,40h
MOV ES,AX
MOV DI,ES:[1Ah]
CMP DI,ES:[1Ch]       ; quit if no keys in keyboard buffer
JZ i9_exit
MOV CS:SSTimer,0      ; zero timer for screen saver
CMP CS:SSOn,0
JZ i9_skip
CALL RemoveSaver      ; if screen saver active, restore screen
i9_skip:
MOV DI,ES:[DI]        ; get key in keyboard buffer
CMP DI,4200h          ; check for F8 , zeroes needed after scan code
JNZ i9_exit
PUSH DI
PUSH ES
CALL ScreenSaver      ; startup screen saver
POP ES
POP DI
i9_remove:
INC WORD PTR ES:[1Ah]
INC WORD PTR ES:[1Ah] ; remove key from buffer
CMP WORD PTR ES:[1Ah],3Eh
JNZ i9_exit
MOV WORD PTR ES:[1Ah],1Eh      ; wrap around if required
i9_exit:
POP ES
POP DS
POPA
IRET
ENDP

; INT 1Ch interrupt handler
; activates screen saver when timeout occurs

Int1CHandler PROC FAR
PUSHF
CALL CS:OldInt1C
PUSHA
PUSH DS

PUSH ES
CMP CS:SSOn,0
JZ i1c_off
CALL DeltaSaver      ; store changes to virtual screen
CALL RunSaver        ; blank screen
CALL DrawSaver       ; draw message or graphic
i1c_off:
MOV AL,CS:Timer1
DEC AL
MOV CS:Timer1,AL
JNZ i1c_exit
MOV AH,18
MOV AL,CS:Timer2
DEC AL
JNZ i1c_not19
INC AH
MOV AL,5
i1c_not19:
MOV CS:Timer2,AL
MOV CS:Timer1,AH
CMP CS:SSOn,0
JZ i1c_count
CALL IncSaver
JMP SHORT i1c_exit
i1c_count:
MOV AX,CS:SSTimer
INC AX
MOV CS:SSTimer,AX
CMP AX,180           ; 3 minutes (min x 60 secs)
JNZ i1c_exit
XOR AX,AX
MOV CS:SSTimer,AX    ; set to zero
CALL ScreenSaver     ; startup screen saver
i1c_exit:
POP ES
POP DS
POPA
IRET
ENDP

; TSR data

ScrAddress DW 0
OldCursor  DW 0
OldInt09   DD 0
OldInt1C   DD 0
SSTimer    DW 0
SSOn       DB 0
Timer1     DB 18
Timer2     DB 5
ScrData    DW 2000 DUP (?)
Row        DB 0
Color      DB 1
Row2       DB 0
Color2     DB 1
Copyright  DB 'รจ Hello, I am a Hotkey popup TSR',0
Sig        DB 'VXSS'

TSR_end LABEL BYTE

; * Main Program *

init:
MOV AX,CS
MOV DS,AX
MOV ES,AX
MOV BX,OFFSET code_end
ADD BX,15
SHR BX,4
MOV AH,4AH
INT 21H                         ; free unneeded memory given to program
StAlloc 50h                     ; allocate stack (saves memory on disk)
XOR AX,AX
MOV ES,AX
PUSH DS
MOV DS,ES:[26h]
CMP WORD PTR DS:Sig,'XV'
JNZ i_skip
CMP WORD PTR DS:Sig+2,'SS'
JNZ i_skip
MOV AX,WORD PTR DS:OldInt09
MOV BX,WORD PTR DS:OldInt09+2
CLI
MOV ES:[24h],AX
MOV ES:[26h],BX
MOV AX,WORD PTR DS:OldInt1C
MOV BX,WORD PTR DS:OldInt1C+2
MOV ES:[70h],AX
MOV ES:[72h],BX
STI
MOV AX,DS
MOV ES,AX
MOV AH,49h
INT 21h
POP DS
MOV AH,09h
MOV DX,OFFSET Deinstall
INT 21h
StDeAlloc
MOV AX,4C00h
INT 21h

i_skip:

POP DS
MOV AX,0B800h
CMP BYTE PTR ES:[0449h],7       ; check if current mode @ 0:449 is 7 (mono)
JNZ i_gotmode
MOV AX,0B000h

i_gotmode:
MOV ScrAddress,AX               ; store screen address
MOV AX,ES:[24h]
MOV BX,ES:[26h]
MOV WORD PTR OldInt09,AX
MOV WORD PTR OldInt09+2,BX      ; save old interrupt 09h
MOV AX,OFFSET Int09Handler
MOV BX,CS
CLI
MOV ES:[24h],AX
MOV ES:[26h],BX
STI
MOV AX,ES:[70h]
MOV BX,ES:[72h]
MOV WORD PTR OldInt1C,AX

MOV WORD PTR OldInt1C+2,BX      ; save old interrupt 1Ch
MOV AX,OFFSET Int1CHandler
MOV BX,CS
CLI
MOV ES:[70h],AX
MOV ES:[72h],BX
STI
MOV AH,49h
MOV ES,CS:[2Ch]
INT 21h                         ; deallocate environment block
MOV AH,09h
MOV DX,OFFSET Install
INT 21h                         ; display message
StDeAlloc                       ; deallocate stack
MOV DX,OFFSET TSR_end
ADD DX,15
SHR DX,4
MOV AX,3100h
INT 21h                         ; go TSR, exit with errorlevel 0

;* Data Area *

; main program data

Install     DB 13,10,'Screen Saver now installed - press F8 to activate.'
            DB 13,10,'Type Saver again to un-install.',13,10,10,'$'

Deinstall   DB 13,10,'Screen Saver un-installed Ok.',13,10,10,'$'

;* End Program *

code_end LABEL BYTE         ; mark end of code segment (end of program)
code ENDS                   ; end code segment "code"
END start                   ; end program, start execution at "start:"

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org