Category : BASIC Source Code
Archive   : EMSFILES.ZIP
Filename : EMSFILES.BAS

 
Output of file : EMSFILES.BAS contained in archive : EMSFILES.ZIP
' PROGRAM EMSFILES.BAS Written By Erik Olson, Spectra Tech Support
' ================================================================
' April 30, 1992 Spectra BBS (813) 625-1721
' Digitek BBS (813) 629-9145
' WELCOME TO THE MACHINE
' (813) 764-0165 login name "SPECTRA"
'
' This program uses the EMS functions of Thomas Hanlin's PBWIZ316.ZIP
' PowerBASIC library. This program reads two files:
' "\COMMAND.COM" and "\DOS\LIST.COM" and copies them into EMS memory.
'
' This first illustration reads LIST.COM with a single GET$, since it is
' a very small program (8-10k depending on the version) and slams it into
' a single 16K ems page.
'
' The second illustration reads COMMAND.COM in 16000 byte blocks (I was
' having some trouble with reading exactly 16K) and pushes them into
' 16K EMS pages. It reads COMMAND.COM in such a way that a file of
' any length could be read, as long as you have enough free EMS. This
' technique is preferred to the first, which would choke on a file larger
' than 16K.
'
' The final part of this program goes back into EMS and pulls out LIST.COM
' and COMMAND.COM and writes the files LIST2.COM and COMMAND2.COM to the
' current directory. These files are intact and actually work. (GEE!)
'
' Of course, this program serves no real purpose other than to demostrate
' the use of Hanlin's EMS functions. ...But you can see the potential for
' creating your own EMS string-swapping, FAST LOADING SHELLS, huge
' simulated arrays, complex help screens that don't kill your free string
' space, simulated "ram disk" type storage for software level processing...
' jeepers, thanks Tom!



$INCLUDE "PBWIZ.INC" '\
' > You have to have or download PBWIZ316.ZIP
$link "ems.obj" '/

On Error Goto ErrorHandler

IF EMSexists% THEN PRINT "EMS Exists..." ELSE PRINT "Sorry, no EMS found!":END

PRINT "Total EMS Memory:"; EMStotal%; " 16K pages"
PRINT " Total EMS Free:"; EMSfree%; " 16K pages"


' Allocate all free EMS

Pages%=EMSfree%
CALL EMSopen(Pages%, Handle%, ErrCode%)

' Map a 16K EMS blocks into the 64k EMS segment (a peekable pokeable area)

CALL EMSmap(Handle%, 0,0)


' Read a program file from disk - assuming LIST.COM is in the DOS directory
PRINT "Reading \DOS\LIST.COM..."
OPEN "\DOS\LIST.COM" FOR BINARY AS #1
GET$ 1,LOF(1), TEMP$
CLOSE #1

' put the file into EMS
PRINT " Putting it into EMS..."
DEF SEG = EMSseg&
POKE$ 0, TEMP$ + "SAVE THE KRILL!" ' an unlikely terminator

' Read another program from disk
PRINT "Reading \COMMAND.COM..."
OPEN "\COMMAND.COM" FOR BINARY AS #1

Physical% = 0 ' we're just using EMS block page 0, 16k at a time
Virtual% = 0 ' we need to map real EMS memory in 16k pages
blocks% = LOF(1) \ 16000
Remainder = LOF(1) - (LOF(1) \ 16000)

PRINT " Putting it into EMS..."
FOR y=1 to blocks%

Virtual% = Virtual% + 1 ' this is real EMS memory
CALL EMSmap(Handle%, Physical%, Virtual%)
GET$ 1, 16000, TEMP$
DEF SEG = EMSseg&
POKE$ 0, TEMP$
DEF SEG
next y

' get the rest of command.com
GET$ 1, Remainder, TEMP$
Virtual% = Virtual% + 1
CALL EMSmap(Handle%, Physical%, Virtual%)
DEF SEG = EMSseg&
POKE$ 0, TEMP$ + "SAVE THE KRILL!" ' so we know where COMMAND.COM
' ends in memory
DEF SEG
CLOSE #1


' we put LIST.COM and COMMAND.COM into EMS
' we will scan EMS memory and pull them out


' get LIST.COM back
PRINT:PRINT:PRINT "Writing LIST2.COM..."
CALL EMSmap(Handle%, 0,0)
DEF SEG = EMSseg&
TEMP$=PEEK$(0, 16000) ' Get the whole 16000 chars
DEF SEG
A% = INSTR(TEMP$, "SAVE THE KRILL!") - 1 ' locate our unlikely terminator
OPEN "O", #1, "LIST2.COM"
PRINT #1, LEFT$(TEMP$, A%);
CLOSE #1

' get COMMAND.COM back
Virtual%=0
PRINT "Writing COMMAND2.COM..."
OPEN "COMMAND2.COM" FOR OUTPUT AS #1
DO
Virtual%=Virtual%+1
CALL EMSmap(Handle%, 0, Virtual%)
DEF SEG = EMSseg&
TEMP$=PEEK$(0, 16000) ' 16000 bytes total: 0-16000
DEF SEG
Done% = INSTR(TEMP$, "SAVE THE KRILL!") ' find our unlikely terminator
IF Done% THEN EXIT LOOP
PRINT #1, TEMP$;
LOOP


' write the remainder of COMMAND2.COM
PRINT #1, LEFT$(TEMP$, Done%-1);
CLOSE #1
PRINT "Success!"
GOTO EndProg


ErrorHandler:
Er=Err
PRINT "Error:";Er ' big WHOOP, but we MUST make sure that EMSClose gets
Resume Here ' called before the program ends.
Here:



EndProg:
' MAKE SURE YOU DEALLOCATE EMS BEFORE QUITTING
' (so that's why.... Oh, never mind)

CALL EMSClose(Handle%)
END


  3 Responses to “Category : BASIC Source Code
Archive   : EMSFILES.ZIP
Filename : EMSFILES.BAS

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/