1 /*
2  * PROJECT:     FreeLoader
3  * LICENSE:     GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
4  * PURPOSE:     Header file for NEC PC-98 series
5  * COPYRIGHT:   Copyright 2020 Dmitry Borisov (di.sean@protonmail.com)
6  */
7 
8 #pragma once
9 
10 #ifndef __MEMORY_H
11 #include "mm.h"
12 #endif
13 
14 /*
15  * BIOS work area memory
16  */
17 
18 /* Extended RAM between 0x100000 and 0xFFFFFF in 128 kB */
19 #define MEM_EXPMMSZ 0x401
20 
21 #define MEM_BIOS_FLAG5 0x458
22     #define NESA_BUS_FLAG    0x80
23 
24 #define MEM_SCSI_TABLE 0x460
25 
26 /* Bit 3 and bit 6 - keyboard type */
27 #define MEM_KEYB_TYPE 0x481
28 
29 /* Status about connected SCSI hard drives */
30 #define MEM_DISK_EQUIPS 0x482
31 
32 /* Status about RAM drives */
33 #define MEM_RDISK_EQUIP 0x488
34 
35 #define MEM_BIOS_FLAG1 0x501
36     #define CONVENTIONAL_MEMORY_SIZE 0x07 /* In 128 kB */
37     #define HIGH_RESOLUTION_FLAG     0x08
38     #define SYSTEM_CLOCK_8MHZ_FLAG   0x80 /* 0 = PIT runs at 2.4576 MHz, 1 = at 1.9968 MHz */
39 
40 /* Status about connected floppies */
41 #define MEM_DISK_EQUIP 0x55C
42 
43 /* Device Address/Unit Address (DA/UA) */
44 #define MEM_DISK_BOOT 0x584
45 
46 /* Extended RAM after 0x1000000, low part, in 1 MB */
47 #define MEM_EXPMMSZ16M_LOW 0x594
48 
49 /* Extended RAM after 0x1000000, high part, in 1 MB */
50 #define MEM_EXPMMSZ16M_HIGH 0x595
51 
52 /* Status about connected 1.44 MB floppies */
53 #define MEM_F144_SUPPORT 0x5AE
54 
55 #define MEM_EXTENDED_NORMAL    0xF8E80
56 #define MEM_EXTENDED_HIGH_RESO 0xFFE80
57 
58 VOID Pc98Beep(VOID);
59 
60 VOID Pc98ConsPutChar(int Ch);
61 BOOLEAN Pc98ConsKbHit(VOID);
62 int Pc98ConsGetCh(VOID);
63 
64 VOID Pc98VideoInit(VOID);
65 VOID Pc98VideoClearScreen(UCHAR Attr);
66 VIDEODISPLAYMODE Pc98VideoSetDisplayMode(char *DisplayMode, BOOLEAN Init);
67 VOID Pc98VideoGetDisplaySize(PULONG Width, PULONG Height, PULONG Depth);
68 ULONG Pc98VideoGetBufferSize(VOID);
69 VOID Pc98VideoGetFontsFromFirmware(PULONG RomFontPointers);
70 VOID Pc98VideoSetTextCursorPosition(UCHAR X, UCHAR Y);
71 VOID Pc98VideoHideShowTextCursor(BOOLEAN Show);
72 VOID Pc98VideoPutChar(int Ch, UCHAR Attr, unsigned X, unsigned Y);
73 VOID Pc98VideoCopyOffScreenBufferToVRAM(PVOID Buffer);
74 BOOLEAN Pc98VideoIsPaletteFixed(VOID);
75 VOID Pc98VideoSetPaletteColor(UCHAR Color, UCHAR Red, UCHAR Green, UCHAR Blue);
76 VOID Pc98VideoGetPaletteColor(UCHAR Color, UCHAR* Red, UCHAR* Green, UCHAR* Blue);
77 VOID Pc98VideoSync(VOID);
78 VOID Pc98VideoPrepareForReactOS(VOID);
79 
80 VOID Pc98PrepareForReactOS(VOID);
81 TIMEINFO* Pc98GetTime(VOID);
82 BOOLEAN Pc98InitializeBootDevices(VOID);
83 
84 PCONFIGURATION_COMPONENT_DATA
85 Pc98HwDetect(
86     _In_opt_ PCSTR Options);
87 
88 VOID Pc98HwIdle(VOID);
89 
90 /* pcmem.c */
91 extern BIOS_MEMORY_MAP PcBiosMemoryMap[];
92 extern ULONG PcBiosMapCount;
93 
94 PFREELDR_MEMORY_DESCRIPTOR Pc98MemGetMemoryMap(ULONG *MemoryMapSize);
95 
96 /* hwpci.c */
97 BOOLEAN PcFindPciBios(PPCI_REGISTRY_INFO BusData);
98 
99 /*
100  * Disk Variables and Functions
101  */
102 
103 typedef struct _PC98_DISK_DRIVE
104 {
105     /* Disk geometry */
106     GEOMETRY Geometry;
107 
108     /* BIOS drive number */
109     UCHAR DaUa;
110 
111     /* IDE driver drive number */
112     UCHAR IdeUnitNumber;
113 
114     /* Drive type flags */
115     UCHAR Type;
116 #define DRIVE_SASI     0x00
117 #define DRIVE_IDE      0x01
118 #define DRIVE_SCSI     0x02
119 #define DRIVE_CDROM    0x04
120 #define DRIVE_FDD      0x08
121 #define DRIVE_MO       0x10
122 #define DRIVE_RAM      0x20
123 
124     /* TRUE when LBA access are supported */
125     BOOLEAN LBASupported;
126 
127     /*
128      * 'IsRemovable' flag: TRUE when the drive is removable (e.g. floppy, CD-ROM...).
129      * In that case some of the cached information might need to be refreshed regularly.
130      */
131     BOOLEAN IsRemovable;
132 
133     /*
134      * 'Initialized' flag: if TRUE then the drive has been initialized;
135      * if FALSE then the disk isn't detected by BIOS/FreeLoader.
136      */
137     BOOLEAN Initialized;
138 } PC98_DISK_DRIVE, *PPC98_DISK_DRIVE;
139 
140 /* Platform-specific boot drive and partition numbers */
141 extern UCHAR FrldrBootDrive;
142 extern ULONG FrldrBootPartition;
143 
144 LONG DiskReportError(BOOLEAN bShowError);
145 BOOLEAN DiskResetController(IN PPC98_DISK_DRIVE DiskDrive);
146 
147 BOOLEAN Pc98DiskReadLogicalSectors(UCHAR DriveNumber, ULONGLONG SectorNumber, ULONG SectorCount, PVOID Buffer);
148 BOOLEAN Pc98DiskGetDriveGeometry(UCHAR DriveNumber, PGEOMETRY DriveGeometry);
149 ULONG Pc98DiskGetCacheableBlockCount(UCHAR DriveNumber);
150 UCHAR Pc98GetFloppyCount(VOID);
151 PPC98_DISK_DRIVE Pc98DiskDriveNumberToDrive(IN UCHAR DriveNumber);
152 
153 ULONG Pc98GetBootSectorLoadAddress(IN UCHAR DriveNumber);
154 VOID Pc98DiskPrepareForReactOS(VOID);
155 
156 /* hwdisk.c */
157 BOOLEAN PcInitializeBootDevices(VOID);
158