1 /* 2 ** Nofrendo (c) 1998-2000 Matthew Conte (matt@conte.com) 3 ** 4 ** 5 ** This program is free software; you can redistribute it and/or 6 ** modify it under the terms of version 2 of the GNU Library General 7 ** Public License as published by the Free Software Foundation. 8 ** 9 ** This program is distributed in the hope that it will be useful, 10 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 11 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 ** Library General Public License for more details. To obtain a 13 ** copy of the GNU Library General Public License, write to the Free 14 ** Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, 15 ** MA 02110-1301, USA. 16 ** 17 ** Any permitted reproduction of these routines, in whole or in part, 18 ** must bear this legend. 19 ** 20 ** 21 ** nsf.h 22 ** 23 ** NSF loading/saving related defines / prototypes 24 ** $Id: nsf.h,v 1.3 2007/01/18 21:34:10 dgp85 Exp $ 25 */ 26 27 #ifndef _NSF_H_ 28 #define _NSF_H_ 29 30 #if defined(HAVE_CONFIG_H) && !defined(__XINE_LIB_CONFIG_H__) 31 # error config.h not included 32 #endif 33 34 #include "osd.h" 35 #include "nes6502.h" 36 #include "nes_apu.h" 37 38 #define NSF_MAGIC "NESM\x1A" 39 40 #define NSF_DEDICATED_PAL 0x01 41 #define NSF_DUAL_PAL_NTSC 0x02 42 43 #define EXT_SOUND_NONE 0x00 44 #define EXT_SOUND_VRCVI 0x01 45 #define EXT_SOUND_VRCVII 0x02 46 #define EXT_SOUND_FDS 0x04 47 #define EXT_SOUND_MMC5 0x08 48 #define EXT_SOUND_NAMCO106 0x10 49 #define EXT_SOUND_SUNSOFT_FME07 0x20 50 /* bits 6,7: future expansion */ 51 52 #define NSF_HEADER_SIZE 0x80 53 54 /* 60 Hertz refresh (NTSC) */ 55 #define NES_MASTER_CLOCK 21477272.7272 56 #define NTSC_REFRESH 60 57 #define NTSC_SUBCARRIER_DIV 12 58 #define NTSC_SCANLINES 262 59 60 #define NES_FRAME_CYCLES ((NES_MASTER_CLOCK / NTSC_SUBCARRIER_DIV) / NTSC_REFRESH) 61 #define NES_SCANLINE_CYCLES (NES_FRAME_CYCLES / NTSC_SCANLINES) 62 63 /* filter levels */ 64 enum 65 { 66 NSF_FILTER_NONE, 67 NSF_FILTER_LOWPASS, 68 NSF_FILTER_WEIGHTED, 69 NSF_FILTER_MAX, /* $$$ ben : add this one for range chacking */ 70 }; 71 72 typedef struct nsf_s 73 { 74 /* NESM header */ 75 uint8 id[5]; /* NESM\x1A */ 76 uint8 version; /* spec version */ 77 uint8 num_songs; /* total num songs */ 78 uint8 start_song; /* first song */ 79 uint16 load_addr; /* loc to load code */ 80 uint16 init_addr; /* init call address */ 81 uint16 play_addr; /* play call address */ 82 uint8 song_name[32]; /* name of song */ 83 uint8 artist_name[32]; /* artist name */ 84 uint8 copyright[32]; /* copyright info */ 85 uint16 ntsc_speed; /* playback speed (if NTSC) */ 86 uint8 bankswitch_info[8]; /* initial code banking */ 87 uint16 pal_speed; /* playback speed (if PAL) */ 88 uint8 pal_ntsc_bits; /* NTSC/PAL determination bits */ 89 uint8 ext_sound_type; /* type of external sound gen. */ 90 uint8 reserved[4]; /* reserved */ 91 92 /* things that the NSF player needs */ 93 uint8 *data; /* actual NSF data */ 94 uint32 length; /* length of data */ 95 uint32 playback_rate; /* current playback rate */ 96 uint8 current_song; /* current song */ 97 boolean bankswitched; /* is bankswitched? */ 98 99 /* $$$ ben : Playing time ... */ 100 uint32 cur_frame; 101 uint32 cur_frame_end; 102 uint32 * song_frames; 103 104 /* $$$ ben : Last error string */ 105 const char * errstr; 106 107 /* CPU and APU contexts */ 108 nes6502_context *cpu; 109 apu_t *apu; 110 111 /* our main processing routine, calls all external mixing routines */ 112 void (*process)(void *buffer, int num_samples); 113 } XINE_PACKED nsf_t; 114 115 /* $$$ ben : Generic loader struct */ 116 struct nsf_loader_t { 117 /* Init and open. */ 118 int (*open)(struct nsf_loader_t * loader); 119 120 /* Close and shutdown. */ 121 void (*close) (struct nsf_loader_t * loader); 122 123 /* This function should return <0 on error, else the number of byte NOT read. 124 * that way a simple 0 test tell us if read was complete. 125 */ 126 int (*read) (struct nsf_loader_t * loader, void *data, int n); 127 128 /* Get file length. */ 129 int (*length) (struct nsf_loader_t * loader); 130 131 /* Skip n bytes. */ 132 int (*skip) (struct nsf_loader_t * loader,int n); 133 134 /* Get filename (for debug). */ 135 const char * (*fname) (struct nsf_loader_t * loader); 136 137 }; 138 139 /* Function prototypes */ 140 extern int nsf_init(void); 141 142 extern nsf_t * nsf_load_extended(struct nsf_loader_t * loader); 143 extern nsf_t *nsf_load(const char *filename, void *source, int length); 144 extern void nsf_free(nsf_t **nsf_info); 145 146 extern int nsf_playtrack(nsf_t *nsf, int track, int sample_rate, 147 int sample_bits, boolean stereo); 148 extern void nsf_frame(nsf_t *nsf); 149 extern int nsf_setchan(nsf_t *nsf, int chan, boolean enabled); 150 extern int nsf_setfilter(nsf_t *nsf, int filter_type); 151 152 #endif /* _NSF_H_ */ 153 154 /* 155 ** $Log: nsf.h,v $ 156 ** Revision 1.3 2003/05/01 22:34:20 benjihan 157 ** New NSF plugin 158 ** 159 ** Revision 1.2 2003/04/09 14:50:32 ben 160 ** Clean NSF api. 161 ** 162 ** Revision 1.1 2003/04/08 20:53:00 ben 163 ** Adding more files... 164 ** 165 ** Revision 1.11 2000/07/04 04:59:24 matt 166 ** removed DOS-specific stuff 167 ** 168 ** Revision 1.10 2000/07/03 02:19:36 matt 169 ** dynamic address range handlers, cleaner and faster 170 ** 171 ** Revision 1.9 2000/06/23 03:27:58 matt 172 ** cleaned up external sound inteface 173 ** 174 ** Revision 1.8 2000/06/20 04:04:37 matt 175 ** moved external soundchip struct to apu module 176 ** 177 ** Revision 1.7 2000/06/20 00:05:45 matt 178 ** changed to driver-based external sound generation 179 ** 180 ** Revision 1.6 2000/06/13 03:51:54 matt 181 ** update API to take freq/sample data on nsf_playtrack 182 ** 183 ** Revision 1.5 2000/06/12 01:13:00 matt 184 ** added CPU/APU as members of the nsf struct 185 ** 186 ** Revision 1.4 2000/06/09 15:12:26 matt 187 ** initial revision 188 ** 189 */ 190