![]() |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Technical Reference ManualMEMORY USAGE
INTRODUCTIONThis chapter covers all aspects of memory usage, RAM, ROM, registers and I/0. To use an Organiser effectively it is essential to understand the way memory is used. The six scratch registers UTW_S0 to UTW_S5 may be used for local values. They are used by the operating system and are not guaranteed to be preserved by operating system calls. The seven scratch register UTW_R0 to UTW_R6 are maintained values. If they are used, the existing values must be pushed and restored before returning from that routine. MEMORY MAP
RAM MEMORYZERO PAGEZero page RAM runs from $40 to $FF. From $40 to $DF is used by the operating system; from $E0 to $FF is the transient application area. It is safe to assume that these variables get trashed by all device drivers. In particular it should be noted that a WARM BOOT uses $F8 to $FF. For example the RS232 uses $E0 to $FF for the setup parameters so that the code is faster and more compact. Every time COMM is re-invoked these parameters are copied down from the dedicated application space (at DV_SPAR - $214F). NON-ZERO PAGEOn the different models RAM is at the following addresses: The top $100 bytes of RAM is reserved for the processor stack in models CM, XP and LA. In models POS-350, LZ and LZ64 the processor stack is situated inmidst the system variables (BTT_MSTACK). Models LZ and LZ64 use the top $100 bytes for additional system variables. The RAM in an POS-350 and an LZ64 is arranged in 3 (LZ64) or 5 (POS-350) "banks" of 16K which are switched as required. On the LZ64 and the POS-350, the 16K RAM between addresses $4000 and $8000 is used in the same way as on the CM/XP/LZ models, for example to hold the current diary (and on the LZ, the current notepad), except that "PACK A:" starts in the highest RAM bank and, as it grows, works its way through the other banks and then into the main bank which the other functions (diary etc.) use. PEEKing and POKEing between addresses $4000 and $8000 on an LZ64 or an POS-350 will only access the bank which is currently selected, and is therefore not recommended. At $2000 the non-zero page variables start. Immediately thereafter is allocated space. This consists of 16 pre-allocated cells for use by the operating system and 16 cells which can be used by applications for permanent use. The pre-allocated areas are (in order):
Device A: has the same format as a datapack and contains both OPL procedures and databases. There are just a few differences between device A: and devices B: & C:
The allocated area grows up towards the language stack. Before any operation involving memory both the allocator and the language ensure there is at least $100 bytes between RTA_SP and ALA_FREE. If there isn't 'OUT OF MEMORY' or 'PACK FULL' is reported. These messages are functionally the same in the case of device A:, it depends on which routine the out of memory condition is detected. NON-RAM MEMORY MAPIn the memory map certain areas contain system registers and I/O rather than RAM. INTERNAL REGISTERSThe addresses in the range $01 to $1F are used as internal registers by the 6303 processor. Their use is as follows:
See System Board for a full description of the Organiser use of the timers and ports and the Hitachi 6303X User Guide for a more detailed general description of the ports. MEMORY MAPPED I/OIn the memory map between $180 and $3FF lie the semi-custom chip addresses:
The LZ, P350 and multi-lingual XP need more control lines for their memory management, and for this the following semi-custom addresses are used:
The semi-custom chip does not decode all the address lines. For the LCD driver $180,$182,$184 up to $1BE are identical, as are $181,$183, up to $1BF. For the other addresses the bottom 6 bits are ignored (except that LZ only ignores only bottom 5 bits). These addresses should be accessed with great care. To prevent casual accessing, Peeking and POKEing from OPL to the range $0182 to $03FF and in the range $00 to $3F are disallowed. MEMORY USAGEOPERATING SYSTEMNAMING CONVENTIONAll variable names have the following format: XXY_ABCD where XX is the abbreviated name of the module which uses the variable, The abbreviated module names are:
SYSTEM VARIABLESThe System Variables are described in detail at the System Variables Page. BUFFERSRTT_FILE ($22E9) - File Control BlocksRTT_FILE contains 4 file control blocks with the following structure:
PKT_ID ($20D7) - Pack IDsContains 4 pack IDs, these are the 10 bytes header of each pack. See Datapack ID String for details. RTT_NUMB ($20FF) - Calculator VariablesEach memory, M0 to M9 has 8 bytes allocated to it. The format of each is the same format as a floating point number. AMT_TAB ($22F9) - Alarm TableSix bytes for each entry in the format:
TIMINGThere are a number of variables which are measured in ticks. A tick is (KBW_TDEL + 35) / 921600. The default value of KBW_TDEL is $B3DD, which gives a tick of 50 milliseconds delay. I/O DRIVER SPACEAt DVT_SPAR ($214F) 56 bytes are reserved for I/O drivers. This space is allocated by PSION to officially supported devices. This area may not be used for any other purpose. FREE MEMORYEvery time an OPL operand or operator is executed, it checks that at least 256 bytes is free - no operand or operator can increase the size of the stack by more than 256 bytes. Before increasing the size of an allocated cell the allocator checks there will be, at the end of the operation, at least 256 bytes free. ALLOCATORThere are 32 allocator cells available; the first 16 are pre-allocated to the operating system, the others are available for applications. The allocator scheme is very simple. Each cell has one word associated with it (pointed to by a tag). If the cell is assigned it gives the start address of the cell, otherwise it is zero. The first non-zero word following gives the length of the cell by subtraction. When a cell is grown all the allocated cells above it are moved up in memory, when a cell is shrunk all the cells above are moved down. You may deduce from this that frequent growing and contracting of cells can slow an application down considerably. If any cell is altered in size, for example by calling one of the allocator functions or by adding or deleting a record from device A:, any of the other cells may move. It is therefore essential to re-calculate the base address of a cell every time something could have moved it.
When device drivers are loaded in, the code is fixed up and becomes non-relocatable. So once a device is loaded it cannot be moved which is why it is placed in the lowest cell. When the Organiser is rebooted (by pressing the ON/CLEAR key at the top level) it first removes all devices currently loaded and then boots in all the device drivers from the devices B:, C: and D:. This also happens if the language is changed on multilingual organisers. LANGUAGEOPL is a stack based language. Almost every operand/operator has some effect on the stack size. The one exception is file buffers. When a file is opened the file buffer cell is grown to 256 and the field names' cell grown to take the field names. When a file is closed both these cells are reduced back to zero length. For details of the buffer structure see section Records and Fields. When OPL starts running, the stack is initialised to BTA_SBAS. If this is changed, the next time OPL is run it will start from the new address. The only thing which resets BTA_SBAS is resetting the machine. PERMANENT MEMORYFor many applications it is sufficient to have permanent data in an allocated cell and to access it indirectly from the address of the cell. For other applications it is desirable to be able to use a permanent fixed area of memory either for machine code or for data. An application can grab permanent memory in two different ways. It must be noted that if a number of applications use these techniques there is no reliable way to free the space selectively .
The only way to automatically reset these two allocations are a TOP LEVEL RESET or, of course, a COLD BOOT. SYSTEM SERVICESServices that change the size of a cell will not move the base of the cell. However all cells which come after this cell will be moved. Warning: The parameters are not checked. If incorrect values for tag or offset are supplied results will be unpredictable and potentially catastrophic. The user may write his own shell to protect against this bug. AL$FREEFrees a cell. A cell is freed by making its entry zero in the allocator table. This is the reverse of AL$GRAB. AL$GRABAllocates a new memory cell. As the allocator may move the base of a cell any time a request is made to the allocator, the base addresses of all cells are held in the table of addresses starting at ALA_BASE. Thus if the tag returned from this call is stored in a memory address called CELL then the following code should always be used to get the base of the memory cell into a memory address called BASE. LDX CELL ; Load the tag
LDX 0,X ; Get the de-referenced address
STX BASE ; Save the real address
This procedure should be called any time a routine is called which could cause the allocator to move the memory cells around. AL$GROWIncrease a cell. The base of the cell will not move as the extra space is added after the start of the cell. However all cells which come after this cell will be moved to make room for the extra space. AL$REPLIncrease or decrease a cell. The base of the cell will not move as the extra space is added or deleted after the start of the cell. However all cells which come after this cell may be moved. AL$SHNKDecrease a cell. AL$SIZEReturn the size of a cell. AL$ZERODecreases the size of a cell to zero but does not de-allocate the cell. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||