From 1b429c0fc28e5cd8b474ad5a1de1fa6f3d7c2e2a Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Mon, 12 Jul 2021 18:14:44 +0200 Subject: Renamed files to match presentation --- src/loader/dev.c | 84 -------------------------------------------------------- 1 file changed, 84 deletions(-) delete mode 100644 src/loader/dev.c (limited to 'src/loader/dev.c') diff --git a/src/loader/dev.c b/src/loader/dev.c deleted file mode 100644 index 2a57b02..0000000 --- a/src/loader/dev.c +++ /dev/null @@ -1,84 +0,0 @@ -// MIT License, Copyright (c) 2021 Marvin Borner -// Device manager - -#include -#include -#include - -static struct dev devices[32] = { 0 }; - -static const char *dev_resolve_type(enum dev_type type) -{ - switch (type) { - case DEV_DISK: - return "Disk"; - case DEV_FB: - return "Framebuffer"; - case DEV_NONE: - default: - return "Unknown"; - } -} - -struct dev *dev_get_by_id(u8 id) -{ - assert(id < COUNT(devices)); - return &devices[id]; -} - -struct dev *dev_get_by_name(const char *name, u32 len) -{ - if (!name || !name[0]) - return NULL; - - for (u8 i = 0; i < COUNT(devices); i++) { - struct dev *dev = &devices[i]; - if (strncmp(dev->name, name, MIN(sizeof(dev->name), len)) == 0) - return dev; - } - - return NULL; -} - -void dev_foreach(enum dev_type type, u8 (*cb)(struct dev *)) -{ - for (u8 i = 0; i < COUNT(devices); i++) { - struct dev *dev = &devices[i]; - if (dev->type == type) - if (cb(dev)) - break; - } -} - -u8 dev_register(enum dev_type type, char *name, u32 data, - s32 (*read)(void *, u32, u32, struct dev *), - s32 (*write)(const void *, u32, u32, struct dev *)) -{ - static u8 id = 0; - assert(++id < 0xff); - - struct dev *dev = &devices[id]; - dev->id = id; - dev->type = type; - dev->read = read; - dev->write = write; - dev->data = data; - - assert(strlen(name) < sizeof(dev->name)); - memcpy(dev->name, name, sizeof(dev->name)); - - if (type == DEV_DISK) - dsk_detect(dev); - - return id; -} - -void dev_print(void) -{ - for (u8 i = 0; i < COUNT(devices); i++) { - struct dev *dev = &devices[i]; - if (!dev->id) - continue; - log("[DEV] %d: %s device: %s\n", dev->id, dev_resolve_type(dev->type), dev->name); - } -} -- cgit v1.2.3