# 2. Memory Model

## 2.1 Overview

Within the computer there are four divided areas of memory usable by the Chaprola language, accessed by character position. With commands such as MOVE, GET, or PUT these four areas can be read and modified.

```
+--------------------------------------------------+
|  Primary Data File         1 to  5000             |
+--------------------------------------------------+
|  Secondary Data File      -1 to -5000             |
+--------------------------------------------------+
|  User Buffer Area       5001 to  5896             |
+--------------------------------------------------+
|  System Text Area       6001 to  6054             |
+--------------------------------------------------+
```

## 2.2 The Primary Data File (1 to 5000)

The Primary Data File is the file displayed on the screen in SCIENTRY or the input file in CHAPRPG. When memory is accessed with a Chaprola program, the primary data file occupies locations 1 to 5000. Only one record is loaded at a time.

In SCIENTRY, any change in the Primary Data File is automatically updated on the screen display. In CHAPRPG, the input file is the Primary Data File.

## 2.3 The Secondary Data File (-1 to -5000)

The Secondary Data File is opened by the OPEN command and can be modified with information from the Primary Data File, or vice versa. Memory locations are addressed with a minus sign: -1 to -5000.

**Rules:**
- Only one Secondary Data File may be open at one time.
- The record length does not have to be the same as the Primary Data File.
- If a second Secondary Data File is opened, the first is automatically closed.
- There is no limit to how many files can be opened and closed during execution.

## 2.4 The User Buffer Area (5001 to 5896)

From location 5001 to 5896 is a buffer area for storing information. This area is user-assignable and is not disturbed by the system unless instructed through a program.

**Key properties:**
- If a procedure file is changed during program execution, the user buffer goes unaltered.
- Useful for saving information when going between display or data files.
- Used as a staging area for sending character strings to the print file.
- Can hold information when going from one secondary file to another.

## 2.5 The System Text Area (6001 to 6054)

Fifty-four characters of information are supplied by the computer at all times. Any or all of this information may be accessed or changed by the user using the MOVE command.

| Location | Length | Description |
|----------|--------|-------------|
| 6001 | 2 | Year (last two digits) |
| 6003 | 3 | Julian Date (1--366) |
| 6006 | 2 | Hour (military time, 0--23) |
| 6008 | 1 | Filler (a blank) |
| 6009 | 2 | Minute (0--59) |
| 6011 | 2 | Hundredths of a minute (0--99) |
| 6013 | 3 | Terminal Number (multi-terminal only) |
| 6016 | 3 | User Initials (multi-terminal only) |
| 6019 | 4 | Field Number (cursor position) |
| 6023 | 1 | IVAL (file change control) |
| 6024 | 1 | Reserved for future use |
| 6025 | 1 | MRTENTRY Command (multi-terminal only) |
| 6026 | 5 | Record Number of Primary File |
| 6031 | 8 | Display filename (first 8 chars before .DI) |
| 6039 | 8 | Data filename (first 8 chars before .DA) |
| 6047 | 8 | Procedure filename (first 8 chars before .PR) |

### 2.5.1 Year (6001, length 2)

The last two digits of the year. If the year is 1990, then "90" is in location 6001.

### 2.5.2 Julian Date (6003, length 3)

A three-digit number from 1 to 365 (or 366 for leap years). January 1st is 1; February 1st is 32. The SCIOS converter handles leap years correctly.

### 2.5.3 Time (6006--6011)

- **Hour** (6006, length 2): Military time, 0 to 23.
- **Minute** (6009, length 2): Standard 60 minutes per hour, 0 to 59.
- **Hundredths of a minute** (6011, length 2): Seconds are not used. Every six seconds equals a tenth of a minute. If the time is thirty seconds past the minute, the value is 50.

### 2.5.4 Terminal and User Info (6013--6016)

Active only in multi-terminal systems. The terminal number and user initials are automatically set when the user logs on. Useful for audit trail programs.

### 2.5.5 Field Number (6019, length 4)

The field number where the cursor is placed. Can be changed by the user. Default is field 1.

### 2.5.6 IVAL -- File Change Control (6023, length 1)

IVAL is a number between 0 and 8 representing changes to the display (.DI), data (.DA), or procedure (.PR) files:

| IVAL | .DI | .DA | .PR | Description |
|------|-----|-----|-----|-------------|
| 0 | -- | -- | -- | No change |
| 1 | -- | -- | X | Procedure file changes |
| 2 | -- | X | -- | Data file changes |
| 3 | -- | X | X | Data and procedure change |
| 4 | X | -- | -- | Display file changes |
| 5 | X | -- | X | Display and procedure change |
| 6 | X | X | -- | Display and data change |
| 7 | X | X | X | All three change |
| 8 | -- | -- | -- | Change field number |

The correspondence is a binary translation into base ten: the procedure file is the one's place, the data file is the two's place, and the display file is the four's place.

IVAL is changed by the user after placing the corresponding filenames in the correct system text locations (6031, 6039, 6047).

### 2.5.7 Record Number (6026, length 5)

The record number of the Primary File currently being accessed. Placing a different number in this location moves the user to that record.

### 2.5.8 File Names (6031--6054)

- **6031** (length 8): Display file name prefix (before .DI)
- **6039** (length 8): Data file name prefix (before .DA)
- **6047** (length 8): Procedure file name prefix (before .PR)

Used in conjunction with IVAL to change the active files. This is the basis for menu generation.

---

*Previous: [Introduction](01-introduction.md) | Next: [Commands](03-commands.md)*
