;       SCCSID = @(#)bitmap.asm 6.11 92/03/19
        page    66,80
        title   Bitmap, OS/2 logo boot screen - Part 1
SCCSID  equ     "@(#)bitmap.asm         6.01 94/03/15"
;*****************************************************************************
;                       IBM Confidential
;
;            Copyright (c) IBM Corporation 1987, 1989
;
;       All Rights Reserved
;*****************************************************************************
;
; SOURCE FILE NAME: Bitmap
;
; DESCRIPTIVE NAME: OS/2 logo boot screen
;
; STATUS: OS/2 2.0
;
; FUNCTION: Display OS/2 logo boot screen
;
; NOTES:
;   DEPENDENCIES: None
;   RESTRICTIONS: None
;
; ENTRY POINTS: syiNextBMPSection
;               syiSetupForBMP
;
; EXTERNAL REFERENCES:
;               DHF.DosHlpCallInt10  -DosHelp to call Int10
;               RealModeIC           -switch to real mode
;               ProtModeIC           -switch to protect mode
;               syiDisplayMessage    -Used to display default banner
;               AllocateGDTSelector  -like it says
;               FreeGDTSelector      -ditto
;               PhysToGDTSelector    -map video memory to selector
;
;*****************************************************************************
; Revision History:
; ID    Date     Description
; ----  -------- ------------------------------------------------------------
; D1357 9/3/91   DCR 1357 Suppress boot messages
;---------------------------------------------------------------------------


;INTERNALREVISION = 1 if we want to display internal revision level
;INTERNALREVISION = 0 if we want don't to display it

INTERNALREVISION EQU 0

;DOCOPYRIGHT = 1 if copyright is not part of bitmap (we need to display it).
;DOCOPYRIGHT = 0 if copyright is part of bitmap (we don't need to display it).

DOCOPYRIGHT  EQU 1



       .xlist
        include basemaca.inc
        include basemid.inc
        include dosseg.inc
        include osmaca.inc
        include doshlp.inc
        include mi.inc
        include sicg.inc
        include infoseg.inc
        include ldrvars.inc
        include tkexport.inc
        include pmode.inc
        include vmowner.inc
        include fnoinit.inc
        include struc.inc             ; Structured assembler macros
        include inisms.inc            ; SysInit Message Segment
        include iodelay.inc
        .list

        ModName  , FNO_BITMAP_ASM
        CpuMode 386

BLUE_PLANE      EQU  0
GREEN_PLANE     EQU  1
RED_PLANE       EQU  2
INTENSE_PLANE   EQU  3

COPYRIGHTLINE     EQU  25
HEADERLINE        EQU  29

VGA_ADDRESS       EQU  0A0000H


        extrn           ProtModeIC:near
        extrn           RealModeIC:near
        extrn           syiDisplayMessage:near

        extrn           SYICloseFile:near
        extrn           SYIOpenFile:near
        extrn           SYIReadFile:near
        extrn           syiReadAtFile:near
        extrn           _EP2_32_Decompress:near


        EXTRNFAR        PhysToGDTSelector
        EXTRNFAR        AllocateGDTSelector
        EXTRNFAR        FreeGDTSelector
        EXTRNFAR        w_SICG
        EXTRNFAR        SegAlloc
        EXTRNFAR        SegFree

        EXTRNF32        _TKSetSSBase

        ReferGlobal     SISData,BYTE
        ReferGlobal     DHF,DWORD

        ReferInitGlobal pBanner,dword
        ReferInitGlobal sicg_packet_16,word
        ReferInitGlobal sicg_packet_16_d,byte
        ReferInitGlobal command_string,byte

        ReferGDT        GDT_MSSTACK,WORD

        extrn           MSSTACKSIZE:ABS

        extrn           Header:byte
        extrn           HeaderLen:ABS
        EXTRN           _SELVirtToLin:near

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

INITDATA segment
   videosave63h    dd      0
   videosave60h    dd      0
   videosave4ch    dd      0
   videosave49h    dd      0
   videosave10h    dw      0
   videosave84h    dd      0
   videosave88h    dw      0
   ;temporary gdt selector
   gdtsel          dw      0
LOGO_filespec       db "OS2LOGO",0

public   tbl_syibanner                          ;D1357
tbl_syibanner    SMT    <MSG_SYSINIT_BANNER,1>
if INTERNALREVISION
                        SMT_Var <Header>
else
                        SMT_Var <Blank>
   Blank            db     " ",0
endif
INITDATA ends



CINIT_DATA segment

   outbuff_virt         dd     0
   outbuff_lin          dd     0
   logo_selector        dw      0
   logo_linaddr         dd      0

   public   dologo
   dologo                 db     0     ; initially set to "don't do logo"

   ColorPaletteTable   db   0h,  0h,  0h, 0h
                       db   0h,  0h, 28h, 0h
                       db   0h, 28h,  0h, 0h
                       db   0h, 28h, 28h, 0h
                       db  28h,  0h,  0h, 0h
                       db  28h,  0h, 28h, 0h
                       db  28h, 28h,  0h, 0h
                       db  20h, 20h, 20h, 0h
                       db  35h, 35h, 35h, 0h
                       db   0h,  0h, 3fh, 0h
                       db   0h, 3fh,  0h, 0h
                       db   0h, 3fh, 3fh, 0h
                       db  3fh,  0h,  0h, 0h
                       db  3fh,  0h, 3fh, 0h
                       db  3fh, 3fh,  0h, 0h
                       db  3fh, 3fh, 3fh, 0h

   MonoPaletteTable    db  00h, 00h, 00h, 0h
                       db  09h, 09h, 09h, 0h
                       db  19h, 19h, 19h, 0h
                       db  1eh, 1eh, 1eh, 0h
                       db  0dh, 0dh, 0dh, 0h
                       db  11h, 11h, 11h, 0h
                       db  22h, 22h, 22h, 0h
                       db  20h, 20h, 20h, 0h
                       db  35h, 35h, 35h, 0h
                       db  18h, 18h, 18h, 0h
                       db  27h, 27h, 27h, 0h
                       db  2eh, 2eh, 2eh, 0h
                       db  1dh, 1dh, 1dh, 0h
                       db  20h, 20h, 20h, 0h
                       db  37h, 37h, 37h, 0h
                       db  3fh, 3fh, 3fh, 0h

    VRAM0_start  DD 0   ; Starting file offset of VRAM0 info
    VRAM0_size   DD 0   ; Size of VRAM0 info
    VRAM1_start  DD 0   ; Starting file offset of VRAM1 info
    VRAM1_size   DD 0   ; Size of VRAM1 info
    VRAM2_start  DD 0   ; Starting file offset of VRAM2 info
    VRAM2_size   DD 0   ; Size of VRAM2 info
    VRAM3_start  DD 0   ; Starting file offset of VRAM3 info
    VRAM3_size   DD 0   ; Size of VRAM3 info

CINIT_DATA ends



;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
        FARCODE INIT
INITCODE segment
;   assume cs:INITCODE
    assume ds:FLAT, es:FLAT, fs:nothing, gs:nothing, ss:nothing


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;*****************************************************************************
;
;    Procedure syiFillColor
;
;    Entry:
;          ECX = color plane
;          EBX = starting address
;          ESI = length
;
;*****************************************************************************

Procedure syiFillColor, near
        EnterProc

        pushad
        push    ecx

        mov     edx,03c4h
        mov     eax,02
        out     dx,al
        kIODelay   di
        mov     edx,03c5h
        mov     eax,01h
        pop     ecx
        shl     eax,cl  ;bit in AL that is turned on will be map that's enabled
        out     dx,al   ;Map Mask Register
        kIODelay   di

        mov     edx,03ceh
        mov     eax,04
        out     dx,al
        kIODelay   di
        mov     edx,03cfh
        mov     eax,ecx   ;al=mapnumber
        out     dx,al     ;read map select (because we "or", it's a read/write
                          ;   so we need to set this)

        mov     eax,outbuff_lin
        mov     edx,640*480/8


        CCALL32 _EP2_32_Decompress <esi,edx,ebx,eax>, nocall
        add     esp,10h   ; Pop parameters off stck

                 ; EP2_32_Decompress(cbIn,    //Size of SrcBuf
                 ;                  (ulong_t)PAGESIZE, //Size of DstBuf
                 ;                   pBuff,             //Source buffer
                 ;                   pPage )))          //Destination Buffer


        mov     dx,03c4h
        mov     al,02
        out     dx,al
        kIODelay   di
        mov     dx,03c5h
        mov     al,0fh    ;all maps selected
        out     dx,al     ;set register back to default
        kIODelay   di
        popad
        LeaveProc
        RETC
EndProc syiFillColor

;*****************************************************************************
;
;    Procedure syiSetupPMPallete
;
;    Entry:
;
;*****************************************************************************

Procedure syiSetupPMPallete, near
        EnterProc

        pushad


 ; Setup pallette
        xor   eax,eax
        mov   edx,03c8h
        out   dx,al

        DosInitContext  es
        mov     al,BYTE PTR es:videosave49h ;Get video mode
        FlatContext     es
        .if <al eq 7>                    ;mono,
           lea   esi,MonoPaletteTable    ; use mono palette table
        .else                            ;otherwise (color),
           lea   esi,ColorPaletteTable   ; use color palette table
        .endif
        mov   ecx,10h

        mov   edx,03c9h
spp_next_pallette:
        db    67h         ; Make it use DS:ESI rather than DS:SI
        lodsd
        out   dx, al
        kIODelay   di
        ror   eax,8
        out   dx, al
        kIODelay   di
        ror   eax,8
        out   dx, al
        kIODelay   di
        dec   ecx
        jnz   spp_next_pallette


 ; Setup pallette indices
        xor   bx,bx
        mov   cx,10h

        mov   dx,03dah        ;Status Register 1
        in    al,dx           ;reset address flip-flop
        kIODelay   di

        xor   ax,ax
        mov   dx,03c0h        ; Set color index to 0
        out   dx,al
        kIODelay   di

spp_next_index:
        mov   dx,3dah         ;Status Register 1
        in    al, dx          ;reset address flip-flop
        kIODelay   di

        mov   dx,3c0h         ; Set index
        mov   al,bl
        out   dx, al
        kIODelay   di

        out   dx, al          ; Set attribute address
        kIODelay   di

        inc   bx
        dec   cx
        jnz   spp_next_index


        popad
        LeaveProc
        RETC
EndProc syiSetupPMPallete

;*****************************************************************************
;
;    Procedure syiEnableVideo
;
;    Entry:
;
;*****************************************************************************

Procedure syiEnableVideo, near
        push  ax
        push  dx



        mov   dx,03dah             ;Status Register 1
        in    al, dx               ;reset address flip-flop
        kIODelay   di

        mov   al,20h
        mov   dx,03c0h             ;Re-enable video

        out   dx,al
        kIODelay   di

        pop   dx
        pop   ax
        RETC
EndProc syiEnableVideo

;*****************************************************************************
;
;    Procedure syiProcessLogoFile
;
;    Entry:
;
;*****************************************************************************

Procedure syiProcessLogoFile, near
        EnterProc
        pushad
        FlatContext <ds,es>

        mov     cx, outbuff_virt.Segmt
        xor     esi,esi
        CCALL32 _SELVirtToLin <esi, ecx>
        cmp     eax, -1
        jz      plf_panic
        mov     outbuff_lin,eax

        mov     cx, logo_selector
        xor     esi,esi
        CCALL32 _SELVirtToLin <esi, ecx>
        cmp     eax, -1
        jz      plf_panic
        mov     logo_linaddr,eax

        call    syiSetupPMPallete

         mov     ax,logo_selector
         shl     eax,16          ; eax = virt addr of buffer to read into
         mov     ebx,VRAM0_start ; ecx = start of VRAM0 info
         mov     ecx,VRAM0_size  ; ecx = size of VRAM0 info
         call    syiReadAtFile

        mov     ebx,logo_linaddr ;Get offset to VRAM0 data
        mov     esi,VRAM0_size   ;Get size of VRAM0 data
        xor     ecx,ecx          ; Set ECX=0
        call    syiFillColor

         mov     ax,logo_selector
         shl     eax,16          ; eax = virt addr of buffer to read into
         mov     ebx,VRAM1_start ; ecx = start of VRAM1 info
         mov     ecx,VRAM1_size  ; ecx = size of VRAM1 info
         call    syiReadAtFile

        mov     ebx,logo_linaddr ;Get offset to VRAM1 data
        mov     esi,VRAM1_size   ;Get size of VRAM1 data
        mov     ecx,1           ; Set ECX=1
        call    syiFillColor

         mov     ax,logo_selector
         shl     eax,16          ; eax = virt addr of buffer to read into
         mov     ebx,VRAM2_start ; ecx = start of VRAM2 info
         mov     ecx,VRAM2_size  ; ecx = size of VRAM2 info
         call    syiReadAtFile

        mov     ebx,logo_linaddr ;Get offset to VRAM2 data
        mov     esi,VRAM2_size   ;Get size of VRAM2 data
        mov     ecx,2           ; Set ECX=2
        call    syiFillColor

         mov     ax,logo_selector
         shl     eax,16          ; eax = virt addr of buffer to read into
         mov     ebx,VRAM3_start ; ecx = start of VRAM3 info
         mov     ecx,VRAM3_size  ; ecx = size of VRAM3 info
         call    syiReadAtFile

        mov     ebx,logo_linaddr ;Get offset to VRAM3 data
        mov     esi,VRAM3_size   ;Get size of VRAM3 data
        mov     ecx,3           ; Set ECX=3
        call    syiFillColor

        call    syiEnableVideo

        popad
        LeaveProc
        RETC
plf_panic:
        Panic "ProcessLogoFile:Bad Linear Address"

EndProc syiProcessLogoFile



Procedure syiBlastLogo, near
     assume ds:nothing, es:nothing
        EnterProc
        pushad
        push    ds
        push    es

        DosInitContext <es>
        lea     di, DOSINITDATA:LOGO_filespec
        call    SYIOpenFile

        .if nc and near                 ; File is found
         ; Get size in eax         ;Do this after check for carry!
         rol     eax,16            ;
         mov     ax,bx             ;
        .if <eax ge 20h> near           ; and is at least 20h bytes long


            xor     ax,ax                        ;ax:bx = size to alloc
            mov     bx,9600h
            mov     cl, SA_GDT                   ; flags
            mov     ch, D_DATA0                  ; access rights
            mov     si, HF_MOVABLE+HF_LOWMEM     ; flags
            mov     di, INITOWNER                ; owner
            xor     dx,dx                        ; ptda handle
            CALLFAR SegAlloc        ; returns (bx) = selector (ax) = handle

            push    es
            FlatContext <es>
            mov     logo_selector,bx
            pop     es

            mov     ax,bx           ; ax:bx = seg:off of buffer to read into
            xor     bx,bx
            xor     cx,cx
            mov     dx,20h          ; read header
            call    SYIReadFile

            push    es
            push    ds
            FlatContext <es>
            mov     ax,logo_selector
            push    ax
            pop     ds
            xor     si,si
            lea     edi, VRAM0_start
            mov     cx,8
            .while  <cx ne 0>
               mov     eax,DWORD PTR ds:[si]
               mov     DWORD PTR es:[edi],eax
               add     si,4
               add     edi,4
               dec     cx
            .endwhile

            pop     ds
            pop     es


            call    syiProcessLogoFile

            call    SYICloseFile
            push    es
            FlatContext <es>
            mov     ax,logo_selector
            pop     es

            CALLFAR  SegFree        ; free segment, selector in ax

        .else
           ; Logo file must not exist.  Reset video state and simply
           ; display copyright.

           call    syiResetVideoMode
           call    syiBMPRestoreBIOSData

           DosInitContext <ds>,ax
           lea     si,tbl_syibanner
           call    syiDisplayMessage  ;put up message the old way
           FlatContext <ds>,ax
           mov     dologo,0           ; set flag, don't do logo

        .endif


        pop     es
        pop     ds
        popad
        LeaveProc
        RETC
EndProc syiBlastLogo


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


Procedure syiSetupForBMP, <far16,faronly>
    assume ds:FLAT, es:nothing, fs:nothing, gs:nothing, ss:nothing
        pushad
        FlatContext <DS,ES>

        push    ds
        push    es
        call    syiSetVideoMode
        pop     es
        pop     ds

        call    syiBMPGetSelector

        call    syiBlastLogo

if DOCOPYRIGHT
;       call    syiBMPDoCopyright
endif
if INTERNALREVISION
        call    syiBMPDoRevision
endif



        call    syiBMPFreeSelector

        popad
        RETC

EndProc syiSetupForBMP


Procedure syiSetVideoMode, <near>

;
;       Switch to real mode
        pushad
        push    ds
        push    es

        DosInitContext <ds>,ax
        mov     ax,40h
        mov     es,ax                ;
        mov     eax,es:[49h]         ;
        mov     ds:videosave49h,eax  ;
        mov     eax,es:[4ch]         ; Save video info from 40:0 area
        mov     ds:videosave4ch,eax  ;
        mov     eax,es:[60h]         ;
        mov     ds:videosave60h,eax  ;
        mov     eax,es:[63h]         ;
        mov     ds:videosave63h,eax  ;
        mov     ax,es:[10h]          ;
        mov     ds:videosave10h,ax   ;
        mov     eax,es:[84h]         ;
        mov     ds:videosave84h,eax  ;
        mov     ax,es:[88h]          ;
        mov     ds:videosave88h,ax   ;

        DosContext <ds>,ax
        call    RealModeIC

        xor     ax, ax               ;al=0   get display combo code
        mov     ah, 1ah              ;ah=1ah read/write display combo function
        call    DHF.DosHlpCallInt10
        cmp     al, 1ah              ;this function supported?
        jne     svm_notvga           ;no, can't do logo
        cmp     bl, 0ffh             ;display unknown?
        je      svm_notvga           ;yes, can't do logo
        cmp     bl, 07h              ;display below VGA level?
        jb      svm_notvga           ;yes, can't do logo

        mov     ah, 0fh            ;Get video mode
        call    DHF.DosHlpCallInt10
        push    ax                 ;Save video mode

        xor     ah, ah             ;Set video mode
        mov     al, 12h            ;640X480 16 color
        call    DHF.DosHlpCallInt10

        mov     ah, 0fh            ;Get video mode
        call    DHF.DosHlpCallInt10
        cmp     al,12h             ;mode set correctly?
        pop     ax
        je      svm_modeOK         ;

  ;Mode wasn't set correctly, can't do logo.

        xor     ah, ah             ;Set mode back to what it was (AL is set)
        call    DHF.DosHlpCallInt10

svm_notvga:
        call    ProtModeIC

        DosInitContext <ds>,ax
        lea     si,tbl_syibanner
        call    syiDisplayMessage  ;put up message the old way
        pop     es
        pop     ds
        popad
        mov     dologo,0           ; set flag, don't do logo
        jmp     svm_x


svm_modeOK:

        call    ProtModeIC
        pop     es
        pop     ds
        popad
        mov     dologo,1           ; set flag to do logo
svm_x:
        RETC
EndProc syiSetVideoMode


Procedure syiResetVideoMode, <faronly,near>
        pushad
        push    es
        push    ds

        FlatContext <ds>,ax
        mov     al, dologo
        test    al, al
        je      rvm_x

        DosInitContext  es
        xor     ah, ah                     ;Set video mode
        mov     al,BYTE PTR es:videosave49h;to what it was before

       ; Set stack to below-1MB stack
        mov     cx,ss                   ; save current SS:SP in CX:DX
        mov     dx,sp
        push    GSEL GDT_MSSTACK        ; switch to mode switch stack
        pop     ss
        mov     sp,MSSTACKSIZE          ; SS:SP -> top of mode switch stack

        push    eax
        push    ecx
        push    edx
        push    ds
        FlatContext ds,ax,NOASSUME
        CALLF32 _TKSetSSBase,,nocheck   ; Must do after every stack switch
        pop     ds
        pop     edx
        pop     ecx
        pop     eax

        push    cx                      ; save stack link
        push    dx

        DosContext <ds>
        call    RealModeIC
        push    ax

        xor     ah, ah              ;Set video mode
        mov     al, 12h             ;640X480 16 color
        call    DHF.DosHlpCallInt10 ; This call is neccessary to get around
                                    ; a BIOS bug if switching to mode 7.
        pop     ax
        call    DHF.DosHlpCallInt10
        call    ProtModeIC

        pop     ax                      ; AX = saved SP
        pop     ss                      ; switch stacks
        mov     sp,ax

        push    eax
        push    ecx
        push    edx
        push    ds
        FlatContext ds,ax,NOASSUME
        CALLF32 _TKSetSSBase,,nocheck   ; Must do after every stack switch
        pop     ds
        pop     edx
        pop     ecx
        pop     eax

rvm_x:
        pop     ds
        pop     es
        popad
        RETC
EndProc syiResetVideoMode


if DOCOPYRIGHT

Procedure syiBMPDoCopyright, near
        assume  ds:nothing, es:nothing
        pushad
        push    ds
        push    es

        DosInitContext <ds>,ax

        les     di,[pBanner]
        assume  es:nothing
        mov     bx,es:[di]                       ; bx = length
        inc     di
        inc     di

cr_checknextfront:
        mov     al, es:[di]
        cmp     al,0DH
        je      cr_chopofffront
        cmp     al,0AH
        je      cr_chopofffront
        jmp     cr_thrufront

cr_chopofffront:
        inc     di
        dec     bx
        jmp     cr_checknextfront

cr_thrufront:

cr_checknextback:
        mov     al, es:[di+bx-1]
        cmp     al,0DH
        je      cr_chopoffback
        cmp     al,0AH
        je      cr_chopoffback
        cmp     al,'%'
        je      cr_chopoffback
        cmp     al,'1'
        je      cr_chopoffback
        jmp     cr_thruback

cr_chopoffback:
        dec     bx
        jmp     cr_checknextback

cr_thruback:

        mov     cx,bx                            ; cx = length
        mov     bp,di                            ; (es:bp) = message text
        mov     edx, (COPYRIGHTLINE*0100h)+0     ; dx = row, column
        mov     ebx, 08h                         ; bh = page # (0 based)
                                                 ; bl = attribute
        mov     eax, 1301h                       ; ah = 13H (function)
                                                 ; al = 01H move cursor
        DosContext <ds>
        call    RealModeIC

        call    DHF.DosHlpCallInt10

        call    ProtModeIC


        pop     es
        pop     ds
        popad
        RETC
EndProc syiBMPDoCopyright
endif


if INTERNALREVISION
Procedure syiBMPDoRevision, <near>
        assume  ds:nothing, es:nothing
        pushad
        push    ds
        push    es

        DosContext <es>,ax

        mov     di,offset DOSGROUP:Header
        mov     bx,HeaderLen                     ; bx = length

rev_checknextfront:
        mov     al, es:[di]
        cmp     al,0DH
        je      rev_chopofffront
        cmp     al,0AH
        je      rev_chopofffront
        jmp     rev_thrufront

rev_chopofffront:
        inc     di
        dec     bx
        jmp     rev_checknextfront

rev_thrufront:

rev_checknextback:
        mov     al, es:[di+bx-1]
        cmp     al,0DH
        je      rev_chopoffback
        cmp     al,0AH
        je      rev_chopoffback
        jmp     rev_thruback

rev_chopoffback:
        dec     bx
        jmp     rev_checknextback

rev_thruback:
        cmp     bx,3
        jbe     rev_x

        mov     cx,bx                            ; cx = length
        mov     bp,di                            ; (es:bp) = message text
        mov     edx, (HEADERLINE*0100h)+0        ; dx = row, column
        mov     ebx, 08h                         ; bh = page # (0 based)
                                                 ; bl = attribute
        mov     eax, 1301h                       ; ah = 13H (function)
                                                 ; al = 01H move cursor
        DosContext <ds>
        call    RealModeIC

        call    DHF.DosHlpCallInt10

        call    ProtModeIC

rev_x:
        pop     es
        pop     ds
        popad
        RETC
EndProc syiBMPDoRevision

endif



;*****************************************************************************
;
;    Procedure syiBMPStandBy
;
;    Entry:
;           DX = cursor location to start string (dh=row,dl=column)
;
;*****************************************************************************

Procedure syiBMPStandBy, <faronly,far16>
        assume  ds:nothing, es:nothing
        pushad
        push    ds
        push    es


        FlatContext <ds>,ax
        mov     al, dologo
        test    al, al
        je      bsb_x

        DosContext      es

        DosInitContext DS,ax

        mov     ax,MSG_STAND_BY
        mov     sicg_packet_16_d.sicg_msg_num,ax
        mov     ax,offset DOSINITDATA:command_string
        mov     sicg_packet_16_d.sicg_msg_buf.Offst,ax
        push    ds
        pop     ax
        mov     sicg_packet_16_d.sicg_msg_buf.Segmt,ax
        mov     si,offset DOSINITDATA:sicg_packet_16
                                                 ;ds:si -> packet
        CALLFAR w_SICG
        mov     si,offset DOSINITDATA:command_string
        mov     cx,ds:[si]
        sub     cx,2
        mov     bx,cx
        add     si,2

        cmp     bx,5
        jle     sb_dontadddots
        mov     BYTE PTR ds:[si+bx-4],'.'               ;add trailing ...
        mov     BYTE PTR ds:[si+bx-3],'.'
        mov     BYTE PTR ds:[si+bx-2],0DH               ;add trailing CRLF
        mov     BYTE PTR ds:[si+bx-1],0AH
sb_dontadddots:
        sub     bx,2                             ; bx = length of string
        shr     bx,1                             ; divide by two
        mov     ax,40
        sub     ax,bx                            ; subtract from 40 to get
        mov     dl,al                            ; starting column (put in DL)

                                                 ; cx = length
                                                 ; dx = row, column
        push    ds
        pop     es
        mov     bp,si                            ; (es:bp) = message text
        mov     ebx, 0007h                       ; bh = page # (0 based)
                                                 ; bl = attribute
        mov     eax, 1301h                       ; ah = 13H (function)
                                                 ; al = 01H move cursor
        DosContext <ds>
        call    RealModeIC

        call    DHF.DosHlpCallInt10

  ;Now hide cursor

        xor     bx,bx                            ; bh = page # (0 based)
                                                 ; bl = attribute (black/black)
        mov     cx,1                             ; cx = # chars
        mov     al,' '                           ; al = char to write
        mov     ah,09h                           ; ah = 09H (function
        call    DHF.DosHlpCallInt10

        call    ProtModeIC

bsb_x:
        pop     es
        pop     ds
        popad
        RETC
EndProc syiBMPStandBy


Procedure syiBMPRestoreBIOSData, <faronly,near>
     assume  ds:nothing, es:nothing
     push    eax
     push    ds
     push    es
     FlatContext <ds>,ax
     mov     al, dologo
     test    al, al
     je      rbd_x

     DosInitContext <ds>,ax
     mov     ax,40h
     mov     es,ax                ;
     mov     eax,ds:videosave63h  ;
     mov     es:[63h],eax         ;
     mov     eax,ds:videosave60h  ;
     mov     es:[60h],eax         ; Restore video info from 40:0 area
     mov     eax,ds:videosave4ch  ;
     mov     es:[4ch],eax         ;
     mov     eax,ds:videosave49h  ;
     mov     es:[49h],eax         ;
     mov     ax,ds:videosave10h   ;
     mov     es:[10h],ax          ;
     mov     eax,ds:videosave84h  ;
     mov     es:[84h],eax         ;
     mov     ax,ds:videosave88h   ;
     mov     es:[88h],ax          ;

rbd_x:
     pop     es
     pop     ds
     pop     eax
     RETC
EndProc syiBMPRestoreBIOSData



Procedure syiBMPGetSelector, <far16,near>
        assume  ds:FLAT
        push    es
        DosInitContext  <es>,di
        mov     di,offset INITDATA:gdtsel
        mov     cx,1
        CALLFAR AllocateGDTSelector

        mov     cx, 095ffh       ;cx = size
        xor     bx, bx           ;ax:bx = 32bit physical address
        mov     ax, 0ah
        mov     si, es:[gdtsel]
        CALLFAR PhysToGDTSelector
        mov     ax,es:[gdtsel]
        mov     outbuff_virt.Segmt,ax
        pop     es
        RETC
EndProc syiBMPGetSelector




Procedure syiBMPFreeSelector, <near>
        push    ds
        DosInitContext  <ds>,ax
        mov     ax,DS:[gdtsel]
        CALLFAR FreeGDTSelector
        pop     ds
        RETC
EndProc syiBMPFreeSelector





INITCODE ends

        end
