Skip to content

Commit e1b7d90

Browse files
committed
Add mock CharMon (character-based monitor) peripheral.
This fake peripheral can be used to print to the emulator's stdout from the emulated software.
1 parent 2e2c69a commit e1b7d90

4 files changed

Lines changed: 39 additions & 0 deletions

File tree

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ set(CORE_SRCS
1818
src/int.c
1919
src/keyboard.c
2020
src/main.c
21+
src/charmon.c
2122
src/serial.c
2223
src/sio2.c
2324
src/speaker.c

src/charmon.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#include "charmon.h"
2+
3+
#include "conf.h"
4+
#include "ubus.h"
5+
6+
#include <stdio.h>
7+
#include <string.h>
8+
9+
#define CHARMON_BASE (0xF0)
10+
11+
void charmon_out(ceda_ioaddr_t address, uint8_t value) {
12+
(void)address;
13+
(void)putc(value, stdout);
14+
}
15+
16+
void charmon_init(CEDAModule *mod) {
17+
memset(mod, 0, sizeof(*mod));
18+
19+
bool *conf_installed = conf_getBool("mod", "charmon_installed");
20+
bool installed = conf_installed ? *conf_installed : false;
21+
22+
if (!installed)
23+
return;
24+
25+
ubus_register(CHARMON_BASE, CHARMON_BASE + 1, NULL, charmon_out);
26+
}

src/charmon.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#ifndef CEDA_CHAR_MONITOR_H
2+
#define CEDA_CHAR_MONITOR_H
3+
4+
#include "module.h"
5+
#include "type.h"
6+
7+
void charmon_init(CEDAModule *mod);
8+
void charmon_out(ceda_ioaddr_t address, uint8_t value);
9+
10+
#endif // CEDA_CHAR_MONITOR_H

src/conf.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ static const char *CONF_PATH_HOME =
2323
// Emulator dynamic configuration
2424
static struct {
2525
bool cge_installed;
26+
bool charmon_installed;
2627
ceda_string_t *bios_rom_path;
2728
ceda_string_t *char_rom_path;
2829
ceda_string_t *cge_rom_path;
@@ -46,6 +47,7 @@ typedef struct conf_tuple_t {
4647

4748
static conf_tuple_t conf_tuples[] = {
4849
{"mod", "cge_installed", CONF_BOOL, &conf.cge_installed},
50+
{"mod", "charmon_installed", CONF_BOOL, &conf.charmon_installed},
4951
{"path", "bios_rom", CONF_STR, &conf.bios_rom_path},
5052
{"path", "char_rom", CONF_STR, &conf.char_rom_path},
5153
{"path", "cge_rom", CONF_STR, &conf.cge_rom_path},

0 commit comments

Comments
 (0)