From 80db44425aa5b46185fb9a64520f4b6f5d494ba5 Mon Sep 17 00:00:00 2001 From: notaz Date: Sat, 27 Oct 2007 20:04:36 +0000 Subject: [PATCH] various bugfixes git-svn-id: file:///home/notaz/opt/svn/PicoDrive@282 be3aeb3a-fb24-0410-a615-afba39da0efa --- Pico/Misc.c | 2 +- cpu/DrZ80/drz80.s | 1 - cpu/cz80/cz80.c | 5 ++- cpu/fame/famec.c | 75 +++++++++++----------------------------- cpu/fame/famec_opcodes.h | 28 +++++++-------- platform/linux/Makefile | 20 +++++++---- platform/psp/emu.c | 34 +++++++++--------- platform/psp/menu.c | 16 ++++----- 8 files changed, 77 insertions(+), 104 deletions(-) diff --git a/Pico/Misc.c b/Pico/Misc.c index a458f4de..a092b93b 100644 --- a/Pico/Misc.c +++ b/Pico/Misc.c @@ -330,7 +330,7 @@ typedef struct PICO_INTERNAL_ASM void memcpy16(unsigned short *dest, unsigned short *src, int count) { - if (((int)dest & (int)src & 3) == 0) + if ((((int)dest | (int)src) & 3) == 0) { if (count >= 32) { memcpy32((int *)dest, (int *)src, count/2); diff --git a/cpu/DrZ80/drz80.s b/cpu/DrZ80/drz80.s index 16f09afb..5a4801ac 100644 --- a/cpu/DrZ80/drz80.s +++ b/cpu/DrZ80/drz80.s @@ -1459,7 +1459,6 @@ DoInterrupt: bne DoInterrupt_mode1 tst r1,#2 bne DoInterrupt_mode2 - b DoInterrupt_mode0 DoInterrupt_mode0: ;@ get 3 byte vector diff --git a/cpu/cz80/cz80.c b/cpu/cz80/cz80.c index bcff740a..f2ab0032 100644 --- a/cpu/cz80/cz80.c +++ b/cpu/cz80/cz80.c @@ -248,7 +248,10 @@ Cz80_Exec: { afterEI = 0; Cz80_Check_Interrupt: - CHECK_INT + if (CPU->IRQState != CLEAR_LINE) + { + CHECK_INT + } goto Cz80_Exec; } } diff --git a/cpu/fame/famec.c b/cpu/fame/famec.c index 8c71c079..474fa948 100644 --- a/cpu/fame/famec.c +++ b/cpu/fame/famec.c @@ -306,44 +306,38 @@ static u32 flag_I; #define POST_IO \ // CCnt = io_cycle_counter; -#ifndef FAME_BIG_ENDIAN +#define READ_BYTE_F(A, D) \ + D = m68kcontext.read_byte(A) & 0xFF; + +#define READ_WORD_F(A, D) \ + D = m68kcontext.read_word(A) & 0xFFFF; - #define READ_BYTE_F(A, D) \ - D = m68kcontext.read_byte(A) & 0xFF; +#define READ_LONG_F(A, D) \ + D = m68kcontext.read_long(A); - #define READ_WORD_F(A, D) \ - D = m68kcontext.read_word(A) & 0xFFFF; +#define READSX_LONG_F READ_LONG_F - #define READ_LONG_F(A, D) \ - D = m68kcontext.read_word((A)) << 16; \ - D |= m68kcontext.read_word((A) + 2) & 0xFFFF; +#define WRITE_LONG_F(A, D) \ + m68kcontext.write_long(A, D); - #define READSX_LONG_F(A, D) \ - D = m68kcontext.read_word((A)) << 16; \ - D |= m68kcontext.read_word((A) + 2) & 0xFFFF; +#define WRITE_LONG_DEC_F(A, D) \ + m68kcontext.write_word((A) + 2, (D) & 0xFFFF); \ + m68kcontext.write_word((A), (D) >> 16); - #define WRITE_LONG_F(A, D) \ - m68kcontext.write_word((A), (D) >> 16); \ - m68kcontext.write_word((A) + 2, (D) & 0xFFFF); +#define PUSH_32_F(D) \ + AREG(7) -= 4; \ + m68kcontext.write_long(AREG(7), D); - #define WRITE_LONG_DEC_F(A, D) \ - m68kcontext.write_word((A), (D) >> 16); \ - m68kcontext.write_word((A) + 2, (D) & 0xFFFF); +#define POP_32_F(D) \ + D = m68kcontext.read_long(AREG(7)); \ + AREG(7) += 4; + +#ifndef FAME_BIG_ENDIAN #define FETCH_LONG(A) \ (A) = PC[1] | (PC[0] << 16); \ PC += 2; - #define PUSH_32_F(D) \ - AREG(7) -= 4; \ - m68kcontext.write_word(AREG(7), (D) >> 16); \ - m68kcontext.write_word(AREG(7) + 2, (D) & 0xFFFF); - - #define POP_32_F(D) \ - D = m68kcontext.read_word(AREG(7)) << 16; \ - D |= m68kcontext.read_word(AREG(7) + 2) & 0xFFFF; \ - AREG(7) += 4; - #define GET_SWORD \ (s16)(*PC) @@ -372,37 +366,10 @@ static u32 flag_I; #else - #define READ_BYTE_F(A, D) \ - D = m68kcontext.read_byte(A) & 0xFF; - - #define READ_WORD_F(A, D) \ - D = m68kcontext.read_word(A) & 0xFFFF; - - #define READ_LONG_F(A, D) \ - D = m68kcontext.read_long(A); - - #define READSX_LONG_F(A, D) \ - D = m68kcontext.read_long(A); - - #define WRITE_LONG_F(A, D) \ - m68kcontext.write_long(A, D); - - #define WRITE_LONG_DEC_F(A, D) \ - m68kcontext.write_word((A) + 2, (D) >> 16); \ - m68kcontext.write_word((A), (D) & 0xFFFF); - #define FETCH_LONG(A) \ (A) = PC[0] | (PC[1] << 16); \ PC += 2; - #define PUSH_32_F(D) \ - AREG(7) -= 4; \ - m68kcontext.write_long(AREG(7), D); - - #define POP_32_F(D) \ - D = m68kcontext.read_long(AREG(7)); \ - AREG(7) += 4; - #define GET_SWORD \ ((s16)(((*PC & 0xFF) << 8) | (*PC >> 8))) diff --git a/cpu/fame/famec_opcodes.h b/cpu/fame/famec_opcodes.h index de1ce170..215dbd60 100644 --- a/cpu/fame/famec_opcodes.h +++ b/cpu/fame/famec_opcodes.h @@ -8167,7 +8167,7 @@ OPCODE(0x2100) adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; PRE_IO - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(12) } @@ -8350,7 +8350,7 @@ OPCODE(0x2108) adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; PRE_IO - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(12) } @@ -8539,7 +8539,7 @@ OPCODE(0x2110) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(20) } @@ -8738,7 +8738,7 @@ OPCODE(0x2118) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(20) } @@ -8943,7 +8943,7 @@ OPCODE(0x2120) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(22) } @@ -9148,7 +9148,7 @@ OPCODE(0x2128) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(24) } @@ -9353,7 +9353,7 @@ OPCODE(0x2130) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(26) } @@ -9554,7 +9554,7 @@ OPCODE(0x2138) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(24) } @@ -9749,7 +9749,7 @@ OPCODE(0x2139) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(28) } @@ -9948,7 +9948,7 @@ OPCODE(0x213A) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(24) } @@ -10153,7 +10153,7 @@ OPCODE(0x213B) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(26) } @@ -10348,7 +10348,7 @@ OPCODE(0x213C) adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; PRE_IO - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(20) } @@ -10541,7 +10541,7 @@ OPCODE(0x211F) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(20) } @@ -10746,7 +10746,7 @@ OPCODE(0x2127) flag_N = res >> 24; adr = AREG((Opcode >> 9) & 7) - 4; AREG((Opcode >> 9) & 7) = adr; - WRITE_LONG_F(adr, res) + WRITE_LONG_DEC_F(adr, res) POST_IO RET(22) } diff --git a/platform/linux/Makefile b/platform/linux/Makefile index 6aed56e1..90a149c6 100644 --- a/platform/linux/Makefile +++ b/platform/linux/Makefile @@ -1,6 +1,7 @@ # settings -use_fame = 1 +#use_musashi = 1 +#use_mz80 = 1 # profile = 1 @@ -47,16 +48,21 @@ OBJS += ../../zlib/gzio.o ../../zlib/inffast.o ../../zlib/inflate.o ../../zlib/i # unzip OBJS += ../../unzip/unzip.o ../../unzip/unzip_stream.o # CPU cores -ifeq "$(use_fame)" "1" -DEFINC += -DEMU_F68K -OBJS += ../../cpu/fame/famec.o -else +ifeq "$(use_musashi)" "1" DEFINC += -DEMU_M68K OBJS += ../../cpu/musashi/m68kops.o ../../cpu/musashi/m68kcpu.o +else +DEFINC += -DEMU_F68K +OBJS += ../../cpu/fame/famec.o endif -# mz80 -DEFINC += -D_USE_MZ80 +# z80 +ifeq "$(use_mz80)" "1" +CFLAGS += -D_USE_MZ80 OBJS += ../../cpu/mz80/mz80.o +else +CFLAGS += -D_USE_CZ80 +OBJS += ../../cpu/cz80/cz80.o +endif # faked asm #DEFINC += -D_ASM_DRAW_C diff --git a/platform/psp/emu.c b/platform/psp/emu.c index d2eaca78..0ecbcc66 100644 --- a/platform/psp/emu.c +++ b/platform/psp/emu.c @@ -206,13 +206,15 @@ static void set_scaling_params(void) if (fbimg_yoffs < 0) fbimg_yoffs = 0; fbimg_offs = (fbimg_yoffs*512 + fbimg_xoffs) * 2; // dst is always 16bit + /* lprintf("set_scaling_params:\n"); lprintf("offs: %i, %i\n", fbimg_xoffs, fbimg_yoffs); lprintf("xy0, xy1: %i, %i; %i, %i\n", g_vertices[0].x, g_vertices[0].y, g_vertices[1].x, g_vertices[1].y); lprintf("uv0, uv1: %i, %i; %i, %i\n", g_vertices[0].u, g_vertices[0].v, g_vertices[1].u, g_vertices[1].v); + */ } -static void do_slowmode_pal(void) +static void do_pal_update(int allow_sh) { unsigned int *spal=(void *)Pico.cram; unsigned int *dpal=(void *)localPal; @@ -221,11 +223,11 @@ static void do_slowmode_pal(void) for (i = 0x3f/2; i >= 0; i--) dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4); - if (Pico.video.reg[0xC]&8) // shadow/hilight? + if (allow_sh && (Pico.video.reg[0xC]&8)) // shadow/hilight? { // shadowed pixels for (i = 0x3f/2; i >= 0; i--) - dpal[0x20|i] = dpal[0x60|i] = (spal[i]>>1)&0x738e738e; + dpal[0x20|i] = dpal[0x60|i] = (dpal[i]>>1)&0x738e738e; // hilighted pixels for (i = 0x3f; i >= 0; i--) { int t=localPal[i]&0xe71c;t+=0x4208; @@ -259,7 +261,7 @@ static void EmuScanPrepare(void) dynamic_palette = 0; if (Pico.m.dirtyPal) - do_slowmode_pal(); + do_pal_update(1); } static int EmuScanSlow(unsigned int num, void *sdata) @@ -271,7 +273,7 @@ static int EmuScanSlow(unsigned int num, void *sdata) do_slowmode_lines(num); dynamic_palette = 1; } - do_slowmode_pal(); + do_pal_update(1); } if (dynamic_palette) { @@ -289,8 +291,6 @@ static void blitscreen_clut(void) int offs = fbimg_offs; offs += (psp_screen == VRAM_FB0) ? VRAMOFFS_FB0 : VRAMOFFS_FB1; - sceKernelDcacheWritebackAll(); - sceGuSync(0,0); // sync with prev sceGuStart(GU_DIRECT, guCmdList); sceGuDrawBuffer(GU_PSM_5650, (void *)offs, 512); // point to back buffer @@ -314,14 +314,9 @@ static void blitscreen_clut(void) } if ((PicoOpt&0x10) && Pico.m.dirtyPal) - { - int i, *dpal = (void *)localPal, *spal = (int *)Pico.cram; - for (i = 0x3f/2; i >= 0; i--) - dpal[i] = ((spal[i]&0x000f000f)<< 1)|((spal[i]&0x00f000f0)<<3)|((spal[i]&0x0f000f00)<<4); - localPal[0xe0] = 0; - Pico.m.dirtyPal = 0; - need_pal_upload = 1; - } + do_pal_update(0); + + sceKernelDcacheWritebackAll(); if (need_pal_upload) { need_pal_upload = 0; @@ -577,7 +572,8 @@ static void sound_prepare(void) static void sound_end(void) { - while (samples_made - samples_done >= samples_block || sceAudioOutput2GetRestSample() > 0) + samples_made = samples_done = 0; + while (sceAudioOutput2GetRestSample() > 0) psp_msleep(100); sceAudio_5C37C0AE(); } @@ -586,6 +582,8 @@ static void sound_deinit(void) { sound_thread_exit = 1; sceKernelSignalSema(sound_sem, 1); + sceKernelDeleteSema(sound_sem); + sound_sem = -1; } static void writeSound(int len) @@ -998,8 +996,8 @@ void emu_Loop(void) SRam.changed = 0; } - // draw a frame for bg.. - emu_forcedFrame(); + // clear fps counters and stuff + memset32((int *)psp_video_get_active_fb() + 512*264*2/4, 0, 512*8*2/4); } diff --git a/platform/psp/menu.c b/platform/psp/menu.c index 573e5f30..32c41152 100644 --- a/platform/psp/menu.c +++ b/platform/psp/menu.c @@ -43,7 +43,7 @@ static unsigned short bg_buffer[480*272] __attribute__((aligned(16))); #define menu_screen psp_screen static void menu_darken_bg(void *dst, const void *src, int pixels, int darker); -static void menu_prepare_bg(int use_game_bg); +static void menu_prepare_bg(int use_game_bg, int use_fg); static unsigned int inp_prev = 0; @@ -190,10 +190,10 @@ static void draw_dirlist(char *curdir, struct my_dirent **namelist, int n, int s if (pos > 26) break; if (namelist[i+1]->d_type & DT_DIR) { smalltext_out16_lim(14, pos*10, "/", 0xd7ff, 1); - smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xd7ff, 53-3); + smalltext_out16_lim(14+6, pos*10, namelist[i+1]->d_name, 0xd7ff, 80-3); } else { unsigned short color = file2color(namelist[i+1]->d_name); - smalltext_out16_lim(14, pos*10, namelist[i+1]->d_name, color, 53-2); + smalltext_out16_lim(14, pos*10, namelist[i+1]->d_name, color, 80-2); } } text_out16(5, 130, ">"); @@ -552,7 +552,7 @@ static void draw_savestate_bg(int slot) } emu_forcedFrame(); - menu_prepare_bg(1); + menu_prepare_bg(1, 0); restore_oldstate(oldstate); } @@ -1016,7 +1016,7 @@ static void menu_opt3_preview(int is_32col) memset32(psp_screen, 0, 512*272*2/4); emu_forcedFrame(); - menu_prepare_bg(1); + menu_prepare_bg(1, 0); if (oldstate) restore_oldstate(oldstate); } @@ -1655,13 +1655,13 @@ static void menu_darken_bg(void *dst, const void *src, int pixels, int darker) } } -static void menu_prepare_bg(int use_game_bg) +static void menu_prepare_bg(int use_game_bg, int use_fg) { if (use_game_bg) { // darken the active framebuffer unsigned short *dst = bg_buffer; - unsigned short *src = psp_screen; + unsigned short *src = use_fg ? psp_video_get_active_fb() : psp_screen; int i; for (i = 272; i > 0; i--, dst += 480, src += 512) menu_darken_bg(dst, src, 480, 1); @@ -1678,7 +1678,7 @@ static void menu_prepare_bg(int use_game_bg) static void menu_gfx_prepare(void) { - menu_prepare_bg(rom_data != NULL); + menu_prepare_bg(rom_data != NULL, 1); menu_draw_begin(); menu_draw_end(); -- 2.39.5