Chapter 2. General principles of screen output in UKNTS.      

                           

             

§four. EMT and TRAP software interrupts.

                           

              4.0 Interrupt Commands             

             

              Among the many instructions of the microprocessor 1801 there are several instructions whose action is as follows: an interrupt is called at a fixed address (the address of the interrupt vector is a.v.p.). These commands are:

 

              Table 4.0. Interrupt Commands             

             

Team

Code

A.V.P.

BPT

000003

14

IOT

000004

20

EMT

104xYZ

thirty

TRAP

104XYZ

34

 

              Example 11. Exercise with interrupt commands IOT and EMT.             

             

The IOT (Input-Output Trap) command causes an interrupt with address 20. In the System, this a.v.p. not used in any way. Fill this gap. We work in RAM:

 

              20: 000240             

             

              240: 104044 EMT 44                           

                            163573 "* DOWNLOAD FROM THE NETWORK *"             

                            000002 RTI             

                           

Now in any free cell write down the number 4 (IOT code) and run from this address. Well, if you get bored playing with this inscription, find another in the application, and write down its address after the EMT 44 code. Better still, read on.

 

             

The first two teams ( BPT and IOT ) are not interesting to us, although they can be put into action if you wish. The other two, EMT and TRAP, are of some interest.

The high byte of these commands contains the command code (according to it, the processor recognizes them), and the low byte can be any. This organization of teams allows you to carry useful information. To implement this information, it is necessary to suspend each interrupt routine, which is called the dispatcher.

This name is due to the fact that, depending on the code in the low byte, these programs transfer control to different subprograms that perform each of their actions. This allows you to use the EMT and TRAP commands as single-word subroutine call instructions.

              Consider the implementation of both dispatchers in the System.

             

              4.1 EMT dispatcher.             

             

              At address 30, the interrupt vector of the EMT-dispatcher is written:

             

              30: 174270

              32: 0             

             

The first word is the address of the dispatcher. The second is the word that is loaded into the processor status word (PS) when entering the interrupt routine. 0 means that all interrupts are allowed while the EMT manager is running.

The following is a block diagram of an EMT dispatcher with explanations:             

 

             

             

The diagram shows that the dispatcher calls the subroutine, the address of which is determined by the following formula:

              Adr = (160000 + XXX), where XXX is the low byte of EMT.

             

In other words, a table is stored from the address 160000, which contains the addresses of the desired routines. Of course, the low byte of EMT should be even, in order to avoid misunderstandings in the processor.

ROM addresses from 160000 to 160012 store some interrupt vectors, therefore EMT with low bytes is used, starting with 14. There are only 10 useful routines called by the EMT manager. A list of them is given in the appendix. The remaining routines consist of one command - RETURN.

 

 

 

              4.2 TRAP dispatcher.             

             

The TRAP dispatcher vector is written at address 34:

             

              34: 174344

              36: 200

             

The second word says that during the operation of the TRAP-manager interrupts from the network and programmable timers, from the keyboard, from the RESET command in the CPU, from channel interruptions will be prohibited.

The block diagram of the TRAP dispatcher looks like this:

             

              < >

             

The routine address is calculated as follows:

              Adr = (160160 + XXX), where XXX is the low byte of TRAP.

             

Those. subprogram addresses are stored from address 160160. There are only 3 of these subprograms, i.e. only three TRAP commands make sense:

              TRAP 0,

              TRAP 2,

              TRAP 4.

              The difference between them and EMT routines is that they should end on RTI, and not on RETURN.

 

                            Summary to §4:

             

             

§five. The general scheme of output to the screen.

             

             

              5.0 Buffer and its structure .               

             

              Information on the screen is sent byte by byte. Each processor can have access to the output of symbolic and graphic information to the terminal. For this, each processor has its own path.

The CPU sends information through K0. PP sends it through EMT commands. But in any case, these bytes are written to a special area of ​​the RAM RAM called the buffer. It is located in addresses from 2000 to 2177 (200 bytes).

The buffer allows you not to wait until the sent byte is displayed on the screen (in one way or another), and is a "queue" of bytes in, ready for processing (output).

The variable in the RAM RAM (22544) is a pointer to the tail of this queue. That is, it contains the address of the cell where the next incoming package will be recorded (from the CPU or the PC).

 

              5.1 Writing to the buffer from K0.             

             

When recording from the CPU to channel K0, with an allowed interrupt from the receiver, the interrupt from the receiver 320. If interrupts are disabled, then there is another way to read information from K0 into the buffer - this is the TRAP 4 command. Then, if the message was valid (the readiness bit was set in the receiver), the information is read into the buffer from the corresponding data register.

 

Both bp from K0 and TRAP 4 are essentially the same program, but with different entry points (Figure 5.1).

A few more variables are used here. Their meaning is as follows:

             

              Table 5.1

Address

Appointment

7042

Enables or disables communication with the CPU through K0:

              0 - communication is prohibited,

              1 - communication is allowed.

7064

Counter of bytes to be processed. May contain from 0 to 177.

22546

Buffer overflow sign . If (7064) = 177, and a new byte arrives, its entry in the buffer is not performed, and (22546) APPROPRIATE and wa etsya 2 (overflow). Resets via TRAP 4.

                           

              5.2 Writing to the buffer from the software.             

                           

The buffer can also be replenished from the PP. Three commands can be used for this: EMT 42, EMT 44 and EMT 46.

EMT 42 writes the low byte of R0 to the buffer, EMT 44 - the line whose address is contained in the word following the command, and EMT 46 - the line with the address in R1.

In schemes ah 5.2 and 5.3 shows the execution of these commands. Since EMT routines can also be called via CALL, the diagram shows the addresses of additional entry points.

             

             

If you execute, for example, such an excerpt from the program:

             

                            JSR R5, @ # 117204             

                            .WORD A             

                            .

                            .

              A: ASCIZ / *** WHY DO YOU EMT 44? *** /             

             

then a line is loaded into the buffer, the starting address of which is A. This will be somewhat faster than using the fragment:

                            EMT 44             

                            .WORD A             

                            .

                            .

              A: ASCIZ / *** WHAT WOULD YOU DO WITHOUT EMT 44? *** /             

             

              since the call to the EMT dispatcher is bypassed.

             

Note that after increasing, the & ~ 200 command is executed with the buffer pointer , which prevents it from exceeding the value 2177.

 

                            Summary to §5:

                           

 

 

 

- the interrupt from the receiver K0 is triggered.         

- when calling TRAP 4.         

 

             

              Table 5.2

What we write and where

Ways to achieve

With immediate withdrawal

Without it

1 byte from R0

EMT 42

CALL @ # 117136

A string whose address is in R1

EMT 46

JSR R5, @ # 117206             

A string whose address is A

EMT 44

Word a

JSR R5, @ # 117204             

.WORD A

 

Immediate display methods differ by executing TRAP 0 at the end of the subroutine.

 

 

§6. TRAP 0, or Process Manager. Management strategy.             

             

                            6. 0 Scheme of the Process Manager .             

 

Of all the procedures performed by the software, TRAP 0 is perhaps the most necessary and indispensable. In addition to the output to the screen, she is responsible for many other I / O functions, as well as some internal functions.

TRAP 0 can also be called a process manager , which coordinates the work of external devices, adjusting to their needs (and to the needs of the user, in the end) all the resources that are wired into ROM.

The TRAP 0 routine itself is laconic. It is just short (you can take a look at the 6.0 scheme). However, understanding her work immediately will be quite difficult. Therefore, in a simplified manner, we consider the "management strategy" in the RAM RAM.

              6. 1 Management Strategy.             

             

              We trace what happens in the criminal code when the power is turned on.

             

  1. The software starts up and starts working from the address 160300. This is the start address of the initial start-up program (PNZ).

 

  1. PNZ stops the CPU (just in case), copies the programs necessary for normal operation to the CPU RAM, and starts the CPU.

 

  1. Then comes the test control of memory and processors. Its results are remembered.

 

  1. Initialization of external and internal devices is performed, standard interrupts are suspended from them, RAM RAM is created (i.e., the initial values ​​of some variables are loaded). Note that screen initialization is performed using the EMT 40.

 

  1. According to the results of the start test, in case of an error, a diagnosis message is issued, for example: "Start test ROM error 2", indicating that the 2nd bank of the ROM is faulty.

 

  1. There is a transition to the process manager, to the point @. (We will distinguish between TRAP 0 and the process manager as the entry point. If you enter the point @, we assume that the process manager is working).

             

              Further, all the work of the software goes through the process manager. How does this happen?

 

              6. 2 Requests. Query and process tables.             

             

There is a table in RAM RAM at addresses from 7060 to 7102. We will call it a query table and try to explain this name.

Each word in the table has its own task:

             

              7060 - processing information from the keyboard,

              7062 - loading from WU,

              7064 - screen output,

              7066 - cursor control,

              7070 - menu "Setting modes",

              7072 - me "Download",

              7074 - work with the printer,

              7076 - start a user routine,

              7100 - testing,

              7102 - exit to the process manager (back).

             

Their normal state is zero. If you need to perform any of the above processes, 1 is added to the contents of the corresponding cell.

The process manager works on a cycle basis and scans the query table in its work. Having found a cell from the table nonzero (and he looks through them in order), the dispatcher calls the corresponding subroutine, i.e. the process itself. The addresses of such routines compose their own label — a table of process addresses.

This table is located in the ROM at the addresses 174232 ... 174252, i.e. contains 9 addresses. The last cell in the query table 7102 does not match the address in the process address table.

How and when does the contents of the query table change? We have already met with cell 7064 - each time it is written to the byte buffer, it is incremented. As you can see from the table, this cell is really responsible for the on-screen output. If it is set (not equal to 0), the dispatcher starts the screen output routine, and it already processes the information written to the buffer, subtracting the unit from (7064) after each processed byte. This is repeated until the cell is reset to zero. Then there is a return to the process manager and the scan continues.

Other processes treat their request cells in a similar way, with some decrementing and others immediately zeroing them out.

The increase or installation of requests is carried out "from the side", mainly by interrupts: from the keyboard, from channels, from the network timer.

The cell with the address 7102 - the last of the query tables - does not change its value - 1, and serves to resume the cycle of the process manager.

 

              6. 3 table of vectors. Calling processes through TRAP 0.             

             

Immediately after the query table in RAM, another table follows - the table of vectors. If one of the processes is executing, and another process must be executed from it without completing the current one, then TRAP 0 is called (as is done from EMT 44, for example). The vector of the interrupted process, or rather, the current address is rewritten in the vector table. In it, each cell also corresponds to a process. The difference between the addresses of the "same" cells of the query table and the vector table is 24.

By executing the process for which it was called, TRAP 0 finds the installed cell in the query table. Depending on the contents of the vector table (or rather, its cell to which the established request corresponds), TRAP 0 either returns to the interrupted old process via JMP (in the vector table - a nonzero vector) or starts the process via CALL (in the vector table - 0) .

Minor subtlety: TRAP 0 cannot execute a process that is “below” the one from which it was called. That is, called from the screen output program (request address - 7064), it will not reach requests whose addresses are more than 7064 and can only process keyboards and external devices. Therefore, the processes are arranged in decreasing order of importance.

 

              Example 12. Interception of requests.             

             

The vector table is the most convenient loophole for intercepting processing of requests for processes. Let's try to intercept the processing of requests for the cursor tracking process.

 

In the PP monitor, record the following:

             

              41000 : 042737 BIC # 200, @ # 177716                                                       

                            000200

                            177716

                            052737 BIS # 200, @ # 177716                                         

                            000200

                            177716

                            004737 CALL @ # 176056                           

                            176056

                            012737 MOV # 41000, @ # 7112                                         

                            041000

                            007112

                            000137 JMP @ # 174222                           

                            174222

                           

              7112: 041000             

             

Each time you access the cursor tracking process, a piezodynamic click will now sound.

 

 

              6. 4 Internal and external procedures.             

             

All procedures executed by the software can be divided into internal and external relative to the process manager. Internal - processes controlled by the dispatcher. External ones are subroutines not controlled by the dispatcher (interrupt routine).

External procedures do not have the right to call TRAP 0, this will cause the process manager to "crash" out of the loop and the machine will freeze.

The addresses of the vector query tables, as well as the contents of the task table are shown in table 6.0:

 

              Table 6.0.

N

Process

Request Address

Vector Address

Process address

one

Terminal input

7060

7104

104306

2

Download from WU

7062

7106

125030

3

Terminal output

7064

7110

111144

four

Cursor control

7066

7112

176056

five

Menu "Setting modes"

7070

7114

100040

6

Download Menu

7072

7116

100742

7

Work with printer

7074

7120

176076

eight

User routine

7076

7122

176116

9

Testing

7100

7124

176460

ten

Process manager cycle

7102

7126

-

             

Example 13. Interception of a cycle of the manager of processes. Method 1

             

              The last word of the vector table 7126 contains the number 174222 (address of the restart of the process manager). In principle, nothing prevents you from writing another address there, and do something like continue the process manager on it.

 

              Our process will remain the same - click:

             

              41100: 042737 BIC # 200, @ # 177716                                                       

                            000200

                            177716             

                            052737 BIS # 200, @ # 177716                                         

                            000200

                            177716

                            000137 JMP @ # 174230                           

                            174230

             

              7112: 000000             

              71 26: 041100             

             

              Do not be surprised, however, that after the changes made, everything will remain as it were, as it were - quiet and smooth. The PP monitor is the reason for this - it is part of the "Installation" menu process, and as long as you are in it, the process manager will not reach the end of the query table, which means that it will also restart request. Exit this menu, and if you do not immediately get to the "Download" menu, which, by the way, is one of the processes, you will hear sound with a frequency of about 10 KHz .

 

 

Example 14. Interception of a cycle of a manager of processes. Method 2             

             

Let's see what happens if the process manager restart vector is reset to zero : (7126) = 0. Then the dispatcher will process the restart process through CALL, taking the address from the table of process addresses in ROM. But such an address is not provided for the restart process, and the dispatcher will take the first cell after the table. Its contents are 13700, which means that the subroutine will be called at address 13700. This is the second way to bring the dispatcher cycle to its ending. The exit from this ending should be through RETURN.

 

              13700: 000137 JMP @ # 41200                                         

                            041200

                           

              41200: 042737 BIC # 200, @ # 177716                                                       

                            000200

                            177716

                            052737 BIS # 200, @ # 177716                                         

                            000200

                            177716

                            000207 RETURN             

                           

              7126: 000000             

 

Filling this example and exiting all the menus, you will hear a sound. So, we taught the process manager to whistle.

 

                            Summary to §6:

                           

             

  1. Bootstrap program.
  2. Process Manager (aka TRAP 0).
  3. Interrupt routines.
  4. All the rest.

                           

              Everything that is included in paragraph 4 is called by the process manager.

             

 

 

 

 

 

 

 

             

              1) internal to the process manager (the processes themselves),

              2) external to it (initial start-up program, interrupt routines).

Original text

Среди множества команд микропроцессора 1801 есть несколько команд, действие которых состоит в следующем: вызывается прерывание по фиксированному адресу (адрес вектора прерываний - а.в.п.).