-
Notifications
You must be signed in to change notification settings - Fork 2
/
enable_timer.h
79 lines (63 loc) · 1.29 KB
/
enable_timer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#ifndef ENABLE_TIMER_H
#define ENABLE_TIMER_H
#ifndef __linux
#pragma output REGISTER_SP = 0xFF58
#pragma output CLIB_MALLOC_HEAP_SIZE = -0xFBFA
#include <z80.h>
#include <string.h>
#include <intrinsic.h>
#include <im2.h>
#include <arch/zx.h>
IM2_DEFINE_ISR(isr)
{
unsigned *clock_ptr=(void*)(23672);
unsigned char *high_ptr=(void*)(23674);
if(*clock_ptr == 0xFFFF) {
++*high_ptr;
}
++*clock_ptr;
}
#define TABLE_HIGH_BYTE ((unsigned int)0xfc)
#define JUMP_POINT_HIGH_BYTE ((unsigned int)0xfb)
#define UI_256 ((unsigned int)256)
#define TABLE_ADDR ((void*)(TABLE_HIGH_BYTE*UI_256))
#define JUMP_POINT ((unsigned char*)( (unsigned int)(JUMP_POINT_HIGH_BYTE*UI_256) + JUMP_POINT_HIGH_BYTE ))
long get_time()
{
return (*(long*)(23674)<<16) + *(unsigned *)(23672);
}
long timer;
void start_timer()
{
timer = get_time();
}
long stop_timer()
{
return (get_time()-timer);
}
void enable_timer()
{
memset( TABLE_ADDR, JUMP_POINT_HIGH_BYTE, 257 );
z80_bpoke( JUMP_POINT, 195 );
z80_wpoke( JUMP_POINT+1, (unsigned int)isr );
im2_init( TABLE_ADDR );
intrinsic_ei();
}
#else
long get_time()
{
return 0;
}
long timer;
void start_timer()
{
}
long stop_timer()
{
return 1;
}
void enable_timer()
{
}
#endif
#endif