aboutsummaryrefslogtreecommitdiff
path: root/backends/dc/dcmain.cpp
blob: 77a0afa23683c588ea4cffd82a2d679c5396ae73 (plain)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* ScummVM - Scumm Interpreter
 * Dreamcast port
 * Copyright (C) 2002  Marcus Comstedt
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.

 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.

 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 * $Header$
 *
 */

#define RONIN_TIMER_ACCESS

#include <common/scummsys.h>
#include <common/stdafx.h>
#include <common/engine.h>
#include <common/gameDetector.h>
#include "dc.h"
#include "icon.h"


Icon icon;


OSystem *OSystem_Dreamcast_create() {
	return OSystem_Dreamcast::create();
}

OSystem *OSystem_Dreamcast::create() {
	OSystem_Dreamcast *syst = new OSystem_Dreamcast();
	return syst;
}

/* CD Audio */
static bool find_track(int track, int &first_sec, int &last_sec)
{
  struct TOC *toc = cdfs_gettoc();
  if(!toc)
    return false;
  int i, first, last;
  first = TOC_TRACK(toc->first);
  last = TOC_TRACK(toc->last);
  if(first < 1 || last > 99 || first > last)
    return false;
  for(i=last; i>=first; --i)
    if(!(TOC_CTRL(toc->entry[i-1])&4))
      if(track==1) {
	first_sec = TOC_LBA(toc->entry[i-1]);
	last_sec = TOC_LBA(toc->entry[i]);
	return true;
      } else
	--track;
  return false;
}

void OSystem_Dreamcast::play_cdrom(int track, int num_loops,
				   int start_frame, int end_frame)
{
  int first_sec, last_sec;
#if 1
  if(num_loops)
    --num_loops;
#endif
  if(num_loops>14) num_loops=14;
  else if(num_loops<0) num_loops=15; // infinity
  if(!find_track(track, first_sec, last_sec))
    return;
  if(end_frame)
    last_sec = first_sec + start_frame + end_frame;
  first_sec += start_frame;
  play_cdda_sectors(first_sec, last_sec, num_loops);
}

void OSystem_Dreamcast::stop_cdrom()
{
  stop_cdda();
}

bool OSystem_Dreamcast::poll_cdrom()
{
  extern int getCdState();
  return getCdState() == 3;
}

void OSystem_Dreamcast::update_cdrom()
{
  // Dummy.  The CD drive takes care of itself.
}

uint32 OSystem_Dreamcast::property(int param, Property *value)
{
  switch(param) {

  case PROP_GET_SAMPLE_RATE:
    return 22050;

  }
  
  return 0;
}

void OSystem_Dreamcast::quit() {
  exit(0);
}

void *OSystem_Dreamcast::create_thread(ThreadProc *proc, void *param) {
  warning("Creating a thread! (not supported.)\n");
}

uint32 OSystem_Dreamcast::get_msecs()
{
  static uint32 msecs=0;
  static unsigned int t0=0;

  unsigned int t = Timer();
  unsigned int dm, dt = t - t0;

  t0 = t;
  dm = (dt << 6)/3125U;
  dt -= (dm * 3125U)>>6;
  t0 -= dt;

  return msecs += dm;
}

void OSystem_Dreamcast::delay_msecs(uint msecs)
{
  get_msecs();
  unsigned int t, start = Timer();
  int time = (((unsigned int)msecs)*100000U)>>11;
  while(((int)((t = Timer())-start))<time)
    checkSound();
  get_msecs();
}

void OSystem_Dreamcast::set_timer(int timer, int (*callback)(int))
{
  warning("Setting a timer! (not supported.)\n");  
}

/* Mutex handling */
void *OSystem_Dreamcast::create_mutex(void)
{
  return NULL;
}

void OSystem_Dreamcast::lock_mutex(void *mutex)
{
}
 
void OSystem_Dreamcast::unlock_mutex(void *mutex)
{
}

void OSystem_Dreamcast::delete_mutex(void *mutex)
{
}


/*
void waitForTimer(Scumm *s, int time)
{
  if(time<0)
    return;
  unsigned int start = Timer();
  unsigned int devpoll = start+USEC_TO_TIMER(25000);
  unsigned int t;
  int oldmousex = s->mouse.x, oldmousey = s->mouse.y;
  time = (((unsigned int)time)*100000U)>>11;
  int mask = getimask();
  while(((int)((t = Timer())-start))<time)
    if(((int)(t-devpoll))>0) {
      setimask(15);
      checkSound();
      handleInput(locked_get_pads(), s->mouse.x, s->mouse.y,
		  s->_leftBtnPressed, s->_rightBtnPressed, s->_keyPressed);
      setimask(mask);
      devpoll += USEC_TO_TIMER(17000);
      if(s->mouse.x != oldmousex || s->mouse.y != oldmousey) {
	extern void updateScreen(Scumm *s);
	updateScreen(s);
	oldmousex = s->mouse.x;
	oldmousey = s->mouse.y;
      }
    }
}
*/

void dc_init_hardware(void)
{
#ifndef NOSERIAL
  serial_init(57600);
  usleep(2000000);
  printf("Serial OK\r\n");
#endif

  cdfs_init();
  maple_init();
  dc_setup_ta();
  init_arm();
}

int dc_setup(GameDetector &detector)
{
  static char *argv[] = { "scummvm", NULL, NULL, NULL };
  static int argc = 3;

  initSound();

  if(!selectGame(&detector, argv[2], argv[1], icon))
    exit(0);

  detector.parseCommandLine(argc, argv);

  return 0;
}