        page    ,132
        title   LMSTUB.ASM - Low memory stub for DOS when DOS runs in HMA

;===========================================================================
;
;       IBM Confidential
;       Copyright (C) IBM Corporation 1991-1992
;       All Rights Reserved.
;
;       Revision History:
;
;       M003 - MS PASCAL 3.2 support. Please see under tag M003 in dossym.inc
;              7/30/90
;
;       M006 - print A20 Hardware error using int 10.
;
;       M020 - Fix for Rational Bug - see exepatch.asm for details
;
;       M011 - check for wrap rather than do an XMS query
;              A20 after int 23,24 and 28
;
;       M012 - Rearranged stuff to make Share build with msdata
;
;       M023 - Added variable UmbSave1 for preserving umb_head arena across
;              win /3 session for win ver < 3.1
;
;       M032 - Correct length of Exec data block in Win 2.x instance table.
;
;
; AC000 - 04/09/92 - Added new ROM/POWER code from MS OAK.  WRA.
;
;       M034 - add a new variable i20to28count to be used by MSDOS.SYS
;               (msinit.asm). IF POWER is built into BIOS, then this
;               var should be 8 (which means, DOS will not patch INT
;               28 to an IRET); otherwise, this should be 9.
;
;       M00x - Added a variable for storing the ROM Exclude list ptr
;
;============================================================================


.xlist
include v86seg.inc
.xcref
include basemaca.inc
include osmaca.inc
include demmac.inc
include dossymc.inc
include demver.inc
include demdbcs.inc
include switch.inc
include doscntry.inc
include struc30.inc
include dirent.inc
include fastopen.inc
include devsym.inc
include exe.inc
include error.inc
.cref
.list



V86DATA SEGMENT
        EXTRN   UCASE_TAB: byte
        EXTRN   FILE_UCASE_TAB: byte
        EXTRN   FILE_CHAR_TAB: byte
        EXTRN   COLLATE_TAB: byte
        EXTRN   DBCS_TAB: byte
        EXTRN   MAP_CASE: far
V86DATA ENDS



V86TABLE        SEGMENT
;------------------------------------------------------------------------------

; The following table is used for DOS 3.3
;DOS country and code page information is defined here for DOS 3.3.
;The initial value for ccDosCountry is 1 (USA).
;The initial value for ccDosCodepage is 850.
;
;
PUBLIC  COUNTRY_CDPG
;
; country and code page infomation
;
COUNTRY_CDPG  label  byte

         db   0,0,0,0,0,0,0,0         ; reserved words
         db   '\COUNTRY.SYS',0        ; path name of country.sys
         db   51 dup (?)
         dw   437                     ; system code page id
         dw   6                       ; number of entries
         db   SetUcase                ; Ucase type
         dw   OFFSET V86GROUP:UCASE_TAB    ;pointer to upper case table
         dw   0                            ; segment of poiter
         db   SetUcaseFile            ; Ucase file char type
         dw   OFFSET V86GROUP:FILE_UCASE_TAB    ;pointer to file upper case table
         dw   0                            ; segment of poiter
         db   SetFileList             ; valid file chars type
         dw   OFFSET V86GROUP:FILE_CHAR_TAB   ;pointer to valid file char tab
         dw   0                            ; segment of poiter
         db   SetCollate              ; collate type
         dw   OFFSET V86GROUP:COLLATE_TAB  ;pointer to collate table
         dw   0                            ; segment of poiter
         db   SetDBCS                 ;AN000; DBCS Ev                     2/12/KK
         dw   OFFSET V86GROUP:DBCS_TAB ;AN000;;pointer to DBCS Ev table   2/12/KK
         dw   0                        ;AN000; segment of pointer        2/12/KK
         db   SetCountryInfo          ; country info type
         dw   NEW_COUNTRY_SIZE        ; extended country info size
         dw   1                       ; USA country id
         dw   437                     ; USA system code page id
         dw   0                       ; date format
         db   '$',0,0,0,0             ; currency symbol
         db   ',',0                   ; thousand separator
         db   '.',0                   ; decimal separator
         db   '-',0                   ; date separator
         db   ':',0                   ; time separator
         db   0                       ; currency format flag
         db   2                       ; # of disgit in currency
         db   0                       ; time format
         dw   OFFSET V86GROUP:MAP_CASE  ;mono case routine entry point
         dw   0                         ; segment of entry point
         db   ',',0                    ; data list separator
         dw   0,0,0,0,0                ; reserved



;------------------------------------------------------------------------------

                public  Message_Buffer
Message_Buffer  label   byte
                db      512 dup(0)

V86TABLE    ENDS



V86CODE            SEGMENT
ASSUME  CS:V86GROUP,DS:NOTHING,ES:NOTHING

SUBTTL EDIT FUNCTION ASSIGNMENTS AND HEADERS
PAGE
; The following two tables implement the current buffered input editing
; routines.  The tables are pairwise associated in reverse order for ease
; in indexing.  That is; The first entry in ESCTAB corresponds to the last
; entry in ESCFUNC, and the last entry in ESCTAB to the first entry in ESCFUNC.


V86TABLE   SEGMENT
        PUBLIC  CANCHAR
CANCHAR DB      CANCEL                  ;Cancel line character
        PUBLIC  ESCCHAR
ESCCHAR DB      ESCCH                   ;Lead-in character for escape sequences

ESCTAB  LABEL BYTE
        DB      64                      ; Ctrl-Z - F6
        DB      77                      ; Copy one char - -->
        DB      59                      ; Copy one char - F1
        DB      83                      ; Skip one char - DEL
        DB      60                      ; Copy to char - F2
        DB      62                      ; Skip to char - F4
        DB      61                      ; Copy line - F3
        DB      61                      ; Kill line (no change to template ) - Not used
        DB      63                      ; Reedit line (new template) - F5
        DB      75                      ; Backspace - <--
        DB      82                      ; Enter insert mode - INS (toggle)
        DB      82                      ; Exit insert mode - INS (toggle)
        DB      65                      ; Escape character - F7
        DB      65                      ; End of table
ESCEND LABEL BYTE
ESCTABLEN EQU   ESCEND-ESCTAB

ESCFUNC LABEL   WORD
        short_addr  GETCH               ;Ignore the escape sequence
        short_addr  TWOESC
        short_addr  EXITINS
        short_addr  ENTERINS
        short_addr  BACKSP
        short_addr  REEDIT
        short_addr  KILNEW
        short_addr  COPYLIN
        short_addr  SKIPSTR
        short_addr  COPYSTR
        short_addr  SKIPONE
        short_addr  COPYONE
        short_addr  COPYONE
        short_addr  CTRLZ

;---------------------------------------------------------------------- ;
        I_am    internal_val_seg,WORD                                   ;
        PUBLIC  FCBtabl                                                 ;
FCBtabl LABEL   DWORD           ; [SYSTEM] file table                   ;
        DW      -1              ; [SYSTEM] link to next table           ;
        DW      -1              ; [SYSTEM] link seg to next table       ;
        public  number_of_FCBs                                          ;
number_of_FCBs  label   word                                            ;
        DW      4               ; [SYSTEM] Number of entries in table   ;
;---------------------------------------------------------------------- ;

V86TABLE   ENDS

;
; OEMFunction key is expected to process a single function
;   key input from a device and dispatch to the proper
;   routines leaving all registers UNTOUCHED.
;
; Inputs:   CS, SS are V86GROUP
; Outputs:  None. This function is expected to JMP to one of
;           the following labels:
;
;           GetCh       - ignore the sequence
;           TwoEsc      - insert an ESCChar in the buffer
;           ExitIns     - toggle insert mode
;           EnterIns    - toggle insert mode
;           BackSp      - move backwards one space
;           ReEdit      - reedit the line with a new template
;           KilNew      - discard the current line and start from scratch
;           CopyLin     - copy the rest of the template into the line
;           SkipStr     - read the next character and skip to it in the template
;           CopyStr     - read next char and copy from template to line until char
;           SkipOne     - advance position in template one character
;           CopyOne     - copy next character in template into line
;           CtrlZ       - place a ^Z into the template
; Registers that are allowed to be modified by this function are:
;           AX, CX, BP

Procedure   OEMFunctionKey,NEAR
        ASSUME  DS:NOTHING,ES:NOTHING
        extrn   intCNE0:near            ;AN000; 2/17/KK
        CALL    intCNE0                 ;AN000; 2/17/KK
;;;;;;;;invoke  $std_con_input_no_echo  ; Get the second byte of the sequence
        MOV     CL,ESCTABLEN            ; length of table for scan
        PUSH    DI                      ; save DI (cannot change it!)
        MOV     DI,OFFSET V86GROUP:ESCTAB   ; offset of second byte table
        REPNE   SCASB                   ; Look it up in the table
        POP     DI                      ; restore DI
        SHL     CX,1                    ; convert byte offset to word
        MOV     BP,CX                   ; move to indexable register
        JMP     ESCFUNC[BP]             ; Go to the right routine


EndProc OEMFunctionKey

V86CODE            ENDS

V86CODE SEGMENT
        EXTRN   RetExePatch: near       ;MsProc.asm
V86CODE ENDS


V86DATA SEGMENT
        assume  cs:V86DATA

PUBLIC  DosHasHMA,fixexepatch,RationalPatchPtr,RatBugCode,UmbSave1

;
; DosHasHMA - This flag is set by seg_reinit when the DOS actually
;       takes control of the HMA.  When running, this word is a reliable
;       indicator that the DOS is actually using HMA.  You can't just use
;       CS, because ROMDOS uses HMA with CS < F000.



DosHasHMA               db      0
FixExePatch             dw      offset V86GROUP:RetExePatch
RationalPatchPtr        dw      offset V86GROUP:RetExePatch


RatBugCode proc far
        push    cx
        mov     cx, word ptr ds:[10h]
        loop    $
        pop     cx
        ret
RatBugCode endp

UmbSave1        db      0bh dup (?)     ; M023

V86DATA ENDS
        END
