• R/O
  • SSH
  • HTTPS

mdr: Commit


Commit MetaInfo

Revision107 (tree)
Time2023-10-19 05:30:08
Authormateuszviste

Log Message

renamed all timer_ functions to mdr_timer_, improved header documentation and removed the atexit() registration of timer_stop() (to be done by the user if needed)

Change Summary

Incremental Difference

--- trunk/inc/mdr/timer.h (revision 106)
+++ trunk/inc/mdr/timer.h (revision 107)
@@ -4,7 +4,7 @@
44 * This file is part of the Mateusz' DOS Routines (MDR): http://mdr.osdn.io
55 * Published under the terms of the MIT License, as stated below.
66 *
7- * Copyright (C) 2014-2022 Mateusz Viste
7+ * Copyright (C) 2014-2023 Mateusz Viste
88 *
99 * Permission is hereby granted, free of charge, to any person obtaining a copy
1010 * of this software and associated documentation files (the "Software"), to
@@ -28,25 +28,24 @@
2828 #ifndef MDR_TIMER_H
2929 #define MDR_TIMER_H
3030
31-/* reset the timer value, this can be used by the application to make sure
32- * no timer wrap occurs during critical parts of the code flow */
33-void timer_reset(void);
31+/* Starts the timer by reprogramming the 8253 chip from its default 18.2 Hz
32+ * frequency to about 1.1 kHz. It is mandatory to revert the timer to its
33+ * original frequency via mdr_timer_stop() before your application quits. */
34+void mdr_timer_init(void);
3435
35-/* This routine will stop the fast clock if it is going. It has void return
36- * value so that it can be an exit procedure. */
37-void timer_stop(void);
36+/* Fills res with the amount of microseconds that elapsed since either
37+ * mdr_timer_init() or mdr_timer_reset(), whichever was called last.
38+ * Note that the res counter wraps around approximately every 71 minutes if
39+ * mdr_timer_reset() is not called. */
40+void mdr_timer_read(unsigned long *res);
3841
39-/* This routine will start the fast clock rate by installing the
40- * handle_clock routine as the interrupt service routine for the clock
41- * interrupt and then setting the interrupt rate up to its higher speed
42- * by programming the 8253 timer chip.
43- * This routine does nothing if the clock rate is already set to
44- * its higher rate, but then it returns -1 to indicate the error. */
45-void timer_init(void);
42+/* Reset the timer value, this can be used by the application to make sure
43+ * no timer wrap occurs during critical parts of your code flow */
44+void mdr_timer_reset(void);
4645
47-/* This routine will return the present value of the time, which is
48- * read from the nowtime structure. Interrupts are disabled during this
49- * time to prevent the clock from changing while it is being read. */
50-void timer_read(unsigned long *res);
46+/* Stops (uninstalls) the timer. This must be called before your application
47+ * quits, otherwise the system will likely crash. This function has a void
48+ * return value so that it can be registered as an atexit() procedure. */
49+void mdr_timer_stop(void);
5150
5251 #endif
--- trunk/timer/timer.c (revision 106)
+++ trunk/timer/timer.c (revision 107)
@@ -4,7 +4,7 @@
44 * This file is part of the Mateusz' DOS Routines (MDR): http://mdr.osdn.io
55 * Published under the terms of the MIT License, as stated below.
66 *
7- * Copyright (C) 2014-2022 Mateusz Viste
7+ * Copyright (C) 2014-2023 Mateusz Viste
88 *
99 * Permission is hereby granted, free of charge, to any person obtaining a copy
1010 * of this software and associated documentation files (the "Software"), to
@@ -29,7 +29,7 @@
2929 #include <dos.h>
3030 #include <conio.h> /* outp() */
3131
32-#include <mdr\timer.h> /* include self for control */
32+#include <mdr/timer.h> /* include self for control */
3333
3434 /* selects timer's resolution */
3535 #define TIMER_1165_HZ
@@ -104,14 +104,16 @@
104104
105105 /* reset the timer value, this can be used by the application to make sure
106106 * no timer wrap occurs during critical parts of the code flow */
107-void timer_reset(void) {
107+void mdr_timer_reset(void) {
108+ disable();
108109 nowtime = 0;
110+ enable();
109111 }
110112
111113
112114 /* This routine will stop the timer. It has void return value so that it
113115 * can be an exit procedure. */
114-void timer_stop(void) {
116+void mdr_timer_stop(void) {
115117 /* Disable interrupts */
116118 disable();
117119
@@ -132,7 +134,7 @@
132134 * routine as the interrupt service routine for the clock interrupt and then
133135 * setting the interrupt rate up to its higher speed by programming the 8253
134136 * timer chip. */
135-void timer_init(void) {
137+void mdr_timer_init(void) {
136138 /* Store the old interrupt handler */
137139 oldfunc = getvect(CLOCK_INT);
138140
@@ -152,10 +154,6 @@
152154
153155 /* Enable interrupts */
154156 enable();
155-
156- /* Install the timer_stop() routine to be called at exit */
157- atexit(timer_stop);
158-
159157 }
160158
161159
@@ -162,7 +160,7 @@
162160 /* This routine will return the present value of the time, as a number of
163161 * microseconds. Interrupts are disabled during this time to prevent the
164162 * clock from changing while it is being read. */
165-void timer_read(unsigned long *res) {
163+void mdr_timer_read(unsigned long *res) {
166164 /* Disable interrupts */
167165 disable();
168166
--- trunk/history.txt (revision 106)
+++ trunk/history.txt (revision 107)
@@ -7,6 +7,7 @@
77 - added mdr_bios_ticks()
88 - renamed keyb_getkey() to mdr_dos_getkey()
99 - renamed keyb_flush() to mdr_dos_flushkeyb()
10+- renamed all timer_ functions to mdr_timer_
1011 - new mdr_dos_getkey2(), same as mdr_dos_getkey() but immune to CTRL+C
1112 - new mdr_dos_keypending()
1213 - removed keyb_getkey_ifany(): use mdr_dos_keypending + mdr_dos_getkey instead
Show on old repository browser