diff --git a/Assets/dll/virtualjaguar.wbx.zst b/Assets/dll/virtualjaguar.wbx.zst index a37f282365..6754c9057d 100644 Binary files a/Assets/dll/virtualjaguar.wbx.zst and b/Assets/dll/virtualjaguar.wbx.zst differ diff --git a/waterbox/virtualjaguar/src/cdhle.cpp b/waterbox/virtualjaguar/src/cdhle.cpp index 37308a65c9..7bf0ae8369 100644 --- a/waterbox/virtualjaguar/src/cdhle.cpp +++ b/waterbox/virtualjaguar/src/cdhle.cpp @@ -111,7 +111,7 @@ void CDHLEInit(void) cd_boot_lba = startLba + i; cd_boot_off = j + 32 + 4 + 4; cd_byte_swapped = false; - cd_word_alignment = (4 - j) & 3; + cd_word_alignment = -j & 3; foundHeader = true; break; } @@ -124,7 +124,7 @@ void CDHLEInit(void) cd_boot_lba = startLba + i; cd_boot_off = j + 32 + 4 + 4; cd_byte_swapped = true; - cd_word_alignment = (4 - j) & 3; + cd_word_alignment = -j & 3; foundHeader = true; break; } @@ -244,10 +244,10 @@ static void CDSendBlock(void) cd_buf_rm += 2352; } - // send one block of data - for (uint32_t i = 0; i < 64; i++) + // send one block of data, one long at a time + for (uint32_t i = 0; i < 64; i += 4) { - JaguarWriteByte(cd_read_addr_start + i, cd_buf2352[cd_buf_pos + i], GPU); + GPUWriteLong(cd_read_addr_start + i, GET32(cd_buf2352, cd_buf_pos + i), GPU); } cd_read_addr_start += 64; @@ -258,8 +258,7 @@ static void CDSendBlock(void) { cd_is_reading = false; } - - if (cd_buf_circular_size && (cd_read_addr_end - cd_read_addr_start) >= cd_buf_circular_size) + else if (cd_buf_circular_size && (cd_read_addr_start - cd_read_orig_addr_start) >= cd_buf_circular_size) { cd_read_addr_start = cd_read_orig_addr_start; } @@ -270,12 +269,15 @@ static void CDHLECallback(void) RemoveCallback(CDHLECallback); if (cd_is_reading) { - if (!cd_paused) + if (!GPURunning()) + fprintf(stderr, "CDHLECallback called with GPU inactive\n"); + + if (GPURunning() && !cd_paused) { CDSendBlock(); + //GPUSetIRQLine(GPUIRQ_DSP, ASSERT_LINE); } - //GPUSetIRQLine(GPUIRQ_DSP, ASSERT_LINE); - SetCallbackTime(CDHLECallback, 240 >> (cd_mode & 1)); + SetCallbackTime(CDHLECallback, 285 >> (cd_mode & 1)); } } @@ -366,14 +368,6 @@ static void CD_mode(void) static void CD_ack(void) { - if (!cd_paused) - { - while (cd_is_reading) - { - CDSendBlock(); - } - } - NO_ERR(); } @@ -521,8 +515,9 @@ static void CD_read(void) cd_buf_rm = bufRm; cd_buf_circular_size = circBufSz ? (1 << circBufSz) : 0; RemoveCallback(CDHLECallback); - SetCallbackTime(CDHLECallback, 240 >> (cd_mode & 1)); + SetCallbackTime(CDHLECallback, 285 >> (cd_mode & 1)); JERRYWriteWord(0xF10020, 0, M68K); + //GPUWriteLong(0xF02100, GPUReadLong(0xF02100, M68K) | 0x20, M68K); break; } } @@ -542,8 +537,9 @@ static void CD_read(void) cd_buf_rm = 0; cd_buf_circular_size = 0; RemoveCallback(CDHLECallback); - SetCallbackTime(CDHLECallback, 240 >> (cd_mode & 1)); + SetCallbackTime(CDHLECallback, 285 >> (cd_mode & 1)); JERRYWriteWord(0xF10020, 0, M68K); + //GPUWriteLong(0xF02100, GPUReadLong(0xF02100, M68K) | 0x20, M68K); } } diff --git a/waterbox/virtualjaguar/src/dsp.cpp b/waterbox/virtualjaguar/src/dsp.cpp index 6089f49127..b0a0393906 100644 --- a/waterbox/virtualjaguar/src/dsp.cpp +++ b/waterbox/virtualjaguar/src/dsp.cpp @@ -784,7 +784,7 @@ static void dsp_opcode_nop(void) static void dsp_opcode_storeb(void) { if (RM >= DSP_WORK_RAM_BASE && RM <= (DSP_WORK_RAM_BASE + 0x1FFF)) - DSPWriteLong(RM, RN & 0xFF, DSP); + DSPWriteLong(RM & 0xFFFFFFFC, RN, DSP); else JaguarWriteByte(RM, RN, DSP); } @@ -792,7 +792,7 @@ static void dsp_opcode_storeb(void) static void dsp_opcode_storew(void) { if (RM >= DSP_WORK_RAM_BASE && RM <= (DSP_WORK_RAM_BASE + 0x1FFF)) - DSPWriteLong(RM, RN & 0xFFFF, DSP); + DSPWriteLong(RM & 0xFFFFFFFC, RN, DSP); else JaguarWriteWord(RM, RN, DSP); } @@ -805,7 +805,7 @@ static void dsp_opcode_store(void) static void dsp_opcode_loadb(void) { if (RM >= DSP_WORK_RAM_BASE && RM <= (DSP_WORK_RAM_BASE + 0x1FFF)) - RN = DSPReadLong(RM, DSP) & 0xFF; + RN = DSPReadLong(RM & 0xFFFFFFFC, DSP); else RN = JaguarReadByte(RM, DSP); } @@ -813,7 +813,7 @@ static void dsp_opcode_loadb(void) static void dsp_opcode_loadw(void) { if (RM >= DSP_WORK_RAM_BASE && RM <= (DSP_WORK_RAM_BASE + 0x1FFF)) - RN = DSPReadLong(RM & 0xFFFFFFFE, DSP) & 0xFFFF; + RN = DSPReadLong(RM & 0xFFFFFFFC, DSP); else RN = JaguarReadWord(RM & 0xFFFFFFFE, DSP); } diff --git a/waterbox/virtualjaguar/src/gpu.cpp b/waterbox/virtualjaguar/src/gpu.cpp index 17d4fe389d..7cf108cc12 100644 --- a/waterbox/virtualjaguar/src/gpu.cpp +++ b/waterbox/virtualjaguar/src/gpu.cpp @@ -216,9 +216,9 @@ uint32_t gpu_convert_zero[32] = uint8_t * branch_condition_table = 0; #define BRANCH_CONDITION(x) branch_condition_table[(x) + ((jaguar_flags & 7) << 5)] -uint32_t GPUGetPC(void) +bool GPURunning(void) { - return gpu_pc; + return GPU_RUNNING; } void build_branch_condition_table(void) @@ -609,11 +609,6 @@ void GPUReset(void) *((uint32_t *)(&gpu_ram_8[i])) = rand(); } -uint32_t GPUReadPC(void) -{ - return gpu_pc; -} - void GPUDone(void) { } @@ -865,7 +860,7 @@ static void gpu_opcode_pack(void) static void gpu_opcode_storeb(void) { if ((RM >= 0xF03000) && (RM <= 0xF03FFF)) - GPUWriteLong(RM, RN & 0xFF, GPU); + GPUWriteLong(RM & 0xFFFFFFFC, RN, GPU); else JaguarWriteByte(RM, RN, GPU); } @@ -873,7 +868,7 @@ static void gpu_opcode_storeb(void) static void gpu_opcode_storew(void) { if ((RM >= 0xF03000) && (RM <= 0xF03FFF)) - GPUWriteLong(RM & 0xFFFFFFFE, RN & 0xFFFF, GPU); + GPUWriteLong(RM & 0xFFFFFFFC, RN, GPU); else JaguarWriteWord(RM, RN, GPU); } @@ -890,8 +885,7 @@ static void gpu_opcode_storep(void) { if ((RM >= 0xF03000) && (RM <= 0xF03FFF)) { - GPUWriteLong((RM & 0xFFFFFFF8) + 0, gpu_hidata, GPU); - GPUWriteLong((RM & 0xFFFFFFF8) + 4, RN, GPU); + GPUWriteLong(RM & 0xFFFFFFFC, RN, GPU); } else { @@ -903,7 +897,7 @@ static void gpu_opcode_storep(void) static void gpu_opcode_loadb(void) { if ((RM >= 0xF03000) && (RM <= 0xF03FFF)) - RN = GPUReadLong(RM, GPU) & 0xFF; + RN = GPUReadLong(RM & 0xFFFFFFFC, GPU); else RN = JaguarReadByte(RM, GPU); } @@ -911,7 +905,7 @@ static void gpu_opcode_loadb(void) static void gpu_opcode_loadw(void) { if ((RM >= 0xF03000) && (RM <= 0xF03FFF)) - RN = GPUReadLong(RM & 0xFFFFFFFE, GPU) & 0xFFFF; + RN = GPUReadLong(RM & 0xFFFFFFFC, GPU); else RN = JaguarReadWord(RM, GPU); } @@ -925,8 +919,7 @@ static void gpu_opcode_loadp(void) { if ((RM >= 0xF03000) && (RM <= 0xF03FFF)) { - gpu_hidata = GPUReadLong((RM & 0xFFFFFFF8) + 0, GPU); - RN = GPUReadLong((RM & 0xFFFFFFF8) + 4, GPU); + RN = GPUReadLong(RM & 0xFFFFFFFC, GPU); } else { diff --git a/waterbox/virtualjaguar/src/gpu.h b/waterbox/virtualjaguar/src/gpu.h index 2d24715ffb..5c125805fe 100644 --- a/waterbox/virtualjaguar/src/gpu.h +++ b/waterbox/virtualjaguar/src/gpu.h @@ -25,8 +25,7 @@ void GPUWriteByte(uint32_t offset, uint8_t data, uint32_t who = UNKNOWN); void GPUWriteWord(uint32_t offset, uint16_t data, uint32_t who = UNKNOWN); void GPUWriteLong(uint32_t offset, uint32_t data, uint32_t who = UNKNOWN); -uint32_t GPUGetPC(void); -uint32_t GPUReadPC(void); +bool GPURunning(void); // GPU interrupt numbers (from $F00100, bits 4-8)