; Program:      WSSHLFIX
; Author:       Jay Sage
; Date:         March 26, 1988

; This code is a configuration overlay to correct a problem in the shell
; handling code in WordStar Release 4.
;
; Problem:  WS takes a mistaken shortcut when installing its name on the shell
; stack.  If the stack is currently empty, it does not bother to push the
; entries up.  However, when it exits, it does pop the stack, at which point
; any garbage that had been in the stack becomes the active shell.  This patch
; makes sure that the second stack entry is null in that case.

;---- Addresses

initsub equ     03bbh
exitsub equ     03b3h
morpat  equ     045bh

;---- Patch code

       org     initsub         ; Initialization subroutine patch

init:   jp      initpatch

;----

       org     morpat          ; General patch area

initpatch:                      ; Initialization patch
       ld      hl,(109h)       ; Get ENV address
       ld      de,1eh          ; Offset to shell stack address
       add     hl,de           ; Pointer th shell stack address in HL
       ld      e,(hl)          ; Address to DE
       inc     hl
       ld      d,(hl)
       ld      a,(de)          ; See if first entry is null
       or      a
       ret     nz              ; If not, we have no problem
       inc     hl              ; Advance to ENV pointer to
       inc     hl              ; ..size of stack entry
       ld      l,(hl)          ; Get size into HL
       ld      h,0
       add     hl,de           ; Address of 2nd entry in HL
       ld      (hl),0          ; Make sure that entry is null
       ret

       end