page    60,132
              title   Assembler utilities
              .286
;------------------------------------------------------------------------------
; ASMTOOLS.ASM                         Alan C. Partis
;                                      Copyright (C) AP MicroSystems, Inc.
;                                      1994 - All rights reserved
; 
; Description:  This is a collection of ASM utility routines
;
; Technical Reference:
;
;
; Contents:   fstrcpy()   
;             GetDOSVer() 
;             GetIntVect()
;             HexDump()   
;             PrintXByte()
;             SetIntVect()
;             StrDump()
;             _StrDump()
;
; Date        Initials Comments
; -----------------------------------------------------------------------
; 08-20-94    acp      initial creation
;
;------------------------------------------------------------------------------

include       stdapms.inc

DGROUP        group   _DATA, _CONST, _BSS                   ;linker order

_DATA         segment word public 'DATA'
              assume  ds:DGROUP
_DATA         ends



_CONST        segment word public 'CONST'
              assume  ds:DGROUP
_CONST        ends



_BSS          segment word public 'BSS'
              assume  ds:DGROUP
_BSS          ends



_ASMTOOLS     segment word public 'CODE'
              assume  cs:_ASMTOOLS, ds:DGROUP

;------------------------------------------------------------------------------
; _fstrcpy                                  Alan Partis
;                                           Copyright (C) AP MicroSystems, Inc.
;                                           1994 - All rights reserved
; 
; Description:  copies bytes from 'src' string to 'dest' string up to, and 
;             including, a terminating NULL in the 'dest' string.
;
; Input:      bp+6                          ;far pointer to 'dest' string
;             bp+10                         ;far pointer to 'src' string
;
; Output:     none
;
; Date        Initials Rev Comments
; -----------------------------------------------------------------------
; 09-27-94    acp      01  initial creation
;
;------------------------------------------------------------------------------
;
              public _fstrcpy
_fstrcpy      proc    far 

              push    bp                    ;save application stack offset pointer
              mov     bp,sp                 ;load current stack point

              ;
              ; save regs
              ;
              push    ds
              push    es
              push    si
              push    di

              ;
              ; access arguments es:di = 'dest'  ds:si = 'src'
              ;
              mov     ax,word ptr [bp+8]    ;segment to dest
              mov     es,ax
              mov     di,word ptr [bp+6]    ;offset to dest

              mov     ax,word ptr [bp+12]   ;segment to src
              mov     ds,ax
              mov     si,word ptr [bp+10]   ;offset to src

              ;
              ; copy src bytes to dest location until a NULL is copied
              ;
fsc1:         movsb                         ;copy byte
              cmp     byte ptr [si],0       ;check for NULL
              jnz     fsc1                  ;go again if no NULL found

              ;
              ; restore regs
              ;
              pop     di
              pop     si
              pop     es
              pop     ds

              pop     bp

              ret
_fstrcpy      endp

;------------------------------------------------------------------------------
; _GetIntVect()                             Alan Partis
;                                           Copyright (C) AP MicroSystems, Inc.
;                                           1994 - All rights reserved
; 
; Description:  Retrieves a given interrupt vector value via DOS services.
;
; Input:      bp+6                          word hex vector to retrieve
;
; Output:     ax                            offset of retrieved vector
;             dx                            segment address of retrieved vector
;
; Date        Initials Rev Comments
; -----------------------------------------------------------------------
; 09-30-94    acp      01  initial creation
;
;------------------------------------------------------------------------------
;
              public _GetIntVect
_GetIntVect   proc    far 

              push    bp                    ;access stacked args
              mov     bp,sp

              ;
              ; save affected regs
              ;
              push    bx
              push    es

              ;
              ; get vector
              ;
              mov     ax,[bp+6]
              mov     ah,GET_INT_VECT
              int     21h

              ;
              ; set up return value
              ;
              mov     dx,es
              mov     ax,bx

              ;
              ; restore regs
              ;
              pop     es
              pop     bx

              pop     bp                    ;reset stack frame
              retf

_GetIntVect   endp



;------------------------------------------------------------------------------
; _GetDOSVer                                Alan Partis
;                                           Copyright (C) AP MicroSystems, Inc.
;                                           1993 - All rights reserved
; 
; Description:  Updates two global variables (_osmajor & _osminor) with the
;             REAL DOS ver (not masked with SETVER).                
;
; Input:      none
;
; Output:     ax                            0 = DOS 5.0 or greater
;                                           1 = prior DOS version
;
; Date        Initials Rev Comments
; -----------------------------------------------------------------------
; 08-21-94    acp      01  initial creation
;
;------------------------------------------------------------------------------
;
extrn         __osmajor:byte
extrn         __osminor:byte

              public _GetDOSVer
_GetDOSVer    proc    far 

              ;
              ; save regs
              ;
              push    bx
              push    dx

              ;
              ; get DOS version - first check the documented
              ;  version, but since this can be overridden by
              ;  SETVER, we'll possibly override this with the
              ;  results from the undocumented version.
              ;
              xor     ax,ax                 ;clear return values
              xor     bx,bx
              mov     ah,GET_DOS_VER
              int     21h
              mov     __osmajor,al          ;save results
              mov     __osminor,ah

              mov     ax,GET_REAL_DOS
              xor     bx,bx                 ;preset - if 0 on return do nothing
              int     21h
              cmp     bx,0                  ;if 0, function is unsupported
              je      gdv1
              mov     __osmajor,bl          ;override with real DOS version
              mov     __osminor,bh

              xor     ax,ax                 ;DOS version 5.0 or later
              jmp     gdvx

gdv1:         mov     ax,0001h              ;DOS version pre-5.0

              ;
              ; restore regs and get outta Dodge
              ;
gdvx:         pop     dx
              pop     bx
              retf

_GetDOSVer    endp



;------------------------------------------------------------------------------
; _HexDump                                  Alan Partis
;                                           Copyright (C) AP MicroSystems, Inc.
;                                           1993 - All rights reserved
; 
; Description:  Outputs a block of raw bytes in hex format as specified
;             by the input parameters to the console for diagnostics
;
; Input:      bp+6                          ;4 byte pointer to data
;             bp+10                         ;size of data
;
; Output:     none
;
; Date        Initials Rev Comments
; -----------------------------------------------------------------------
; 05-20-93    acp      01  initial creation
;
;------------------------------------------------------------------------------
;
              public _HexDump
_HexDump      proc    far 

              push    bp                    ;save application stack offset pointer
              mov     bp,sp                 ;load current stack point

              ;
              ;save registers
              ;
              push    ax
              push    bx
              push    cx
              push    dx
              push    es

;
;get parameters
;
              mov     ax,word ptr [bp+8]    ;segment to data
              mov     es,ax
              mov     bx,word ptr [bp+6]    ;offset to data
              mov     cx,[bp+10]            ;count

;
;print address first
;
              mov     ax,es
              mov     dl,ah
              call    PrintXByte
              mov     dl,al
              call    PrintXByte
              PRINTC  COLON
              mov     dl,bh
              call    PrintXByte
              mov     dl,bl
              call    PrintXByte
              PRINTC  SPACE
              PRINTC  SPACE

              ;
              ;display byte
              ;
hd1:          mov     dl,byte ptr es:[bx]   ;byte to display
              call    PrintXByte

              ;
              ;output a space
              ;
              PRINTC  SPACE

              ;
              ;update pointer and loop
              ;
              inc     bx
              loop    hd1

              ;
              ;put out cr/lf and return
              ;
              PRINTC  CR
              PRINTC  LF

              ;
              ;exit back to caller
              ;
              pop     es
              pop     dx
              pop     cx
              pop     bx
              pop     ax

              pop     bp
              ret

_HexDump      endp


;------------------------------------------------------------------------------
; PrintXByte                                Alan Partis
;                                           Copyright (C) AP MicroSystems, Inc.
;                                           1993 - All rights reserved
; 
; Description:  Displays a given hexidecimal byte to the console
;
; Input:      dl                            ;byte to display
;
; Output:     none
;
; Date        Initials Rev Comments
; -----------------------------------------------------------------------
; 08-20-94    acp      01  initial creation
;
;------------------------------------------------------------------------------
;
ASCII         db      30h, 31h, 32h, 33h, 34h, 35h, 36h, 37h
              db      38h, 39h, 41h, 42h, 43h, 44h, 45h, 46h

PrintXByte    proc    near

              push    bx

              mov     al,dl                 ;get entire byte
              lea     bx,ASCII              ;get pointer to translation table

              and     ax,00f0h              ;isolate high nibble
              shr     ax,4                  ;move high nibble to low nibble
              xlat    ASCII                 ;convert to ASCII

              PRINTC  al

              ;
              ;low nibble
              ;
              mov     al,dl                 ;get entire byte
              lea     bx,ASCII              ;get pointer to translation table

              and     ax, 000fh             ;isolate low nibble
              xlat    ASCII                 ;convert to ASCII

              PRINTC  al

              pop     bx
              ret

PrintXByte    endp



;------------------------------------------------------------------------------
; _SetIntVect()                             Alan Partis
;                                           Copyright (C) AP MicroSystems, Inc.
;                                           1994 - All rights reserved
; 
; Description:  Sets a given interrupt vector value via DOS services.
;
; Input:      bp+6                          word hex vector to retrieve
;             bp+8                          offset of new ISR
;             bp+10                         segment of new ISR
;
; Output:     none
;
; Date        Initials Rev Comments
; -----------------------------------------------------------------------
; 09-30-94    acp      01  initial creation
;
;------------------------------------------------------------------------------
;
              public _SetIntVect
_SetIntVect   proc    far 

              push    bp                    ;access stacked args
              mov     bp,sp

              ;
              ; save affected regs
              ;
              push    dx
              push    ds

              ;
              ; get ISR pointer and interrupt number
              ;
              mov     ax,[bp+10]
              mov     ds,ax
              mov     dx,[bp+8]
              mov     ax,[bp+6]
              mov     ah,SET_INT_VECT
              int     21h

              ;
              ; restore regs
              ;
              pop     ds
              pop     dx

              pop     bp                    ;reset stack frame
              retf

_SetIntVect   endp



;------------------------------------------------------------------------------
; _StrDump                                  Alan Partis
;                                           Copyright (C) AP MicroSystems, Inc.
;                                           1993 - All rights reserved
;
; Description:  Outputs a block of characters              as specified
;             by the input parameters to the console for diagnostics
;
; Input:      bp+6                          ;4 byte pointer to data
;             bp+10                         ;size of data
;
; Output:     none
;
; Date        Initials Rev Comments
; -----------------------------------------------------------------------
; 05-20-93    acp      01  initial creation
;
;------------------------------------------------------------------------------
;
              public _StrDump
_StrDump      proc    far 

              push    bp                    ;save application stack offset pointer
              mov     bp,sp                 ;load current stack point

              ;
              ;save registers
              ;
              push    ax
              push    bx
              push    cx
              push    dx
              push    es

;
;get parameters
;
              mov     ax,word ptr [bp+8]    ;segment to data
              mov     es,ax
              mov     bx,word ptr [bp+6]    ;offset to data
              mov     cx,[bp+10]            ;count

;
;display byte
;
sd1:          PRINTC  [es:bx]

              ;
              ;update pointer and loop
              ;
              inc     bx
              loop    sd1

              ;
              ;put out cr/lf and return
              ;
              PRINTC  CR
              PRINTC  LF

              ;
              ;exit back to caller
              ;
              pop     es
              pop     dx
              pop     cx
              pop     bx
              pop     ax

              pop     bp
              ret

_StrDump      endp


;------------------------------------------------------------------------------
; __StrDump                                 Alan Partis
;                                           Copyright (C) AP MicroSystems, Inc.
;                                           1994 - All rights reserved
;
; Description:  Outputs a block of characters via ROM BIOS as specified
;             by the input parameters to the console for diagnostics
;
; Input:      bp+6                          ;4 byte pointer to data
;             bp+10                         ;size of data
;
; Output:     none
;
; Date        Initials Rev Comments
; -----------------------------------------------------------------------
; 09-27-94    acp      01  initial creation
;
;------------------------------------------------------------------------------
;
              public __StrDump
__StrDump     proc    far 

              push    bp                    ;save application stack offset pointer
              mov     bp,sp                 ;load current stack point

              ;
              ;save registers
              ;
              push    ax
              push    bx
              push    cx
              push    dx
              push    es

;
;get parameters
;
              mov     ax,word ptr [bp+8]    ;segment to data
              mov     es,ax
              mov     bx,word ptr [bp+6]    ;offset to data
              mov     cx,[bp+10]            ;count

;
;display byte
;
_sd1:         PRINTC_B [es:bx]

              ;
              ;update pointer and loop
              ;
              inc     bx
              loop    _sd1

              ;
              ;put out cr/lf and return
              ;
              PRINTC_B CR
              PRINTC_B LF

              ;
              ;exit back to caller
              ;
              pop     es
              pop     dx
              pop     cx
              pop     bx
              pop     ax

              pop     bp
              ret

__StrDump     endp


_ASMTOOLS     ends
              end


  Copyright © Thundernet Development Group Inc., 2003.
All rights reserved.