home *** CD-ROM | disk | FTP | other *** search
/ Emulator Universe CD / emulatoruniversecd1998.iso / MSX / OS / MSXDOS2.ZIP / MEMMAN24.LZH / MM24SPEC.ENG < prev    next >
Encoding:
Text File  |  1996-04-15  |  35.6 KB  |  776 lines

  1. File: MM24SPEC.ENG
  2. Date: 19 september 1992
  3. By  : Ries Vriend / Ramon van der Winkel - (c) MST
  4.  
  5. Unauthorized translation by Arnold Metselaar, 1 April 1996 
  6. ----------------------------------------------------------
  7.  
  8.   This text contains the information neccessary to write  application
  9. programs for MemMan 2.4. For the specifications regarding  prgramming
  10. TSR's we point to the technical documentation that can  be  found  on
  11. the   `TSR-Development   disk'.   This   disk   contains   the   full
  12. specifications on TSR's and some development tools. It can be ordered
  13. from the MST, see the `LezersService' of `MSX Computer Magazine'  for
  14. more information.
  15.  
  16. Contents
  17. --------
  18.  
  19. Changes in MemMan 2.3 with respect to version 2.2
  20. Updates from MemMan 2.30 to MemMan 2.31
  21. Changes in MemMan 2.4 with respect to version 2.3
  22.  
  23. Used terminology
  24. Why MemMan 2.4?
  25.  
  26. The basics
  27.  
  28. Appendix 1: BIOS-calls under Turbo Pascal
  29. Appendix 2: Hints and directions for programmers
  30.  
  31. MEMMAN versie 2.4 - specifications
  32. ==================================
  33.  
  34. Changes in MemMan 2.3 with respect to version 2.2
  35. -------------------------------------------------
  36.  
  37. -      The function XTsrCall has been added. This function  works  in
  38.        the same way as TsrCall (63), the only difference  being  that
  39.        the Tsr-ID is expected in register  IX  instead  of  BC.  This
  40.        makes BC avaible for passing an argument.
  41.  
  42. -      The function Info (50) can be used to  obtain  the  address  at
  43.        which XTsrCall can be called directly.
  44.  
  45. -      The function Status is improved. The total  amount  of  usable
  46.        memory is reported correctly, even under MSX-DOS2.
  47.  
  48. -      The function Alloc (10) now also recognizes  the  memory  that
  49.        becomes available when the DOS2 RAMdisk is removed or  shrunk!
  50.        It does not matter whether the RAMdisk was installed before or
  51.        after MemMan wss installed. 
  52.  
  53. -      The internal stack of MemMan that is used to process  function
  54.        calls is enlarged from 160 to 240 bytes. The stack  of  MemMan
  55.        proved to be too small to process nested "TsrCalls".
  56.  
  57. Updates from MemMan 2.30 to MemMan 2.31
  58. ---------------------------------------
  59.  
  60. -      A bug turned up in TL.COM, that caused problems  when  loading
  61.        TSR's under DOS1. The error was in the parsing of the  command
  62.        line and was known and solved the day after the fair.
  63.  
  64. -      The second bug was more complicated, en  was  revealed  during
  65.        experiments with new TSR's. It was not reported before. It was
  66.        about CMD TL. Thet command did not perform an IniChk,  due  to
  67.        which the CurSeg function of MemMan did not work well  either.
  68.        TSR's that used CurSeg and  switched  memory  in  page  2  got
  69.        stuck. The printerbuffer was (is?) the only TSR to do so.  The
  70.        problem did not occur when loading a TSR with  TL.COM  because
  71.        TL.COM does perform an IniChk. This bug is also solved.
  72.  
  73. Changes in MemMan 2.4 with respect to version 2.3
  74. -------------------------------------------------
  75.  
  76. -      The function GetTPA (33) is added, making it possible  to  use
  77.        the 32 kB RAM behind the BIOS and the  BASIC  ROM  under  disk
  78.        BASIC. Many people asked for this!
  79.  
  80. -      CMD HELP is now supported by the standard TSR `MST  TsrUtils'.
  81.        This command puts a small overview of the extra BASIC commands
  82.        on  the  screen.  Look  at  the  hints  and   directions   for
  83.        programmers for more information on CMD HELP. 
  84.  
  85. -      TL.COM uses the environment item  TL,  to  locate  the  TSR's.
  86.        Owners of a harddisk only need  to  put  `SET  TL=A:\TSRS'  in
  87.        their  AUTOEXEC.BAT  and  to  place  all  the  TSR's  in   the
  88.        subdirectory A:\TSRS can allways be found by  TL.  giving  the
  89.        path is than no longer neccessary.
  90.  
  91. -      TV.COM also shows in which  segment  the  TSR's  reside.  This
  92.        makes it easy to free a segment by removing all the  TSR's  in
  93.        them. TSR segment 0 is the MemMan  segment,  the  memory  left
  94.        over in that segment can only be used by TSR's, not  by  other
  95.        programs.
  96.  
  97. -      Two functions have been added read and set the  stack  pointer
  98.        of MemMan's internal stack. That is neccessary  if  a  program
  99.        calls the expression evaluator in the BASIC ROM and  wants  to
  100.        handle errors itself. This is because ExpEval may  call a  TSR
  101.        that calls ExpEval and an error may than occur. In  that  case
  102.        junk will be left on the stack. If  the  errorhandler  of  MSX
  103.        BASIC is used after such errors, there  is  no  problem:  then
  104.        MemMan itself clears its stack.
  105.  
  106. -      In  all  MemMan  TSR-segments  the  MemMan  function  handling
  107.        routine starts at &h4002. Therefore MemMan can be called  from
  108.        a TSR with a quick and simple `call &H4002'.
  109.  
  110. -      A new version (1.04) of the filecopier BK  is  delivered  that
  111.        makes no errors if more than 4 MB  is  available.  In  version
  112.        1.02 a counter would overflow causing a  wrong  indication  on
  113.        screen of the amount of memory.
  114.  
  115. -      IniChk gives the address of the MemMan function handler in  HL.
  116.        This saves a call to the Info function.
  117.  
  118.  
  119. Why MemMan 2.4?
  120. ---------------
  121.  
  122.   In fact there was little reason for a releasing new  version  after
  123. the updates. The differences between 2.3 and 2.4 are small. All known
  124. bugs had been solved and there are no  big  extensions,  just  a  few
  125. small extras. 
  126.   Apart from what is new now, we have and had more and bigger  plans.
  127. We still work on them but we did not want to wait with releasing  2.4
  128. untill the other things had  been  finished  and  tested.  Especially
  129. because more and more programmers  encountered  an  design  error  in
  130. MemMan: It was impossible to switch the 32  kB  RAM  behind  the  ROM
  131. under disk BASIC using MemMan. That has been solved: From now on  All
  132. switching can be done neatly using MemMan, even  if  a  program  runs
  133. under disk BASIC and really wants to use all the memory.
  134.   All other extensions are nice but could have waited. On  the  other
  135. hand there are some wishes amongst the further plans that are in fact
  136. quite important. But they all require a considerable  change  in  the
  137. internal structure of MemMan and that takes time. 
  138.  
  139. Used terminology
  140. ----------------
  141.  
  142. Page     Part of the addressing space. The addressing  space  of  the
  143.          Z80 is divided into 4 pages of 16  k,  starting  at  &h0000,
  144.          &h4000, &h8000 and &hC000 respectively.
  145.  
  146. Segment  Memory block 16 kB in size. There are two types of segments;
  147.          pagebound and flexible segments. The flexible  segments  can
  148.          can be switched on page 0, 1 and 2. There are three sorts of
  149.          pagebound segments: PSEG0000, PSEG4000  and  PSEG8000.  They
  150.          can be switched on page 0, 1 and 2 respectively.
  151.  
  152. Heap     Memory area in page 3 (somewhere between &hC000 and &hFFFF).
  153.          MemMan aplication programs can allocate a piece and  use  it
  154.          freely. The size can be set with the confioguration  program
  155.          CFGMMAN.
  156.  
  157. FastUse  Equal to Use, called directly in  page  3.  There  are  also
  158.          other routines that can be called directly,  which  benefits
  159.          the speed.
  160.  
  161. Uncrash  To prevent allocated  segments  from  never  being  released
  162.          because a program crashed, the IniChk  routine  performs  an
  163.          UnCrash. This releases all segments.  One  can  prevent  the
  164.          UnCrashing of a segment by giving it  the  Reserved  status.
  165.          This can be done with the  function  SetRes.  In  general  a
  166.          segment does not need be given the Reserved status.
  167.  
  168. TPA      `Transient Program Area'. Originally this meant the piece of
  169.          memory from &h0100 untill the first byte  of  the  operating
  170.          system under CP/M or MSX DOS. That was the area  where  user
  171.          programs could be loaded. In this text the term TPA is  used
  172.          for the four segments (64 kB) that are switched on under MSX
  173.          DOS. The upper two of them are also switched  on  under  MSX
  174.          BASIC.
  175.  
  176. The basics
  177. ----------
  178.  
  179.   MemMan divides the memory into segments of 16 kB. Before a  segment
  180. may be used it must be allocated. After use  it  should  be  released
  181. again. There are two types of segments:  the  pagebound  segments  or
  182. PSEG's end the flexible FSEG's.
  183.   PSEG's are segments that are requested for use in a specific  page,
  184. e.g. &h4000-&h7FFF or &h8000-&hBFFF. When a PSEG is requested, MemMan
  185. will allocate a segment that is not in a memory mapper, if  possible.
  186. FSEG's are segments that can be used on any page. These allways  come
  187. from memory-mappers.
  188.   Whatever type of segment is requested MemMan will return a  16-bits
  189. `segmentcode'. This segmentcode is needed for switching or  releasing
  190. the segment. Those who only need memeory in the area from  &h8000  to
  191. &hBFFF, can best request PSEG's. MemMan than first uses  memory  from
  192. `old' 16 and 64 kB modules before it starts using the mapper.
  193.   Using MemMan eliminates the need to serach for memory. Just request
  194. a page, use it and release it in the end. It's as simple as that.
  195.   However there is a page that MemMan can not switch. Page 3 contains
  196. a part of the MemMan code the stack (in most  cases)  and  a  lot  of
  197. system variables. Switching all that is quite tricky business.
  198.  
  199. Description of MemMan 2.4 funtions
  200. ----------------------------------
  201.  
  202.   One can execute MemMan functions by calling the `Extended BIOS'  or
  203. EXTBIO hook, on address &hFFCA. The device ID of MemMan -`M' or  &h4D-
  204. should be placed in register D. Register E should contain the  MemMan
  205. function code. After calling a MemMan function all registers  can  be
  206. altered unless the description states otherwise.
  207.   MemMan can also be called directly, the address  where  it  can  be
  208. called, can be asked for using the info function  (50)  and  is  also
  209. returned by IniChk (30). This way the disadvantages of calling MemMan
  210. via a hook  are  avoided.  Look  at  the  hints  and  directions  for
  211. programmers for more information.
  212.   The state of interupts remains unchanged after a MemMan function in
  213. most cases. Some  functions,  like  the  FastUse  functions,  disable
  214. interupts. When MemMan was called with interupts  disables,  it  will
  215. never return with interupts enabled. 
  216.   This feature is important for e.g. TSR programs that  only  have  a
  217. very small stack. As long  as  interupts  are  disabled,  all  MemMan
  218. functions can be processed without problems. However  with  interupts
  219. enabled a big stack is required, as the interupt handler puts tens of
  220. bytes on the stack.
  221.  
  222. Name:        Use0
  223. Number:      0
  224. Purpose:     Switch a segment on page 0 (addresses &h0000-&h3FFF) 
  225. In:          HL           = Segmentcode
  226. Out:         A            = Exit status (-1 = Faillure, 0 = Succes)
  227.  
  228.              Switching a segment in page 0 is only  possible  if  the
  229.              segment  contains  the  standard  MSX  slotswitch  entry
  230.              points.
  231.  
  232. Remark:      This function may not be called  via  the  EXTBIO  hook.
  233.              This function may only be executed after a  direct  call
  234.              to the MemMan function handler or the FastUse0 function.
  235.              One can ask for the addresses where these functions  can
  236.              be called directly, using the function Info (50).
  237.  
  238.  
  239. Name:        Use1
  240. Number:      1
  241. Purpose:     Switch a segment on page 0 (addresses &h4000-&h7FFF) 
  242. In:          HL           = Segmentcode
  243. Out:         A            = Exit status (-1 = Faillure, 0 = Succes)
  244.  
  245. Remark:      This function may not be called  via  the  EXTBIO  hook.
  246.              This function may only be executed after a  direct  call
  247.              to the MemMan function handler or the FastUse1 function.
  248.              One can ask for the addresses where these functions  can
  249.              be called directly, using the function Info (50).
  250.  
  251.  
  252. Name:        Use2
  253. Number:      2
  254. Purpose:     Switch a segment on page 0 (addresses &h0000-&h3FFF)
  255. In:          HL           = Segmentcode
  256. Out:         A            = Exit status (-1 = Faillure, 0 = Succes)
  257.  
  258. Remark:      This function may not be called  via  the  EXTBIO  hook.
  259.              This function may only be executed after a  direct  call
  260.              to the MemMan function handler or the FastUse1 function.
  261.              One can ask for the addresses where these functions  can
  262.              be called directly, using the function Info (50).
  263.  
  264.  
  265. Name:        Alloc
  266. Number:      10
  267. Purpose:     Request a segment
  268. In:          B            = Segment preference code
  269.              Bit 0 and 1: 00 = PSEG0000
  270.                           01 = PSEG4000
  271.                           10 = PSEG8000
  272.                           11 = FSEG
  273.              Bit 2 til 5: Unused. Must be 0.
  274.              Bit 6:       1 = Prefer TPA or the standard  MSXDOS  RAM
  275.                           slot. This results in faster switching  but
  276.                           probably  also  in  not  cooperating   with
  277.                           non-MemMan TSR's that put themselves in the
  278.                           TPA slot.
  279.              Bit 7:       1 = Prefer unexpanded (thus fast) slot. The
  280.                           same things as for bit six hold  for  this.
  281.                           Unexpanded slots era switched  faster,  but
  282.                           have a bigger change of  being  in  use  by
  283.                           non-MemMan applications.
  284. Out:         HL           = Segmentcode. (&h0000 = No free segment 
  285.                             left)
  286.              B            = Type of segment (-1 = FSeg, 0 = PSeg)
  287.  
  288.              If a PSEG is requested, but not available, an FSEG, that
  289.              can replace the PSEG,  is allocated instead.
  290.  
  291.  
  292. Name:        SetRes
  293. Number:      11
  294. Purpose:     Give a segment the Reserved status
  295. In:          HL           = Segmentcode
  296.  
  297.              Gives a segment the `Reserved-status' preventing it from
  298.              being released automatically after a call to the  IniChk
  299.              function. In general programs do not  need  to  set  the
  300.              reserved status, unless a  program  -e.g.  a  RAM  disk-
  301.              wants to secure a segment for its own use.
  302.  
  303.  
  304. Name:        DeAlloc
  305. Number:      20
  306. Purpose:     Releasing a segment
  307. In:          HL           = Segmentcode
  308.  
  309.              On exiting a program this function  should  be  used  to
  310.              release all allocated  segments.  DeAlloc  automatically
  311.              unsets  the  reserved  status  of  the   segment   being
  312.              released.
  313.              DeAlloc will make segments that are also administered by
  314.              DOS2, available for DOS2 again.
  315.  
  316.  
  317. Name:        ClrRes
  318. Number:      21
  319. Purpose:     Clear the reserved status of a segment
  320. In:          HL           = Segmentcode
  321.  
  322.              It is not neccessary to call this function  just  before
  323.              calling DeAlloc. DeAlloc clears the reserved status of a
  324.              segment itself.
  325.  
  326.  
  327. Name:        IniChk
  328. Number:      30
  329. Purpose:     Initializes MemMan for a program
  330. In:          A            = Check code
  331. Out:         A            = Check code + "M"
  332.              DE           = Version number (format: Version #D.E)
  333.              HL           = Starting from version 2.4: address of  the
  334.                             MemMan function  handler  (Look  at  Info
  335.                             (50) for more information.)
  336.  
  337.              This routine adds the ASCII-value of the letter  "M"  to
  338.              the contents of register A. This makes  it  possible  to
  339.              chack the presence of  MemMan.  Further  an  UnCrash  is
  340.              performed en the segmentcodes of the currently  switched
  341.              segments are computed and stored for use by CurSeg.
  342.              The function IniChk may only  be  called  once  by  each
  343.              MemMan application program. This should be  done  before
  344.              any other MemMan function is called.  TSR  programs  may
  345.              never call the IniChk function.
  346.  
  347. Name:        Status
  348. Number:      31
  349. Purpose:     Get status data of MemMan
  350. Out:         HL           = Number of present segments
  351.              BC           = Number of free segments
  352.              DE           = Number of segments administered by both 
  353.                             DOS2 and MemMan
  354.              A            = Connected Status of the connected
  355.                             hardware.
  356.                             Bit 0: 1 if the DOS2 Mapper Support
  357.                             Routines are present, 0 otherwise
  358.                             Bit 1-7: Reserved, allways 0.
  359.  
  360.        If bit 0 of the Connected  status  is  set,  the  Mapper
  361.              Support functions of DOS 2.20 are present. The number of
  362.              free segments can be lower than stated in  register  bc,
  363.              because  some  segments  are  used  by  DOS2  after  the
  364.              installation of MemMan -e.g. to install a RAMdisk.  
  365.  
  366.  
  367. Name:        CurSeg
  368. Number:      32
  369. Purpose:     Ask for the segmentcode of a switched segment 
  370. In:          B            = Pagenumber (0,1,2,3)
  371. Out:         HL           = Segmentcode
  372.              A            = Type of segment (255 = FSeg, 0 = Pseg)
  373.  
  374.              This routine returns the segmentcode of one of the  four
  375.              pages. 
  376.              TSR's may not use this function to determine the current
  377.              segment in page 0. To save some time this setting is not
  378.              automatically computed and stored when a TSR is  called.
  379.              The current segments in the pages 1 and  2  however  are
  380.              computed at each call to a  hook,  and  can  allways  be
  381.              asked for using this function. The segment  in  page  3,
  382.              allways being the same, can also be  asked  for  at  all
  383.              times. 
  384.              There is also a FastCurSeg  that  does  the  same  thing
  385.              faster. One can ask for  the  address  where  it  can  be
  386.              called directly, using the function Info (50).
  387.  
  388.  
  389. Name:        GetTPA
  390. Number:      33
  391. Purpose:     Ask for the@segmentcode of a TPA segment
  392. In:          B            = Page number (0,1,2,3)
  393. Out:         HL           = Segmentcode
  394.              A            = Type of segment (255 = FSeg, 0 = Pseg)
  395.  
  396.              The purpose of this function is to make it  possible  to
  397.              use the lower 32 kB of the TPA from a program under Disk
  398.              BASIC. MemMan normally does not use these as they  might
  399.              contain RAMcartridges, or BASIC's RAMdisk. Use  at  your
  400.              own risk. Do check whether the segments are  FSEG's,  if
  401.              neccessary. Note that the TPA  segments  should  not  be
  402.              passed to DeAlloc.
  403.  
  404.  
  405. Name:        StoSeg
  406. Number:      40
  407. Purpose:     Store the current setting of segments
  408. In:          HL           = Adress of a buffer (9 bytes)
  409.  
  410.              The segmentcodes known  to  MemMan  are  stored  in  the
  411.              buffer. These codes are normally computed by IniChk  and
  412.              subsequently updated by the Use  functions.  The  stored
  413.              settings are not the current setting but the settings as
  414.              known to  MemMan.  Therefore  TSR's  can  not  use  this
  415.              function to store the current settings.
  416.  
  417. Remark:      This function may not be called  via  the  EXTBIO  hook.
  418.              This function may only be executed after a  direct  call
  419.              to the MemMan function handler.  One  can  ask  for  the
  420.              addresses where these functions can be called  directly,
  421.              using the function Info (50). Of  course  the  functions
  422.              (Fast)CurSeg can also be used to  ask  for  the  current
  423.              segment settings.
  424.  
  425.  
  426. Name:        RstSeg
  427. Number:      41
  428. Purpose:     Make stored segment settings active
  429. In:          HL           = Address of buffer
  430.  
  431.              The settings stored in the buffer are made active  again
  432.              and are stored for future use by CurSeg.
  433.  
  434. Remark:      This function may not be called  via  the  EXTBIO  hook.
  435.              This function may only be executed after a  direct  call
  436.              to the MemMan function handler.  One  can  ask  for  the
  437.              addresses where these functions can be  called  directly,
  438.              using the function Info (50). Of  course  the  functions
  439.              (Fast)Use can also be used to restore segment settings.
  440.  
  441.  
  442. Name:        Info
  443. Number:      50
  444. Purpose:     Give information about amongst others call addresses  of
  445.              MemMan functions
  446. In:          B            = Information number (0..8)
  447. Out:         HL           = Information
  448.  
  449.              Information number overview. Between parentheses are the
  450.              equivalent MemMan function codes:
  451.              0 - Call address of FastUse0 (function 0)
  452.              1 - Call address of FastUse1 (function 1)
  453.              2 - Call address of FastUse2 (function 2)
  454.              3 - Call address of TsrCall (function 63)
  455.              4 - Call address of BasicCall
  456.              5 - Call address of FastCurSeg (function 32)
  457.              6 - Call address of MemMan, the function handler
  458.              7 - Versienummer van MemMan, format: Versie #H.L
  459.              8 - Call address of XTsrCall (function 61)
  460.              9 - Call address of GetMMSP
  461.              10 - Call address of SetMMSP
  462.  
  463.              The  call  addresses  mentioned  above  may  be   called
  464.              directly by an application program or a  TSR.  All  call
  465.              addresses are garantied to be in page 3.
  466.              The functions are performed quickly because  the  MemMan
  467.              call to the EXTBIO hook is omitted and function codes in
  468.              D and E need not be parsed. Another  advantage  is  that
  469.              arguments can also be passed using register DE, this  is
  470.              especially  important  for  the  functions  TsrCall  and
  471.              BasicCall.
  472.              E.g. the initializing routine of a TSR can ask  for  the
  473.              calladdresses of the needed functions using the function
  474.              Info and store them in the TSR program  code  for  later
  475.              use, which can greatly benefit the speed of the TSR.
  476.              An exact description of the functions above can be found
  477.              at the MemMan function of  which  the  number  is  given
  478.              between paretheses. One should however bear in mind that
  479.              the `fast' functions differ  from  the  ordinary  MemMan
  480.              functions in the following ways: 
  481.  
  482. FastUse?:    Switches a segment in a specific memory  page.  Look  at
  483.              the description at the MemMan `Use' functions.
  484.  
  485. TsrCall:     Register DE is passed to the TSR unchanged. In  contrast
  486.              with  function  (TsrCall),  in  that  case  DE   already
  487.              contains the MemMan function code.
  488.  
  489. XTsrCall:    All main registers are passed to the TSR unchanged.  The
  490.              TSR-Id code  should be placed in register IX.
  491.  
  492. BasicCall:   Does not have a MemMan function code.
  493. Purpose:     Call a routine in the BASIC ROM.
  494. In:          IX           = Call address in page 0 or 1
  495.              AF,HL,BC,DE  = dataregisters for the BASIC-ROM
  496. Out:         AF,HL,BC,E   = dataregisters from the BASIC-ROM
  497.              Interrupts disabled
  498.  
  499.              Via this function TSR's can call a  routine  in  page  0
  500.              and/or 1 of the BASIC-ROM.  The  bios  must  already  be
  501.              switched in page 0. The BASIC ROM is switched by  MemMan
  502.              in page 1
  503.              This is neccessary for instance to  call  the  math-pack
  504.              routine that are in page 0 of the  BASIC  ROM  but  call
  505.              some routines in page 1 in the mean time.
  506.              The H.STKE (stack error) hook is changed, to  clear  the
  507.              internal stacks of MemMan if a BASIC error occurs.
  508.  
  509. fastCurSeg:  The returned value  in  register  A  is  undefined.  The
  510.              function CurSeg (32) indicates whether a  segment  is  a
  511.              PSEG or an FSEG 
  512.  
  513. MemMan:      Does not have MemMan function code
  514. Purpose:     Call a MemMan function directly
  515. In:          E            = MemMan function code
  516.              AF,HL,BC     = Dataregisters depending on  the  function
  517.                             to be called.
  518. Out:         AF,HL,BC,DE  = Dataregisters  depending  on  the  called
  519.                             function.
  520.  
  521.              A call to this routine has the same effect as calling  a
  522.              MemMan function via the EXTBIO hook. Because the calling
  523.              of the EXTBIO is omitted  other  extensions  using  this
  524.              hook are not called. Due to this,  the  usage  of  stack
  525.              stays limited en the processing speed is increased.
  526.  
  527. GetMMSP:     Does not have MemMan function code
  528. Purpose:     Ask for the internal MemMan Stack Pointer
  529. In:          Nothing
  530. Out:         HL           = Internal stack pointer of the
  531.                             TSR-Manager.
  532.  
  533. SetMMSP:     Does not have MemMan function code
  534. Purpose:     Set the internal MemMan Stack Pointer
  535. In:          HL           = New value for the Internal stack pointer
  536.                             of the TSR-Manager.
  537. Out:         Nothing
  538.  
  539.              TSR's can  use  these  two  functions  to  ask  for  the
  540.              internal stack pointer of MemMan and restore it  when  a
  541.              TSR has not returned neatly to the return address of  the
  542.              TSR-Manager.
  543.              That is neccessary if a programm  calls  the  Expression
  544.              Evaluator in the BASIC ROM and wants  to  handle  errors
  545.              itself. The situation may occur  that  ExpEval  calls  a
  546.              TSR, that itself calls ExpEval resulting  in  an  error.
  547.              That would leave junk on  the  MemMan  stack.  If  after
  548.              such errors the error handler  of  MSX  BASIC  is  used,
  549.              there is no problem: then MemMan itself will  clear  its
  550.              own stack.  
  551.  
  552.              Example:
  553.              ; This is an example of a good invocation of the
  554.              ; expression evaluator in the BASIC ROM, like it
  555.              ; can occur in a program.
  556.              ...
  557.              ld (saveSP),sp          ;Store SP of TSR-program
  558.              call getMMSP
  559.              ld (saveMMSP),hl        ;Store SP of MemMan
  560.              invocation frmEval      ;Evaluate expression (BIOS)
  561.              ...
  562.              jp main
  563.  
  564.              ; This routine is connected to H.ERRO
  565.              ; it is called if there was an error
  566.              ; in the expression
  567.              ld sp,(saveSP)          ;Restore the TSR-stack
  568.              ld hl,(saveMMSP)
  569.              call setMMSP            ;Restore the MemMan stack
  570.              jp main                 ;Act as if nothing  happened
  571.  
  572.  
  573. Name:        XTsrCall
  574. Number:      61
  575. Purpose:     Call the driver-entry of a TSR
  576. In:          IX           = ID code of the TSR to be called
  577.              AF,HL,BC,DE  = passed unchanged to the TSR
  578. Out:         AF,HL,BC,DE  = returned unchanged from the TSR
  579.  
  580.              This function is an improved  version  of  the  function
  581.              TsrCall  (63).  Because  with  the  function  all   main
  582.              registers can  be  used  for  passing  arguments  it  is
  583.              recommendable to use this funcion  instead  of  function
  584.              63.
  585.  
  586. Remark:      This function may not be called  vie  the  EXTBIO  hook,
  587.              because the IX register is altered when a call to EXTBIO
  588.              is made. Call this function directly or use  the  MemMan
  589.              function handler. One can ask for  the  addresses  where
  590.              these  functions  can  be  called  directly,  using  the
  591.              function Info (50). 
  592.  
  593.  
  594. Name:        GetTsrID
  595. Number:      62
  596. Purpose:     Determine TSR ID code
  597. In:          HL           = Pointer to the TsrName (12 characters).
  598.                             Fill unused positions with spaces.
  599. Out:         Carry        = Clear (NC) if the TSR is found,  Set  (C)
  600.                             if the TSR is not found,
  601.              BC           = TSR ID code
  602.  
  603.  
  604. Name:        TsrCall
  605. Number:      63
  606. Purpose:     Call the driver-entry of a TSR
  607. In:          BC           = ID code of the TSR to be called
  608.              AF,HL,DE     = passed unchanged to the TSR.
  609. Out:         AF,HL,BC,DE  = returned unchanged from the TSR.
  610.  
  611.              Note that though DE is passed unchanged to the  TSR,  it
  612.              can not be used  to  pass  arguments  to  the  TSR.  The
  613.              Extended BIOS function code of MemMan (D='M' E=63)  must
  614.              be placed in this register. This is not the case for the
  615.              Fast-TsrCall routine; one can ask  for  the  address  of
  616.              this routine using the function Info (50)
  617.  
  618.  
  619. Name:        HeapAlloc
  620. Number:      70
  621. Purpose:     Request space in the heap
  622. In:          HL           = requested size of the space (in bytes)
  623. Out:         HL           = &h0000 if there was insufficient space,
  624.                             else the starting address of the space.
  625.  
  626.              One can allocate a piece of memory using this  function.
  627.              The memory block is garantied to be in page 3.
  628.              The heap is primarily of use to  TSR-programs  That  can
  629.              use  it  as  temporary  or  permanent  dikbuffer.  Other
  630.              buffers - that really must be in page 3 - can be  placed
  631.              in the heap as well. Allocated blocks in the heap remain
  632.              unusable to  other  programs  untill  a  HeapDeAlloc  is
  633.              executed (function 71).
  634.              One can set the size of the heap using the configuration
  635.              programm CFGMMAN.
  636.  
  637.  
  638. Name:        HeapDeAlloc
  639. Number:      71
  640. Purpose:     Release allocated space in the heap
  641. In:          HL           = Startadres of the space
  642.  
  643.  
  644. Name:        HeapMax
  645. Number:      72
  646. Purpose:     Return the length of the largest free block in the heap.
  647. Out:         HL           = Length of the largest free block
  648.  
  649.  
  650. Appendix 1: BIOS-calls under Turbo Pascal
  651.   If interslot-calls to the BIOS are used in  a  program  written  in
  652. Turbo Pascal it is important that the stack is in page  2  or  3.  In
  653. that case MemMan can safely activate a TSR  when  the  BIOS  calls  a
  654. hook. The position of the stack is dependent of thye maximum  program
  655. address to which Turbo Pascal is  configured.  In  Turbo  Pascal  the
  656. stack is directly below the memory used for variables. Therefore  the
  657. memory for variables should be placed well above address &h8000.
  658.   If no source is available, one can still change the  stack  address
  659. of  programs  written  in  Turbo  Pascal  using   a   debugger.   The
  660. initiallizing code of a TP program looks as follows:
  661.  
  662.   start: jp init
  663.          ...
  664.          ...
  665.   init:  ld sp,100h
  666.          ld hl,nn
  667.          ld de,nn
  668.          ld bc,nn
  669.          call yy
  670.          ld hl,nn
  671.          ld de,stack    ;DE contains the stack address, this
  672.          ld bc,nn       ; only needs to be changed if it is 
  673.          call zz        ; lower than &h80A0
  674.          ...
  675.  
  676. The stack address in register DE can be set to e.g. &hC100. 
  677.  
  678.  
  679. Appendix 2: Hints and directions for programmers
  680.   Because the EXTBIO hook is used for various system extensions  like
  681. KANJI and RS232 interfaces, it is possible that MemMan function calls
  682. are processed very slowly. One can  increase  the  performance  of  a
  683. MemMan application significantly by calling the function  handler  of
  684. MemMan directly instead of the EXTBIO  hook.  One  can  ask  for  the
  685. address where the function handler can be called, using the  function
  686. Info (50). Starting from version 2.4 the function IniChk also returns
  687. the  address  of  the  function  handler  in  HL,  this  address  can
  688. immediatedly be stored in the program.
  689.   Most MemMan functions reside in a special memory segment in page 1.
  690. These functions switch to an internal  stack,  due  to  which  MemMan
  691. applications can have a relatively small  stack.  A  MemMan  function
  692. places at most twenty bytes on the stack of an application.  This  is
  693. only valid if the function is called directly or by a direct call  to
  694. the MemMan function handler. A function call via the EXTBIO hook  can
  695. require a very big stack. This is because all  extensions  linked  to
  696. the EXTBIO hook call eachother untill  one  of  them  recognizes  the
  697. call. When interupts have to be handled in the same time,  the  Stack
  698. use can rise a lot. This is another reason to use the MemMan function
  699. handler instead of the EXTBIO hook.
  700.  
  701.   MemMan version 1.1 contains some bugs that are solved in version 2.
  702. The advantage of MemMan 1.1 is that it does not use an extra segment,
  703. and therefore works on computers  with  only  64  kB  memory.  It  is
  704. however not worth the trouble to keep MemMan 1.1 up to date for  this
  705. limited group. To make a program work on a 64 kB computer  we  advise
  706. to switch and use 64 kB in  the  program  itself  if  MemMan  is  not
  707. present. One could even use the whole mapper. Under DOS MemMan is not
  708. needed to use 64 kB and under MSX Basic it can  not  be  done  neatly
  709. with MemMan 1.1.  MemMan  version  1.1  will  not  be  developed  any
  710. further.
  711.  
  712.   When programming TSR's one can use, starting from version 2.4,  the
  713. MemMan function handler on address &h4002  that  is  present  in  all
  714. TSR-segments. This makes the code TSR's fasters and  much  easier  to
  715. read.
  716.  
  717.   Allways use the BIOS-routines when writing to  the  VDP  registers.
  718. This keeps the system variables in page 3 up to date and  some  TSR's
  719. (CurBlink, screensavers, debuggers, memory  viewers)  use  these.  To
  720. determine e.g. the the active screen  mode  or  the  address  of  the
  721. sprite-tables. Writing to the palette registers should also  be  done
  722. using the BIOS to keep the information in the VRAM up to  date.  Only
  723. when the VRAM is really needed for other things (e.g. in  case  of  a
  724. VDP(24)-scroll) one has to do otherwise.
  725.  
  726.   Disable interupts when sending of block of data to the VRAM. It  is
  727. possible that a TSR that activated in the  mean  time,  accesses  the
  728. VRAM, changing the read/write pointer in the VDP. Be aware that  some
  729. BIOS routines anable interupts themselves. In these cases one can use
  730. the interupt enable bit in the VDP in the main program (or in  a  TSR
  731. but than this bit should be read and restored afterwards).  Resetting
  732. this bit stops interupts from being generated by the VDP. A DI should
  733. still beused as there are also cartridges  that  generate  interupts,
  734. but it is somewhat safer.
  735.  
  736.   Requesting a segment (ALLOC) from an  interupt  routine  can  cause
  737. hanging the machine. This is because DOS2 is not reentrant.  If  DOS2
  738. is active at the time of an interupt and DOS2 is  called  again  from
  739. the interupt routine, the  internal  stack  of  DOS2,  amongst  other
  740. things, is overwritten. And  ALLOC  calls  the  DOS2  Mapper  support
  741. routines (if DOS2 is present). This problem  presumably  occurs  with
  742. DEALLOC in the same way. Experience with the printerbuffer has  shown
  743. that USE causes no problem at all.
  744.  
  745.   Limit the number of  segments  a  program  requests  to  a  certain
  746. maximum. There are 4MB Memory Mappers, and it is not too  complicated
  747. to connect eight of them to one MSX using  two  slot-expanders.  This
  748. gives a total memory of over 32 MB (2048 segments).  Requesting  more
  749. segments than necessary only wastes time and space. By  the  way,  BK
  750. for instance has a limit as well,  it  requests  at  most  4  MB.  In
  751. version 1.02 however things still go wrong if these 4 MB are actually
  752. available... The solution is to install a  RAMdisk  or  printerbuffer
  753. that is big enough to make the available memory less  than  4MB.  The
  754. wordprocessor TED does it right it requests at most 2 MB from MemMan.
  755.    
  756.   It is practical to let TSR's  that  extend  BASIC  in  one  way  or
  757. another, recognize `CMD HELP' and  print  a  small  overview  of  the
  758. possibilities. Do not set the `QuitHook'-flag  and  leave  the  stack
  759. unchanged to have the CMD HELP's of other TSR's (and finally the  one
  760. of `MST TsrUtils', that  suppresses  the  error  messages  of  BASIC)
  761. executed as well.
  762.  
  763.   Never forget to test for the  presence  and  (also  in  TSR's)  the
  764. version number of MemMan. Require at least 2.3(1),  or  even  better:
  765. 2.4. This version can be spread together with the program so it  need
  766. not be a limitation.
  767.  
  768.   It is often convenient to put the current segment  in  page  2  and
  769. (for programs under Disk Basic) the TPA-segments 0 and  1,  that  can
  770. now be determined with the function GetTPA, in the table of segments.
  771. Note that DeAlloc should not be called  for  these  segments.  MemMan
  772. does not check the segmentcodes passed to DeAlloc and  starts  making
  773. errors.
  774.  
  775. ** End **
  776.