~ubuntu-branches/ubuntu/lucid/fceux/lucid

« back to all changes in this revision

Viewing changes to fceu/src/input/arkanoid.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Fabrice Coutadeur
  • Date: 2009-12-14 08:05:17 UTC
  • Revision ID: james.westby@ubuntu.com-20091214080517-abi5tj8avthfan7c
Tags: upstream-2.1.2+repack
ImportĀ upstreamĀ versionĀ 2.1.2+repack

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* FCE Ultra - NES/Famicom Emulator
 
2
 *
 
3
 * Copyright notice for this file:
 
4
 *  Copyright (C) 2002 Xodnizel
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
19
 */
 
20
 
 
21
#include        <string.h>
 
22
#include        <stdlib.h>
 
23
#include        "share.h"
 
24
 
 
25
typedef struct {
 
26
        uint32 mzx,mzb;
 
27
        uint32 readbit;
 
28
} ARK;
 
29
 
 
30
static ARK NESArk[2];
 
31
static ARK FCArk;
 
32
 
 
33
static void StrobeARKFC(void)
 
34
{
 
35
        FCArk.readbit=0;
 
36
}
 
37
 
 
38
 
 
39
static uint8 ReadARKFC(int w,uint8 ret)
 
40
{
 
41
 ret&=~2;
 
42
 
 
43
 if(w)  
 
44
 {
 
45
  if(FCArk.readbit>=8) 
 
46
   ret|=2;
 
47
  else
 
48
  {
 
49
   ret|=((FCArk.mzx>>(7-FCArk.readbit))&1)<<1;
 
50
   if(!fceuindbg)
 
51
    FCArk.readbit++;
 
52
  }
 
53
 }
 
54
 else
 
55
  ret|=FCArk.mzb<<1;
 
56
 return(ret);
 
57
}
 
58
 
 
59
static uint32 FixX(uint32 x)
 
60
{
 
61
 x=98+x*144/240;
 
62
 if(x>242) x=242;
 
63
 x=~x;
 
64
 return(x);
 
65
}
 
66
 
 
67
static void UpdateARKFC(void *data, int arg)
 
68
{
 
69
 uint32 *ptr=(uint32 *)data;
 
70
 FCArk.mzx=FixX(ptr[0]);
 
71
 FCArk.mzb=ptr[2]?1:0;
 
72
}
 
73
 
 
74
static INPUTCFC ARKCFC={ReadARKFC,0,StrobeARKFC,UpdateARKFC,0,0};
 
75
 
 
76
INPUTCFC *FCEU_InitArkanoidFC(void)
 
77
{
 
78
 FCArk.mzx=98;
 
79
 FCArk.mzb=0;
 
80
 return(&ARKCFC);
 
81
}
 
82
 
 
83
static uint8 ReadARK(int w)
 
84
{
 
85
 uint8 ret=0;
 
86
 
 
87
 if(NESArk[w].readbit>=8)
 
88
  ret|=1<<4;
 
89
 else
 
90
 {
 
91
  ret|=((NESArk[w].mzx>>(7-NESArk[w].readbit))&1)<<4;
 
92
  if(!fceuindbg)
 
93
   NESArk[w].readbit++;
 
94
 }
 
95
 ret|=(NESArk[w].mzb&1)<<3;
 
96
 return(ret);
 
97
}
 
98
 
 
99
 
 
100
static void StrobeARK(int w)
 
101
{
 
102
        NESArk[w].readbit=0;
 
103
}
 
104
 
 
105
static void UpdateARK(int w, void *data, int arg)
 
106
{
 
107
 uint32 *ptr=(uint32*)data;
 
108
 NESArk[w].mzx=FixX(ptr[0]);
 
109
 NESArk[w].mzb=ptr[2]?1:0;
 
110
}
 
111
 
 
112
static INPUTC ARKC={ReadARK, 0, StrobeARK, UpdateARK, 0, 0};
 
113
 
 
114
INPUTC *FCEU_InitArkanoid(int w)
 
115
{
 
116
 NESArk[w].mzx=98;
 
117
 NESArk[w].mzb=0;
 
118
 return(&ARKC);
 
119
}