DOSBox-X
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines
include/clockdomain.h
00001 
00002 /* DOSBox-X clock domain class.
00003  * The clock domain implementation allows DOSBox-X to accurately
00004  * track time in clocks instead of less precise floating point
00005  * intervals, and to more accurately emulate hardware in terms of
00006  * the reference clock.
00007  *
00008  * (C) 2014 Jonathan Campbell */
00009 
00010 #include <stdint.h>
00011 #include <assert.h>
00012 #include <math.h>
00013 
00014 #include <string>
00015 #include <vector>
00016 #include <list>
00017 
00018 #ifndef DOSBOX_CLOCKDOMAIN_H
00019 #define DOSBOX_CLOCKDOMAIN_H
00020 
00021 #include "dosbox.h"
00022 /* this code contains support for existing DOSBox code that uses PIC_AddEvent, etc. callbacks */
00023 #include "pic.h"
00024 
00025 class ClockDomain {
00026 public:
00027         ClockDomain() {
00028                 freq = 0;
00029                 freq_div = 1;
00030         }
00031         ClockDomain(unsigned long long freq_new) {
00032                 freq = freq_new;
00033                 freq_div = 1;
00034         }
00035         /* we allow non-integer frequencies as integer fractions.
00036          * example: 33.3333333...MHz as 100,000,000Hz / 3 */
00037         ClockDomain(unsigned long long freq_new,unsigned long long div) {
00038                 freq = freq_new;
00039                 freq_div = div;
00040         }
00041 public:
00042         void set_name(const char *s) {
00043                 name = s;
00044         }
00045         void set_frequency(unsigned long long freq_new,unsigned long long div_new=1) {
00046                 counter = 0;
00047                 freq = freq_new;
00048                 freq_div = div_new;
00049         }
00050         const char *get_name() {
00051                 return name.c_str();
00052         }
00053 public:
00054         /* NTS: Slave clock rules:
00055          *       - Must have the same "freq" value as master
00056          *       - Do not set clock time by floating point time (only the toplevel clocks in the tree should do that)
00057          *       - Must rebase at the same reference time as the master
00058          *       - Must maintain time according to master time divided by master's clock divider */
00059         unsigned long long              freq,freq_div;  /* frequency of clock as integer ratio */
00060         unsigned long long              counter;        /* in units of freq */
00061         std::string                     name;
00062 };
00063 
00064 #endif //DOSBOX_CLOCKDOMAIN_H
00065