R-PAGE
Resistance's Portable-Adventure-Game-Engine
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
time.c
Go to the documentation of this file.
1 /* Resistance's Portable-Adventure-Game-Engine (R-PAGE), Copyright (C) 2019 François Gutherz, Resistance.no
2  Released under MIT License, see license.txt for details.
3 */
4 
5 #ifdef LATTICE
6 #include <stdio.h>
7 #include <stdlib.h>
8 
9 #include <exec/types.h>
10 #include <exec/ports.h>
11 #include <proto/exec.h>
12 #include <proto/dos.h>
13 #include <devices/timer.h>
14 
15 #include "rpage/aos/debug.h"
16 
17 // #include <proto/all.h>
18 
19 struct Library *TimerBase = NULL;
20 struct MsgPort *timer_port = NULL;
21 struct timerequest *timer_io = NULL;
22 BYTE time_r_error = 0;
23 
24 BOOL init_timer_device(void)
25 {
26 #ifdef DEBUG_MACROS
27  printf("init_timer_device()\n");
28 #endif
29  timer_port = CreatePort(NULL, 0);
30  if (!timer_port)
31  {
32 #ifdef DEBUG_MACROS
33  printf("could not create message port\n");
34 #endif
35  return FALSE;
36  }
37  timer_io = (struct timerequest *)CreateExtIO(timer_port,
38  sizeof(struct timerequest));
39  if (!timer_io)
40  {
41 #ifdef DEBUG_MACROS
42  printf("could not create create timerequest object\n");
43 #endif
44  DeletePort(timer_port);
45  return FALSE;
46  }
47  time_r_error = OpenDevice(TIMERNAME, UNIT_MICROHZ,
48  (struct IORequest *)timer_io, 0);
49  if (!time_r_error)
50  TimerBase = (struct Library *)timer_io->tr_node.io_Device;
51 #ifdef DEBUG_MACROS
52  else
53  printf("could not open timer.device\n");
54 #endif
55 }
56 
57 void timer_device_get_system_time(struct timeval *time_val)
58 {
59  timer_io->tr_node.io_Command = TR_GETSYSTIME;
60  DoIO((struct IORequest *) timer_io);
61  time_val->tv_secs = timer_io->tr_time.tv_secs;
62  time_val->tv_micro = timer_io->tr_time.tv_micro;
63 }
64 
65 void uninit_timer_device(void)
66 {
67 #ifdef DEBUG_MACROS
68  printf("uninit_timer_device()\n");
69 #endif
70  if (!CheckIO((struct IORequest *)timer_io))
71  AbortIO((struct IORequest *)timer_io);
72 
73  WaitIO((struct IORequest *)timer_io);
74  TimerBase = NULL;
75 
76  /* cleanup */
77  CloseDevice((struct IORequest *)timer_io);
78  if (timer_io)
79  DeleteExtIO((struct IORequest *)timer_io);
80  if (timer_port)
81  DeletePort(timer_port);
82 }
83 
84 #endif
#define FALSE
Definition: utils.h:41
int BOOL
Definition: utils.h:32
unsigned char BYTE
Definition: utils.h:16