GE-115 Emulator
An Emulator of the General Electrics GE-115 computer
peripherical.c
Go to the documentation of this file.
1 #include <stdlib.h>
2 #include <string.h>
3 
4 #include "ge.h"
5 #include "peripherical.h"
6 
7 int ge_peri_on_pulses(struct ge *ge)
8 {
9  struct ge_peri *p;
10  int r;
11 
12  for (p = ge->peri; p != NULL; p = p->next) {
13  if (p->on_pulse == NULL)
14  continue;
15  r = p->on_pulse(ge, p->ctx);
16  if (r != 0)
17  return r;
18  }
19  return 0;
20 }
21 
22 int ge_peri_on_clock(struct ge *ge)
23 {
24  int r;
25  struct ge_peri *p;
26 
27  for (p = ge->peri; p != NULL; p = p->next) {
28  if (p->on_clock == NULL)
29  continue;
30  r = p->on_clock(ge, p->ctx);
31  if (r != 0)
32  return r;
33  }
34  return 0;
35 }
36 
37 int ge_peri_deinit(struct ge *ge)
38 {
39  struct ge_peri *p, *p2;
40  int r;
41 
42  for (p = ge->peri; p != NULL;) {
43  p2 = p;
44  p = p->next;
45  if (p2->deinit != NULL) {
46  r = p2->deinit(ge, p2->ctx);
47  if (r != 0)
48  return r;
49  }
50  }
51 
52  return 0;
53 }
54 
55 int ge_register_peri(struct ge *ge, struct ge_peri *p)
56 {
57  struct ge_peri **prec_next = &ge->peri;
58  struct ge_peri *pp = ge->peri;
59 
60  while (pp != NULL) {
61  prec_next = &pp->next;
62  pp = pp->next;
63  }
64  *prec_next = p;
65  p->next = NULL;
66 
67  if (p->init != NULL)
68  return p->init(ge, p->ctx);
69 
70  return 0;
71 }
int ge_peri_on_pulses(struct ge *ge)
Definition: peripherical.c:7
int ge_peri_deinit(struct ge *ge)
Definition: peripherical.c:37
int ge_register_peri(struct ge *ge, struct ge_peri *p)
Definition: peripherical.c:55
int ge_peri_on_clock(struct ge *ge)
Definition: peripherical.c:22
Definition: ge.h:606
int(* on_pulse)(struct ge *, void *)
Definition: ge.h:609
void * ctx
Definition: ge.h:612
struct ge_peri * next
Definition: ge.h:607
int(* init)(struct ge *, void *)
Definition: ge.h:608
int(* deinit)(struct ge *, void *)
Definition: ge.h:611
int(* on_clock)(struct ge *, void *)
Definition: ge.h:610
The entire state of the emulated system, including registers, memory, peripherals and timings.
Definition: ge.h:94
struct ge_peri * peri
Definition: ge.h:547