Subversion Repositories SvarDOS

Rev

Rev 1409 | Rev 1443 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1409 Rev 1413
1
/*
1
/*
2
 * Functions interacting with DOS
2
 * Functions interacting with DOS
3
 *
3
 *
4
 * This file is part of the Mateusz' DOS Routines (MDR): http://mdr.osdn.io
4
 * This file is part of the Mateusz' DOS Routines (MDR): http://mdr.osdn.io
5
 * Published under the terms of the MIT License, as stated below.
5
 * Published under the terms of the MIT License, as stated below.
6
 *
6
 *
7
 * Copyright (C) 2014-2023 Mateusz Viste
7
 * Copyright (C) 2014-2023 Mateusz Viste
8
 *
8
 *
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
9
 * Permission is hereby granted, free of charge, to any person obtaining a copy
10
 * of this software and associated documentation files (the "Software"), to
10
 * of this software and associated documentation files (the "Software"), to
11
 * deal in the Software without restriction, including without limitation the
11
 * deal in the Software without restriction, including without limitation the
12
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
12
 * rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
13
 * sell copies of the Software, and to permit persons to whom the Software is
13
 * sell copies of the Software, and to permit persons to whom the Software is
14
 * furnished to do so, subject to the following conditions:
14
 * furnished to do so, subject to the following conditions:
15
 *
15
 *
16
 * The above copyright notice and this permission notice shall be included in
16
 * The above copyright notice and this permission notice shall be included in
17
 * all copies or substantial portions of the Software.
17
 * all copies or substantial portions of the Software.
18
 *
18
 *
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
25
 * IN THE SOFTWARE.
25
 * IN THE SOFTWARE.
26
 */
26
 */
27
 
27
 
28
#ifndef MDR_DOS_H
28
#ifndef MDR_DOS_H
29
#define MDR_DOS_H
29
#define MDR_DOS_H
30
 
30
 
31
#include <time.h> /* time_t */
31
#include <time.h> /* time_t */
32
 
32
 
33
/* returns a far pointer to the current process PSP structure */
33
/* returns a far pointer to the current process PSP structure */
34
void far *mdr_dos_psp(void);
34
void far *mdr_dos_psp(void);
35
 
35
 
36
/* returns a far pointer to the environment block of the current process */
36
/* returns a far pointer to the environment block of the current process */
37
char far *mdr_dos_env(void);
37
char far *mdr_dos_env(void);
38
 
38
 
39
/* looks for varname in the DOS environment and fills result with its value if
39
/* looks for varname in the DOS environment and fills result with its value if
40
 * found. returns NULL if not found or if value is too big to fit in result
40
 * found. returns NULL if not found or if value is too big to fit in result
41
 * (reslimit exceeded). returns result on success.
41
 * (reslimit exceeded). returns result on success.
42
 * NOTE: this function performs case-sensitive matches */
42
 * NOTE: this function performs case-sensitive matches */
43
char *mdr_dos_getenv(char *result, const char *varname, unsigned short reslimit);
43
char *mdr_dos_getenv(char *result, const char *varname, unsigned short reslimit);
44
 
44
 
45
/* fetches directory where the program was loaded from and return its length.
45
/* fetches directory where the program was loaded from and return its length.
46
 * path string is never longer than 128 (incl. the null terminator) and it is
46
 * path string is never longer than 128 (incl. the null terminator) and it is
47
 * always terminated with a backslash separator, unless it is an empty string */
47
 * always terminated with a backslash separator, unless it is an empty string */
48
unsigned char mdr_dos_exepath(char *path);
48
unsigned char mdr_dos_exepath(char *path);
49
 
49
 
50
/* returns a far pointer to the full path and filename of the running program.
50
/* returns a far pointer to the full path and filename of the running program.
51
 * returns NULL on error. */
51
 * returns NULL on error. */
52
const char far *mdr_dos_selfexe(void);
52
const char far *mdr_dos_selfexe(void);
53
 
53
 
54
/* waits for a keypress and returns it
54
/* waits for a keypress and returns it
55
 * extended keys are returned ORed with 0x100 (example: PGUP is 0x149) */
55
 * extended keys are returned ORed with 0x100 (example: PGUP is 0x149) */
56
int mdr_dos_getkey(void);
56
int mdr_dos_getkey(void);
57
 
57
 
58
/* Same as mdr_dos_getkey(), but this call cannot be aborted by CTRL+C */
58
/* Same as mdr_dos_getkey(), but this call cannot be aborted by CTRL+C */
59
int mdr_dos_getkey2(void);
59
int mdr_dos_getkey2(void);
60
 
60
 
61
/* flush the keyboard buffer */
61
/* flush the keyboard buffer */
62
void mdr_dos_flushkeyb(void);
62
void mdr_dos_flushkeyb(void);
63
 
63
 
64
/* poll stdin status, returns 0 if no character is pending in the keyboard
64
/* poll stdin status, returns 0 if no character is pending in the keyboard
65
 * buffer, non-zero otherwise */
65
 * buffer, non-zero otherwise */
66
int mdr_dos_keypending(void);
66
int mdr_dos_keypending(void);
67
 
67
 
68
/* disables the CTRL+C handler for the running program - in other words,
68
/* sets up the CTRL+C handler for the running program to a no-op - in other
69
 * after this call DOS will no longer abort the program on CTRL+C */
69
 * words, after this call DOS will no longer abort the program on CTRL+C.
-
 
70
 * this is only valid for the duration of the program because DOS will restore
-
 
71
 * the original handler after the program exits.
-
 
72
 *
-
 
73
 * an alternative is mdr_dos_ctrlc_off(), but this does not inhibit the
-
 
74
 * handler, it sets DOS to not react to CTRL+C in the first place, and this
-
 
75
 * setting stays active after the program quits so the program should remember
-
 
76
 * to restore the original setting before quitting. */
-
 
77
void mdr_dos_ctrlc_inhibit(void);
-
 
78
 
-
 
79
/* sets the DOS BREAK control OFF, ie. instructs DOS not to check for CTRL+C
-
 
80
 * during most input operations. returns the previous state of the break
-
 
81
 * control flag (0=disabled 1=enabled). this changes a global DOS flag that can
-
 
82
 * be checked on command line with the "BREAK" command, so the program should
-
 
83
 * take care to restore the initial setting before quitting. */
-
 
84
unsigned char mdr_dos_ctrlc_disable(void);
-
 
85
 
-
 
86
/* sets the DOS BREAK control ON. see mdr_dos_ctrlc_disable() for details. */
70
void mdr_dos_ctrlc_disable(void);
87
void mdr_dos_ctrlc_enable(void);
71
 
88
 
72
/* converts a "DOS format" 16-bit packed date into a standard (time_t)
89
/* converts a "DOS format" 16-bit packed date into a standard (time_t)
73
 * unix timestamp. A DOS date is a 16-bit value:
90
 * unix timestamp. A DOS date is a 16-bit value:
74
 * YYYYYYYM MMMDDDDD
91
 * YYYYYYYM MMMDDDDD
75
 *
92
 *
76
 * day of month is always within 1-31 range;
93
 * day of month is always within 1-31 range;
77
 * month is always within 1-12 range;
94
 * month is always within 1-12 range;
78
 * year starts at 1980 and continues for 127 years */
95
 * year starts at 1980 and continues for 127 years */
79
time_t mdr_dos_date2unix(unsigned short d);
96
time_t mdr_dos_date2unix(unsigned short d);
80
 
97
 
81
/* converts a "DOS format" 16-bit packed time into hours, minutes and seconds
98
/* converts a "DOS format" 16-bit packed time into hours, minutes and seconds
82
 *
99
 *
83
 * A DOS time is a 16-bit value:
100
 * A DOS time is a 16-bit value:
84
 * HHHHHMMM MMMSSSSS
101
 * HHHHHMMM MMMSSSSS
85
 *
102
 *
86
 * HHHHH  = hours, always within 0-23 range
103
 * HHHHH  = hours, always within 0-23 range
87
 * MMMMMM = minutes, always within 0-59 range
104
 * MMMMMM = minutes, always within 0-59 range
88
 * SSSSS  = seconds/2 (always within 0-29 range) */
105
 * SSSSS  = seconds/2 (always within 0-29 range) */
89
void mdr_dos_time2hms(unsigned char *h, unsigned char *m, unsigned char *s, unsigned short t);
106
void mdr_dos_time2hms(unsigned char *h, unsigned char *m, unsigned char *s, unsigned short t);
90
 
107
 
91
#endif
108
#endif
92
 
109