home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
D!Zone (Collector's Edition)
/
D_ZONE_CD.ISO
/
programs
/
editors
/
dhtk100
/
swapa.asm
< prev
next >
Wrap
Assembly Source File
|
1994-12-06
|
27KB
|
711 lines
;**************************************************************************;
;* S W A P A . A S M *;
;*------------------------------------------------------------------------*;
;* Task : Assembler module for the SWAP unit *;
;*------------------------------------------------------------------------*;
;* Author : MICHAEL TISCHER *;
;* developed on : 06/01/1989 *;
;* last update : 02/28/1990 *;
;*------------------------------------------------------------------------*;
;* assembly : TASM - /MX SWAPA *;
;* ... bind to the SWAP unit *;
;**************************************************************************;
;== Constants ===============================================================
STACK_LEN equ 64 ;Number of words in the internal stack
;== Structures =============================================================
ExecStruc struc ;Data structure for EXEC function
EsSegEnv dw ? ;Segment address of environment blocks
EsCmdPAdr dd ? ;Pointer to command line parameters
EsFCB1Adr dd ? ;Pointer to FCB #1
EsFCB2Adr dd ? ;Pointer to FCB #2
ExecStruc ends
public SwapOutAndExec ;Gives a Turbo Pascal program the
;ability to pass the address of
;the assembler handler
public InitSwapa ;Initialization procedure
;== Data segment ===========================================================
DATA segment word public
extrn PrefixSeg : word ;Segment address of PSP in Turbo variables
DATA ends
;== Program ===============================================================
CODE segment byte public ;Program segment
;== Variables in code segment ===============================================
CodeStart equ this word ;Code begins here which is copied to
;the Turbo program
;-- Variables needed by the Swap routines for uploading and downloading ----
CoStAddr dd ? ;Orig. address of PARA(CodeStart)
CoStLen dw ? ;Number of words swapped w/ CoStAddr
StackPtr dw ? ;Gets old stack pointer
StackSeg dw ? ;Gets old stack segment
TurboSeg dw ? ;Segment address - Turbo code segment
;-- Variables needed for program configuration and command execution -------
NewStack dw STACK_LEN dup (?) ;New stack
EndStack equ this word ;End of stack
Command dd ? ;Pointer to command
CmdPara dd ? ;Pointer to command line parameters
ToDisk db ? ;True when disk swapping occurs
Handle dw ? ;Disk or EMS handle
Len dd ? ;Number of bytes saved
FCB1 db 16 dup ( 0 ) ;FCB #1 for PSP
FCB2 db 16 dup ( 0 ) ;FCB #2 for PSP
CmdBuf db 128 dup ( 0 ) ;Commands following prg. name
PrgName db 64 dup ( 0 ) ;Program name
ExecData ExecStruc < 0, CmdBuf, FCB1, FCB2 > ;Data structure for EXEC
OldPara dw ? ;Number of previously reserved paragraphs
FrameSeg dw ? ;Segment address of EMS page frame
Error_Code db 0 ;Error code for caller
TerMes db 13,10,13,10
db "╔═══════════════════════════════════════════════════╗",13,10
db "║ Done_Swap: Stored Turbo Pascal program could ║",13,10
db "║ not be reloaded back into memory. ║",13,10
db "║ Program execution terminated! ║",13,10
db "╚═══════════════════════════════════════════════════╝"
db 13,10,13,10,"$"
Msg1 db 13,10,13,10
db "╔════════════════════════════╗",13,10
db "║ Init_Swap: Swapping out ║",13,10
db "╚════════════════════════════╝"
db 13,10,13,10,"$"
;== Procedures =============================================================
;---------------------------------------------------------------------------
;-- StartSwap : Coordinate swapping of Turbo Pascal program
StartSwap proc far
assume cs:code, ds:nothing
;-- Store current stack and initialize new stack ----------------
cli ;Suppress interrupts
mov StackPtr,sp ;Mark current stack
mov StackSeg,ss
push cs ;Install new stack
pop ss
mov sp,offset EndStack - 2
sti ;Re-enable interrupts
push cs ;Set DS to CS
pop ds
assume cs:code, ds:code
;-- Overwrite unnecessary memory --------------------------------
cmp ToDisk,0 ;Write to EMS memory?
je Ems ;Yes ---> Ems
call Write2File ;No ---> Write to file
jnc ShrinkMem ;No error ---> ShrinkMem
mov Error_Code, 1 ;File output error?
jmp short GetBack ;return to Turbo
Ems: mov ah,41h ;Pass segment address of the page frame
int 67h ;Call EMM
mov FrameSeg,bx ;Place result in variables
call Write2Ems ;Write program to EMS
;-- Provide number of currently allocated paragraphs ------------
ShrinkMem: mov ax,TurboSeg ;Segment address of Turbo code segment
sub ax,11h ;Allocate 10 paragraphs for PSP and 1
;for MCB
mov es,ax ;ES now pointer to Turbo prog. MCB
mov bx,es:[3] ;Get number of paragraphs allocated
mov OldPara,bx ;and place in variable
;-- Calculate the number of paragraphs needed and reduce --
;-- memory requirements by this amount --
inc ax ;AX now points to the PSP
mov es,ax ;for function call to ES
mov bx,CostLen ;Number of words needed by Swap routine
add bx,128+7 ;Recalculate and round off PSP
mov cl,3 ;Divide by 8 words (per paragraph)
shr bx,cl
mov ah,4Ah ;Function number for "change size"
int 21h ;Call DOS interrupt
;-- Execute specified command line using the EXE function ------
mov bp,ds ;Store DS
mov ax,cs ;Set ES and DS to CS
mov es,ax
mov ds,ax
;-- Enter segment address of code segments in the pointer -----
;-- to the EXEC structure
mov word ptr ExecData.EsFCB1Adr + 2,ax
mov word ptr ExecData.EsFCB1Adr + 2,ax
mov word ptr ExecData.EsCmdPAdr + 2,ax
mov bx,offset ExecData ;ES:BX point to parameter block
mov dx,offset PrgName ;DS:DX point to command string
mov ax,4B00h ;Function number for "EXEC"
int 21h ;Call DOS interrupt
mov ds,bp ;Move DS
jnc ReMem ;No error ---> ReMem
mov Error_Code,ah ;Note ErrorCode
;-- Return memory to original size ------------------------------
ReMem: mov ax,TurboSeg ;Set Turbo code segment address
sub ax,10h ;to start of PSP
mov es,ax ;and load into ES
mov bx,OldPara ;Old number of paragraphs
mov ah,4Ah ;Function number for "change size"
int 21h ;Call DOS interrupt
jnc GetBack ;No error ---> GetBack
jmp Terminate ;Error in ReMem --> End program
;-- Return to program -------------------------------------------
GetBack: cmp ToDisk,0 ;Write to EMS memory?
je Ems1 ;Yes ---> Ems1
call GetFromFile ;No, reload as file
jnc CloseUp ;No error ---> CloseUp
jmp