-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbus.c
More file actions
95 lines (85 loc) · 2.51 KB
/
bus.c
File metadata and controls
95 lines (85 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <math.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "bus.h"
#include "cpu.h"
#include "disk.h"
#include "serial.h"
extern fox32_vm_t vm;
extern disk_controller_t disk_controller;
int bus_io_read(void *user, uint32_t *value, uint32_t port) {
(void) user;
switch (port) {
case 0x00000000: { // serial port
*value = serial_get();
break;
};
case 0x80001000 ... 0x80002003: { // disk controller port
size_t id = port & 0xFF;
uint8_t operation = (port & 0x0000F000) >> 8;
switch (operation) {
case 0x10: {
// current insert state of specified disk id
// size will be zero if disk isn't inserted
*value = get_disk_size(id);
break;
};
case 0x20: {
// current buffer pointer
*value = disk_controller.buffer_pointer;
break;
};
}
break;
};
}
return 0;
}
int bus_io_write(void *user, uint32_t value, uint32_t port) {
(void) user;
switch (port) {
case 0x00000000: { // serial port
serial_put(value);
break;
};
case 0x80001000 ... 0x80005003: { // disk controller port
size_t id = port & 0xFF;
uint8_t operation = (port & 0x0000F000) >> 8;
switch (operation) {
case 0x10: {
// no-op
break;
};
case 0x20: {
// set the buffer pointer
disk_controller.buffer_pointer = value;
break;
};
case 0x30: {
// read specified disk sector into memory
set_disk_sector(id, value);
read_disk_into_memory(id);
break;
};
case 0x40: {
// write specified disk sector from memory
set_disk_sector(id, value);
write_disk_from_memory(id);
break;
};
case 0x50: {
// remove specified disk
remove_disk(id);
break;
};
}
break;
};
}
return 0;
}