non-asm compatibility re-fixed
[fceu.git] / input / arkanoid.c
CommitLineData
c62d2810 1/* FCE Ultra - NES/Famicom Emulator
2 *
3 * Copyright notice for this file:
4 * Copyright (C) 2002 Ben Parnell
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
25typedef struct {
26 uint32 mzx,mzb;
27 uint32 readbit;
28} ARK;
29
30static ARK NESArk[2];
31static ARK FCArk;
32
33static void StrobeARKFC(void)
34{
35 FCArk.readbit=0;
36}
37
38
39static uint8 FP_FASTAPASS(2) 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 FCArk.readbit++;
51 }
52 }
53 else
54 ret|=FCArk.mzb<<1;
55 return(ret);
56}
57
58static uint32 FixX(uint32 x)
59{
60 x=98+x*144/240;
61 if(x>242) x=242;
62 x=~x;
63 return(x);
64}
65
66static void FP_FASTAPASS(2) UpdateARKFC(void *data, int arg)
67{
68 uint32 *ptr=data;
69 FCArk.mzx=FixX(ptr[0]);
70 FCArk.mzb=ptr[2]?1:0;
71}
72
73static INPUTCFC ARKCFC={ReadARKFC,0,StrobeARKFC,UpdateARKFC,0,0};
74
75INPUTCFC *FCEU_InitArkanoidFC(void)
76{
77 FCArk.mzx=98;
78 FCArk.mzb=0;
79 return(&ARKCFC);
80}
81
82static uint8 FP_FASTAPASS(1) ReadARK(int w)
83{
84 uint8 ret=0;
85
86 if(NESArk[w].readbit>=8)
87 ret|=1<<4;
88 else
89 {
90 ret|=((NESArk[w].mzx>>(7-NESArk[w].readbit))&1)<<4;
91 NESArk[w].readbit++;
92 }
93 ret|=(NESArk[w].mzb&1)<<3;
94 return(ret);
95}
96
97
98static void FP_FASTAPASS(1) StrobeARK(int w)
99{
100 NESArk[w].readbit=0;
101}
102
103static void FP_FASTAPASS(3) UpdateARK(int w, void *data, int arg)
104{
105 uint32 *ptr=data;
106 NESArk[w].mzx=FixX(ptr[0]);
107 NESArk[w].mzb=ptr[2]?1:0;
108}
109
110static INPUTC ARKC={ReadARK, 0, StrobeARK, UpdateARK, 0, 0};
111
112INPUTC *FCEU_InitArkanoid(int w)
113{
114 NESArk[w].mzx=98;
115 NESArk[w].mzb=0;
116 return(&ARKC);
117}