Skip to content

Commit

Permalink
Added AT chipset config
Browse files Browse the repository at this point in the history
  • Loading branch information
andreas-jonsson committed Sep 11, 2024
1 parent be87bf9 commit 5b6fe4f
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 104 deletions.
2 changes: 1 addition & 1 deletion lib/vxt/include/vxt/vxtu.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ VXT_API struct vxt_peripheral *vxtu_memory_create(vxt_allocator *alloc, vxt_poin
VXT_API void *vxtu_memory_internal_pointer(struct vxt_peripheral *p);
VXT_API bool vxtu_memory_device_fill(struct vxt_peripheral *p, const vxt_byte *data, int size);

VXT_API struct vxt_peripheral *vxtu_pic_create(vxt_allocator *alloc);
VXT_API struct vxt_peripheral *vxtu_pic_create(vxt_allocator *alloc, struct vxt_peripheral *master);

VXT_API struct vxt_peripheral *vxtu_dma_create(vxt_allocator *alloc);

Expand Down
68 changes: 49 additions & 19 deletions lib/vxt/pic.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,30 @@

struct pic {
vxt_byte mask_reg;
vxt_byte request_reg;
vxt_byte service_reg;
vxt_byte icw_step;
vxt_byte read_mode;
vxt_byte request_reg;
vxt_byte service_reg;
vxt_byte icw_step;
vxt_byte read_mode;
vxt_byte icw[5];

vxt_word base_port;
struct vxt_peripheral *master;
};

static vxt_byte in(struct pic *c, vxt_word port) {
switch (port) {
case 0x20:
switch (port - c->base_port) {
case 0:
return c->read_mode ? c->service_reg : c->request_reg;
case 0x21:
case 1:
return c->mask_reg;
default:
return c->master->io.in(VXT_GET_DEVICE_PTR(c->master), port);
}
return 0;
}

static void out(struct pic *c, vxt_word port, vxt_byte data) {
switch (port) {
case 0x20:
switch (port - c->base_port) {
case 0:
if (data & 0x10) {
c->icw_step = 1;
c->mask_reg = 0;
Expand All @@ -64,7 +68,7 @@ static void out(struct pic *c, vxt_word port, vxt_byte data) {
}
}
break;
case 0x21:
case 1:
if ((c->icw_step == 3) && (c->icw[1] & 2))
c->icw_step = 4;

Expand All @@ -75,12 +79,20 @@ static void out(struct pic *c, vxt_word port, vxt_byte data) {

c->mask_reg = data;
break;
default:
c->master->io.out(VXT_GET_DEVICE_PTR(c->master), port, data);
}
}

static int next(struct pic *c) {
vxt_byte has = c->request_reg & (~c->mask_reg);
if (c->master) {
int v = c->master->pic.next(VXT_GET_DEVICE_PTR(c->master));
if (v >= 0)
return v;
}

vxt_byte has = c->request_reg & (~c->mask_reg);

for (vxt_byte i = 0; i < 8; i++) {
vxt_byte mask = 1 << i;
if (!(has & mask))
Expand All @@ -99,28 +111,46 @@ static int next(struct pic *c) {
}

static void irq(struct pic *c, int n) {
c->request_reg |= (vxt_byte)(1 << n);
if (c->master) {
if (n <= 7) {
c->master->pic.irq(VXT_GET_DEVICE_PTR(c->master), n);
return;
} else {
n -= 8;
}
}
c->request_reg |= (vxt_byte)(1 << n);
}

static vxt_error install(struct pic *c, vxt_system *s) {
vxt_system_install_io(s, VXT_GET_PERIPHERAL(c), 0x20, 0x21);
return VXT_NO_ERROR;
vxt_system_install_io(s, VXT_GET_PERIPHERAL(c), 0x20, 0x21);

// We should NOT run install on master. All calls are forwarded.
if (c->master)
vxt_system_install_io(s, VXT_GET_PERIPHERAL(c), 0xA0, 0xA1);

return VXT_NO_ERROR;
}

static vxt_error reset(struct pic *c) {
vxt_memclear(c, sizeof(struct pic));
return VXT_NO_ERROR;
c->mask_reg = c->request_reg = c->service_reg = 0;
c->icw_step = c->read_mode = 0;
vxt_memclear(c->icw, 5);
return c->master ? c->master->reset(VXT_GET_DEVICE_PTR(c->master)) : VXT_NO_ERROR;
}

static enum vxt_pclass pclass(struct pic *c) {
(void)c; return VXT_PCLASS_PIC;
}

static const char *name(struct pic *c) {
(void)c; return "PIC (Intel 8259)";
return c->master ? "PIC Master/Slave (Intel 8259)" : "PIC (Intel 8259)";
}

VXT_API struct vxt_peripheral *vxtu_pic_create(vxt_allocator *alloc) VXT_PERIPHERAL_CREATE(alloc, pic, {
VXT_API struct vxt_peripheral *vxtu_pic_create(vxt_allocator *alloc, struct vxt_peripheral *master) VXT_PERIPHERAL_CREATE(alloc, pic, {
DEVICE->master = master;
DEVICE->base_port = master ? 0xA0 : 0x20;

PERIPHERAL->install = &install;
PERIPHERAL->reset = &reset;
PERIPHERAL->name = &name;
Expand Down
1 change: 1 addition & 0 deletions lib/vxt/system.c
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,7 @@ VXT_API void vxt_system_wait(CONSTP(vxt_system) s, int cycles) {
}

VXT_API void vxt_system_interrupt(CONSTP(vxt_system) s, int n) {
s->cpu.halt = false;
if (s->cpu.pic)
s->cpu.pic->pic.irq(VXT_GET_DEVICE_PTR(s->cpu.pic), n);
}
Expand Down
44 changes: 33 additions & 11 deletions modules/chipset/pcxt.c → modules/chipset/chipset.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,14 @@
#include <stdio.h>
#include <string.h>

// AT kbc controller
struct vxt_peripheral *kbc_create(vxt_allocator *alloc);
bool kbc_key_event(struct vxt_peripheral *p, enum vxtu_scancode key, bool force);
vxt_int16 kbc_generate_sample(struct vxt_peripheral *p, int freq);

static struct vxt_peripheral *pic_create(vxt_allocator *alloc, void *frontend, const char *args) {
(void)frontend; (void)args;
return vxtu_pic_create(alloc);
(void)frontend;
return vxtu_pic_create(alloc, strcmp(args, "at") ? NULL : vxtu_pic_create(alloc, NULL));
}

static struct vxt_peripheral *dma_create(vxt_allocator *alloc, void *frontend, const char *args) {
Expand Down Expand Up @@ -65,26 +70,43 @@ static vxt_error ppi_config(void *dev, const char *section, const char *key, con
return VXT_NO_ERROR;
}

static struct vxt_peripheral *ppi_create(vxt_allocator *alloc, void *frontend, const char *args) {
static struct vxt_peripheral *ppi_kbc_create(vxt_allocator *alloc, void *frontend, const char *args) {
(void)args;

struct vxt_peripheral *p = NULL;
bool (*key_event)(struct vxt_peripheral*,enum vxtu_scancode,bool) = NULL;
vxt_int16 (*generate_sample)(struct vxt_peripheral*,int) = NULL;

if (!strcmp(args, "at")) {
VXT_LOG("AT Chipset selected!");
if (!(p = kbc_create(alloc)))
return NULL;

struct vxt_peripheral *p = vxtu_ppi_create(alloc);
if (!p) return NULL;

key_event = &kbc_key_event;
generate_sample = &kbc_generate_sample;
} else {
VXT_LOG("PC/XT Chipset selected!");
if (!(p = vxtu_ppi_create(alloc)))
return NULL;

p->config = &ppi_config;

key_event = &vxtu_ppi_key_event;
generate_sample = &vxtu_ppi_generate_sample;
}

if (frontend) {
struct frontend_interface *fi = (struct frontend_interface*)frontend;
if (fi->set_keyboard_controller) {
struct frontend_keyboard_controller controller = { p, &vxtu_ppi_key_event };
struct frontend_keyboard_controller controller = { p, key_event };
fi->set_keyboard_controller(&controller);
}
if (fi->set_audio_adapter) {
struct frontend_audio_adapter adapter = { p, &vxtu_ppi_generate_sample };
struct frontend_audio_adapter adapter = { p, generate_sample };
fi->set_audio_adapter(&adapter);
}
}

p->config = &ppi_config;
return p;
}

VXTU_MODULE_ENTRIES(&pic_create, &dma_create, &pit_create, &ppi_create)
VXTU_MODULE_ENTRIES(&pic_create, &dma_create, &pit_create, &ppi_kbc_create)
File renamed without changes.
5 changes: 3 additions & 2 deletions modules/chipset/premake5.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
files {
"pcxt.c"
}
"chipset.c",
"kbc.c"
}
67 changes: 0 additions & 67 deletions modules/chipset_at/at.c

This file was deleted.

4 changes: 0 additions & 4 deletions modules/chipset_at/premake5.lua

This file was deleted.

0 comments on commit 5b6fe4f

Please sign in to comment.