EMULATOR_PDP_11
STEPIC Учебный проект на 'С', эмулятор PDP_11 в стиле ООП
Loading...
Searching...
No Matches
command.c File Reference
#include "pdp_11/command/command_p.h"
#include "pdp_11/pdp_11.h"
#include "pdp_11/pdp_11_p.h"
#include "pdp_11/register/register_p.h"
#include "utils/logger/logger.h"
#include <stdio.h>
#include <stdlib.h>
Include dependency graph for command.c:

Functions

command_t ** command_new ()
 
void command_create (command_t **commands)
 
void command_destroy (command_t **commands)
 
void print_command (address_word_t addr, word_t word_command, byte_t *name_command)
 
void command_reg_dump (struct pdp_11_t *pdp)
 
void command_do_halt (struct pdp_11_t *pdp, address_word_t addr, word_t word_command)
 
void command_do_add (struct pdp_11_t *pdp, address_word_t addr, word_t word_command)
 
void command_do_mov (struct pdp_11_t *pdp, address_word_t addr, word_t word_command)
 
void command_do_inc (struct pdp_11_t *pdp, address_word_t addr, word_t word_command)
 
void command_do_unknown (struct pdp_11_t *pdp, address_word_t addr, word_t word_command)
 

Variables

command_t template_commands []
 
byte_t commands_list = sizeof(template_commands) / sizeof(command_t)
 

Function Documentation

◆ command_create()

void command_create ( command_t **  commands)
33{
34 for (int i = 0; i < commands_list; i++) {
35 commands[i] = (command_t *) malloc(sizeof(command_t));
36 if (commands[i] != NULL) {
37 *commands[i] = template_commands[i];
38 }
39 }
40}
command_t template_commands[]
Definition command.c:10
byte_t commands_list
Definition command.c:21
Definition command_p.h:5
Here is the caller graph for this function:

◆ command_destroy()

void command_destroy ( command_t **  commands)
44{
45 for (int i = 0; i < commands_list; i++) {
46 free(commands[i]);
47 }
48}
Here is the caller graph for this function:

◆ command_do_add()

void command_do_add ( struct pdp_11_t pdp,
address_word_t  addr,
word_t  word_command 
)
92{
93 struct pdp_11_t *ptr_pdp = pdp;
94 if (ptr_pdp)
95 printf("\b");
96 print_command(addr, word_command, (byte_t *) "add");
97}
void print_command(address_word_t addr, word_t word_command, byte_t *name_command)
Definition command.c:51
Definition pdp_11_p.h:4
unsigned char byte_t
Definition types.h:6
Here is the call graph for this function:

◆ command_do_halt()

void command_do_halt ( struct pdp_11_t pdp,
address_word_t  addr,
word_t  word_command 
)
77{
78 pdp_11_t *ptr_pdp = (pdp_11_t *) pdp;
79 word_t * ptr_pc = ptr_pdp->PC;
80 *ptr_pc += 2;
81 print_command(addr, word_command, (byte_t *) "halt");
83 PRINT_RESULT("THE END!!!", "");
84
85 pdp_destroy(pdp);
86 free(pdp);
87 exit(0);
88}
void command_reg_dump(struct pdp_11_t *pdp)
Definition command.c:57
#define PRINT_RESULT(fmt,...)
Definition logger.h:34
void pdp_destroy(struct pdp_11_t *)
Освобождает ресурсы, связанные с экземпляром PDP-11.
Definition pdp_11.c:60
word_t * PC
Definition pdp_11_p.h:16
unsigned short int word_t
Definition types.h:7
Here is the call graph for this function:

◆ command_do_inc()

void command_do_inc ( struct pdp_11_t pdp,
address_word_t  addr,
word_t  word_command 
)
110{
111 struct pdp_11_t *ptr_pdp = pdp;
112 if (ptr_pdp)
113 printf("\b");
114 print_command(addr, word_command, (byte_t *) "inc");
115}
Here is the call graph for this function:

◆ command_do_mov()

void command_do_mov ( struct pdp_11_t pdp,
address_word_t  addr,
word_t  word_command 
)
101{
102 struct pdp_11_t *ptr_pdp = pdp;
103 if (ptr_pdp)
104 printf("\b");
105 print_command(addr, word_command, (byte_t *) "mov");
106}
Here is the call graph for this function:

◆ command_do_unknown()

void command_do_unknown ( struct pdp_11_t pdp,
address_word_t  addr,
word_t  word_command 
)
121{
122 struct pdp_11_t *ptr_pdp = pdp;
123 if (ptr_pdp)
124 printf("\b");
125 print_command(addr, word_command, (byte_t *) "unknown");
126}
Here is the call graph for this function:

◆ command_new()

command_t ** command_new ( )
25{
26 return (command_t **) malloc(
28 * sizeof(command_t *)); // Выделение паамяти для обЪекта command_t
29}
Here is the caller graph for this function:

◆ command_reg_dump()

void command_reg_dump ( struct pdp_11_t pdp)
58{
59 pdp_11_t *ptr_pdp = (pdp_11_t *) pdp;
60 reg_t * ptr_reg = (reg_t *) ptr_pdp->regist;
61
62 PRINT_RESULT("r0:%o r1:%o r2:%o r3:%o r4:%o r5:%o r6:%o r7:%o",
63 ptr_reg->R0,
64 ptr_reg->R1,
65 ptr_reg->R2,
66 ptr_reg->R3,
67 ptr_reg->R4,
68 ptr_reg->R5,
69 ptr_reg->SP,
70 ptr_reg->PC);
71}
struct reg_t * regist
Definition pdp_11_p.h:7
Definition register_p.h:2
Here is the caller graph for this function:

◆ print_command()

void print_command ( address_word_t  addr,
word_t  word_command,
byte_t name_command 
)
52{
53 PRINT_RESULT("%06o %06o : %s", addr, word_command, name_command);
54}
Here is the caller graph for this function:

Variable Documentation

◆ commands_list

byte_t commands_list = sizeof(template_commands) / sizeof(command_t)

◆ template_commands

command_t template_commands[]
Initial value:
= {
{ 0000000, 0111111, (byte_t *) "unknown", command_do_unknown },
{ 0177777, 0000000, (byte_t *) "halt", command_do_halt },
{ 0170000, 0010000, (byte_t *) "mov", command_do_mov },
{ 0170000, 0060000, (byte_t *) "add", command_do_add },
{ 0107700, 0005200, (byte_t *) "inc", command_do_inc }
}
void command_do_halt(struct pdp_11_t *pdp, address_word_t addr, word_t word_command)
Definition command.c:76
void command_do_unknown(struct pdp_11_t *pdp, address_word_t addr, word_t word_command)
Definition command.c:118
void command_do_add(struct pdp_11_t *pdp, address_word_t addr, word_t word_command)
Definition command.c:91
void command_do_mov(struct pdp_11_t *pdp, address_word_t addr, word_t word_command)
Definition command.c:100
void command_do_inc(struct pdp_11_t *pdp, address_word_t addr, word_t word_command)
Definition command.c:109
10 {
11 { 0000000, 0111111, (byte_t *) "unknown", command_do_unknown },
12 { 0177777, 0000000, (byte_t *) "halt", command_do_halt },
13 { 0170000, 0010000, (byte_t *) "mov", command_do_mov },
14 { 0170000, 0060000, (byte_t *) "add", command_do_add },
15 { 0107700, 0005200, (byte_t *) "inc", command_do_inc }
16
17 // добавить остальные команды
18};