Back to home page

DOS ain't dead

Forum index page

Log in | Register

Back to the forum
Board view  Mix view

opinion (Developers)

posted by Ninho E-mail, 29.05.2011, 16:36

> Possibly disagree. Have to see source code.

Here you have it as written this morning, raw cut&paste - the whole installation section, I can't seem to be able to copy the whole source into this box nor is it necessary - refer to the v 1.5 for context. It's unpolished, untested and just to give you crumbles to attack until I give you more food :=)


;-------------------------------------------- installation
align 16

; everything before this point /might/ be trashed by further processing,
; offset (from initial PSP) MUST be >= max resident's size (currently 1F0h)
.ERRNZ $-Firstb LT 0F0h ; resident size minus 100h bytes
NMCB DB "M" ; or "Z"
NOwner DW 0 ; owner
NParas DW 0 ; size
DB 11 dup (?)

NPSP DW 40h/2 dup (?) ; new mini-PSP while installing
Shft EQU 10h+(NPSP-firstb) shr 4 ; #paras from old to new PSP
Shftb = Shft shl 4 ; #bytes dø
doinstall:
if ?ATCHECK
; (skipped)
endif ; ?ATCHECK

; KBINST3 : enhanced conventional memory use.

; : copy MCB and PSP (to NMCB)
; : adjust seg reference in copied PSP
; : adjust new MCB, mark self-owned.
; : activate new PSP
; : split our own container at newMCB
; : *CLI*
; : *manually* mark our low part, and environment (if any) MCBs owner-free
; : DOS-allocate resident block (from low) see note 2 below
; : *STI*
; : copy resident part down into new block.
; : set ptrs to previous ints 15 & optional 2F (in new code)
; : activate new ints
; : done! back to caller (DOS) by int 21/4C

;Notes:
;1- we never execute from freed memory,
;2- we use int 21/48 rather than duplicate its function. We are not worried that
; DOS will STI internally, TSRs interrupting int21 should know how to behave.

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

; 1 - copy MCB+PSP out of the way (10h+40h bytes !) -> NMCB,NPSP
mov cx,(10h+40h)/2 ; size of MCB+size of mini-PSP
CLD
MOV AX, CS:[psp]
DEC AX ; AX: seg oldMCB
MOV DS, AX ; Assume DS: oldMCB
mov BX, AX
add BX, Shft ; BX: seg newMCB
MOV ES, BX ; Assume ES: newMCB
sub si, si
sub di, di
rep movsw ; copy 5 paras, from MCB (really)
inc BX ; BX: seg newPSP
mov es:[10h+36h], BX; adjust seg(handles pointer)

; 2 - prepare new MCB, keeping copied M or Z signature
mov es:[1], BX ; owner (self)
sub word ptr es:[3], Shft ; size

; 3 - make copied PSP active :
mov ah, 50h
int 21h ; ASSUME BX:newPSP

; 4 - *CLI*. Adjust Original MCB to cover only up to NewMCB, and mark it FREE.
CLI ; protection
mov byte ptr ds:[0], 'M' ; signature
mov word ptr ds:[3], Shft-1 ; paragraphs
mov word ptr ds:[1], 0 ; mark free !

; 5 - Mark our environment block, if any, FREE :
mov CX,DS:[10h+2Ch]
jcxz @F
DEC CX
mov ES, CX
MOV word ptr ES:[1], 0 ; owner=None
@@:
; 6 - ask DOS for a suitable block; make it owned by system
; calculate resident size.
if ?SUPPINT2F
mov BX, offset EndofInt2F
test byte ptr inst2f,01
jnz @F
endif
mov BX, offset EndofInt15
@@:
mov al, BL
shr BX, 4
and al,0fh
jz @F
inc BX
@@:
mov prglen, BX ; local store (BP rel)

mov AH, 48h ; DOS allocate for resident code
int 21h ; will STI internally, not a problem
; JC XXXX ; ... error? shouldn't happen :=) TODO
...rec mov CS:[psp], AX ; to be kept by resident copy
push AX
dec ax ; MCB of new block
mov ES, AX
mov bx, 0008
mov es:[0001], bx ; owner = System
xor si,si
xor di,di
mov word ptr es:[BX],"BK" ; indicator = "KBF"
mov word ptr es:[BX+2]," F"
pop ES

; 7 - Copy resident part to its final place :
INT 3
; ES: newly allocated for Resident Segment
mov BX, KBRES ; segment
mov DS, BX ; source
mov cx,prglen ; paragraphs
shl cx,3 ; -> words
rep movsw

; 4.5 - set pointers to previous ints in resident code :
push ES
pop DS ; resident segment

ASSUME DS: KBRES ; in fact, DS: *new* Resident Segment
mov ax, 3515h
int 21h
mov word ptr orgint15+0, bx
mov word ptr orgint15+2, es

if ?SUPPINT2F
test byte ptr inst2f,01
jz @F
mov ax, 352Fh
int 21h
mov word ptr orgint2f+0, bx
mov word ptr orgint2f+2, es
ASSUME DS: NOTHING

@@:
endif

; 5 - Activate interrupt hook(s) :
if NOT ?KBZERO
if ?KBFR ; make sure dead key related flags are reset :
PUSH DS
push 40h ; BIOS data seg
pop ds
ASSUME ds:BIOSSEG
and Cflags, not 3
POP DS
ASSUME DS:nothing
endif
endif

INT 3
; ASSUME DS: new (resident) segment
mov dx,offset introu15
mov ax,2515h
; push ds
int 21h
; pop ds
if ?SUPPINT2F
test byte ptr inst2f,01 ; local storage
jz @F
mov dx,offset introu2f
mov ax, 252fh
int 21h
@@:
endif
INT 3

; 6 - Installation done, return to DOS.

mov ax,4c00h
int 21h

main endp
; ---------------------------------------------------------------------

---
Ninho

 

Complete thread:

Back to the forum
Board view  Mix view
22049 Postings in 2034 Threads, 396 registered users, 250 users online (0 registered, 250 guests)
DOS ain't dead | Admin contact
RSS Feed
powered by my little forum