News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

memory resident

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

Previous topic - Next topic

majid1605

This is a code sample for resident program




; You may customize this and other start-up templates;
; The location of this template is c:\emu8086\inc\0_com_template.txt

org 100h

TITLE     A24TSTNM  (CoM) Resident program
             BIODATA SEGMENT AT 4OH              ;BIOS data aTEA
                       ;ORG     17H
             KBSTAT DB         ?                 ;Keyboard 8tatu8 byEe
             BIODATA ENDS
;---------------------------------------------------------------------
             CODESG SEGMENT     PARA
                       ASSUME  CS:CODESG,DS:BIODATA
                       ;ORG     1OOH
             BEGIN:
                       jMP    Bl0INIT            ;Jump Lo initialization
             SAVINT9   DD        ?                  ;INt 09H addresa
             AlOTEST:
                       PUSH AX                    ;Save regigtere
                       PUSH CX
                       PUSH DS
                       MOv     AX,BIODATA         ;SegmenE  addrese of
                       MOV     DS,AX             ;  BIOS daEa area
                       MOV     AL,KBSTAT          ;Gee keyboard flag
                       TEST    AL,00100000b       ;Nurnlock state?
                       JZ      A3oEXIT           ;No, exit
                       mov     dx,96 
                       IN      AL,dx              ;Get keyatroke  from port
                                 
                       CMP     AL,71             ;Scan code < 71?
                       JL      A3oEXIT            ;  yea, exiE
                       CMP     AL,83             ;Scan code > 83?
                       JG      A3OEXIT            ;  yes,  exiE,
                                                  ;Must  be from numeric  kQlTad
                       MOV     AL,10110110b       ;Set frequency
                       OUT     43H,AL
                       MOV     AX,1000
                       OUT     42H,AL
                       MOV     AL,AH
                       OUT     42H,AL
                        IN     AL,61H            ;Turn on apeaker
                       MOV     AH,AL
                       OR      AL,03
                       ouT     61H,AL
                       MOV     CX,9000            ;Set duralion
             A2OPAUSE:
                       LOOP A2OPAUSE
                       MOV     AL,AH              ;Turn off  speaker
                       out     61H,AL
             A3OEXIT:
                        POP    DS                 ;Restore  regiatera
                        POP    CX
                        POP    AX
                        JMP CS:SAVINT9           ;Resume  INT 09H
              ;                 Initializat,ion  routine:
             Bl0INIT:           ; -----------
                        CLI                       ;Preven! further inEerruPts
                        MOV    AH,35H             ;Get addrees  of  INT 09H
                        MOV    AL,09H            ;  in ES:BX
                        INT    21H
                        MOv    WORD  PTR SAVINT9,BX  ;    and save it
                        MOv    WORD  PTR SAVINT9+2,ES
                        MOV    AH,25H
                        MOV    AL,09H            ;Set nen addresg  for   INT 09lt
                        MOV    DX,OFFSET AlOTEST      ; in  AlOTEST
                        INT    21H   

MOV      AH,31H              ;Req[ue6t st,ay  reEident
                        MOV      DX,OFFSET Bl0INIT  ;Set size  of          resident     portion
                        STI                             ;ResEore  interruptg
                        INT      21H
            CODESG ENDS
                        END       BEGIN

ret




Unfortunately, the masm does not work .This code is written in IBM PC Assembly Language and Programming  (1998) :bgrin:

nidud

#16
deleted

nidud

#17
deleted

FORTRANS

Quote from: Magnum on January 12, 2013, 02:46:20 PM
Steve,

Could post some of your TSR code ?

Hi Andy,

   Sure.  Doing a search turned up the Y2K program.
Mildly editted.


        PAGE ,132
        TITLE PAST2.ASM
COMMENT |
  Based on jw work. and noting pr remarks,
here is a slightly tested version.  Probably still too
simple, but it passed tests a) and b) above.
        |
; Steve N 17 October 2003

CODE    SEGMENT
        ASSUME  CS:CODE,DS:CODE,ES:NOTHING
        ORG     100H    ; COM file opening
START:
        JMP     INSTALL
        NOP             ; Fill to 104H

WayBackIt:
        CMP     AH,02AH
        JNZ     FallThru ; None of our business...

        PUSHF           ; Emulate an interrupt
        CALL DWORD PTR CS:[100H]
        SUB     CX,0AH  ; Fn 2A dosen't care about flags (thank you)
        IRET            ; Interrupt return (with bogus flags)

FallThru:               ; Just let DOS do its thing.
        JMP     DWORD PTR CS:[100H]

INSTALL:
        MOV     AL,021H ; Get DOS interrupt vector
        MOV     AH,035H ; DOS get interrupt vector Fn
        INT     21H
        MOV     WORD PTR DS:[100H],BX
        MOV     WORD PTR DS:[102H],ES

        MOV     DX,OFFSET WayBackIt     ; Interrupt handler segment in DS, offset in DX.
        MOV     AH,025H ; DOS set interrupt vector Fn (Don't do by hand).
        INT     21H

        MOV     DX,12H  ; Size to Keep (could get fancy, but KISS).
        MOV     AX,3100H ; DOS Keep program and return code of 0
        INT     21H

CODE    ENDS
        END     START


   And the clock program.  Again names deleted.  It looks
like I deleted the debug code at the time, so who knows
what all that was about.


        PAGE ,132
        TITLE TSR to create synchronize 200LX clocks.
        NAME  Clocks

        COMMENT *

   COM file TSR to create synchronize 200LX clocks.  Based on
discussions on the HPLX mailing list.  N G had a problem
with the BIOS clock being delayed after running 1-2-3 macros.

9-13 February 2005
*
        .XCREF
        .XLIST
INCLUDE DEFMS.ASM   ; System Call MACRO and MS-DOS definitions
        DOSF_GETPSP     EQU 62H         ; Get Program Segment Prefix
        .LIST           ;  from Heath/Zenith software.
        .CREF
DEBUG    EQU    1       ; should be self-documenting..
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Set up the code definitions the operating system wants.
; In a COM program all segments are the same.

.186    ; Should be okay, test for 200LX before installing.
CODE    SEGMENT
        ORG     100H
        ASSUME  CS:CODE,DS:NOTHING

START:
        JMP     INSTALL

OldInt1C DD     0
Counter DW      10920

NewInt1C:       
        PUSHF
        DEC     CS:[Counter]
        JLE     Synch
        POPF
        JMP     DWORD PTR CS:[OldInt1C] ; rejoin timer interrupt chain

Synch:
        PUSHA
        MOV     AH,4BH  ; This is the 200LX synch
        INT     15H

        MOV     CS:[Counter],10920      ; reset to ten minutes

        POPA
        POPF
        JMP     DWORD PTR CS:[OldInt1C] ; rejoin timer interrupt chain

INSTALL:
        ASSUME  CS:CODE,DS:CODE

        CLD
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Check for 200LX, won't work on anything else.
; Test200:
; Make sure we are on a 100LX family machine.

        mov     ax,4dd4h
        int     15h
        cmp     bx,'HP'         ; HP machine?
        jne     msg_exit        ; No
        cmp     ch,1            ; palmtop?
        jne     msg_exit        ; No
        cmp     cl,2            ; later than the 95LX?
        jb      msg_exit        ; No
        JMP     msg_exit2
msg_exit:
        mov     dx, offset not100lx_msg
        SCALL   OUTSTR
        MOV     AL,1    ; Show error
        SCALL   EXIT
msg_exit2:
; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
;       Get old int 1CH
        MOV     AL,1CH                  ; Function 35 interrupt 1C
        SCALL   GIVEC                   ; Get Interrupt VECtor
        MOV     WORD PTR [OldInt1C],BX  ; Int 1C is BIOS clock tick
        MOV     AX,ES                   ; Returns in ES:BX
        MOV     WORD PTR [OldInt1C+2],AX

;       Store new int 1C
        MOV     DX,OFFSET NewInt1C      ; clock tick service routine
                                        ; DS:DX points to new handler
        MOV     AL,1CH                  ; Point to NewInt1c
        SCALL   SIVEC                   ; Set Interrupt VECtor

; - - -
; Free the environment (similar to Waite Group code {or others}).
        SCALL GETPSP
        MOV     ES,BX   ; Set ES to the PSP
        XOR     AX,AX
        XCHG    AX,ES:[2CH]     ; Zap environment segment in PSP
                                ; and put env seg in AX.
        TEST    AX,0FFH
        JZ      Hunh            ; Hard to see how this could ever
                                ; happen.
        MOV     ES,AX           ; Point ES to environment.
        SCALL DEALLOC           ; Free the environment block.
Hunh:

; - - -
;    Here we can copy code into the PSP DTA (command line) to
; free up another bunch of bytes.
; - - -

        MOV     DX,OFFSET MSG
        SCALL OUTSTR

        MOV     AL,0    ; Show no error
        MOV     DX,13H  ; Paragraphs to keep (HEX NOT DECIMAL!)
        SCALL KEEPPRC   ; Keep process

; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
; Data area for the installation.

MSG      DB     'Installed Clock Synch TSR.$'
Not100LX_msg db ' TSR is intended for an HP 100/200LX'
        DB      ' machine!',13,'$'

CODE    ENDS
        END     START


   Hm.  Looking at it, it does do one sneaky thing.  So may
not be best as an example.

Regards,

Steve N.

MichaelW

Quote from: majid1605 on January 12, 2013, 03:13:49 AM
I want this programm resident in to memory and be active With a key in other Programs

That particular code as it stands, and called in response to a hardware interrupt, is likely to have problems with reentrancy. I'm not sure about the mouse driver but BIOS code is generally not reentrant, so to avoid problems with this you must ensure that any BIOS ISR you call was not executing at the time the user pressed the key that activated the code.

Another problem is that the code is calling a BIOS function that waits for a key to become available.

And another problem is that your code popping up and changing the video mode without preserving/restoring the mode and display buffer contents could present a serious problem for any "other programs".

A better approach would be for your TSR to hook the keyboard hardware interrupt or keyboard intercept and capture the keystrokes from the handler, and use the current video mode and/or preserve/restore the video state (and do this without reentrant BIOS calls).




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

Magnum

Quote from: japheth on January 12, 2013, 08:33:39 AM
Quote from: Gunther on January 12, 2013, 08:01:49 AM
under DOS is it not obsolete. The question is: is a single tasking OS state of the art?

IMO the level of modernity of DOS is NOT AT ALL the question. If I may use your words: the question is: has DOS still a purpose today?

And the answer to this question definitely is: yes. At least for those people who are interested in assembly language and want to use or play with privileged instructions or talk directly to the hardware. Because DOS is by far the simplest platform to do exactly these things.

From this MY point of view it's more "obsolete" to code a Win32 desktop applications in assembly language ( and using the native Win32 API ) than to code a DOS TSR.

http://en.wikipedia.org/wiki/DOS#DOS_under_OS.2F2_and_Windows

http://en.wikipedia.org/wiki/BIOS#Overclocking

If you think about it, there really is no such thing as any multitasking O.S.

I stand corrected. I just found this. I would like to try it.  :t


In the mid-1980s Microsoft developed a multitasking version of DOS.[5][6] This version of DOS is generally referred to as "European MS-DOS 4" because it was developed for ICL and licensed to several European companies. It was never released to the general public or any other OEMs. This version of DOS supports preemptive multitasking, shared memory, device helper services and New Executable ("NE") format executables. None of these features were used in later versions of DOS but they were used to form the basis of the OS/2 1.0 kernel. This version of DOS is distinct from the widely released PC DOS 4.0 which was developed by IBM and based upon DOS 3.3.



If you start more than one program, the CPU is making decisions as to what to run and in what order.

This is true of any O.S., I am amazed the clock doesn't lose more time even with it's own power supply.

For me, "dropping to Dos" (should be "where speed is important") is an important feature.

For example, deleting only .obj and .map files quickly out of a host of other extensions.

Even M.S. MVPs frequently recommend using cmd or Run commands, and many admin kits have command line programs.

Rambling over.
                   

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

FORTRANS

Hi,

   Oops, used an include file.  This should be what is
necessary.


DOSF_OUTSTR EQU  9 ; Output string

DOSF_EXIT EQU 76 ; Exit
; 04CH

DOSF_GIVEC EQU 53 ; Set/get interrupt vector
; 035H

DOSF_SIVEC EQU 37 ; Set interrupt vecter
;025H

DOSF_DEALLOC EQU 73 ; Deallocate block
DOSF_KEEPPRC EQU 49 ; Keep process

; Macro for dealing with system software interrupts
;
; Syntax is:
;
; SCALL foo
;
; The result is a system call to DOSF_foo
;

SCALL MACRO ARG
MOV AH,DOSF_&ARG
INT 21H
ENDM


   Habits, oh well.

Regards,

Steve

Magnum

I am typing using Maxthon browser which I am testing.

(Supposed to be the best in terms of HTML 5.0 compliancy.)

Thanks gentlemen for the code.

Steve,
           Your code is short and I will study it.
           
           I prefer using Tasm, don't think it will take much work converting it.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

Gunther

Hi Andy,

Quote from: Magnum on January 13, 2013, 12:38:01 AM
           I prefer using Tasm, don't think it will take much work converting it.

Andy

yes, TASM code can be easy converted into MASM code.

Gunther
You have to know the facts before you can distort them.

dedndave

i never had any luck with "SEGMENT AT" on older versions of MASM
haven't tried it on newer versions
BIODATA SEGMENT AT 4OH              ;BIOS data area

        ORG     17H
KBSTAT  DB      ?                   ;Keyboard status byte

BIODATA ENDS


but, all you really need is the 40h and the offset of 17h
you can do that with EQUates

as for the clock TSR, i wrote something similar, but as a device driver
CLOCK$ is the actual DOS device name - a character device
by doing it that way, it automatically comes up with the right date and time
no need for the DATE/TIME commands
if you set the DOS date or time with DATE/TIME, the driver sets the RTC
i see the CLOCK$ device doesn't seem to be supported under win32   :P

QuoteTo allow a clock board to be integrated into the system for TIME and DATE,
the CLOCK$ device is used. This device defines and performs functions like any
other character device (most functions will be reset done bit, reset error bit,
and return). When a read or write to this device occurs, 6 bytes are
transferred. The first 2 bytes are a word, which is the count of days since
01-01-80. The third byte is minutes, the fourth is hours, the fifth is
hundredths of a second, and the sixth is seconds.

of course, the RTC boards used in XT's varied
so - you had to write the I/O stuff to match your board - lol

for an AT-class machine, it is standardized at 70h/71h

EDIT: the device name for CLOCK$ is "CLOCK$  ", and the attribute is 8008h

FORTRANS

Quote from: dedndave on January 13, 2013, 02:15:37 AM
i never had any luck with "SEGMENT AT" on older versions of MASM
haven't tried it on newer versions

Hi,

   Really?  What kind of problems?  What version?  The
following is fine with MASM Version 3.0.


; - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
BIOSSEG SEGMENT AT 40H  ; BIOS Data area
        ORG    6CH
ClockTic DD    ?        ; 55 ms timer ticks since midnight
BIOSSEG ENDS


   As for the date and time, you can use the BIOS interrupt
1AH to read the RTC.  I posted some code in the old forum.
Or I could post it again here.

   According to the TASM documentation I have, there
should be no translation required, unless you want to use
their "Ideal Mode".  But as I only have the, rather old,
documentation and not TASM itself, if you encounter any
problems, please post your corrections.

Cheers,

Steve N.

dedndave

yah - it probably doesn't make sense to write a CLOCK$ driver for AT-class machines

Magnum

Steve,

I assembled and ran your program.

It takes up 1152 bytes, but I can't figure out what it does besides going resident.

Andy
Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org

FORTRANS

Quote from: Magnum on January 13, 2013, 03:51:34 AM
Steve,

I assembled and ran your program.

It takes up 1152 bytes, but I can't figure out what it does besides going resident.

Hi Andy,

   The first program, PAST2.ASM, subtracts 10 years
from the DOS date function.  CLOCKS.ASM is a program
to update the current time on the HP 200LX palmtop
computer using the RTC to update the DOS time.  It
shouldn't go resident on other computers.

Regards,

Steve

Magnum

What specifically do you mean by Dos date function ?

Since it subtracts 10 years, I thought when I did date at the command line, it would show 2003.  :t

Take care,
                   Andy

Ubuntu-mate-18.04-desktop-amd64

http://www.goodnewsnetwork.org