Skip to content

Commit a1a93f4

Browse files
committed
Merge branch 'joematt/structs'
Signed-off-by: Joseph Mattello <[email protected]> # Conflicts: # src/blitter.c # src/dsp.c # src/gpu.c # src/joystick.c # src/vjag_memory.h
2 parents c6f8158 + 84a0808 commit a1a93f4

5 files changed

Lines changed: 82 additions & 148 deletions

File tree

src/blitter.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,10 +305,10 @@ static int32_t a1_clip_x, a1_clip_y;
305305
// to optimize the blitter, then we may revisit it in the future...
306306

307307
// Generic blit handler
308-
void blitter_generic(uint32_t icmd)
308+
void blitter_generic(uint32_t cmdi)
309309
{
310310
Bits32 cmd;
311-
cmd.WORD = icmd;
311+
cmd.WORD = cmdi;
312312

313313
uint32_t srcdata, srczdata, dstdata, dstzdata, writedata, inhibit;
314314
uint32_t bppSrc = (DSTA2 ? 1 << ((REG(A1_FLAGS) >> 3) & 0x07) : 1 << ((REG(A2_FLAGS) >> 3) & 0x07));
@@ -2917,7 +2917,7 @@ with srcshift bits 4 & 5 selecting the start position
29172917
*/
29182918
//So... basically what we have here is:
29192919
*zcomp = 0;
2920-
// TODO: Byte and bit this -jm provenance
2920+
// TODO: Byte and bit this - @joematt provenance
29212921
if ((((*srcz & 0x000000000000FFFFLL) < (dstz & 0x000000000000FFFFLL)) && (zmode & 0x01u))
29222922
|| (((*srcz & 0x000000000000FFFFLL) == (dstz & 0x000000000000FFFFLL)) && (zmode & 0x02u))
29232923
|| (((*srcz & 0x000000000000FFFFLL) > (dstz & 0x000000000000FFFFLL)) && (zmode & 0x04u)))
@@ -3048,7 +3048,7 @@ Sfine := DECH38EL (s_fine[0..7], dstart[0..2], sfen\);*/
30483048
/*Maskt[0] := BUF1 (maskt[0], s_fine[0]);
30493049
Maskt[1-7] := OAN1P (maskt[1-7], maskt[0-6], s_fine[1-7], e_fine\[1-7]);*/
30503050
////////////////////////////////////// C++ CODE //////////////////////////////////////
3051-
// TODO: Byte and bit this -jm provenance
3051+
// TODO: Byte and bit this - @joematt provenance
30523052

30533053
maskt = s_fine & 0x0001;
30543054
maskt |= (((maskt & 0x0001) || (s_fine & 0x02u)) && (e_fine & 0x02u) ? 0x0002 : 0x0000);
@@ -3061,6 +3061,7 @@ Maskt[1-7] := OAN1P (maskt[1-7], maskt[0-6], s_fine[1-7], e_fine\[1-7]);*/
30613061
//////////////////////////////////////////////////////////////////////////////////////
30623062

30633063
/* Produce a look-ahead on the ripple carry */
3064+
// TODO: Byte and bit this - @joematt provenance
30643065
maskt |= (((s_coarse & e_coarse & 0x01u) || (s_coarse & 0x02u)) && (e_coarse & 0x02u) ? 0x0100 : 0x0000);
30653066
maskt |= (((maskt & 0x0100) || (s_coarse & 0x04u)) && (e_coarse & 0x04u) ? 0x0200 : 0x0000);
30663067
maskt |= (((maskt & 0x0200) || (s_coarse & 0x08u)) && (e_coarse & 0x08u) ? 0x0400 : 0x0000);
@@ -3097,6 +3098,7 @@ Masku[14] := MX2 (masku[14], maskt[14], maskt[0], mir_byte);*/
30973098
mir_bit = true/*big_pix*/ && !phrase_mode;
30983099
mir_byte = true/*big_pix*/ && phrase_mode;
30993100
masku = maskt;
3101+
// TODO: Byte and bit this - @joematt provenance
31003102

31013103
if (mir_bit)
31023104
{

src/dsp.c

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -394,21 +394,16 @@ uint8_t DSPReadByte(uint32_t offset, uint32_t who/*=UNKNOWN*/)
394394

395395
uint16_t DSPReadWord(uint32_t offset, uint32_t who/*=UNKNOWN*/)
396396
{
397-
#ifdef USE_STRUCTS
398397
Offset offsett;
399398
offsett.LONG = offset;
400399
offset = offsett.Members.offset;
401-
#else
402-
offset &= 0xFFFFFFFE;
403-
#endif
404400
if (offset >= DSP_WORK_RAM_BASE && offset <= DSP_WORK_RAM_BASE+0x1FFF)
405401
{
406402
offset -= DSP_WORK_RAM_BASE;
407403
return GET16(dsp_ram_8, offset);
408404
}
409405
else if ((offset>=DSP_CONTROL_RAM_BASE)&&(offset<DSP_CONTROL_RAM_BASE+0x20))
410406
{
411-
#ifdef USE_STRUCTS
412407
DSPLong data;
413408
data.LONG = DSPReadLong(offset & 0xFFFFFFFC, who);
414409

@@ -417,13 +412,6 @@ uint16_t DSPReadWord(uint32_t offset, uint32_t who/*=UNKNOWN*/)
417412
} else {
418413
return data.Data.UWORD;
419414
}
420-
#else
421-
uint32_t data = DSPReadLong(offset & 0xFFFFFFFC, who);
422-
423-
if (offset & 0x03)
424-
return data & 0xFFFF;
425-
return data >> 16;
426-
#endif
427415
}
428416

429417
return JaguarReadWord(offset, who);
@@ -868,7 +856,6 @@ INLINE void DSPExec(int32_t cycles)
868856
IMASKCleared = false;
869857
}
870858

871-
#ifdef USE_STRUCTS
872859
OpCode opcode;
873860
opcode.WORD = DSPReadWord(dsp_pc, DSP);
874861
uint8_t index = opcode.Codes.index;
@@ -878,20 +865,8 @@ INLINE void DSPExec(int32_t cycles)
878865
dsp_opcode_second_parameter = sp;
879866
dsp_pc += 2;
880867
dsp_opcode[index]();
881-
#else
882-
uint16_t opcode;
883-
uint32_t index;
884-
opcode = DSPReadWord(dsp_pc, DSP);
885-
index = opcode >> 10;
886-
dsp_opcode_first_parameter = (opcode >> 5) & 0x1F;
887-
dsp_opcode_second_parameter = opcode & 0x1F;
888-
dsp_pc += 2;
889-
dsp_opcode[index]();
890-
dsp_opcode_use[index]++;
891-
#endif
892-
// Counter is not necessary and expensive -jm prov
893-
// dsp_opcode_use[index]++;
894-
cycles -= dsp_opcode_cycles[index];
868+
869+
cycles -= dsp_opcode_cycles[index];
895870
}
896871

897872
dsp_in_exec--;
@@ -1955,7 +1930,6 @@ INLINE static void DSP_jr(void)
19551930
}//*/
19561931
dsp_pc += 2; // For DSP_DIS_* accuracy
19571932
DSPOpcode[pipeline[plPtrExec].opcode]();
1958-
// dsp_opcode_use[pipeline[plPtrExec].opcode]++;
19591933
pipeline[plPtrWrite] = pipeline[plPtrExec];
19601934

19611935
// Step 3: Flush pipeline & set new PC

src/gpu.c

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -325,16 +325,10 @@ INLINE uint16_t GPUReadWord(uint32_t offset, uint32_t who/*=UNKNOWN*/)
325325
if ((offset >= GPU_WORK_RAM_BASE) && (offset < GPU_WORK_RAM_BASE+0x1000))
326326
{
327327
offset &= 0xFFF;
328-
#ifdef USE_STRUCTS
329328
OpCode data;
330329
data.Bytes.UBYTE = (uint16_t)gpu_ram_8[offset];
331330
data.Bytes.LBYTE = (uint16_t)gpu_ram_8[offset+1];
332331
return data.WORD;
333-
#else
334-
uint16_t data;
335-
data = ((uint16_t)gpu_ram_8[offset] << 8) | (uint16_t)gpu_ram_8[offset+1];
336-
return data;
337-
#endif
338332
}
339333
else if ((offset >= GPU_CONTROL_RAM_BASE) && (offset < GPU_CONTROL_RAM_BASE+0x20))
340334
{
@@ -398,8 +392,9 @@ INLINE uint32_t GPUReadLong(uint32_t offset, uint32_t who/*=UNKNOWN*/)
398392
case 0x1C:
399393
return gpu_remain;
400394
default: // unaligned long read
401-
return 0;
395+
break;
402396
}
397+
return 0;
403398
}
404399

405400
return (JaguarReadWord(offset, who) << 16) | JaguarReadWord(offset + 2, who);
@@ -609,7 +604,7 @@ void GPUHandleIRQs(void)
609604
return;
610605

611606
// Get the interrupt latch & enable bits
612-
bits = gpu_control.gpuIRQ.irqMask; //(gpu_control >> 6) & 0x1F;
607+
bits = gpu_control.gpuIRQ.irqMask; //(gpu_control >> 6) & 0x1F;
613608
mask = (gpu_flags >> 4) & 0x1F;
614609

615610
// Bail out if latched interrupts aren't enabled

src/joystick.c

Lines changed: 70 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -61,109 +61,78 @@ uint16_t JoystickReadWord(uint32_t offset)
6161

6262
offset &= 0x03;
6363

64-
if (offset == 0)
65-
{
66-
uint8_t offset0, offset1;
67-
uint16_t data = 0xFFFF;
68-
64+
if (offset == 0)
65+
{
66+
uint8_t offset0, offset1;
67+
uint16_t data = 0xFFFF;
68+
6969
if (!joysticksEnabled) {
70-
return 0xFFFF;
71-
}
72-
73-
// Joystick data returns active low for buttons pressed, high for non-
74-
// pressed.
75-
offset0 = joypad0Offset[joystick_ram[1] & 0x0F];
76-
offset1 = joypad1Offset[(joystick_ram[1] >> 4) & 0x0F];
77-
78-
if (offset0 != 0xFF)
79-
{
80-
uint16_t mask[4] = { 0xFEFF, 0xFDFF, 0xFBFF, 0xF7FF };
81-
uint16_t msk2[4] = { 0xFFFF, 0xFFFD, 0xFFFB, 0xFFF7 };
82-
83-
for(uint8_t i = 0; i < 4; i++) {
84-
data &= (joypad0Buttons[offset0 + i] ? mask[i] : 0xFFFF);
85-
}
86-
87-
data &= msk2[offset0 / 4];
88-
}
89-
90-
if (offset1 != 0xFF)
91-
{
92-
uint16_t mask[4] = { 0xEFFF, 0xDFFF, 0xBFFF, 0x7FFF };
93-
uint16_t msk2[4] = { 0xFF7F, 0xFFBF, 0xFFDF, 0xFFEF };
94-
95-
for(uint8_t i = 0; i < 4; i++) {
96-
data &= (joypad1Buttons[offset1 + i] ? mask[i] : 0xFFFF);
97-
}
98-
data &= msk2[offset1 / 4];
70+
return 0xFFFF;
9971
}
100-
101-
return data;
102-
}
103-
else if (offset == 2)
104-
{
105-
uint8_t offset0, offset1;
106-
// Hardware ID returns NTSC/PAL identification bit here
107-
// N.B.: On real H/W, bit 7 is *always* zero...!
108-
uint16_t data = 0xFF6F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
109-
110-
if (!joysticksEnabled)
111-
return data;
112-
113-
// Joystick data returns active low for buttons pressed, high for non-
114-
// pressed.
115-
uint8_t jrmLow = joystick_ram[1] & 0x0F;
116-
uint8_t jrmHigh = (joystick_ram[1] >> 4) & 0x0F;
117-
uint8_t jp0offset = joypad0Offset[jrmLow];
118-
uint8_t jp1offset = joypad1Offset[jrmHigh];
119-
120-
offset0 = jp0offset; // % 4;
121-
offset1 = jp1offset; // % 4;
122-
123-
const int8_t mask[4][2] = {
124-
{ BUTTON_A, BUTTON_PAUSE },
125-
{ BUTTON_B, 0xFF },
126-
{ BUTTON_C, 0xFF },
127-
{ BUTTON_OPTION, 0xFF } };
128-
129-
if (offset0 != 0xFF)
130-
{
131-
offset0 /= 4;
132-
133-
uint8_t i0 = mask[offset0][0];
134-
uint8_t i1 = mask[offset0][1];
135-
136-
uint8_t maskOffset00 = joypad0Buttons[i0];
137-
uint8_t maskOffset01 = joypad0Buttons[i1];
138-
139-
data &= (maskOffset00 ? 0xFFFD : 0xFFFF);
140-
141-
if (i1 != 0xFF) {
142-
data &= (joypad0Buttons[i1] ? 0xFFFE : 0xFFFF);
143-
}
144-
}
145-
146-
if (offset1 != 0xFF)
147-
{
148-
offset1 /= 4;
149-
150-
uint8_t i0 = mask[offset1][0];
151-
uint8_t i1 = mask[offset1][1];
152-
153-
uint8_t maskOffset10 = joypad1Buttons[i0];
154-
155-
data &= (maskOffset10 ? 0xFFF7 : 0xFFFF);
156-
157-
if (i1 != 0xFF) {
158-
uint8_t maskOffset11 = joypad1Buttons[i1];
159-
uint8_t button = maskOffset11;
160-
uint16_t dataMask = (button ? 0xFFFB : 0xFFFF);
161-
data &= dataMask;
162-
}
163-
}
164-
165-
return data;
166-
}
72+
73+
// Joystick data returns active low for buttons pressed, high for non-
74+
// pressed.
75+
offset0 = joypad0Offset[joystick_ram[1] & 0x0F];
76+
offset1 = joypad1Offset[(joystick_ram[1] >> 4) & 0x0F];
77+
78+
if (offset0 != 0xFF)
79+
{
80+
unsigned i;
81+
uint16_t mask[4] = { 0xFEFF, 0xFDFF, 0xFBFF, 0xF7FF };
82+
uint16_t msk2[4] = { 0xFFFF, 0xFFFD, 0xFFFB, 0xFFF7 };
83+
84+
for(i = 0; i < 4; i++)
85+
data &= (joypad0Buttons[offset0 + i] ? mask[i] : 0xFFFF);
86+
87+
data &= msk2[offset0 / 4];
88+
}
89+
90+
if (offset1 != 0xFF)
91+
{
92+
unsigned i;
93+
uint16_t mask[4] = { 0xEFFF, 0xDFFF, 0xBFFF, 0x7FFF };
94+
uint16_t msk2[4] = { 0xFF7F, 0xFFBF, 0xFFDF, 0xFFEF };
95+
96+
for(i = 0; i < 4; i++)
97+
data &= (joypad1Buttons[offset1 + i] ? mask[i] : 0xFFFF);
98+
99+
data &= msk2[offset1 / 4];
100+
}
101+
102+
return data;
103+
}
104+
else if (offset == 2)
105+
{
106+
uint8_t offset0, offset1;
107+
// Hardware ID returns NTSC/PAL identification bit here
108+
// N.B.: On real H/W, bit 7 is *always* zero...!
109+
uint16_t data = 0xFF6F | (vjs.hardwareTypeNTSC ? 0x10 : 0x00);
110+
const int8_t mask[4][2] = { { BUTTON_A, BUTTON_PAUSE }, { BUTTON_B, 0xFF }, { BUTTON_C, 0xFF }, { BUTTON_OPTION, 0xFF } };
111+
112+
if (!joysticksEnabled)
113+
return data;
114+
115+
// Joystick data returns active low for buttons pressed, high for non-
116+
// pressed.
117+
offset0 = joypad0Offset[joystick_ram[1] & 0x0F] / 4;
118+
offset1 = joypad1Offset[(joystick_ram[1] >> 4) & 0x0F] / 4;
119+
120+
if (offset0 != 0xFF)
121+
{
122+
data &= (joypad0Buttons[mask[offset0][0]] ? 0xFFFD : 0xFFFF);
123+
if (mask[offset0][1] != 0xF)
124+
data &= (joypad0Buttons[mask[offset0][1]] ? 0xFFFE : 0xFFFF);
125+
}
126+
127+
if (offset1 != 0xFF)
128+
{
129+
data &= (joypad1Buttons[mask[offset1][0]] ? 0xFFF7 : 0xFFFF);
130+
if (mask[offset1][1] != 0xF)
131+
data &= (joypad1Buttons[mask[offset1][1]] ? 0xFFFB : 0xFFFF);
132+
}
133+
134+
return data;
135+
}
167136

168137
return 0xFFFF;
169138
}

src/vjag_memory.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ extern "C" {
4040
} bytes;
4141
} Bits64;
4242
#pragma pack(pop)
43-
_Static_assert( sizeof(Bits64) == sizeof(uint64_t), "Pack error");
44-
43+
4544
#pragma pack(push, 1)
4645
typedef union Bits32 {
4746
uint32_t WORD;
@@ -148,7 +147,6 @@ typedef union Bits32 {
148147
} bits;
149148
} Bits32;
150149
#pragma pack(pop)
151-
_Static_assert( sizeof(Bits32) == sizeof(uint32_t), "Pack error");
152150

153151
#pragma pack(push, 1)
154152
typedef union GPUControl {
@@ -170,7 +168,6 @@ typedef union GPUControl {
170168

171169
} GPUControl;
172170

173-
#ifdef USE_STRUCTS
174171
#pragma pack(push, 1)
175172
typedef union OpCode {
176173
uint16_t WORD;
@@ -198,9 +195,7 @@ typedef union GPUControl {
198195
#pragma pack(pop)
199196

200197
typedef OpCode U16Union;
201-
#endif //USE_STRUCTS
202198

203-
#ifdef USE_STRUCTS
204199
typedef union Offset {
205200
uint32_t LONG;
206201
#pragma pack(push, 1)
@@ -215,7 +210,6 @@ typedef union Offset {
215210
} Members;
216211
#pragma pack(pop)
217212
} Offset;
218-
#endif //USE_STRUCTS
219213

220214
typedef union DSPLong {
221215
uint32_t LONG;

0 commit comments

Comments
 (0)