OXYGENHUB
◆ main enhanced-x16-emulator / src / ieee.h
3.2 KiB · Objective-C · last changed chore(): initial commit 25 days ago source blame history raw
1
// Commander X16 Emulator
2
// Copyright (c) 2022 Michael Steil
3
// All rights reserved. License: 2-clause BSD
4
5
#pragma once
6
7
#include <stdint.h>
8
#include <stdbool.h>
9
10
#define IEEE_HISTORY_MAX 64
11
12
typedef enum {
13
	IEEE_OP_OPEN        = 0,
14
	IEEE_OP_OPEN_FAILED = 1,
15
	IEEE_OP_CLOSE       = 2,
16
	IEEE_OP_DIR         = 3,
17
	IEEE_OP_COMMAND     = 4,
18
	IEEE_OP_STATUS      = 5,
19
} ieee_op_kind_t;
20
21
typedef struct {
22
	uint32_t seq;           /* monotonic; 0 means "empty slot" */
23
	uint8_t  kind;          /* ieee_op_kind_t */
24
	int8_t   channel;       /* -1 when not channel-specific */
25
	bool     read;
26
	bool     write;
27
	char     name[80];      /* filename, command text, or status text */
28
	char     status[48];    /* resulting DOS status, "" if none yet */
29
	uint32_t bytes_read;
30
	uint32_t bytes_written;
31
} ieee_history_entry_t;
32
33
#ifdef __cplusplus
34
extern "C" {
35
#endif
36
37
void ieee_init();
38
int SECOND(uint8_t a);
39
int TKSA(uint8_t a);
40
int ACPTR(uint8_t *a);
41
int CIOUT(uint8_t a);
42
int UNTLK(void);
43
int UNLSN(void);
44
int LISTEN(uint8_t a);
45
int TALK(uint8_t a);
46
int MACPTR(uint16_t addr, uint16_t *count, uint8_t stream_mode);
47
int MCIOUT(uint16_t addr, uint16_t *count, uint8_t stream_mode);
48
int XMACPTR(uint8_t stream_mode);
49
int XMCIOUT(uint8_t stream_mode);
50
51
// ─── Debugger accessor ───────────────────────────────────────────────────────
52
// Side-effect-free snapshot of IEEE/hostfs state. Safe to call every frame
53
// from the debugger while the emulation is running.
54
//
55
// All strings are NUL-terminated copies; no pointers into emulator state.
56
// Per-channel bytes_read/bytes_written are cumulative since the channel was
57
// last opened.
58
59
typedef struct {
60
	bool     is_open;          // channel has an active file handle
61
	bool     read;             // channel is open for reading
62
	bool     write;            // channel is open for writing
63
	char     name[80];         // filename as seen by the DOS layer (NUL-terminated)
64
	uint32_t bytes_read;       // bytes successfully read from this channel
65
	uint32_t bytes_written;    // bytes successfully written to this channel
66
} ieee_channel_debug_t;
67
68
typedef struct {
69
	bool     using_hostfs;              // hostfs is active (vs CMDR-DOS block device)
70
	int      ieee_unit;                 // emulated device number (usually 8)
71
	char     hostfscwd[512];            // current host working directory (NUL-terminated)
72
	int      channel;                   // currently addressed channel (secondary address)
73
	bool     listening;                 // device is in LISTEN state
74
	bool     talking;                   // device is in TALK state
75
	bool     opening;                   // currently accumulating a filename (OPEN in progress)
76
	char     cmd[256];                  // last DOS command received on channel 15
77
	int      cmdlen;                    // valid bytes in cmd[]
78
	char     error_str[256];            // current error string (channel 15 status)
79
	ieee_channel_debug_t channels[16]; // per-channel state
80
	int                  history_count;                    // valid entries, oldest first
81
	ieee_history_entry_t history[IEEE_HISTORY_MAX];
82
} ieee_debug_state_t;
83
84
void ieee_debug_get_state(ieee_debug_state_t *out);
85
86
#ifdef __cplusplus
87
}
88
#endif