From 0031c06df2f7f099ca5ecf1632f46b92f6b0dd79 Mon Sep 17 00:00:00 2001 From: Neils Wagenaar Date: Tue, 8 Jul 2003 19:09:53 +0000 Subject: [PATCH] This commit was generated by cvs2svn to compensate for changes in r8, which included commits to RCS files with non-trunk default branches. --- INSTALL | 17 +- Makefile.win32 | 4 +- docs/WHATSNEW | 13 + src/Jagem.cpp | 193 +++--- src/anajoy.cpp | 64 +- src/blitter.cpp | 202 +++--- src/cdbios.cpp | 346 ++-------- src/cdi.cpp | 180 ++--- src/cdrom.cpp | 140 ++-- src/clock.cpp | 67 +- src/crc32.cpp | 49 +- src/dsound_dummy.cpp | 64 +- src/dsp.cpp | 921 +++----------------------- src/eeprom.cpp | 543 +++++++-------- src/gpu.cpp | 1390 +++++++++++++++------------------------ src/include/SDLptc.h | 3 +- src/include/fbmpop16.h | 136 ++-- src/include/jaguar.h | 5 + src/include/types.h | 4 - src/include/wavetable.h | 2 +- src/jagdasm.cpp | 38 +- src/jaguar.cpp | 267 +++----- src/jerry.cpp | 733 +++++++++------------ src/joystick.cpp | 297 ++++----- src/log.cpp | 61 +- src/memory.cpp | 222 +++---- src/objectp.cpp | 634 +++++++++--------- src/pcm.cpp | 204 ++---- src/tom.cpp | 100 +-- src/version.cpp | 54 +- 30 files changed, 2408 insertions(+), 4545 deletions(-) diff --git a/INSTALL b/INSTALL index 340239a..28cd958 100644 --- a/INSTALL +++ b/INSTALL @@ -1,4 +1,4 @@ -Virtual Jaguar v1.0.0 GCC/SDL release INSTALL +Virtual Jaguar v1.0.3 GCC/SDL release INSTALL --------------------------------------------- - Requirements : @@ -26,20 +26,15 @@ The .o's can be quite big and the binary is likely to be about a If you sure you have the minimum software requirements, you can safely compile Virtual Jaguar v1.0.0 GCC/SDL release by doing the following : -1) On UN*X systems first do the command : sh ./fix-unix.sh -2) Go to the src/star026c directory and start on of the scripts : - - ./build_s68000.win32 (for WIN32 systems with mingw) - ./build_s68000.unix (for UN*X systems with gcc) - -3) After the generation of the 68000.o file, you can now compile the - program with the following commands : +1) Compile: make -f Makefile.win32 (for WIN32 systems with mingw) make -f Makefile.unix (for UN*X systems with gcc) -4) Optionally you can manually strip jag_em[.exe] to downsize the binary. +2) Optionally you can manually strip jag_em[.exe] to downsize the binary. +If you don't have upx in your path somewhere, you can ignore the error +message that make throws at you about not being able to find upx. That's it! You're done! You can now start the emulator with ./jag_em[.exe]. See the output for more details or consult the docs/README for more info. @@ -48,5 +43,3 @@ For more info, go to http://sdlemu.ngemu.com or send use an e-mail to the following e-mail address : sdlemu AT ngemu DOT com. SDLEMU - - diff --git a/Makefile.win32 b/Makefile.win32 index bc318d9..d1311b3 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -3,8 +3,8 @@ LD = gcc NASM = nasm CFLAGS = -Wall -O3 -D__PORT__ -D__GCCWIN32__ -Dstricmp="strcasecmp" \ - -fomit-frame-pointer `sdl-config --cflags` -# -fomit-frame-pointer `sdl-config --cflags` -DCPU_DEBUG + -fomit-frame-pointer `sdl-config --cflags` -DLOG_UNMAPPED_MEMORY_ACCESSES +# -fomit-frame-pointer `sdl-config --cflags` # -fomit-frame-pointer `sdl-config --cflags` -DTOM_DEBUG LDFLAGS = $(CFLAGS) diff --git a/docs/WHATSNEW b/docs/WHATSNEW index 2e768ee..89824e1 100644 --- a/docs/WHATSNEW +++ b/docs/WHATSNEW @@ -1,3 +1,16 @@ +Virtual Jaguar v1.0.3 GCC/SDL - source only release +------------------------------------------------------ + +* Converted GNU assembly in the GPU core to C code -- Rayman and + Alien vs Predator work again. :-) +* Removed closed source Starscream and replaced it with the open source + Musashi core. Because of this, VJ runs a little faster now. :-) +* Various cleanups to the source files (still lots of work to do!) + +NOTE: Tested only on WIN32 platform! + +1.0.1 - 1.0.2 - Unreleased, mostly for testing/finding bugs + Virtual Jaguar v1.0.0 GCC/SDL - initial source release ------------------------------------------------------ diff --git a/src/Jagem.cpp b/src/Jagem.cpp index 95e79a9..c03572c 100644 --- a/src/Jagem.cpp +++ b/src/Jagem.cpp @@ -1,14 +1,11 @@ -//////////////////////////////////////////////////////////////////////////////// // -//////////////////////////////////////////////////////////////////////////////// +// Virtual Jaguar Emulator // +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons // -// -// -// -// -// -//////////////////////////////////////////////////////////////////////////////// + #ifndef __PORT__ #include "stdafx.h" #include @@ -54,28 +51,27 @@ void main_screen_switch(void) int main(int argc, char * argv[]) { - - uint32 startTime, totalFrames, endTime, w, h; - int32 *vs; - unsigned int nNormalLast = 0; - int nNormalFrac = 0; - int i = 0; - int nTime = 0; - int nCount = 0; - int nFrameskip = 1; /* Frameskip */ - int nFrame = 0; /* No. of Frame */ - int nJoyport = 0; /* Joystick port */ + uint32 startTime, totalFrames;//, endTime;//, w, h; +// int32 * vs; + uint32 nNormalLast = 0; + int32 nNormalFrac = 0; +// int32 i = 0; +//unused int32 nTime = 0; +//unused int32 nCount = 0; + int32 nFrameskip = 1; // Frameskip + int32 nFrame = 0; // No. of Frame + int32 nJoyport = 0; // Joystick port printf("Virtual Jaguar/SDL v1.0.1 (GCC/SDL Port)\n"); printf("Based upon Virtual Jaguar core v1.0.0 by Potato emulation.\n"); printf("Written by Niels Wagenaar (Linux/WIN32) and Caz (BeOS)\n"); printf("Portions massaged by James L. Hammons (WIN32)\n"); - printf("Contact : http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"); + printf("Contact: http://sdlemu.ngemu.com/ | sdlemu@ngemu.com\n"); if (argc <= 1) { printf("Usage : \n\n"); - printf("jag_em [switches] ]\n"); + printf("jag_em [switches]\n"); printf(" -fullscreen : Enable fullscreen mode \n"); printf(" -window : Enable windowed mode (default) \n"); printf(" -frameskip 1-10 : Enable frameskip 1 (default) - 10\n"); @@ -84,8 +80,8 @@ int main(int argc, char * argv[]) return true; } - jaguar_boot_dir=(char*)malloc(1024); - getcwd(jaguar_boot_dir,1024); + jaguar_boot_dir = (char *)malloc(1024); + getcwd(jaguar_boot_dir, 1024); log_init("jag_em.log"); @@ -95,137 +91,136 @@ int main(int argc, char * argv[]) jaguar_init(argv[1]); jaguar_reset(); - /* Setting up the backbuffer */ - int16 *backbuffer=(int16*)malloc(845*525*sizeof(int16)); - memset(backbuffer,0xaa,tom_getVideoModeWidth()*tom_getVideoModeHeight()*sizeof(int16)); + /* Setting up the backbuffer */ + int16 * backbuffer = (int16 *)malloc(845 * 525 * sizeof(int16)); + memset(backbuffer, 0xAA, tom_getVideoModeWidth() * tom_getVideoModeHeight() * sizeof(int16)); /* Setting up the primary SDL display */ - Format format(16,0x007c00,0x00003e0,0x0000001f); - surface=new Surface(tom_getVideoModeWidth(),tom_getVideoModeHeight(), format); +//Already defined! Format format(16, 0x007C00, 0x00003E0, 0x0000001F); + surface = new Surface(tom_getVideoModeWidth(), tom_getVideoModeHeight(), format); console.option("windowed output"); - /* Checking the switches ;) */ - for(i = 0; (i < argc || argv[i] != NULL); i++) + /* Checking the switches ;) */ + for(int i=0; (i 3) nJoyport = 3; - } + if (!strcmp(argv[i], "-joyport")) + { + nJoyport = atoi(argv[++i]) + 1; + if (nJoyport > 3) + nJoyport = 3; + } - if(!strcmp(argv[i], "-frameskip")) - { - nFrameskip = atoi(argv[++i]) + 1; - if(nFrameskip > 10) nFrameskip = 10; + if (!strcmp(argv[i], "-frameskip")) + { + nFrameskip = atoi(argv[++i]) + 1; + if (nFrameskip > 10) + nFrameskip = 10; #ifdef SPEED_CONTROL nFrameskip = 0; #endif } - - - } - /* Initialize Joystick support under SDL */ - if ( console.JoyEnabled() == 1 ) { - - if(SDL_NumJoysticks() <= 0) + if (console.JoyEnabled() == 1) { - console.option("joystick disabled"); - printf("No joystick(s) or joypad(s) detected on your system. Using keyboards....\n"); - } - else { - if((console.joystick = SDL_JoystickOpen(nJoyport)) == 0) - { - console.option("joystick disabled"); - printf("Unable to open a Joystick on port : %d\n", nJoyport); - } - else - printf("Using: %s\n", SDL_JoystickName(nJoyport)); - } + if (SDL_NumJoysticks() <= 0) + { + console.option("joystick disabled"); + printf("No joystick(s) or joypad(s) detected on your system. Using keyboards....\n"); + } + else + { + if ((console.joystick = SDL_JoystickOpen(nJoyport)) == 0) + { + console.option("joystick disabled"); + printf("Unable to open a Joystick on port : %d\n", (int)nJoyport); + } + else + printf("Using: %s\n", SDL_JoystickName(nJoyport)); + } } /* Open the display and start emulating some l337 Atari Jaguar games :P */ - console.open("Virtual Jaguar",tom_getVideoModeWidth(),tom_getVideoModeHeight(),format); - + console.open("Virtual Jaguar", tom_getVideoModeWidth(), tom_getVideoModeHeight(), format); - totalFrames=0; - startTime=clock(); - nNormalLast=0;// Last value of timeGetTime() - nNormalFrac=0; // Extra fraction we did + totalFrames = 0; + startTime = clock(); + nNormalLast = 0; // Last value of timeGetTime() + nNormalFrac = 0; // Extra fraction we did + nNormalLast = SDL_GetTicks(); //timeGetTime(); - nNormalLast=SDL_GetTicks();//timeGetTime(); while (!finished) { #ifdef SPEED_CONTROL - nTime=SDL_GetTicks()-nNormalLast; // calcule le temps écoulé depuis le dernier affichage - // nTime est en mili-secondes. + nTime = SDL_GetTicks() - nNormalLast; // calcule le temps écoulé depuis le dernier affichage + // nTime est en mili-secondes. // détermine le nombre de trames à passer + 1 - nCount=(nTime*600 - nNormalFrac) /10000; + nCount = (nTime * 600 - nNormalFrac) / 10000; // si le nombre de trames à passer + 1 est nul ou négatif, // ne rien faire pendant 2 ms - if (nCount<=0) + if (nCount <= 0) { //Sleep(2); //SDL_Delay(1); } // No need to do anything for a bit else { - nNormalFrac+=nCount*10000; // - nNormalLast+=nNormalFrac/600; // add the duration of nNormalFrac frames - nNormalFrac%=600; // + nNormalFrac += nCount * 10000; // + nNormalLast += nNormalFrac / 600; // add the duration of nNormalFrac frames + nNormalFrac %= 600; // // Pas plus de 9 (10-1) trames non affichées - if (nCount>10) - nCount=10; - for (i=0;i 10) + nCount = 10; + for(int i=0; ilock(); - memcpy(vs,backbuffer,w*h*2); - surface->unlock(); - surface->copy(console); - console.update(); - nFrame = 0; + if (nFrame == nFrameskip) + { + int32 * vs = (int32 *)surface->lock(); + memcpy(vs, backbuffer, tom_width * tom_height * 2); + surface->unlock(); + surface->copy(console); + console.update(); + nFrame = 0; } - else - nFrame++; + else + nFrame++; + joystick_exec(); #ifdef SPEED_CONTROL } #endif } - int elapsedTime=clock()-startTime; - int fps=(1000*totalFrames)/elapsedTime; - printf("statistics: %i fps\n",fps); + + int elapsedTime = clock() - startTime; + int fps = (1000 * totalFrames) / elapsedTime; + fprintf(log_get(), "Statistics: %i fps\n", fps); - if ( console.JoyEnabled() == 1 ) {} + if (console.JoyEnabled() == 1) {} jaguar_done(); version_done(); memory_done(); log_done(); - console.close(); // Close SDL items as last! + console.close(); // Close SDL items as last! return 0; } diff --git a/src/anajoy.cpp b/src/anajoy.cpp index 9210817..adab2c4 100644 --- a/src/anajoy.cpp +++ b/src/anajoy.cpp @@ -1,73 +1,45 @@ +// +// Analog joystick handler +// +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons +// + #include "jaguar.h" static uint8 anajoy_ram[2]; static uint8 analog_x, analog_y; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void anajoy_init(void) { anajoy_reset(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void anajoy_reset(void) { memset(anajoy_ram,0x00,2); analog_x=128; analog_y=128; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void anajoy_done(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void anajoy_byte_write(uint32 offset, uint8 data) { anajoy_ram[offset&0x01]=data; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void anajoy_word_write(uint32 offset, uint16 data) { offset&=0x01; anajoy_ram[offset+0]=(data>>8)&0xff; anajoy_ram[offset+1]=data&0xff; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint8 anajoy_byte_read(uint32 offset) { if (anajoy_ram[1]&0x01) @@ -75,13 +47,7 @@ uint8 anajoy_byte_read(uint32 offset) else return(analog_x); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint16 anajoy_word_read(uint32 offset) { uint16 data=anajoy_byte_read((offset+0)&0x01); diff --git a/src/blitter.cpp b/src/blitter.cpp index aa5e46f..52a117a 100644 --- a/src/blitter.cpp +++ b/src/blitter.cpp @@ -1,3 +1,11 @@ +// +// Blitter core +// +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons +// + #define GEN_CODE //#define LOG_BLITS //#define USE_GENERIC_BLITTER @@ -1064,48 +1072,48 @@ void blitter_generic(uint32 cmd) void blitter_blit(uint32 cmd) { colour_index = 0; - src=(cmd&0x07); - dst=(cmd>>3)&0x07; - misc=(cmd>>6)&0x03; - a1ctl=(cmd>>8)&0x7; - mode=(cmd>>11)&0x07; - ity=(cmd>>14)&0x0f; - zop=(cmd>>18)&0x07; - op=(cmd>>21)&0x0f; - ctrl=(cmd>>25)&0x3f; - - a1_addr=REG(A1_BASE); - a2_addr=REG(A2_BASE); + src = cmd & 0x07; + dst = (cmd >> 3) & 0x07; + misc = (cmd >> 6) & 0x03; + a1ctl = (cmd >> 8) & 0x7; + mode = (cmd >> 11) & 0x07; + ity = (cmd >> 14) & 0x0F; + zop = (cmd >> 18) & 0x07; + op = (cmd >> 21) & 0x0F; + ctrl = (cmd >> 25) & 0x3F; + + a1_addr = REG(A1_BASE); + a2_addr = REG(A2_BASE); a1_zoffs = (REG(A1_FLAGS) >> 6) & 7; a2_zoffs = (REG(A2_FLAGS) >> 6) & 7; - xadd_a1_control=(REG(A1_FLAGS)>>16)&0x03; - xadd_a2_control=(REG(A2_FLAGS)>>16)&0x03; + xadd_a1_control = (REG(A1_FLAGS) >> 16) & 0x03; + xadd_a2_control = (REG(A2_FLAGS) >> 16) & 0x03; a1_pitch = (REG(A1_FLAGS) & 3) ^ ((REG(A1_FLAGS) & 2) >> 1); a2_pitch = (REG(A2_FLAGS) & 3) ^ ((REG(A2_FLAGS) & 2) >> 1); - n_pixels=(REG(PIXLINECOUNTER)&0xffff); - n_lines=((REG(PIXLINECOUNTER)>>16)&0xffff); + n_pixels = REG(PIXLINECOUNTER) & 0xFFFF; + n_lines = (REG(PIXLINECOUNTER) >> 16) & 0xFFFF; - a1_x=(REG(A1_PIXEL)<<16)|(REG(A1_FPIXEL)&0xffff); - a1_y=(REG(A1_PIXEL)&0xffff0000)|(REG(A1_FPIXEL)>>16); - a1_width=blitter_scanline_width[((REG(A1_FLAGS)&0x00007E00)>>9)]; + a1_x = (REG(A1_PIXEL) << 16) | (REG(A1_FPIXEL) & 0xFFFF); + a1_y = (REG(A1_PIXEL) & 0xFFFF0000) | (REG(A1_FPIXEL) >> 16); + a1_width = blitter_scanline_width[((REG(A1_FLAGS) & 0x00007E00) >> 9)]; - a2_x=(REG(A2_PIXEL)&0x0000ffff)<<16; - a2_y=(REG(A2_PIXEL)&0xffff0000); - a2_width=blitter_scanline_width[((REG(A2_FLAGS)&0x00007E00)>>9)]; - a2_mask_x=0xffff|((REG(A2_MASK)&0x0000ffff)<<16); - a2_mask_y=((REG(A2_MASK)&0xffff0000)|0xffff); + a2_x = (REG(A2_PIXEL) & 0x0000FFFF) << 16; + a2_y = (REG(A2_PIXEL) & 0xFFFF0000); + a2_width = blitter_scanline_width[((REG(A2_FLAGS) & 0x00007E00) >> 9)]; + a2_mask_x = 0xFFFF | ((REG(A2_MASK) & 0x0000FFFF) << 16); + a2_mask_y = ((REG(A2_MASK) & 0xFFFF0000) | 0xFFFF); // - if (!((REG(A2_FLAGS))&0x8000)) + if (!(REG(A2_FLAGS) & 0x8000)) { - a2_mask_x=0xffffffff; // must be 16.16 - a2_mask_y=0xffffffff; // must be 16.16 + a2_mask_x = 0xFFFFFFFF; // must be 16.16 + a2_mask_y = 0xFFFFFFFF; // must be 16.16 } - a1_phrase_mode=0; + a1_phrase_mode = 0; // determine a1_yadd if (YADD1_A1) @@ -1114,76 +1122,74 @@ void blitter_blit(uint32 cmd) a1_yadd = 0; if (YSIGNSUB_A1) - a1_yadd=-a1_yadd; + a1_yadd = -a1_yadd; // determine a1_xadd switch (xadd_a1_control) { case XADDPHR: - // add phrase offset to X and truncate - a1_xadd = 1 << 16; - - a1_phrase_mode=1; - break; + // add phrase offset to X and truncate + a1_xadd = 1 << 16; + a1_phrase_mode = 1; + break; case XADDPIX: - // add pixelsize (1) to X - a1_xadd = 1 << 16; - break; + // add pixelsize (1) to X + a1_xadd = 1 << 16; + break; case XADD0: - // add zero (for those nice vertical lines) - a1_xadd = 0; - break; + // add zero (for those nice vertical lines) + a1_xadd = 0; + break; case XADDINC: - // add the contents of the increment register - a1_xadd = (REG(A1_INC) << 16) | (REG(A1_FINC) & 0xffff); - a1_yadd = (REG(A1_INC) & 0xffff0000) | (REG(A1_FINC) >> 16); - break; + // add the contents of the increment register + a1_xadd = (REG(A1_INC) << 16) | (REG(A1_FINC) & 0xFFFF); + a1_yadd = (REG(A1_INC) & 0xFFFF0000) | (REG(A1_FINC) >> 16); + break; } if (XSIGNSUB_A1) - a1_xadd=-a1_xadd; + a1_xadd = -a1_xadd; // determine a2_yadd - if ((YADD1_A2)||(YADD1_A1)) + if (YADD1_A2 || YADD1_A1) a2_yadd = 1 << 16; else a2_yadd = 0; if (YSIGNSUB_A2) - a2_yadd=-a2_yadd; + a2_yadd = -a2_yadd; - a2_phrase_mode=0; + a2_phrase_mode = 0; // determine a2_xadd switch (xadd_a2_control) { case XADDPHR: - // add phrase offset to X and truncate - a2_xadd = 1 << 16; - - a2_phrase_mode=1; - break; + // add phrase offset to X and truncate + a2_xadd = 1 << 16; + a2_phrase_mode = 1; + break; case XADDPIX: - // add pixelsize (1) to X - a2_xadd = 1 << 16; - break; + // add pixelsize (1) to X + a2_xadd = 1 << 16; + break; case XADD0: - // add zero (for those nice vertical lines) - a2_xadd = 0; - break; + // add zero (for those nice vertical lines) + a2_xadd = 0; + break; case XADDINC: - // add the contents of the increment register - // since there is no register for a2 we just add 1 - a2_xadd = 1 << 16; - break; + // add the contents of the increment register + // since there is no register for a2 we just add 1 + a2_xadd = 1 << 16; + break; } if (XSIGNSUB_A2) - a2_xadd=-a2_xadd; + a2_xadd = -a2_xadd; // modify outer loop steps based on command - a1_step_x=0; - a1_step_y=0; - a2_step_x=0; - a2_step_y=0; + a1_step_x = 0; + a1_step_y = 0; + a2_step_x = 0; + a2_step_y = 0; if (cmd & 0x00000100) { @@ -1201,53 +1207,50 @@ void blitter_blit(uint32 cmd) a2_step_y = (REG(A2_STEP)&0xffff0000); } + outer_loop = n_lines; - outer_loop=n_lines; - - - a2_psize=1 << ((REG(A2_FLAGS) >> 3) & 7); - a1_psize=1 << ((REG(A1_FLAGS) >> 3) & 7); + a2_psize = 1 << ((REG(A2_FLAGS) >> 3) & 7); + a1_psize = 1 << ((REG(A1_FLAGS) >> 3) & 7); // zbuffering if (GOURZ) { - zadd=jaguar_long_read(0xF02274); + zadd = jaguar_long_read(0xF02274); - for(int v=0;v<4;v++) - z_i[v]=(int32)jaguar_long_read(0xF0228C+(v<<2)); + for(int v=0; v<4; v++) + z_i[v] = (int32)jaguar_long_read(0xF0228C + (v << 2)); } - if ((GOURD)||(GOURZ)||(SRCSHADE)) + if (GOURD || GOURZ || SRCSHADE) { // gouraud shading gouraud_add = jaguar_long_read(0xF02270); - gd_c[0] = jaguar_byte_read(0xF02268); gd_i[0] = jaguar_byte_read(0xF02269); - gd_i[0]<<=16; - gd_i[0]|=jaguar_word_read(0xF02240); + gd_i[0] <<= 16; + gd_i[0] |= jaguar_word_read(0xF02240); gd_c[1] = jaguar_byte_read(0xF0226A); - gd_i[1] = jaguar_byte_read(0xF0226b); - gd_i[1]<<=16; - gd_i[1]|=jaguar_word_read(0xF02242); + gd_i[1] = jaguar_byte_read(0xF0226B); + gd_i[1] <<= 16; + gd_i[1] |= jaguar_word_read(0xF02242); gd_c[2] = jaguar_byte_read(0xF0226C); - gd_i[2] = jaguar_byte_read(0xF0226d); - gd_i[2]<<=16; - gd_i[2]|=jaguar_word_read(0xF02244); + gd_i[2] = jaguar_byte_read(0xF0226D); + gd_i[2] <<= 16; + gd_i[2] |= jaguar_word_read(0xF02244); gd_c[3] = jaguar_byte_read(0xF0226E); - gd_i[3] = jaguar_byte_read(0xF0226f); - gd_i[3]<<=16; - gd_i[3]|=jaguar_word_read(0xF02246); + gd_i[3] = jaguar_byte_read(0xF0226F); + gd_i[3] <<= 16; + gd_i[3] |= jaguar_word_read(0xF02246); gd_ia = gouraud_add & 0xFFFFFF; - if(gd_ia & 0x800000) + if (gd_ia & 0x800000) gd_ia = 0xFF000000 | gd_ia; gd_ca = (gouraud_add>>24) & 0xFF; - if(gd_ca & 0x80) + if (gd_ca & 0x80) gd_ca = 0xFFFFFF00 | gd_ca; } @@ -1376,13 +1379,12 @@ void blitter_blit(uint32 cmd) } #endif - - blitter_working=1; + blitter_working = 1; #ifndef USE_GENERIC_BLITTER if (!blitter_execute_cached_code(blitter_in_cache(cmd))) #endif blitter_generic(cmd); - blitter_working=0; + blitter_working = 0; } uint32 blitter_reg_read(uint32 offset) @@ -1422,11 +1424,11 @@ void blitter_init(void) { for (int i=0;i<256;i++) { - blitter_cache[i]=(struct s_blitter_cache *)malloc(sizeof(struct s_blitter_cache)); + blitter_cache[i] = (struct s_blitter_cache *)malloc(sizeof(struct s_blitter_cache)); blitter_cache[i]->next=null; blitter_cache[i]->prev=null; } - blitter_cache_init=1; + blitter_cache_init = 1; } #ifndef USE_GENERIC_BLITTER #include "include/blit_i.h" @@ -1434,8 +1436,8 @@ void blitter_init(void) blitter_reset(); #ifdef GEN_CODE - blitters_code_fp=fopen("include/blit_c.h","awrt"); - blitters_code_init_fp=fopen("include/blit_i.h","awrt"); + blitters_code_fp = fopen("include/blit_c.h","awrt"); + blitters_code_init_fp = fopen("include/blit_i.h","awrt"); #endif } @@ -1446,11 +1448,12 @@ void blitter_reset(void) void blitter_done(void) { - blitter_list(); +// blitter_list(); #ifdef GEN_CODE fclose(blitters_code_fp); fclose(blitters_code_init_fp); #endif + fprintf(log_get(), "BLIT: Done.\n"); } void blitter_byte_write(uint32 offset, uint8 data) @@ -1480,7 +1483,6 @@ void blitter_byte_write(uint32 offset, uint8 data) case 0x89: blitter_ram[0x6F] = data; break; case 0x9A: blitter_ram[0x46] = data; break; case 0x9B: blitter_ram[0x47] = data; break; - } } diff --git a/src/cdbios.cpp b/src/cdbios.cpp index 447a5b6..b57c01b 100644 --- a/src/cdbios.cpp +++ b/src/cdbios.cpp @@ -1,32 +1,31 @@ -////////////////////////////////////////////////////////////////////////////// // -////////////////////////////////////////////////////////////////////////////// +// CD BIOS core // -// 20.02.2002: fixed sector to msf conversion -// 19.02.2002: fixed a bug in toc encoding function +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons // +// cal2: +// 02/20/2002: fixed sector to msf conversion +// 02/19/2002: fixed a bug in toc encoding function // -// -////////////////////////////////////////////////////////////////////////////// -#include "include/cdbios.h" + +#include "cdbios.h" /* Added by SDLEMU (http://sdlemu.ngemu.com */ /* Some GCC UNIX includes */ #ifdef __GCCUNIX__ - #include +#include #endif #define ERR_FLAG 0x3e00 #define CD_TOC 0x2c00 #define BIOS_VER 0x3004 - #define CDBIOS_INIT 0 #define CDBIOS_INITM 1 #define CDBIOS_INITF 2 - - #define CD_INIT 0x3000 #define CD_MODE 0x3006 #define CD_ACK 0x300C @@ -46,10 +45,10 @@ #define CD_INITM 0x3060 #define CD_INITF 0x3066 - -char *cdbios_command[]={"init","mode","ack","jeri","spin","stop","mute","umute","pause","upause", - "read","uread","setup","ptr","osamp","getoc","initm","initf", - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; +char * cdbios_command[] = + { "init", "mode", "ack", "jeri", "spin", "stop", "mute", "umute", "pause", "upause", + "read", "uread", "setup", "ptr", "osamp", "getoc", "initm", "initf", + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; #define CDROM_AUDIO_MODE 0 #define CDROM_DATA_MODE 1 @@ -60,11 +59,10 @@ char *cdbios_command[]={"init","mode","ack","jeri","spin","stop","mute","umute", #define CDROM_STATUS_OK 0 #define CDROM_STATUS_ERROR 1 - uint32 cdrom_mode = CDROM_DATA_MODE; uint32 cdrom_speed = CDROM_SINGLE_SPEED; uint32 cdrom_oversample_factor = 1; -uint32 cdbios_session=0; +uint32 cdbios_session = 0; uint32 cdrom_destination_buffer_beginning; uint32 cdrom_destination_buffer_end; @@ -74,19 +72,10 @@ uint32 cdrom_partition_marker; uint32 cdrom_circular_buffer_size; uint32 cdbios_init_type; -uint32 *cdbios_sector_lut; -uint32 cdbios_init_done=0; +uint32 * cdbios_sector_lut; +uint32 cdbios_init_done = 0; + -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// void cdbios_build_sector_lut(void) { uint32 last_sector=0; @@ -129,16 +118,7 @@ void cdbios_build_sector_lut(void) } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_get_time(uint32 sectors, uint32 *mm, uint32 *ss, uint32 *ff) { uint32 _sectors=sectors; @@ -156,16 +136,7 @@ void cdbios_get_time(uint32 sectors, uint32 *mm, uint32 *ss, uint32 *ff) // fprintf(log_get(),"[%.2i:%.2i:%.2i]\n",_mm,_ss,_ff); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_encode_toc(void) { int i; @@ -229,16 +200,7 @@ void cdbios_encode_toc(void) } } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_decode_toc(void) { uint32 addr=0x2c00; @@ -277,16 +239,7 @@ void cdbios_decode_toc(void) nb_tracks--; } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cd_bios_boot(char *filename) { cd_bios_init(); @@ -321,16 +274,7 @@ void cd_bios_boot(char *filename) // fprintf(log_get(),"cdbios: boot code:\n"); // jaguar_dasm(cdi_load_address, cdi_code_length); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cd_bios_init(void) { fprintf(log_get(),"cd_bios: initializing\n"); @@ -342,16 +286,7 @@ void cd_bios_init(void) cd_bios_reset(); cdbios_init_done=1; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cd_bios_reset(void) { fprintf(log_get(), "cd_bios: reset\n"); @@ -361,47 +296,20 @@ void cd_bios_reset(void) cdrom_oversample_factor = 1; cdbios_session = 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cd_bios_done(void) { - fprintf(log_get(),"cd_bios: done\n"); close(cdi_fp); + fprintf(log_get(), "CD BIOS: Done.\n"); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_init(void) { cdbios_init_type = CDBIOS_INIT; jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK); fprintf(log_get(), "cdbios: init(0x%.8x)\n", m68k_get_reg(NULL, M68K_REG_A0)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_mode(void) { // uint32 data = s68000context.dreg[0]; @@ -414,44 +322,17 @@ void cdbios_cmd_mode(void) // fprintf(log_get(),"cdbios: %s\n",(cdrom_mode==CDROM_AUDIO_MODE)?"audio mode":"data mode"); // fprintf(log_get(),"cdbios: %s\n",(cdrom_speed==CDROM_DOUBLE_SPEED)?"double speed":"single speed"); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_ack(void) { jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_jeri(void) { jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_spin(void) { // uint16 spin=(1<<(s68000context.dreg[0]&0xffff)); @@ -460,72 +341,27 @@ void cdbios_cmd_spin(void) jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK); // fprintf(log_get(),"cdbios: switching to session %i\n",spin); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_stop(void) { jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_mute(void) { jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_umute(void) { jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_pause(void) { jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_upause(void) { jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); @@ -540,16 +376,7 @@ void cdi_read_block(uint32 sector, uint8 *buffer, uint32 count) count--; } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_read(void) { static uint8 cdbios_sector[2352]; @@ -662,93 +489,39 @@ void cdbios_cmd_read(void) } jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_uread(void) { // stop the recording started with a cd_read command // for now, there is nothing to do jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_setup(void) { // initialize the cd system jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_ptr(void) { // s68000context.areg[0]=cdrom_destination_buffer_end+4; m68k_set_reg(M68K_REG_A0, cdrom_destination_buffer_end + 4); jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_osamp(void) { // cdrom_oversample_factor=(1<<(s68000context.dreg[0]&0xffff)); cdrom_oversample_factor = 1 << (m68k_get_reg(NULL, M68K_REG_D0) & 0xFFFF); jaguar_word_write(ERR_FLAG, CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_gettoc(void) { jaguar_word_write(ERR_FLAG,CDROM_STATUS_OK); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_initm(void) { cdbios_init_type = CDBIOS_INITM; @@ -756,16 +529,7 @@ void cdbios_cmd_initm(void) // fprintf(log_get(),"cdbios: initm(0x%.8x)\n",s68000context.areg[0]); fprintf(log_get(), "cdbios: initm(0x%.8x)\n", m68k_get_reg(NULL, M68K_REG_A0)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdbios_cmd_initf(void) { cdbios_init_type = CDBIOS_INITF; @@ -773,16 +537,7 @@ void cdbios_cmd_initf(void) // fprintf(log_get(),"cdbios: initf(0x%.8x)\n",s68000context.areg[0]); fprintf(log_get(), "cdbios: initf(0x%.8x)\n", m68k_get_reg(NULL, M68K_REG_A0)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cd_bios_process(uint32 offset) { if (!cdbios_init_done) @@ -822,16 +577,7 @@ void cd_bios_process(uint32 offset) m68k_set_reg(M68K_REG_PC, jaguar_long_read(m68k_get_reg(NULL, M68K_REG_A7))); m68k_set_reg(M68K_REG_A7, (m68k_get_reg(NULL, M68K_REG_A7) + 4) & 0xFFFFFFFF); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cd_bios_exec(uint32 scanline) { // single speed mode: 150 Kb/s (153600 bytes/s) diff --git a/src/cdi.cpp b/src/cdi.cpp index f03f0b4..61e1c4f 100644 --- a/src/cdi.cpp +++ b/src/cdi.cpp @@ -1,77 +1,57 @@ +// +// CD Interface handler +// +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons +// + #include "cdi.h" /* Added by SDLEMU (http://sdlemu.ngemu.com) */ /* Added for GCC UNIX compatibility */ #ifdef __GCCUNIX__ - #include - #include - #include +#include +#include +#include - #define O_BINARY (0) +#define O_BINARY (0) #endif #define CDI_V2 0x80000004 #define CDI_V3 0x80000005 #define CDI_V35 0x80000006 -static uint8 cdi_track_start_mark[10] = { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF }; - - +static uint8 cdi_track_start_mark[10] = + { 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0xFF, 0xFF, 0xFF, 0xFF }; int cdi_fp; uint32 cdi_load_address; uint32 cdi_code_length; -s_cdi_descriptor *cdi_descriptor; -s_cdi_track **cdi_tracks; -uint32 cdi_tracks_count; +s_cdi_descriptor * cdi_descriptor; +s_cdi_track ** cdi_tracks; +uint32 cdi_tracks_count; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -int cdi_open(char *path) +int cdi_open(char * path) { - fprintf(log_get(),"cdi: opening %s\n",path); - return(open(path,O_BINARY|O_RDONLY)); + fprintf(log_get(), "CDI: Opening %s\n", path); + return open(path, O_BINARY | O_RDONLY); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdi_close(int fp) { - fprintf(log_get(),"cdi: closing\n"); + fprintf(log_get(), "CDI: Closing\n"); close(fp); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + #ifdef __PORT__ long tell(int fd) { return lseek(fd, 0LL, SEEK_CUR); } #endif + s_cdi_descriptor *cdi_get_descriptor(int fp, FILE *stdfp) { s_cdi_descriptor *descriptor; @@ -211,16 +191,7 @@ s_cdi_descriptor *cdi_get_descriptor(int fp, FILE *stdfp) return(descriptor); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdi_dump_descriptor(FILE *fp,s_cdi_descriptor *cdi_descriptor) { fprintf(fp,"cdi: %i Mb\n",cdi_descriptor->length>>20); @@ -234,83 +205,72 @@ void cdi_dump_descriptor(FILE *fp,s_cdi_descriptor *cdi_descriptor) } fprintf(fp,"cdi: %i sessions\n",cdi_descriptor->nb_of_sessions); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -uint8 *cdi_extract_boot_code(int fp, s_cdi_descriptor *cdi_descriptor) + +uint8 * cdi_extract_boot_code(int fp, s_cdi_descriptor * cdi_descriptor) { - s_cdi_track *boot_track=&cdi_descriptor->sessions[1].tracks[0]; - uint32 boot_track_size=boot_track->length*boot_track->sector_size; + s_cdi_track * boot_track = &cdi_descriptor->sessions[1].tracks[0]; + uint32 boot_track_size = boot_track->length * boot_track->sector_size; - uint8 *boot_track_data=(uint8*)malloc(boot_track_size); - lseek(fp,2+(boot_track->position), SEEK_SET); - read(fp,boot_track_data,boot_track_size); + uint8 * boot_track_data = (uint8 *)malloc(boot_track_size); + lseek(fp, 2 + (boot_track->position), SEEK_SET); + read(fp, boot_track_data, boot_track_size); - uint32 *boot_track_data_32=(uint32*)boot_track_data; - uint32 offset=0; - while (offset<(boot_track_size>>2)) + uint32 * boot_track_data_32 = (uint32 *)boot_track_data; + uint32 offset = 0; + while (offset < (boot_track_size >> 2)) { - if (boot_track_data_32[offset]==0x49205452) + if (boot_track_data_32[offset] == 0x49205452) break; offset++; } - if (offset==(boot_track_size>>2)) + if (offset == (boot_track_size >> 2)) { - fprintf(log_get(),"cdi: cannot find the boot code\n"); - return(NULL); + fprintf(log_get(), "CDI: Cannot find the boot code\n"); + return NULL; } - offset=(offset<<2)+4; - uint16 *data16=(uint16*)&boot_track_data[offset]; - cdi_load_address=*data16++; cdi_load_address<<=16; cdi_load_address|=*data16++; - cdi_code_length=*data16++; cdi_code_length<<=16; cdi_code_length|=*data16++; - fprintf(log_get(),"cdi: load address: 0x%.8x\n",cdi_load_address); - fprintf(log_get(),"cdi: length: 0x%.8x\n",cdi_code_length); - fprintf(log_get(),"cdi: byte swapping boot code\n"); - - for (uint32 i=0;i<(cdi_code_length>>1);i++) + + offset = (offset << 2) + 4; + uint16 * data16 = (uint16 *)&boot_track_data[offset]; + cdi_load_address = *data16++; + cdi_load_address <<= 16; + cdi_load_address |= *data16++; + cdi_code_length = *data16++; + cdi_code_length <<= 16; + cdi_code_length |= *data16++; + fprintf(log_get(), "CDI: Load address: %08X\n", cdi_load_address); + fprintf(log_get(), "CDI: Length: %08X\n", cdi_code_length); +//No need for byte swapping any more... +/* fprintf(log_get(), "cdi: byte swapping boot code\n"); + + for(uint32 i=0; i<(cdi_code_length >> 1); i++) { - uint16 sdata=data16[i]; - sdata=(sdata>>8)|(sdata<<8); - data16[i]=sdata; - } - return((uint8*)data16); + uint16 sdata = data16[i]; + sdata = (sdata >> 8) | (sdata << 8); + data16[i] = sdata; + }*/ + + return (uint8 *)data16; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void cdi_load_sector(uint32 sector, uint8 *buffer) + +void cdi_load_sector(uint32 sector, uint8 * buffer) { - if (sector==0xffffffff) + if (sector == 0xFFFFFFFF) { - memset(buffer,0x00,2352); + memset(buffer, 0x00, 2352); return; } - sector*=2352; + sector *= 2352; - lseek(cdi_fp,2+sector,SEEK_SET); - read(cdi_fp,buffer,2352); + lseek(cdi_fp, 2+sector, SEEK_SET); + read(cdi_fp, buffer, 2352); - // byte swap +//This is probably not needed any more... +/* // byte swap for (uint32 i=0;i<2352;i+=2) { uint8 sdata=buffer[i+0]; buffer[i+0]=buffer[i+1]; buffer[i+1]=sdata; - } - + }*/ } diff --git a/src/cdrom.cpp b/src/cdrom.cpp index 1a64042..9d98e0b 100644 --- a/src/cdrom.cpp +++ b/src/cdrom.cpp @@ -1,86 +1,48 @@ -#include "include/cdrom.h" +// +// CD handler +// +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons +// + +#include "cdrom.h" //#define CDROM_LOG -static uint8 cdrom_ram[0x100]; -static uint16 cdrom_cmd=0; +static uint8 cdrom_ram[0x100]; +static uint16 cdrom_cmd = 0; + -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// void cdrom_init(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdrom_reset(void) { - memset(cdrom_ram,0x00,0x100); - cdrom_cmd=0; - + memset(cdrom_ram, 0x00, 0x100); + cdrom_cmd = 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdrom_done(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdrom_byte_write(uint32 offset, uint8 data) { - offset&=0xff; - cdrom_ram[offset]=data; + offset &= 0xFF; + cdrom_ram[offset] = data; #ifdef CDROM_LOG fprintf(log_get(),"cdrom: writing byte 0x%.2x at 0x%.8x\n",data,offset); #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void cdrom_word_write(uint32 offset, uint16 data) { - offset&=0xff; - cdrom_ram[offset+0]=(data>>8)&0xff; - cdrom_ram[offset+1]=data&0xff; + offset &= 0xFF; + cdrom_ram[offset+0] = (data >> 8) & 0xFF; + cdrom_ram[offset+1] = data & 0xFF; // command register /* @@ -117,61 +79,37 @@ void cdrom_word_write(uint32 offset, uint16 data) fprintf(log_get(),"cdrom: writing word 0x%.4x at 0x%.8x\n",data,offset); #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint8 cdrom_byte_read(uint32 offset) { - offset&=0xff; #ifdef CDROM_LOG fprintf(log_get(),"cdrom: reading byte from 0x%.8x\n",offset); #endif - return(cdrom_ram[offset]); + return cdrom_ram[offset & 0xFF]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint16 cdrom_word_read(uint32 offset) { - offset&=0xff; + offset &= 0xFF; - uint16 data=0x0000; + uint16 data = 0x0000; - if (offset==0x00) - data=0x0000; - else - if (offset==0x02) - data=0x2000; - else - if (offset==0x0a) + if (offset == 0x00) + data = 0x0000; + else if (offset == 0x02) + data = 0x2000; + else if (offset == 0x0A) { - if (cdrom_cmd==0x7001) - data=cdrom_cmd; + if (cdrom_cmd == 0x7001) + data = cdrom_cmd; else - data=0x0400; + data = 0x0400; } else - { - data=cdrom_ram[offset+0]; - data<<=8; - data|=cdrom_ram[offset+1]; - } + data = (cdrom_ram[offset+0] << 8) | cdrom_ram[offset+1]; + #ifdef CDROM_LOG fprintf(log_get(),"cdrom: reading word 0x%.4x from 0x%.8x [68k pc=0x%.8x]\n",data,offset,s68000readPC()); #endif - return(data); + return data; } diff --git a/src/clock.cpp b/src/clock.cpp index ec2ac8a..8ca3bc1 100644 --- a/src/clock.cpp +++ b/src/clock.cpp @@ -1,76 +1,41 @@ -#include "include/jaguar.h" - - -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// // +// Clock handler // +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons // -////////////////////////////////////////////////////////////////////////////// + +#include "jaguar.h" + + void clock_init(void) { clock_reset(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void clock_reset(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void clock_done(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void clock_byte_write(uint32 offset, uint8 data) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void clock_word_write(uint32 offset, uint16 data) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint8 clock_byte_read(uint32 offset) { - return(0xff); + return 0xFF; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint16 clock_word_read(uint32 offset) { - return(0xffff); + return 0xFFFF; } diff --git a/src/crc32.cpp b/src/crc32.cpp index e9c60b5..1879404 100644 --- a/src/crc32.cpp +++ b/src/crc32.cpp @@ -1,13 +1,14 @@ -////////////////////////////////////////////////////////////////////////////// // -////////////////////////////////////////////////////////////////////////////// +// CRC support // +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons // -// -////////////////////////////////////////////////////////////////////////////// + #include #include -#include "include/crc32.h" +#include "crc32.h" unsigned long crctable[256] = { @@ -77,42 +78,26 @@ unsigned long crctable[256] = 0xB40BBE37L, 0xC30C8EA1L, 0x5A05DF1BL, 0x2D02EF8DL }; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// -static unsigned long update_crc(unsigned char *p, unsigned long crc, int reclen) -{ - int i; - for (i = 0; i < reclen; i++) +static unsigned long update_crc(unsigned char * p, unsigned long crc, int reclen) +{ + for(int i=0; i> 8); - return (crc); + return crc; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// -int crc32_calcCheckSum(unsigned char *data, unsigned int length) +int crc32_calcCheckSum(unsigned char * data, unsigned int length) { - int sum; +/* int sum; int Xor; unsigned int i; - int j; - + int j;*/ - return(update_crc(data, 0xFFFFFFFFL, length)^0xFFFFFFFFL); - sum = 0; - Xor = 0; + return update_crc(data, 0xFFFFFFFFL, length) ^ 0xFFFFFFFFL; +/* sum = 0; + Xor = 0; for (i = 0;i < length;i+=2) { @@ -121,5 +106,5 @@ int crc32_calcCheckSum(unsigned char *data, unsigned int length) Xor ^= j; } sum = ((sum & 0xffff) << 16) | (Xor & 0xffff); - return sum; + return sum;*/ } diff --git a/src/dsound_dummy.cpp b/src/dsound_dummy.cpp index f81f4c6..4baa7c6 100644 --- a/src/dsound_dummy.cpp +++ b/src/dsound_dummy.cpp @@ -1,13 +1,19 @@ -//////////////////////////////////////////////////////////////////////////////// -// Audio -//////////////////////////////////////////////////////////////////////////////// +// +// Audio handler +// +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons +// +// We really need to convert this to SDL... DirectSound won't cut it here! +// -#include "include/jaguar.h" -#include "include/dsnd.h" +#include "jaguar.h" +#include "dsnd.h" int ym2413_enable; -int FREQUENCE=44100; +int FREQUENCE = 44100; void dsound_reset(void); @@ -18,30 +24,20 @@ void dsound_reset(void); int chipBufferLength; //Number of bytes to hold SOUND_BUFFER seconds. -int lastChipWrite =0; -int chipWrite =UNDEFINED; //Write Cursor +int lastChipWrite = 0; +int chipWrite = UNDEFINED; //Write Cursor -INT16* buf1; +INT16 * buf1; -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// void ws_write_state(int fp) { } - void ws_read_state(int fp) { } - - - -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// void ws_audio_init(void) { #ifdef _EMULATE_SOUND @@ -49,9 +45,7 @@ void ws_audio_init(void) // ws_audio_reset(); #endif } -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// + void ws_audio_reset(void) { #ifdef _EMULATE_SOUND @@ -72,10 +66,6 @@ void ws_audio_reset(void) #endif } - -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// void ws_audio_done(void) { #ifdef _EMULATE_SOUND @@ -83,10 +73,6 @@ void ws_audio_done(void) #endif } - -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// void ws_audio_clear_channel(int Channel) { #ifdef _EMULATE_SOUND @@ -107,11 +93,10 @@ void ws_audio_clear_channel(int Channel) #endif } - - -//////////////////////////////////////////////////////////////////////////////// +// // start playing a channel -//////////////////////////////////////////////////////////////////////////////// +// + int ws_audio_play_channel(int Channel) { #ifdef _EMULATE_SOUND @@ -130,10 +115,10 @@ int ws_audio_play_channel(int Channel) return 0; } - -//////////////////////////////////////////////////////////////////////////////// +// // stop playing a channel -//////////////////////////////////////////////////////////////////////////////// +// + int ws_audio_stop_channel(int Channel) { #ifdef _EMULATE_SOUND @@ -153,8 +138,6 @@ int ws_audio_stop_channel(int Channel) return(0); } - - void dsound_reset(void) { #ifdef _EMULATE_SOUND @@ -188,8 +171,6 @@ IDirectSoundBuffer_Play(chipBuffer, 0,0, DSBPLAY_LOOPING ); #endif } - - void system_sound_shutdown(void) { #ifdef _EMULATE_SOUND @@ -203,7 +184,6 @@ void system_sound_shutdown(void) #endif } - void system_sound_update(void) { #ifdef _EMULATE_SOUND diff --git a/src/dsp.cpp b/src/dsp.cpp index 99cc887..294b73e 100644 --- a/src/dsp.cpp +++ b/src/dsp.cpp @@ -1,15 +1,12 @@ -////////////////////////////////////////////////////////////////////////////// // -////////////////////////////////////////////////////////////////////////////// +// DSP core // +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons // -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -#include "include/dsp.h" +#include "dsp.h" #define CINT0FLAG 0x00200 #define CINT1FLAG 0x00400 @@ -155,7 +152,6 @@ char *dsp_opcode_str[64]= static uint16 *mirror_table; static uint8 *dsp_ram_8; - static uint32 dsp_pc; static uint32 dsp_acc; static uint32 dsp_remain; @@ -200,52 +196,23 @@ uint32 dsp_convert_zero[32] = { 32,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18, uint8 *dsp_branch_condition_table=0; #define branch_condition(x) dsp_branch_condition_table[(x) + ((jaguar_flags & 7) << 5)] -static uint32 dsp_in_exec=0; -static uint32 dsp_releaseTimeSlice_flag=0; +static uint32 dsp_in_exec = 0; +static uint32 dsp_releaseTimeSlice_flag = 0; + +FILE * dsp_fp; -FILE *dsp_fp; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// void dsp_reset_stats(void) { - for (uint32 i=0;i<64;i++) - dsp_opcode_use[i]=0; + for (uint32 i=0; i<64; i++) + dsp_opcode_use[i] = 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// void dsp_releaseTimeslice(void) { - dsp_releaseTimeSlice_flag=1; + dsp_releaseTimeSlice_flag = 1; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// void dsp_build_branch_condition_table(void) { int i,j; @@ -291,16 +258,7 @@ void dsp_build_branch_condition_table(void) } } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + unsigned dsp_byte_read(unsigned int offset) { // battlemorph @@ -333,16 +291,7 @@ unsigned dsp_byte_read(unsigned int offset) } return(jaguar_byte_read(offset)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + unsigned dsp_word_read(unsigned int offset) { offset&=0xFFFFFFFE; @@ -408,16 +357,7 @@ unsigned dsp_word_read(unsigned int offset) } return(jaguar_word_read(offset)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + unsigned dsp_long_read(unsigned int offset) { offset&=0xFFFFFFFC; @@ -459,16 +399,7 @@ unsigned dsp_long_read(unsigned int offset) data|=jaguar_word_read(offset+2); return(data); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void dsp_byte_write(unsigned offset, unsigned data) { if ((offset >= dsp_work_ram_base) && (offset < dsp_work_ram_base+0x2000)) @@ -502,16 +433,7 @@ void dsp_byte_write(unsigned offset, unsigned data) // fprintf(log_get(),"dsp: writing %.2x at 0x%.8x\n",data,offset); jaguar_byte_write(offset, data); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void dsp_word_write(unsigned offset, unsigned data) { offset &= 0xFFFFFFFE; @@ -552,16 +474,7 @@ void dsp_word_write(unsigned offset, unsigned data) } jaguar_word_write(offset, data); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void dsp_long_write(unsigned offset, unsigned data) { offset &= 0xFFFFFFFC; @@ -663,16 +576,7 @@ void dsp_long_write(unsigned offset, unsigned data) jaguar_word_write(offset, (data>>16) & 0xFFFF); jaguar_word_write(offset+2, data & 0xFFFF); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint8 * jaguar_rom_load(char * path, uint32 * romSize); void dsp_load_bin_at(char * path, uint32 offset) { @@ -683,16 +587,7 @@ void dsp_load_bin_at(char * path, uint32 offset) for(uint32 i=0; i= dsp_work_ram_base) && (Rm < (dsp_work_ram_base+0x2000))) @@ -2093,16 +1679,7 @@ static void dsp_opcode_storeb(void) else jaguar_byte_write(Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_storew(void) { if ((Rm >= dsp_work_ram_base) && (Rm < (dsp_work_ram_base+0x2000))) @@ -2110,30 +1687,12 @@ static void dsp_opcode_storew(void) else jaguar_word_write(Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_store(void) { dsp_long_write(Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_loadb(void) { if ((Rm >= dsp_work_ram_base) && (Rm < (dsp_work_ram_base+0x2000))) @@ -2141,16 +1700,7 @@ static void dsp_opcode_loadb(void) else Rn=jaguar_byte_read(Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_loadw(void) { if ((Rm >= dsp_work_ram_base) && (Rm < (dsp_work_ram_base+0x2000))) @@ -2158,175 +1708,67 @@ static void dsp_opcode_loadw(void) else Rn=jaguar_word_read(Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_load(void) { Rn = dsp_long_read(Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_load_r14_indexed(void) { Rn = dsp_long_read( dsp_reg[14] + (dsp_convert_zero[imm_1] << 2)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_load_r15_indexed(void) { Rn = dsp_long_read( dsp_reg[15] + (dsp_convert_zero[imm_1] << 2)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_movei(void) { Rn = ((uint32)dsp_word_read(dsp_pc)) + (((uint32)dsp_word_read(dsp_pc+2))<<16); dsp_pc+=4; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_moveta(void) { alternate_Rn = Rm; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_movefa(void) { Rn = alternate_Rm; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_move(void) { Rn = Rm; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_moveq(void) { Rn = imm_1; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_resmac(void) { Rn = dsp_acc; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_imult(void) { uint32 res=Rn=((int16)Rn)*((int16)Rm); set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_mult(void) { uint32 res=Rn = ((uint16)Rm) * ((uint16)Rn); set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_bclr(void) { uint32 _Rm=imm_1; @@ -2382,16 +1824,7 @@ static void dsp_opcode_bclr(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_btst(void) { uint32 _Rm=imm_1; @@ -2435,16 +1868,7 @@ static void dsp_opcode_btst(void) }; #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_bset(void) { uint32 _Rm=imm_1; @@ -2499,59 +1923,23 @@ static void dsp_opcode_bset(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_subqt(void) { Rn -= dsp_convert_zero[imm_1]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_addqt(void) { Rn += dsp_convert_zero[imm_1]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_imacn(void) { uint32 res=((int16)Rm) * ((int16)(Rn)); dsp_acc += res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_mtoi(void) { uint32 _Rm=Rm; @@ -2559,16 +1947,7 @@ static void dsp_opcode_mtoi(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_normi(void) { uint32 _Rm = Rm; @@ -2591,16 +1970,7 @@ static void dsp_opcode_normi(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_mmult(void) { int count = dsp_matrix_control&0x0f; @@ -2641,16 +2011,7 @@ static void dsp_opcode_mmult(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_abs(void) { uint32 _Rn=Rn; @@ -2668,16 +2029,7 @@ static void dsp_opcode_abs(void) set_flag_z(res); } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_div(void) { uint32 _Rm=Rm; @@ -2703,16 +2055,7 @@ static void dsp_opcode_div(void) else Rn=0xffffffff; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_imultn(void) { uint32 res=(int32)(((int16)Rn)*((int16)Rm)); @@ -2720,16 +2063,7 @@ static void dsp_opcode_imultn(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_neg(void) { uint32 _Rn=Rn; @@ -2785,16 +2119,7 @@ static void dsp_opcode_neg(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_shlq(void) { uint32 shift=(32-dsp_convert_zero[imm_1]); @@ -2855,16 +2180,7 @@ static void dsp_opcode_shlq(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_shrq(void) { uint32 shift=dsp_convert_zero[imm_1]; @@ -2926,16 +2242,7 @@ static void dsp_opcode_shrq(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_ror(void) { uint32 shift=Rm; @@ -2996,16 +2303,7 @@ static void dsp_opcode_ror(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_rorq(void) { uint32 shift=dsp_convert_zero[imm_1&0x1f]; @@ -3066,16 +2364,7 @@ static void dsp_opcode_rorq(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_sha(void) { int32 sRm=(int32)Rm; @@ -3107,16 +2396,7 @@ static void dsp_opcode_sha(void) set_flag_z(_Rn); set_flag_n(_Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_sharq(void) { uint32 shift=dsp_convert_zero[imm_1]; @@ -3132,16 +2412,7 @@ static void dsp_opcode_sharq(void) set_flag_z(_Rn); set_flag_n(_Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void dsp_opcode_sh(void) { int32 sRm=(int32)Rm; diff --git a/src/eeprom.cpp b/src/eeprom.cpp index 1610e1c..197d269 100644 --- a/src/eeprom.cpp +++ b/src/eeprom.cpp @@ -1,3 +1,11 @@ +// +// EEPROM handler +// +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons +// + #include "eeprom.h" #define eeprom_LOG @@ -41,388 +49,279 @@ uint16 jerry_ee_direct_jump = 0; FILE * jerry_ee_fp; extern char * jaguar_boot_dir; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void eeprom_init(void) { - static char eeprom_filename[256]; - sprintf(eeprom_filename,"%s\\%s%.8x.eep",jaguar_boot_dir,jaguar_eeproms_path,jaguar_mainRom_crc32); - jerry_ee_fp=fopen(eeprom_filename,"rb"); + static char eeprom_filename[1024]; + + sprintf(eeprom_filename, "%s\\%s%08X.eep", jaguar_boot_dir, jaguar_eeproms_path, (unsigned int)jaguar_mainRom_crc32); + jerry_ee_fp = fopen(eeprom_filename, "rb"); if (jerry_ee_fp) { - fread(eeprom_ram,1,128,jerry_ee_fp); + fread(eeprom_ram, 1, 128, jerry_ee_fp); fclose(jerry_ee_fp); - fprintf(log_get(),"eeprom: loaded from %s\n",eeprom_filename); - jerry_ee_fp=fopen(eeprom_filename,"wrb"); + fprintf(log_get(), "eeprom: loaded from %s\n", eeprom_filename); + jerry_ee_fp = fopen(eeprom_filename, "wrb"); } else { - fprintf(log_get(),"eeprom: creating %s\n",eeprom_filename); - jerry_ee_fp=fopen(eeprom_filename,"wb"); - if (jerry_ee_fp==NULL) - fprintf(log_get(),"eeprom: could not open/create %s\n",eeprom_filename); + fprintf(log_get(), "eeprom: creating %s\n", eeprom_filename); + jerry_ee_fp = fopen(eeprom_filename, "wb"); + if (jerry_ee_fp == NULL) + fprintf(log_get(), "EEPROM: Could not open/create %s\n", eeprom_filename); } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void eeprom_reset(void) { - if (jerry_ee_fp==NULL) - memset(eeprom_ram,0xff,64*2); + if (jerry_ee_fp == NULL) + memset(eeprom_ram, 0xFF, 64 * sizeof(uint16)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void eeprom_done(void) { if (jerry_ee_fp) { - fwrite(eeprom_ram,1,128,jerry_ee_fp); + fwrite(eeprom_ram, 1, 128, jerry_ee_fp); fclose(jerry_ee_fp); } else fprintf(log_get(),"eeprom: not saved\n"); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void eeprom_byte_write(uint32 offset, uint8 data) { switch (offset) { - case 0xf14001: break; - case 0xf14801: eeprom_set_di(data&0x01); break; - case 0xf15001: eeprom_set_cs(1); break; + case 0xF14001: + break; + case 0xF14801: + eeprom_set_di(data & 0x01); + break; + case 0xF15001: + eeprom_set_cs(1); + break; // default: fprintf(log_get(),"eeprom: unmapped 0x%.8x\n",offset); break; } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void eeprom_word_write(uint32 offset, uint16 data) { - eeprom_byte_write(offset+0,(data>>8)&0xff); - eeprom_byte_write(offset+1,(data&0xff)); + eeprom_byte_write(offset+0, (data >> 8) & 0xFF); + eeprom_byte_write(offset+1, data & 0xFF); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint8 eeprom_byte_read(uint32 offset) { switch (offset) { - case 0xf14001: return(eeprom_get_do()); break; - case 0xf14801: break; - case 0xf15001: eeprom_set_cs(1); break; + case 0xF14001: + return eeprom_get_do(); + case 0xF14801: + break; + case 0xF15001: + eeprom_set_cs(1); + break; // default: fprintf(log_get(),"eeprom: unmapped 0x%.8x\n",offset); break; } - return(0x00); + + return 0x00; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint16 eeprom_word_read(uint32 offset) { - uint16 data=eeprom_byte_read(offset+0); - data<<=8; - data|=eeprom_byte_read(offset+1); - return(data); + return ((uint16)eeprom_byte_read(offset+0) << 8) | eeprom_byte_read(offset+1); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void eeprom_set_di(uint32 data) { // fprintf(log_get(),"eeprom: di=%i\n",data); // fprintf(log_get(),"eeprom: state %i\n",jerry_ee_state); switch (jerry_ee_state) { - case EE_STATE_START: { - jerry_ee_state=EE_STATE_OP_A; - break; - } - case EE_STATE_OP_A: { - jerry_ee_op=(data<<1); - jerry_ee_state=EE_STATE_OP_B; - break; - } - case EE_STATE_OP_B: { - jerry_ee_op|=data; - jerry_ee_direct_jump=0; -// fprintf(log_get(),"eeprom: opcode %i\n",jerry_ee_op); - switch (jerry_ee_op) - { - case 0: jerry_ee_state=EE_STATE_0; break; - case 1: jerry_ee_state=EE_STATE_1; break; - case 2: jerry_ee_state=EE_STATE_2; break; - case 3: jerry_ee_state=EE_STATE_3; break; - } - eeprom_set_di(data); - break; - } - case EE_STATE_0: { - jerry_ee_rstate=EE_STATE_0_0; - jerry_ee_state=EE_READ_ADDRESS; - jerry_ee_direct_jump=1; - jerry_ee_address_cnt=6; - jerry_ee_address_data=0; - break; - } - case EE_STATE_0_0: { - switch ((jerry_ee_address_data>>4)&0x03) - { - case 0: jerry_ee_state=EE_STATE_0_0_0; break; - case 1: jerry_ee_state=EE_STATE_0_0_1; break; - case 2: jerry_ee_state=EE_STATE_0_0_2; break; - case 3: jerry_ee_state=EE_STATE_0_0_3; break; - } - eeprom_set_di(data); - break; - } - case EE_STATE_0_0_0:{ - // writes disable - // fprintf(log_get(),"eeprom: read only\n"); - jerry_writes_enabled=0; - jerry_ee_state=EE_STATE_START; - break; - } - case EE_STATE_0_0_1:{ - // writes all - jerry_ee_rstate=EE_STATE_0_0_1_0; - jerry_ee_state=EE_READ_DATA; - jerry_ee_data_cnt=16; - jerry_ee_data=0; - jerry_ee_direct_jump=1; - break; - } - case EE_STATE_0_0_1_0:{ - // fprintf(log_get(),"eeprom: filling eeprom with 0x%.4x\n",data); - if (jerry_writes_enabled) - { - for (int i=0;i<64;i++) - eeprom_ram[i]=jerry_ee_data; - } - //else - // fprintf(log_get(),"eeprom: not writing because read only\n"); - jerry_ee_state=EE_STATE_BUSY; - break; - } - case EE_STATE_0_0_2:{ - // erase all - //fprintf(log_get(),"eeprom: erasing eeprom\n"); - if (jerry_writes_enabled) - { - for (int i=0;i<64;i++) - eeprom_ram[i]=0xffff; - } - jerry_ee_state=EE_STATE_BUSY; - break; - } - case EE_STATE_0_0_3:{ - // writes enable - //fprintf(log_get(),"eeprom: read/write\n"); - jerry_writes_enabled=1; - jerry_ee_state=EE_STATE_START; - break; - } - case EE_STATE_1: { - jerry_ee_rstate=EE_STATE_1_0; - jerry_ee_state=EE_READ_ADDRESS; - jerry_ee_address_cnt=6; - jerry_ee_address_data=0; - jerry_ee_direct_jump=1; - break; - } - case EE_STATE_1_0: { - jerry_ee_rstate=EE_STATE_1_1; - jerry_ee_state=EE_READ_DATA; - jerry_ee_data_cnt=16; - jerry_ee_data=0; - jerry_ee_direct_jump=1; - break; - } - case EE_STATE_1_1: { - //fprintf(log_get(),"eeprom: writing 0x%.4x at 0x%.2x\n",jerry_ee_data,jerry_ee_address_data); - if (jerry_writes_enabled) - eeprom_ram[jerry_ee_address_data]=jerry_ee_data; - jerry_ee_state=EE_STATE_BUSY; - break; - } - case EE_STATE_2: { - jerry_ee_rstate=EE_STATE_2_0; - jerry_ee_state=EE_READ_ADDRESS; - jerry_ee_address_cnt=6; - jerry_ee_address_data=0; - jerry_ee_data_cnt=16; - jerry_ee_data=0; - break; - } - case EE_STATE_3: { - jerry_ee_rstate=EE_STATE_3_0; - jerry_ee_state=EE_READ_ADDRESS; - jerry_ee_address_cnt=6; - jerry_ee_address_data=0; - jerry_ee_direct_jump=1; - break; - } - case EE_STATE_3_0: { - //fprintf(log_get(),"eeprom: erasing 0x%.2x\n",jerry_ee_address_data); - if (jerry_writes_enabled) - eeprom_ram[jerry_ee_address_data]=0xffff; - jerry_ee_state=EE_STATE_BUSY; - break; - } + case EE_STATE_START: + jerry_ee_state = EE_STATE_OP_A; + break; + case EE_STATE_OP_A: + jerry_ee_op = (data << 1); + jerry_ee_state = EE_STATE_OP_B; + break; + case EE_STATE_OP_B: + jerry_ee_op |= data; + jerry_ee_direct_jump = 0; +// fprintf(log_get(),"eeprom: opcode %i\n",jerry_ee_op); + switch (jerry_ee_op) + { + case 0: jerry_ee_state = EE_STATE_0; break; + case 1: jerry_ee_state = EE_STATE_1; break; + case 2: jerry_ee_state = EE_STATE_2; break; + case 3: jerry_ee_state = EE_STATE_3; break; + } + eeprom_set_di(data); + break; + case EE_STATE_0: + jerry_ee_rstate = EE_STATE_0_0; + jerry_ee_state = EE_READ_ADDRESS; + jerry_ee_direct_jump = 1; + jerry_ee_address_cnt = 6; + jerry_ee_address_data = 0; + break; + case EE_STATE_0_0: + switch ((jerry_ee_address_data >> 4) & 0x03) + { + case 0: jerry_ee_state=EE_STATE_0_0_0; break; + case 1: jerry_ee_state=EE_STATE_0_0_1; break; + case 2: jerry_ee_state=EE_STATE_0_0_2; break; + case 3: jerry_ee_state=EE_STATE_0_0_3; break; + } + eeprom_set_di(data); + break; + case EE_STATE_0_0_0: + // writes disable + // fprintf(log_get(),"eeprom: read only\n"); + jerry_writes_enabled = 0; + jerry_ee_state = EE_STATE_START; + break; + case EE_STATE_0_0_1: + // writes all + jerry_ee_rstate = EE_STATE_0_0_1_0; + jerry_ee_state = EE_READ_DATA; + jerry_ee_data_cnt = 16; + jerry_ee_data = 0; + jerry_ee_direct_jump = 1; + break; + case EE_STATE_0_0_1_0: + // fprintf(log_get(),"eeprom: filling eeprom with 0x%.4x\n",data); + if (jerry_writes_enabled) + for(int i=0; i<64; i++) + eeprom_ram[i] = jerry_ee_data; + //else + // fprintf(log_get(),"eeprom: not writing because read only\n"); + jerry_ee_state = EE_STATE_BUSY; + break; + case EE_STATE_0_0_2: + // erase all + //fprintf(log_get(),"eeprom: erasing eeprom\n"); + if (jerry_writes_enabled) + for(int i=0; i<64; i++) + eeprom_ram[i] = 0xFFFF; + + jerry_ee_state=EE_STATE_BUSY; + break; + case EE_STATE_0_0_3: + // writes enable + //fprintf(log_get(),"eeprom: read/write\n"); + jerry_writes_enabled = 1; + jerry_ee_state = EE_STATE_START; + break; + case EE_STATE_1: + jerry_ee_rstate = EE_STATE_1_0; + jerry_ee_state = EE_READ_ADDRESS; + jerry_ee_address_cnt = 6; + jerry_ee_address_data = 0; + jerry_ee_direct_jump = 1; + break; + case EE_STATE_1_0: + jerry_ee_rstate = EE_STATE_1_1; + jerry_ee_state = EE_READ_DATA; + jerry_ee_data_cnt = 16; + jerry_ee_data = 0; + jerry_ee_direct_jump = 1; + break; + case EE_STATE_1_1: + //fprintf(log_get(),"eeprom: writing 0x%.4x at 0x%.2x\n",jerry_ee_data,jerry_ee_address_data); + if (jerry_writes_enabled) + eeprom_ram[jerry_ee_address_data] = jerry_ee_data; + jerry_ee_state = EE_STATE_BUSY; + break; + case EE_STATE_2: + jerry_ee_rstate = EE_STATE_2_0; + jerry_ee_state = EE_READ_ADDRESS; + jerry_ee_address_cnt = 6; + jerry_ee_address_data = 0; + jerry_ee_data_cnt = 16; + jerry_ee_data = 0; + break; + case EE_STATE_3: + jerry_ee_rstate = EE_STATE_3_0; + jerry_ee_state = EE_READ_ADDRESS; + jerry_ee_address_cnt = 6; + jerry_ee_address_data = 0; + jerry_ee_direct_jump = 1; + break; + case EE_STATE_3_0: + //fprintf(log_get(),"eeprom: erasing 0x%.2x\n",jerry_ee_address_data); + if (jerry_writes_enabled) + eeprom_ram[jerry_ee_address_data] = 0xFFFF; + jerry_ee_state = EE_STATE_BUSY; + break; case EE_READ_DATA: - { - //fprintf(log_get(),"eeprom:\t\t\t%i bit %i\n",data,jerry_ee_data_cnt-1); - jerry_ee_data<<=1; - jerry_ee_data|=data; - jerry_ee_data_cnt--; - if (!jerry_ee_data_cnt) - { - jerry_ee_state=jerry_ee_rstate; - if (jerry_ee_direct_jump) - eeprom_set_di(data); - } - break; - } + //fprintf(log_get(),"eeprom:\t\t\t%i bit %i\n",data,jerry_ee_data_cnt-1); + jerry_ee_data <<= 1; + jerry_ee_data |= data; + jerry_ee_data_cnt--; + if (!jerry_ee_data_cnt) + { + jerry_ee_state = jerry_ee_rstate; + if (jerry_ee_direct_jump) + eeprom_set_di(data); + } + break; case EE_READ_ADDRESS: - { - jerry_ee_address_data<<=1; - jerry_ee_address_data|=data; - jerry_ee_address_cnt--; -// fprintf(log_get(),"eeprom:\t%i bits remaining\n",jerry_ee_address_cnt); - if (!jerry_ee_address_cnt) - { - jerry_ee_state=jerry_ee_rstate; - //fprintf(log_get(),"eeprom:\t\tread address 0x%.2x\n",jerry_ee_address_data); - if (jerry_ee_direct_jump) - eeprom_set_di(data); - } - break; - } - default: { - jerry_ee_state=EE_STATE_OP_A; - break; - } - + jerry_ee_address_data <<= 1; + jerry_ee_address_data |= data; + jerry_ee_address_cnt--; +// fprintf(log_get(),"eeprom:\t%i bits remaining\n",jerry_ee_address_cnt); + if (!jerry_ee_address_cnt) + { + jerry_ee_state = jerry_ee_rstate; + //fprintf(log_get(),"eeprom:\t\tread address 0x%.2x\n",jerry_ee_address_data); + if (jerry_ee_direct_jump) + eeprom_set_di(data); + } + break; + default: + jerry_ee_state = EE_STATE_OP_A; } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void eeprom_set_cs(uint32 state) { // fprintf(log_get(),"eeprom: cs=%i\n",state); - jerry_ee_state=EE_STATE_START; - jerry_ee_op=0; - jerry_ee_rstate=0; - jerry_ee_address_data=0; - jerry_ee_address_cnt=6; - jerry_ee_data=0; - jerry_ee_data_cnt=16; - jerry_writes_enabled=1; + jerry_ee_state = EE_STATE_START; + jerry_ee_op = 0; + jerry_ee_rstate = 0; + jerry_ee_address_data = 0; + jerry_ee_address_cnt = 6; + jerry_ee_data = 0; + jerry_ee_data_cnt = 16; + jerry_writes_enabled = 1; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint32 eeprom_get_do(void) { - uint16 data=1; + uint16 data = 1; + switch (jerry_ee_state) { - case EE_STATE_START: { - data=1; - break; - } - case EE_STATE_BUSY: { - jerry_ee_state=EE_STATE_START; - data=0; - break; - } - case EE_STATE_2_0: { - jerry_ee_data_cnt--; - data=((eeprom_ram[jerry_ee_address_data]&(1<>jerry_ee_data_cnt); - if (!jerry_ee_data_cnt) - { - //fprintf(log_get(),"eeprom: read 0x%.4x at 0x%.2x cpu %i pc=0x%.8x\n",eeprom_ram[jerry_ee_address_data],jerry_ee_address_data,jaguar_cpu_in_exec,s68000readPC()); - jerry_ee_state=EE_STATE_START; - } - break; - } + case EE_STATE_START: + data = 1; + break; + case EE_STATE_BUSY: + jerry_ee_state = EE_STATE_START; + data = 0; + break; + case EE_STATE_2_0: + jerry_ee_data_cnt--; + data = (eeprom_ram[jerry_ee_address_data] & (1 << jerry_ee_data_cnt)) >> jerry_ee_data_cnt; + if (!jerry_ee_data_cnt) + { + //fprintf(log_get(),"eeprom: read 0x%.4x at 0x%.2x cpu %i pc=0x%.8x\n",eeprom_ram[jerry_ee_address_data],jerry_ee_address_data,jaguar_cpu_in_exec,s68000readPC()); + jerry_ee_state = EE_STATE_START; + } + break; } + // fprintf(log_get(),"eeprom: do=%i\n",data); - return(data); + return data; } diff --git a/src/gpu.cpp b/src/gpu.cpp index 38d13c6..f9e505b 100644 --- a/src/gpu.cpp +++ b/src/gpu.cpp @@ -1,15 +1,14 @@ -////////////////////////////////////////////////////////////////////////////// // -////////////////////////////////////////////////////////////////////////////// +// GPU Core // +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups, endian wrongness, and bad ASM amelioration by James L. Hammons +// Note: Endian wrongness probably stems from the MAME origins of this emu and +// the braindead way in which MAME handles memory. :-) // -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -#include "include/gpu.h" +#include "gpu.h" #define CINT0FLAG 0x00200 #define CINT1FLAG 0x00400 @@ -20,7 +19,6 @@ extern int start_logging; - static void gpu_opcode_add(void); static void gpu_opcode_addc(void); static void gpu_opcode_addq(void); @@ -155,7 +153,7 @@ static uint32 * gpu_reg_bank_1; static uint32 gpu_opcode_first_parameter; static uint32 gpu_opcode_second_parameter; -#define gpu_running (gpu_control&0x01) +#define GPU_RUNNING (gpu_control & 0x01) #define Rm gpu_reg[gpu_opcode_first_parameter] #define Rn gpu_reg[gpu_opcode_second_parameter] @@ -164,12 +162,23 @@ static uint32 gpu_opcode_second_parameter; #define imm_1 gpu_opcode_first_parameter #define imm_2 gpu_opcode_second_parameter -#define set_flag_z(r) gpu_flag_z=(r==0); -#define set_flag_n(r) gpu_flag_n=((r&0x80000000)>>31); +#define set_flag_z(r) gpu_flag_z = (r==0); +#define set_flag_n(r) gpu_flag_n = ((r&0x80000000)>>31); + +#define reset_flag_z() gpu_flag_z = 0; +#define reset_flag_n() gpu_flag_n = 0; +#define reset_flag_c() gpu_flag_c = 0; -#define reset_flag_z() gpu_flag_z=0; -#define reset_flag_n() gpu_flag_n=0; -#define reset_flag_c() gpu_flag_c=0; +#define CLR_Z (gpu_flag_z = 0) +#define CLR_ZN (gpu_flag_z = gpu_flag_n = 0) +#define CLR_ZNC (gpu_flag_z = gpu_flag_n = gpu_flag_c = 0) +#define SET_Z(r) (gpu_flag_z = ((r) == 0)) +#define SET_N(r) (gpu_flag_n = (((UINT32)(r) >> 31) & 0x01)) +#define SET_C_ADD(a,b) (gpu_flag_c = ((UINT32)(b) > (UINT32)(~(a)))) +#define SET_C_SUB(a,b) (gpu_flag_c = ((UINT32)(b) > (UINT32)(a))) +#define SET_ZN(r) SET_N(r); SET_Z(r) +#define SET_ZNC_ADD(a,b,r) SET_N(r); SET_Z(r); SET_C_ADD(a,b) +#define SET_ZNC_SUB(a,b,r) SET_N(r); SET_Z(r); SET_C_SUB(a,b) uint32 gpu_convert_zero[32] = { 32,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 }; @@ -203,44 +212,17 @@ char *gpu_opcode_str[64]= static uint32 gpu_in_exec = 0; static uint32 gpu_releaseTimeSlice_flag = 0; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void gpu_releaseTimeslice(void) { gpu_releaseTimeSlice_flag = 1; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint32 gpu_get_pc(void) { return gpu_pc; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void build_branch_condition_table(void) { #define ZFLAG 0x00001 @@ -311,7 +293,7 @@ unsigned gpu_word_read(unsigned int offset) if ((offset >= gpu_work_ram_base) && (offset < gpu_work_ram_base+0x1000)) { offset &= 0xFFF; - uint16 data = (((uint16)gpu_ram_8[offset]) << 8) | (uint16)gpu_ram_8[offset+1]; + uint16 data = ((uint16)gpu_ram_8[offset] << 8) | (uint16)gpu_ram_8[offset+1]; return data; } else if ((offset >= gpu_control_ram_base) && (offset < gpu_control_ram_base+0x20)) @@ -518,10 +500,10 @@ void gpu_long_write(unsigned offset, unsigned data) break; case 0x14: { - uint32 gpu_was_running = gpu_running; + uint32 gpu_was_running = GPU_RUNNING; data &= (~0x7C0); // disable writes to irq pending - /*if (gpu_running) + /*if (GPU_RUNNING) { fprintf(log_get(),"gpu pc is 0x%.8x\n",gpu_pc); fclose(log_get()); @@ -573,12 +555,18 @@ void gpu_long_write(unsigned offset, unsigned data) // if gpu wasn't running but is now running, execute a few cycles #ifndef GPU_SINGLE_STEPPING - if ((!gpu_was_running) && (gpu_running)) + if ((!gpu_was_running) && (GPU_RUNNING)) gpu_exec(200); #else if (gpu_control & 0x18) gpu_exec(1); -#endif +#endif // #ifndef GPU_SINGLE_STEPPING +#ifdef GPU_DEBUG +fprintf(log_get(), "Write to GPU CTRL: %08X ", data); +if (GPU_RUNNING) + fprintf(log_get(), "-- Starting to run at %08X...", gpu_pc); +fprintf(log_get(), "\n"); +#endif // #ifdef GPU_DEBUG break; } case 0x18: @@ -597,16 +585,7 @@ void gpu_long_write(unsigned offset, unsigned data) jaguar_word_write(offset, (data >> 16) & 0xFFFF); jaguar_word_write(offset+2, data & 0xFFFF); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void gpu_update_register_banks(void) { uint32 temp; @@ -656,16 +635,7 @@ void gpu_update_register_banks(void) // fprintf(log_get(),"\tnot switching banks\n"); // } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void gpu_check_irqs(void) { int bits, mask, which = 0; @@ -715,16 +685,7 @@ void gpu_check_irqs(void) gpu_pc += which * 0x10; gpu_reg[30] = gpu_pc; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void gpu_set_irq_line(int irqline, int state) { if (start_logging) @@ -738,16 +699,7 @@ void gpu_set_irq_line(int irqline, int state) gpu_check_irqs(); } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void gpu_init(void) { memory_malloc_secure((void **)&gpu_ram_8, 0x1000, "GPU work ram"); @@ -761,16 +713,7 @@ void gpu_init(void) gpu_reset(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void gpu_reset(void) { gpu_pc = 0x00F03000; @@ -808,61 +751,32 @@ void gpu_reset(void) gpu_reset_stats(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint32 gpu_read_pc(void) { return gpu_pc; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void gpu_reset_stats(void) { for(uint32 i=0; i<64; i++) gpu_opcode_use[i] = 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void gpu_done(void) { - int i, j; - fprintf(log_get(),"gpu: stopped at pc=0x%.8x (gpu %s running)\n",gpu_pc,gpu_running?"was":"wasn't"); - int bits, mask; + fprintf(log_get(), "GPU: stopped at PC=%08X (GPU %s running)\n", gpu_pc, GPU_RUNNING ? "was" : "wasn't"); // get the active interrupt bits - bits = (gpu_control >> 6) & 0x1F; + int bits = (gpu_control >> 6) & 0x1F; bits |= (gpu_control >> 10) & 0x20; // get the interrupt mask - mask = (gpu_flags >> 4) & 0x1F; + int mask = (gpu_flags >> 4) & 0x1F; mask |= (gpu_flags >> 11) & 0x20; - fprintf(log_get(),"gpu: bits=0x%.8x mask=0x%.8x\n",bits,mask); + fprintf(log_get(), "GPU: ibits=0x%.8x imask=0x%.8x\n", bits, mask); // fprintf(log_get(),"\nregisters bank 0\n"); // for (int j=0;j<8;j++) // { @@ -883,9 +797,9 @@ void gpu_done(void) // (j<<2)+3,gpu_alternate_reg[(j<<2)+3]); // // } -// fprintf(log_get(),"---[GPU code at 0x00f03000]---------------------------\n"); + fprintf(log_get(),"---[GPU code at 00F03000]---------------------------\n"); static char buffer[512]; - j = 0xF03000; + int j = 0xF03000; for(int i=0; i<4096; i++) { uint32 oldj = j; @@ -895,7 +809,7 @@ void gpu_done(void) fprintf(log_get(), "---[GPU code at %08X]---------------------------\n", gpu_pc); j = gpu_pc - 64; - for(i=0; i<4096; i++) + for(int i=0; i<4096; i++) { uint32 oldj = j; j += dasmjag(JAGUAR_GPU, buffer, j); @@ -903,26 +817,21 @@ void gpu_done(void) } fprintf(log_get(), "gpu opcodes use:\n"); - for(i=0; i<64; i++) + for(int i=0; i<64; i++) { if (gpu_opcode_use[i]) fprintf(log_get(), "\t%s %lu\n", gpu_opcode_str[i], gpu_opcode_use[i]); } memory_free(gpu_ram_8); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// + // +// Main GPU execution core // -////////////////////////////////////////////////////////////////////////////// + void gpu_exec(int32 cycles) { - if (!gpu_running) + if (!GPU_RUNNING) return; #ifdef GPU_SINGLE_STEPPING @@ -936,17 +845,20 @@ void gpu_exec(int32 cycles) gpu_releaseTimeSlice_flag = 0; gpu_in_exec++; - while ((cycles > 0) && gpu_running) + while ((cycles > 0) && GPU_RUNNING) { gpu_flag_c = (gpu_flag_c ? 1 : 0); gpu_flag_z = (gpu_flag_z ? 1 : 0); gpu_flag_n = (gpu_flag_n ? 1 : 0); uint16 opcode = gpu_word_read(gpu_pc); +/*static char buffer[512]; +dasmjag(JAGUAR_GPU, buffer, gpu_pc); +fprintf(log_get(), "GPU: [%08X] %s\n", gpu_pc, buffer);*/ uint32 index = opcode >> 10; - gpu_opcode_first_parameter = (opcode & 0x3E0) >> 5; - gpu_opcode_second_parameter = (opcode & 0x1F); + gpu_opcode_first_parameter = (opcode >> 5) & 0x1F; + gpu_opcode_second_parameter = opcode & 0x1F; gpu_pc += 2; gpu_opcode[index](); cycles -= gpu_opcode_cycles[index]; @@ -955,16 +867,11 @@ void gpu_exec(int32 cycles) gpu_in_exec--; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// + // +// GPU opcodes // -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_jump(void) { uint32 delayed_pc = Rm; @@ -983,16 +890,7 @@ static void gpu_opcode_jump(void) gpu_pc = delayed_pc; } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_jr(void) { int32 offset=(imm_1&0x10) ? (0xFFFFFFF0|imm_1) : imm_1; @@ -1013,31 +911,43 @@ static void gpu_opcode_jr(void) gpu_pc=delayed_pc; } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_add(void) { uint32 _Rm=Rm; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* uint32 index = opcode >> 10; + gpu_opcode_first_parameter = (opcode & 0x3E0) >> 5; + gpu_opcode_second_parameter = (opcode & 0x1F); + gpu_pc += 2; + gpu_opcode[index](); + cycles -= gpu_opcode_cycles[index]; + gpu_opcode_use[index]++;*/ +/* int dreg = jaguar.op & 31; + UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 + r1; + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZNC_ADD(r2,r1,res);*/ + + UINT32 res = Rn + Rm; + CLR_ZNC; SET_ZNC_ADD(Rn, Rm, res); + Rn = res; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - - #ifdef __GCCWIN32__ + +#ifdef __GCCWIN32__ asm( "addl %1, %2 \n\ @@ -1049,7 +959,7 @@ static void gpu_opcode_add(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "addl %1, %2 \n\ @@ -1061,7 +971,8 @@ static void gpu_opcode_add(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -1074,26 +985,31 @@ static void gpu_opcode_add(void) sets [gpu_flag_n] mov res,eax }; -#endif +#endif // #ifdef __PORT__ Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_addc(void) { uint32 _Rm=Rm; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 + r1 + ((jaguar.FLAGS >> 1) & 1); + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZNC_ADD(r2,r1,res);*/ + UINT32 res = Rn + Rm + gpu_flag_c; + CLR_ZNC; SET_ZNC_ADD(Rn, Rm, res); + Rn = res; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -1101,7 +1017,7 @@ static void gpu_opcode_addc(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "addl %1, %2 \n\ @@ -1119,7 +1035,7 @@ static void gpu_opcode_addc(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "addl %1, %2 \n\ @@ -1137,7 +1053,8 @@ static void gpu_opcode_addc(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -1158,23 +1075,28 @@ gpu_opcode_addc_no_carry: #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_addq(void) { uint32 _Rn=Rn; uint32 _Rm=gpu_convert_zero[imm_1]; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r1 = convert_zero[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 + r1; + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZNC_ADD(r2,r1,res);*/ + UINT32 r1 = gpu_convert_zero[imm_1]; + UINT32 res = Rn + r1; + CLR_ZNC; SET_ZNC_ADD(Rn, r1, res); + Rn = res; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -1182,7 +1104,7 @@ static void gpu_opcode_addq(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "addl %1, %2 \n\ @@ -1194,7 +1116,7 @@ static void gpu_opcode_addq(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "addl %1, %2 \n\ @@ -1206,7 +1128,8 @@ static void gpu_opcode_addq(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -1222,37 +1145,32 @@ static void gpu_opcode_addq(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_addqt(void) { Rn += gpu_convert_zero[imm_1]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_sub(void) { uint32 _Rm=Rm; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 - r1; + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZNC_SUB(r2,r1,res);*/ + UINT32 res = Rn - Rm; + CLR_ZNC; SET_ZNC_SUB(Rn, Rm, res); + Rn = res; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -1260,7 +1178,7 @@ static void gpu_opcode_sub(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "subl %1, %2 \n\ @@ -1272,7 +1190,7 @@ static void gpu_opcode_sub(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "subl %1, %2 \n\ @@ -1284,7 +1202,8 @@ static void gpu_opcode_sub(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -1300,23 +1219,27 @@ static void gpu_opcode_sub(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_subc(void) { uint32 _Rm=Rm; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 - r1 - ((jaguar.FLAGS >> 1) & 1); + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZNC_SUB(r2,r1,res);*/ + UINT32 res = Rn - Rm - gpu_flag_c; + CLR_ZNC; SET_ZNC_SUB(Rn, Rm, res); + Rn = res; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -1324,7 +1247,7 @@ static void gpu_opcode_subc(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "addl %1, %2 \n\ @@ -1342,7 +1265,7 @@ static void gpu_opcode_subc(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "addl %1, %2 \n\ @@ -1360,7 +1283,8 @@ static void gpu_opcode_subc(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -1381,23 +1305,28 @@ gpu_opcode_subc_no_carry: #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_subq(void) { uint32 _Rm=gpu_convert_zero[imm_1]; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r1 = convert_zero[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 - r1; + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZNC_SUB(r2,r1,res);*/ + UINT32 r1 = gpu_convert_zero[imm_1]; + UINT32 res = Rn - r1; + CLR_ZNC; SET_ZNC_SUB(Rn, r1, res); + Rn = res; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -1405,7 +1334,7 @@ static void gpu_opcode_subq(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "subl %1, %2 \n\ @@ -1417,7 +1346,7 @@ static void gpu_opcode_subq(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "subl %1, %2 \n\ @@ -1429,7 +1358,8 @@ static void gpu_opcode_subq(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -1445,35 +1375,28 @@ static void gpu_opcode_subq(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_subqt(void) { Rn -= gpu_convert_zero[imm_1]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_cmp(void) { uint32 _Rm=Rm; uint32 _Rn=Rn; #ifdef __PORT__ +#ifndef USE_ASSEMBLY +{ +/* UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[jaguar.op & 31]; + UINT32 res = r2 - r1; + CLR_ZNC; SET_ZNC_SUB(r2,r1,res);*/ + UINT32 res = Rn - Rm; + CLR_ZNC; SET_ZNC_SUB(Rn, Rm, res); + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared @@ -1482,7 +1405,7 @@ static void gpu_opcode_cmp(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "cmpl %0, %1 \n\ @@ -1493,7 +1416,7 @@ static void gpu_opcode_cmp(void) : : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "cmpl %0, %1 \n\ @@ -1504,7 +1427,8 @@ static void gpu_opcode_cmp(void) : : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -1518,23 +1442,26 @@ static void gpu_opcode_cmp(void) }; #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_cmpq(void) { - static int32 sqtable[32] = { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1}; + static int32 sqtable[32] = + { 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,-16,-15,-14,-13,-12,-11,-10,-9,-8,-7,-6,-5,-4,-3,-2,-1 }; int32 _Rm=sqtable[imm_1&0x1f]; uint32 _Rn=Rn; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* UINT32 r1 = (INT8)(jaguar.op >> 2) >> 3; + UINT32 r2 = jaguar.r[jaguar.op & 31]; + UINT32 res = r2 - r1; + CLR_ZNC; SET_ZNC_SUB(r2,r1,res);*/ + UINT32 r1 = sqtable[imm_1 & 0x1F]; // I like this better -> (INT8)(jaguar.op >> 2) >> 3; + UINT32 res = Rn - r1; + CLR_ZNC; SET_ZNC_SUB(Rn, r1, res); + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -1542,7 +1469,7 @@ static void gpu_opcode_cmpq(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "cmpl %0, %1 \n\ @@ -1553,7 +1480,7 @@ static void gpu_opcode_cmpq(void) : : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "cmpl %0, %1 \n\ @@ -1564,7 +1491,9 @@ static void gpu_opcode_cmpq(void) : : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY + #else __asm { @@ -1577,22 +1506,27 @@ static void gpu_opcode_cmpq(void) }; #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_and(void) { uint32 _Rm=Rm; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 & r1; + jaguar.r[dreg] = res; + CLR_ZN; SET_ZN(res);*/ + UINT32 res = Rn & Rm; + Rn = res; + CLR_ZN; SET_ZN(res); + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared @@ -1601,7 +1535,7 @@ static void gpu_opcode_and(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "andl %1, %2 \n\ @@ -1612,7 +1546,7 @@ static void gpu_opcode_and(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "andl %1, %2 \n\ @@ -1623,7 +1557,9 @@ static void gpu_opcode_and(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY + #else __asm { @@ -1637,23 +1573,27 @@ static void gpu_opcode_and(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_or(void) { uint32 _Rm=Rm; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r1 | r2; + jaguar.r[dreg] = res; + CLR_ZN; SET_ZN(res);*/ + UINT32 res = Rn | Rm; + Rn = res; + CLR_ZN; SET_ZN(res); + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -1661,7 +1601,7 @@ static void gpu_opcode_or(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "orl %1, %2 \n\ @@ -1672,7 +1612,7 @@ static void gpu_opcode_or(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "orl %1, %2 \n\ @@ -1683,7 +1623,9 @@ static void gpu_opcode_or(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY + #else __asm { @@ -1697,23 +1639,27 @@ static void gpu_opcode_or(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_xor(void) { uint32 _Rm=Rm; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r1 ^ r2; + jaguar.r[dreg] = res; + CLR_ZN; SET_ZN(res);*/ + UINT32 res = Rn ^ Rm; + Rn = res; + CLR_ZN; SET_ZN(res); + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -1721,7 +1667,7 @@ static void gpu_opcode_xor(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "xorl %1, %2 \n\ @@ -1732,7 +1678,7 @@ static void gpu_opcode_xor(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #else +#else asm( "xorl %1, %2 \n\ @@ -1743,7 +1689,9 @@ static void gpu_opcode_xor(void) : "=m"(res) : "d"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY + #else __asm { @@ -1757,22 +1705,24 @@ static void gpu_opcode_xor(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_not(void) { uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 res = ~jaguar.r[dreg]; + jaguar.r[dreg] = res; + CLR_ZN; SET_ZN(res);*/ + UINT32 res = ~Rn; + Rn = res; + CLR_ZN; SET_ZN(res); + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -1780,7 +1730,7 @@ static void gpu_opcode_not(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "notl %1 \n\ @@ -1791,7 +1741,7 @@ static void gpu_opcode_not(void) : "=m"(res) : "a"(_Rn)); - #else +#else asm( "notl %1 \n\ @@ -1802,7 +1752,9 @@ static void gpu_opcode_not(void) : "=m"(res) : "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY + #else __asm { @@ -1815,30 +1767,12 @@ static void gpu_opcode_not(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_move_pc(void) { Rn = gpu_pc-2; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_sat8(void) { int32 _Rn=(int32)Rn; @@ -1847,16 +1781,7 @@ static void gpu_opcode_sat8(void) set_flag_z(res); reset_flag_n(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_sat16(void) { int32 _Rn=(int32)Rn; @@ -1864,16 +1789,7 @@ static void gpu_opcode_sat16(void) set_flag_z(res); reset_flag_n(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_sat24(void) { int32 _Rn=(int32)Rn; @@ -1882,113 +1798,41 @@ static void gpu_opcode_sat24(void) set_flag_z(res); reset_flag_n(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_store_r14_indexed(void) { gpu_long_write( gpu_reg[14] + (gpu_convert_zero[imm_1] << 2),Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_store_r15_indexed(void) { gpu_long_write( gpu_reg[15] + (gpu_convert_zero[imm_1] << 2),Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_load_r14_ri(void) { Rn=gpu_long_read(gpu_reg[14] + Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_load_r15_ri(void) { Rn=gpu_long_read(gpu_reg[15] + Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_store_r14_ri(void) { gpu_long_write(gpu_reg[14] + Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_store_r15_ri(void) { gpu_long_write(gpu_reg[15] + Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_nop(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_pack(void) { uint32 _Rn=Rn; @@ -2010,16 +1854,7 @@ static void gpu_opcode_pack(void) set_flag_z(Rn); set_flag_n(Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_storeb(void) { if ((Rm >= 0xF03000) && (Rm < 0xF04000)) @@ -2027,16 +1862,7 @@ static void gpu_opcode_storeb(void) else jaguar_byte_write(Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_storew(void) { if ((Rm >= 0xF03000) && (Rm < 0xF04000)) @@ -2044,46 +1870,19 @@ static void gpu_opcode_storew(void) else jaguar_word_write(Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_store(void) { gpu_long_write(Rm,Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_storep(void) { uint32 _Rm=Rm; gpu_long_write(_Rm, gpu_hidata); gpu_long_write(_Rm+4, Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_loadb(void) { if ((Rm >= 0xF03000) && (Rm < 0xF04000)) @@ -2091,16 +1890,7 @@ static void gpu_opcode_loadb(void) else Rn=jaguar_byte_read(Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_loadw(void) { if ((Rm >= 0xF03000) && (Rm < 0xF04000)) @@ -2108,30 +1898,12 @@ static void gpu_opcode_loadw(void) else Rn=jaguar_word_read(Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_load(void) { Rn = gpu_long_read(Rm); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_loadp(void) { uint32 _Rm=Rm; @@ -2139,168 +1911,82 @@ static void gpu_opcode_loadp(void) gpu_hidata = gpu_long_read(_Rm); Rn = gpu_long_read(_Rm+4); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_load_r14_indexed(void) { Rn = gpu_long_read( gpu_reg[14] + (gpu_convert_zero[imm_1] << 2)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_load_r15_indexed(void) { Rn = gpu_long_read( gpu_reg[15] + (gpu_convert_zero[imm_1] << 2)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_movei(void) { - Rn = ((uint32)gpu_word_read(gpu_pc)) + (((uint32)gpu_word_read(gpu_pc+2))<<16); - gpu_pc+=4; -} -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + Rn = (uint32)gpu_word_read(gpu_pc) | ((uint32)gpu_word_read(gpu_pc + 2) << 16); + gpu_pc += 4; +} + static void gpu_opcode_moveta(void) { alternate_Rn = Rm; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_movefa(void) { Rn = alternate_Rm; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_move(void) { Rn = Rm; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_moveq(void) { Rn = imm_1; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_resmac(void) { Rn = gpu_acc; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_imult(void) { uint32 res=Rn=((int16)Rn)*((int16)Rm); set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_mult(void) { uint32 res=Rn = ((uint16)Rm) * ((uint16)Rn); set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_bclr(void) { uint32 _Rm=imm_1; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r1 = (jaguar.op >> 5) & 31; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 & ~(1 << r1); + jaguar.r[dreg] = res; + CLR_ZN; SET_ZN(res);*/ + UINT32 res = Rn & ~(1 << imm_1); + Rn = res; + CLR_ZN; SET_ZN(res); + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -2308,7 +1994,7 @@ static void gpu_opcode_bclr(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "btrl %1, %2 \n\ @@ -2320,7 +2006,7 @@ static void gpu_opcode_bclr(void) : "=m"(res) : "c"(_Rm), "a"(_Rn)); - #else +#else asm( "btrl %1, %2 \n\ @@ -2332,7 +2018,8 @@ static void gpu_opcode_bclr(void) : "=m"(res) : "c"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -2348,22 +2035,21 @@ static void gpu_opcode_bclr(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_btst(void) { uint32 _Rm=imm_1; uint32 _Rn=Rn; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* UINT32 r1 = (jaguar.op >> 5) & 31; + UINT32 r2 = jaguar.r[jaguar.op & 31]; + CLR_Z; jaguar.FLAGS |= (~r2 >> r1) & 1;*/ + CLR_Z; gpu_flag_z = (~Rn >> imm_1) & 1; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -2371,7 +2057,7 @@ static void gpu_opcode_btst(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "bt %0, %1 \n\ @@ -2380,7 +2066,7 @@ static void gpu_opcode_btst(void) : : "c"(_Rm), "a"(_Rn)); - #else +#else asm( "bt %0, %1 \n\ @@ -2389,7 +2075,9 @@ static void gpu_opcode_btst(void) : : "c"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY + #else __asm { @@ -2400,23 +2088,27 @@ static void gpu_opcode_btst(void) }; #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_bset(void) { uint32 _Rm=imm_1; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r1 = (jaguar.op >> 5) & 31; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 | (1 << r1); + jaguar.r[dreg] = res; + CLR_ZN; SET_ZN(res);*/ + UINT32 res = Rn | (1 << imm_1); + Rn = res; + CLR_ZN; SET_ZN(res); + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -2424,7 +2116,7 @@ static void gpu_opcode_bset(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "btsl %1, %2 \n\ @@ -2436,7 +2128,7 @@ static void gpu_opcode_bset(void) : "=m"(res) : "c"(_Rm), "a"(_Rn)); - #else +#else asm( "btsl %1, %2 \n\ @@ -2448,7 +2140,8 @@ static void gpu_opcode_bset(void) : "=m"(res) : "c"(_Rm), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -2464,31 +2157,13 @@ static void gpu_opcode_bset(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_imacn(void) { uint32 res = ((int16)Rm) * ((int16)(Rn)); gpu_acc += res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_mtoi(void) { uint32 _Rm=Rm; @@ -2496,16 +2171,7 @@ static void gpu_opcode_mtoi(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_normi(void) { uint32 _Rm = Rm; @@ -2513,12 +2179,12 @@ static void gpu_opcode_normi(void) if (_Rm) { - while ((_Rm & 0xffc00000) == 0) + while ((_Rm & 0xFFC00000) == 0) { _Rm <<= 1; res--; } - while ((_Rm & 0xff800000) != 0) + while ((_Rm & 0xFF800000) != 0) { _Rm >>= 1; res++; @@ -2528,19 +2194,10 @@ static void gpu_opcode_normi(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_mmult(void) { - int count = gpu_matrix_control&0x0f; + int count = gpu_matrix_control & 0x0F; uint32 addr = gpu_pointer_to_matrix; // in the gpu ram int64 accum = 0; uint32 res; @@ -2580,16 +2237,7 @@ static void gpu_opcode_mmult(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_abs(void) { uint32 _Rn=Rn; @@ -2607,16 +2255,7 @@ static void gpu_opcode_abs(void) set_flag_z(res); } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_div(void) { uint32 _Rm=Rm; @@ -2642,16 +2281,7 @@ static void gpu_opcode_div(void) else Rn=0xffffffff; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_imultn(void) { uint32 res = (int32)((int16)Rn * (int16)Rm); @@ -2659,22 +2289,25 @@ static void gpu_opcode_imultn(void) set_flag_z(res); set_flag_n(res); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_neg(void) { uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +{ +/* int dreg = jaguar.op & 31; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = -r2; + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZNC_SUB(0,r2,res);*/ + UINT32 res = -Rn; + CLR_ZNC; SET_ZNC_SUB(0, Rn, res); + Rn = res; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -2682,7 +2315,7 @@ static void gpu_opcode_neg(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "subl %1, %2 \n\ @@ -2694,7 +2327,7 @@ static void gpu_opcode_neg(void) : "=m"(res) : "d"(_Rn), "a"(0)); - #else +#else asm( "subl %1, %2 \n\ @@ -2706,7 +2339,9 @@ static void gpu_opcode_neg(void) : "=m"(res) : "d"(_Rn), "a"(0)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY + #else __asm { @@ -2721,23 +2356,28 @@ static void gpu_opcode_neg(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_shlq(void) { uint32 shift=(32-gpu_convert_zero[imm_1]); uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +/* int dreg = jaguar.op & 31; + INT32 r1 = convert_zero[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 << (32 - r1); + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZN(res); jaguar.FLAGS |= (r2 >> 30) & 2;*/ +{ + INT32 r1 = gpu_convert_zero[imm_1]; + UINT32 res = Rn << (32 - r1); + CLR_ZNC; SET_ZN(res); gpu_flag_c = (Rn >> 31) & 1; + Rn = res; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -2745,7 +2385,7 @@ static void gpu_opcode_shlq(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "testl $0x80000000, %2 \n\ @@ -2759,7 +2399,7 @@ static void gpu_opcode_shlq(void) : "=m"(res) : "c"(shift), "a"(_Rn)); - #else +#else asm( "testl $0x80000000, %2 \n\ @@ -2773,7 +2413,8 @@ static void gpu_opcode_shlq(void) : "=m"(res) : "c"(shift), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -2791,16 +2432,7 @@ static void gpu_opcode_shlq(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_shrq(void) { uint32 shift=gpu_convert_zero[imm_1]; @@ -2808,7 +2440,21 @@ static void gpu_opcode_shrq(void) uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +/* int dreg = jaguar.op & 31; + INT32 r1 = convert_zero[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = r2 >> r1; + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZN(res); jaguar.FLAGS |= (r2 << 1) & 2;*/ +{ + INT32 r1 = gpu_convert_zero[imm_1]; + UINT32 res = Rn >> r1; + CLR_ZNC; SET_ZN(res); gpu_flag_c = Rn & 1; + Rn = res; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -2816,7 +2462,7 @@ static void gpu_opcode_shrq(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "testl $0x00000001, %2 \n\ @@ -2830,7 +2476,7 @@ static void gpu_opcode_shrq(void) : "=m"(res) : "c"(shift), "a"(_Rn)); - #else +#else asm( "testl $0x00000001, %2 \n\ @@ -2844,7 +2490,9 @@ static void gpu_opcode_shrq(void) : "=m"(res) : "c"(shift), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY + #else __asm { @@ -2861,23 +2509,29 @@ static void gpu_opcode_shrq(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_ror(void) { uint32 shift=Rm; uint32 _Rn=Rn; uint32 res; #ifdef __PORT__ - +#ifndef USE_ASSEMBLY +//#ifndef __PORT__ // For testing... +/* int dreg = jaguar.op & 31; + UINT32 r1 = jaguar.r[(jaguar.op >> 5) & 31] & 31; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = (r2 >> r1) | (r2 << (32 - r1)); + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZN(res); jaguar.FLAGS |= (r2 >> 30) & 2;*/ +{ + UINT32 r1 = Rm & 0x1F; + UINT32 res = (Rn >> r1) | (Rn << (32 - r1)); + CLR_ZNC; SET_ZN(res); gpu_flag_c = (Rn >> 31) & 1; + Rn = res; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared variables in asm until we put a _ before it. @@ -2885,7 +2539,7 @@ static void gpu_opcode_ror(void) So the declaration dsp_flag_c needs to be _dsp_flag_c on mingw. */ - #ifdef __GCCWIN32__ +#ifdef __GCCWIN32__ asm( "testl $0x80000000, %2 \n\ @@ -2899,7 +2553,7 @@ static void gpu_opcode_ror(void) : "=m"(res) : "c"(shift), "a"(_Rn)); - #else +#else asm( "testl $0x80000000, %2 \n\ @@ -2913,7 +2567,8 @@ static void gpu_opcode_ror(void) : "=m"(res) : "c"(shift), "a"(_Rn)); - #endif +#endif // #ifdef __GCCWIN32__ +#endif // #ifndef USE_ASSEMBLY #else __asm @@ -2931,22 +2586,37 @@ static void gpu_opcode_ror(void) #endif Rn=res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_rorq(void) { uint32 shift = gpu_convert_zero[imm_1 & 0x1F]; uint32 _Rn = Rn; uint32 res; #ifdef __PORT__ +#ifndef USE_ASSEMBLY +/* uint32 index = opcode >> 10; + gpu_opcode_first_parameter = (opcode & 0x3E0) >> 5; + gpu_opcode_second_parameter = (opcode & 0x1F); + gpu_pc += 2; + gpu_opcode[index](); + cycles -= gpu_opcode_cycles[index]; + gpu_opcode_use[index]++;*/ + +/* int dreg = jaguar.op & 31; + UINT32 r1 = convert_zero[(jaguar.op >> 5) & 31]; + UINT32 r2 = jaguar.r[dreg]; + UINT32 res = (r2 >> r1) | (r2 << (32 - r1)); + jaguar.r[dreg] = res; + CLR_ZNC; SET_ZN(res); jaguar.FLAGS |= (r2 >> 30) & 2;*/ +{ + UINT32 r1 = gpu_convert_zero[imm_1 & 0x1F]; + UINT32 r2 = Rn; + UINT32 res = (r2 >> r1) | (r2 << (32 - r1)); + Rn = res; + CLR_ZNC; SET_ZN(res); gpu_flag_c = (r2 >> 31) & 0x01; + return; +} +#else /* GCC on WIN32 (more importantly mingw) doesn't know the declared @@ -2984,7 +2654,8 @@ static void gpu_opcode_rorq(void) : "c"(shift), "a"(_Rn)); #endif // #ifdef __GCCWIN32__ - +#endif // #ifndef USE_ASSEMBLY + #else __asm { @@ -3001,16 +2672,7 @@ static void gpu_opcode_rorq(void) #endif // #ifdef __PORT__ Rn = res; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_sha(void) { int32 sRm=(int32)Rm; @@ -3042,16 +2704,7 @@ static void gpu_opcode_sha(void) set_flag_z(_Rn); set_flag_n(_Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_sharq(void) { uint32 shift=gpu_convert_zero[imm_1]; @@ -3067,16 +2720,7 @@ static void gpu_opcode_sharq(void) set_flag_z(_Rn); set_flag_n(_Rn); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + static void gpu_opcode_sh(void) { int32 sRm=(int32)Rm; diff --git a/src/include/SDLptc.h b/src/include/SDLptc.h index 163421b..0827956 100644 --- a/src/include/SDLptc.h +++ b/src/include/SDLptc.h @@ -199,7 +199,8 @@ class Console: public Surface { Uint32 flags = SDL_SWSURFACE; - if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) +//Testing if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER) < 0) + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK | SDL_INIT_AUDIO | SDL_INIT_TIMER | SDL_INIT_NOPARACHUTE) < 0) throw Error(SDL_GetError()); const SDL_VideoInfo * info = SDL_GetVideoInfo(); // Let us get proper info about the platform. diff --git a/src/include/fbmpop16.h b/src/include/fbmpop16.h index 2564ccb..4b20593 100644 --- a/src/include/fbmpop16.h +++ b/src/include/fbmpop16.h @@ -1,112 +1,144 @@ - if (flags&FLAGS_READMODIFY) + if (flags & FLAGS_READMODIFY) { - if (flags&FLAGS_HFLIP) + if (flags & FLAGS_HFLIP) { while (iwidth) { - if (flags&FLAGS_TRANSPARENT) + uint8 dataHi = jaguar_byte_read(ptr++), dataLo = jaguar_byte_read(ptr++); + + if (flags & FLAGS_TRANSPARENT) { - uint16 data=jaguar_byte_read(ptr++); - data<<=8; - data|=jaguar_byte_read(ptr++); - if (data) +// uint16 data = jaguar_byte_read(ptr++); +// data <<= 8; +// data |= jaguar_byte_read(ptr++); +/* if (data) + { + *current_line_buffer-- = BLEND_Y(*current_line_buffer, data >> 8); + *current_line_buffer-- = BLEND_CC(*current_line_buffer, data & 0xFF); + }*/ + if (dataHi | dataLo) { - *current_line_buffer--=BLEND_Y(*current_line_buffer,(data>>8)); - *current_line_buffer--=BLEND_CC(*current_line_buffer,(data&0xff)); + *current_line_buffer-- = BLEND_Y(*current_line_buffer, dataHi); + *current_line_buffer-- = BLEND_CC(*current_line_buffer, dataLo); } else - current_line_buffer-=2; + current_line_buffer -= 2; } - else + else // !FLAGS_TRANSPARENT { - *current_line_buffer--=BLEND_Y(*current_line_buffer,jaguar_byte_read(ptr++)); - *current_line_buffer--=BLEND_CC(*current_line_buffer,jaguar_byte_read(ptr++)); +// *current_line_buffer-- = BLEND_Y(*current_line_buffer, jaguar_byte_read(ptr++)); +// *current_line_buffer-- = BLEND_CC(*current_line_buffer, jaguar_byte_read(ptr++)); + *current_line_buffer-- = BLEND_Y(*current_line_buffer, dataHi); + *current_line_buffer-- = BLEND_CC(*current_line_buffer, dataLo); } iwidth--; } } - else + else // !FLAGS_HFLIP { while (iwidth) { - if (flags&FLAGS_TRANSPARENT) + uint8 dataHi = jaguar_byte_read(ptr++), dataLo = jaguar_byte_read(ptr++); + + if (flags & FLAGS_TRANSPARENT) { - uint16 data=jaguar_byte_read(ptr++); - data<<=8; - data|=jaguar_byte_read(ptr++); +/* uint16 data = jaguar_byte_read(ptr++); + data <<= 8; + data |= jaguar_byte_read(ptr++); if (data) { - *current_line_buffer++=BLEND_Y(*current_line_buffer,(data>>8)); - *current_line_buffer++=BLEND_CC(*current_line_buffer,(data&0xff)); + *current_line_buffer++ = BLEND_Y(*current_line_buffer, data >> 8); + *current_line_buffer++ = BLEND_CC(*current_line_buffer, data & 0xFF); + }*/ + if (dataHi | dataLo) + { + *current_line_buffer++ = BLEND_Y(*current_line_buffer, dataHi); + *current_line_buffer++ = BLEND_CC(*current_line_buffer, dataLo); } else - current_line_buffer+=2; + current_line_buffer += 2; } else { - *current_line_buffer++=BLEND_Y(*current_line_buffer,jaguar_byte_read(ptr++)); - *current_line_buffer++=BLEND_CC(*current_line_buffer,jaguar_byte_read(ptr++)); +// *current_line_buffer++ = BLEND_Y(*current_line_buffer, jaguar_byte_read(ptr++)); +// *current_line_buffer++ = BLEND_CC(*current_line_buffer, jaguar_byte_read(ptr++)); + *current_line_buffer++ = BLEND_Y(*current_line_buffer, dataHi); + *current_line_buffer++ = BLEND_CC(*current_line_buffer, dataLo); } iwidth--; } } } - else + else // !FLAGS_READMODIFY { - if (flags&FLAGS_HFLIP) + if (flags & FLAGS_HFLIP) { while (iwidth) { - if (flags&FLAGS_TRANSPARENT) + uint8 dataHi = jaguar_byte_read(ptr++), dataLo = jaguar_byte_read(ptr++); + + if (flags & FLAGS_TRANSPARENT) { - uint16 data=jaguar_byte_read(ptr++); - data<<=8; - data|=jaguar_byte_read(ptr++); +/* uint16 data = jaguar_byte_read(ptr++); + data <<= 8; + data |= jaguar_byte_read(ptr++); if (data) { - *current_line_buffer--=(data>>8); - *current_line_buffer--=(data&0xff); - } + *current_line_buffer-- = data >> 8; + *current_line_buffer-- = data & 0xFF; + }*/ + if (dataHi | dataLo) + *current_line_buffer-- = dataHi, + *current_line_buffer-- = dataLo; else - current_line_buffer-=2; + current_line_buffer -= 2; } else { - *current_line_buffer--=jaguar_byte_read(ptr++); - *current_line_buffer--=jaguar_byte_read(ptr++); +// *current_line_buffer-- = jaguar_byte_read(ptr++); +// *current_line_buffer-- = jaguar_byte_read(ptr++); + *current_line_buffer-- = dataHi; + *current_line_buffer-- = dataLo; } iwidth--; } } - else + else // !FLAGS_HFLIP { - int count=0; + int count = 0; while (iwidth) { - if (flags&FLAGS_TRANSPARENT) - { - uint16 data=jaguar_byte_read(ptr++); - data<<=8; - data|=jaguar_byte_read(ptr++); + uint8 dataHi = jaguar_byte_read(ptr++), dataLo = jaguar_byte_read(ptr++); + + if (flags & FLAGS_TRANSPARENT) + { +/* uint16 data = jaguar_byte_read(ptr++); + data <<= 8; + data |= jaguar_byte_read(ptr++); if (data) { - *current_line_buffer++=(data>>8); - *current_line_buffer++=(data&0xff); - } + *current_line_buffer++ = data >> 8; + *current_line_buffer++ = data & 0xFF; + }*/ + if (dataHi | dataLo) + *current_line_buffer++ = dataHi, + *current_line_buffer++ = dataLo; else - current_line_buffer+=2; + current_line_buffer += 2; } else { - *current_line_buffer++=jaguar_byte_read(ptr++); - *current_line_buffer++=jaguar_byte_read(ptr++); +// *current_line_buffer++ = jaguar_byte_read(ptr++); +// *current_line_buffer++ = jaguar_byte_read(ptr++); + *current_line_buffer++ = dataHi; + *current_line_buffer++ = dataLo; } - count+=2; - if (count==8) // 8 bytes = a phrase (64 bits) + count += 2; + if (count == 8) // 8 bytes = a phrase (64 bits) { - ptr+=8*(pitch-1); - count=0; + ptr += 8 * (pitch - 1); + count = 0; } iwidth--; } diff --git a/src/include/jaguar.h b/src/include/jaguar.h index f35a69f..aeb449d 100644 --- a/src/include/jaguar.h +++ b/src/include/jaguar.h @@ -46,4 +46,9 @@ void jaguar_long_write(unsigned offset, unsigned data); uint32 jaguar_interrupt_handler_is_valid(uint32 i); void jaguar_dasm(uint32 offset, uint32 qt); +//Temp debug stuff + +void DumpMainMemory(void); +uint8 * GetRamPtr(void); + #endif // #ifndef __JAGUAR_H__ diff --git a/src/include/types.h b/src/include/types.h index 2ca0521..3ed734d 100644 --- a/src/include/types.h +++ b/src/include/types.h @@ -1,7 +1,3 @@ -// -// Useful types (platform specific) -// -// by cal16 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) // Removal of unsafe macros and addition of typdefs by James L. Hammons // diff --git a/src/include/wavetable.h b/src/include/wavetable.h index 5ce7c9d..8faffb9 100644 --- a/src/include/wavetable.h +++ b/src/include/wavetable.h @@ -255,4 +255,4 @@ const unsigned char wave_table[4096] = { 0x00, 0x00, 0x0A, 0xBC, 0xFF, 0xFF, 0xEC, 0xFD, 0x00, 0x00, 0x0E, 0xAA, 0xFF, 0xFF, 0xFC, 0x53, 0xFF, 0xFF, 0xFB, 0xFD, 0xFF, 0xFF, 0xF0, 0x58, 0x00, 0x00, 0x02, 0x91, 0xFF, 0xFF, 0xE3, 0x83, 0x00, 0x00, 0x18, 0x80, 0xFF, 0xFF, 0xF1, 0x35, 0xFF, 0xFF, 0xF3, 0x0C, 0xFF, 0xFF, 0xE6, 0xD6, - } ; + }; diff --git a/src/jagdasm.cpp b/src/jagdasm.cpp index eaeceeb..45ec567 100644 --- a/src/jagdasm.cpp +++ b/src/jagdasm.cpp @@ -64,22 +64,22 @@ unsigned dasmjag(int dsp_type, char *buffer, unsigned pc) pc += 2; switch (op >> 10) { - case 0: sprintf(buffer, "add r%d,r%d", reg1, reg2); break; - case 1: sprintf(buffer, "addc r%d,r%d", reg1, reg2); break; - case 2: sprintf(buffer, "addq $%x,r%d", convert_zero[reg1], reg2); break; + case 0: sprintf(buffer, "+add r%d,r%d", reg1, reg2); break; + case 1: sprintf(buffer, "+addc r%d,r%d", reg1, reg2); break; + case 2: sprintf(buffer, "+addq $%x,r%d", convert_zero[reg1], reg2); break; case 3: sprintf(buffer, "addqt $%x,r%d", convert_zero[reg1], reg2); break; - case 4: sprintf(buffer, "sub r%d,r%d", reg1, reg2); break; - case 5: sprintf(buffer, "subc r%d,r%d", reg1, reg2); break; - case 6: sprintf(buffer, "subq $%x,r%d", convert_zero[reg1], reg2); break; + case 4: sprintf(buffer, "+sub r%d,r%d", reg1, reg2); break; + case 5: sprintf(buffer, "+subc r%d,r%d", reg1, reg2); break; + case 6: sprintf(buffer, "+subq $%x,r%d", convert_zero[reg1], reg2); break; case 7: sprintf(buffer, "subqt $%x,r%d", convert_zero[reg1], reg2); break; - case 8: sprintf(buffer, "neg r%d", reg2); break; - case 9: sprintf(buffer, "and r%d,r%d", reg1, reg2); break; - case 10: sprintf(buffer, "or r%d,r%d", reg1, reg2); break; - case 11: sprintf(buffer, "xor r%d,r%d", reg1, reg2); break; - case 12: sprintf(buffer, "not r%d", reg2); break; - case 13: sprintf(buffer, "btst $%x,r%d", reg1, reg2); break; - case 14: sprintf(buffer, "bset $%x,r%d", reg1, reg2); break; - case 15: sprintf(buffer, "bclr $%x,r%d", reg1, reg2); break; + case 8: sprintf(buffer, "+neg r%d", reg2); break; + case 9: sprintf(buffer, "+and r%d,r%d", reg1, reg2); break; + case 10: sprintf(buffer, "+or r%d,r%d", reg1, reg2); break; + case 11: sprintf(buffer, "+xor r%d,r%d", reg1, reg2); break; + case 12: sprintf(buffer, "+not r%d", reg2); break; + case 13: sprintf(buffer, "+btst $%x,r%d", reg1, reg2); break; + case 14: sprintf(buffer, "+bset $%x,r%d", reg1, reg2); break; + case 15: sprintf(buffer, "+bclr $%x,r%d", reg1, reg2); break; case 16: sprintf(buffer, "mult r%d,r%d", reg1, reg2); break; case 17: sprintf(buffer, "imult r%d,r%d", reg1, reg2); break; case 18: sprintf(buffer, "imultn r%d,r%d", reg1, reg2); break; @@ -88,14 +88,14 @@ unsigned dasmjag(int dsp_type, char *buffer, unsigned pc) case 21: sprintf(buffer, "div r%d,r%d", reg1, reg2); break; case 22: sprintf(buffer, "abs r%d", reg2); break; case 23: sprintf(buffer, "sh r%d,r%d", reg1, reg2); break; - case 24: sprintf(buffer, "shlq $%x,r%d", 32 - convert_zero[reg1], reg2); break; - case 25: sprintf(buffer, "shrq $%x,r%d", convert_zero[reg1], reg2); break; + case 24: sprintf(buffer, "+shlq $%x,r%d", 32 - convert_zero[reg1], reg2); break; + case 25: sprintf(buffer, "+shrq $%x,r%d", convert_zero[reg1], reg2); break; case 26: sprintf(buffer, "sha r%d,r%d", reg1, reg2); break; case 27: sprintf(buffer, "sharq $%x,r%d", convert_zero[reg1], reg2); break; - case 28: sprintf(buffer, "ror r%d,r%d", reg1, reg2); break; + case 28: sprintf(buffer, "+ror r%d,r%d", reg1, reg2); break; case 29: sprintf(buffer, "rorq $%x,r%d", convert_zero[reg1], reg2); break; - case 30: sprintf(buffer, "cmp r%d,r%d", reg1, reg2); break; - case 31: sprintf(buffer, "cmpq %s,r%d", signed_16bit((INT16)(reg1 << 11) >> 11), reg2);break; + case 30: sprintf(buffer, "+cmp r%d,r%d", reg1, reg2); break; + case 31: sprintf(buffer, "+cmpq %s,r%d", signed_16bit((INT16)(reg1 << 11) >> 11), reg2);break; case 32: if (dsp_type == JAGUAR_GPU) sprintf(buffer, "sat8 r%d", reg2); else diff --git a/src/jaguar.cpp b/src/jaguar.cpp index 429f76a..74c1de4 100644 --- a/src/jaguar.cpp +++ b/src/jaguar.cpp @@ -1,7 +1,7 @@ // // JAGUAR.CPP // -// by cal16 +// by cal2 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) // Cleanups and endian wrongness amelioration by James L. Hammons // Note: Endian wrongness probably stems from the MAME origins of this emu and @@ -40,26 +40,15 @@ uint32 jaguar_use_bios = 0; #define JAGUAR_WIP_RELEASE #define JAGUAR_REAL_SPEED - -////////////////////////////////////////////////////////////////////////////// -// Bios path -////////////////////////////////////////////////////////////////////////////// -// // +// Bios path // -////////////////////////////////////////////////////////////////////////////// + //static char *jaguar_bootRom_path="c:/jaguarEmu/newload.img"; static char * jaguar_bootRom_path = "./bios/jagboot.rom"; //static char *jaguar_bootRom_path="./bios/JagOS.bin"; char * jaguar_eeproms_path = "./eeproms/"; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// uint32 jaguar_mainRom_crc32; static uint32 m68k_cycles_per_scanline; @@ -70,7 +59,6 @@ static uint32 jaguar_screen_scanlines; static uint8 * jaguar_mainRam = NULL; static uint8 * jaguar_bootRom = NULL; static uint8 * jaguar_mainRom = NULL; -////////////////////////////////////////////////////////////////////////////// // @@ -90,7 +78,7 @@ int irq_ack_handler(int level) return vector; } -//Do this in makefile??? +//Do this in makefile??? Yes! //#define LOG_UNMAPPED_MEMORY_ACCESSES 1 unsigned int m68k_read_memory_8(unsigned int address) @@ -188,17 +176,6 @@ void m68k_write_memory_32(unsigned int address, unsigned int value) m68k_write_memory_16(address + 2, value & 0xFFFF); } -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// -/*struct STARSCREAM_PROGRAMREGION *jaguar_programfetch; -struct STARSCREAM_DATAREGION *jaguar_readbyte; -struct STARSCREAM_DATAREGION *jaguar_readword; -struct STARSCREAM_DATAREGION *jaguar_writebyte; -struct STARSCREAM_DATAREGION *jaguar_writeword; -UINT16 jaguar_regionsCount[6];*/ ////////////////////////////////////////////////////////////////////////////// // @@ -210,7 +187,8 @@ UINT16 jaguar_regionsCount[6];*/ uint32 jaguar_get_handler(uint32 i) { // return (jaguar_word_read(i<<2) << 16) | jaguar_word_read((i<<2) + 2); - return (jaguar_word_read(i*4) << 16) | jaguar_word_read((i*4) + 2); +// return (jaguar_word_read(i*4) << 16) | jaguar_word_read((i*4) + 2); + return jaguar_long_read(i * 4); } ////////////////////////////////////////////////////////////////////////////// @@ -226,14 +204,10 @@ static char romLoadDialog_filePath[1024]; #ifndef __PORT__ static char romLoadDialog_initialDirectory[1024]; -int jaguar_open_rom(HWND hWnd,char *title,char *filterString) +int jaguar_open_rom(HWND hWnd, char * title, char * filterString) { OPENFILENAME ofn; - - romLoadDialog_initialDirectory[0] = 0; - - romLoadDialog_filePath[0] = 0; ZeroMemory(&ofn, sizeof(OPENFILENAME)); @@ -359,9 +333,6 @@ unsigned jaguar_unknown_readword(unsigned address) uint8 * jaguar_rom_load(char * path, uint32 * romSize) { - uint8 * rom = NULL; - fpos_t pos; - int x; __int64 filepos; fprintf(log_get(), "jaguar: loading %s...", path); @@ -377,15 +348,15 @@ uint8 * jaguar_rom_load(char * path, uint32 * romSize) /* Added by SDLEMU (http://sdlemu.ngemu.com) */ /* Added for GCC UNIX compatibility */ - #ifdef __GCCUNIX__ +#ifdef __GCCUNIX__ fgetpos(fp, (fpos_t *)&filepos); - #else +#else fgetpos(fp, &filepos); - #endif +#endif *romSize = (int)filepos; fseek(fp, 0, SEEK_SET); - rom = (uint8 *)malloc(*romSize); + uint8 * rom = (uint8 *)malloc(*romSize); fread(rom, 1, *romSize, fp); fclose(fp); fprintf(log_get(), "ok (%i bytes)\n", *romSize); @@ -415,11 +386,11 @@ void jaguar_rom_load_to(uint8 * rom, char * path, uint32 * romSize) /* Added by SDLEMU (http://sdlemu.ngemu.com) */ /* Added for GCC UNIX compatibility */ - #ifdef __GCCUNIX__ +#ifdef __GCCUNIX__ fgetpos(fp, (fpos_t *)&filepos); - #else +#else fgetpos(fp, &filepos); - #endif +#endif *romSize = (int)filepos; fseek(fp, 0, SEEK_SET); @@ -432,7 +403,7 @@ void jaguar_rom_load_to(uint8 * rom, char * path, uint32 * romSize) // Byte swap a region of memory // -void jaguar_byte_swap(uint8 * rom, uint32 size) +/*void jaguar_byte_swap(uint8 * rom, uint32 size) { while (size > 0) { @@ -442,7 +413,7 @@ void jaguar_byte_swap(uint8 * rom, uint32 size) rom += 2; size -= 2; } -} +}*/ // // Disassemble instructions at the given offset @@ -450,6 +421,7 @@ void jaguar_byte_swap(uint8 * rom, uint32 size) void jaguar_dasm(uint32 offset, uint32 qt) { +#ifdef CPU_DEBUG static char buffer[2048], mem[64]; int pc = offset, oldpc; @@ -457,14 +429,12 @@ void jaguar_dasm(uint32 offset, uint32 qt) { oldpc = pc; for(int j=0; j<64; j++) -// mem[j^0x01] = jaguar_byte_read(pc + j); mem[j^0x01] = jaguar_byte_read(pc + j); pc += Dasm68000((char *)mem, buffer, 0); -#ifdef CPU_DEBUG fprintf(log_get(), "%08X: %s\n", oldpc, buffer); -#endif } +#endif } // @@ -479,7 +449,7 @@ void jaguar_load_cart(char * path, uint8 * mem, uint32 offs, uint32 boot, uint32 // Is there a need for this? The answer is !!! NO !!! // jaguar_byte_swap(mem+offs, romsize); jaguar_mainRom_crc32 = crc32_calcCheckSum(jaguar_mainRom, romsize); - fprintf(log_get(), "crc: %08X\n", jaguar_mainRom_crc32); + fprintf(log_get(), "CRC: %08X\n", jaguar_mainRom_crc32); // Brain dead endian dependent crap // *((uint32 *)&jaguar_mainRam[4]) = boot; @@ -507,9 +477,9 @@ void jaguar_init(void) gpu_cycles_per_scanline = (26591000 / 4) / (jaguar_screen_scanlines * 60); dsp_cycles_per_scanline = (26591000 / 4) / (jaguar_screen_scanlines * 60); - memory_malloc_secure((void**)&jaguar_mainRam, 0x400000, "Jaguar 68k cpu ram"); - memory_malloc_secure((void**)&jaguar_bootRom, 0x040000, "Jaguar 68k cpu boot rom"); - memory_malloc_secure((void**)&jaguar_mainRom, 0x600000, "Jaguar 68k cpu rom"); + memory_malloc_secure((void **)&jaguar_mainRam, 0x400000, "Jaguar 68k cpu ram"); + memory_malloc_secure((void **)&jaguar_bootRom, 0x040000, "Jaguar 68k cpu boot rom"); + memory_malloc_secure((void **)&jaguar_mainRom, 0x600000, "Jaguar 68k cpu rom"); memset(jaguar_mainRam, 0x00, 0x400000); jaguar_rom_load_to(jaguar_bootRom, jaguar_bootRom_path, &romsize); @@ -528,6 +498,15 @@ void jaguar_init(void) #endif //WAS: jaguar_load_cart(romLoadDialog_filePath, jaguar_mainRom, 0x0000, 0x20000080, 0); jaguar_load_cart(romLoadDialog_filePath, jaguar_mainRom, 0x0000, 0x00802000, 0); + +//JLH: +/* if (jaguar_mainRom_crc32 == 0xA9F8A00E) + { + dsp_enabled = 1; + fprintf(log_get(), "--> Rayman detected, DSP enabled...\n"); + }//*/ + + if ((jaguar_mainRom_crc32 == 0x3966698f) || (jaguar_mainRom_crc32 == 0x5e705756) || (jaguar_mainRom_crc32 == 0x2630cbc4) || (jaguar_mainRom_crc32 == 0xd46437e8) || (jaguar_mainRom_crc32 == 0x2630cbc4)) @@ -776,7 +755,8 @@ void jaguar_init(void) if (jaguar_use_bios) { memcpy(jaguar_mainRam, jaguar_bootRom, 8); - *((uint32 *)&jaguar_mainRam[0]) = 0x00000020; +// *((uint32 *)&jaguar_mainRam[0]) = 0x00000020; +// SET32(jaguar_mainRam, 0, 0x00200000); } // s68000init(); @@ -787,16 +767,7 @@ void jaguar_init(void) jerry_init(); cdrom_init(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + unsigned jaguar_byte_read(unsigned int offset) { uint8 data = 0x00; @@ -804,70 +775,55 @@ unsigned jaguar_byte_read(unsigned int offset) offset &= 0xFFFFFF; if (offset < 0x400000) // data = (jaguar_mainRam[(offset^0x01) & 0x3FFFFF]); - data = (jaguar_mainRam[offset & 0x3FFFFF]); + data = jaguar_mainRam[offset & 0x3FFFFF]; else if ((offset >= 0x800000) && (offset < 0xC00000)) // data = (jaguar_mainRom[(offset^0x01)-0x800000]); - data = (jaguar_mainRom[offset - 0x800000]); - else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00)) + data = jaguar_mainRom[offset - 0x800000]; +// else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00)) + else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF)) data = cdrom_byte_read(offset); else if ((offset >= 0xE00000) && (offset < 0xE40000)) // data = (jaguar_bootRom[(offset^0x01) & 0x3FFFF]); - data = (jaguar_bootRom[offset & 0x3FFFF]); + data = jaguar_bootRom[offset & 0x3FFFF]; else if ((offset >= 0xF00000) && (offset < 0xF10000)) - data = (tom_byte_read(offset)); + data = tom_byte_read(offset); else if ((offset >= 0xF10000) && (offset < 0xF20000)) - data = (jerry_byte_read(offset)); + data = jerry_byte_read(offset); else data = jaguar_unknown_readbyte(offset); return data; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + unsigned jaguar_word_read(unsigned int offset) { offset &= 0xFFFFFF; - if (offset < 0x400000) + if (offset <= 0x3FFFFE) { // return (jaguar_mainRam[(offset+1) & 0x3FFFFF] << 8) | jaguar_mainRam[(offset+0) & 0x3FFFFF]; return (jaguar_mainRam[(offset+0) & 0x3FFFFF] << 8) | jaguar_mainRam[(offset+1) & 0x3FFFFF]; } - else if ((offset >= 0x800000) && (offset < 0xC00000)) + else if ((offset >= 0x800000) && (offset <= 0xBFFFFE)) { offset -= 0x800000; // return (jaguar_mainRom[offset+1] << 8) | jaguar_mainRom[offset+0]; return (jaguar_mainRom[offset+0] << 8) | jaguar_mainRom[offset+1]; } - else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00)) +// else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00)) + else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFE)) return cdrom_word_read(offset); - else if ((offset >= 0xE00000) && (offset < 0xE40000)) - return *((uint16 *)&jaguar_bootRom[offset & 0x3FFFF]); - else if ((offset >= 0xF00000) && (offset < 0xF10000)) + else if ((offset >= 0xE00000) && (offset <= 0xE3FFFE)) +// return *((uint16 *)&jaguar_bootRom[offset & 0x3FFFF]); + return (jaguar_bootRom[(offset+0) & 0x3FFFF] << 8) | jaguar_bootRom[(offset+1) & 0x3FFFF]; + else if ((offset >= 0xF00000) && (offset <= 0xF0FFFE)) return tom_word_read(offset); - else if ((offset >= 0xF10000) && (offset < 0xF20000)) + else if ((offset >= 0xF10000) && (offset <= 0xF1FFFE)) return jerry_word_read(offset); return jaguar_unknown_readword(offset); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void jaguar_byte_write(unsigned offset, unsigned data) + +void jaguar_byte_write(unsigned offset, unsigned data) { offset &= 0xFFFFFF; if (offset < 0x400000) @@ -876,17 +832,18 @@ void jaguar_byte_write(unsigned offset, unsigned data) jaguar_mainRam[offset & 0x3FFFFF] = data; return; } - else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00)) +// else if ((offset >= 0xDFFF00) && (offset < 0xDFFF00)) + else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFF)) { cdrom_byte_write(offset, data); return; } - else if ((offset >= 0xF00000) && (offset < 0xF10000)) + else if ((offset >= 0xF00000) && (offset <= 0xF0FFFF)) { tom_byte_write(offset, data); return; } - else if ((offset >= 0xF10000) && (offset < 0xF20000)) + else if ((offset >= 0xF10000) && (offset <= 0xF1FFFF)) { jerry_byte_write(offset, data); return; @@ -894,21 +851,12 @@ void jaguar_byte_write(unsigned offset, unsigned data) jaguar_unknown_writebyte(offset, data); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jaguar_word_write(unsigned offset, unsigned data) { offset &= 0xFFFFFF; - if (offset < 0x400000) + if (offset <= 0x3FFFFE) { // jaguar_mainRam[(offset+0) & 0x3FFFFF] = data & 0xFF; // jaguar_mainRam[(offset+1) & 0x3FFFFF] = (data>>8) & 0xFF; @@ -916,17 +864,17 @@ void jaguar_word_write(unsigned offset, unsigned data) jaguar_mainRam[(offset+1) & 0x3FFFFF] = data & 0xFF; return; } - else if ((offset >= 0xDFFF00) && (offset < 0xDFFFFF)) + else if ((offset >= 0xDFFF00) && (offset <= 0xDFFFFE)) { cdrom_word_write(offset, data); return; } - else if ((offset >= 0xF00000) && (offset < 0xF10000)) + else if ((offset >= 0xF00000) && (offset <= 0xF0FFFE)) { tom_word_write(offset, data); return; } - else if ((offset >= 0xF10000) && (offset < 0xF20000)) + else if ((offset >= 0xF10000) && (offset <= 0xF1FFFE)) { jerry_word_write(offset, data); return; @@ -934,16 +882,7 @@ void jaguar_word_write(unsigned offset, unsigned data) jaguar_unknown_writeword(offset, data); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + unsigned jaguar_long_read(unsigned int offset) { /* uint32 data = jaguar_word_read(offset); @@ -951,37 +890,22 @@ unsigned jaguar_long_read(unsigned int offset) return data;*/ return (jaguar_word_read(offset) << 16) | jaguar_word_read(offset+2); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jaguar_long_write(unsigned offset, unsigned data) { jaguar_word_write(offset, data >> 16); jaguar_word_write(offset+2, data & 0xFFFF); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jaguar_done(void) { + fprintf(log_get(), "jaguar_done() ...START\n"); +#ifdef CPU_DEBUG fprintf(log_get(), "jaguar: top of stack: %08X\n", jaguar_long_read(0x001FFFF8)); // fprintf(log_get(),"jaguar: cd bios version 0x%.4x\n",jaguar_word_read(0x3004)); // fprintf(log_get(),"jaguar: vbl interrupt is %s\n",((tom_irq_enabled(IRQ_VBLANK))&&(jaguar_interrupt_handler_is_valid(64)))?"enabled":"disabled"); s68000show_context(); +#endif #ifdef SOUND_OUTPUT ws_audio_done(); #endif @@ -993,18 +917,9 @@ void jaguar_done(void) memory_free(jaguar_mainRom); memory_free(jaguar_bootRom); memory_free(jaguar_mainRam); -// fprintf(log_get(),"jaguar_done()\n"); + fprintf(log_get(), "jaguar_done() ...END\n"); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jaguar_reset(void) { // fprintf(log_get(),"jaguar_reset():\n"); @@ -1021,27 +936,14 @@ void jaguar_reset(void) m68k_pulse_reset(); // Reset the 68000 fprintf(log_get(), "\t68K PC=%06X SP=%08X\n", m68k_get_reg(NULL, M68K_REG_PC), m68k_get_reg(NULL, M68K_REG_A7)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jaguar_reset_handler(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jaguar_exec(int16 * backbuffer, uint8 render) { - int i; - uint32 vblank_duration = tom_get_vdb(); + uint32 i, vblank_duration = tom_get_vdb(); // vblank if ((tom_irq_enabled(IRQ_VBLANK)) && (jaguar_interrupt_handler_is_valid(64))) @@ -1056,6 +958,7 @@ void jaguar_exec(int16 * backbuffer, uint8 render) // Then again, since IRQ_VBLANK is set to zero, this would not be necessary in this case. } } + for(i=0; i>1] @@ -169,16 +167,7 @@ static uint32 jerry_i2s_interrupt_divide = 8; static int32 jerry_i2s_interrupt_timer = -1; static int32 jerry_i2s_interrupt_cycles_per_scanline = 0; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jerry_i2s_exec(uint32 cycles) { jerry_i2s_interrupt_divide &= 0xFF; @@ -201,163 +190,85 @@ void jerry_i2s_exec(uint32 cycles) jerry_i2s_interrupt_timer += jerry_i2s_interrupt_cycles_per_scanline; } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jerry_reset_i2s_timer(void) { //fprintf(log_get(),"i2s: reseting\n"); - jerry_i2s_interrupt_divide=8; - jerry_i2s_interrupt_timer=-1; + jerry_i2s_interrupt_divide = 8; + jerry_i2s_interrupt_timer = -1; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jerry_reset_timer_1(void) { - if ((!jerry_timer_1_prescaler)||(!jerry_timer_1_divider)) - jerry_timer_1_counter=0; + if (!jerry_timer_1_prescaler || !jerry_timer_1_divider) + jerry_timer_1_counter = 0; else - jerry_timer_1_counter=(1+jerry_timer_1_prescaler)*(1+jerry_timer_1_divider); + jerry_timer_1_counter = (1 + jerry_timer_1_prescaler) * (1 + jerry_timer_1_divider); // if (jerry_timer_1_counter) // fprintf(log_get(),"jerry: reseting timer 1 to 0x%.8x (%i)\n",jerry_timer_1_counter,jerry_timer_1_counter); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jerry_reset_timer_2(void) { - if ((!jerry_timer_2_prescaler)||(!jerry_timer_2_divider)) + if (!jerry_timer_2_prescaler || !jerry_timer_2_divider) { - jerry_timer_2_counter=0; + jerry_timer_2_counter = 0; return; } else - jerry_timer_2_counter=((1+jerry_timer_2_prescaler)*(1+jerry_timer_2_divider)); + jerry_timer_2_counter = ((1 + jerry_timer_2_prescaler) * (1 + jerry_timer_2_divider)); // if (jerry_timer_2_counter) // fprintf(log_get(),"jerry: reseting timer 2 to 0x%.8x (%i)\n",jerry_timer_2_counter,jerry_timer_2_counter); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jerry_pit_exec(uint32 cycles) { if (jerry_timer_1_counter) - jerry_timer_1_counter-=cycles; + jerry_timer_1_counter -= cycles; - if (jerry_timer_1_counter<=0) + if (jerry_timer_1_counter <= 0) { - dsp_set_irq_line(2,1); + dsp_set_irq_line(2, 1); jerry_reset_timer_1(); } if (jerry_timer_2_counter) - jerry_timer_2_counter-=cycles; + jerry_timer_2_counter -= cycles; - if (jerry_timer_2_counter<=0) + if (jerry_timer_2_counter <= 0) { - dsp_set_irq_line(3,1); + dsp_set_irq_line(3, 1); jerry_reset_timer_2(); } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jerry_wave_rom_init(void) { - memory_malloc_secure((void **)&jerry_wave_rom, 0x1000, "jerry wave rom"); - uint32 * jaguar_wave_rom_32 = (uint32 *)jerry_wave_rom; - -/* for (i = 0; i < 0x80; i++) - { - // F1D000 = triangle wave - jaguar_wave_rom_32[0x000 + i] = ((i <= 0x40) ? i : 0x80 - i) * 32767 / 0x40; - - // F1D200 = full sine wave - jaguar_wave_rom_32[0x080 + i] = (int)(32767. * sin(2.0 * 3.1415927 * (double)i / (double)0x80)); - - // F1D400 = amplitude modulated sine wave? - jaguar_wave_rom_32[0x100 + i] = (int)(32767. * sin(2.0 * 3.1415927 * (double)i / (double)0x80)); - - // F1D600 = sine wave and second order harmonic - jaguar_wave_rom_32[0x180 + i] = (int)(32767. * sin(2.0 * 3.1415927 * (double)i / (double)0x80)); +// memory_malloc_secure((void **)&jerry_wave_rom, 0x1000, "jerry wave rom"); +// uint32 * jaguar_wave_rom_32 = (uint32 *)jerry_wave_rom; - // F1D800 = chirp (sine wave of increasing frequency) - jaguar_wave_rom_32[0x200 + i] = (int)(32767. * sin(2.0 * 3.1415927 * (double)i / (double)0x80)); - - // F1DA00 = traingle wave with noise - jaguar_wave_rom_32[0x280 + i] = jaguar_wave_rom_32[0x000 + i] * (rand() % 32768) / 32768; - - // F1DC00 = spike - jaguar_wave_rom_32[0x300 + i] = (i == 0x40) ? 32767 : 0; - - // F1DE00 = white noise - jaguar_wave_rom_32[0x380 + i] = rand() % 32768; - } - */ // use real wave table dump -// Looks like this WT dump is in the wrong endian... - memcpy(jerry_wave_rom, wave_table, 0x1000); +// JLH: Looks like this WT dump is in the wrong endian (For the Jaguar, that is)... +// memcpy(jerry_wave_rom, wave_table, 0x1000); // reverse byte ordering -// Actually, this does nothing... - for(int i=0; i<0x400; i++) +// JLH: Actually, this does nothing... +/* for(int i=0; i<0x400; i++) { uint32 data = jaguar_wave_rom_32[i]; - data = ((data&0xff000000)>>24)|((data&0x0000ff00)<<8)| - ((data&0x00ff0000)>>8) |((data&0x000000ff)<<24); - } + data = ((data & 0xFF000000) >> 24) | ((data & 0x0000FF00) << 8) + | ((data & 0x00FF0000) >> 8) | ((data & 0x000000FF) << 24); + }*/ +// Why the need for an extra buffer to hold it, when it already exists in the form of wave_table??? +// Also, there was a memory leak, since it was never deallocated... (jerry_wave_rom) - // copy it to dsp ram - memcpy(&jerry_ram_8[0xD000], jerry_wave_rom, 0x1000); + // Copy it to DSP RAM +//WAS: memcpy(&jerry_ram_8[0xD000], jerry_wave_rom, 0x1000); + memcpy(&jerry_ram_8[0xD000], wave_table, 0x1000); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jerry_init(void) { //fprintf(log_get(),"jerry_init()\n"); @@ -369,16 +280,7 @@ void jerry_init(void) // jerry_ram_16 = (uint16 *)jerry_ram_8; jerry_wave_rom_init(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jerry_reset(void) { //fprintf(log_get(),"jerry_reset()\n"); @@ -398,16 +300,7 @@ void jerry_reset(void) jerry_timer_2_counter = 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void jerry_done(void) { //fprintf(log_get(),"jerry_done()\n"); @@ -417,16 +310,11 @@ void jerry_done(void) joystick_done(); eeprom_done(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// + // +// JERRY byte access (read) // -////////////////////////////////////////////////////////////////////////////// + unsigned jerry_byte_read(unsigned int offset) { #ifdef JERRY_DEBUG @@ -434,148 +322,140 @@ unsigned jerry_byte_read(unsigned int offset) #endif if ((offset >= dsp_control_ram_base) && (offset < dsp_control_ram_base+0x20)) return dsp_byte_read(offset); - - if ((offset >= dsp_work_ram_base) && (offset < dsp_work_ram_base+0x2000)) + else if ((offset >= dsp_work_ram_base) && (offset < dsp_work_ram_base+0x2000)) return dsp_byte_read(offset); - - if ((offset >= 0xF10000) && (offset <= 0xF10007)) + else if ((offset >= 0xF10000) && (offset <= 0xF10007)) { switch(offset & 0x07) { - case 0: return(jerry_timer_1_prescaler>>8); - case 1: return(jerry_timer_1_prescaler&0xff); - case 2: return(jerry_timer_1_divider>>8); - case 3: return(jerry_timer_1_divider&0xff); - case 4: return(jerry_timer_2_prescaler>>8); - case 5: return(jerry_timer_2_prescaler&0xff); - case 6: return(jerry_timer_2_divider>>8); - case 7: return(jerry_timer_2_divider&0xff); + case 0: + return jerry_timer_1_prescaler >> 8; + case 1: + return jerry_timer_1_prescaler & 0xFF; + case 2: + return jerry_timer_1_divider >> 8; + case 3: + return jerry_timer_1_divider & 0xFF; + case 4: + return jerry_timer_2_prescaler >> 8; + case 5: + return jerry_timer_2_prescaler & 0xFF; + case 6: + return jerry_timer_2_divider >> 8; + case 7: + return jerry_timer_2_divider & 0xFF; } } - - if ((offset>=0xf10010)&&(offset<0xf10016)) - return(clock_byte_read(offset)); - - if ((offset>=0xf17c00)&&(offset<0xf17c02)) - return(anajoy_byte_read(offset)); - - if ((offset>=0xf14000)&&(offset<=0xf14003)) + else if ((offset >= 0xF10010) && (offset <= 0xf10015)) + return clock_byte_read(offset); + else if ((offset >= 0xF17C00) && (offset <= 0xF17C01)) + return anajoy_byte_read(offset); + else if ((offset >= 0xF14000) && (offset <= 0xF14003)) { - return(joystick_byte_read(offset)|eeprom_byte_read(offset)); + return joystick_byte_read(offset) | eeprom_byte_read(offset); } - - if ((offset >= 0xF14000) && (offset <= 0xF1A0FF)) - return(eeprom_byte_read(offset)); + else if ((offset >= 0xF14000) && (offset <= 0xF1A0FF)) + return eeprom_byte_read(offset); return jerry_ram_8[offset & 0xFFFF]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// + // +// JERRY word access (read) // -////////////////////////////////////////////////////////////////////////////// + unsigned jerry_word_read(unsigned int offset) { #ifdef JERRY_DEBUG fprintf(log_get(),"jerry: reading word at 0x%.6x\n",offset); #endif - if ((offset>=dsp_control_ram_base)&&(offset=dsp_work_ram_base)&&(offset=0xf10000)&&(offset<=0xf10007)) + if ((offset >= dsp_control_ram_base) && (offset < dsp_control_ram_base+0x20)) + return dsp_word_read(offset); + else if ((offset >= dsp_work_ram_base) && (offset < dsp_work_ram_base+0x2000)) + return dsp_word_read(offset); + else if ((offset >= 0xF10000) && (offset <= 0xF10007)) { - switch(offset&0x07) + switch(offset & 0x07) { - case 0: return(jerry_timer_1_prescaler); - case 2: return(jerry_timer_1_divider); - case 4: return(jerry_timer_2_prescaler); - case 6: return(jerry_timer_2_divider); + case 0: + return jerry_timer_1_prescaler; + case 2: + return jerry_timer_1_divider; + case 4: + return jerry_timer_2_prescaler; + case 6: + return jerry_timer_2_divider; } + // Unaligned word reads??? } - - if ((offset>=0xf10010)&&(offset<0xf10016)) - return(clock_word_read(offset)); - - if (offset==0xF10020) - return(0x00); - - if ((offset>=0xf17c00)&&(offset<0xf17c02)) - return(anajoy_word_read(offset)); - - if (offset==0xf14000) + else if ((offset >= 0xF10010) && (offset <= 0xF10015)) + return clock_word_read(offset); + else if (offset == 0xF10020) + return 0x00; + else if ((offset >= 0xF17C00) && (offset <= 0xF17C01)) + return anajoy_word_read(offset); + else if (offset == 0xF14000) { - uint16 dta=(joystick_word_read(offset)&0xfffe)|eeprom_word_read(offset); //fprintf(log_get(),"reading 0x%.4x from 0xf14000\n"); - return(dta); + return (joystick_word_read(offset) & 0xFFFE) | eeprom_word_read(offset); } - if ((offset>=0xf14002)&&(offset<0xf14003)) - return(joystick_word_read(offset)); - - if ((offset>=0xf14000)&&(offset<=0xF1A0FF)) - return(eeprom_word_read(offset)); - - + else if ((offset >= 0xF14002) && (offset < 0xF14003)) + return joystick_word_read(offset); + else if ((offset >= 0xF14000) && (offset <= 0xF1A0FF)) + return eeprom_word_read(offset); - offset&=0xffff; +// This is never executed! +/* offset &= 0xFFFF; if (offset==0x4002) - return(0xffff); - + return(0xffff);*/ - uint16 data=jerry_ram_8[offset+0]; - data<<=8; - data|=jerry_ram_8[offset+1]; - return(data); +/* uint16 data = jerry_ram_8[offset+0]; + data <<= 8; + data |= jerry_ram_8[offset+1]; + return data;*/ + return ((uint16)jerry_ram_8[offset+0] << 8) | jerry_ram_8[offset+1]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// + // +// JERRY byte access (write) // -////////////////////////////////////////////////////////////////////////////// -void jerry_byte_write(unsigned offset, unsigned data) + +void jerry_byte_write(unsigned offset, unsigned data) { #ifdef JERRY_DEBUG fprintf(log_get(),"jerry: writing byte %.2x at 0x%.6x\n",data,offset); #endif - if ((offset>=dsp_control_ram_base)&&(offset= dsp_control_ram_base) && (offset < dsp_control_ram_base+0x20)) { - dsp_byte_write(offset,data); + dsp_byte_write(offset, data); return; } - if ((offset>=dsp_work_ram_base)&&(offset= dsp_work_ram_base) && (offset < dsp_work_ram_base+0x2000)) { - dsp_byte_write(offset,data); + dsp_byte_write(offset, data); return; } - - if ((offset>=0xf1a152)&&(offset<0xf1a154)) + else if ((offset >= 0xF1A152) && (offset <= 0xF1A153)) { // fprintf(log_get(),"i2s: writing 0x%.2x to SCLK\n",data); - if ((offset&0x03)==2) - jerry_i2s_interrupt_divide=(jerry_i2s_interrupt_divide&0x00ff)|(((uint32)data)<<8); + if ((offset & 0x03) == 2) + jerry_i2s_interrupt_divide = (jerry_i2s_interrupt_divide & 0x00FF) | ((uint32)data << 8); else - jerry_i2s_interrupt_divide=(jerry_i2s_interrupt_divide&0xff00)|((uint32)data); + jerry_i2s_interrupt_divide = (jerry_i2s_interrupt_divide & 0xFF00) | (uint32)data; - jerry_i2s_interrupt_timer=-1; + jerry_i2s_interrupt_timer = -1; jerry_i2s_exec(0); + return; } - if ((offset>=0xf10000)&&(offset<=0xf10007)) + else if ((offset >= 0xF10000) && (offset <= 0xF10007)) { - switch(offset&0x07) + switch(offset & 0x07) { - case 0: { jerry_timer_1_prescaler=(jerry_timer_1_prescaler&0x00ff)|(data<<8); jerry_reset_timer_1(); return; } + case 0: + jerry_timer_1_prescaler = (jerry_timer_1_prescaler & 0x00FF) | (data << 8); + jerry_reset_timer_1(); + break; case 1: { jerry_timer_1_prescaler=(jerry_timer_1_prescaler&0xff00)|(data); jerry_reset_timer_1(); return; } case 2: { jerry_timer_1_divider=(jerry_timer_1_divider&0x00ff)|(data<<8); jerry_reset_timer_1(); return; } case 3: { jerry_timer_1_divider=(jerry_timer_1_divider&0xff00)|(data); jerry_reset_timer_1(); return; } @@ -584,43 +464,37 @@ void jerry_byte_write(unsigned offset, unsigned data) case 6: { jerry_timer_2_divider=(jerry_timer_2_divider&0x00ff)|(data<<8); jerry_reset_timer_2(); return; } case 7: { jerry_timer_2_divider=(jerry_timer_2_divider&0xff00)|(data); jerry_reset_timer_2(); return; } } + return; } - - - if ((offset>=0xf10010)&&(offset<0xf10016)) + else if ((offset >= 0xF10010) && (offset <= 0xF10015)) { - clock_byte_write(offset,data); + clock_byte_write(offset, data); return; } - if ((offset>=0xf17c00)&&(offset<0xf17c02)) + else if ((offset >= 0xF17C00) && (offset <= 0xF17C01)) { - anajoy_byte_write(offset,data); + anajoy_byte_write(offset, data); return; } - if ((offset>=0xf14000)&&(offset<0xf14003)) + else if ((offset >= 0xF14000) && (offset <= 0xF14003)) { - joystick_byte_write(offset,data); - eeprom_byte_write(offset,data); + joystick_byte_write(offset, data); + eeprom_byte_write(offset, data); return; } - if ((offset>=0xf14000)&&(offset<=0xF1A0FF)) + else if ((offset >= 0xF14000) && (offset <= 0xF1A0FF)) { - eeprom_byte_write(offset,data); + eeprom_byte_write(offset, data); return; } - offset&=0xffff; - jerry_ram_8[offset]=data; + + jerry_ram_8[offset & 0xFFFF] = data; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// + // +// JERRY word access (write) // -////////////////////////////////////////////////////////////////////////////// + void jerry_word_write(unsigned offset, unsigned data) { #ifdef JERRY_DEBUG @@ -632,59 +506,68 @@ void jerry_word_write(unsigned offset, unsigned data) dsp_word_write(offset, data); return; } - if ((offset >=dsp_work_ram_base) && (offset < dsp_work_ram_base+0x2000)) + else if ((offset >= dsp_work_ram_base) && (offset < dsp_work_ram_base+0x2000)) { dsp_word_write(offset, data); return; } - if (offset == 0xF1A152) + else if (offset == 0xF1A152) { // fprintf(log_get(),"i2s: writing 0x%.4x to SCLK\n",data); jerry_i2s_interrupt_divide = data & 0xFF; jerry_i2s_interrupt_timer = -1; jerry_i2s_exec(0); } - - if ((offset >= 0xF10000) && (offset <= 0xF10007)) + else if ((offset >= 0xF10000) && (offset <= 0xF10007)) { switch(offset & 0x07) { - case 0: { jerry_timer_1_prescaler=data; jerry_reset_timer_1(); return; } - case 2: { jerry_timer_1_divider=data; jerry_reset_timer_1(); return; } - case 4: { jerry_timer_2_prescaler=data; jerry_reset_timer_2(); return; } - case 6: { jerry_timer_2_divider=data; jerry_reset_timer_2(); return; } + case 0: + jerry_timer_1_prescaler = data; + jerry_reset_timer_1(); + break; + case 2: + jerry_timer_1_divider = data; + jerry_reset_timer_1(); + break; + case 4: + jerry_timer_2_prescaler = data; + jerry_reset_timer_2(); + break; + case 6: + jerry_timer_2_divider = data; + jerry_reset_timer_2(); } + // Need to handle (unaligned) cases??? + return; } - - if ((offset >= 0xF1A148) && (offset < 0xF1A150)) + else if ((offset >= 0xF1A148) && (offset < 0xF1A150)) { - pcm_word_write(offset-0xF1A148, data); + pcm_word_write(offset - 0xF1A148, data); return; } - - if ((offset >= 0xF10010) && (offset < 0xF10016)) + else if ((offset >= 0xF10010) && (offset < 0xF10016)) { clock_word_write(offset, data); return; } - if ((offset >= 0xf17C00) && (offset < 0xF17C02)) + else if ((offset >= 0xF17C00) && (offset < 0xF17C02)) { anajoy_word_write(offset, data); return; } - if ((offset >= 0xF14000) && (offset < 0xF14003)) + else if ((offset >= 0xF14000) && (offset < 0xF14003)) { joystick_word_write(offset, data); eeprom_word_write(offset, data); return; } - if ((offset >= 0xF14000) && (offset <= 0xF1A0FF)) + else if ((offset >= 0xF14000) && (offset <= 0xF1A0FF)) { - eeprom_word_write(offset,data); + eeprom_word_write(offset, data); return; } jerry_ram_8[(offset+0) & 0xFFFF] = (data >> 8) & 0xFF; jerry_ram_8[(offset+1) & 0xFFFF] = data & 0xFF; - } diff --git a/src/joystick.cpp b/src/joystick.cpp index 53d386e..b764bdd 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -1,15 +1,22 @@ +// +// Joystick handler +// +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons +// + #ifndef __PORT__ #include "include/stdafx.h" #include #endif #include #include -#include "include/SDLptc.h" -#include "include/jaguar.h" +#include "SDLptc.h" +#include "jaguar.h" void main_screen_switch(void); - #define BUTTON_U 0 #define BUTTON_D 1 #define BUTTON_L 2 @@ -40,225 +47,183 @@ static uint8 joypad_1_buttons[21]; extern uint8 finished; extern int start_logging; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void joystick_init(void) { joystick_reset(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void joystick_exec(void) { - - uint8 *keystate = SDL_GetKeyState(NULL); - Sint16 x = 0, y = 0; - extern Console console; + uint8 * keystate = SDL_GetKeyState(NULL); + extern Console console; - memset(joypad_0_buttons,0,21); - memset(joypad_1_buttons,0,21); + memset(joypad_0_buttons, 0, 21); + memset(joypad_1_buttons, 0, 21); - if ((keystate[SDLK_LALT])&(keystate[SDLK_RETURN])) main_screen_switch(); + if ((keystate[SDLK_LALT]) & (keystate[SDLK_RETURN])) + main_screen_switch(); /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com) */ - if (keystate[SDLK_UP]) joypad_0_buttons[BUTTON_U]=0x01; - if (keystate[SDLK_DOWN]) joypad_0_buttons[BUTTON_D]=0x01; - if (keystate[SDLK_LEFT]) joypad_0_buttons[BUTTON_L]=0x01; - if (keystate[SDLK_RIGHT]) joypad_0_buttons[BUTTON_R]=0x01; - if (keystate[SDLK_z]) joypad_0_buttons[BUTTON_A]=0x01; - if (keystate[SDLK_x]) joypad_0_buttons[BUTTON_B]=0x01; - if (keystate[SDLK_c]) joypad_0_buttons[BUTTON_C]=0x01; - if (keystate[SDLK_TAB]) joypad_0_buttons[BUTTON_OPTION]=0x01; - if (keystate[SDLK_RETURN]) joypad_0_buttons[BUTTON_PAUSE]=0x01; - if (keystate[SDLK_q]) start_logging=1; - if (keystate[SDLK_w]) gpu_reset_stats(); -//f (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1); + if (keystate[SDLK_UP]) joypad_0_buttons[BUTTON_U] = 0x01; + if (keystate[SDLK_DOWN]) joypad_0_buttons[BUTTON_D] = 0x01; + if (keystate[SDLK_LEFT]) joypad_0_buttons[BUTTON_L] = 0x01; + if (keystate[SDLK_RIGHT]) joypad_0_buttons[BUTTON_R] = 0x01; + if (keystate[SDLK_z]) joypad_0_buttons[BUTTON_A] = 0x01; + if (keystate[SDLK_x]) joypad_0_buttons[BUTTON_B] = 0x01; + if (keystate[SDLK_c]) joypad_0_buttons[BUTTON_C] = 0x01; + if (keystate[SDLK_TAB]) joypad_0_buttons[BUTTON_OPTION] = 0x01; + if (keystate[SDLK_RETURN]) joypad_0_buttons[BUTTON_PAUSE] = 0x01; + if (keystate[SDLK_q]) + start_logging = 1; + if (keystate[SDLK_w]) + gpu_reset_stats(); +// if (keystate[SDLK_u]) jaguar_long_write(0xf1c384,jaguar_long_read(0xf1c384)+1); + if (keystate[SDLK_d]) + DumpMainMemory(); + + if (keystate[SDLK_KP0]) joypad_0_buttons[BUTTON_0] = 0x01; + if (keystate[SDLK_KP1]) joypad_0_buttons[BUTTON_1] = 0x01; + if (keystate[SDLK_KP2]) joypad_0_buttons[BUTTON_2] = 0x01; + if (keystate[SDLK_KP3]) joypad_0_buttons[BUTTON_3] = 0x01; + if (keystate[SDLK_KP4]) joypad_0_buttons[BUTTON_4] = 0x01; + if (keystate[SDLK_KP5]) joypad_0_buttons[BUTTON_5] = 0x01; + if (keystate[SDLK_KP6]) joypad_0_buttons[BUTTON_6] = 0x01; + if (keystate[SDLK_KP7]) joypad_0_buttons[BUTTON_7] = 0x01; + if (keystate[SDLK_KP8]) joypad_0_buttons[BUTTON_8] = 0x01; + if (keystate[SDLK_KP9]) joypad_0_buttons[BUTTON_9] = 0x01; + + if (keystate[SDLK_ESCAPE]) + finished = 1; - if (keystate[SDLK_KP0]) joypad_0_buttons[BUTTON_0]=0x01; - if (keystate[SDLK_KP1]) joypad_0_buttons[BUTTON_1]=0x01; - if (keystate[SDLK_KP2]) joypad_0_buttons[BUTTON_2]=0x01; - if (keystate[SDLK_KP3]) joypad_0_buttons[BUTTON_3]=0x01; - if (keystate[SDLK_KP4]) joypad_0_buttons[BUTTON_4]=0x01; - if (keystate[SDLK_KP5]) joypad_0_buttons[BUTTON_5]=0x01; - if (keystate[SDLK_KP6]) joypad_0_buttons[BUTTON_6]=0x01; - if (keystate[SDLK_KP7]) joypad_0_buttons[BUTTON_7]=0x01; - if (keystate[SDLK_KP8]) joypad_0_buttons[BUTTON_8]=0x01; - if (keystate[SDLK_KP9]) joypad_0_buttons[BUTTON_9]=0x01; - - if (keystate[SDLK_ESCAPE]) finished=1; - /* Added/Changed by SDLEMU (http://sdlemu.ngemu.com */ /* Joystick support */ - if ( console.JoyEnabled() == 1 ) { - - x = SDL_JoystickGetAxis(console.joystick, 0); - y = SDL_JoystickGetAxis(console.joystick, 1); + if (console.JoyEnabled() == 1) + { + int16 x = SDL_JoystickGetAxis(console.joystick, 0), + y = SDL_JoystickGetAxis(console.joystick, 1); - if ( x > 16384 ) joypad_0_buttons[BUTTON_R]=0x01; - if ( x < -16384 ) joypad_0_buttons[BUTTON_L]=0x01; - if ( y > 16384 ) joypad_0_buttons[BUTTON_D]=0x01; - if ( y < -16384 ) joypad_0_buttons[BUTTON_U]=0x01; + if (x > 16384) + joypad_0_buttons[BUTTON_R] = 0x01; + if (x < -16384) + joypad_0_buttons[BUTTON_L] = 0x01; + if (y > 16384) + joypad_0_buttons[BUTTON_D] = 0x01; + if (y < -16384) + joypad_0_buttons[BUTTON_U] = 0x01; - if (SDL_JoystickGetButton(console.joystick, 0) == SDL_PRESSED) joypad_0_buttons[BUTTON_A]=0x01; - if (SDL_JoystickGetButton(console.joystick, 1) == SDL_PRESSED) joypad_0_buttons[BUTTON_B]=0x01; - if (SDL_JoystickGetButton(console.joystick, 2) == SDL_PRESSED) joypad_0_buttons[BUTTON_C]=0x01; - + if (SDL_JoystickGetButton(console.joystick, 0) == SDL_PRESSED) + joypad_0_buttons[BUTTON_A] = 0x01; + if (SDL_JoystickGetButton(console.joystick, 1) == SDL_PRESSED) + joypad_0_buttons[BUTTON_B] = 0x01; + if (SDL_JoystickGetButton(console.joystick, 2) == SDL_PRESSED) + joypad_0_buttons[BUTTON_C] = 0x01; } /* ADDED by SDLEMU (http://sdlemu.ngemu.com */ /* Needed to make sure that the events queue is empty */ SDL_PumpEvents(); - } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void joystick_reset(void) { - memset(joystick_ram,0x00,4); - memset(joypad_0_buttons,0,21); - memset(joypad_1_buttons,0,21); + memset(joystick_ram, 0x00, 4); + memset(joypad_0_buttons, 0, 21); + memset(joypad_1_buttons, 0, 21); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void joystick_done(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void joystick_byte_write(uint32 offset, uint8 data) { - joystick_ram[offset&0x03]=data; + joystick_ram[offset&0x03] = data; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void joystick_word_write(uint32 offset, uint16 data) { - offset&=0x03; - joystick_ram[offset+0]=(data>>8)&0xff; - joystick_ram[offset+1]=data&0xff; + offset &= 0x03; + joystick_ram[offset+0] = (data >> 8) & 0xFF; + joystick_ram[offset+1] = data & 0xFF; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint8 joystick_byte_read(uint32 offset) { - offset&=0x03; + offset &= 0x03; - if (offset==0) + if (offset == 0) { - uint8 data=0x00; - int pad0Index=joystick_ram[1]&0x0f; - int pad1Index=(joystick_ram[1]>>4)&0x0f; + uint8 data = 0x00; + int pad0Index = joystick_ram[1] & 0x0F; + int pad1Index = (joystick_ram[1] >> 4) & 0x0F; - if (!(pad0Index&0x01)) - pad0Index=0; - else - if (!(pad0Index&0x02)) - pad0Index=1; - else - if (!(pad0Index&0x04)) - pad0Index=2; - else - pad0Index=3; + if (!(pad0Index & 0x01)) + pad0Index = 0; + else if (!(pad0Index & 0x02)) + pad0Index = 1; + else if (!(pad0Index & 0x04)) + pad0Index = 2; + else + pad0Index = 3; - if (!(pad1Index&0x01)) - pad1Index=0; + if (!(pad1Index & 0x01)) + pad1Index = 0; + else if (!(pad1Index & 0x02)) + pad1Index = 1; + else if (!(pad1Index & 0x04)) + pad1Index = 2; else - if (!(pad1Index&0x02)) - pad1Index=1; - else - if (!(pad1Index&0x04)) - pad1Index=2; - else - pad1Index=3; - - if (joypad_0_buttons[(pad0Index<<2)+0]) data|=0x01; - if (joypad_0_buttons[(pad0Index<<2)+1]) data|=0x02; - if (joypad_0_buttons[(pad0Index<<2)+2]) data|=0x04; - if (joypad_0_buttons[(pad0Index<<2)+3]) data|=0x08; - if (joypad_1_buttons[(pad1Index<<2)+0]) data|=0x10; - if (joypad_1_buttons[(pad1Index<<2)+1]) data|=0x20; - if (joypad_1_buttons[(pad1Index<<2)+2]) data|=0x40; - if (joypad_1_buttons[(pad1Index<<2)+3]) data|=0x80; - return(~data); + pad1Index = 3; + + if (joypad_0_buttons[(pad0Index << 2) + 0]) data |= 0x01; + if (joypad_0_buttons[(pad0Index << 2) + 1]) data |= 0x02; + if (joypad_0_buttons[(pad0Index << 2) + 2]) data |= 0x04; + if (joypad_0_buttons[(pad0Index << 2) + 3]) data |= 0x08; + if (joypad_1_buttons[(pad1Index << 2) + 0]) data |= 0x10; + if (joypad_1_buttons[(pad1Index << 2) + 1]) data |= 0x20; + if (joypad_1_buttons[(pad1Index << 2) + 2]) data |= 0x40; + if (joypad_1_buttons[(pad1Index << 2) + 3]) data |= 0x80; + + return ~data; } - else - if (offset==3) + else if (offset == 3) { - uint8 data=((1<<5)|(1<<4)|0x0f) ; - int pad0Index=joystick_ram[1]&0x0f; - int pad1Index=(joystick_ram[1]>>4)&0x0f; + uint8 data = ((1 << 5) | (1 << 4) | 0x0F); + int pad0Index = joystick_ram[1] & 0x0F; +//unused int pad1Index = (joystick_ram[1] >> 4) & 0x0F; - if (!(pad0Index&0x01)) + if (!(pad0Index & 0x01)) { - if (joypad_0_buttons[BUTTON_PAUSE]) data^=0x01; - if (joypad_0_buttons[BUTTON_A]) data^=0x02; + if (joypad_0_buttons[BUTTON_PAUSE]) + data ^= 0x01; + if (joypad_0_buttons[BUTTON_A]) + data ^= 0x02; } - else - if (!(pad0Index&0x02)) + else if (!(pad0Index & 0x02)) { - if (joypad_0_buttons[BUTTON_B]) data^=0x02; + if (joypad_0_buttons[BUTTON_B]) + data ^= 0x02; } - else - if (!(pad0Index&0x04)) + else if (!(pad0Index & 0x04)) { - if (joypad_0_buttons[BUTTON_C]) data^=0x02; + if (joypad_0_buttons[BUTTON_C]) + data ^= 0x02; } else { - if (joypad_0_buttons[BUTTON_OPTION]) data^=0x02; + if (joypad_0_buttons[BUTTON_OPTION]) + data ^= 0x02; } - return(data); + return data; } - return(joystick_ram[offset]); + + return joystick_ram[offset]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint16 joystick_word_read(uint32 offset) { - uint16 data=joystick_byte_read((offset+0)&0x03); - data<<=8; - data|=joystick_byte_read((offset+1)&0x03); - return(data); + return ((uint16)joystick_byte_read((offset+0)&0x03) << 8) | joystick_byte_read((offset+1)&0x03); } diff --git a/src/log.cpp b/src/log.cpp index bdbab62..f748183 100644 --- a/src/log.cpp +++ b/src/log.cpp @@ -1,59 +1,28 @@ -////////////////////////////////////////////////////////////////////////////// // -////////////////////////////////////////////////////////////////////////////// +// Log handler // +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons // -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -#include "include/log.h" +#include "log.h" -FILE *log_stream=NULL; +FILE * log_stream = NULL; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -int log_init(char *path) +int log_init(char * path) { - log_stream=fopen(path,"wrt"); - if (log_stream==NULL) - return(0); - return(1); + log_stream = fopen(path, "wrt"); + if (log_stream == NULL) + return 0; + return 1; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -FILE *log_get(void) + +FILE * log_get(void) { - return(log_stream); + return log_stream; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void log_done(void) { fclose(log_stream); diff --git a/src/memory.cpp b/src/memory.cpp index 8c4007f..39376ca 100644 --- a/src/memory.cpp +++ b/src/memory.cpp @@ -1,184 +1,128 @@ -////////////////////////////////////////////////////////////////////////////// // -////////////////////////////////////////////////////////////////////////////// +// Memory handler // +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons // -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -#include "include/memory.h" +#include "memory.h" typedef struct sMemBlockInfo { - void *ptr; - char *info; - UINT32 size; - struct sMemBlockInfo *next; - struct sMemBlockInfo *prev; + void * ptr; + char * info; + UINT32 size; + struct sMemBlockInfo * next; + struct sMemBlockInfo * prev; } sMemBlockInfo; -sMemBlockInfo memoryInfo; -UINT32 memoryMaxAllocated; -UINT32 currentAllocatedMemory; -UINT32 maximumAllocatedMemory; +sMemBlockInfo memoryInfo; +UINT32 memoryMaxAllocated; +UINT32 currentAllocatedMemory; +UINT32 maximumAllocatedMemory; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void memory_addMemInfo(void *ptr, UINT32 size, char *info) + +void memory_addMemInfo(void * ptr, UINT32 size, char * info) { - sMemBlockInfo *alias; + sMemBlockInfo * alias; - alias=&memoryInfo; - while (alias->next) alias=alias->next; - alias->next=(sMemBlockInfo*)malloc(sizeof(sMemBlockInfo)); - if (alias->next==NULL) + alias = &memoryInfo; + while (alias->next) + alias=alias->next; + alias->next = (sMemBlockInfo *)malloc(sizeof(sMemBlockInfo)); + if (alias->next == NULL) { exit(0); return; } - alias->next->prev=alias; - alias=alias->next; - alias->next=NULL; - alias->size=size; - alias->ptr=ptr; - alias->info=info; + alias->next->prev = alias; + alias = alias->next; + alias->next = NULL; + alias->size = size; + alias->ptr = ptr; + alias->info = info; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void memory_init(void) { - memoryInfo.next=NULL; - memoryInfo.prev=NULL; - currentAllocatedMemory=0; - maximumAllocatedMemory=0; + memoryInfo.next = NULL; + memoryInfo.prev = NULL; + currentAllocatedMemory = 0; + maximumAllocatedMemory = 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void *memory_malloc(UINT32 size, char *info) + +void * memory_malloc(UINT32 size, char * info) { - void *ptr; + void * ptr; - ptr=(void*)malloc(size); - if (ptr==NULL) - { - return(NULL); - } - memory_addMemInfo(ptr,size,info); - currentAllocatedMemory+=size; - if (currentAllocatedMemory>maximumAllocatedMemory) - maximumAllocatedMemory=currentAllocatedMemory; - return(ptr); + ptr = (void *)malloc(size); + if (ptr == NULL) + return NULL; + + memory_addMemInfo(ptr, size, info); + currentAllocatedMemory += size; + + if (currentAllocatedMemory > maximumAllocatedMemory) + maximumAllocatedMemory = currentAllocatedMemory; + + return ptr; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void memory_malloc_secure(void **new_ptr, UINT32 size, char *info) + +void memory_malloc_secure(void ** new_ptr, UINT32 size, char * info) { - void *ptr; + void * ptr; - fprintf(log_get(),"memory: allocating %i bytes of memory for <%s>...",size,(info==NULL)?"unknown":info); - ptr=(void*)malloc(size); - if (ptr==NULL) + fprintf(log_get(), "memory: allocating %i bytes of memory for <%s>...", size, (info == NULL) ? "unknown" : info); + ptr = (void *)malloc(size); + if (ptr == NULL) { - fprintf(log_get(),"failed\n"); + fprintf(log_get(), "failed\n"); log_done(); exit(0); } - memory_addMemInfo(ptr,size,info); - currentAllocatedMemory+=size; - if (currentAllocatedMemory>maximumAllocatedMemory) - maximumAllocatedMemory=currentAllocatedMemory; - *new_ptr=ptr; - fprintf(log_get(),"ok\n"); + memory_addMemInfo(ptr, size, info); + currentAllocatedMemory += size; + if (currentAllocatedMemory > maximumAllocatedMemory) + maximumAllocatedMemory = currentAllocatedMemory; + *new_ptr = ptr; + fprintf(log_get(), "ok\n"); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void memory_memoryUsage(FILE *fp) + +void memory_memoryUsage(FILE * fp) { - sMemBlockInfo *alias; - UINT32 total=0; + sMemBlockInfo * alias; + UINT32 total = 0; - fprintf(fp,"Memory usage:\n"); - alias=&memoryInfo; - alias=alias->next; + fprintf(fp, "Memory usage:\n"); + alias = &memoryInfo; + alias = alias->next; while (alias) { - fprintf(fp,"\t%16i bytes : <%s> (@ 0x%.8x)\n",alias->size,alias->info,alias->ptr); - total+=alias->size; - alias=alias->next; + fprintf(fp, "\t%16i bytes : <%s> (@ 0x%.8x)\n", alias->size, alias->info, alias->ptr); + total += alias->size; + alias = alias->next; } - fprintf(fp,"\n\t%16i bytes total(%i Mb)\n",total,(total>>20)); - fprintf(fp,"\n\t%16i bytes memory peak(%i Mb)\n",maximumAllocatedMemory,maximumAllocatedMemory>>20); + fprintf(fp, "\n\t%16i bytes total(%i Mb)\n", total, total >> 20); + fprintf(fp, "\n\t%16i bytes memory peak(%i Mb)\n", maximumAllocatedMemory, maximumAllocatedMemory >> 20); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// void memory_done(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void memory_free(void *ptr) + +void memory_free(void * ptr) { - sMemBlockInfo *alias; + sMemBlockInfo * alias; - alias=&memoryInfo; - alias=alias->next; - while (alias->ptr!=ptr) - alias=alias->next; + alias = &memoryInfo; + alias = alias->next; + while (alias->ptr != ptr) + alias = alias->next; free(ptr); - currentAllocatedMemory-=alias->size; - alias->prev->next=alias->next; - if (alias->next!=NULL) - alias->next->prev=alias->prev; + currentAllocatedMemory -= alias->size; + alias->prev->next = alias->next; + if (alias->next != NULL) + alias->next->prev = alias->prev; free(alias); } diff --git a/src/objectp.cpp b/src/objectp.cpp index ee2418c..792a850 100644 --- a/src/objectp.cpp +++ b/src/objectp.cpp @@ -1,13 +1,19 @@ +// +// Object Processor +// +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons +// #include #include #include #include "jaguar.h" - //#define OP_DEBUG //#define OP_DEBUG_BMP -static int cnt = 0; +//WTFITF???static int cnt = 0; extern uint32 jaguar_mainRom_crc32; static uint8 * op_blend_y; @@ -16,7 +22,6 @@ static uint8 * op_blend_cc; #define BLEND_Y(dst,src) op_blend_y[(((uint16)dst)<<8) | ((uint16)(src))] #define BLEND_CC(dst,src) op_blend_cc[(((uint16)dst)<<8) | ((uint16)(src))] - static uint8 objectp_ram[0x40]; uint8 objectp_running; @@ -27,6 +32,13 @@ uint8 objectp_stop_reading_list; #define OBJECT_TYPE_GPU 2 #define OBJECT_TYPE_BRANCH 3 #define OBJECT_TYPE_STOP 4 +/* +#define OBJECT_TYPE_BITMAP 000 +#define OBJECT_TYPE_SCALE 001 +#define OBJECT_TYPE_GPU 010 +#define OBJECT_TYPE_BRANCH 011 +#define OBJECT_TYPE_STOP 100 +*/ #define CONDITION_EQUAL 0 #define CONDITION_LESS_THAN 1 @@ -39,53 +51,51 @@ uint8 objectp_stop_reading_list; #define FLAGS_READMODIFY 2 #define FLAGS_HFLIP 1 - -static char * condition_to_str[8] = {"==","<",">","(opflag set)","(second half line)","?","?","?"}; - -static uint8 op_bitmap_bit_depth[8]={1, 2, 4, 8, 16, 24, 32, 0 }; -static uint32 op_bitmap_bit_size[8]={0.125*65536, 0.25*65536, 0.5*65536, 1*65536, 2*65536, 1*65536, 1*65536, 1*65536}; +static uint8 op_bitmap_bit_depth[8] = { 1, 2, 4, 8, 16, 24, 32, 0 }; +static uint32 op_bitmap_bit_size[8] = + { (uint32)(0.125*65536), (uint32)(0.25*65536), (uint32)(0.5*65536), (uint32)(1*65536), + (uint32)(2*65536), (uint32)(1*65536), (uint32)(1*65536), (uint32)(1*65536) }; static uint32 op_pointer; -static int cnt_bitmap = 0; +//WTFITF???static int cnt_bitmap = 0; -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// // +// Object Processor bitmap processing // -// -////////////////////////////////////////////////////////////////////////////// -void op_process_bitmap(int16 *backbuffer, int scanline, uint64 p0, uint64 p1, int render) + +void op_process_bitmap(int16 * backbuffer, int scanline, uint64 p0, uint64 p1, int render) { - uint8 bitdepth=(p1>>12)&0x07; - - int16 ypos=(((p0>>3)&0x3ff)/2); - int32 xpos=(((int32)((p1<<20)&0xffffffff))>>20)-tom_getHBlankWidthInPixels(); - int32 iwidth=((p1>>28)&0x3ff)*4; - uint32 dwidth=((p1>>18)&0x3ff)*4; - int16 height=((p0>>14)&0x3ff)-1; - uint32 link=((p0>>24)&0x7ffff)<<3; - uint32 ptr=(((p0>>43)&0x1fffff)<<3); - uint32 firstPix=(p1>>49)&0x3f; - uint8 flags=(p1>>45)&0x0f; - uint8 idx=(p1>>38)&0x7f; - uint32 pitch=(p1>>15)&0x07; - int16 scanline_width=tom_getVideoModeWidth(); - uint8 *tom_ram_8=tom_get_ram_pointer(); - uint8 *current_line_buffer=&tom_ram_8[0x1800]; - uint8 *paletteRam=&tom_ram_8[0x400]; - uint8 doom_hack=0; - - op_pointer=link; - - if ((!render)||(op_pointer==0)||(height<0)||(dwidth<0)||(ptr==0)||(pitch==0)) - { + uint8 bitdepth = (p1 >> 12) & 0x07; + int16 ypos = ((p0 >> 3) & 0x3FF) / 2; // ??? What if not interlaced (/2)? + int32 xpos = (((int32)((p1 << 20) & 0xFFFFFFFF)) >> 20) - tom_getHBlankWidthInPixels(); + int32 iwidth = ((p1 >> 28) & 0x3FF) * 4; + int32 dwidth = ((p1 >> 18) & 0x3FF) * 4; // ??? Should it be signed or unsigned ??? + int16 height = ((p0 >> 14) & 0x3FF) - 1; + uint32 link = ((p0 >> 24) & 0x7FFFF) << 3; + uint32 ptr = ((p0 >> 43) & 0x1FFFFF) << 3; +#ifdef OP_DEBUG_BMP + uint32 firstPix = (p1 >> 49) & 0x3F; +#endif + uint8 flags = (p1 >> 45) & 0x0F; + uint8 idx = (p1 >> 38) & 0x7F; + uint32 pitch = (p1 >> 15) & 0x07; + int16 scanline_width = tom_getVideoModeWidth(); + uint8 * tom_ram_8 = tom_get_ram_pointer(); + uint8 * current_line_buffer = &tom_ram_8[0x1800]; + uint8 * paletteRam = &tom_ram_8[0x400]; + uint8 doom_hack = 0; + +//if (scanline == 200) +// fprintf(log_get(), "OP --> Current OPPtr: %08X, next: %08X, BMPPtr: %08X\n", op_pointer, link, ptr); + + op_pointer = link; + + if (!render || (op_pointer == 0) || (height < 0) || (dwidth < 0) || (ptr == 0) || (pitch == 0)) return; - } - if (iwidth==0) - { - dwidth=iwidth=height; - } - if (jaguar_mainRom_crc32==0x5e705756) // doom + + if (iwidth == 0) + dwidth = iwidth = height; + + if (jaguar_mainRom_crc32 == 0x5e705756) // doom { if ((iwidth==160)&&(height==179)&&(xpos==-9)&&(ypos==24)) { @@ -107,51 +117,47 @@ void op_process_bitmap(int16 *backbuffer, int scanline, uint64 p0, uint64 p1, in { ypos+=8; } - if (op_bitmap_bit_depth[bitdepth]==24) + if (op_bitmap_bit_depth[bitdepth] == 24) { - iwidth*=2; - dwidth*=2; + iwidth *= 2; + dwidth *= 2; } - if (op_bitmap_bit_depth[bitdepth]==8) + if (op_bitmap_bit_depth[bitdepth] == 8) { - iwidth*=2; - dwidth*=2; + iwidth *= 2; + dwidth *= 2; } - if (op_bitmap_bit_depth[bitdepth]==4) + if (op_bitmap_bit_depth[bitdepth] == 4) { - iwidth*=2; - dwidth*=2; + iwidth *= 2; + dwidth *= 2; } - if (op_bitmap_bit_depth[bitdepth]==2) + if (op_bitmap_bit_depth[bitdepth] == 2) { - iwidth*=2; - dwidth*=2; + iwidth *= 2; + dwidth *= 2; } - if (op_bitmap_bit_depth[bitdepth]==1) + if (op_bitmap_bit_depth[bitdepth] == 1) { - iwidth*=2; - dwidth*=2; + iwidth *= 2; + dwidth *= 2; } // Power Drive Rally (fixed size bitmaps have a 240 lines vertical offset) // but could well be a modulo 240 if (jaguar_mainRom_crc32==0x0ab88d90) - ypos%=240; - + ypos %= 240; #ifdef OP_DEBUG_BMP fprintf(log_get(),"bitmap %ix%i %ibpp at %i,%i firstpix=%i ptr=0x%.8x pitch %i hflipped=%s dwidth=%i (linked to 0x%.8x) Transluency=%s\n",iwidth,height,op_bitmap_bit_depth[bitdepth],xpos,ypos,firstPix,ptr,pitch,flags&FLAGS_HFLIP?"yes":"no",dwidth,op_pointer,(flags&FLAGS_READMODIFY)?"yes":"no"); #endif - if ((scanline(ypos+height))) - { + if ((scanline < ypos) || (scanline > (ypos + height))) return; - } + // seek to the good bitmap scanline // not sure for palettized modes if (op_bitmap_bit_depth[bitdepth] > 8) - { ptr += ((dwidth * op_bitmap_bit_size[bitdepth]) >> 16) * (scanline - ypos); - } else ptr += dwidth * (scanline - ypos); @@ -164,31 +170,30 @@ void op_process_bitmap(int16 *backbuffer, int scanline, uint64 p0, uint64 p1, in if (iwidth <= 0) { -#ifdef OP_DEBUG - fprintf(log_get(),"not rendering because iwidth<0\n"); +#ifdef OP_DEBUG_BMP + fprintf(log_get(), "not rendering because iwidth <= 0\n"); #endif return; } - if (flags&FLAGS_HFLIP) + if (flags & FLAGS_HFLIP) { - if ((xpos<0)||((xpos-iwidth)>=scanline_width)) + if ((xpos < 0) || ((xpos - iwidth) >= scanline_width)) return; - if ((xpos-iwidth)<0) - iwidth=xpos; + if ((xpos - iwidth) < 0) + iwidth = xpos; } else { - if (((xpos+iwidth)<0)||(xpos>=scanline_width)) + if (((xpos + iwidth) < 0) || (xpos >= scanline_width)) return; - if ((xpos+iwidth)>scanline_width) - iwidth=scanline_width-xpos; + if ((xpos + iwidth) > scanline_width) + iwidth = scanline_width - xpos; } - - current_line_buffer+=(xpos*2); // 2 in 16 bpp modes (need to take the mode into account) + current_line_buffer += xpos * 2; // 2 in 16 bpp modes (need to take the mode into account) // doom switches the resolution from 320 to 160 to double the display width // this is not yet supported @@ -207,111 +212,102 @@ void op_process_bitmap(int16 *backbuffer, int scanline, uint64 p0, uint64 p1, in } return; } - if (op_bitmap_bit_depth[bitdepth]==1) + if (op_bitmap_bit_depth[bitdepth] == 1) { - if (pitch==1) + if (pitch == 1) { - #include "include/fbmpop1.h" +#include "fbmpop1.h" } else { - #include "include/fbmpop1p.h" +#include "fbmpop1p.h" } } - else - if (op_bitmap_bit_depth[bitdepth]==2) + else if (op_bitmap_bit_depth[bitdepth] == 2) { - if (pitch==1) + if (pitch == 1) { - #include "include/fbmpop2.h" +#include "fbmpop2.h" } else { - #include "include/fbmpop2p.h" +#include "fbmpop2p.h" } } - else - if (op_bitmap_bit_depth[bitdepth]==4) + else if (op_bitmap_bit_depth[bitdepth] == 4) { - if (pitch==1) + if (pitch == 1) { - #include "include/fbmpop4.h" +#include "fbmpop4.h" } else { - #include "include/fbmpop4p.h" +#include "fbmpop4p.h" } } - else - if (op_bitmap_bit_depth[bitdepth]==8) + else if (op_bitmap_bit_depth[bitdepth] == 8) { - if (pitch==1) + if (pitch == 1) { - #include "include/fbmpop8.h" +#include "fbmpop8.h" } else { - #include "include/fbmpop8p.h" +#include "fbmpop8p.h" } } - else - if (op_bitmap_bit_depth[bitdepth]==16) + else if (op_bitmap_bit_depth[bitdepth] == 16) { - if (pitch==1) + if (pitch == 1) { - #include "include/fbmpop16.h" +#include "fbmpop16.h" } else { - #include "include/fbmpop16p.h" +#include "fbmpop16p.h" } } - else - if (op_bitmap_bit_depth[bitdepth]==24) + else if (op_bitmap_bit_depth[bitdepth] == 24) { - if (pitch==1) + if (pitch == 1) { - #include "include/fbmpop24.h" +#include "fbmpop24.h" } else { - #include "include/fbmpop24p.h" +#include "fbmpop24p.h" } } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// + // +// Object Processor scaled bitmap processing // -////////////////////////////////////////////////////////////////////////////// -void op_process_scaled_bitmap(int16 *backbuffer, int scanline, uint64 p0, uint64 p1, uint64 p2, int render) -{ - int32 xpos=(((int32)((p1<<20)&0xffffffff))>>20)-tom_getHBlankWidthInPixels(); - int16 ypos=(((p0&0x3ff8)>>3)/2); - uint16 iwidth=((p1>>28)&0x3ff)*4; - uint16 dwidth=((p1>>18)&0x3ff)*4; - uint16 height=(p0>>14)&0x3ff; - uint32 link=((p0>>24)&0x7ffff)<<3; - uint32 ptr=((p0>>43)&0x1fffff)<<3; - uint32 firstPix=(p1>>49)&0x3f; - uint8 flags=(p1>>45)&0x0f; - uint8 idx=(p1>>38)&0x7f; - uint8 pitch=(p1>>15)&0x07; - uint8 bitdepth=(p1>>12)&0x07; - int16 scanline_width=tom_getVideoModeWidth(); - uint8 *tom_ram_8=tom_get_ram_pointer(); - uint8 *current_line_buffer=&tom_ram_8[0x1800]; - float vscale; - float hscale; - - uint32 vscale_fixed3p5=((p2>>8)&0xff); - uint32 hscale_fixed3p5=(p2&0xff); - vscale=((float)vscale_fixed3p5)/32; - hscale=((float)hscale_fixed3p5)/32; - op_pointer=link; +void op_process_scaled_bitmap(int16 * backbuffer, int scanline, uint64 p0, uint64 p1, uint64 p2, int render) +{ +// if ((render == 0) || (op_pointer == 0) || (height < 0) || (dwidth < 0) || (ptr == 0) || (pitch == 0)) + + int32 xpos = (((int32)((p1 << 20) & 0xFFFFFFFF)) >> 20) - tom_getHBlankWidthInPixels(); + int16 ypos = ((p0 & 0x3FF8) >> 3) / 2; + uint16 iwidth = ((p1 >> 28) & 0x3FF) * 4; + int16 dwidth = ((p1 >> 18) & 0x3FF) * 4; // ??? Signed or unsigned ??? + int16 height = (p0 >> 14) & 0x3FF; // ??? Signed or unsigned ??? + uint32 link = ((p0 >> 24) & 0x7FFFF) << 3; + uint32 ptr = ((p0 >> 43) & 0x1FFFFF) << 3; +//unused uint32 firstPix = (p1 >> 49) & 0x3F; + uint8 flags = (p1 >> 45) & 0x0F; + uint8 idx = (p1 >> 38) & 0x7F; + uint8 pitch = (p1 >> 15) & 0x07; + uint8 bitdepth = (p1 >> 12) & 0x07; + int16 scanline_width = tom_getVideoModeWidth(); + uint8 * tom_ram_8 = tom_get_ram_pointer(); + uint8 * current_line_buffer = &tom_ram_8[0x1800]; + uint32 vscale_fixed3p5 = ((p2 >> 8) & 0xFF); + uint32 hscale_fixed3p5 = (p2 & 0xFF); + float vscale = (float)vscale_fixed3p5 / 32.0f, hscale = (float)hscale_fixed3p5 / 32.0f; + + op_pointer = link; if (jaguar_mainRom_crc32==0x5a5b9c68) // atari karts { @@ -323,23 +319,15 @@ void op_process_scaled_bitmap(int16 *backbuffer, int scanline, uint64 p0, uint64 } #ifdef OP_DEBUG_BMP if (xpos == -3) - fprintf(log_get(),"[scanline %i] %ix%i scaled to %ix%i scale (%f, %f)%i bpp pitch %i at (%i,%i) @ 0x%.8x Transluency=%s\n", - scanline, - iwidth,height, - (int)(iwidth*hscale), - (int)(height*vscale), - hscale, vscale, - op_bitmap_bit_depth[bitdepth],pitch,xpos,ypos,ptr,(flags&FLAGS_READMODIFY)?"yes":"no"); + fprintf(log_get(), "[scanline %i] %ix%i scaled to %ix%i scale (%f, %f)%i bpp pitch %i at (%i,%i) @ 0x%.8x Transluency=%s\n", + scanline, iwidth,height, (int)(iwidth*hscale), (int)(height*vscale), hscale, vscale, + op_bitmap_bit_depth[bitdepth], pitch, xpos, ypos, ptr, (flags&FLAGS_READMODIFY) ? "yes" : "no"); #endif if (jaguar_mainRom_crc32==0x2f032271) - { - ypos+=8; - } + ypos += 8; - if ((render==0)||(op_pointer==0)||(height<0)||(dwidth<0)||(ptr==0)||(pitch==0)) - { + if ((render == 0) || (op_pointer == 0) || (height < 0) || (dwidth < 0) || (ptr == 0) || (pitch == 0)) return; - } if (op_bitmap_bit_depth[bitdepth]==8) { @@ -362,35 +350,35 @@ void op_process_scaled_bitmap(int16 *backbuffer, int scanline, uint64 p0, uint64 dwidth*=2; } - uint16 scaled_width=iwidth*hscale; - uint16 scaled_height=height*vscale; + uint16 scaled_width = (uint16)((float)iwidth * hscale), + scaled_height = (uint16)((float)height * vscale); - if (op_bitmap_bit_depth[bitdepth]==4) // why ? - scaled_width*=2; + if (op_bitmap_bit_depth[bitdepth] == 4) // why ? + scaled_width *= 2; - if (op_bitmap_bit_depth[bitdepth]==2) // why ? - scaled_width*=4; + if (op_bitmap_bit_depth[bitdepth] == 2) // why ? + scaled_width *= 4; - if (op_bitmap_bit_depth[bitdepth]==1) // why ? - scaled_width*=8; + if (op_bitmap_bit_depth[bitdepth] == 1) // why ? + scaled_width *= 8; // seek to the good bitmap scanline // not sure for palettized modes - if (op_bitmap_bit_depth[bitdepth]>8) - ptr+=((dwidth*op_bitmap_bit_size[bitdepth])>>16)*((uint32)((scanline-ypos)/vscale)); + if (op_bitmap_bit_depth[bitdepth] > 8) + ptr += ((dwidth * op_bitmap_bit_size[bitdepth]) >> 16) * ((uint32)((scanline - ypos) / vscale)); else - ptr+=dwidth*((uint32)((scanline-ypos)/vscale)); + ptr += dwidth * ((uint32)((scanline - ypos) / vscale)); // visible ? - if ((scanline(ypos+scaled_height))||((xpos+scaled_width)<0)||(xpos>=scanline_width)) + if ((scanline < ypos) || (scanline > (ypos+scaled_height)) || ((xpos+scaled_width) < 0) + || (xpos >= scanline_width)) return; - - if (xpos<0) + if (xpos < 0) { - scaled_width+=xpos; - ptr+=(pitch*op_bitmap_bit_size[bitdepth]*((uint32)((-xpos)/hscale)))>>16; - xpos=0; + scaled_width += xpos; + ptr += (pitch * op_bitmap_bit_size[bitdepth] * ((uint32)((-xpos) / hscale))) >> 16; + xpos = 0; } if (iwidth<=0) @@ -413,114 +401,85 @@ void op_process_scaled_bitmap(int16 *backbuffer, int scanline, uint64 p0, uint64 scaled_width=scanline_width-xpos; } - current_line_buffer+=(xpos*2); + current_line_buffer += xpos * 2; - int32 hscale_fixed=(int32)(65536.0f/hscale); - int32 cnt=0; + int32 hscale_fixed = (int32)(65536.0f / hscale); + int32 cnt = 0; - if (op_bitmap_bit_depth[bitdepth]==1) + if (op_bitmap_bit_depth[bitdepth] == 1) { - if (pitch==1) + if (pitch == 1) { - #include "include/zbmpop1.h" +#include "zbmpop1.h" } else { - #include "include/zbmpop1p.h" +#include "zbmpop1p.h" } } - else - if (op_bitmap_bit_depth[bitdepth]==2) + else if (op_bitmap_bit_depth[bitdepth] == 2) { - if (pitch==1) + if (pitch == 1) { - #include "include/zbmpop2.h" +#include "zbmpop2.h" } else { - #include "include/zbmpop2p.h" +#include "zbmpop2p.h" } } - else - if (op_bitmap_bit_depth[bitdepth]==4) + else if (op_bitmap_bit_depth[bitdepth] == 4) { - if (pitch==1) + if (pitch == 1) { - #include "include/zbmpop4.h" +#include "zbmpop4.h" } else { - #include "include/zbmpop4p.h" +#include "zbmpop4p.h" } } - else - if (op_bitmap_bit_depth[bitdepth]==8) + else if (op_bitmap_bit_depth[bitdepth] == 8) { - if (pitch==1) + if (pitch == 1) { - #include "include/zbmpop8.h" +#include "zbmpop8.h" } else { - #include "include/zbmpop8p.h" +#include "zbmpop8p.h" } } - else - if (op_bitmap_bit_depth[bitdepth]==16) + else if (op_bitmap_bit_depth[bitdepth] == 16) { - if (pitch==1) + if (pitch == 1) { - #include "include/zbmpop16.h" +#include "zbmpop16.h" } else { - #include "include/zbmpop16p.h" +#include "zbmpop16p.h" } } else fprintf(log_get(),"(unimplemented) %i bpp scaled bitmap\n",op_bitmap_bit_depth[bitdepth]); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint64 op_load_phrase(uint32 offset) { - offset &= (~0x07); // 8 byte alignment - - uint64 data = jaguar_byte_read(offset++); - data <<= 8; - data |= jaguar_byte_read(offset++); - data <<= 8; - data |= jaguar_byte_read(offset++); - data <<= 8; - data |= jaguar_byte_read(offset++); - data <<= 8; - data |= jaguar_byte_read(offset++); - data <<= 8; - data |= jaguar_byte_read(offset++); - data <<= 8; - data |= jaguar_byte_read(offset++); - data <<= 8; - data |= jaguar_byte_read(offset++); - - return data; + offset &= ~0x07; // 8 byte alignment + return ((uint64)jaguar_long_read(offset) << 32) | (uint64)jaguar_long_read(offset+4); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// + // +// Object Processor main list processing // -////////////////////////////////////////////////////////////////////////////// + void op_process_list(int16 * backbuffer, int scanline, int render) { - uint64 p0; - - cnt_bitmap = 0; +// char * condition_to_str[8] = +// { "==", "<", ">", "(opflag set)", "(second half line)", "?", "?", "?" }; +//WTFITF??? cnt_bitmap = 0; if (scanline < tom_get_vdb()) return; @@ -531,7 +490,7 @@ void op_process_list(int16 * backbuffer, int scanline, int render) op_pointer = op_get_list_pointer(); objectp_stop_reading_list = 0; - cnt = 0; +//WTFITF??? cnt = 0; // if (op_pointer) fprintf(log_get()," new op list at 0x%.8x scanline %i\n",op_pointer,scanline); while (op_pointer) @@ -539,12 +498,58 @@ void op_process_list(int16 * backbuffer, int scanline, int render) if (objectp_stop_reading_list) return; - p0 = op_load_phrase(op_pointer); + uint64 p0 = op_load_phrase(op_pointer); op_pointer += 8; +/*if (scanline == tom_get_vdb()) +{ +fprintf(log_get(), "%08X --> phrase %08X %08X", op_pointer - 8, (int)(p0>>32), (int)(p0&0xFFFFFFFF)); +if ((p0 & 0x07) == OBJECT_TYPE_BITMAP) +{ +fprintf(log_get(), " (BITMAP) "); +uint64 p1 = op_load_phrase(op_pointer); +fprintf(log_get(), "\n%08X --> phrase %08X %08X ", op_pointer, (int)(p1>>32), (int)(p1&0xFFFFFFFF)); + uint8 bitdepth = (p1 >> 12) & 0x07; + int16 ypos = ((p0 >> 3) & 0x3FF); // ??? What if not interlaced (/2)? +// int32 xpos = (((int32)((p1 << 20) & 0xFFFFFFFF)) >> 20); +int32 xpos = p1 & 0xFFF; +xpos = (xpos & 0x800 ? xpos | 0xFFFFF000 : xpos); + uint32 iwidth = ((p1 >> 28) & 0x3FF); + uint32 dwidth = ((p1 >> 18) & 0x3FF); // ??? Should it be signed or unsigned ??? + int16 height = ((p0 >> 14) & 0x3FF) - 1; + uint32 link = ((p0 >> 24) & 0x7FFFF) << 3; + uint32 ptr = ((p0 >> 43) & 0x1FFFFF) << 3; + uint32 firstPix = (p1 >> 49) & 0x3F; + uint8 flags = (p1 >> 45) & 0x0F; + uint8 idx = (p1 >> 38) & 0x7F; + uint32 pitch = (p1 >> 15) & 0x07; +fprintf(log_get(), "[%u (%u) x %u @ %i, %u (%u bpp), l: %08X, p: %08X fp: %02X, fl:%02X, idx:%02X, pt:%02X]\n", iwidth, dwidth, height, xpos, ypos, op_bitmap_bit_depth[bitdepth], link, ptr, firstPix, flags, idx, pitch); +uint8 * jaguar_mainRam = GetRamPtr(); +fprintf(log_get(), "[RAM] --> "); +for(int k=0; k<16; k++) + fprintf(log_get(), "%02X ", jaguar_mainRam[op_pointer-8 + k]); +fprintf(log_get(), "\n"); +} +if ((p0 & 0x07) == OBJECT_TYPE_SCALE) +{ +fprintf(log_get(), " (SCALED BITMAP)\n"); +} +if ((p0 & 0x07) == OBJECT_TYPE_GPU) +fprintf(log_get(), " (GPU)\n"); +if ((p0 & 0x07) == OBJECT_TYPE_BRANCH) +{ +fprintf(log_get(), " (BRANCH)\n"); +uint8 * jaguar_mainRam = GetRamPtr(); +fprintf(log_get(), "[RAM] --> "); +for(int k=0; k<8; k++) + fprintf(log_get(), "%02X ", jaguar_mainRam[op_pointer-8 + k]); +fprintf(log_get(), "\n"); +} +if ((p0 & 0x07) == OBJECT_TYPE_STOP) +fprintf(log_get(), " --> List end\n"); +}*/ - // fprintf(log_get(),"0x%.8x type %i\n",op_pointer,((uint8)p0&0x07)); - switch ((uint8)p0&0x07) + switch ((uint8)p0 & 0x07) { case OBJECT_TYPE_BITMAP: { @@ -564,16 +569,16 @@ void op_process_list(int16 * backbuffer, int scanline, int render) } case OBJECT_TYPE_GPU: { - uint64 data = p0 >> 3; +//unused uint64 data = p0 >> 3; op_set_current_object(p0); gpu_set_irq_line(3, 1); break; } case OBJECT_TYPE_BRANCH: { - uint16 vcnt = (p0>>3) & 0x7FF; - uint8 cc = (p0>>14) & 0x03; - uint32 link = ((p0>>24) & 0x1FFFFF) << 3; + uint16 vcnt = (p0 >> 3) & 0x7FF; + uint8 cc = (p0 >> 14) & 0x03; + uint32 link = ((p0 >> 24) & 0x1FFFFF) << 3; // if ((vcnt!=507)&&(vcnt!=25)) // fprintf(log_get(),"\t%i%s%i link=0x%.8x\n",scanline,condition_to_str[cc],vcnt>>1,link); @@ -582,20 +587,20 @@ void op_process_list(int16 * backbuffer, int scanline, int render) case CONDITION_EQUAL: if ((vcnt != 0x7FF) && (vcnt & 0x01)) vcnt ^= 0x01; - if (((2*tom_get_scanline()) == vcnt) || (vcnt == 0x7FF)) - op_pointer=link; + if (((2 * tom_get_scanline()) == vcnt) || (vcnt == 0x7FF)) + op_pointer = link; break; case CONDITION_LESS_THAN: - if ((2*tom_get_scanline()) < vcnt) - op_pointer=link; + if ((2 * tom_get_scanline()) < vcnt) + op_pointer = link; break; case CONDITION_GREATER_THAN: - if ((2*tom_get_scanline()) > vcnt) - op_pointer=link; + if ((2 * tom_get_scanline()) > vcnt) + op_pointer = link; break; case CONDITION_OP_FLAG_SET: if (op_get_status_register() & 0x01) - op_pointer=link; + op_pointer = link; break; case CONDITION_SECOND_HALF_LINE: fprintf(log_get(), "op: unexpected CONDITION_SECOND_HALF_LINE in BRANCH object\nop: shuting down\n"); @@ -627,20 +632,16 @@ void op_process_list(int16 * backbuffer, int scanline, int render) break; } default: - { fprintf(log_get(),"op: unknown object type %i\n", ((uint8)p0 & 0x07)); return; } - } } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// + // +// Object Processor initialization // -////////////////////////////////////////////////////////////////////////////// + void op_init(void) { memory_malloc_secure((void **)&op_blend_y, 0x10000, "Jaguar Object processor Y blend lookup table"); @@ -671,108 +672,76 @@ void op_init(void) } op_reset(); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// + // +// Object Processor reset // -////////////////////////////////////////////////////////////////////////////// + void op_reset(void) { - memset(objectp_ram, 0x00, 0x18); + memset(objectp_ram, 0x00, 0x40); objectp_running = 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void op_done(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void op_byte_write(uint32 offset, uint8 data) { offset &= 0x3F; objectp_ram[offset] = data; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void op_word_write(uint32 offset, uint16 data) { offset &= 0x3F; objectp_ram[offset] = (data >> 8) & 0xFF; objectp_ram[offset+1] = data & 0xFF; +/*if (offset == 0x20) +fprintf(log_get(), "OP: Setting lo list pointer: %04X\n", data); +if (offset == 0x22) +fprintf(log_get(), "OP: Setting hi list pointer: %04X\n", data);//*/ } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + +// Memory range: F00010 - F00027 + uint8 op_byte_read(uint32 offset) { offset &= 0x3F; return objectp_ram[offset]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint16 op_word_read(uint32 offset) { return (objectp_ram[offset & 0x3F] << 8) | objectp_ram[(offset+1) & 0x3F]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + +// F00010-F00017 R xxxxxxxx xxxxxxxx OB - current object code from the graphics processor +// F00020-F00023 W xxxxxxxx xxxxxxxx OLP - start of the object list +// F00026 W -------- -------x OBF - object processor flag + uint32 op_get_list_pointer(void) { - uint32 ptr = objectp_ram[0x22]; + // Note: This register is WORD swapped, hence the funky look of this... +/* uint32 ptr = objectp_ram[0x22]; ptr <<= 8; ptr |= objectp_ram[0x23]; ptr <<= 8; ptr |= objectp_ram[0x20]; ptr <<= 8; ptr |= objectp_ram[0x21]; +fprintf(log_get(), "OP: Getting list pointer: %08X\n", (unsigned int)ptr); ptr &= ~0x07; return ptr;//*/ -// return (objectp_ram[0x20] << 24) | (objectp_ram[0x21] << 16) | (objectp_ram[0x22] << 8) | objectp_ram[0x23]; + return (objectp_ram[0x22] << 24) | (objectp_ram[0x23] << 16) | (objectp_ram[0x20] << 8) | objectp_ram[0x21]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint32 op_get_status_register(void) { - uint32 ptr = objectp_ram[0x26]; +/* uint32 ptr = objectp_ram[0x26]; ptr <<= 8; ptr |= objectp_ram[0x27]; ptr <<= 8; @@ -780,15 +749,10 @@ uint32 op_get_status_register(void) ptr <<= 8; ptr |= objectp_ram[0x29]; - return ptr; + return ptr;//*/ + return (objectp_ram[0x26] << 24) | (objectp_ram[0x27] << 16) | (objectp_ram[0x28] << 8) | objectp_ram[0x29]; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void op_set_status_register(uint32 data) { objectp_ram[0x26] = (data & 0xFF000000) >> 24; @@ -796,24 +760,28 @@ void op_set_status_register(uint32 data) objectp_ram[0x28] = (data & 0x0000FF00) >> 8; objectp_ram[0x29] |= (data & 0xFE); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void op_set_current_object(uint64 object) { - // less significant 32 bits first - objectp_ram[0x13] = object&0xff; object>>=8; - objectp_ram[0x12] = object&0xff; object>>=8; - objectp_ram[0x11] = object&0xff; object>>=8; - objectp_ram[0x10] = object&0xff; object>>=8; - - objectp_ram[0x17] = object&0xff; object>>=8; - objectp_ram[0x16] = object&0xff; object>>=8; - objectp_ram[0x15] = object&0xff; object>>=8; - objectp_ram[0x14] = object&0xff; +/* + 32 28 24 20 16 12 8 4 0 + +--------^---------^---------^--------^--------^--------^--------^--------+ +0 | object-data | + +-------------------------------------------------------------------------+ + + 64 60 56 52 48 44 40 36 32 + +--------^---------^---------^--------^--------^--------^--------^--------+ +1 | object-data | + +-------------------------------------------------------------------------+ +*/ + // Stored as least significant 32 bits first, ms32 last in big endian + objectp_ram[0x13] = object & 0xFF; object >>= 8; + objectp_ram[0x12] = object & 0xFF; object >>= 8; + objectp_ram[0x11] = object & 0xFF; object >>= 8; + objectp_ram[0x10] = object & 0xFF; object >>= 8; + + objectp_ram[0x17] = object & 0xFF; object >>= 8; + objectp_ram[0x16] = object & 0xFF; object >>= 8; + objectp_ram[0x15] = object & 0xFF; object >>= 8; + objectp_ram[0x14] = object & 0xFF; } - diff --git a/src/pcm.cpp b/src/pcm.cpp index 596d846..ad49706 100644 --- a/src/pcm.cpp +++ b/src/pcm.cpp @@ -1,6 +1,14 @@ -#include "include/pcm.h" +// +// PCM Handler +// +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons +// + +#include "pcm.h" -#define PCM_DUMP +//#define PCM_DUMP #define sample_rate 44100 #define sample_bits 16 @@ -13,45 +21,29 @@ static uint32 pcm_left_pos; static uint32 pcm_right_pos; static uint32 pcm_left_playback_pos; static uint32 pcm_right_playback_pos; -static FILE * fp_left; -static FILE * fp_right; static uint32 pcm_sample_rate = sample_rate; static uint32 pcm_inc = (pcm_sample_rate << 8) / sample_rate; +#ifdef PCM_DUMP +static FILE * fp_left; +static FILE * fp_right; +#endif + -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// void pcm_set_sample_rate(int rate) { pcm_sample_rate = rate; pcm_inc = (pcm_sample_rate << 8) / sample_rate; // fprintf(log_get(),"pcm: sample rate is %i hz, sample increment is %i (%f)\n",pcm_sample_rate,pcm_inc,((float)pcm_inc)/256.0f); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void pcm_updateOne(int channel, int16 *data, uint32 length) + +void pcm_updateOne(int channel, int16 * data, uint32 length) { - if (channel==0) + if (channel == 0) { while (length) { - *data++=pcm_left[(pcm_left_playback_pos>>8)%buffer_modulo]; - pcm_left_playback_pos+=pcm_inc; + *data++ = pcm_left[(pcm_left_playback_pos >> 8) % buffer_modulo]; + pcm_left_playback_pos += pcm_inc; length--; } } @@ -59,177 +51,91 @@ void pcm_updateOne(int channel, int16 *data, uint32 length) { while (length) { - *data++=pcm_right[(pcm_right_playback_pos>>8)%buffer_modulo]; - pcm_right_playback_pos+=pcm_inc; + *data++ = pcm_right[(pcm_right_playback_pos >> 8) % buffer_modulo]; + pcm_right_playback_pos += pcm_inc; length--; } } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_init(void) { - memory_malloc_secure((void**)&pcm_left,buffer_modulo*sizeof(int16),"Left dac buffer"); - memory_malloc_secure((void**)&pcm_right,buffer_modulo*sizeof(int16),"Right dac buffer"); + memory_malloc_secure((void **)&pcm_left, buffer_modulo * sizeof(int16), "Left dac buffer"); + memory_malloc_secure((void **)&pcm_right, buffer_modulo * sizeof(int16), "Right dac buffer"); pcm_reset(); - fp_left=fopen("leftdac.raw","wb"); - fp_right=fopen("rightdac.raw","wb"); - +#ifdef PCM_DUMP + fp_left = fopen("leftdac.raw", "wb"); + fp_right = fopen("rightdac.raw", "wb"); +#endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_reset(void) { - pcm_left_pos=0; - pcm_right_pos=0; - pcm_left_playback_pos=0; - pcm_right_playback_pos=0; + pcm_left_pos = 0; + pcm_right_pos = 0; + pcm_left_playback_pos = 0; + pcm_right_playback_pos = 0; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_done(void) { +#ifdef PCM_DUMP fclose(fp_left); fclose(fp_right); +#endif + fprintf(log_get(), "PCM: Done.\n"); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_update(void) { } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_render_left_dac(void) { #ifdef PCM_DUMP - fwrite(pcm_left,1,sample_rate*2,fp_left); + fwrite(pcm_left, 1, sample_rate * 2, fp_left); #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_render_right_dac(void) { #ifdef PCM_DUMP - fwrite(pcm_right,1,sample_rate*2,fp_right); + fwrite(pcm_right, 1, sample_rate * 2, fp_right); #endif } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_byte_write(uint32 offset, uint8 data) { // fprintf(log_get(),"pcm: writing 0x%.2x at 0x%.8x\n",data,offset); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void pcm_word_write(uint32 offset, uint16 data) { - if (offset==2) + if (offset == 2) { - pcm_left[pcm_left_pos%buffer_modulo]=data; + pcm_left[pcm_left_pos % buffer_modulo] = data; pcm_left_pos++; - if ((pcm_left_pos%buffer_modulo)==0) + if ((pcm_left_pos % buffer_modulo) == 0) pcm_render_left_dac(); } else - if (offset==6) + if (offset == 6) { - pcm_right[pcm_right_pos%buffer_modulo]=data; + pcm_right[pcm_right_pos % buffer_modulo] = data; pcm_right_pos++; - if ((pcm_right_pos%buffer_modulo)==0) + if ((pcm_right_pos % buffer_modulo) == 0) pcm_render_right_dac(); } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint8 pcm_byte_read(uint32 offset) { // fprintf(log_get(),"pcm: reading byte from 0x%.8x\n",offset); - return(0xff); + return 0xFF; } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + uint16 pcm_word_read(uint32 offset) { // fprintf(log_get(),"pcm: reading word from 0x%.8x\n",offset); - return(0xffff); + return 0xFFFF; } diff --git a/src/tom.cpp b/src/tom.cpp index f1709e6..c98916a 100644 --- a/src/tom.cpp +++ b/src/tom.cpp @@ -1,7 +1,7 @@ // // TOM Processing // -// by cal16 +// by cal2 // GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) // Cleanups and endian wrongness amelioration by James L. Hammons // Note: Endian wrongness probably stems from the MAME origins of this emu and @@ -931,31 +931,6 @@ void tom_reset(void) tom_timer_counter = 0; memcpy(scanline_render, scanline_render_normal, sizeof(scanline_render)); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// -void tom_done(void) -{ -// fprintf(log_get(),"tom: done()\n"); - op_done(); - pcm_done(); - blitter_done(); - fprintf(log_get(), "tom: resolution %ix%i %s\n", tom_getVideoModeWidth(), tom_getVideoModeHeight(), - videoMode_to_str[tom_getVideoMode()]); -// fprintf(log_get(),"\ntom: object processor:\n"); -// fprintf(log_get(),"tom: pointer to object list: 0x%.8x\n",op_get_list_pointer()); -// fprintf(log_get(),"tom: INT1=0x%.2x%.2x\n",tom_byte_read(0xf000e0),tom_byte_read(0xf000e1)); - gpu_done(); - dsp_done(); - memory_free(tom_ram_8); -} // // TOM byte access (read) @@ -1199,58 +1174,22 @@ void tom_word_write(unsigned offset, unsigned data) } } } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + int tom_irq_enabled(int irq) { return jaguar_byte_read(0xF000E1) & (1 << irq); } -////////////////////////////////////////////////////////////////////////////// -// -////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -////////////////////////////////////////////////////////////////////////////// + void tom_set_irq_latch(int irq, int enabled) { tom_ram_8[0xE0] = (tom_ram_8[0xE0] & (~(1< 0) @@ -1289,3 +1219,21 @@ void tom_pit_exec(uint32 cycles) } } } + +void tom_done(void) +{ + fprintf(log_get(),"TOM: done() ...START\n"); + op_done(); + pcm_done(); +//This is killing the log for some reason, even though it doesn't do much of anything... +// blitter_done(); + fprintf(log_get(), "TOM: resolution %i x %i %s\n", tom_getVideoModeWidth(), tom_getVideoModeHeight(), + videoMode_to_str[tom_getVideoMode()]); +// fprintf(log_get(),"\ntom: object processor:\n"); +// fprintf(log_get(),"tom: pointer to object list: 0x%.8x\n",op_get_list_pointer()); +// fprintf(log_get(),"tom: INT1=0x%.2x%.2x\n",tom_byte_read(0xf000e0),tom_byte_read(0xf000e1)); + gpu_done(); + dsp_done(); + memory_free(tom_ram_8); + fprintf(log_get(),"TOM: done() ...END\n"); +} diff --git a/src/version.cpp b/src/version.cpp index 53d86d3..a62ec53 100644 --- a/src/version.cpp +++ b/src/version.cpp @@ -1,58 +1,22 @@ -//////////////////////////////////////////////////////////////////////////////// // -//////////////////////////////////////////////////////////////////////////////// +// VERSION.CPP // +// by cal2 +// GCC/SDL port by Niels Wagenaar (Linux/WIN32) and Caz (BeOS) +// Cleanups by James L. Hammons // -// -// -// -// -// -//////////////////////////////////////////////////////////////////////////////// -#include "include/version.h" +#include "version.h" -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -// -//////////////////////////////////////////////////////////////////////////////// void version_init(void) { } -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -// -//////////////////////////////////////////////////////////////////////////////// -void version_display(FILE *fp) + +void version_display(FILE * fp) { - fprintf(fp,"VirtualJaguar v1.0.0 (Last full build on %s %s)\n",__DATE__,__TIME__); + fprintf(fp, "VirtualJaguar v1.0.3 (Last full build on %s %s)\n", __DATE__, __TIME__); } -//////////////////////////////////////////////////////////////////////////////// -// -//////////////////////////////////////////////////////////////////////////////// -// -// -// -// -// -// -// -//////////////////////////////////////////////////////////////////////////////// + void version_done(void) { } - -- 2.37.2