X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=gp2x%2F940ctl.c;h=a9279139e6d87de8082bb63467ce38a38430bca7;hb=4b8f4f3c0d614637f1ec6df36330b1ad7a32b498;hp=f2e98a9954ecb47240703bb5e7f5a2984678f69f;hpb=79cad122559536a7831b121c5ec798847102d0de;p=libpicofe.git diff --git a/gp2x/940ctl.c b/gp2x/940ctl.c index f2e98a9..a927913 100644 --- a/gp2x/940ctl.c +++ b/gp2x/940ctl.c @@ -1,3 +1,6 @@ +// Code for communication with ARM940 and control of it. +// (c) Copyright 2007, Grazvydas "notaz" Ignotas + #include #include #include @@ -11,9 +14,12 @@ #include "gp2x.h" #include "emu.h" #include "menu.h" -#include "asmutils.h" -#include "mp3.h" +#include "../common/mp3.h" +#include "../common/arm_utils.h" +#include "../common/menu.h" +#include "../common/emu.h" #include "../../Pico/PicoInt.h" +#include "../../Pico/sound/ym2612.h" #include "../../Pico/sound/mix.h" /* we will need some gp2x internals here */ @@ -26,7 +32,8 @@ static _940_data_t *shared_data = 0; _940_ctl_t *shared_ctl = 0; unsigned char *mp3_mem = 0; -#define MP3_SIZE_MAX (0x1000000 - 4*640*480) +#define MP3_SIZE_MAX (0x400000 + 0x800000) // 12M +#define CODE940_FILE "pico940.bin" int crashed_940 = 0; @@ -46,11 +53,10 @@ static FILE *loaded_mp3 = 0; /* these will be managed locally on our side */ extern int *ym2612_dacen; extern INT32 *ym2612_dacout; -extern void *ym2612_regs; - static UINT8 *REGS = 0; /* we will also keep local copy of regs for savestates and such */ -static INT32 addr_A1; /* address line A1 */ -static int dacen; +static INT32 *addr_A1; /* address line A1 */ + +static int dacen; static INT32 dacout; static UINT8 ST_address; /* address register */ static UINT8 ST_status; /* status flag */ @@ -108,19 +114,19 @@ int YM2612Write_940(unsigned int a, unsigned int v) switch( a ) { case 0: /* address port 0 */ - if (!addr_A1 && ST_address == v) + if (!*addr_A1 && ST_address == v) return 0; /* address already selected, don't send this command to 940 */ ST_address = v; /* don't send DAC or timer related address changes to 940 */ - if (!addr_A1 && (v & 0xf0) == 0x20 && + if (!*addr_A1 && (v & 0xf0) == 0x20 && (v == 0x24 || v == 0x25 || v == 0x26 || v == 0x2a)) return 0; - addr_A1 = 0; + *addr_A1 = 0; upd = 0; break; case 1: /* data port 0 */ - if (addr_A1 != 0) { + if (*addr_A1 != 0) { return 0; /* verified on real YM2608 */ } @@ -179,15 +185,15 @@ int YM2612Write_940(unsigned int a, unsigned int v) break; case 2: /* address port 1 */ - if (addr_A1 && ST_address == v) + if (*addr_A1 && ST_address == v) return 0; ST_address = v; - addr_A1 = 1; + *addr_A1 = 1; upd = 0; break; case 3: /* data port 1 */ - if (addr_A1 != 1) { + if (*addr_A1 != 1) { return 0; /* verified on real YM2608 */ } @@ -285,7 +291,7 @@ static void wait_busy_940(int job) gp2x_memregs[0x3b46>>1], gp2x_memregl[0x4500>>2], gp2x_memregl[0x4510>>2]); printf("last lr: %08x, lastjob: %i\n", shared_ctl->last_lr, shared_ctl->lastjob); - strcpy(menuErrorMsg, "940 crashed."); + strcpy(menuErrorMsg, "940 crashed, too much overclock?"); engineState = PGS_Menu; crashed_940 = 1; } @@ -308,7 +314,13 @@ static void add_job_940(int job) void YM2612PicoStateLoad_940(void) { - int i, old_A1 = addr_A1; + int i, old_A1 = *addr_A1; + + /* make sure JOB940_PICOSTATELOAD gets done before next JOB940_YM2612UPDATEONE */ + add_job_940(JOB940_PICOSTATELOAD); + if (CHECK_BUSY(JOB940_PICOSTATELOAD)) wait_busy_940(JOB940_PICOSTATELOAD); + + writebuff_ptr = 0; // feed all the registers and update internal state for(i = 0; i < 0x100; i++) { @@ -320,9 +332,7 @@ void YM2612PicoStateLoad_940(void) YM2612Write_940(3, REGS[i|0x100]); } - addr_A1 = old_A1; - -// add_job_940(JOB940_PICOSTATELOAD); + *addr_A1 = old_A1; } @@ -335,7 +345,9 @@ static void internal_reset(void) ST_TAC = 0; ST_TB = 0; ST_TBC = 0; - dacen = 0; + dacen = 0; + dacout = 0; + ST_address= 0; } @@ -353,7 +365,7 @@ void sharedmem_init(void) shared_data = (_940_data_t *) (shared_mem+0x100000); /* this area must not get buffered on either side */ shared_ctl = (_940_ctl_t *) (shared_mem+0x200000); - mp3_mem = (unsigned char *) mmap(0, MP3_SIZE_MAX, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x3000000); + mp3_mem = (unsigned char *) mmap(0, MP3_SIZE_MAX, PROT_READ|PROT_WRITE, MAP_SHARED, memdev, 0x2400000); if (mp3_mem == MAP_FAILED) { printf("mmap(mp3_mem) failed with %i\n", errno); @@ -402,15 +414,15 @@ void YM2612Init_940(int baseclock, int rate) binpath[1023] = 0; for (i = strlen(binpath); i > 0; i--) if (binpath[i] == '/') { binpath[i] = 0; break; } - strcat(binpath, "/code940.bin"); + strcat(binpath, "/" CODE940_FILE); fp = fopen(binpath, "rb"); if(!fp) { - memset(gp2x_screen, 0, 320*240); - gp2x_text_out8(10, 100, "failed to open required file:"); - gp2x_text_out8(10, 110, "code940.bin"); - gp2x_video_flip(); + memset(gp2x_screen, 0, 320*240*2); + text_out16(10, 100, "failed to open required file:"); + text_out16(10, 110, CODE940_FILE); + gp2x_video_flip2(); printf("failed to open %s\n", binpath); exit(1); } @@ -430,7 +442,11 @@ void YM2612Init_940(int baseclock, int rate) memset(shared_data, 0, sizeof(*shared_data)); memset(shared_ctl, 0, sizeof(*shared_ctl)); + /* cause local ym2612 to init REGS */ + YM2612Init_(baseclock, rate); + REGS = YM2612GetRegs(); + addr_A1 = (INT32 *) (REGS + 0x200); ym2612_dacen = &dacen; ym2612_dacout = &dacout; @@ -517,9 +533,8 @@ void mp3_update(int *buffer, int length, int stereo) int length_mp3; int cdda_on; - // not data track, CDC is reading, playback was started, track not ended - cdda_on = !(Pico_mcd->s68k_regs[0x36] & 1) && (Pico_mcd->scd.Status_CDC & 1) && - loaded_mp3 && shared_ctl->mp3_offs < shared_ctl->mp3_len; + // playback was started, track not ended + cdda_on = loaded_mp3 && shared_ctl->mp3_offs < shared_ctl->mp3_len; if (!cdda_on) return; @@ -592,7 +607,6 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023 if (loaded_mp3 != f) { - // printf("loading mp3... "); fflush(stdout); if (PicoMessage != NULL) { fseek(f, 0, SEEK_END); @@ -601,8 +615,7 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023 } fseek(f, 0, SEEK_SET); fread(mp3_mem, 1, MP3_SIZE_MAX, f); - // if (feof(f)) printf("done.\n"); - // else printf("done. mp3 too large, not all data loaded.\n"); + if (!feof(f)) printf("Warning: mp3 was too large, not all data loaded.\n"); shared_ctl->mp3_len = ftell(f); loaded_mp3 = f; @@ -635,7 +648,7 @@ void mp3_start_play(FILE *f, int pos) // pos is 0-1023 int mp3_get_offset(void) { - int offs1024 = 0; + unsigned int offs1024 = 0; int cdda_on; cdda_on = (PicoMCD & 1) && (PicoOpt&0x800) && !(Pico_mcd->s68k_regs[0x36] & 1) && @@ -643,10 +656,9 @@ int mp3_get_offset(void) if (cdda_on) { offs1024 = shared_ctl->mp3_offs << 7; - offs1024 /= shared_ctl->mp3_len; - offs1024 <<= 3; + offs1024 /= shared_ctl->mp3_len >> 3; } - printf("offs1024=%i (%i/%i)\n", offs1024, shared_ctl->mp3_offs, shared_ctl->mp3_len); + printf("offs1024=%u (%i/%i)\n", offs1024, shared_ctl->mp3_offs, shared_ctl->mp3_len); return offs1024; }