Annotation of hatari/src/cpu/events.c, revision 1.1.1.1

1.1       root        1: /*
                      2: * UAE - The Un*x Amiga Emulator
                      3: *
                      4: * Event stuff
                      5: *
                      6: * Copyright 1995-2002 Bernd Schmidt
                      7: * Copyright 1995 Alessandro Bissacco
                      8: * Copyright 2000-2012 Toni Wilen
                      9: */
                     10: 
                     11: #include "main.h"
                     12: 
                     13: #include "sysconfig.h"
                     14: #include "sysdeps.h"
                     15: 
                     16: #include "options_cpu.h"
                     17: #include "events.h"
                     18: #include "memory.h"
                     19: #include "newcpu.h"
                     20: //#include "uae/ppc.h"
                     21: 
                     22: static const int pissoff_nojit_value = 256 * CYCLE_UNIT;
                     23: 
                     24: #ifndef WINUAE_FOR_HATARI
                     25: unsigned long int event_cycles, nextevent, currcycle;
                     26: int is_syncline, is_syncline_end;
                     27: long cycles_to_next_event;
                     28: long max_cycles_to_next_event;
                     29: long cycles_to_hsync_event;
                     30: unsigned long start_cycles;
                     31: bool event_wait;
                     32: 
                     33: frame_time_t vsyncmintime, vsyncmaxtime, vsyncwaittime;
                     34: int vsynctimebase;
                     35: int event2_count;
                     36: 
                     37: void events_schedule (void)
                     38: {
                     39:        int i;
                     40: 
                     41:        unsigned long int mintime = ~0L;
                     42:        for (i = 0; i < ev_max; i++) {
                     43:                if (eventtab[i].active) {
                     44:                        unsigned long int eventtime = eventtab[i].evtime - currcycle;
                     45:                        if (eventtime < mintime)
                     46:                                mintime = eventtime;
                     47:                }
                     48:        }
                     49:        nextevent = currcycle + mintime;
                     50: }
                     51: #endif
                     52: 
                     53: void do_cycles_slow (unsigned long cycles_to_add)
                     54: {
                     55: #ifndef WINUAE_FOR_HATARI
                     56:        if ((pissoff -= cycles_to_add) >= 0)
                     57:                return;
                     58: 
                     59:        cycles_to_add = -pissoff;
                     60:        pissoff = 0;
                     61: 
                     62:        while ((nextevent - currcycle) <= cycles_to_add) {
                     63:                int i;
                     64: 
                     65:                /* Keep only CPU emulation running while waiting for sync point. */
                     66:                if (is_syncline) {
                     67:                        if (!vblank_found_chipset) {
                     68:                                if (is_syncline > 0) {
                     69:                                        int rpt = read_processor_time ();
                     70:                                        int v = rpt - vsyncmintime;
                     71:                                        int v2 = rpt - is_syncline_end;
                     72:                                        if (v > vsynctimebase || v < -vsynctimebase) {
                     73:                                                v = 0;
                     74:                                        }
                     75:                                        if (v < 0 && v2 < 0 && event_wait) {
                     76: 
                     77: #ifdef WITH_PPC
                     78:                                                if (ppc_state) {
                     79:                                                        if (is_syncline == 1) {
                     80:                                                                uae_ppc_execute_check();
                     81:                                                        } else {
                     82:                                                                uae_ppc_execute_quick();
                     83:                                                        }
                     84:                                                }
                     85: #endif
                     86:                                                if (currprefs.cachesize)
                     87:                                                        pissoff = pissoff_value;
                     88:                                                else
                     89:                                                        pissoff = pissoff_nojit_value;
                     90:                                                return;
                     91:                                        }
                     92:                                } else if (is_syncline < 0) {
                     93:                                        int rpt = read_processor_time ();
                     94:                                        int v = rpt - is_syncline_end;
                     95:                                        if (v < 0 && event_wait) {
                     96: 
                     97: #ifdef WITH_PPC
                     98:                                                if (ppc_state) {
                     99:                                                        uae_ppc_execute_check();
                    100:                                                }
                    101: #endif
                    102:                                                if (currprefs.cachesize)
                    103:                                                        pissoff = pissoff_value;
                    104:                                                else
                    105:                                                        pissoff = pissoff_nojit_value;
                    106:                                                return;
                    107:                                        }
                    108:                                }
                    109:                        }
                    110:                        is_syncline = 0;
                    111:                }
                    112: 
                    113:                cycles_to_add -= nextevent - currcycle;
                    114:                currcycle = nextevent;
                    115: 
                    116:                for (i = 0; i < ev_max; i++) {
                    117:                        if (eventtab[i].active && eventtab[i].evtime == currcycle) {
                    118:                                if (eventtab[i].handler == NULL) {
                    119:                                        gui_message(_T("eventtab[%d].handler is null!\n"), i);
                    120:                                        eventtab[i].active = 0;
                    121:                                } else {
                    122:                                        (*eventtab[i].handler)();
                    123:                                }
                    124:                        }
                    125:                }
                    126:                events_schedule ();
                    127: 
                    128: 
                    129:        }
                    130: #endif
                    131:        currcycle += cycles_to_add;
                    132: }
                    133: 
                    134: #ifndef WINUAE_FOR_HATARI
                    135: void MISC_handler (void)
                    136: {
                    137:        static bool dorecheck;
                    138:        bool recheck;
                    139:        int i;
                    140:        evt mintime;
                    141:        evt ct = get_cycles ();
                    142:        static int recursive;
                    143: 
                    144:        if (recursive) {
                    145:                dorecheck = true;
                    146:                return;
                    147:        }
                    148:        recursive++;
                    149:        eventtab[ev_misc].active = 0;
                    150:        recheck = true;
                    151:        while (recheck) {
                    152:                recheck = false;
                    153:                mintime = ~0L;
                    154:                for (i = 0; i < ev2_max; i++) {
                    155:                        if (eventtab2[i].active) {
                    156:                                if (eventtab2[i].evtime == ct) {
                    157:                                        eventtab2[i].active = false;
                    158:                                        event2_count--;
                    159:                                        eventtab2[i].handler (eventtab2[i].data);
                    160:                                        if (dorecheck || eventtab2[i].active) {
                    161:                                                recheck = true;
                    162:                                                dorecheck = false;
                    163:                                        }
                    164:                                } else {
                    165:                                        evt eventtime = eventtab2[i].evtime - ct;
                    166:                                        if (eventtime < mintime)
                    167:                                                mintime = eventtime;
                    168:                                }
                    169:                        }
                    170:                }
                    171:        }
                    172:        if (mintime != ~0UL) {
                    173:                eventtab[ev_misc].active = true;
                    174:                eventtab[ev_misc].oldcycles = ct;
                    175:                eventtab[ev_misc].evtime = ct + mintime;
                    176:                events_schedule ();
                    177:        }
                    178:        recursive--;
                    179: }
                    180: 
                    181: 
                    182: void event2_newevent_xx (int no, evt t, uae_u32 data, evfunc2 func)
                    183: {
                    184:        evt et;
                    185:        static int next = ev2_misc;
                    186: 
                    187:        et = t + get_cycles ();
                    188:        if (no < 0) {
                    189:                no = next;
                    190:                for (;;) {
                    191:                        if (!eventtab2[no].active) {
                    192:                                event2_count++;
                    193:                                break;
                    194:                        }
                    195:                        if (eventtab2[no].evtime == et && eventtab2[no].handler == func && eventtab2[no].data == data)
                    196:                                break;
                    197:                        no++;
                    198:                        if (no == ev2_max)
                    199:                                no = ev2_misc;
                    200:                        if (no == next) {
                    201:                                write_log (_T("out of event2's!\n"));
                    202:                                return;
                    203:                        }
                    204:                }
                    205:                next = no;
                    206:        }
                    207:        eventtab2[no].active = true;
                    208:        eventtab2[no].evtime = et;
                    209:        eventtab2[no].handler = func;
                    210:        eventtab2[no].data = data;
                    211:        MISC_handler ();
                    212: }
                    213: 
                    214: int current_hpos (void)
                    215: {
                    216:        int hp = current_hpos_safe ();
                    217:        if (hp < 0 || hp > 256) {
                    218:                gui_message(_T("hpos = %d!?\n"), hp);
                    219:                hp = 0;
                    220:        }
                    221:        return hp;
                    222: }
                    223: #endif
                    224: 
                    225: 

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.