GE-115 Emulator
An Emulator of the General Electrics GE-115 computer
cap.h
Go to the documentation of this file.
1#ifndef CAP_H
2#define CAP_H
3#include <stdint.h>
4
5#define CAP_COLS_PER_CARD 80
6
7struct cap_deck; /* opaque */
8
14
23
24/* Parse a .cap file. Returns NULL on open/parse error. */
25struct cap_deck *cap_load(const char *path);
26
27/* Create an empty in-memory deck. Returns NULL on allocation failure. */
28struct cap_deck *cap_create(void);
29
30/* Number of cards parsed. */
31int cap_num_cards(const struct cap_deck *d);
32
33/* Number of columns in card `i` (normally 80). 0 if i out of range. */
34int cap_card_ncols(const struct cap_deck *d, int i);
35
36/* Pointer to the column array (uint16_t, 12-bit values) for card `i`,
37 * or NULL if i out of range. Length == cap_card_ncols(d,i). */
38const uint16_t *cap_card_columns(const struct cap_deck *d, int i);
39
40/* Append one card to an in-memory deck. Returns 0 on success, -1 on failure. */
41int cap_append_card(struct cap_deck *d, const uint16_t *cols, int ncols);
42
43/* Save a deck back to the textual .cap format. Returns 0 on success. */
44int cap_save(const struct cap_deck *d, const char *path);
45
46void cap_free(struct cap_deck *d);
47
48/* Inspect a deck's framing. `mode` is an `enum transcode_mode` used when
49 * decoding binary columns for scatter-family detection. On success returns the
50 * detected family and, if `info` is non-NULL, fills the summary fields. */
51enum cap_deck_family cap_detect_family(const struct cap_deck *d, int mode,
52 struct cap_deck_info *info);
53
54/* Human-readable family name for logs/errors. */
55const char *cap_family_name(enum cap_deck_family family);
56
57/*
58 * cap_load_scattered - load a self-addressed binary card deck into a flat image.
59 *
60 * Each data card (>= 11 columns) is decoded (TC_COLBIN) and read as a
61 * self-describing record: b[8]=LL, b[9..10]=load address (big-endian),
62 * b[11..11+LL]=LL+1 payload bytes. The payload is *scattered* to `addr` in
63 * `image` (a caller-provided 65536-byte buffer). Cards are gated by the deck's
64 * dominant 8-byte prefix (cols 0-7); if no dominant prefix is found, any
65 * self-consistent record is accepted (loose). Bytes not written keep their
66 * existing value in `image` (caller should pre-zero or pre-seed as desired).
67 *
68 * This mirrors the gdis `--image` depunch so a .cap deck loads identically
69 * whether depunched offline or fed to the emulator directly. It honours each
70 * card's embedded load address (the deck format), independent of the (separate,
71 * cycle-faithful) card-reader bootstrap.
72 *
73 * On success returns the number of cards loaded (>0) and sets `*lo` / `*hi` to
74 * the lowest/highest address written (so [`*lo`, `*hi`] is the populated span; entry is
75 * conventionally *lo). Returns -1 on parse error or if nothing loaded. `mode` is
76 * an `enum transcode_mode` (pass TC_COLBIN for binary decks).
77 */
78int cap_load_scattered(const char *path, int mode,
79 unsigned char *image /* 65536 bytes */,
80 unsigned *lo, unsigned *hi);
81
82/* Load a CPU isolation deck's 76-byte payload cards contiguously at `org`.
83 * The title/summary framing cards are skipped via the Hollerith 77-79 card id.
84 * Returns the number of payload cards loaded (>0), or -1 on parse/family/load
85 * failure. */
86int cap_load_isolation_stream(const char *path,
87 unsigned char *image /* 65536 bytes */,
88 unsigned org,
89 unsigned *lo, unsigned *hi);
90#endif
const uint16_t * cap_card_columns(const struct cap_deck *d, int i)
Definition cap.c:214
int cap_append_card(struct cap_deck *d, const uint16_t *cols, int ncols)
Definition cap.c:221
const char * cap_family_name(enum cap_deck_family family)
Definition cap.c:374
cap_deck_family
Definition cap.h:9
@ CAP_FAMILY_ISOLATION
Definition cap.h:12
@ CAP_FAMILY_UNKNOWN
Definition cap.h:10
@ CAP_FAMILY_SCATTER
Definition cap.h:11
int cap_card_ncols(const struct cap_deck *d, int i)
Definition cap.c:207
struct cap_deck * cap_create(void)
Definition cap.c:195
int cap_num_cards(const struct cap_deck *d)
Definition cap.c:200
void cap_free(struct cap_deck *d)
Definition cap.c:263
struct cap_deck * cap_load(const char *path)
Definition cap.c:124
int cap_load_scattered(const char *path, int mode, unsigned char *image, unsigned *lo, unsigned *hi)
Definition cap.c:442
int cap_save(const struct cap_deck *d, const char *path)
Definition cap.c:238
int cap_load_isolation_stream(const char *path, unsigned char *image, unsigned org, unsigned *lo, unsigned *hi)
Definition cap.c:505
enum cap_deck_family cap_detect_family(const struct cap_deck *d, int mode, struct cap_deck_info *info)
Definition cap.c:386
int isolation_cards
Definition cap.h:20
uint8_t scatter_prefix[8]
Definition cap.h:21
int full_80col_cards
Definition cap.h:19
int eligible_scatter_cards
Definition cap.h:17
enum cap_deck_family family
Definition cap.h:16
int scatter_prefix_count
Definition cap.h:18
Definition cap.c:35