-
Notifications
You must be signed in to change notification settings - Fork 9
/
io.c
132 lines (125 loc) · 2.83 KB
/
io.c
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
#include "io.h"
#include <stdint.h>
#include <stdio.h>
#include "emulator.h"
#include "kbd.h"
#include "instructions.h"
#include "util.h"
/*
* PS/2 (keyboard) Controller
* 0x60: in|out: Data Register
* 0x64: in: Status Register | out: Command Register
*/
#define PS2DATA 0x60
#define PS2STACMD 0x64
/*
* Serial (COM1)
* 0x3f8: in|out: Data port
* 0x3fd: in: Status port
*/
#define SERIALSTA 0x3fd
#define SERIALDATA 0x3f8
#define SERIALLINESTA 0x3fd
/*
* Disk
* 0x1F0: Data Register
* 0x1F2: in|out: Sector Count Register
* 0x1F3: in|out: LBA Low
* 0x1F4: in|out: LBA Mid
* 0x1F5: in|out: LBA High
* 0x1F6: in|out: Drive/Head Register
* 0x1F7: in: Status Register | out: Command Register
*/
#define DISKDATA 0x1f0
#define DISKSECCOUNT 0x1f2
#define DISKLBALOW 0x1f3
#define DISKLBAMID 0x1f4
#define DISKLBAHIGH 0x1f5
#define DISKDRVHEAD 0x1f6
#define DISKSTACMD 0x1f7
uint8_t io_in8(Emulator *emu, uint16_t address)
{
switch (address)
{
case PS2DATA:
return get_kbd_data();
case PS2STACMD:
return get_kbd_status();
case DISKSTACMD:
return get_disk_status(emu->disk);
case SERIALDATA:
return 0;
// return getchar();
case SERIALLINESTA:
return 0x20;
default:
if (config.verbose)
printf("IN8 on port %x not implemented.\n", address);
return 0;
}
}
uint32_t io_in32(Emulator *emu, uint16_t address)
{
switch (address)
{
case 0x1F0:
return read_disk_data32(emu->disk);
case SERIALDATA:
return 0;
// return getchar();
default:
if (config.verbose)
printf("IN32 on port %x not implemented.\n", address);
return 0;
}
}
void io_out8(Emulator *emu, uint16_t address, uint8_t value)
{
switch (address)
{
case PS2DATA:
write_ps2_config_byte(value);
break;
case PS2STACMD:
write_ps2_output_port(value);
break;
case DISKSECCOUNT:
set_sec_count(emu->disk, value);
break;
case DISKLBALOW:
set_lba_low(emu->disk, value);
break;
case DISKLBAMID:
set_lba_mid(emu->disk, value);
break;
case DISKLBAHIGH:
set_lba_high(emu->disk, value);
break;
case DISKDRVHEAD:
set_drive_head(emu->disk, value);
break;
case DISKSTACMD:
set_disk_command(emu->disk, value);
break;
case SERIALDATA:
putchar(value);
break;
default:
if (config.verbose)
printf("OUT8 on port %x not implemented.\n", address);
break;
}
}
void io_out32(Emulator *emu, uint16_t address, uint32_t value)
{
switch (address)
{
case SERIALDATA:
putchar(value);
break;
default:
if (config.verbose)
printf("OUT32 on port %x not implemented.\n", address);
break;
}
}