-
Notifications
You must be signed in to change notification settings - Fork 0
/
bios.h
176 lines (120 loc) · 5.04 KB
/
bios.h
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
/*
Created by Fabrizio Di Vittorio ([email protected]) - <http://www.fabgl.com>
Copyright (c) 2019-2022 Fabrizio Di Vittorio.
All rights reserved.
* Please contact [email protected] if you need a commercial license.
* This library and related software is available under GPL v3.
FabGL is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
FabGL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with FabGL. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#include "fabgl.h"
#include "emudevs/i8042.h"
#include "emudevs/MC146818.h"
// 0 = floppy 0 (fd0, A:)
// 1 = floppy 1 (fd1, B:)
// 2 = hard disk 0 (hd0, C: or D:, depends by partitions)
// 3 = hard disk 1 (hd1)
constexpr int DISKCOUNT = 4;
#define BIOS_SEG 0xF000
#define BIOS_OFF 0x0100
#define BIOS_ADDR (BIOS_SEG * 16 + BIOS_OFF)
// BIOS Data Area
#define BIOS_DATAAREA_SEG 0x40
#define BIOS_DATAAREA_ADDR (BIOS_DATAAREA_SEG << 4)
#define BIOS_KBDSHIFTFLAGS1 0x17 // keyboard shift flags
#define BIOS_KBDSHIFTFLAGS2 0x18 // more keyboard shift flags
#define BIOS_KBDALTKEYPADENTRY 0x19 // Storage for alternate keypad entry
#define BIOS_KBDBUFHEAD 0x1a // pointer to next character in keyboard buffer
#define BIOS_KBDBUFTAIL 0x1c // pointer to first available spot in keyboard buffer
#define BIOS_KBDBUF 0x1e // keyboard buffer (32 bytes, 16 keys, but actually 15)
#define BIOS_DISKLASTSTATUS 0x41 // diskette status return code
#define BIOS_SYSTICKS 0x6c // system ticks (dword)
#define BIOS_CLKROLLOVER 0x70 // system tick rollover flag (24h)
#define BIOS_CTRLBREAKFLAG 0x71 // Ctrl-Break flag
#define BIOS_HDLASTSTATUS 0x74 // HD status return code
#define BIOS_NUMHD 0x75 // number of fixed disk drives
#define BIOS_DRIVE0MEDIATYPE 0x90 // media type of drive 0
#define BIOS_DRIVE1MEDIATYPE 0x91 // media type of drive 1
#define BIOS_KBDMODE 0x96 // keyboard mode and other shift flags
#define BIOS_KBDLEDS 0x97 // keyboard LEDs
#define BIOS_PRINTSCREENFLAG 0x100 // PRINTSCREEN flag
// Extended BIOS Data Area (EBDA)
#define EBDA_SEG 0x9fc0 // EBDA Segment, must match with same value in bios.asm
#define EBDA_ADDR (EBDA_SEG << 4)
#define EBDA_DRIVER_OFFSET 0x22 // Pointing device device driver far call offset
#define EBDA_DRIVER_SEG 0x24 // Pointing device device driver far call segment
#define EBDA_FLAGS1 0x26 // Flags 1 (bits 0-2: recv data index)
#define EBDA_FLAGS2 0x27 // Flags 2 (bits 0-2: packet size, bit 7: device handler installed)
#define EBDA_PACKET 0x28 // Start of packet
using fabgl::PS2Controller;
using fabgl::Keyboard;
using fabgl::Mouse;
using fabgl::i8042;
using fabgl::MC146818;
enum MediaType {
mediaUnknown,
floppy160KB,
floppy180KB,
floppy320KB,
floppy360KB,
floppy720KB,
floppy1M2K,
floppy1M44K,
floppy2M88K,
HDD,
};
class Machine;
class BIOS {
public:
BIOS();
void init(Machine * machine);
void reset();
void helpersEntry();
void diskHandlerEntry();
void videoHandlerEntry();
void setDriveMediaType(int drive, MediaType media);
private:
void getKeyFromKeyboard();
void getKeyFromBuffer();
void getKeyboardFlags();
void setKeyboardTypematicAndDelay();
void storeKeyboardKeyData();
bool storeKeyInKbdBuffer(uint16_t syscode);
bool processScancode(int scancode, uint16_t * syscode);
void emptyKbdBuffer();
void pointingDeviceInterface();
void syncTicksWithRTC();
void diskHandler_floppy();
bool diskHandler_calcAbsAddr(int drive, uint32_t * pos, uint32_t * dest, uint32_t * count);
void diskHandler_floppyExit(uint8_t err, bool setErrStat);
void diskHandler_HD();
void diskHandler_HDExit(uint8_t err, bool setErrStat);
bool checkDriveMediaType(int drive);
uint32_t getDriveMediaTableAddr(int drive);
Machine * m_machine;
uint8_t * m_memory;
Keyboard * m_keyboard;
Mouse * m_mouse;
i8042 * m_i8042;
MC146818 * m_MC146818;
// state of multibyte scancode intermediate reception:
// 0 = none
// pause (0xe1 0x1d 0x45 0xe1 0x9d 0xc5): 1 = 0x1d, 2 = 0x45, 3 = 0x9d
uint8_t m_kbdScancodeComp;
// address of bios.asm:media_drive_parameters (0, 1)
// address of int41 (2), int46 (3)
//uint32_t m_mediaDriveParametersAddr[4];
// original int 1e address (may be changed by O.S.)
uint32_t m_origInt1EAddr;
// media type for floppy (0,1) and HD (>=2)
MediaType m_mediaType[DISKCOUNT];
};