-
Notifications
You must be signed in to change notification settings - Fork 3
/
amalBank.cpp
151 lines (113 loc) · 3.08 KB
/
amalBank.cpp
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
#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/retroMode.h>
#include <string.h>
#include "bank_helper.h"
#include "amosKittens.h"
#include "AmalCompiler.h"
#include "channel.h"
#include "amalBank.h"
amalBankPlay::amalBankPlay( char *start)
{
offset_tab = (unsigned short *) (start + 6) ;
size_tab = offset_tab + 48; // next 48
name_tab = (char *) ( size_tab +48);
move_data = ((char *) name_tab) + (48*8);
}
amalBankScript::amalBankScript( char *start)
{
unsigned int offset = *((unsigned int *) start) ;
printf("offset in bank: %08x\n",offset);
prog_block = start +offset;
progs = *((unsigned short *) prog_block);
offsets = (unsigned short *) (prog_block + 2);
first_script = (prog_block+2) + ((progs+1) * 2);
}
namespace amalBank
{
BOOL deNext( struct amalPlayContext *data )
{
if (data -> repeat)
{
// printf("repeat %d\n", data -> repeat);
data -> repeat --;
return FALSE;
}
{
signed char value = *data -> data;
if (value & 0x80)
{
data -> repeat=(value & 127);
data -> value = 0;
data -> size+= data -> repeat;
// printf("got repeat %d\n",data -> repeat);
}
else
{
data -> value = value & 0x40 ? 0x80 | value : value & 0x3F;
// printf("got data %d\n", data -> value);
data -> size++;
}
data -> data++; // get next
}
return TRUE;
}
#define amal_play_adr(start,item ) (start+( amalPlayBank -> offset_tab[ item ]*2+4))
void initPlayContext(struct amalPlayContext *pc, signed char *data)
{
pc -> repeat =0;
pc -> data = data;
}
void getMove( struct amalBankPlay *amalPlayBank, int id, char *start )
{
int sp;
char d;
char *ap;
ap = amal_play_adr( start, id );
sp = *((unsigned short *) ap);
ap+=2;
amalPlayBank -> lx = *((unsigned short *) ap)-2-4;
ap+=2;
d = *((char *) ap);
initPlayContext(&( amalPlayBank -> cdx), (signed char *) ap );
initPlayContext(&( amalPlayBank -> cdy), (signed char *) ap +amalPlayBank -> lx + 2);
}
int play( struct kittyChannel *self, int id )
{
// amalPlayBank missing, init...
if (self -> amalPlayBank == NULL)
{
struct kittyBank *bank = findBankById( 4 );
if (bank)
{
if (bank -> start == NULL) return channel_status::error;
self -> amalPlayBank = new amalBankPlay( bank -> start );
getMove( self -> amalPlayBank, id , bank -> start );
}
}
// scope ready...
{
struct amalBankPlay *amalPlayBank = self -> amalPlayBank;
if ( amalPlayBank == NULL) return channel_status::error;
if (( amalPlayBank -> lx > 0 || amalPlayBank -> cdx.repeat > 0))
{
int number = self -> number;
if (deNext( &amalPlayBank -> cdx )) amalPlayBank -> lx--;
deNext( &amalPlayBank -> cdy );
self -> objectAPI -> setX( number, self -> objectAPI -> getX( number ) + amalPlayBank -> cdx.value );
self -> objectAPI -> setY( number, self -> objectAPI -> getY( number ) + amalPlayBank -> cdy.value );
return channel_status::active;
}
else // done
{
delete self -> amalPlayBank;
self -> amalPlayBank = NULL;
return channel_status::done;
}
}
return channel_status::error;
}
} // end of name space