Scenergy #01
31 мая 1999 |
|
Coding - Driver RAM DISK'a for ZX-Spectrum'128.
Driver RAM Disk'a for the ZX Spectrum 128 1. Instead of joining It was a very long time ... Or, to be exact - in the courtyard stood a 1995-th year. As once in a while, we, like all beginners Spectrum team worked directly over many projects, and planned to make more. Some of these projects naturally applies to such genres as game and the demo (including the plans were notorious Megaball and Paradise Lost). And that is also quite obvious to start-up team - we've had problems with software. In particular, we did not have enough programs to work with sprites - it simply not there. It was then that the idea SpriteLand'a. At first it was just a bunch of protsedurok not having not only the public interface, but did not cumulate. Each of them simply run out of Zeus'a, rehearsed, and then the results manually unloaded by BASIC. Subsequently (Where such a "convenience" we sick and tired) wrote the first version interface (on BASIC'e) and were taken attempts to assemble it all in a heap. More - more. We have already become clear that of "utility for internal use" This program is gradually grows into something quite competitive ... Version 1.0 appeared in October of 1995, Then, literally within a month came up to version 1.19. And version 1.11, even managed to sell Logrosu for "big money" - $ 100! :) Apparently, so version 1.11 was the most widespread, despite some bugs. At version 1.19, oddly enough all decayed ... And the decayed capital - as much as 2 years:) And this is despite the fact that there sat a couple of ugly bugs, and some necessary functions simply absent. Resuscitation of the project no matter how SpriteLand strange happened thanks to the emergence Project Scenergy, the first issue of which you currently watching on the screen your monitor. Was produced significantly Modified version 1.25, but further me she had never left. The thing is, I was planning to publish it in annex to the zero number Scenergy, but a number of reasons it was never released. Now, in the first issue you Scenergy It starts with two gifts: a new version SpriteLand'a in the annex, as well as in As a bonus, this article. :) "Where the hell was he?" - You ask - "when What is life SpriteLand'a, when the article is something about the RAM Disk? ". My answer: The fact is that during development SpriteLand'a created two very useful things: a driver and RAM Disk'a interface library. The time has come, and Now I want to publish their source code for use throughout the Spectrum scene. It is always easier and more enjoyable use to design their programs ready, the organized and well documented source code, rather than try for the umpteenth time to reinvent the wheel. That is why the pages I Scenergy I would like to begin publishing the different source texts. I hope that experienced coders support me in this endeavor - because of this will all just good! Not for nothing on all other platforms are written in a heap Articles with the descriptions of the algorithms published sources pile - it is very contributes to the development platform. That's right learn from this good tradition! 2. A few general words So what we have today? In this article you will find a complete description of the driver RAM Disk'a and annex - itself the source format TASM v3.0. All (c) at the source and description belong to me - Flying / DR. Wherefore, I, as the copyright holder, authorize its free use for any purpose. Also allow to patch the source with to its completion or alteration to your needs. The only condition - to save copyrights. This driver was created specifically for SpriteLand'a. Date of last revision: 10/25/1995 (antiquity of which:)). When establishment used TASM v3.0 (c) RST7/CBS and STS v2.6 (c) Stalker, for which they thank you so much! I hasten to note that I have not finished the driver specifically for publication - it it is in the form in which it stands in SpriteLand'e. This is partly because my laziness thoroughly understand the source written by more than 3 years ago, and partly the fact that I do not want to go into full work program. About 100% bug-free this driver I can speak Based on what has been 3 years he works in SpriteLand'e and for all this time no bugs in it is not noticed. Again due to my laziness in the text source code remains a bit vague description of the driver features a slightly clumsy English (because it is not TASM supports Russian characters and Glory God! :)) 3. Characteristics of drivers Utility: This program is a driver for the RAM Disk'a ZX Spectrum 128. Specifications Driver: - Maximum number of files on the RAM Disk'e: 256 - File size: 1 .. 65535 bytes. - The maximum amount of disk: 64kb (More on this below) - Operations are supported: - Read - Record - Remove - Rename - Optimization of space RAM Disk'a - The principle of organization: a-la TR-DOS, but memory is not divided into sectors minimum unit - 1 bytes. - How it works: a-la TR-DOS. Ie through entry point to the transfer function number and the parameters in registers. - Memory requirements: - The driver itself: 1588 bytes - Buffer for the operation: 256 bytes - Catalog of RAM Disk'a: 256 * 6 = 1536 bytes - The rest of the page based memory can be used under the RAM disk. Directory can be paged in memory, the driver itself and a buffer should stay below # C000. All operations with data on the RAM Disk'e made through the buffer. This allows remove all restrictions on the address location data for read / write. The buffer size can be varied at compilation, however, should remember that too small buffer size will lead to general slowing down procedures RAM Disk'a. It should be noted that in contrast to TR-DOS files on the RAM Disk'e not have a name - only the number, which, in essence, is file name and is used in all disk operations. 4. Driver Features All work with the driver of RAM Disk'a performed through a single point of entry. Number of the calling function and the necessary parameters are passed through registers. The general format of the call driver functions: LD A, <function number> CALL RAMDRV Output for all functions of the contents register reflects the current state of RAM Disk'a: - Flag CY indicates success or ended with the driver. CY = 0 - everything is OK CY = 1 - error. In this case, A would be an error code (see below) - Register B contains a number of used descriptors. In general, If it is not equal to the number of files on the RAM as Disk'e Deleted files too occupy descriptors before will Optimization space RAM Disk'a. - Register C contains a number of free memory pages. - Register of HL contains the number of free memory currently in use page. Thus as registers C and HL can estimate the total number of free memory on RAM Disk'e. Driver functions: # 00 - driver initialization RAM Disk'a. Directory is cleaned and initialize all internal variables. This function must be call before you start working with RAM Disk'om. Parameters: No # 01 - Reading a file from the RAM Disk'a in memory. Reading is made to any address in memory, but only the main computer memory! Read / write Page memory driver does not know how! Parameters: HL - Address of buffer in memory to be reads. DE - The size of the read block. If DE = 0 the size of the block will be taken from descriptor file in the directory. B - Number of retrieved files. Possible errors: # 03 - 'Object is non exist'. File with the same number on the RAM Disk'e absent. # 02 - Writing to a file on the RAM Disk. Recording from any address in memory, but only from the main computer memory! Read / write Page memory driver does not know how! Parameters: HL - Address of buffer in memory, which will be recorded on the RAM Disk. DE - The size of the recording unit. B - Number of the recording file. Possible errors: # 01 - 'No free ram disk space' Out space to write the file to RAM Disk. Worth a try free up space, making the optimization RAM space Disk'a. # 02 - 'Catalogue overflow'. All the descriptors Directory RAM Disk'a busy. Worth try to free the descriptors occupied by deleted files, making optimization space RAM Disk'a. # 05 - 'Object is already exist'. File with this number is already in RAM Disk'e # 03 - Deleting a file from the RAM Disk'a. Parameters: B - Number of deleted files. Possible errors: # 03 - 'Object is non exist'. File with the same number on the RAM Disk'e absent. # 04 - Rename the file. Parameters: B - Old file number. C - A new file number. Possible errors: # 05 - 'Object is already exist'. File with this number is already in RAM Disk'e # 05 - Optimize RAM Space Disk'a This function is similar to the operation MOVE in TR-DOS. As a rule, cause it should be in case of errors 'No free ram disk space' or 'Catalogue overflow' when trying to record file as it may frees disk space and descriptors employed remote files. For example, in SpriteLand'e call this function is built into the procedure Driver error handling RAM Disk'a and after receiving appropriate error at first tries to defragment the RAM space Disk'a, then re-done attempt to write the file, and only case of repeated failures is given error message. Parameters: None. Possible errors: None. # 06 - Getting information about the current state RAM Disk'a. Actually, this function is purely formal because return it data and so returned to each accessing RAM Disk'u. But sometimes it is useful to learn about the current state RAM Disk'a nothing in this not doing. Parameters: None. Possible errors: None. # 07 - Getting information about the file. Parameters: B - File Number. Return values: B - File Number. C - Number of page on which beginning of the file is located. If C = # FF, then the file does not exist on the disk. HL - Address to which the file resides on the RAM Disk'e. In principle, data Registers C and HL can get to file data directly to Disk'e RAM, but I do not do it advise as no one can guarantee that the file entirely located in one page memory. DE - The length of the file. Possible errors: None. 5. Error messages. These error messages are returned A case in every time you call the driver RAM Disk'a. If the error code is different from # 00 - CY flag is set as a sign erroneous conclusion. # 00 - 'No errors'. All OK. # 01 - 'No free ram disk space' Out space to write the file to RAM Disk. Worth a try free up space, making the optimization RAM space Disk'a. # 02 - 'Catalogue overflow'. All elements in catalog RAM Disk'a busy. Worth try to free the descriptors occupied by deleted files, making optimization space RAM Disk'a. # 03 - 'Object is non exist'. File with the same number on the RAM Disk'e absent. # 04 - 'Illegal function number'. Function with this number is not in driver. # 05 - 'Object is already exist'. File with this number is already in RAM Disk'e 6. The directory structure RAM Disk'a The directory structure Disk'a RAM: +0 [Byte] File Number. +1 [Byte] starting page number or # FF if this descriptor free. +2 [Word] Address of the beginning of the file in memory. +4 [Word] size. Data from (a) and (2) form a complete pointer to the beginning of the file in the space RAM Disk'a. Number of pages - the logical (# 00 .. # FE). Physical page number is taken from Table RAMPAGE (see below) 7. Description of the internal variables Strictly speaking, the source is sufficiently well commented (though in English dubious quality:)), so here I will describe only the most important variables and function. EQUS: CATLEN EQU 6 The size of each directory entry RAM Disk'a. At the moment, is 6 bytes thus, the entire directory is: 6 * 256 = # 600 = 1536 bytes. Postscript to this variable in the source states that when resizing directory entry to be rewritten multiplication CATLEN the procedure GETPADR so be aware! :) CAT EQU # C000 Directory location in memory. As I have already said - it can be located anywhere (even on pages where he sits in SpriteLand'e). More details See description on CATPAGE and procedures SETCATP. BUFLEN EQU 256 The buffer size for data exchange between Disk'om RAM and main memory. In original form is located in the body driver, but can be located on any address below # C000. MAXFUNC EQU 7 The number of functions supported Driver RAM Disk'a. Need for validation function number. RAMPORT EQU # 7FFD Port number of switching pages. Originally intended to do support for extended memory (as below), but before the end of this idea has not has been implemented ... Variables PAGES DEFB 4 Number of memory pages used a RAM Disk. In principle, the RAM size disk'a not limited to 64KB, but because in SpriteLand'e (where I got this source) of free memory left only 64kb - and here, respectively, is the number 4. An increase in the size RAM disk'a - below. MAINRAM DEFB # 10 Number of pages included by default as the main computer memory. I will explain a bit: The driver actually can work (read / write) with only the main computer memory, which As is known, consists of a 5-st, 2 nd, and another one (any) included in the page Articles with the descriptions of algorithms, procedures, koderskih various tricks to enable improve the performance of programs ... And in appendix, we will see high-quality source that will be useful not only novice coders. Dreaming ... :) Let's see - can my dreams come true ... Address # C000-# FFFF. So, the number of the pages and must be set in this variable. The page number should be Physics! By the way, if you change this number of the country particle - you can read / write and other pages of memory:) CATPAGE DEFB # 11 Page number in which the Catalog RAM Disk'a. It remains of SpriteLand'a in which directory RAM Disk'a lies in the paged memory. Number Pages must be physical! RAMPAGE DEFB # 13, # 14, # 16, # 17 This table lists the physical number of pages allocated for RAM Disk. Their number is specified in the variable PAGES. BUFFER DEFS BUFLEN Buffer for data exchange. If desired, can be rearranged to another location. FUNCT DEFW INIT DEFW READ DEFW WRITE DEFW ERASE DEFW RENAME DEFW MOVE DEFW SYSINFO DEFW OBJINFO This is a table of pointers to procedures implement the corresponding functions Driver RAM Disk'a. Address Procedure selected by the feature number. Procedure, I will not describe here - those who need it, will be able to deal with them yourself. The more so because each procedure in the source file contains a comment with a brief description and listing of its input parameters. 8. Prospects. Naturally, the first thing you want to do with this driver - make it work with different top memory computer models. Getting to write this article, I have just looked at the source, and found that obstacles to this no! :) How Still cool, I wrote the program 3 years ago! :) Apparently affected by training 3 rd POVT'a course at the university. In general the only thing that interferes directly immediately begin using this driver with upper memory - no proper switcher pages of upper memory. What should be done to make it work? 1) Insert the procedure for switching page top of memory instead of the procedure CHPAGE. At the entrance of this procedure transferred to the logical page number RAM Memory Disk'a. This procedure should take a physical page number from the table RAMPAGE and turn it on. All registers must be preserved. 2) A remake of procedure SETMRAM and SETCATP so that they included pages respectively of main memory and Catalog RAM Disk'a. (For more details see descriptions of variables and MAINRAM CATPAGE). Everything! :) Thus, you will receive the full working RAM Disk with a maximum capacity # FE * # 4000 = 4,161,536 bytes, or nearly 4Mb! In addition, it would be nice to add another functions in addition to the existing. Make it is also easy: 1) Write a new function driver. All procedures for dealing with low-level RAM Disk'om at the start of the driver. 2) Add a pointer to the table FUNCT. 3) Change the number of functions in MAXFUNC. And yet - the function will be part of the driver. 9. Afterword Hopefully, this driver useful to you. Its really easy to use when writing a number of programs (SpriteLand'a, for example:)). I also hope that other coders support my initiative, and in the pages our journal, we see good
Other articles:
Similar articles:
В этот день... 23 November