├── src ├── GBSImport.h ├── main_cmd.cpp ├── GBSImport2.sln ├── global_stuff.h ├── GBS_Emu.h ├── ft_stuff.h ├── GBSImport2.rc ├── FTMFile.h ├── Winmain.cpp ├── GBSImport2.vcproj ├── GBZ80_tables.h ├── GBS_Emu.cpp ├── GBZ80_macros.h ├── GBSImport.cpp ├── GBS_Cpu.cpp ├── resource.h ├── FTMFile.cpp └── license.txt ├── README.md └── LICENSE /src/GBSImport.h: -------------------------------------------------------------------------------- 1 | namespace GBSImport 2 | { 3 | bool Scan(char* filename); 4 | bool Import(char* filename, int track, int seconds, bool alltracks, bool nosilence); 5 | char* GetError(); 6 | } -------------------------------------------------------------------------------- /src/main_cmd.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "GBSImport.h" 3 | 4 | char filename[] = "Mega Man Xtreme 2.gbs"; 5 | 6 | int main(int argc, char** argv) 7 | { 8 | if(!GBSImport::Import(filename, 8, 5, 0, 1)) goto main_error; 9 | 10 | system("pause"); 11 | return 0; 12 | 13 | main_error: 14 | 15 | system("pause"); 16 | return 1; 17 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GBS-Import 2 | .gbs to .ftm converter for famitracker written by Slimeball. 3 | Uploaded to github after original release went down (http://famitracker.com/forum/posts.php?page=1&id=5715) 4 | 5 | ### Instructions 6 | 7 | Output files are located in the gbs's source directory. The rest should be obvious. ;) 8 | 9 | Credits go to: 10 | 11 | - Slimeball for writing the tool 12 | - jsr for famitracker 13 | - blargg and kode54 for foo_gep 14 | - rainwarrior for the import dialog 15 | - The FUSE team for the Z80_regpair 16 | - Warheart, jrlepage, Shywolf, B00daW, mega9man, Macromaniac, moviemovies1, Vinyl Scratch, Rozul_TheBlue and betasword for beta testing! 17 | -------------------------------------------------------------------------------- /src/GBSImport2.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 10.00 3 | # Visual Studio 2008 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "GBSImport2", "GBSImport2.vcproj", "{F85C1C1C-1A17-4984-961A-1FD9C6C48C5D}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {F85C1C1C-1A17-4984-961A-1FD9C6C48C5D}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {F85C1C1C-1A17-4984-961A-1FD9C6C48C5D}.Debug|Win32.Build.0 = Debug|Win32 14 | {F85C1C1C-1A17-4984-961A-1FD9C6C48C5D}.Release|Win32.ActiveCfg = Release|Win32 15 | {F85C1C1C-1A17-4984-961A-1FD9C6C48C5D}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /src/global_stuff.h: -------------------------------------------------------------------------------- 1 | //Custom global functions, types and macros 2 | 3 | #pragma once 4 | 5 | #include 6 | 7 | typedef unsigned char byte; 8 | typedef unsigned short word; 9 | typedef unsigned int dword; 10 | 11 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 12 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 13 | 14 | #define STRCMP_EQUAL 0 15 | 16 | #define zero_mem(a,b) memset(a,0,b) 17 | 18 | byte read_byte(FILE* fp); 19 | dword read_word(FILE* fp); 20 | dword read_dword(FILE* fp); 21 | dword read_inv_word(FILE* fp); 22 | dword read_inv_dword(FILE* fp); 23 | 24 | void write_byte(FILE* fp, byte value); 25 | void write_word(FILE* fp, word value); 26 | void write_dword(FILE* fp, dword value); 27 | void write_inv_word(FILE* fp,word value); 28 | void write_inv_dword(FILE* fp,dword value); 29 | 30 | void write_zeros(FILE* fp, int count); 31 | 32 | inline byte read_byte(FILE* fp) { int value; fread(&value,1,1,fp); return value&0xFF; } 33 | inline dword read_word(FILE* fp) { dword value; fread(&value,2,1,fp); return value&0xFFFF; } 34 | inline dword read_dword(FILE* fp) { dword value; fread(&value,4,1,fp); return value; } 35 | inline dword read_inv_word(FILE* fp) { dword value; value=256*read_byte(fp)+read_byte(fp); return value&0xFFFF; } 36 | inline dword read_inv_dword(FILE* fp) { dword value; value=65536*read_inv_word(fp)+read_inv_word(fp); return value; } 37 | 38 | inline void write_byte(FILE* fp, byte value) { fwrite(&value,1,1,fp); } 39 | inline void write_word(FILE* fp, word value) { fwrite(&value,2,1,fp); } 40 | inline void write_dword(FILE* fp, dword value) { fwrite(&value,4,1,fp); } 41 | inline void write_inv_word(FILE* fp,word value) { write_byte(fp,value>>8); write_byte(fp,value&255); } 42 | inline void write_inv_dword(FILE* fp,dword value) { write_inv_word(fp,value>>16); write_inv_word(fp,value&65535); } 43 | inline void write_zeros(FILE* fp, int count) { for(int i=0;i 2 | #include 3 | #include "FTMFile.h" 4 | 5 | // Z80_regpair from FUSE 6 | 7 | typedef union { 8 | struct { unsigned char l,h; } b; 9 | unsigned short w; 10 | } Z80_regpair; 11 | 12 | // Gb_Env class from Game Music Emu 13 | 14 | class Gb_Env { 15 | public: 16 | int env_delay; 17 | int volume; 18 | bool env_enabled; 19 | 20 | int vol,va,vp,vc; 21 | 22 | unsigned char regs[5]; 23 | 24 | void clock_envelope(); 25 | bool write_register( int frame_phase, int reg, int old_data, int data ); 26 | 27 | void reset() 28 | { 29 | memset(this,0,sizeof(Gb_Env)); 30 | } 31 | 32 | // Non-zero if DAC is enabled 33 | int dac_enabled() const { return regs [2] & 0xF8; } 34 | 35 | void zombie_volume( int old, int data ); 36 | int reload_env_timer(); 37 | }; 38 | 39 | class CGBS_Emu { 40 | public: 41 | FILE* fp_src; 42 | FILE* fp_dst; 43 | FILE* fp_log; 44 | 45 | int src_size; 46 | 47 | unsigned char* data; 48 | unsigned char* bdata; 49 | int* op_count; 50 | 51 | struct stInfo{ 52 | char file_id[3]; 53 | unsigned char version; 54 | unsigned char n_songs; 55 | unsigned char first; 56 | unsigned short load_addr; 57 | unsigned short init_addr; 58 | unsigned short play_addr; 59 | unsigned short sp_init; 60 | unsigned char tmod; 61 | unsigned char tctl; 62 | char title[32]; 63 | char author[32]; 64 | char ccccc[32]; 65 | } Info; 66 | 67 | Z80_regpair af; 68 | Z80_regpair bc; 69 | Z80_regpair de; 70 | Z80_regpair hl; 71 | Z80_regpair ix; 72 | Z80_regpair iy; 73 | Z80_regpair sp; 74 | Z80_regpair pc; 75 | 76 | unsigned char wave[16]; 77 | 78 | Gb_Env Env[3]; 79 | 80 | char sweeped; 81 | char sq1_vol; 82 | char sq1_vp; 83 | char sq1_va; 84 | char sq1_vc; 85 | char sq1_ll; 86 | char sq1_lc; 87 | char sq2_vol; 88 | char sq2_vp; 89 | char sq2_va; 90 | char sq2_vc; 91 | char sq2_ll; 92 | char sq2_lc; 93 | char noise_vol; 94 | char noise_vp; 95 | char noise_va; 96 | char noise_vc; 97 | char noise_ll; 98 | char noise_lc; 99 | 100 | int wave_ll; 101 | int wave_lc; 102 | int wave_vol; 103 | 104 | bool is_switched; 105 | int n_banks; 106 | int c_bank; 107 | 108 | char errorcode[256]; 109 | 110 | CGBS_Emu(); 111 | ~CGBS_Emu(); 112 | void Cleanup(); 113 | 114 | bool LoadFile(char* filename); 115 | bool ReadHeader(); 116 | bool ReadData(); 117 | 118 | void LogHeader(); 119 | void LogData(); 120 | void LogDisasm(); 121 | 122 | void Clock64(); 123 | 124 | bool Init(int track); 125 | bool PlayOnce(); 126 | int RunCpu(); 127 | int RunExtCB(); 128 | }; 129 | 130 | -------------------------------------------------------------------------------- /src/ft_stuff.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** FamiTracker - NES/Famicom sound tracker 3 | ** Copyright (C) 2005-2012 Jonathan Liss 4 | ** 5 | ** This program is free software; you can redistribute it and/or modify 6 | ** it under the terms of the GNU General Public License as published by 7 | ** the Free Software Foundation; either version 2 of the License, or 8 | ** (at your option) any later version. 9 | ** 10 | ** This program is distributed in the hope that it will be useful, 11 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | ** Library General Public License for more details. To obtain a 14 | ** copy of the GNU Library General Public License, write to the Free 15 | ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 16 | ** 17 | ** Any permitted reproduction of these routines, in whole or in part, 18 | ** must bear this legend. 19 | */ 20 | 21 | // Part of this is directly taken from FamiTracker's source, hence the copyright notice. ;) 22 | // -Slimeball 23 | 24 | typedef unsigned char byte; 25 | 26 | #define EX_NONE 0x00 27 | #define EX_VRC6 0x01 28 | #define EX_VRC7 0x02 29 | #define EX_FDS 0x04 30 | #define EX_MMC5 0x08 31 | #define EX_N163 0x10 32 | #define EX_S5B 0x20 33 | 34 | #define FT_NOTE_OFF 0x0D 35 | #define FT_NOTE_CUT 0x0E 36 | 37 | enum{ 38 | TYPE_2A03=1, 39 | TYPE_VRC6, 40 | TYPE_FDS, 41 | TYPE_VRC7, 42 | TYPE_N163, 43 | TYPE_S5B 44 | }; 45 | 46 | #define max(a,b) (((a) > (b)) ? (a) : (b)) 47 | #define min(a,b) (((a) < (b)) ? (a) : (b)) 48 | 49 | // Channel effects 50 | #define DEF_CMD(x) ((x << 1) | 0x80) 51 | enum { 52 | EF_NONE = 0, 53 | EF_SPEED, 54 | EF_JUMP, 55 | EF_SKIP, 56 | EF_HALT, 57 | EF_VOLUME, 58 | EF_PORTAMENTO, 59 | EF_PORTAOFF, // unused!! 60 | EF_SWEEPUP, 61 | EF_SWEEPDOWN, 62 | EF_ARPEGGIO, 63 | EF_VIBRATO, 64 | EF_TREMOLO, 65 | EF_PITCH, 66 | EF_DELAY, 67 | EF_EARRAPE, 68 | EF_PORTA_UP, 69 | EF_PORTA_DOWN, 70 | EF_DUTY_CYCLE, 71 | EF_SAMPLE_OFFSET, 72 | EF_SLIDE_UP, 73 | EF_SLIDE_DOWN, 74 | EF_VOLUME_SLIDE, 75 | EF_NOTE_CUT, 76 | EF_RETRIGGER, 77 | EF_DELAYED_VOLUME, // Unimplemented 78 | EF_FDS_MOD_DEPTH, 79 | EF_FDS_MOD_SPEED_HI, 80 | EF_FDS_MOD_SPEED_LO, 81 | EF_DPCM_PITCH, 82 | EF_SUNSOFT_ENV_LO, 83 | EF_SUNSOFT_ENV_HI, 84 | EF_SUNSOFT_ENV_TYPE, 85 | // EF_TARGET_VOLUME_SLIDE, 86 | /* 87 | EF_VRC7_MODULATOR, 88 | EF_VRC7_CARRIER, 89 | EF_VRC7_LEVELS, 90 | */ 91 | EF_COUNT 92 | }; 93 | 94 | inline char ftmn2not(byte ftmn) 95 | { 96 | if(ftmn==0x00) return '-'; 97 | if(ftmn==0x13) return '='; 98 | if(ftmn==0x14) return '^'; 99 | switch((ftmn+1)%12){ 100 | case 0: case 1: return 'C'; 101 | case 2: case 3: return 'D'; 102 | case 4: case 5: return 'E'; 103 | case 6: return 'F'; 104 | case 7: case 8: return 'G'; 105 | case 9: case 10: return 'A'; 106 | case 11: return 'B'; 107 | default: return 'X'; 108 | } 109 | } 110 | 111 | inline char ftmn2acc(byte ftmn) 112 | { 113 | if(ftmn==0x00) return '-'; 114 | if(ftmn==0x13) return '='; 115 | if(ftmn==0x14) return '^'; 116 | switch((ftmn+1)%12){ 117 | case 1: return '#'; 118 | case 3: return '#'; 119 | case 6: return '#'; 120 | case 8: return '#'; 121 | case 10: return '#'; 122 | default: return '-'; 123 | } 124 | } 125 | 126 | inline char ftmno2oct(byte ftmn, byte ftmo) 127 | { 128 | if(ftmn==0x00) return '-'; 129 | if(ftmn==0x13) return '='; 130 | if(ftmn==0x14) return '^';; 131 | return 48+ftmo; 132 | } 133 | 134 | inline char ftmfx(byte rawfx) 135 | { 136 | switch(rawfx){ 137 | case 0: return '-'; 138 | case EF_SPEED: return 'F'; 139 | case EF_JUMP: return 'B'; 140 | case EF_SKIP: return 'D'; 141 | case EF_HALT: return 'C'; 142 | case EF_VOLUME: return 'E'; 143 | case EF_PORTAMENTO: return '3'; 144 | case EF_PORTA_UP: return '1'; 145 | case EF_PORTA_DOWN: return '2'; 146 | case EF_SWEEPUP: return 'H'; 147 | case EF_SWEEPDOWN: return 'I'; 148 | case EF_ARPEGGIO: return '0'; 149 | case EF_VIBRATO: return '4'; 150 | case EF_TREMOLO: return '7'; 151 | case EF_PITCH: return 'P'; 152 | case EF_DELAY: return 'G'; 153 | case EF_EARRAPE: return 'Z'; 154 | case EF_DUTY_CYCLE: return 'V'; 155 | case EF_SAMPLE_OFFSET: return 'Y'; 156 | case EF_SLIDE_UP: return 'Q'; 157 | case EF_SLIDE_DOWN: return 'R'; 158 | case EF_VOLUME_SLIDE: return 'A'; 159 | case EF_NOTE_CUT: return 'S'; 160 | case EF_RETRIGGER: return 'X'; 161 | case EF_DPCM_PITCH: return 'W'; 162 | default: return '?'; 163 | } 164 | } -------------------------------------------------------------------------------- /src/GBSImport2.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #include "resource.h" 4 | 5 | #define APSTUDIO_READONLY_SYMBOLS 6 | ///////////////////////////////////////////////////////////////////////////// 7 | // 8 | // Generated from the TEXTINCLUDE 2 resource. 9 | // 10 | #include "afxres.h" 11 | 12 | ///////////////////////////////////////////////////////////////////////////// 13 | #undef APSTUDIO_READONLY_SYMBOLS 14 | 15 | ///////////////////////////////////////////////////////////////////////////// 16 | // Dutch (Netherlands) resources 17 | 18 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NLD) 19 | #ifdef _WIN32 20 | LANGUAGE LANG_DUTCH, SUBLANG_DUTCH 21 | #pragma code_page(1252) 22 | #endif //_WIN32 23 | 24 | ///////////////////////////////////////////////////////////////////////////// 25 | // 26 | // Dialog 27 | // 28 | 29 | ABOUTBOX DIALOG 32, 32, 180, 100 30 | STYLE DS_SETFONT | DS_MODALFRAME | WS_POPUP 31 | FONT 8, "MS Sans Serif" 32 | BEGIN 33 | DEFPUSHBUTTON "OK",IDOK,66,80,50,14 34 | ICON "ABOUT1",IDC_STATIC,7,7,21,20 35 | CTEXT "About1",IDC_STATIC,40,12,100,8 36 | CTEXT "About Box Demo Program",IDC_STATIC,7,40,166,8 37 | CTEXT "(c) Charles Petzold, 1998",IDC_STATIC,7,52,166,8 38 | END 39 | 40 | IDD_DIALOG1 DIALOGEX 0, 0, 316, 180 41 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU 42 | CAPTION "Dialog" 43 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 44 | BEGIN 45 | DEFPUSHBUTTON "OK",IDOK,205,159,50,14 46 | PUSHBUTTON "Cancel",IDCANCEL,259,159,50,14 47 | LTEXT "Static",IDC_STATIC,24,47,136,35 48 | END 49 | 50 | IDD_DIALOG_NSF_IMPORT DIALOGEX 0, 0, 316, 183 51 | STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU 52 | CAPTION "GBS Import v0.1" 53 | FONT 8, "MS Shell Dlg", 400, 0, 0x1 54 | BEGIN 55 | DEFPUSHBUTTON "Import",IDOK,205,162,50,14 56 | PUSHBUTTON "Exit",IDCANCEL,259,162,50,14 57 | LTEXT "Filename",IDC_FILENAME,7,7,302,14,0,WS_EX_CLIENTEDGE 58 | LTEXT "Name",IDC_NSFINFO1,76,26,233,14,0,WS_EX_CLIENTEDGE 59 | LTEXT "Composer",IDC_NSFINFO2,76,44,233,14,0,WS_EX_CLIENTEDGE 60 | LTEXT "Copyright",IDC_NSFINFO3,76,63,233,14,0,WS_EX_CLIENTEDGE 61 | RTEXT "Name:",IDC_STATIC,7,27,66,14 62 | RTEXT "Copyright:",IDC_STATIC,7,64,66,14 63 | RTEXT "Composer:",IDC_STATIC,7,45,66,14 64 | EDITTEXT IDC_TRACK,76,80,55,16,ES_CENTER | ES_AUTOHSCROLL 65 | CTEXT "1",IDC_TRACKCOUNT,149,80,55,16,0,WS_EX_CLIENTEDGE 66 | CTEXT "/",IDC_STATIC,133,81,14,14 67 | RTEXT "Track:",IDC_STATIC,7,82,66,15 68 | EDITTEXT IDC_SECONDS,76,100,55,16,ES_CENTER | ES_AUTOHSCROLL 69 | LTEXT "seconds",IDC_STATIC,136,102,77,14 70 | RTEXT "Record time:",IDC_STATIC,7,101,66,13 71 | CONTROL "Import all tracks",IDC_ALLTRACKS,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,208,80,97,13 72 | CONTROL "Remove silence at end",IDC_NOSILENCE,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,208,100,97,13 73 | CONTROL "Progress",IDC_PROGRESSINFO,"msctls_progress32",WS_BORDER,205,147,104,8 74 | END 75 | 76 | 77 | ///////////////////////////////////////////////////////////////////////////// 78 | // 79 | // Menu 80 | // 81 | 82 | ABOUT1 MENU 83 | BEGIN 84 | POPUP "&Help" 85 | BEGIN 86 | MENUITEM "&About About1...", IDM_APP_ABOUT 87 | END 88 | END 89 | 90 | 91 | #ifdef APSTUDIO_INVOKED 92 | ///////////////////////////////////////////////////////////////////////////// 93 | // 94 | // TEXTINCLUDE 95 | // 96 | 97 | 1 TEXTINCLUDE 98 | BEGIN 99 | "resource.\0" 100 | END 101 | 102 | 3 TEXTINCLUDE 103 | BEGIN 104 | "\r\0" 105 | END 106 | 107 | 2 TEXTINCLUDE 108 | BEGIN 109 | "#include ""afxres.h""\r\0" 110 | END 111 | 112 | #endif // APSTUDIO_INVOKED 113 | 114 | 115 | ///////////////////////////////////////////////////////////////////////////// 116 | // 117 | // DESIGNINFO 118 | // 119 | 120 | #ifdef APSTUDIO_INVOKED 121 | GUIDELINES DESIGNINFO 122 | BEGIN 123 | IDD_DIALOG1, DIALOG 124 | BEGIN 125 | LEFTMARGIN, 7 126 | RIGHTMARGIN, 309 127 | TOPMARGIN, 7 128 | BOTTOMMARGIN, 173 129 | END 130 | END 131 | #endif // APSTUDIO_INVOKED 132 | 133 | #endif // Dutch (Netherlands) resources 134 | ///////////////////////////////////////////////////////////////////////////// 135 | 136 | 137 | 138 | #ifndef APSTUDIO_INVOKED 139 | ///////////////////////////////////////////////////////////////////////////// 140 | // 141 | // Generated from the TEXTINCLUDE 3 resource. 142 | // 143 | 144 | 145 | ///////////////////////////////////////////////////////////////////////////// 146 | #endif // not APSTUDIO_INVOKED 147 | 148 | -------------------------------------------------------------------------------- /src/FTMFile.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | #include "global_stuff.h" 5 | 6 | #define SEQ_COUNT 5 7 | #define MAX_FRAMES 128 8 | #define VRC7_REGS 8 9 | 10 | struct stSequence{ 11 | stSequence::stSequence(); 12 | dword index; 13 | dword type; 14 | byte length; 15 | dword loop; 16 | dword release; 17 | dword setting; 18 | byte data[256]; 19 | }; 20 | 21 | struct Instrument_2A03{ 22 | Instrument_2A03::Instrument_2A03(); 23 | dword index; 24 | byte type; 25 | dword seq_count; 26 | byte seq_data[2*SEQ_COUNT]; 27 | byte DPCM_data[288]; 28 | dword name_length; // Inst. name length 29 | char name[64]; 30 | }; 31 | 32 | struct Instrument_FDS{ 33 | Instrument_FDS::Instrument_FDS(); 34 | dword index; 35 | byte type; 36 | byte wave[64]; 37 | byte mtable[32]; 38 | int mspeed; 39 | int mdepth; 40 | int mdelay; 41 | stSequence Seq[3]; 42 | dword name_length; // Inst. name length 43 | char name[64]; 44 | }; 45 | 46 | struct Instrument_VRC6{ 47 | Instrument_VRC6::Instrument_VRC6(); 48 | dword index; 49 | byte type; 50 | dword seq_count; 51 | byte seq_data[2*SEQ_COUNT]; 52 | dword name_length; // Inst. name length 53 | char name[64]; 54 | }; 55 | 56 | 57 | struct Instrument_VRC7{ 58 | Instrument_VRC7::Instrument_VRC7(); 59 | dword index; 60 | byte type; 61 | int patch; 62 | byte data[8]; 63 | dword name_length; // Inst. name length 64 | char name[64]; 65 | }; 66 | 67 | struct Instrument_N163{ 68 | Instrument_N163::Instrument_N163(); 69 | dword index; 70 | int type; 71 | dword seq_count; 72 | byte seq_data[2*SEQ_COUNT]; 73 | int wave_size; 74 | int wave_pos; 75 | int wave_count; 76 | byte wave_data[16][32]; 77 | dword name_length; // Inst. name length 78 | char name[64]; 79 | }; 80 | 81 | struct DPCM_Sample{ 82 | int index; 83 | int namelength; 84 | int datalength; 85 | char name[64]; 86 | byte data[4096]; 87 | }; 88 | 89 | struct FTItem{ 90 | FTItem(); 91 | dword row; 92 | byte note; 93 | byte octave; 94 | byte instrument; 95 | byte volume; 96 | byte fxdata[8]; 97 | }; 98 | 99 | struct FTPattern{ 100 | FTPattern(); 101 | dword track; 102 | dword channel; 103 | dword index; 104 | int items; 105 | FTItem Item[256]; 106 | }; 107 | 108 | class CFTMFile{ 109 | public: CFTMFile(); 110 | FILE* fp_src; 111 | FILE* fp_log; 112 | FILE* fp_dst; 113 | FILE* fp_asm; 114 | 115 | int src_size; 116 | 117 | char file_id[24]; 118 | dword file_version; 119 | 120 | char pr_id[24]; //PARAMS 121 | dword pr_version; 122 | dword pr_size; 123 | byte expansion; 124 | int channels; 125 | dword machine; 126 | dword e_speed; 127 | dword v_style; 128 | dword highlight1; 129 | dword highlight2; 130 | dword N163_channels; 131 | dword s_split; 132 | 133 | char nf_id[24]; //INFO 134 | dword nf_version; 135 | dword nf_size; 136 | char author[32]; 137 | char title[32]; 138 | char ccccc[32]; 139 | 140 | char he_id[24]; //HEADER 141 | dword he_version; 142 | dword he_size; 143 | byte n_tracks; 144 | char track_name[64]; 145 | char ch_id[32]; 146 | char ch_fx[32]; 147 | 148 | char i0_id[24]; //INSTRUMENTS 149 | dword i0_version; 150 | dword i0_size; 151 | int n_instruments; 152 | int FDS_instruments; 153 | int VRC6_instruments; 154 | int VRC7_instruments; 155 | int N163_instruments; 156 | Instrument_2A03 Inst_2A03[64]; 157 | Instrument_FDS Inst_FDS[64]; 158 | Instrument_VRC6 Inst_VRC6[64]; 159 | Instrument_VRC7 Inst_VRC7[64]; 160 | Instrument_N163 Inst_N163[64]; 161 | 162 | char s0_id[24]; //SEQUENCES 163 | dword s0_version; 164 | dword s0_size; 165 | int n_sequences; 166 | stSequence Sequence[320]; 167 | 168 | char fr_id[24]; //FRAMES 169 | dword fr_version; 170 | dword fr_size; 171 | int n_frames; 172 | dword speed; 173 | dword tempo; 174 | int p_length; 175 | byte fdata[MAX_FRAMES][16]; 176 | 177 | char pt_id[24]; //PATTERNS 178 | dword pt_version; 179 | dword pt_size; 180 | FTPattern Pattern[640]; 181 | 182 | char ds_id[24]; //DPCM SAMPLES 183 | dword ds_version; 184 | dword ds_size; 185 | byte n_samples; 186 | 187 | char vrc6s_id[24]; //VRC6 SEQUENCES 188 | char vrc6s_version; 189 | char vrc6s_size; 190 | int n_VRC6_sequences; 191 | stSequence VRC6_Sequence[128]; 192 | 193 | char n163s_id[24]; //N163 SEQUENCES 194 | char n163s_version; 195 | char n163s_size; 196 | int n_N163_sequences; 197 | stSequence N163_Sequence[128]; 198 | 199 | DPCM_Sample Sample[64]; 200 | 201 | int n_patterns; 202 | 203 | bool LoadFile(char* filename); 204 | bool SaveFile(char* filename); 205 | bool Optimize(); 206 | bool ExportTXT(char* filename); 207 | 208 | bool ReadID(); 209 | bool ReadParams(); 210 | bool ReadInfo(); 211 | bool ReadHeader(); 212 | bool ReadInstruments(); 213 | bool ReadSequences(); 214 | bool ReadFrames(); 215 | bool ReadPatterns(); 216 | bool ReadSamples(); 217 | 218 | bool WriteID(); 219 | bool WriteParams(); 220 | bool WriteInfo(); 221 | bool WriteHeader(); 222 | bool WriteInstruments(); 223 | bool WriteSequences(); 224 | bool WriteFrames(); 225 | bool WritePatterns(); 226 | bool WriteSamples(); 227 | bool WriteVRC6Sequences(); 228 | bool WriteN163Sequences(); 229 | 230 | bool LogStuff(); 231 | }; -------------------------------------------------------------------------------- /src/Winmain.cpp: -------------------------------------------------------------------------------- 1 | #define _CRT_SECURE_NO_WARNINGS 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include "resource.h" 8 | #include "GBSImport.h" 9 | 10 | #pragma comment(linker, \ 11 | "\"/manifestdependency:type='Win32' "\ 12 | "name='Microsoft.Windows.Common-Controls' "\ 13 | "version='6.0.0.0' "\ 14 | "processorArchitecture='*' "\ 15 | "publicKeyToken='6595b64144ccf1df' "\ 16 | "language='*'\"") 17 | 18 | #pragma comment(lib, "ComCtl32.lib") 19 | 20 | HWND w_hDlg; 21 | OPENFILENAME* pOmf; 22 | FILE* w_file; 23 | 24 | wchar_t* w_title=new wchar_t[40]; 25 | wchar_t* w_author=new wchar_t[40]; 26 | wchar_t* w_copyright=new wchar_t[40]; 27 | wchar_t* w_error=new wchar_t[256]; 28 | char* w_temp=new char[40]; 29 | char* w_trash=new char[40]; 30 | char* w_filename8=new char[256]; 31 | int w_id; 32 | int w_songs; 33 | int w_track=1; 34 | int w_seconds=120; 35 | bool w_debug=false; 36 | bool w_alltracks=false; 37 | bool w_nosilence=true; 38 | 39 | INT_PTR CALLBACK DialogProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam); 40 | INT_PTR CALLBACK NSF_Import_Dlg_Proc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam); 41 | 42 | void set_progress(int value) 43 | { 44 | SendDlgItemMessage(w_hDlg, IDC_PROGRESSINFO, PBM_SETPOS, value, 0); 45 | } 46 | 47 | bool start_import() 48 | { 49 | w_track = GetDlgItemInt(w_hDlg, IDC_TRACK, NULL, FALSE); 50 | w_seconds = GetDlgItemInt(w_hDlg, IDC_SECONDS, NULL, FALSE); 51 | w_alltracks = (BST_CHECKED == SendDlgItemMessage(w_hDlg, IDC_ALLTRACKS, BM_GETCHECK, 0, 0)); 52 | w_nosilence = (BST_CHECKED == SendDlgItemMessage(w_hDlg, IDC_NOSILENCE, BM_GETCHECK, 0, 0)); 53 | 54 | if(w_track < 1) w_track=1; 55 | if(w_track > w_songs) w_track=w_songs; 56 | if(w_seconds > 500) w_seconds=90; 57 | 58 | //w_seconds = 5; 59 | 60 | if(GBSImport::Import(w_filename8, w_track, w_seconds, w_alltracks, w_nosilence)) 61 | MessageBoxW(NULL,_T("Import successful! ^o^"),_T("Yay"),0); 62 | else 63 | MessageBoxW(NULL,_T("Import failed! :("),NULL,0); 64 | 65 | return true; 66 | } 67 | 68 | int WINAPI _tWinMain(HINSTANCE hInst, HINSTANCE h0, LPTSTR lpCmdLine, int nCmdShow) 69 | { 70 | MSG msg; BOOL ret; int error; size_t field=32; 71 | 72 | InitCommonControls(); 73 | 74 | pOmf = new OPENFILENAME; 75 | wchar_t filename[256]={0}; 76 | 77 | ZeroMemory(pOmf, sizeof(OPENFILENAME)); 78 | pOmf->lStructSize = sizeof(OPENFILENAME); 79 | pOmf->hwndOwner = NULL; 80 | pOmf->lpstrFilter = _T("GBS Files (*.gbs)\0*.gbs\0All Files (*.*)\0*.*\0\0"); 81 | pOmf->lpstrFile = filename; 82 | pOmf->nMaxFile = 256; 83 | pOmf->lpstrTitle = _T("Select GBS to import"); 84 | pOmf->Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; 85 | 86 | ret=GetOpenFileName(pOmf); 87 | error=CommDlgExtendedError(); 88 | wcstombs(w_filename8,pOmf->lpstrFile,256); 89 | 90 | if(ret==0){ 91 | if(error==0) return 0; 92 | wsprintf(w_error, L"Error code: %X", error); 93 | return MessageBoxW(NULL,w_error,L"Error",0); 94 | } 95 | 96 | _wfopen_s(&w_file,pOmf->lpstrFile,_T("rb")); 97 | fread(&w_id,3,1,w_file); fread(w_trash,1,1,w_file); 98 | fread(&w_songs,1,1,w_file); fread(w_trash,1,11,w_file); 99 | fread(w_temp,1,32,w_file); mbstowcs_s(&field,w_title,33,w_temp,32); 100 | fread(w_temp,1,32,w_file); mbstowcs_s(&field,w_author,33,w_temp,32); 101 | fread(w_temp,1,32,w_file); mbstowcs_s(&field,w_copyright,33,w_temp,32); 102 | fclose(w_file); 103 | 104 | if(!GBSImport::Scan(w_filename8)){ 105 | mbstowcs(w_error,GBSImport::GetError(),255); 106 | MessageBox(NULL,w_error,_T("Error"),0); 107 | return -1; 108 | } 109 | 110 | w_hDlg = CreateDialogParam(hInst,MAKEINTRESOURCE(IDD_DIALOG_NSF_IMPORT),0,NSF_Import_Dlg_Proc,0); 111 | ShowWindow(w_hDlg, nCmdShow); 112 | 113 | while((ret=GetMessage(&msg,0,0,0))!=0) 114 | { 115 | if(ret==-1) return -1; 116 | if(!IsDialogMessage(w_hDlg, &msg)){ 117 | TranslateMessage(&msg); 118 | DispatchMessage(&msg); 119 | } 120 | } 121 | return 0; 122 | } 123 | 124 | INT_PTR CALLBACK NSF_Import_Dlg_Proc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam) 125 | { 126 | switch(Msg) 127 | { 128 | case WM_INITDIALOG: 129 | SetDlgItemText(hWndDlg, IDC_FILENAME, pOmf->lpstrFile); 130 | SetDlgItemText(hWndDlg, IDC_NSFINFO1, w_title); 131 | SetDlgItemText(hWndDlg, IDC_NSFINFO2, w_author); 132 | SetDlgItemText(hWndDlg, IDC_NSFINFO3, w_copyright); 133 | SetDlgItemInt(hWndDlg, IDC_TRACK, 1, FALSE); 134 | SetDlgItemInt(hWndDlg, IDC_TRACKCOUNT, w_songs, FALSE); 135 | SetDlgItemInt(hWndDlg, IDC_SECONDS, w_seconds, FALSE); 136 | SetDlgItemInt(hWndDlg, IDC_PATTERN, 256, FALSE); 137 | SetDlgItemInt(hWndDlg, IDC_ROW, 0, FALSE); 138 | SendDlgItemMessage(hWndDlg, IDC_ALLTRACKS, BM_SETCHECK, w_alltracks? BST_CHECKED: BST_UNCHECKED, 0); 139 | SendDlgItemMessage(hWndDlg, IDC_NOSILENCE, BM_SETCHECK, w_nosilence? BST_CHECKED: BST_UNCHECKED, 0); 140 | SendDlgItemMessage(hWndDlg, IDC_PROGRESSINFO, PBM_SETPOS, 0, 0); 141 | return TRUE; 142 | 143 | case WM_COMMAND: 144 | switch(wParam){ 145 | case IDOK: start_import(); PostQuitMessage(0); return TRUE; 146 | case IDCANCEL: PostQuitMessage(-1); return TRUE; 147 | } break; 148 | } 149 | return FALSE; 150 | } -------------------------------------------------------------------------------- /src/GBSImport2.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 26 | 29 | 32 | 35 | 38 | 41 | 52 | 55 | 58 | 61 | 68 | 71 | 74 | 77 | 80 | 83 | 86 | 89 | 90 | 98 | 101 | 104 | 107 | 110 | 113 | 124 | 127 | 130 | 133 | 142 | 145 | 148 | 151 | 154 | 157 | 160 | 163 | 164 | 165 | 166 | 167 | 168 | 173 | 176 | 177 | 180 | 181 | 184 | 185 | 188 | 189 | 192 | 193 | 196 | 197 | 198 | 203 | 206 | 207 | 210 | 211 | 214 | 215 | 218 | 219 | 222 | 223 | 226 | 227 | 230 | 231 | 234 | 235 | 236 | 241 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | -------------------------------------------------------------------------------- /src/GBZ80_tables.h: -------------------------------------------------------------------------------- 1 | const char* gbs_opcodes[]={ 2 | "NOP", "LD BC,nn", "LD (BC),A", "INC BC", "INC B", "DEC B", "LD B,n", "RLC A", 3 | "LD (nn),SP", "ADD HL,BC", "LD A,(BC)", "DEC BC", "INC C", "DEC C", "LD C,n", "RRC A", 4 | "STOP", "LD DE,nn", "LD (DE),A", "INC DE", "INC D", "DEC D", "LD D,n", "RL A", 5 | "JR n", "ADD HL,DE", "LD A,(DE)", "DEC DE", "INC E", "DEC E", "LD E,n", "RR A", 6 | "JR NZ,n", "LD HL,nn", "LDI (HL),A", "INC HL", "INC H", "DEC H", "LD H,n", "DAA", 7 | "JR Z,n", "ADD HL,HL", "LDI A,(HL)", "DEC HL", "INC L", "DEC L", "LD L,n", "CPL", 8 | "JR NC,n", "LD SP,nn", "LDD (HL),A", "INC SP", "INC (HL)", "DEC (HL)", "LD (HL),n", "SCF", 9 | "JR C,n", "ADD HL,SP", "LDD A,(HL)", "DEC SP", "INC A", "DEC A", "LD A,n", "CCF", 10 | "LD B,B", "LD B,C", "LD B,D", "LD B,E", "LD B,H", "LD B,L", "LD B,(HL)", "LD B,A", 11 | "LD C,B", "LD C,C", "LD C,D", "LD C,E", "LD C,H", "LD C,L", "LD C,(HL)", "LD C,A", 12 | "LD D,B", "LD D,C", "LD D,D", "LD D,E", "LD D,H", "LD D,L", "LD D,(HL)", "LD D,A", 13 | "LD E,B", "LD E,C", "LD E,D", "LD E,E", "LD E,H", "LD E,L", "LD E,(HL)", "LD E,A", 14 | "LD H,B", "LD H,C", "LD H,D", "LD H,E", "LD H,H", "LD H,L", "LD H,(HL)", "LD H,A", 15 | "LD L,B", "LD L,C", "LD L,D", "LD L,E", "LD L,H", "LD L,L", "LD L,(HL)", "LD L,A", 16 | "LD (HL),B", "LD (HL),C", "LD (HL),D", "LD (HL),E", "LD (HL),H", "LD (HL),L", "HALT", "LD (HL),A", 17 | "LD A,B", "LD A,C", "LD A,D", "LD A,E", "LD A,H", "LD A,L", "LD A,(HL)", "LD A,A", 18 | "ADD A,B", "ADD A,C", "ADD A,D", "ADD A,E", "ADD A,H", "ADD A,L", "ADD A,(HL)", "ADD A,A", 19 | "ADC A,B", "ADC A,C", "ADC A,D", "ADC A,E", "ADC A,H", "ADC A,L", "ADC A,(HL)", "ADC A,A", 20 | "SUB A,B", "SUB A,C", "SUB A,D", "SUB A,E", "SUB A,H", "SUB A,L", "SUB A,(HL)", "SUB A,A", 21 | "SBC A,B", "SBC A,C", "SBC A,D", "SBC A,E", "SBC A,H", "SBC A,L", "SBC A,(HL)", "SBC A,A", 22 | "AND B", "AND C", "AND D", "AND E", "AND H", "AND L", "AND (HL)", "AND A", 23 | "XOR B", "XOR C", "XOR D", "XOR E", "XOR H", "XOR L", "XOR (HL)", "XOR A", 24 | "OR B", "OR C", "OR D", "OR E", "OR H", "OR L", "OR (HL)", "OR A", 25 | "CP B", "CP C", "CP D", "CP E", "CP H", "CP L", "CP (HL)", "CP A", 26 | "RET NZ", "POP BC", "JP NZ,nn", "JP nn", "CALL NZ,nn", "PUSH BC", "ADD A,n", "RST 0", 27 | "RET Z", "RET", "JP Z,nn", "Ext ops", "CALL Z,nn", "CALL nn", "ADC A,n", "RST 8", 28 | "RET NC", "POP DE", "JP NC,nn", "XX", "CALL NC,nn", "PUSH DE", "SUB A,n", "RST 10", 29 | "RET C", "RETI", "JP C,nn", "XX", "CALL C,nn", "XX", "SBC A,n", "RST 18", 30 | "LDH (n),A", "POP HL", "LDH (C),A", "XX", "XX", "PUSH HL", "AND n", "RST 20", 31 | "ADD SP,d", "JP (HL)", "LD (nn),A", "XX", "XX", "XX", "XOR n", "RST 28", 32 | "LDH A,(n)", "POP AF", "XX", "DI", "XX", "PUSH AF", "OR n", "RST 30", 33 | "LDHL SP,d", "LD SP,HL", "LD A,(nn)", "EI", "XX", "XX", "CP n", "RST 38", 34 | }; 35 | 36 | const char* gbs_cbcodes[]={ 37 | "RLC B", "RLC C", "RLC D", "RLC E", "RLC H", "RLC L", "RLC (HL)", "RLC A", 38 | "RRC B", "RRC C", "RRC D", "RRC E", "RRC H", "RRC L", "RRC (HL)", "RRC A", 39 | "RL B", "RL C", "RL D", "RL E", "RL H", "RL L", "RL (HL)", "RL A", 40 | "RR B", "RR C", "RR D", "RR E", "RR H", "RR L", "RR (HL)", "RR A", 41 | "SLA B", "SLA C", "SLA D", "SLA E", "SLA H", "SLA L", "SLA (HL)", "SLA A", 42 | "SRA B", "SRA C", "SRA D", "SRA E", "SRA H", "SRA L", "SRA (HL)", "SRA A", 43 | "SWAP B", "SWAP C", "SWAP D", "SWAP E", "SWAP H", "SWAP L", "SWAP (HL)", "SWAP A", 44 | "SRL B", "SRL C", "SRL D", "SRL E", "SRL H", "SRL L", "SRL (HL)", "SRL A", 45 | "BIT 0,B", "BIT 0,C", "BIT 0,D", "BIT 0,E", "BIT 0,H", "BIT 0,L", "BIT 0,(HL)", "BIT 0,A", 46 | "BIT 1,B", "BIT 1,C", "BIT 1,D", "BIT 1,E", "BIT 1,H", "BIT 1,L", "BIT 1,(HL)", "BIT 1,A", 47 | "BIT 2,B", "BIT 2,C", "BIT 2,D", "BIT 2,E", "BIT 2,H", "BIT 2,L", "BIT 2,(HL)", "BIT 2,A", 48 | "BIT 3,B", "BIT 3,C", "BIT 3,D", "BIT 3,E", "BIT 3,H", "BIT 3,L", "BIT 3,(HL)", "BIT 3,A", 49 | "BIT 4,B", "BIT 4,C", "BIT 4,D", "BIT 4,E", "BIT 4,H", "BIT 4,L", "BIT 4,(HL)", "BIT 4,A", 50 | "BIT 5,B", "BIT 5,C", "BIT 5,D", "BIT 5,E", "BIT 5,H", "BIT 5,L", "BIT 5,(HL)", "BIT 5,A", 51 | "BIT 6,B", "BIT 6,C", "BIT 6,D", "BIT 6,E", "BIT 6,H", "BIT 6,L", "BIT 6,(HL)", "BIT 6,A", 52 | "BIT 7,B", "BIT 7,C", "BIT 7,D", "BIT 7,E", "BIT 7,H", "BIT 7,L", "BIT 7,(HL)", "BIT 7,A", 53 | "RES 0,B", "RES 0,C", "RES 0,D", "RES 0,E", "RES 0,H", "RES 0,L", "RES 0,(HL)", "RES 0,A", 54 | "RES 1,B", "RES 1,C", "RES 1,D", "RES 1,E", "RES 1,H", "RES 1,L", "RES 1,(HL)", "RES 1,A", 55 | "RES 2,B", "RES 2,C", "RES 2,D", "RES 2,E", "RES 2,H", "RES 2,L", "RES 2,(HL)", "RES 2,A", 56 | "RES 3,B", "RES 3,C", "RES 3,D", "RES 3,E", "RES 3,H", "RES 3,L", "RES 3,(HL)", "RES 3,A", 57 | "RES 4,B", "RES 4,C", "RES 4,D", "RES 4,E", "RES 4,H", "RES 4,L", "RES 4,(HL)", "RES 4,A", 58 | "RES 5,B", "RES 5,C", "RES 5,D", "RES 5,E", "RES 5,H", "RES 5,L", "RES 5,(HL)", "RES 5,A", 59 | "RES 6,B", "RES 6,C", "RES 6,D", "RES 6,E", "RES 6,H", "RES 6,L", "RES 6,(HL)", "RES 6,A", 60 | "RES 7,B", "RES 7,C", "RES 7,D", "RES 7,E", "RES 7,H", "RES 7,L", "RES 7,(HL)", "RES 7,A", 61 | "SET 0,B", "SET 0,C", "SET 0,D", "SET 0,E", "SET 0,H", "SET 0,L", "SET 0,(HL)", "SET 0,A", 62 | "SET 1,B", "SET 1,C", "SET 1,D", "SET 1,E", "SET 1,H", "SET 1,L", "SET 1,(HL)", "SET 1,A", 63 | "SET 2,B", "SET 2,C", "SET 2,D", "SET 2,E", "SET 2,H", "SET 2,L", "SET 2,(HL)", "SET 2,A", 64 | "SET 3,B", "SET 3,C", "SET 3,D", "SET 3,E", "SET 3,H", "SET 3,L", "SET 3,(HL)", "SET 3,A", 65 | "SET 4,B", "SET 4,C", "SET 4,D", "SET 4,E", "SET 4,H", "SET 4,L", "SET 4,(HL)", "SET 4,A", 66 | "SET 5,B", "SET 5,C", "SET 5,D", "SET 5,E", "SET 5,H", "SET 5,L", "SET 5,(HL)", "SET 5,A", 67 | "SET 6,B", "SET 6,C", "SET 6,D", "SET 6,E", "SET 6,H", "SET 6,L", "SET 6,(HL)", "SET 6,A", 68 | "SET 7,B", "SET 7,C", "SET 7,D", "SET 7,E", "SET 7,H", "SET 7,L", "SET 7,(HL)", "SET 7,A", 69 | }; 70 | 71 | int gbs_opbytes[]={ 72 | 1,3,1,1,1,1,2,1,3,1,1,1,1,1,2,1, //0x 73 | 1,3,1,1,1,1,2,1,2,1,1,1,1,1,2,1, //1x 74 | 2,3,1,1,1,1,2,1,2,1,1,1,1,1,2,1, //2x 75 | 2,3,1,1,1,1,2,1,2,1,1,1,1,1,2,1, //3x 76 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //4x 77 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //5x 78 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //6x 79 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //7x 80 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //8x 81 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //9x 82 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //Ax 83 | 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, //Bx 84 | 1,1,3,3,3,1,2,1,1,1,3,2,3,3,2,1, //Cx 85 | 1,1,3,0,3,0,2,1,1,1,3,0,3,0,2,1, //Dx 86 | 2,1,1,0,0,1,2,1,1,1,3,0,0,0,2,1, //Ex 87 | 2,1,0,1,0,1,2,1,1,1,3,1,0,0,2,1, //Fx 88 | }; 89 | -------------------------------------------------------------------------------- /src/GBS_Emu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** GBS Import 3 | ** Copyright (C) 2014 Slimeball 4 | ** 5 | ** Based on: 6 | ** 7 | ** FamiTracker - NES/Famicom sound tracker 8 | ** Copyright (C) 2005-2012 Jonathan Liss 9 | ** 10 | ** NSF Importer v0.5 - Written by Brad Smith 11/21/2011 11 | ** 12 | ** Game Music Emu - Copyright (C) 2003-2009 Shay Green 13 | ** 14 | ** This program is free software; you can redistribute it and/or modify 15 | ** it under the terms of the GNU General Public License as published by 16 | ** the Free Software Foundation; either version 3 of the License, or 17 | ** (at your option) any later version. 18 | ** 19 | ** This program is distributed in the hope that it will be useful, 20 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | ** Library General Public License for more details. To obtain a 23 | ** copy of the GNU Library General Public License, write to the Free 24 | ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 | ** 26 | ** Any permitted reproduction of these routines, in whole or in part, 27 | ** must bear this legend. 28 | */ 29 | 30 | #define _CRT_SECURE_NO_WARNINGS 31 | 32 | #include 33 | #include 34 | #include "FTMFile.h" 35 | #include "GBS_Emu.h" 36 | 37 | #define GBS_HEADER_SIZE 0x70 38 | #define MEM_SIZE 65536 39 | 40 | #define PANIC(msg) \ 41 | { \ 42 | printf("%s\n",msg); \ 43 | return false; \ 44 | } \ 45 | 46 | #define PANIC2(msg) \ 47 | { \ 48 | strcpy(errorcode,msg); \ 49 | printf("%s\n",msg); \ 50 | return false; \ 51 | } \ 52 | 53 | byte default_wave[16]={0x84,0x40,0x43,0xAA,0x2D,0x78,0x92,0x3C,0x60,0x59,0x59,0xB0,0x34,0xB8,0x2E,0xDA}; 54 | 55 | // Gb_Env class functions from Game Music Emu 56 | 57 | inline int Gb_Env::reload_env_timer() 58 | { 59 | int raw = regs [2] & 7; 60 | env_delay = (raw ? raw : 8); 61 | vp = raw&7; 62 | va = raw&8; 63 | vc = raw&7; 64 | return raw; 65 | } 66 | 67 | void Gb_Env::clock_envelope() 68 | { 69 | if ( env_enabled && --env_delay <= 0 && reload_env_timer() ) 70 | { 71 | int v = volume + (regs [2] & 0x08 ? +1 : -1); 72 | if ( 0 <= v && v <= 15 ) 73 | volume = v; 74 | else{ 75 | env_enabled = false; 76 | volume = (regs [2] & 0x08 ? 15 : 0); 77 | } 78 | } 79 | 80 | if(vp && !(--vc)){ 81 | vc = vp; 82 | if(va){ 83 | vol++; 84 | if(vol>15) vol=15; 85 | }else{ 86 | vol--; 87 | if(vol<0) vol=0; 88 | } 89 | } 90 | } 91 | 92 | inline void Gb_Env::zombie_volume( int old, int data ) 93 | { 94 | int v = vol; 95 | int mode = 5; 96 | 97 | if ( mode == 5 ) 98 | { 99 | // CGB-05 behavior, very close to AGB behavior as well 100 | if ( (old ^ data) & 8 ) 101 | { 102 | if ( !(old & 8) ) 103 | { 104 | v++; 105 | if ( old & 7 ) 106 | v++; 107 | } 108 | 109 | v = 16 - v; 110 | } 111 | else if ( (old & 0x0F) == 8 ) 112 | { 113 | v++; 114 | } 115 | } 116 | else 117 | { 118 | // CGB-04&02 behavior, very close to MGB behavior as well 119 | if ( !(old & 7) && env_enabled ) 120 | v++; 121 | else if ( !(old & 8) ) 122 | v += 2; 123 | 124 | if ( (old ^ data) & 8 ) 125 | v = 16 - v; 126 | } 127 | vol = v & 0x0F; 128 | } 129 | 130 | bool Gb_Env::write_register( int frame_phase, int reg, int old, int data ) 131 | { 132 | int const max_len = 64; 133 | 134 | switch ( reg ) 135 | { 136 | /*case 1: 137 | length_ctr = max_len - (data & (max_len - 1)); 138 | break;*/ 139 | 140 | case 2: 141 | // DAC enable/disable 142 | 143 | if (!(data&0xF8)){ 144 | vol = 0; 145 | env_enabled = false; 146 | break; 147 | } 148 | 149 | zombie_volume( old, data ); 150 | 151 | if ( (data & 7) && env_delay == 8 ) 152 | { 153 | vol = data>>4; 154 | vp = data&7; 155 | va = data&8; 156 | vc = data; 157 | env_delay = 1; 158 | clock_envelope(); // TODO: really happens at next length clock 159 | } 160 | break; 161 | 162 | case 4: 163 | if ( data&0x80 ) 164 | { 165 | volume = regs[2] >> 4; 166 | vol = regs[2] >> 4; 167 | reload_env_timer(); 168 | env_enabled = true; 169 | /*if ( frame_phase == 7 ) 170 | env_delay++;*/ 171 | if (!(regs[2]&0xF8)){ 172 | vol = 0; 173 | env_enabled = false; 174 | } 175 | return true; 176 | } 177 | } 178 | 179 | regs[reg] = data; 180 | 181 | return false; 182 | } 183 | 184 | 185 | CGBS_Emu::CGBS_Emu() 186 | { 187 | memset(this,0,sizeof(CGBS_Emu)); 188 | data=new unsigned char[MEM_SIZE]; 189 | //op_count=new int[256]; 190 | memset(data,0,MEM_SIZE); 191 | data[0xFF11]=0xBF; 192 | data[0xFF16]=0x3F; 193 | data[0xFF1B]=0xFF; 194 | data[0xFF1C]=0x9F; 195 | data[0xFF25]=0xFF; 196 | memcpy(&data[0xFF30],default_wave,16); 197 | memset(&data[0xFF70],0xFF,16); 198 | memset(&sweeped,0,19); 199 | } 200 | 201 | CGBS_Emu::~CGBS_Emu() 202 | { 203 | Cleanup(); 204 | } 205 | 206 | void CGBS_Emu::Cleanup() 207 | { 208 | if(bdata) delete[] bdata; 209 | memset(data,0,MEM_SIZE); 210 | data[0xFF11]=0x3F; 211 | data[0xFF16]=0x3F; 212 | data[0xFF1B]=0xFF; 213 | data[0xFF1C]=0x9F; 214 | memcpy(&data[0xFF30],default_wave,16); 215 | memset(&data[0xFF70],0xFF,16); 216 | memset(&sweeped,0,19); 217 | memset(Env,0,sizeof(Env)); 218 | 219 | af.w = 0; 220 | bc.w = 0; 221 | de.w = 0; 222 | hl.w = 0; 223 | } 224 | 225 | bool CGBS_Emu::LoadFile(char* filename) 226 | { 227 | fp_src = fopen(filename,"rb"); if(!fp_src) PANIC2("Couldn't open/find source file! :(\n"); 228 | //fp_log = fopen("GBS_load.log","w"); if(!fp_log) PANIC2("Couldn't create log file! :(\n"); 229 | 230 | fseek(fp_src,0,SEEK_END); src_size=ftell(fp_src); fseek(fp_src,0,SEEK_SET); 231 | 232 | if(!ReadHeader()) return false; 233 | if(!ReadData()) return false; 234 | 235 | fclose(fp_src); 236 | //fclose(fp_log); 237 | fp_src=NULL; 238 | //fp_log=NULL; 239 | return true; 240 | } 241 | 242 | bool CGBS_Emu::ReadHeader() 243 | { 244 | if(src_size1) PANIC2("Unsupported GBS version. :("); 251 | 252 | Info.sp_init -= 2; 253 | 254 | //LogHeader(); 255 | return true; 256 | } 257 | 258 | bool CGBS_Emu::ReadData() 259 | { 260 | int read_size=src_size-ftell(fp_src); 261 | if(read_size+Info.load_addr > 0x8000){ 262 | if(Info.load_addr>=0x4000) PANIC2("Unsupported ROM layout! :(\n"); 263 | is_switched=true; 264 | fread(&data[Info.load_addr],1,0x4000-Info.load_addr,fp_src); 265 | read_size=src_size-ftell(fp_src); 266 | n_banks=(read_size+0x3FFF)>>14; 267 | bdata=new byte[n_banks<<14]; 268 | memset(bdata,0,n_banks<<14); 269 | fread(bdata,1,read_size,fp_src); 270 | memcpy(&data[0x4000],bdata,0x4000); 271 | c_bank=0; 272 | }else{ 273 | is_switched=false; 274 | fread(&data[Info.load_addr],1,read_size,fp_src); 275 | } 276 | 277 | //LogData(); 278 | return true; 279 | } 280 | 281 | void CGBS_Emu::LogHeader() 282 | { 283 | fprintf(fp_log,"GBS HEADER:\n\n"); 284 | fprintf(fp_log,"Version number: %i\n",Info.version); 285 | fprintf(fp_log,"Number of songs: %i\n",Info.n_songs); 286 | fprintf(fp_log,"First song: %i\n",Info.first); 287 | fprintf(fp_log,"Load address: $%04X\n",Info.load_addr); 288 | fprintf(fp_log,"Init address: $%04X\n",Info.init_addr); 289 | fprintf(fp_log,"Play address: $%04X\n",Info.play_addr); 290 | fprintf(fp_log,"Stack pointer: $%04X\n",Info.sp_init); 291 | fprintf(fp_log,"Timer modulo: $%02X\n",Info.tmod); 292 | fprintf(fp_log,"Timer control: $%02X\n",Info.tctl); 293 | 294 | fprintf(fp_log,"Title: %s\n",Info.title); 295 | fprintf(fp_log,"Author: %s\n",Info.author); 296 | fprintf(fp_log,"Copyright: %s\n",Info.ccccc); 297 | } 298 | 299 | void CGBS_Emu::LogData() 300 | { 301 | fprintf(fp_log,"\nGBS DATA:\n\n"); 302 | fprintf(fp_log,"Data size: %i\n\n",src_size-GBS_HEADER_SIZE); 303 | } 304 | 305 | void CGBS_Emu::Clock64() 306 | { 307 | Env[0].clock_envelope(); 308 | Env[1].clock_envelope(); 309 | Env[2].clock_envelope(); 310 | 311 | if((data[0xFF14]&0x40) && sq1_lc){ 312 | sq1_lc-=4; 313 | if(sq1_lc<1){ 314 | sq1_lc=0; 315 | sq1_vol=0; 316 | Env[0].volume = 0; 317 | Env[0].env_enabled = false; 318 | sq1_vp=0; 319 | } 320 | } 321 | 322 | if((data[0xFF19]&0x40) && sq2_lc){ 323 | sq2_lc-=4; 324 | if(sq2_lc<1){ 325 | sq2_lc=0; 326 | sq2_vol=0; 327 | Env[1].volume = 0; 328 | Env[1].env_enabled = false; 329 | sq2_vp=0; 330 | } 331 | } 332 | 333 | if((data[0xFF1E]&0x40) && wave_lc>0){ 334 | wave_lc-=4; 335 | if(wave_lc<1){ 336 | wave_lc=0; 337 | data[0xFF1C]=0; 338 | } 339 | } 340 | 341 | if((data[0xFF23]&0x40) && noise_lc){ 342 | noise_lc-=4; 343 | if(noise_lc<1){ 344 | noise_lc=0; 345 | noise_vol=0; 346 | Env[2].volume = 0; 347 | Env[2].env_enabled = false; 348 | noise_vp=0; 349 | } 350 | } 351 | } -------------------------------------------------------------------------------- /src/GBZ80_macros.h: -------------------------------------------------------------------------------- 1 | /* 2 | ** GBS Import 3 | ** Copyright (C) 2014 Slimeball 4 | ** 5 | ** Based on: 6 | ** 7 | ** FamiTracker - NES/Famicom sound tracker 8 | ** Copyright (C) 2005-2012 Jonathan Liss 9 | ** 10 | ** NSF Importer v0.5 - Written by Brad Smith 11/21/2011 11 | ** 12 | ** Game Music Emu - Copyright (C) 2003-2009 Shay Green 13 | ** 14 | ** This program is free software; you can redistribute it and/or modify 15 | ** it under the terms of the GNU General Public License as published by 16 | ** the Free Software Foundation; either version 3 of the License, or 17 | ** (at your option) any later version. 18 | ** 19 | ** This program is distributed in the hope that it will be useful, 20 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | ** Library General Public License for more details. To obtain a 23 | ** copy of the GNU Library General Public License, write to the Free 24 | ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 | ** 26 | ** Any permitted reproduction of these routines, in whole or in part, 27 | ** must bear this legend. 28 | */ 29 | 30 | //Flags 31 | 32 | #define F_C 0x10 33 | #define F_H 0x20 34 | #define F_N 0x40 35 | #define F_Z 0x80 36 | 37 | // Registers 38 | 39 | #define AF af.w 40 | #define BC bc.w 41 | #define DE de.w 42 | #define HL hl.w 43 | #define IX ix.w 44 | #define IY iy.w 45 | #define SP sp.w 46 | #define PC pc.w 47 | 48 | #define flags af.b.l 49 | #define A af.b.h 50 | #define C bc.b.l 51 | #define B bc.b.h 52 | #define E de.b.l 53 | #define D de.b.h 54 | #define L hl.b.l 55 | #define H hl.b.h 56 | 57 | #define IXL ix.b.l 58 | #define IXH ix.b.h 59 | #define IYL iy.b.l 60 | #define IYH iy.b.h 61 | #define SPL sp.b.l 62 | #define SPH sp.b.h 63 | #define PCL pc.b.l 64 | #define PCH pc.b.h 65 | 66 | #define MEM(address) (data[address]) 67 | #define LO() (MEM(PC)) 68 | #define HI() (MEM(PC+1)) 69 | #define FETCH() (MEM(PC++)) 70 | #define IMM8() (LO()) 71 | #define IMM16() (LO() | (HI() << 8)) 72 | #define IND16() (MEM(IMM16())) 73 | 74 | #define BANKSWITCH(val) \ 75 | { \ 76 | if(c_bank!=val && val!=-1){ \ 77 | printf("Switch! Old: %i New: %i\n",c_bank,val); \ 78 | memcpy(&bdata[c_bank<<14],&data[0x4000],0x4000); \ 79 | printf("Pass 1\n"); \ 80 | memcpy(&data[0x4000],&bdata[(val)<<14],0x4000); \ 81 | printf("Pass 2\n"); \ 82 | c_bank=val; \ 83 | } \ 84 | } 85 | 86 | #define WRITE_NR11(val) \ 87 | { \ 88 | sq1_ll=val&0x3F; \ 89 | sq1_lc=val&0x3F; \ 90 | } 91 | 92 | #define WRITE_NR21(val) \ 93 | { \ 94 | sq2_ll=val&0x3F; \ 95 | sq2_lc=val&0x3F; \ 96 | } 97 | 98 | #define WRITE_NR31(val) \ 99 | { \ 100 | wave_ll=val; \ 101 | wave_lc=val; \ 102 | } 103 | 104 | #define WRITE_NR41(val) \ 105 | { \ 106 | noise_ll=val&0x3F; \ 107 | noise_lc=val&0x3F; \ 108 | } 109 | 110 | #define WRITE_NR12(val) \ 111 | { \ 112 | Env[0].write_register(0, 2, data[0xFF12], val); \ 113 | } 114 | 115 | #define WRITE_NR22(val) \ 116 | { \ 117 | Env[1].write_register(0, 2, data[0xFF17], val); \ 118 | } 119 | 120 | #define WRITE_NR42(val) \ 121 | { \ 122 | Env[2].write_register(0, 2, data[0xFF21], val); \ 123 | } 124 | 125 | #define WRITE_NR14(val) \ 126 | { \ 127 | if(val&0x80){ \ 128 | Env[0].write_register(0, 4, data[0xFF14],val); \ 129 | if(!sq1_lc) sq1_lc=sq1_ll? sq1_ll: 64; \ 130 | } \ 131 | } 132 | 133 | #define WRITE_NR24(val) \ 134 | { \ 135 | if(val&0x80){ \ 136 | Env[1].write_register(0, 4, data[0xFF19],val); \ 137 | if(!sq2_lc) sq2_lc=sq2_ll? sq2_ll: 64; \ 138 | } \ 139 | } 140 | 141 | #define WRITE_NR34(val) \ 142 | { \ 143 | if(val&0x80){ \ 144 | if(wave_lc<1) wave_lc=wave_ll? wave_ll: 256; \ 145 | wave_vol = data[0xFF1C]; \ 146 | } \ 147 | } 148 | 149 | #define WRITE_NR44(val) \ 150 | { \ 151 | if(val&0x80){ \ 152 | Env[2].write_register(0, 4, data[0xFF23],val); \ 153 | if(!noise_lc) noise_lc=noise_ll? noise_ll: 64; \ 154 | } \ 155 | } 156 | 157 | 158 | #define WRITE_WAVE(addr,val) \ 159 | { \ 160 | /*fprintf(fp_log,"PENIS!\n");*/ \ 161 | } 162 | 163 | #define WRITE(addr,val) \ 164 | { \ 165 | temp16=addr; \ 166 | temp=val; \ 167 | if(temp16<0x3FFF && temp16>=0x2000 && is_switched) \ 168 | BANKSWITCH(temp-1); \ 169 | if(temp16>=0xFF00){ \ 170 | /*if(temp16==0xFF25 || temp16==0xFF1E) fprintf(fp_log,"WRITE: %04X %02X\n",temp16,temp);*/ \ 171 | switch(temp16&0xFF){ \ 172 | case 0x10: \ 173 | sweeped=1; \ 174 | break; \ 175 | case 0x11: \ 176 | WRITE_NR11(temp); \ 177 | temp|=0x3F; \ 178 | break; \ 179 | case 0x16: \ 180 | WRITE_NR21(temp); \ 181 | temp|=0x3F; \ 182 | break; \ 183 | case 0x1B: \ 184 | WRITE_NR31(temp); \ 185 | break; \ 186 | case 0x20: \ 187 | WRITE_NR41(temp); \ 188 | temp|=0x3F; \ 189 | break; \ 190 | case 0x14: \ 191 | WRITE_NR14(temp); \ 192 | break; \ 193 | case 0x19: \ 194 | WRITE_NR24(temp); \ 195 | break; \ 196 | case 0x1E: \ 197 | WRITE_NR34(temp); \ 198 | break; \ 199 | case 0x23: \ 200 | WRITE_NR44(temp); \ 201 | break; \ 202 | case 0x12: \ 203 | WRITE_NR12(temp); \ 204 | break; \ 205 | case 0x17: \ 206 | WRITE_NR22(temp); \ 207 | break; \ 208 | case 0x1C: \ 209 | temp|=0x9F; \ 210 | break; \ 211 | case 0x21: \ 212 | WRITE_NR42(temp); \ 213 | break; \ 214 | /*if(temp16>=0xFF30 && temp16<0xFF40)*/ \ 215 | /*WRITE_WAVE(temp16,temp);*/ \ 216 | default: \ 217 | break; \ 218 | } \ 219 | } \ 220 | MEM(temp16)=temp; \ 221 | } 222 | 223 | #define READ(addr) \ 224 | { \ 225 | /*fprintf(fp_log,"READ: %04X %02X\n",addr,data[addr])*/;\ 226 | } 227 | 228 | #define BRANCH() \ 229 | { \ 230 | temp = FETCH(); \ 231 | if (temp>=0x80) PC-=0x100; \ 232 | PC+=temp; \ 233 | } 234 | 235 | #define INC8(dest) \ 236 | { \ 237 | dest++; \ 238 | flags&=F_C; \ 239 | if(!dest) \ 240 | flags |= F_Z; \ 241 | if(!(dest&0x0F)) \ 242 | flags |= F_H; \ 243 | } 244 | 245 | #define INC16(dest) \ 246 | { \ 247 | dest++; \ 248 | } 249 | 250 | #define DEC8(dest) \ 251 | { \ 252 | flags&=F_C; \ 253 | /*if(!dest) flags|=F_C;*/ \ 254 | dest--; \ 255 | flags|=F_N/*|F_H*/; \ 256 | if(!dest) \ 257 | flags |= F_Z; \ 258 | if((dest&0x0F)==0x0F) \ 259 | flags |= F_H; \ 260 | } 261 | 262 | #define DEC16(dest) \ 263 | { \ 264 | dest--; \ 265 | } 266 | 267 | #define SUB8(val) \ 268 | { \ 269 | temp=A; \ 270 | A-=val; \ 271 | flags=F_N; \ 272 | if(!A) flags|=F_Z; \ 273 | if(A>temp) flags|=F_C; \ 274 | if((A&0x0F) > (temp&0x0F)) \ 275 | flags|=F_H; \ 276 | } 277 | 278 | #define SBC8(val) \ 279 | { \ 280 | temp=A; \ 281 | A-=val; \ 282 | if(flags&F_C) A--; \ 283 | flags=F_N; \ 284 | if(!A) flags|=F_Z; \ 285 | if(A>temp) flags|=F_C; \ 286 | if((A&0x0F) > (temp&0x0F)) \ 287 | flags|=F_H; \ 288 | } 289 | 290 | #define ADD8(val) \ 291 | { \ 292 | temp=A; \ 293 | A+=val; \ 294 | flags=0; \ 295 | if(!A) flags|=F_Z; \ 296 | if(Atemp16) flags|=F_C; \ 320 | if((dest&0x0F00) > (temp16&0x0F00)) \ 321 | flags|=F_H; \ 322 | } 323 | 324 | #define SBC16(dest,val) \ 325 | { \ 326 | temp16=dest; \ 327 | dest-=val; \ 328 | if(flags&F_C) dest--; \ 329 | flags=F_N; \ 330 | if(!(dest&0xFF00)) flags=F_Z; \ 331 | if(dest>temp16) flags|=F_C; \ 332 | if((dest&0x0F00) > (temp16&0x0F00)) \ 333 | flags|=F_H; \ 334 | } 335 | 336 | #define ADD16(dest,val) \ 337 | { \ 338 | temp16=dest; \ 339 | dest+=val; \ 340 | flags&=F_Z; \ 341 | /*if(!(dest&0xFF00)) flags=F_Z;*/ \ 342 | if(dest>7)&F_H; \ 344 | } 345 | 346 | #define ADC16(dest,val) \ 347 | { \ 348 | temp16=dest; \ 349 | dest+=val; \ 350 | if(flags&F_C) dest++; \ 351 | flags=0; \ 352 | if(!(dest&0xFF00)) flags=F_Z; \ 353 | if(destA) flags|=F_C; \ 391 | if((temp&0x0F) > (A&0x0F)) \ 392 | flags|=F_H; \ 393 | } 394 | 395 | #define PUSH(val) \ 396 | { \ 397 | MEM(--SP)=(val)>>8; \ 398 | MEM(--SP)=(val)&255; \ 399 | } 400 | 401 | #define POP(val) \ 402 | { \ 403 | val=MEM(SP++); \ 404 | val|=MEM(SP++)<<8; \ 405 | } 406 | 407 | #define SRL(dest) \ 408 | { \ 409 | flags=0; \ 410 | if(dest&1) flags|=F_C; \ 411 | dest>>=1; \ 412 | if(!dest) flags|=F_Z; \ 413 | } 414 | 415 | #define SRA(dest) \ 416 | { \ 417 | flags=0; \ 418 | if(dest&1) flags|=F_C; \ 419 | dest=(dest&128)|(dest>>1); \ 420 | if(!dest) flags|=F_Z; \ 421 | } 422 | 423 | #define SLA(dest) \ 424 | { \ 425 | flags=0; \ 426 | if(dest&128) flags|=F_C; \ 427 | dest<<=1; \ 428 | if(!dest) flags|=F_Z; \ 429 | } 430 | 431 | #define RR(dest) \ 432 | { \ 433 | temp=(flags&F_C)? 128: 0; \ 434 | flags=(dest&1)? F_C: 0; \ 435 | dest=temp|(dest>>1); \ 436 | if(!dest) flags|=F_Z; \ 437 | } 438 | 439 | #define RRA() \ 440 | { \ 441 | temp = (flags&F_C)? 128: 0; \ 442 | flags = (A&1)? F_C: 0; \ 443 | A = temp|(A>>1); \ 444 | } 445 | 446 | 447 | #define RRC(dest) \ 448 | { \ 449 | flags=(dest&1)? F_C: 0; \ 450 | dest=((dest&1)<<7)|(dest>>1); \ 451 | if(!dest) flags|=F_Z; \ 452 | } 453 | 454 | #define RRCA() \ 455 | { \ 456 | flags = (A&1)? F_C: 0; \ 457 | A = ((A&1)<<7)|(A>>1); \ 458 | } 459 | 460 | #define RL(dest) \ 461 | { \ 462 | temp=(flags&F_C)? 1: 0; \ 463 | flags=(dest&128)? F_C: 0; \ 464 | dest=(dest<<1)|temp; \ 465 | if(!dest) flags|=F_Z; \ 466 | } 467 | 468 | #define RLA() \ 469 | { \ 470 | temp=(flags&F_C)? 1: 0; \ 471 | flags=(A&128)? F_C: 0; \ 472 | A=(A<<1)|temp; \ 473 | if(!A) flags|=F_Z; \ 474 | } 475 | 476 | #define RLC(dest) \ 477 | { \ 478 | flags=(dest&128)? F_C: 0; \ 479 | dest=(dest<<1)|(dest>>7); \ 480 | if(!dest) flags|=F_Z; \ 481 | } 482 | 483 | #define RLCA() \ 484 | { \ 485 | flags = (A&128)? F_C: 0; \ 486 | A = (A<<1)|(A>>7); \ 487 | } 488 | 489 | #define BIT(b,val) \ 490 | { \ 491 | flags&=F_C; \ 492 | flags|=F_H; \ 493 | if(!(val&(1<<(b)))){ \ 494 | flags|=F_Z; \ 495 | } \ 496 | } 497 | 498 | #define SET(b,dest) \ 499 | { \ 500 | dest|=(1<<(b)); \ 501 | } 502 | 503 | #define RES(b,dest) \ 504 | { \ 505 | dest&=~(1<<(b)); \ 506 | } 507 | 508 | #define SWAP(dest) \ 509 | { \ 510 | flags=0; \ 511 | dest=(dest>>4)|((dest&15)<<4); \ 512 | if(!dest) flags=F_Z; \ 513 | } 514 | 515 | #define SCF() \ 516 | { \ 517 | flags &= F_Z; \ 518 | flags |= F_C; \ 519 | } 520 | 521 | #define CCF() \ 522 | { \ 523 | flags &= F_C|F_Z; \ 524 | flags ^= F_C; \ 525 | } 526 | 527 | #define RSTCALL(dest) \ 528 | { \ 529 | PUSH(PC); \ 530 | PC=dest; \ 531 | } 532 | 533 | #define CALL(dest) \ 534 | { \ 535 | PUSH((PC+2)); \ 536 | PC=dest; \ 537 | } 538 | 539 | #define RET() \ 540 | { \ 541 | if(SP==Info.sp_init) return 0; \ 542 | POP(PC); \ 543 | } 544 | -------------------------------------------------------------------------------- /src/GBSImport.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** GBS Import 3 | ** Copyright (C) 2014 Slimeball 4 | ** 5 | ** Based on: 6 | ** 7 | ** FamiTracker - NES/Famicom sound tracker 8 | ** Copyright (C) 2005-2012 Jonathan Liss 9 | ** 10 | ** NSF Importer v0.5 - Written by Brad Smith 11/21/2011 11 | ** 12 | ** Game Music Emu - Copyright (C) 2003-2009 Shay Green 13 | ** 14 | ** This program is free software; you can redistribute it and/or modify 15 | ** it under the terms of the GNU General Public License as published by 16 | ** the Free Software Foundation; either version 3 of the License, or 17 | ** (at your option) any later version. 18 | ** 19 | ** This program is distributed in the hope that it will be useful, 20 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | ** Library General Public License for more details. To obtain a 23 | ** copy of the GNU Library General Public License, write to the Free 24 | ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 | ** 26 | ** Any permitted reproduction of these routines, in whole or in part, 27 | ** must bear this legend. 28 | */ 29 | 30 | #define _CRT_SECURE_NO_WARNINGS 31 | 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include "ft_stuff.h" 37 | #include "GBS_Emu.h" 38 | #include "GBSImport.h" 39 | 40 | #define PLAYBACK_LENGTH 7200 41 | #define NOTE_COUNT 96 42 | #define IMPORT_CHANNELS 4 43 | 44 | #define PANIC(msg) \ 45 | { \ 46 | printf("%s\n",msg); \ 47 | return false; \ 48 | } 49 | 50 | extern void set_progress(int value); 51 | 52 | CGBS_Emu* pGBS = new CGBS_Emu(); 53 | CFTMFile* pFTM = new CFTMFile(); 54 | 55 | int noise_ntable[]={ 56 | 0, 1, 2, 3, 4, 6, 9, 11, 13, 14, 15, 15, 15, 15, 15, 15, 57 | 1, 2, 3, 4, 6, 9, 11, 13, 14, 15, 15, 15, 15, 15, 15, 15, 58 | 2, 3, 4, 6, 9, 11, 13, 14, 15, 15, 15, 15, 15, 15, 15, 15, 59 | 2, 3, 5, 8, 10, 12, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 60 | 3, 4, 6, 9, 11, 13, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 61 | 3, 4, 7, 10, 12, 13, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 62 | 3, 5, 8, 10, 12, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 63 | 4, 5, 8, 11, 13, 14, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 64 | }; 65 | 66 | int quadlog[8] = {12,16,20,22,24,25,26,27}; // Fancy term for 4 times the 2-logarithm of the divisor 67 | int old_noisetable[] = { 68 | 15,15,15,15,15,15,15,15,15,15,15,15,15,15,14,14, 69 | 14,13,13,13,12,12,12,11,10,10,9,9,9,8,8,8, 70 | 7,7,7,6,6,6,5,5,5,4,4,4,3,3,3,2, 71 | 2,2,1,1,1,0,0,0,0,0,0,0,0,0,0,0, 72 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 73 | 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 74 | }; // What an ugly table! :P 75 | 76 | int gb_vtable[4]={0,11,6,3}; 77 | 78 | unsigned int freqtable[NOTE_COUNT]; // For 2A03/MMC5/VRC6 79 | unsigned int n163table[NOTE_COUNT]; // For N163 80 | 81 | byte wtable[512][16]; 82 | 83 | int chmap[6]={0,1,3,5,9,9}; 84 | 85 | int w_count=0; 86 | int silence_count=0; 87 | 88 | void init_tables() 89 | { 90 | double clock_ntsc = 1789773 / 16.0; 91 | double clock_gb = 4194304 / 32.0; 92 | double BASE_FREQ = 32.7032; 93 | double Freq; 94 | double Pitch; 95 | 96 | memset(wtable,0,256); 97 | 98 | for (int i=0;i0xFFFF) 107 | n163table[i]=0xFFFF; 108 | } 109 | } 110 | 111 | void GetNote(int Register, int& Note, int& Octave, int& Pitch) 112 | { 113 | if (Register==0){ 114 | Note=FT_NOTE_CUT; Octave=0; Pitch=0; 115 | return; 116 | } 117 | 118 | int MidiNote = 0; 119 | int MinDiff = 9999999; 120 | for (unsigned int i=1; i < 95; i++) 121 | { 122 | int Val = freqtable[i]; 123 | int Diff = Val - Register; 124 | int AbsDiff = (Diff<0)? -Diff: Diff; 125 | if (AbsDiff < MinDiff) 126 | { 127 | MinDiff = AbsDiff; 128 | MidiNote = i; 129 | Pitch = 128+Diff; 130 | } 131 | } 132 | 133 | Note = (MidiNote%12)+1; 134 | Octave = MidiNote/12; 135 | } 136 | 137 | void GetN163Note(int Register, int& Note, int& Octave, int& Pitch) 138 | { 139 | if (Register==0){ 140 | Note=FT_NOTE_CUT; Octave=0; Pitch=0; 141 | return; 142 | } 143 | 144 | int MidiNote = 0; 145 | int MinDiff = 9999999; 146 | double clock_ntsc = 1789773 / 16.0; 147 | double clock_gb = 4194304 / 32.0; 148 | int N163Reg = (int)((((clock_gb/Register)*1*983040.0)/clock_ntsc)/4); 149 | 150 | for (unsigned int i=1; i<95; i++) 151 | { 152 | int Val = n163table[i]; 153 | int Diff = Val - N163Reg; 154 | int AbsDiff = (Diff<0)? -Diff: Diff; 155 | if (AbsDiff < MinDiff) 156 | { 157 | MinDiff = AbsDiff; 158 | MidiNote = i; 159 | Pitch = 128+(Diff/4); 160 | } 161 | } 162 | 163 | Note = (MidiNote%12)+1; 164 | Octave = MidiNote/12; 165 | } 166 | 167 | bool GBS2FTM(CGBS_Emu* pGBS, CFTMFile* pFTM, int length, int track, bool nosilence) 168 | { 169 | int i,j,k; 170 | int c_order=0; 171 | int c_pattern=0; 172 | int c_row=0; 173 | int gb_vol=0; 174 | int gb_duty=0; 175 | int gb_pitch=0; 176 | int gb_sweep=0; 177 | int c_ftnote=0; 178 | int c_ftoct=0; 179 | int c_ftinst=0; 180 | int c_ftvol=0; 181 | int c_ftpitch=0; 182 | int c_ftwave=0; 183 | int n_items=0; 184 | int p_pitch=0; 185 | 186 | int p_ftnote[IMPORT_CHANNELS]={0}; 187 | int p_ftoct[IMPORT_CHANNELS]={0}; 188 | int p_ftinst[IMPORT_CHANNELS]={64,64,64,64}; 189 | int p_ftvol[IMPORT_CHANNELS]={16,16,16,16}; 190 | int p_ftduty[IMPORT_CHANNELS]={0}; 191 | int p_ftpitch[IMPORT_CHANNELS]={0}; 192 | int p_ftsweep=0; 193 | 194 | pFTM->expansion=0x10; 195 | pFTM->channels=6; 196 | pFTM->N163_channels=1; 197 | pFTM->n_frames=1; 198 | pFTM->n_patterns=IMPORT_CHANNELS*pFTM->n_frames; 199 | pFTM->speed=1; 200 | pFTM->tempo=150; 201 | pFTM->p_length=256; 202 | pFTM->ch_fx[0]=2; 203 | pFTM->ch_fx[1]=1; 204 | //pFTM->ch_fx[5]=1; 205 | 206 | pFTM->n_instruments=1; 207 | 208 | //int Note, Octave, Pitch; 209 | 210 | if(!pGBS->Init(track)) return false; 211 | 212 | memcpy(wtable[w_count],&(pGBS->data[0xFF30]),16); 213 | 214 | for(i=0;iPlayOnce(); 220 | if(!result) return false; 221 | 222 | for(j=0;jdata[0xFF30+k]) break; 225 | } 226 | if(k==16){ 227 | c_ftwave=j; 228 | w_new=false; 229 | break; 230 | } 231 | } 232 | 233 | if(w_new){ 234 | c_ftwave = w_count; 235 | memcpy(wtable[w_count],&(pGBS->data[0xFF30]),16); 236 | w_count++; 237 | } 238 | 239 | c_pattern = (c_order*IMPORT_CHANNELS); 240 | 241 | gb_vol = pGBS->Env[0].vol; //pGBS->sq1_vol; 242 | gb_duty = pGBS->data[0xFF11]>>6; 243 | gb_pitch = (((pGBS->data[0xFF14]&7)<<8) | pGBS->data[0xFF13]); 244 | gb_pitch = 2048 - gb_pitch; 245 | gb_sweep = pGBS->data[0xFF10]; 246 | gb_sweeped = pGBS->sweeped? true: false; 247 | pGBS->sweeped = 0; 248 | if((gb_pitch!=p_pitch) && (gb_sweep&0x77)) gb_sweeped = true; 249 | GetNote(gb_pitch, c_ftnote, c_ftoct, c_ftpitch); 250 | 251 | if((gb_sweep&0x8) && ((gb_sweep&0x7)>0)) gb_sweep--; 252 | 253 | if(silence && gb_vol && c_ftnote != FT_NOTE_CUT) silence=false; 254 | 255 | pFTM->Pattern[c_pattern].Item[n_items].row = c_row; 256 | pFTM->Pattern[c_pattern].Item[n_items].note = (c_ftnote==p_ftnote[0] && c_ftoct==p_ftoct[0])? 0: c_ftnote; 257 | pFTM->Pattern[c_pattern].Item[n_items].octave = (c_ftnote==p_ftnote[0] && c_ftoct==p_ftoct[0])? 0: c_ftoct; 258 | pFTM->Pattern[c_pattern].Item[n_items].instrument = (c_ftnote==p_ftnote[0] && c_ftoct==p_ftoct[0])? 64: 0; 259 | pFTM->Pattern[c_pattern].Item[n_items].volume = (gb_vol==p_ftvol[0])? 16: gb_vol; 260 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[0] = (c_ftpitch==p_ftpitch[0])? 0: EF_PITCH; 261 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[1] = (c_ftpitch==p_ftpitch[0])? 0: c_ftpitch; 262 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[2] = (gb_duty==p_ftduty[0])? 0: EF_DUTY_CYCLE; 263 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[3] = (gb_duty==p_ftduty[0])? 0: gb_duty; 264 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[4] = (!gb_sweeped || (gb_sweep==0 && p_ftsweep==gb_sweep))? 0: (gb_sweep&0x8)? EF_SWEEPDOWN: EF_SWEEPUP; 265 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[5] = (!gb_sweeped || (gb_sweep==0 && p_ftsweep==gb_sweep))? 0: gb_sweep&0x77; 266 | 267 | p_pitch = gb_pitch; 268 | p_ftnote[0] = c_ftnote; 269 | p_ftoct[0] = c_ftoct; 270 | p_ftvol[0] = gb_vol; 271 | p_ftduty[0] = gb_duty; 272 | p_ftpitch[0] = c_ftpitch; 273 | p_ftsweep = gb_sweep; 274 | 275 | c_pattern = (c_order*IMPORT_CHANNELS)+1; 276 | 277 | gb_vol = pGBS->Env[1].vol; //pGBS->sq2_vol; 278 | gb_duty = pGBS->data[0xFF16]>>6; 279 | gb_pitch = (((pGBS->data[0xFF19]&7)<<8) | pGBS->data[0xFF18]); 280 | gb_pitch = 2048 - gb_pitch; 281 | GetNote(gb_pitch, c_ftnote, c_ftoct, c_ftpitch); 282 | 283 | if(silence && gb_vol && c_ftnote != FT_NOTE_CUT) silence=false; 284 | 285 | pFTM->Pattern[c_pattern].Item[n_items].row = c_row; 286 | pFTM->Pattern[c_pattern].Item[n_items].note = (c_ftnote==p_ftnote[1] && c_ftoct==p_ftoct[1])? 0: c_ftnote; 287 | pFTM->Pattern[c_pattern].Item[n_items].octave = (c_ftnote==p_ftnote[1] && c_ftoct==p_ftoct[1])? 0: c_ftoct; 288 | pFTM->Pattern[c_pattern].Item[n_items].instrument = (c_ftnote==p_ftnote[1] && c_ftoct==p_ftoct[1])? 64: 0; 289 | pFTM->Pattern[c_pattern].Item[n_items].volume = (gb_vol==p_ftvol[1])? 16: gb_vol; 290 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[0] = (c_ftpitch==p_ftpitch[1])? 0: EF_PITCH; 291 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[1] = (c_ftpitch==p_ftpitch[1])? 0: c_ftpitch; 292 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[2] = (gb_duty==p_ftduty[1])? 0: EF_DUTY_CYCLE; 293 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[3] = (gb_duty==p_ftduty[1])? 0: gb_duty; 294 | 295 | p_ftnote[1]=c_ftnote; 296 | p_ftoct[1]=c_ftoct; 297 | p_ftvol[1]=gb_vol; 298 | p_ftduty[1]=gb_duty; 299 | p_ftpitch[1]=c_ftpitch; 300 | 301 | c_pattern = (c_order*IMPORT_CHANNELS)+2; 302 | 303 | gb_vol = pGBS->Env[2].vol; //pGBS->noise_vol; 304 | gb_duty = pGBS->data[0xFF22]&8; 305 | gb_pitch = ((pGBS->data[0xFF22]<<4)|(pGBS->data[0xFF22]>>4))&0x7F; 306 | 307 | int noisenote=16+old_noisetable[4*(gb_pitch&15)+quadlog[gb_pitch>>4]]; 308 | 309 | if(noise_ntable[gb_pitch]==0x99 || !(pGBS->data[0xFF25]&0x88)){ 310 | c_ftnote=FT_NOTE_CUT; 311 | c_ftoct=0; 312 | } else { 313 | c_ftnote=((31-noise_ntable[gb_pitch])%12)+1; 314 | c_ftoct=(31-noise_ntable[gb_pitch])/12; 315 | } 316 | 317 | if(silence && gb_vol && c_ftnote != FT_NOTE_CUT) silence=false; 318 | 319 | pFTM->Pattern[c_pattern].Item[n_items].row = c_row; 320 | pFTM->Pattern[c_pattern].Item[n_items].note = (c_ftnote==p_ftnote[2] && c_ftoct==p_ftoct[2])? 0: c_ftnote; 321 | pFTM->Pattern[c_pattern].Item[n_items].octave = (c_ftnote==p_ftnote[2] && c_ftoct==p_ftoct[2])? 0: c_ftoct; 322 | pFTM->Pattern[c_pattern].Item[n_items].instrument = (c_ftnote==p_ftnote[2] && c_ftoct==p_ftoct[2])? 64: 0; 323 | pFTM->Pattern[c_pattern].Item[n_items].volume = (gb_vol==p_ftvol[2])? 16:gb_vol; 324 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[0] = (gb_duty==p_ftduty[2])? 0: EF_DUTY_CYCLE; 325 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[1] = (gb_duty==p_ftduty[2])? 0: gb_duty>>3; 326 | 327 | 328 | p_ftnote[2]=c_ftnote; 329 | p_ftoct[2]=c_ftoct; 330 | p_ftvol[2]=gb_vol; 331 | p_ftduty[2]=gb_duty; 332 | 333 | c_pattern = (c_order*IMPORT_CHANNELS)+3; 334 | 335 | gb_vol = ((pGBS->data[0xFF26]&0x4)||(pGBS->data[0xFF25]&0x44))? (pGBS->data[0xFF1C]>>5)&3: 0; 336 | gb_pitch = (((pGBS->data[0xFF1E]&7)<<8) | pGBS->data[0xFF1D]); 337 | gb_pitch = 2048 - gb_pitch; 338 | GetNote(gb_pitch, c_ftnote, c_ftoct, c_ftpitch); 339 | 340 | if(silence && gb_vol && c_ftnote != FT_NOTE_CUT) silence=false; 341 | 342 | pFTM->Pattern[c_pattern].Item[n_items].row = c_row; 343 | pFTM->Pattern[c_pattern].Item[n_items].note = (c_ftnote==p_ftnote[3] && c_ftoct==p_ftoct[3])? 0: c_ftnote; 344 | pFTM->Pattern[c_pattern].Item[n_items].octave = (c_ftnote==p_ftnote[3] && c_ftoct==p_ftoct[3])? 0: c_ftoct; 345 | pFTM->Pattern[c_pattern].Item[n_items].instrument = (c_ftnote==p_ftnote[3] && c_ftoct==p_ftoct[3] && p_ftduty[3]==c_ftwave)? 64: (c_ftwave/16)+1; 346 | pFTM->Pattern[c_pattern].Item[n_items].volume = (gb_vol==p_ftvol[3])? 16: gb_vtable[gb_vol]; 347 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[0] = (p_ftduty[3]==c_ftwave)? 0: EF_DUTY_CYCLE; 348 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[1] = (p_ftduty[3]==c_ftwave)? 0: c_ftwave&15; 349 | 350 | p_ftnote[3]=c_ftnote; 351 | p_ftoct[3]=c_ftoct; 352 | p_ftvol[3]=gb_vol; 353 | p_ftduty[3]=c_ftwave; 354 | 355 | n_items++; 356 | c_row++; 357 | 358 | while(c_row>=256){ 359 | for(j=0;jPattern[c_pattern].items = n_items; 362 | pFTM->Pattern[c_pattern].track = 0; 363 | pFTM->Pattern[c_pattern].channel = chmap[j]; 364 | pFTM->Pattern[c_pattern].index = c_order; 365 | } 366 | n_items=0; 367 | c_row-=256; 368 | c_order++; 369 | pFTM->n_frames++; 370 | pFTM->n_patterns += IMPORT_CHANNELS; 371 | } 372 | pGBS->Clock64(); 373 | 374 | if(silence){ 375 | silence_count++; 376 | if(silence_count>=300 && nosilence) break; 377 | } else silence_count=0; 378 | } 379 | 380 | if(!w_count) w_count=1; 381 | 382 | pFTM->N163_instruments=(w_count+15)/16; 383 | 384 | for(i=0;iInst_N163[c_inst].index=c_inst+1; 388 | pFTM->Inst_N163[c_inst].wave_count=min(w_count-i,16); 389 | } 390 | for(j=0;j<16;j++){ 391 | pFTM->Inst_N163[c_inst].wave_data[i&15][2*j]=wtable[i][j]>>4; 392 | pFTM->Inst_N163[c_inst].wave_data[i&15][2*j+1]=wtable[i][j]&15; 393 | } 394 | } 395 | 396 | for(i=0;iPattern[c_pattern].Item[n_items].row = c_row; 399 | pFTM->Pattern[c_pattern].Item[n_items].note = FT_NOTE_CUT; 400 | pFTM->Pattern[c_pattern].Item[n_items].octave = 0; 401 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[0] = EF_HALT; 402 | pFTM->Pattern[c_pattern].Item[n_items].fxdata[1] = 0; 403 | pFTM->Pattern[c_pattern].items = n_items+1; 404 | pFTM->Pattern[c_pattern].track = 0; 405 | pFTM->Pattern[c_pattern].channel = chmap[i]; 406 | pFTM->Pattern[c_pattern].index = c_order; 407 | } 408 | 409 | for(i=0;in_frames;i++){ 410 | memset(pFTM->fdata[i],0,6); 411 | for(j=0;jfdata[i][chmap[j]]=i; 414 | } 415 | } 416 | return true; 417 | } 418 | 419 | bool GBSImport::Scan(char* filename) 420 | { 421 | //init_tables(); 422 | return pGBS->LoadFile(filename); 423 | } 424 | 425 | bool GBSImport::Import(char* gbsname, int track, int seconds, bool alltracks, bool nosilence) 426 | { 427 | char ftmname[256]; 428 | 429 | init_tables(); 430 | 431 | if(!alltracks){ 432 | memset(ftmname,0,256); 433 | strcpy(ftmname,gbsname); 434 | ftmname[strlen(ftmname)-4]=0; 435 | strcat(ftmname,".ftm"); 436 | 437 | if(!pGBS->LoadFile(gbsname)) return false; 438 | if(!GBS2FTM(pGBS,pFTM,seconds*60,track-1,nosilence)) return false; 439 | if(!pFTM->Optimize()) return false; 440 | if(!pFTM->SaveFile(ftmname)) return false; 441 | } else { 442 | if(!pGBS->LoadFile(gbsname)) return false; 443 | int n_tracks = pGBS->Info.n_songs; 444 | 445 | FILE* fp_log=fopen("GBSImport.log","w"); if(!fp_log) PANIC("Couldn't create log file! :(\n"); 446 | 447 | fprintf(fp_log,"Attempting to import %s\n\n",gbsname); 448 | 449 | for(int i=0;iLoadFile(gbsname)) return false; 458 | if(!GBS2FTM(pGBS,pFTM,seconds*60,i,nosilence)){ 459 | fprintf(fp_log,"Track %i failed to import: %s\n",i+1,pGBS->errorcode); 460 | w_count=0; 461 | pGBS->Cleanup(); 462 | continue; 463 | } 464 | 465 | if(pGBS->Info.tctl==7 && pGBS->Info.tmod==192){ 466 | pFTM->tempo = 600; 467 | pFTM->e_speed = 240; 468 | } 469 | 470 | if(pGBS->Info.tctl==132 && pGBS->Info.tmod==128){ 471 | pFTM->tempo = 160; 472 | pFTM->e_speed = 64; 473 | } 474 | 475 | if(!pFTM->Optimize()) return false; 476 | if(!pFTM->SaveFile(ftmname)) return false; 477 | fprintf(fp_log,"Track %i imported successfully!\n",i+1); 478 | w_count=0; 479 | silence_count=0; 480 | pGBS->Cleanup(); 481 | } 482 | } 483 | 484 | set_progress(100); 485 | 486 | return true; 487 | } 488 | 489 | char* GBSImport::GetError() 490 | { 491 | return pGBS->errorcode; 492 | } -------------------------------------------------------------------------------- /src/GBS_Cpu.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** GBS Import 3 | ** Copyright (C) 2014 Slimeball 4 | ** 5 | ** Based on: 6 | ** 7 | ** FamiTracker - NES/Famicom sound tracker 8 | ** Copyright (C) 2005-2012 Jonathan Liss 9 | ** 10 | ** NSF Importer v0.5 - Written by Brad Smith 11/21/2011 11 | ** 12 | ** Game Music Emu - Copyright (C) 2003-2009 Shay Green 13 | ** 14 | ** This program is free software; you can redistribute it and/or modify 15 | ** it under the terms of the GNU General Public License as published by 16 | ** the Free Software Foundation; either version 3 of the License, or 17 | ** (at your option) any later version. 18 | ** 19 | ** This program is distributed in the hope that it will be useful, 20 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | ** Library General Public License for more details. To obtain a 23 | ** copy of the GNU Library General Public License, write to the Free 24 | ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 | ** 26 | ** Any permitted reproduction of these routines, in whole or in part, 27 | ** must bear this legend. 28 | */ 29 | 30 | #define _CRT_SECURE_NO_WARNINGS 31 | 32 | #include 33 | #include "GBZ80_tables.h" 34 | #include "GBZ80_macros.h" 35 | #include "GBS_Emu.h" 36 | 37 | #define PANIC(msg) \ 38 | { \ 39 | printf("%s\n",msg); \ 40 | return false; \ 41 | } 42 | 43 | #define PANIC2(msg) \ 44 | { \ 45 | strcpy(errorcode,msg); \ 46 | printf("%s\n",msg); \ 47 | return false; \ 48 | } 49 | 50 | void CGBS_Emu::LogDisasm() 51 | { 52 | fprintf(fp_log,"\nGBS DISASM:\n\n"); 53 | 54 | for(int i=Info.init_addr;i<(Info.init_addr+100);i++){ 55 | unsigned char c_byte=data[i]; 56 | fprintf(fp_log,"$%04X $%02X - %s",i,c_byte,gbs_opcodes[c_byte]); 57 | for(int j=0;j200000) PANIC2("Init routine uses an abnormally high amount of instructions! PCM isn't supported yet. ;)\n"); 85 | } 86 | 87 | //fprintf(fp_log,"\nInit routine exited properly :)\n\n"); 88 | return true; 89 | } 90 | 91 | bool CGBS_Emu::PlayOnce() 92 | { 93 | PC = Info.play_addr; 94 | SP = Info.sp_init; 95 | int i=0; 96 | 97 | while(true){ 98 | //fprintf(fp_log,"PC: %04X OP: %02X A:%02X F:%02X HL:%04X BC:%04X DE:%04X SP:%04X ASM: %s\n", PC, data[PC], A, flags, HL, BC, DE, SP, gbs_opcodes[data[PC]]); 99 | int result=RunCpu(); 100 | if(result==0){ 101 | //fprintf(fp_log,"\nPlay routine exited properly :)\n\n"); 102 | break; 103 | } 104 | if(result==-1) return false; 105 | if(i++>200000) PANIC2("Play routine uses an abnormally high amount of instructions! PCM isn't supported yet. ;)\n"); 106 | } 107 | return true; 108 | } 109 | 110 | int CGBS_Emu::RunCpu(void) 111 | { 112 | unsigned char temp; 113 | unsigned short temp16; 114 | 115 | unsigned char op = FETCH(); 116 | 117 | switch(op){ 118 | 119 | // Ext. ops 120 | 121 | case 0xCB: return RunExtCB(); 122 | 123 | // JR 124 | 125 | case 0x18: BRANCH(); break; 126 | case 0x20: if(!(flags&F_Z)) BRANCH() else PC++; break; 127 | case 0x30: if(!(flags&F_C)) BRANCH() else PC++; break; 128 | case 0x28: if(flags&F_Z) BRANCH() else PC++; break; 129 | case 0x38: if(flags&F_C) BRANCH() else PC++; break; 130 | 131 | // LD 132 | 133 | case 0x01: BC=IMM16(); PC+=2; break; 134 | case 0x11: DE=IMM16(); PC+=2; break; 135 | case 0x21: HL=IMM16(); PC+=2; break; 136 | case 0x31: SP=IMM16(); PC+=2; break; 137 | 138 | case 0x02: WRITE(BC,A); break; 139 | case 0x12: WRITE(DE,A); break; 140 | case 0x22: WRITE(HL++,A); break; 141 | case 0x32: WRITE(HL--,A); break; 142 | 143 | case 0x06: B=IMM8(); PC+=1; break; 144 | case 0x16: D=IMM8(); PC+=1; break; 145 | case 0x26: H=IMM8(); PC+=1; break; 146 | case 0x36: WRITE(HL,IMM8()); PC+=1; break; 147 | 148 | case 0x08: MEM(IMM16()) = SP&0xFF; MEM(IMM16()+1) = SP>>8; PC+=2; break; 149 | 150 | case 0x0A: READ(BC); A=MEM(BC); break; 151 | case 0x1A: READ(DE); A=MEM(DE); break; 152 | case 0x2A: READ(HL); A=MEM(HL++); break; 153 | case 0x3A: READ(HL); A=MEM(HL--); break; 154 | 155 | case 0x0E: C=IMM8(); PC+=1; break; 156 | case 0x1E: E=IMM8(); PC+=1; break; 157 | case 0x2E: L=IMM8(); PC+=1; break; 158 | case 0x3E: A=IMM8(); PC+=1; break; 159 | 160 | case 0xE0: WRITE(0xFF00+IMM8(),A); PC+=1; break; 161 | case 0xF0: READ(0xFF00+IMM8()); A=MEM(0xFF00+IMM8()); PC+=1; break; 162 | 163 | case 0xF8: HL=SP+(signed char)(IMM8()); PC+=1; break; 164 | case 0xF9: SP=HL; break; 165 | 166 | case 0xEA: WRITE(IMM16(),A); PC+=2; break; 167 | case 0xFA: READ(IMM16()); A=MEM(IMM16()); PC+=2; break; 168 | 169 | case 0x40: B=B; break; 170 | case 0x41: B=C; break; 171 | case 0x42: B=D; break; 172 | case 0x43: B=E; break; 173 | case 0x44: B=H; break; 174 | case 0x45: B=L; break; 175 | case 0x46: READ(HL); B=MEM(HL); break; 176 | case 0x47: B=A; break; 177 | 178 | case 0x48: C=B; break; 179 | case 0x49: C=C; break; 180 | case 0x4A: C=D; break; 181 | case 0x4B: C=E; break; 182 | case 0x4C: C=H; break; 183 | case 0x4D: C=L; break; 184 | case 0x4E: READ(HL); C=MEM(HL); break; 185 | case 0x4F: C=A; break; 186 | 187 | case 0x50: D=B; break; 188 | case 0x51: D=C; break; 189 | case 0x52: D=D; break; 190 | case 0x53: D=E; break; 191 | case 0x54: D=H; break; 192 | case 0x55: D=L; break; 193 | case 0x56: READ(HL); D=MEM(HL); break; 194 | case 0x57: D=A; break; 195 | 196 | case 0x58: E=B; break; 197 | case 0x59: E=C; break; 198 | case 0x5A: E=D; break; 199 | case 0x5B: E=E; break; 200 | case 0x5C: E=H; break; 201 | case 0x5D: E=L; break; 202 | case 0x5E: READ(HL); E=MEM(HL); break; 203 | case 0x5F: E=A; break; 204 | 205 | case 0x60: H=B; break; 206 | case 0x61: H=C; break; 207 | case 0x62: H=D; break; 208 | case 0x63: H=E; break; 209 | case 0x64: H=H; break; 210 | case 0x65: H=L; break; 211 | case 0x66: READ(HL); H=MEM(HL); break; 212 | case 0x67: H=A; break; 213 | 214 | case 0x68: L=B; break; 215 | case 0x69: L=C; break; 216 | case 0x6A: L=D; break; 217 | case 0x6B: L=E; break; 218 | case 0x6C: L=H; break; 219 | case 0x6D: L=L; break; 220 | case 0x6E: READ(HL); L=MEM(HL); break; 221 | case 0x6F: L=A; break; 222 | 223 | case 0x70: WRITE(HL,B); break; 224 | case 0x71: WRITE(HL,C); break; 225 | case 0x72: WRITE(HL,D); break; 226 | case 0x73: WRITE(HL,E); break; 227 | case 0x74: WRITE(HL,H); break; 228 | case 0x75: WRITE(HL,L); break; 229 | //case 0x76: H=MEM(HL); break; HALT!!!!!!! 230 | case 0x77: WRITE(HL,A); break; 231 | 232 | case 0x78: A=B; break; 233 | case 0x79: A=C; break; 234 | case 0x7A: A=D; break; 235 | case 0x7B: A=E; break; 236 | case 0x7C: A=H; break; 237 | case 0x7D: A=L; break; 238 | case 0x7E: READ(HL); A=MEM(HL); break; 239 | case 0x7F: A=A; break; 240 | 241 | case 0xE2: WRITE(0xFF00+C,A); break; 242 | case 0xF2: READ(0xFF00+C); A=MEM(0xFF00+C); break; 243 | 244 | // INC/DEC 245 | 246 | case 0x03: INC16(BC); break; 247 | case 0x13: INC16(DE); break; 248 | case 0x23: INC16(HL); break; 249 | case 0x33: INC16(SP); break; 250 | case 0x04: INC8(B); break; 251 | case 0x14: INC8(D); break; 252 | case 0x24: INC8(H); break; 253 | case 0x34: INC8(MEM(HL)); break; 254 | case 0x05: DEC8(B); break; 255 | case 0x15: DEC8(D); break; 256 | case 0x25: DEC8(H); break; 257 | case 0x35: DEC8(MEM(HL)); break; 258 | case 0x0B: DEC16(BC); break; 259 | case 0x1B: DEC16(DE); break; 260 | case 0x2B: DEC16(HL); break; 261 | case 0x3B: DEC16(SP); break; 262 | case 0x0C: INC8(C); break; 263 | case 0x1C: INC8(E); break; 264 | case 0x2C: INC8(L); break; 265 | case 0x3C: INC8(A); break; 266 | case 0x0D: DEC8(C); break; 267 | case 0x1D: DEC8(E); break; 268 | case 0x2D: DEC8(L); break; 269 | case 0x3D: DEC8(A); break; 270 | 271 | // ADD/ADC/SUB/SBC 272 | 273 | case 0x09: ADD16(HL,BC); break; 274 | case 0x19: ADD16(HL,DE); break; 275 | case 0x29: ADD16(HL,HL); break; 276 | case 0x39: ADD16(HL,SP); break; 277 | 278 | case 0x80: ADD8(B); break; 279 | case 0x81: ADD8(C); break; 280 | case 0x82: ADD8(D); break; 281 | case 0x83: ADD8(E); break; 282 | case 0x84: ADD8(H); break; 283 | case 0x85: ADD8(L); break; 284 | case 0x86: ADD8(MEM(HL)); break; 285 | case 0x87: ADD8(A); break; 286 | case 0xC6: ADD8(IMM8()); PC+=1; break; 287 | 288 | case 0x88: ADC8(B); break; 289 | case 0x89: ADC8(C); break; 290 | case 0x8A: ADC8(D); break; 291 | case 0x8B: ADC8(E); break; 292 | case 0x8C: ADC8(H); break; 293 | case 0x8D: ADC8(L); break; 294 | case 0x8E: ADC8(MEM(HL)); break; 295 | case 0x8F: ADC8(A); break; 296 | case 0xCE: ADC8(IMM8()); PC+=1; break; 297 | 298 | case 0x90: SUB8(B); break; 299 | case 0x91: SUB8(C); break; 300 | case 0x92: SUB8(D); break; 301 | case 0x93: SUB8(E); break; 302 | case 0x94: SUB8(H); break; 303 | case 0x95: SUB8(L); break; 304 | case 0x96: SUB8(MEM(HL)); break; 305 | case 0x97: SUB8(A); break; 306 | case 0xD6: SUB8(IMM8()); PC+=1; break; 307 | 308 | case 0x98: SBC8(B); break; 309 | case 0x99: SBC8(C); break; 310 | case 0x9A: SBC8(D); break; 311 | case 0x9B: SBC8(E); break; 312 | case 0x9C: SBC8(H); break; 313 | case 0x9D: SBC8(L); break; 314 | case 0x9E: SBC8(MEM(HL)); break; 315 | case 0x9F: SBC8(A); break; 316 | case 0xDE: SBC8(IMM8()); PC+=1; break; 317 | 318 | case 0xE8: ADD16(SP,(signed char)IMM8()); PC+=1; break; // Possibly broken 319 | 320 | // RR/RL 321 | 322 | case 0x07: RLCA(); break; 323 | case 0x0F: RRCA(); break; 324 | case 0x17: RLA(); break; 325 | case 0x1F: RRA(); break; 326 | 327 | // Flags 328 | 329 | case 0x2F: CPL(); break; 330 | case 0x37: SCF(); break; 331 | case 0x3F: CCF(); break; 332 | 333 | // AND/XOR/OR/CP 334 | 335 | case 0xA0: AND(B); break; 336 | case 0xA1: AND(C); break; 337 | case 0xA2: AND(D); break; 338 | case 0xA3: AND(E); break; 339 | case 0xA4: AND(H); break; 340 | case 0xA5: AND(L); break; 341 | case 0xA6: AND(MEM(HL)); break; 342 | case 0xA7: AND(A); break; 343 | case 0xE6: AND(IMM8()); PC+=1; break; 344 | 345 | case 0xA8: XOR(B); break; 346 | case 0xA9: XOR(C); break; 347 | case 0xAA: XOR(D); break; 348 | case 0xAB: XOR(E); break; 349 | case 0xAC: XOR(H); break; 350 | case 0xAD: XOR(L); break; 351 | case 0xAE: XOR(MEM(HL)); break; 352 | case 0xAF: XOR(A); break; 353 | case 0xEE: XOR(IMM8()); PC+=1; break; 354 | 355 | case 0xB0: OR(B); break; 356 | case 0xB1: OR(C); break; 357 | case 0xB2: OR(D); break; 358 | case 0xB3: OR(E); break; 359 | case 0xB4: OR(H); break; 360 | case 0xB5: OR(L); break; 361 | case 0xB6: OR(MEM(HL)); break; 362 | case 0xB7: OR(A); break; 363 | case 0xF6: OR(IMM8()); PC+=1; break; 364 | 365 | case 0xB8: CP(B); break; 366 | case 0xB9: CP(C); break; 367 | case 0xBA: CP(D); break; 368 | case 0xBB: CP(E); break; 369 | case 0xBC: CP(H); break; 370 | case 0xBD: CP(L); break; 371 | case 0xBE: CP(MEM(HL)); break; 372 | case 0xBF: CP(A); break; 373 | case 0xFE: CP(IMM8()); PC+=1; break; 374 | 375 | // RET 376 | 377 | case 0xC0: if(!(flags&F_Z)) RET(); break; 378 | case 0xC8: if(flags&F_Z) RET(); break; 379 | case 0xC9: RET(); break; 380 | case 0xD0: if(!(flags&F_C)) RET(); break; 381 | case 0xD8: if(flags&F_C) RET(); break; 382 | case 0xD9: RET(); break; 383 | 384 | // POP/PUSH 385 | 386 | case 0xC1: POP(BC); break; 387 | case 0xC5: PUSH(BC); break; 388 | case 0xD1: POP(DE); break; 389 | case 0xD5: PUSH(DE); break; 390 | case 0xE1: POP(HL); break; 391 | case 0xE5: PUSH(HL); break; 392 | case 0xF1: POP(AF); flags&=0xF0; break; 393 | case 0xF5: PUSH(AF); break; 394 | 395 | // JP/CALL 396 | 397 | case 0xC2: if(!(flags&F_Z)) PC=IMM16(); else PC+=2; break; 398 | case 0xC3: PC=IMM16(); break; 399 | case 0xCA: if(flags&F_Z) PC=IMM16(); else PC+=2; break; 400 | case 0xD2: if(!(flags&F_C)) PC=IMM16(); else PC+=2; break; 401 | case 0xDA: if(flags&F_C) PC=IMM16(); else PC+=2; break; 402 | 403 | case 0xC4: if(!(flags&F_Z)) CALL(IMM16()) else PC+=2; break; 404 | case 0xCC: if(flags&F_Z) CALL(IMM16()) else PC+=2; break; 405 | case 0xCD: CALL(IMM16()); break; 406 | case 0xD4: if(!(flags&F_C)) CALL(IMM16()) else PC+=2; break; 407 | case 0xDC: if(flags&F_C) CALL(IMM16()) else PC+=2; break; 408 | 409 | case 0xE9: PC=HL; break; 410 | 411 | case 0x00: break; // NOP 412 | case 0xF3: break; // DI 413 | case 0xFB: break; // EI 414 | 415 | // RST Vectors 416 | 417 | case 0xC7: RSTCALL(Info.load_addr+0x00); break; 418 | case 0xCF: RSTCALL(Info.load_addr+0x08); break; 419 | case 0xD7: RSTCALL(Info.load_addr+0x10); break; 420 | case 0xDF: RSTCALL(Info.load_addr+0x18); break; 421 | case 0xE7: RSTCALL(Info.load_addr+0x20); break; 422 | case 0xEF: RSTCALL(Info.load_addr+0x28); break; 423 | case 0xF7: RSTCALL(Info.load_addr+0x30); break; 424 | case 0xFF: RSTCALL(Info.load_addr+0x38); break; 425 | 426 | default: 427 | sprintf(errorcode,"Error: Unknown opcode $%02X at $%04X\n",op,PC-1); 428 | printf("Error: Unknown opcode $%02X at $%04X\n",op,PC-1); 429 | return -1; 430 | } 431 | 432 | return 1; 433 | } 434 | 435 | int CGBS_Emu::RunExtCB(void) 436 | { 437 | unsigned char temp; 438 | unsigned char op = FETCH(); 439 | 440 | switch(op){ 441 | case 0x00: RLC(B); break; 442 | case 0x01: RLC(C); break; 443 | case 0x02: RLC(D); break; 444 | case 0x03: RLC(E); break; 445 | case 0x04: RLC(H); break; 446 | case 0x05: RLC(L); break; 447 | case 0x06: RLC(MEM(HL)); break; 448 | case 0x07: RLC(A); break; 449 | case 0x08: RRC(B); break; 450 | case 0x09: RRC(C); break; 451 | case 0x0A: RRC(D); break; 452 | case 0x0B: RRC(E); break; 453 | case 0x0C: RRC(H); break; 454 | case 0x0D: RRC(L); break; 455 | case 0x0E: RRC(MEM(HL)); break; 456 | case 0x0F: RRC(A); break; 457 | 458 | case 0x10: RL(B); break; 459 | case 0x11: RL(C); break; 460 | case 0x12: RL(D); break; 461 | case 0x13: RL(E); break; 462 | case 0x14: RL(H); break; 463 | case 0x15: RL(L); break; 464 | case 0x16: RL(MEM(HL)); break; 465 | case 0x17: RL(A); break; 466 | case 0x18: RR(B); break; 467 | case 0x19: RR(C); break; 468 | case 0x1A: RR(D); break; 469 | case 0x1B: RR(E); break; 470 | case 0x1C: RR(H); break; 471 | case 0x1D: RR(L); break; 472 | case 0x1E: RR(MEM(HL)); break; 473 | case 0x1F: RR(A); break; 474 | 475 | case 0x20: SLA(B); break; 476 | case 0x21: SLA(C); break; 477 | case 0x22: SLA(D); break; 478 | case 0x23: SLA(E); break; 479 | case 0x24: SLA(H); break; 480 | case 0x25: SLA(L); break; 481 | case 0x26: SLA(MEM(HL)); break; 482 | case 0x27: SLA(A); break; 483 | case 0x28: SRA(B); break; 484 | case 0x29: SRA(C); break; 485 | case 0x2A: SRA(D); break; 486 | case 0x2B: SRA(E); break; 487 | case 0x2C: SRA(H); break; 488 | case 0x2D: SRA(L); break; 489 | case 0x2E: SRA(MEM(HL)); break; 490 | case 0x2F: SRA(A); break; 491 | 492 | case 0x30: SWAP(B); break; 493 | case 0x31: SWAP(C); break; 494 | case 0x32: SWAP(D); break; 495 | case 0x33: SWAP(E); break; 496 | case 0x34: SWAP(H); break; 497 | case 0x35: SWAP(L); break; 498 | case 0x36: SWAP(MEM(HL)); break; 499 | case 0x37: SWAP(A); break; 500 | case 0x38: SRL(B); break; 501 | case 0x39: SRL(C); break; 502 | case 0x3A: SRL(D); break; 503 | case 0x3B: SRL(E); break; 504 | case 0x3C: SRL(H); break; 505 | case 0x3D: SRL(L); break; 506 | case 0x3E: SRL(MEM(HL)); break; 507 | case 0x3F: SRL(A); break; 508 | 509 | // BIT 510 | 511 | case 0x40: case 0x48: case 0x50: case 0x58: 512 | case 0x60: case 0x68: case 0x70: case 0x78: 513 | BIT((op&0x3F)>>3,B); break; 514 | 515 | case 0x41: case 0x49: case 0x51: case 0x59: 516 | case 0x61: case 0x69: case 0x71: case 0x79: 517 | BIT((op&0x3F)>>3,C); break; 518 | 519 | case 0x42: case 0x4A: case 0x52: case 0x5A: 520 | case 0x62: case 0x6A: case 0x72: case 0x7A: 521 | BIT((op&0x3F)>>3,D); break; 522 | 523 | case 0x43: case 0x4B: case 0x53: case 0x5B: 524 | case 0x63: case 0x6B: case 0x73: case 0x7B: 525 | BIT((op&0x3F)>>3,E); break; 526 | 527 | case 0x44: case 0x4C: case 0x54: case 0x5C: 528 | case 0x64: case 0x6C: case 0x74: case 0x7C: 529 | BIT((op&0x3F)>>3,H); break; 530 | 531 | case 0x45: case 0x4D: case 0x55: case 0x5D: 532 | case 0x65: case 0x6D: case 0x75: case 0x7D: 533 | BIT((op&0x3F)>>3,L); break; 534 | 535 | case 0x46: case 0x4E: case 0x56: case 0x5E: 536 | case 0x66: case 0x6E: case 0x76: case 0x7E: 537 | BIT((op&0x3F)>>3,MEM(HL)); break; 538 | 539 | case 0x47: case 0x4F: case 0x57: case 0x5F: 540 | case 0x67: case 0x6F: case 0x77: case 0x7F: 541 | BIT((op&0x3F)>>3,A); break; 542 | 543 | // RES 544 | 545 | case 0x80: case 0x88: case 0x90: case 0x98: 546 | case 0xA0: case 0xA8: case 0xB0: case 0xB8: 547 | RES((op&0x3F)>>3,B); break; 548 | 549 | case 0x81: case 0x89: case 0x91: case 0x99: 550 | case 0xA1: case 0xA9: case 0xB1: case 0xB9: 551 | RES((op&0x3F)>>3,C); break; 552 | 553 | case 0x82: case 0x8A: case 0x92: case 0x9A: 554 | case 0xA2: case 0xAA: case 0xB2: case 0xBA: 555 | RES((op&0x3F)>>3,D); break; 556 | 557 | case 0x83: case 0x8B: case 0x93: case 0x9B: 558 | case 0xA3: case 0xAB: case 0xB3: case 0xBB: 559 | RES((op&0x3F)>>3,E); break; 560 | 561 | case 0x84: case 0x8C: case 0x94: case 0x9C: 562 | case 0xA4: case 0xAC: case 0xB4: case 0xBC: 563 | RES((op&0x3F)>>3,H); break; 564 | 565 | case 0x85: case 0x8D: case 0x95: case 0x9D: 566 | case 0xA5: case 0xAD: case 0xB5: case 0xBD: 567 | RES((op&0x3F)>>3,L); break; 568 | 569 | case 0x86: case 0x8E: case 0x96: case 0x9E: 570 | case 0xA6: case 0xAE: case 0xB6: case 0xBE: 571 | RES((op&0x3F)>>3,MEM(HL)); break; 572 | 573 | case 0x87: case 0x8F: case 0x97: case 0x9F: 574 | case 0xA7: case 0xAF: case 0xB7: case 0xBF: 575 | RES((op&0x3F)>>3,A); break; 576 | 577 | // SET 578 | 579 | case 0xC0: case 0xC8: case 0xD0: case 0xD8: 580 | case 0xE0: case 0xE8: case 0xF0: case 0xF8: 581 | SET((op&0x3F)>>3,B); break; 582 | 583 | case 0xC1: case 0xC9: case 0xD1: case 0xD9: 584 | case 0xE1: case 0xE9: case 0xF1: case 0xF9: 585 | SET((op&0x3F)>>3,C); break; 586 | 587 | case 0xC2: case 0xCA: case 0xD2: case 0xDA: 588 | case 0xE2: case 0xEA: case 0xF2: case 0xFA: 589 | SET((op&0x3F)>>3,D); break; 590 | 591 | case 0xC3: case 0xCB: case 0xD3: case 0xDB: 592 | case 0xE3: case 0xEB: case 0xF3: case 0xFB: 593 | SET((op&0x3F)>>3,E); break; 594 | 595 | case 0xC4: case 0xCC: case 0xD4: case 0xDC: 596 | case 0xE4: case 0xEC: case 0xF4: case 0xFC: 597 | SET((op&0x3F)>>3,H); break; 598 | 599 | case 0xC5: case 0xCD: case 0xD5: case 0xDD: 600 | case 0xE5: case 0xED: case 0xF5: case 0xFD: 601 | SET((op&0x3F)>>3,L); break; 602 | 603 | case 0xC6: case 0xCE: case 0xD6: case 0xDE: 604 | case 0xE6: case 0xEE: case 0xF6: case 0xFE: 605 | SET((op&0x3F)>>3,MEM(HL)); break; 606 | 607 | case 0xC7: case 0xCF: case 0xD7: case 0xDF: 608 | case 0xE7: case 0xEF: case 0xF7: case 0xFF: 609 | SET((op&0x3F)>>3,A); break; 610 | 611 | default: 612 | sprintf(errorcode,"Error: Unknown extended opcode $%02X at $%04X\n",op,PC-1); 613 | printf("Error: Unknown extended opcode $%02X at $%04X\n",op,PC-1); 614 | return -1; 615 | } 616 | return 1; 617 | } 618 | -------------------------------------------------------------------------------- /src/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by GBSImportW.rc 4 | // 5 | #define ID_SEPARATOR 0 6 | #define VS_VERSION_INFO 1 7 | #define AFX_IDC_LISTBOX 100 8 | #define AFX_IDC_CHANGE 101 9 | #define IDD_DIALOG1 101 10 | #define AFX_IDC_BROWSER 102 11 | #define AFX_IDC_PRINT_DOCNAME 201 12 | #define AFX_IDC_PRINT_PRINTERNAME 202 13 | #define AFX_IDC_PRINT_PORTNAME 203 14 | #define AFX_IDC_PRINT_PAGENUM 204 15 | #define ID_MFCLOC_MANIFEST 1000 16 | #define AFX_IDC_FONTPROP 1000 17 | #define AFX_IDC_FONTNAMES 1001 18 | #define AFX_IDC_FONTSTYLES 1002 19 | #define AFX_IDC_FONTSIZES 1003 20 | #define AFX_IDC_STRIKEOUT 1004 21 | #define AFX_IDC_UNDERLINE 1005 22 | #define AFX_IDC_SAMPLEBOX 1006 23 | #define AFX_IDC_COLOR_BLACK 1100 24 | #define AFX_IDC_COLOR_WHITE 1101 25 | #define AFX_IDC_COLOR_RED 1102 26 | #define AFX_IDC_COLOR_GREEN 1103 27 | #define AFX_IDC_COLOR_BLUE 1104 28 | #define AFX_IDC_COLOR_YELLOW 1105 29 | #define AFX_IDC_COLOR_MAGENTA 1106 30 | #define AFX_IDC_COLOR_CYAN 1107 31 | #define AFX_IDC_COLOR_GRAY 1108 32 | #define AFX_IDC_COLOR_LIGHTGRAY 1109 33 | #define AFX_IDC_COLOR_DARKRED 1110 34 | #define AFX_IDC_COLOR_DARKGREEN 1111 35 | #define AFX_IDC_COLOR_DARKBLUE 1112 36 | #define AFX_IDC_COLOR_LIGHTBROWN 1113 37 | #define AFX_IDC_COLOR_DARKMAGENTA 1114 38 | #define AFX_IDC_COLOR_DARKCYAN 1115 39 | #define AFX_IDC_COLORPROP 1116 40 | #define AFX_IDC_SYSTEMCOLORS 1117 41 | #define AFX_IDC_PROPNAME 1201 42 | #define AFX_IDC_PICTURE 1202 43 | #define AFX_IDC_BROWSE 1203 44 | #define AFX_IDC_CLEAR 1204 45 | 46 | ///////////////////////////////////////////////////////////////////////////// 47 | // Import dialog resources 48 | 49 | #define IDD_DIALOG_NSF_IMPORT 288 50 | 51 | #define IDC_SECONDS 1156 52 | #define IDC_PATTERN 1157 53 | #define IDC_ROW 1158 54 | #define IDC_FILENAME 1218 55 | #define IDC_FONT_SIZE 1219 56 | #define IDC_NSFINFO1 1219 57 | #define IDC_COPY_WAVE 1220 58 | #define IDC_NSFINFO2 1220 59 | #define IDC_PASTE_WAVE 1221 60 | #define IDC_NSFINFO3 1221 61 | #define IDC_COPY_TABLE 1222 62 | #define IDC_AVAILABLE_TREE 1222 63 | #define IDC_PASTE_TABLE 1223 64 | #define IDC_TRACK 1223 65 | #define IDC_TRACKCOUNT 1224 66 | #define IDC_COPY 1225 67 | #define IDC_DEBUGWAV 1225 68 | #define IDC_PROGRESSINFO 1226 69 | #define IDC_ALLTRACKS 1227 70 | #define IDC_NOSILENCE 1228 71 | 72 | 73 | ///////////////////////////////////////////////////////////////////////////// 74 | 75 | #define AFX_IDC_TAB_CONTROL 0x3020 76 | #define ID_APPLY_NOW 0x3021 77 | #define ID_WIZBACK 0x3023 78 | #define ID_WIZNEXT 0x3024 79 | #define ID_WIZFINISH 0x3025 80 | #define AFX_IDD_NEWTYPEDLG 30721 81 | #define AFX_IDD_PRINTDLG 30722 82 | #define AFX_IDD_PREVIEW_TOOLBAR 30723 83 | #define AFX_IDD_INSERTOBJECT 30724 84 | #define AFX_IDD_CHANGEICON 30725 85 | #define AFX_IDD_CONVERT 30726 86 | #define AFX_IDD_PASTESPECIAL 30727 87 | #define AFX_IDD_EDITLINKS 30728 88 | #define AFX_IDD_FILEBROWSE 30729 89 | #define AFX_IDD_BUSY 30730 90 | #define AFX_IDD_OBJECTPROPERTIES 30732 91 | #define AFX_IDD_CHANGESOURCE 30733 92 | #define AFX_IDD_EMPTYDIALOG 30734 93 | #define AFX_IDC_CONTEXTHELP 30977 94 | #define AFX_IDC_MAGNIFY 30978 95 | #define AFX_IDC_SMALLARROWS 30979 96 | #define AFX_IDC_HSPLITBAR 30980 97 | #define AFX_IDC_VSPLITBAR 30981 98 | #define AFX_IDC_NODROPCRSR 30982 99 | #define AFX_IDC_TRACKNWSE 30983 100 | #define AFX_IDC_TRACKNESW 30984 101 | #define AFX_IDC_TRACKNS 30985 102 | #define AFX_IDC_TRACKWE 30986 103 | #define AFX_IDC_TRACK4WAY 30987 104 | #define AFX_IDC_MOVE4WAY 30988 105 | #define AFX_IDB_MINIFRAME_MENU 30994 106 | #define AFX_IDB_CHECKLISTBOX_95 30996 107 | #define AFX_IDR_PREVIEW_ACCEL 30997 108 | #define AFX_IDC_MOUSE_PAN_NW 30998 109 | #define AFX_IDC_MOUSE_PAN_N 30999 110 | #define AFX_IDC_MOUSE_PAN_NE 31000 111 | #define AFX_IDC_MOUSE_PAN_W 31001 112 | #define AFX_IDC_MOUSE_PAN_HV 31002 113 | #define AFX_IDC_MOUSE_PAN_E 31003 114 | #define AFX_IDC_MOUSE_PAN_SW 31004 115 | #define AFX_IDC_MOUSE_PAN_S 31005 116 | #define AFX_IDC_MOUSE_PAN_SE 31006 117 | #define AFX_IDC_MOUSE_PAN_HORZ 31007 118 | #define AFX_IDC_MOUSE_PAN_VERT 31008 119 | #define AFX_IDC_MOUSE_ORG_HORZ 31009 120 | #define AFX_IDC_MOUSE_ORG_VERT 31010 121 | #define AFX_IDC_MOUSE_ORG_HV 31011 122 | #define AFX_IDC_MOUSE_MASK 31012 123 | #define AFX_IDI_STD_MDIFRAME 31233 124 | #define AFX_IDI_STD_FRAME 31234 125 | #define AFX_IDD_PROPPAGE_COLOR 32257 126 | #define AFX_IDD_PROPPAGE_FONT 32258 127 | #define AFX_IDD_PROPPAGE_PICTURE 32259 128 | #define AFX_IDB_TRUETYPE 32384 129 | #define IDM_APP_ABOUT 40001 130 | #define AFX_IDS_APP_TITLE 0xE000 131 | #define AFX_IDS_IDLEMESSAGE 0xE001 132 | #define AFX_IDS_HELPMODEMESSAGE 0xE002 133 | #define AFX_IDS_APP_TITLE_EMBEDDING 0xE003 134 | #define AFX_IDS_COMPANY_NAME 0xE004 135 | #define AFX_IDS_OBJ_TITLE_INPLACE 0xE005 136 | #define ID_FILE_NEW 0xE100 137 | #define ID_FILE_OPEN 0xE101 138 | #define ID_FILE_CLOSE 0xE102 139 | #define ID_FILE_SAVE 0xE103 140 | #define ID_FILE_SAVE_AS 0xE104 141 | #define ID_FILE_PAGE_SETUP 0xE105 142 | #define ID_FILE_PRINT_SETUP 0xE106 143 | #define ID_FILE_PRINT 0xE107 144 | #define ID_FILE_PRINT_DIRECT 0xE108 145 | #define ID_FILE_PRINT_PREVIEW 0xE109 146 | #define ID_FILE_UPDATE 0xE10A 147 | #define ID_FILE_SAVE_COPY_AS 0xE10B 148 | #define ID_FILE_SEND_MAIL 0xE10C 149 | #define ID_FILE_NEW_FRAME 0xE10D 150 | #define ID_FILE_MRU_FIRST 0xE110 151 | #define ID_FILE_MRU_FILE1 0xE110 152 | #define ID_FILE_MRU_FILE2 0xE111 153 | #define ID_FILE_MRU_FILE3 0xE112 154 | #define ID_FILE_MRU_FILE4 0xE113 155 | #define ID_FILE_MRU_FILE5 0xE114 156 | #define ID_FILE_MRU_FILE6 0xE115 157 | #define ID_FILE_MRU_FILE7 0xE116 158 | #define ID_FILE_MRU_FILE8 0xE117 159 | #define ID_FILE_MRU_FILE9 0xE118 160 | #define ID_FILE_MRU_FILE10 0xE119 161 | #define ID_FILE_MRU_FILE11 0xE11A 162 | #define ID_FILE_MRU_FILE12 0xE11B 163 | #define ID_FILE_MRU_FILE13 0xE11C 164 | #define ID_FILE_MRU_FILE14 0xE11D 165 | #define ID_FILE_MRU_FILE15 0xE11E 166 | #define ID_FILE_MRU_FILE16 0xE11F 167 | #define ID_FILE_MRU_LAST 0xE11F 168 | #define ID_EDIT_CLEAR 0xE120 169 | #define ID_EDIT_CLEAR_ALL 0xE121 170 | #define ID_EDIT_COPY 0xE122 171 | #define ID_EDIT_CUT 0xE123 172 | #define ID_EDIT_FIND 0xE124 173 | #define ID_EDIT_PASTE 0xE125 174 | #define ID_EDIT_PASTE_LINK 0xE126 175 | #define ID_EDIT_PASTE_SPECIAL 0xE127 176 | #define ID_EDIT_REPEAT 0xE128 177 | #define ID_EDIT_REPLACE 0xE129 178 | #define ID_EDIT_SELECT_ALL 0xE12A 179 | #define ID_EDIT_UNDO 0xE12B 180 | #define ID_EDIT_REDO 0xE12C 181 | #define ID_WINDOW_NEW 0xE130 182 | #define ID_WINDOW_ARRANGE 0xE131 183 | #define ID_WINDOW_CASCADE 0xE132 184 | #define ID_WINDOW_TILE_HORZ 0xE133 185 | #define ID_WINDOW_TILE_VERT 0xE134 186 | #define ID_WINDOW_SPLIT 0xE135 187 | #define ID_APP_ABOUT 0xE140 188 | #define ID_APP_EXIT 0xE141 189 | #define ID_HELP_INDEX 0xE142 190 | #define ID_HELP_FINDER 0xE143 191 | #define ID_HELP_USING 0xE144 192 | #define ID_CONTEXT_HELP 0xE145 193 | #define ID_HELP 0xE146 194 | #define ID_DEFAULT_HELP 0xE147 195 | #define ID_NEXT_PANE 0xE150 196 | #define ID_PREV_PANE 0xE151 197 | #define ID_FORMAT_FONT 0xE160 198 | #define ID_OLE_INSERT_NEW 0xE200 199 | #define ID_OLE_EDIT_LINKS 0xE201 200 | #define ID_OLE_EDIT_CONVERT 0xE202 201 | #define ID_OLE_EDIT_CHANGE_ICON 0xE203 202 | #define ID_OLE_EDIT_PROPERTIES 0xE204 203 | #define ID_OLE_VERB_FIRST 0xE210 204 | #define AFX_ID_PREVIEW_CLOSE 0xE300 205 | #define AFX_ID_PREVIEW_NUMPAGE 0xE301 206 | #define AFX_ID_PREVIEW_NEXT 0xE302 207 | #define AFX_ID_PREVIEW_PREV 0xE303 208 | #define AFX_ID_PREVIEW_PRINT 0xE304 209 | #define AFX_ID_PREVIEW_ZOOMIN 0xE305 210 | #define AFX_ID_PREVIEW_ZOOMOUT 0xE306 211 | #define ID_INDICATOR_EXT 0xE700 212 | #define ID_INDICATOR_CAPS 0xE701 213 | #define ID_INDICATOR_NUM 0xE702 214 | #define ID_INDICATOR_SCRL 0xE703 215 | #define ID_INDICATOR_OVR 0xE704 216 | #define ID_INDICATOR_REC 0xE705 217 | #define ID_INDICATOR_KANA 0xE706 218 | #define ID_VIEW_TOOLBAR 0xE800 219 | #define ID_VIEW_STATUS_BAR 0xE801 220 | #define ID_VIEW_REBAR 0xE804 221 | #define ID_VIEW_AUTOARRANGE 0xE805 222 | #define ID_VIEW_SMALLICON 0xE810 223 | #define ID_VIEW_LARGEICON 0xE811 224 | #define ID_VIEW_LIST 0xE812 225 | #define ID_VIEW_DETAILS 0xE813 226 | #define ID_VIEW_LINEUP 0xE814 227 | #define ID_VIEW_BYNAME 0xE815 228 | #define ID_RECORD_FIRST 0xE900 229 | #define ID_RECORD_LAST 0xE901 230 | #define ID_RECORD_NEXT 0xE902 231 | #define ID_RECORD_PREV 0xE903 232 | #define AFX_IDS_SCSIZE 0xEF00 233 | #define AFX_IDS_SCMOVE 0xEF01 234 | #define AFX_IDS_SCMINIMIZE 0xEF02 235 | #define AFX_IDS_SCMAXIMIZE 0xEF03 236 | #define AFX_IDS_SCNEXTWINDOW 0xEF04 237 | #define AFX_IDS_SCPREVWINDOW 0xEF05 238 | #define AFX_IDS_SCCLOSE 0xEF06 239 | #define AFX_IDS_SCRESTORE 0xEF12 240 | #define AFX_IDS_SCTASKLIST 0xEF13 241 | #define AFX_IDS_MDICHILD 0xEF1F 242 | #define AFX_IDS_DESKACCESSORY 0xEFDA 243 | #define AFX_IDS_OPENFILE 0xF000 244 | #define AFX_IDS_SAVEFILE 0xF001 245 | #define AFX_IDS_ALLFILTER 0xF002 246 | #define AFX_IDS_UNTITLED 0xF003 247 | #define AFX_IDS_SAVEFILECOPY 0xF004 248 | #define AFX_IDS_PREVIEW_CLOSE 0xF005 249 | #define AFX_IDS_UNNAMED_FILE 0xF006 250 | #define AFX_IDS_HIDE 0xF011 251 | #define AFX_IDP_NO_ERROR_AVAILABLE 0xF020 252 | #define AFX_IDS_NOT_SUPPORTED_EXCEPTION 0xF021 253 | #define AFX_IDS_RESOURCE_EXCEPTION 0xF022 254 | #define AFX_IDS_MEMORY_EXCEPTION 0xF023 255 | #define AFX_IDS_USER_EXCEPTION 0xF024 256 | #define AFX_IDS_INVALID_ARG_EXCEPTION 0xF025 257 | #define AFX_IDS_PRINTONPORT 0xF040 258 | #define AFX_IDS_ONEPAGE 0xF041 259 | #define AFX_IDS_TWOPAGE 0xF042 260 | #define AFX_IDS_PRINTPAGENUM 0xF043 261 | #define AFX_IDS_PREVIEWPAGEDESC 0xF044 262 | #define AFX_IDS_PRINTDEFAULTEXT 0xF045 263 | #define AFX_IDS_PRINTDEFAULT 0xF046 264 | #define AFX_IDS_PRINTFILTER 0xF047 265 | #define AFX_IDS_PRINTCAPTION 0xF048 266 | #define AFX_IDS_PRINTTOFILE 0xF049 267 | #define AFX_IDS_OBJECT_MENUITEM 0xF080 268 | #define AFX_IDS_EDIT_VERB 0xF081 269 | #define AFX_IDS_ACTIVATE_VERB 0xF082 270 | #define AFX_IDS_CHANGE_LINK 0xF083 271 | #define AFX_IDS_AUTO 0xF084 272 | #define AFX_IDS_MANUAL 0xF085 273 | #define AFX_IDS_FROZEN 0xF086 274 | #define AFX_IDS_ALL_FILES 0xF087 275 | #define AFX_IDS_SAVE_MENU 0xF088 276 | #define AFX_IDS_UPDATE_MENU 0xF089 277 | #define AFX_IDS_SAVE_AS_MENU 0xF08A 278 | #define AFX_IDS_SAVE_COPY_AS_MENU 0xF08B 279 | #define AFX_IDS_EXIT_MENU 0xF08C 280 | #define AFX_IDS_UPDATING_ITEMS 0xF08D 281 | #define AFX_IDS_METAFILE_FORMAT 0xF08E 282 | #define AFX_IDS_DIB_FORMAT 0xF08F 283 | #define AFX_IDS_BITMAP_FORMAT 0xF090 284 | #define AFX_IDS_LINKSOURCE_FORMAT 0xF091 285 | #define AFX_IDS_EMBED_FORMAT 0xF092 286 | #define AFX_IDS_PASTELINKEDTYPE 0xF094 287 | #define AFX_IDS_UNKNOWNTYPE 0xF095 288 | #define AFX_IDS_RTF_FORMAT 0xF096 289 | #define AFX_IDS_TEXT_FORMAT 0xF097 290 | #define AFX_IDS_INVALID_CURRENCY 0xF098 291 | #define AFX_IDS_INVALID_DATETIME 0xF099 292 | #define AFX_IDS_INVALID_DATETIMESPAN 0xF09A 293 | #define AFX_IDP_INVALID_FILENAME 0xF100 294 | #define AFX_IDP_FAILED_TO_OPEN_DOC 0xF101 295 | #define AFX_IDP_FAILED_TO_SAVE_DOC 0xF102 296 | #define AFX_IDP_ASK_TO_SAVE 0xF103 297 | #define AFX_IDP_FAILED_TO_CREATE_DOC 0xF104 298 | #define AFX_IDP_FILE_TOO_LARGE 0xF105 299 | #define AFX_IDP_FAILED_TO_START_PRINT 0xF106 300 | #define AFX_IDP_FAILED_TO_LAUNCH_HELP 0xF107 301 | #define AFX_IDP_INTERNAL_FAILURE 0xF108 302 | #define AFX_IDP_COMMAND_FAILURE 0xF109 303 | #define AFX_IDP_FAILED_MEMORY_ALLOC 0xF10A 304 | #define AFX_IDP_UNREG_DONE 0xF10B 305 | #define AFX_IDP_UNREG_FAILURE 0xF10C 306 | #define AFX_IDP_DLL_LOAD_FAILED 0xF10D 307 | #define AFX_IDP_DLL_BAD_VERSION 0xF10E 308 | #define AFX_IDP_PARSE_INT 0xF110 309 | #define AFX_IDP_PARSE_REAL 0xF111 310 | #define AFX_IDP_PARSE_INT_RANGE 0xF112 311 | #define AFX_IDP_PARSE_REAL_RANGE 0xF113 312 | #define AFX_IDP_PARSE_STRING_SIZE 0xF114 313 | #define AFX_IDP_PARSE_RADIO_BUTTON 0xF115 314 | #define AFX_IDP_PARSE_BYTE 0xF116 315 | #define AFX_IDP_PARSE_UINT 0xF117 316 | #define AFX_IDP_PARSE_DATETIME 0xF118 317 | #define AFX_IDP_PARSE_CURRENCY 0xF119 318 | #define AFX_IDP_PARSE_GUID 0xF11A 319 | #define AFX_IDP_PARSE_TIME 0xF11B 320 | #define AFX_IDP_PARSE_DATE 0xF11C 321 | #define AFX_IDP_FAILED_INVALID_FORMAT 0xF120 322 | #define AFX_IDP_FAILED_INVALID_PATH 0xF121 323 | #define AFX_IDP_FAILED_DISK_FULL 0xF122 324 | #define AFX_IDP_FAILED_ACCESS_READ 0xF123 325 | #define AFX_IDP_FAILED_ACCESS_WRITE 0xF124 326 | #define AFX_IDP_FAILED_IO_ERROR_READ 0xF125 327 | #define AFX_IDP_FAILED_IO_ERROR_WRITE 0xF126 328 | #define AFX_IDP_SCRIPT_ERROR 0xF130 329 | #define AFX_IDP_SCRIPT_DISPATCH_EXCEPTION 0xF131 330 | #define AFX_IDP_STATIC_OBJECT 0xF180 331 | #define AFX_IDP_FAILED_TO_CONNECT 0xF181 332 | #define AFX_IDP_SERVER_BUSY 0xF182 333 | #define AFX_IDP_BAD_VERB 0xF183 334 | #define AFX_IDS_NOT_DOCOBJECT 0xF184 335 | #define AFX_IDP_FAILED_TO_NOTIFY 0xF185 336 | #define AFX_IDP_FAILED_TO_LAUNCH 0xF186 337 | #define AFX_IDP_ASK_TO_UPDATE 0xF187 338 | #define AFX_IDP_FAILED_TO_UPDATE 0xF188 339 | #define AFX_IDP_FAILED_TO_REGISTER 0xF189 340 | #define AFX_IDP_FAILED_TO_AUTO_REGISTER 0xF18A 341 | #define AFX_IDP_FAILED_TO_CONVERT 0xF18B 342 | #define AFX_IDP_GET_NOT_SUPPORTED 0xF18C 343 | #define AFX_IDP_SET_NOT_SUPPORTED 0xF18D 344 | #define AFX_IDP_ASK_TO_DISCARD 0xF18E 345 | #define AFX_IDP_FAILED_TO_CREATE 0xF18F 346 | #define AFX_IDP_FAILED_MAPI_LOAD 0xF190 347 | #define AFX_IDP_INVALID_MAPI_DLL 0xF191 348 | #define AFX_IDP_FAILED_MAPI_SEND 0xF192 349 | #define AFX_IDP_FILE_NONE 0xF1A0 350 | #define AFX_IDP_FILE_GENERIC 0xF1A1 351 | #define AFX_IDP_FILE_NOT_FOUND 0xF1A2 352 | #define AFX_IDP_FILE_BAD_PATH 0xF1A3 353 | #define AFX_IDP_FILE_TOO_MANY_OPEN 0xF1A4 354 | #define AFX_IDP_FILE_ACCESS_DENIED 0xF1A5 355 | #define AFX_IDP_FILE_INVALID_FILE 0xF1A6 356 | #define AFX_IDP_FILE_REMOVE_CURRENT 0xF1A7 357 | #define AFX_IDP_FILE_DIR_FULL 0xF1A8 358 | #define AFX_IDP_FILE_BAD_SEEK 0xF1A9 359 | #define AFX_IDP_FILE_HARD_IO 0xF1AA 360 | #define AFX_IDP_FILE_SHARING 0xF1AB 361 | #define AFX_IDP_FILE_LOCKING 0xF1AC 362 | #define AFX_IDP_FILE_DISKFULL 0xF1AD 363 | #define AFX_IDP_FILE_EOF 0xF1AE 364 | #define AFX_IDP_ARCH_NONE 0xF1B0 365 | #define AFX_IDP_ARCH_GENERIC 0xF1B1 366 | #define AFX_IDP_ARCH_READONLY 0xF1B2 367 | #define AFX_IDP_ARCH_ENDOFFILE 0xF1B3 368 | #define AFX_IDP_ARCH_WRITEONLY 0xF1B4 369 | #define AFX_IDP_ARCH_BADINDEX 0xF1B5 370 | #define AFX_IDP_ARCH_BADCLASS 0xF1B6 371 | #define AFX_IDP_ARCH_BADSCHEMA 0xF1B7 372 | #define AFX_IDS_OCC_SCALEUNITS_PIXELS 0xF1C0 373 | #define AFX_IDS_STATUS_FONT 0xF230 374 | #define AFX_IDS_TOOLTIP_FONT 0xF231 375 | #define AFX_IDS_UNICODE_FONT 0xF232 376 | #define AFX_IDS_MINI_FONT 0xF233 377 | #define AFX_IDP_SQL_CONNECT_FAIL 0xF281 378 | #define AFX_IDP_SQL_RECORDSET_FORWARD_ONLY 0xF282 379 | #define AFX_IDP_SQL_EMPTY_COLUMN_LIST 0xF283 380 | #define AFX_IDP_SQL_FIELD_SCHEMA_MISMATCH 0xF284 381 | #define AFX_IDP_SQL_ILLEGAL_MODE 0xF285 382 | #define AFX_IDP_SQL_MULTIPLE_ROWS_AFFECTED 0xF286 383 | #define AFX_IDP_SQL_NO_CURRENT_RECORD 0xF287 384 | #define AFX_IDP_SQL_NO_ROWS_AFFECTED 0xF288 385 | #define AFX_IDP_SQL_RECORDSET_READONLY 0xF289 386 | #define AFX_IDP_SQL_SQL_NO_TOTAL 0xF28A 387 | #define AFX_IDP_SQL_ODBC_LOAD_FAILED 0xF28B 388 | #define AFX_IDP_SQL_DYNASET_NOT_SUPPORTED 0xF28C 389 | #define AFX_IDP_SQL_SNAPSHOT_NOT_SUPPORTED 0xF28D 390 | #define AFX_IDP_SQL_API_CONFORMANCE 0xF28E 391 | #define AFX_IDP_SQL_SQL_CONFORMANCE 0xF28F 392 | #define AFX_IDP_SQL_NO_DATA_FOUND 0xF290 393 | #define AFX_IDP_SQL_ROW_UPDATE_NOT_SUPPORTED 0xF291 394 | #define AFX_IDP_SQL_ODBC_V2_REQUIRED 0xF292 395 | #define AFX_IDP_SQL_NO_POSITIONED_UPDATES 0xF293 396 | #define AFX_IDP_SQL_LOCK_MODE_NOT_SUPPORTED 0xF294 397 | #define AFX_IDP_SQL_DATA_TRUNCATED 0xF295 398 | #define AFX_IDP_SQL_ROW_FETCH 0xF296 399 | #define AFX_IDP_SQL_INCORRECT_ODBC 0xF297 400 | #define AFX_IDP_SQL_UPDATE_DELETE_FAILED 0xF298 401 | #define AFX_IDP_SQL_DYNAMIC_CURSOR_NOT_SUPPORTED 0xF299 402 | #define AFX_IDP_SQL_FIELD_NOT_FOUND 0xF29A 403 | #define AFX_IDP_SQL_BOOKMARKS_NOT_SUPPORTED 0xF29B 404 | #define AFX_IDP_SQL_BOOKMARKS_NOT_ENABLED 0xF29C 405 | #define AFX_IDS_DELETED 0xF29D 406 | #define AFX_IDP_DAO_ENGINE_INITIALIZATION 0xF2B0 407 | #define AFX_IDP_DAO_DFX_BIND 0xF2B1 408 | #define AFX_IDP_DAO_OBJECT_NOT_OPEN 0xF2B2 409 | #define AFX_IDP_DAO_ROWTOOSHORT 0xF2B3 410 | #define AFX_IDP_DAO_BADBINDINFO 0xF2B4 411 | #define AFX_IDP_DAO_COLUMNUNAVAILABLE 0xF2B5 412 | #define AFX_IDS_HTTP_TITLE 0xF2D1 413 | #define AFX_IDS_HTTP_NO_TEXT 0xF2D2 414 | #define AFX_IDS_HTTP_BAD_REQUEST 0xF2D3 415 | #define AFX_IDS_HTTP_AUTH_REQUIRED 0xF2D4 416 | #define AFX_IDS_HTTP_FORBIDDEN 0xF2D5 417 | #define AFX_IDS_HTTP_NOT_FOUND 0xF2D6 418 | #define AFX_IDS_HTTP_SERVER_ERROR 0xF2D7 419 | #define AFX_IDS_HTTP_NOT_IMPLEMENTED 0xF2D8 420 | #define AFX_IDS_CHECKLISTBOX_UNCHECK 0xF2E1 421 | #define AFX_IDS_CHECKLISTBOX_CHECK 0xF2E2 422 | #define AFX_IDS_CHECKLISTBOX_MIXED 0xF2E3 423 | #define AFX_IDS_PROPPAGE_UNKNOWN 0xFE01 424 | #define AFX_IDS_COLOR_DESKTOP 0xFE04 425 | #define AFX_IDS_COLOR_APPWORKSPACE 0xFE05 426 | #define AFX_IDS_COLOR_WNDBACKGND 0xFE06 427 | #define AFX_IDS_COLOR_WNDTEXT 0xFE07 428 | #define AFX_IDS_COLOR_MENUBAR 0xFE08 429 | #define AFX_IDS_COLOR_MENUTEXT 0xFE09 430 | #define AFX_IDS_COLOR_ACTIVEBAR 0xFE0A 431 | #define AFX_IDS_COLOR_INACTIVEBAR 0xFE0B 432 | #define AFX_IDS_COLOR_ACTIVETEXT 0xFE0C 433 | #define AFX_IDS_COLOR_INACTIVETEXT 0xFE0D 434 | #define AFX_IDS_COLOR_ACTIVEBORDER 0xFE0E 435 | #define AFX_IDS_COLOR_INACTIVEBORDER 0xFE0F 436 | #define AFX_IDS_COLOR_WNDFRAME 0xFE10 437 | #define AFX_IDS_COLOR_SCROLLBARS 0xFE11 438 | #define AFX_IDS_COLOR_BTNFACE 0xFE12 439 | #define AFX_IDS_COLOR_BTNSHADOW 0xFE13 440 | #define AFX_IDS_COLOR_BTNTEXT 0xFE14 441 | #define AFX_IDS_COLOR_BTNHIGHLIGHT 0xFE15 442 | #define AFX_IDS_COLOR_DISABLEDTEXT 0xFE16 443 | #define AFX_IDS_COLOR_HIGHLIGHT 0xFE17 444 | #define AFX_IDS_COLOR_HIGHLIGHTTEXT 0xFE18 445 | #define AFX_IDS_REGULAR 0xFE19 446 | #define AFX_IDS_BOLD 0xFE1A 447 | #define AFX_IDS_ITALIC 0xFE1B 448 | #define AFX_IDS_BOLDITALIC 0xFE1C 449 | #define AFX_IDS_SAMPLETEXT 0xFE1D 450 | #define AFX_IDS_DISPLAYSTRING_FONT 0xFE1E 451 | #define AFX_IDS_DISPLAYSTRING_COLOR 0xFE1F 452 | #define AFX_IDS_DISPLAYSTRING_PICTURE 0xFE20 453 | #define AFX_IDS_PICTUREFILTER 0xFE21 454 | #define AFX_IDS_PICTYPE_UNKNOWN 0xFE22 455 | #define AFX_IDS_PICTYPE_NONE 0xFE23 456 | #define AFX_IDS_PICTYPE_BITMAP 0xFE24 457 | #define AFX_IDS_PICTYPE_METAFILE 0xFE25 458 | #define AFX_IDS_PICTYPE_ICON 0xFE26 459 | #define AFX_IDS_COLOR_PPG 0xFE28 460 | #define AFX_IDS_COLOR_PPG_CAPTION 0xFE29 461 | #define AFX_IDS_FONT_PPG 0xFE2A 462 | #define AFX_IDS_FONT_PPG_CAPTION 0xFE2B 463 | #define AFX_IDS_PICTURE_PPG 0xFE2C 464 | #define AFX_IDS_PICTURE_PPG_CAPTION 0xFE2D 465 | #define AFX_IDS_PICTUREBROWSETITLE 0xFE30 466 | #define AFX_IDS_BORDERSTYLE_0 0xFE31 467 | #define AFX_IDS_BORDERSTYLE_1 0xFE32 468 | #define AFX_IDS_VERB_EDIT 0xFE40 469 | #define AFX_IDS_VERB_PROPERTIES 0xFE41 470 | #define AFX_IDP_PICTURECANTOPEN 0xFE83 471 | #define AFX_IDP_PICTURECANTLOAD 0xFE84 472 | #define AFX_IDP_PICTURETOOLARGE 0xFE85 473 | #define AFX_IDP_PICTUREREADFAILED 0xFE86 474 | #define AFX_IDP_E_ILLEGALFUNCTIONCALL 0xFEA0 475 | #define AFX_IDP_E_OVERFLOW 0xFEA1 476 | #define AFX_IDP_E_OUTOFMEMORY 0xFEA2 477 | #define AFX_IDP_E_DIVISIONBYZERO 0xFEA3 478 | #define AFX_IDP_E_OUTOFSTRINGSPACE 0xFEA4 479 | #define AFX_IDP_E_OUTOFSTACKSPACE 0xFEA5 480 | #define AFX_IDP_E_BADFILENAMEORNUMBER 0xFEA6 481 | #define AFX_IDP_E_FILENOTFOUND 0xFEA7 482 | #define AFX_IDP_E_BADFILEMODE 0xFEA8 483 | #define AFX_IDP_E_FILEALREADYOPEN 0xFEA9 484 | #define AFX_IDP_E_DEVICEIOERROR 0xFEAA 485 | #define AFX_IDP_E_FILEALREADYEXISTS 0xFEAB 486 | #define AFX_IDP_E_BADRECORDLENGTH 0xFEAC 487 | #define AFX_IDP_E_DISKFULL 0xFEAD 488 | #define AFX_IDP_E_BADRECORDNUMBER 0xFEAE 489 | #define AFX_IDP_E_BADFILENAME 0xFEAF 490 | #define AFX_IDP_E_TOOMANYFILES 0xFEB0 491 | #define AFX_IDP_E_DEVICEUNAVAILABLE 0xFEB1 492 | #define AFX_IDP_E_PERMISSIONDENIED 0xFEB2 493 | #define AFX_IDP_E_DISKNOTREADY 0xFEB3 494 | #define AFX_IDP_E_PATHFILEACCESSERROR 0xFEB4 495 | #define AFX_IDP_E_PATHNOTFOUND 0xFEB5 496 | #define AFX_IDP_E_INVALIDPATTERNSTRING 0xFEB6 497 | #define AFX_IDP_E_INVALIDUSEOFNULL 0xFEB7 498 | #define AFX_IDP_E_INVALIDFILEFORMAT 0xFEB8 499 | #define AFX_IDP_E_INVALIDPROPERTYVALUE 0xFEB9 500 | #define AFX_IDP_E_INVALIDPROPERTYARRAYINDEX 0xFEBA 501 | #define AFX_IDP_E_SETNOTSUPPORTEDATRUNTIME 0xFEBB 502 | #define AFX_IDP_E_SETNOTSUPPORTED 0xFEBC 503 | #define AFX_IDP_E_NEEDPROPERTYARRAYINDEX 0xFEBD 504 | #define AFX_IDP_E_SETNOTPERMITTED 0xFEBE 505 | #define AFX_IDP_E_GETNOTSUPPORTEDATRUNTIME 0xFEBF 506 | #define AFX_IDP_E_GETNOTSUPPORTED 0xFEC0 507 | #define AFX_IDP_E_PROPERTYNOTFOUND 0xFEC1 508 | #define AFX_IDP_E_INVALIDCLIPBOARDFORMAT 0xFEC2 509 | #define AFX_IDP_E_INVALIDPICTURE 0xFEC3 510 | #define AFX_IDP_E_PRINTERERROR 0xFEC4 511 | #define AFX_IDP_E_CANTSAVEFILETOTEMP 0xFEC5 512 | #define AFX_IDP_E_SEARCHTEXTNOTFOUND 0xFEC6 513 | #define AFX_IDP_E_REPLACEMENTSTOOLONG 0xFEC7 514 | //#define IDC_STATIC -1 515 | 516 | // Next default values for new objects 517 | // 518 | #ifdef APSTUDIO_INVOKED 519 | #ifndef APSTUDIO_READONLY_SYMBOLS 520 | #define _APS_NEXT_RESOURCE_VALUE 102 521 | #define _APS_NEXT_COMMAND_VALUE 40002 522 | #define _APS_NEXT_CONTROL_VALUE 1001 523 | #define _APS_NEXT_SYMED_VALUE 101 524 | #endif 525 | #endif 526 | -------------------------------------------------------------------------------- /src/FTMFile.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ** GBS Import 3 | ** Copyright (C) 2014 Slimeball 4 | ** 5 | ** Based on: 6 | ** 7 | ** FamiTracker - NES/Famicom sound tracker 8 | ** Copyright (C) 2005-2012 Jonathan Liss 9 | ** 10 | ** NSF Importer v0.5 - Written by Brad Smith 11/21/2011 11 | ** 12 | ** Game Music Emu - Copyright (C) 2003-2009 Shay Green 13 | ** 14 | ** This program is free software; you can redistribute it and/or modify 15 | ** it under the terms of the GNU General Public License as published by 16 | ** the Free Software Foundation; either version 3 of the License, or 17 | ** (at your option) any later version. 18 | ** 19 | ** This program is distributed in the hope that it will be useful, 20 | ** but WITHOUT ANY WARRANTY; without even the implied warranty of 21 | ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 22 | ** Library General Public License for more details. To obtain a 23 | ** copy of the GNU Library General Public License, write to the Free 24 | ** Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 25 | ** 26 | ** Any permitted reproduction of these routines, in whole or in part, 27 | ** must bear this legend. 28 | */ 29 | 30 | #define _CRT_SECURE_NO_WARNINGS 31 | 32 | #include 33 | #include 34 | #include 35 | #include "ft_stuff.h" 36 | #include "FTMFile.h" 37 | 38 | #define MAGIC_NUMBER 110250 39 | 40 | //TODO: Allocate stuff dynamically ;) 41 | 42 | byte saw_wave[32]={0,0,1,1,2,2,3,3,4,4,5,5,6,6,7,7,8,8,9,9,10,10,11,11,12,12,13,13,14,14,15,15}; 43 | byte dummy_seq[32]={15,15,14,14,13,13,12,12,11,11,10,10,9,9,8,8,7,7,6,6,5,5,4,4,3,3,2,2,1,1,0,0}; 44 | 45 | stSequence::stSequence() 46 | { 47 | index=0; 48 | type=0; 49 | length=0; 50 | loop=0xFFFFFFFF; 51 | release=0xFFFFFFFF; 52 | setting=0; 53 | memset(data,0,256); 54 | } 55 | 56 | Instrument_2A03::Instrument_2A03() 57 | { 58 | index=0; 59 | type=1; 60 | seq_count=SEQ_COUNT; 61 | memset(seq_data,0,2*SEQ_COUNT); 62 | memset(DPCM_data,0,288); //Earrape alert! :( 63 | name_length=0x0E; 64 | sprintf(name,"New instrument"); 65 | } 66 | 67 | Instrument_VRC6::Instrument_VRC6() 68 | { 69 | index=0; 70 | type=2; 71 | seq_count=SEQ_COUNT; 72 | memset(seq_data,0,2*SEQ_COUNT); 73 | name_length=0x0E; 74 | sprintf(name,"New instrument"); 75 | } 76 | 77 | Instrument_VRC7::Instrument_VRC7() 78 | { 79 | index=0; 80 | type=3; 81 | patch=4; 82 | memset(data,0,8); 83 | name_length=0x0E; 84 | sprintf(name,"New instrument"); 85 | } 86 | 87 | Instrument_FDS::Instrument_FDS() 88 | { 89 | index=0; 90 | type=4; 91 | memset(wave,0,64); 92 | memset(mtable,0,32); 93 | mspeed=0; 94 | mdepth=0; 95 | mdelay=0; 96 | name_length=0x0E; 97 | sprintf(name,"New instrument"); 98 | } 99 | 100 | Instrument_N163::Instrument_N163() 101 | { 102 | index=0; 103 | type=5; 104 | seq_count=SEQ_COUNT; 105 | memset(seq_data,0,2*SEQ_COUNT); 106 | wave_size=32; 107 | wave_pos=0; 108 | wave_count=1; 109 | memset(wave_data,0,16*32); 110 | memcpy(wave_data,saw_wave,32); 111 | } 112 | 113 | FTItem::FTItem() 114 | { 115 | memset(this,0,sizeof(FTItem)); 116 | instrument=64; 117 | volume=16; 118 | } 119 | 120 | FTPattern::FTPattern() 121 | { 122 | track=0; 123 | channel=0; 124 | index=0; 125 | items=0; 126 | } 127 | 128 | CFTMFile::CFTMFile() 129 | { 130 | memset(file_id,0,24); 131 | sprintf(file_id,"FamiTracker Module"); 132 | file_version=0x440; 133 | 134 | memset(pr_id,0,24); 135 | sprintf(pr_id,"PARAMS"); 136 | pr_version=6; 137 | pr_size=0x1D; 138 | expansion=0; 139 | channels=5; 140 | machine=0; 141 | e_speed=0; 142 | v_style=1; 143 | highlight1=4; 144 | highlight2=16; 145 | N163_channels=0; 146 | s_split=32; 147 | 148 | memset(nf_id,0,24); 149 | sprintf(nf_id,"INFO"); 150 | nf_version=1; 151 | nf_size=0x60; 152 | memset(author,0,32); 153 | memset(title,0,32); 154 | memset(ccccc,0,32); 155 | 156 | memset(he_id,0,24); 157 | sprintf(he_id,"HEADER"); 158 | he_version=3; 159 | he_size=10+2*channels; 160 | n_tracks=0; 161 | ch_id[0]=0; ch_id[1]=1; ch_id[2]=2; ch_id[3]=3; ch_id[4]=4; 162 | memset(ch_fx,0,16); 163 | 164 | memset(i0_id,0,24); 165 | sprintf(i0_id,"INSTRUMENTS"); 166 | i0_version=6; 167 | i0_size=329; 168 | n_instruments=0; 169 | FDS_instruments=0; 170 | VRC6_instruments=0; 171 | VRC7_instruments=0; 172 | N163_instruments=0; 173 | 174 | memset(s0_id,0,24); 175 | sprintf(s0_id,"SEQUENCES"); 176 | s0_version=6; 177 | s0_size=4; 178 | n_sequences=0; 179 | n_VRC6_sequences=0; 180 | n_N163_sequences=0; 181 | 182 | memset(fr_id,0,24); 183 | sprintf(fr_id,"FRAMES"); 184 | fr_version=3; 185 | fr_size=27; 186 | n_frames=1; 187 | speed=6; 188 | tempo=150; 189 | p_length=64; 190 | memset(fdata[0],0,channels); 191 | memset(fdata[1],0,channels); 192 | 193 | memset(pt_id,0,24); 194 | sprintf(pt_id,"PATTERNS"); 195 | pt_version=5; 196 | pt_size=0; 197 | n_patterns=0; 198 | 199 | memset(ds_id,0,24); 200 | sprintf(ds_id,"DPCM SAMPLES"); 201 | ds_version=1; 202 | ds_size=1; 203 | n_samples=0; 204 | 205 | memset(n163s_id,0,24); 206 | sprintf(n163s_id,"SEQUENCES_N163"); 207 | n163s_version=1; 208 | n163s_size=0x38; 209 | n_N163_sequences=0; 210 | 211 | memset(vrc6s_id,0,24); 212 | sprintf(vrc6s_id,"SEQUENCES_VRC6"); 213 | vrc6s_version=6; 214 | vrc6s_size=0x38; 215 | n_VRC6_sequences=0; 216 | } 217 | 218 | bool CFTMFile::LoadFile(char* filename) 219 | { 220 | //fopen_s(&fp_log,"FTM_load.log","w"); if(fp_log==NULL) {printf("Error! Could not create log file. :(\n"); return false;} 221 | fopen_s(&fp_src,filename,"rb"); if(fp_src==NULL) {printf("Error! Source file not found. :(\n"); return false;} 222 | 223 | fseek(fp_src,0,SEEK_END); src_size=ftell(fp_src); fseek(fp_src,0,SEEK_SET); //Get file size 224 | 225 | if(!ReadID()) return false; 226 | if(!ReadParams()) return false; 227 | if(!ReadInfo()) return false; 228 | if(!ReadHeader()) return false; 229 | if(!ReadInstruments()) return false; 230 | if(!ReadSequences()) return false; 231 | if(!ReadFrames()) return false; 232 | if(!ReadPatterns()) return false; 233 | 234 | //if(!LogStuff()) return false; 235 | 236 | printf("Current file position: 0x%X\n",ftell(fp_src)); 237 | 238 | fclose(fp_src); 239 | //fclose(fp_log); 240 | return true; 241 | } 242 | 243 | bool CFTMFile::SaveFile(char* filename) 244 | { 245 | //fopen_s(&fp_log,"FTM_save.log","w"); if(fp_log==NULL) {printf("Error! Could not create log file. :(\n"); return false;} 246 | fopen_s(&fp_dst,filename,"wb"); if(fp_dst==NULL) {printf("Error! Source file not found. :(\n"); return false;} 247 | 248 | if(!WriteID()) return false; 249 | if(!WriteParams()) return false; 250 | if(!WriteInfo()) return false; 251 | if(!WriteHeader()) return false; 252 | if(!WriteInstruments()) return false; 253 | if(!WriteSequences()) return false; 254 | if(!WriteFrames()) return false; 255 | if(!WritePatterns()) return false; 256 | if(!WriteSamples()) return false; 257 | if(!WriteVRC6Sequences()) return false; 258 | if(!WriteN163Sequences()) return false; 259 | fwrite("END",1,3,fp_dst); 260 | 261 | //if(!LogStuff()) return false; 262 | 263 | fclose(fp_dst); 264 | //fclose(fp_log); 265 | return true; 266 | } 267 | 268 | bool CFTMFile::Optimize() 269 | { 270 | FTPattern Temp; 271 | FTItem Prev; 272 | 273 | for(int i=0;i0); //Skip null-terminated string 511 | for (int i=0;i 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | -------------------------------------------------------------------------------- /src/license.txt: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------