Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 710612 | Differences between
and this patch

Collapse All | Expand All

(-)puNES-0.105.org/src/audio/alsa/snd.c (+6 lines)
Lines 81-86 static _snd_thread snd_thread; Link Here
81
static _alsa alsa;
81
static _alsa alsa;
82
static _callback_data cbd;
82
static _callback_data cbd;
83
83
84
_snd snd;
85
_snd_list snd_list;
86
87
void (*snd_apu_tick)(void);
88
void (*snd_end_frame)(void);
89
84
BYTE snd_init(void) {
90
BYTE snd_init(void) {
85
	memset(&snd, 0x00, sizeof(_snd));
91
	memset(&snd, 0x00, sizeof(_snd));
86
	memset(&alsa, 0x00, sizeof(_alsa));
92
	memset(&alsa, 0x00, sizeof(_alsa));
(-)puNES-0.105.org/src/audio/blipbuf.c (-1 lines)
Lines 18-24 Link Here
18
18
19
#include <stdlib.h>
19
#include <stdlib.h>
20
#include <string.h>
20
#include <string.h>
21
#include "apu.h"
22
#include "audio/snd.h"
21
#include "audio/snd.h"
23
#include "mappers.h"
22
#include "mappers.h"
24
#include "mappers/mapper_VRC7_snd.h"
23
#include "mappers/mapper_VRC7_snd.h"
(-)puNES-0.105.org/src/audio/channels.c (+5 lines)
Lines 23-28 Link Here
23
#include "audio/delay.h"
23
#include "audio/delay.h"
24
#include "audio/panning.h"
24
#include "audio/panning.h"
25
25
26
BYTE (*audio_channels_init)(void);
27
void (*audio_channels_quit)(void);
28
void (*audio_channels_reset)(void);
29
void (*audio_channels_tick)(SWORD value);
30
26
void audio_channels(BYTE channels) {
31
void audio_channels(BYTE channels) {
27
	if (audio_channels_quit) {
32
	if (audio_channels_quit) {
28
		audio_channels_quit();
33
		audio_channels_quit();
(-)puNES-0.105.org/src/audio/channels.h (-4 / +5 lines)
Lines 23-28 Link Here
23
23
24
enum types_of_audio_channels { CH_MONO, CH_STEREO_DELAY, CH_STEREO_PANNING };
24
enum types_of_audio_channels { CH_MONO, CH_STEREO_DELAY, CH_STEREO_PANNING };
25
25
26
extern BYTE (*audio_channels_init)(void);
27
extern void (*audio_channels_quit)(void);
28
extern void (*audio_channels_reset)(void);
29
extern void (*audio_channels_tick)(SWORD value);
30
26
#if defined (__cplusplus)
31
#if defined (__cplusplus)
27
#define EXTERNC extern "C"
32
#define EXTERNC extern "C"
28
#else
33
#else
Lines 31-40 enum types_of_audio_channels { CH_MONO, Link Here
31
36
32
EXTERNC void audio_channels(BYTE channels);
37
EXTERNC void audio_channels(BYTE channels);
33
EXTERNC void audio_channels_init_mode(void);
38
EXTERNC void audio_channels_init_mode(void);
34
EXTERNC BYTE (*audio_channels_init)(void);
35
EXTERNC void (*audio_channels_quit)(void);
36
EXTERNC void (*audio_channels_reset)(void);
37
EXTERNC void (*audio_channels_tick)(SWORD value);
38
39
39
#undef EXTERNC
40
#undef EXTERNC
40
41
(-)puNES-0.105.org/src/audio/snd.h (-9 / +10 lines)
Lines 79-84 typedef struct _snd { Link Here
79
		} limit;
79
		} limit;
80
	} buffer;
80
	} buffer;
81
} _snd;
81
} _snd;
82
typedef struct _snd_list {
83
	_snd_list_dev playback;
84
	_snd_list_dev capture;
85
} _snd_list;
86
87
extern _snd snd;
88
extern _snd_list snd_list;
89
90
extern void (*snd_apu_tick)(void);
91
extern void (*snd_end_frame)(void);
82
92
83
#if defined (__cplusplus)
93
#if defined (__cplusplus)
84
#define EXTERNC extern "C"
94
#define EXTERNC extern "C"
Lines 86-97 typedef struct _snd { Link Here
86
#define EXTERNC
96
#define EXTERNC
87
#endif
97
#endif
88
98
89
EXTERNC _snd snd;
90
EXTERNC struct _snd_list {
91
	_snd_list_dev playback;
92
	_snd_list_dev capture;
93
} snd_list;
94
95
EXTERNC BYTE snd_init(void);
99
EXTERNC BYTE snd_init(void);
96
EXTERNC void snd_quit(void);
100
EXTERNC void snd_quit(void);
97
101
Lines 119-127 EXTERNC void snd_list_devices(void); Link Here
119
123
120
EXTERNC BYTE snd_handler(void);
124
EXTERNC BYTE snd_handler(void);
121
125
122
EXTERNC void (*snd_apu_tick)(void);
123
EXTERNC void (*snd_end_frame)(void);
124
125
#undef EXTERNC
126
#undef EXTERNC
126
127
127
#endif /* SND_H_ */
128
#endif /* SND_H_ */
(-)puNES-0.105.org/src/audio/sndio/snd.c (+6 lines)
Lines 66-71 static _snd_thread snd_thread; Link Here
66
static _sndio sndio;
66
static _sndio sndio;
67
static _callback_data cbd;
67
static _callback_data cbd;
68
68
69
_snd snd;
70
_snd_list snd_list;
71
72
void (*snd_apu_tick)(void);
73
void (*snd_end_frame)(void);
74
69
BYTE snd_init(void) {
75
BYTE snd_init(void) {
70
	memset(&snd, 0x00, sizeof(_snd));
76
	memset(&snd, 0x00, sizeof(_snd));
71
	memset(&sndio, 0x00, sizeof(_sndio));
77
	memset(&sndio, 0x00, sizeof(_sndio));
(-)puNES-0.105.org/src/audio/xaudio/snd.c (-1 / +6 lines)
Lines 25-31 Link Here
25
#include "gui.h"
25
#include "gui.h"
26
#include "fps.h"
26
#include "fps.h"
27
#include "clock.h"
27
#include "clock.h"
28
#include "apu.h"
29
#include "wave.h"
28
#include "wave.h"
30
#if defined (DEBUG)
29
#if defined (DEBUG)
31
#define __inline
30
#define __inline
Lines 93-98 static IXAudio2VoiceCallbackVtbl voice_c Link Here
93
static IXAudio2VoiceCallback voice_callbacks = { &voice_callbacks_vtable };
92
static IXAudio2VoiceCallback voice_callbacks = { &voice_callbacks_vtable };
94
static _callback_data cbd;
93
static _callback_data cbd;
95
94
95
_snd snd;
96
_snd_list snd_list;
97
98
void (*snd_apu_tick)(void);
99
void (*snd_end_frame)(void);
100
96
BYTE snd_init(void) {
101
BYTE snd_init(void) {
97
	memset(&snd, 0x00, sizeof(_snd));
102
	memset(&snd, 0x00, sizeof(_snd));
98
	memset(&xaudio2, 0x00, sizeof(xaudio2));
103
	memset(&xaudio2, 0x00, sizeof(xaudio2));
(-)puNES-0.105.org/src/core/apu.c (+10 lines)
Lines 29-34 Link Here
29
#include "mappers.h"
29
#include "mappers.h"
30
#include "info.h"
30
#include "info.h"
31
31
32
_nla_table nla_table;
33
_apu apu;
34
_r4011 r4011;
35
_r4015 r4015;
36
_r4017 r4017;
37
_apuSquare S1, S2;
38
_apuTriangle TR;
39
_apuNoise NS;
40
_apuDMC DMC;
41
32
void apu_tick(BYTE *hwtick) {
42
void apu_tick(BYTE *hwtick) {
33
	/* sottraggo il numero di cicli eseguiti */
43
	/* sottraggo il numero di cicli eseguiti */
34
	apu.cycles--;
44
	apu.cycles--;
(-)puNES-0.105.org/src/core/apu.h (-20 / +20 lines)
Lines 362-367 typedef struct _config_apu { Link Here
362
	BYTE channel[APU_MASTER + 1];
362
	BYTE channel[APU_MASTER + 1];
363
	double volume[APU_MASTER + 1];
363
	double volume[APU_MASTER + 1];
364
} _config_apu;
364
} _config_apu;
365
typedef struct _nla_table {
366
	SWORD pulse[32];
367
	SWORD tnd[203];
368
} _nla_table;
365
typedef struct _apu {
369
typedef struct _apu {
366
	BYTE mode;
370
	BYTE mode;
367
	BYTE type;
371
	BYTE type;
Lines 503-528 typedef struct _apuDMC { Link Here
503
	BYTE tick_type;
507
	BYTE tick_type;
504
}  _apuDMC;
508
}  _apuDMC;
505
509
506
#if defined (__cplusplus)
507
#define EXTERNC extern "C"
508
#else
509
#define EXTERNC
510
#endif
511
512
EXTERNC struct _nla_table {
513
	SWORD pulse[32];
514
	SWORD tnd[203];
515
} nla_table;
516
517
EXTERNC _apu apu;
518
EXTERNC _r4011 r4011;
519
EXTERNC _r4015 r4015;
520
EXTERNC _r4017 r4017;
521
EXTERNC _apuSquare S1, S2;
522
EXTERNC _apuTriangle TR;
523
EXTERNC _apuNoise NS;
524
EXTERNC _apuDMC DMC;
525
526
/* apuPeriod[mode][type][cycles] */
510
/* apuPeriod[mode][type][cycles] */
527
static const WORD apuPeriod[2][3][7] = {
511
static const WORD apuPeriod[2][3][7] = {
528
	/*
512
	/*
Lines 625-630 static const WORD dmc_rate[3][16] = { Link Here
625
	}
609
	}
626
};
610
};
627
611
612
extern _nla_table nla_table;
613
extern _apu apu;
614
extern _r4011 r4011;
615
extern _r4015 r4015;
616
extern _r4017 r4017;
617
extern _apuSquare S1, S2;
618
extern _apuTriangle TR;
619
extern _apuNoise NS;
620
extern _apuDMC DMC;
621
622
#if defined (__cplusplus)
623
#define EXTERNC extern "C"
624
#else
625
#define EXTERNC
626
#endif
627
628
EXTERNC void apu_tick(BYTE *hwtick);
628
EXTERNC void apu_tick(BYTE *hwtick);
629
EXTERNC void apu_turn_on(void);
629
EXTERNC void apu_turn_on(void);
630
630
(-)puNES-0.105.org/src/core/cheat.c (+3 lines)
Lines 32-37 Link Here
32
32
33
#define GGFILE "gamegenie.rom"
33
#define GGFILE "gamegenie.rom"
34
34
35
_gamegenie gamegenie;
36
_cheats_list cheats_list;
37
35
void gamegenie_init(void) {
38
void gamegenie_init(void) {
36
	memset(&gamegenie, 0x00, sizeof(gamegenie));
39
	memset(&gamegenie, 0x00, sizeof(gamegenie));
37
	gamegenie_reset();
40
	gamegenie_reset();
(-)puNES-0.105.org/src/core/cheat.h (-11 / +13 lines)
Lines 50-63 typedef struct _type_cheat { Link Here
50
	int counter;
50
	int counter;
51
	_cheat cheat[CL_CHEATS];
51
	_cheat cheat[CL_CHEATS];
52
} _type_cheat;
52
} _type_cheat;
53
53
typedef struct _gamegenie {
54
#if defined (__cplusplus)
55
#define EXTERNC extern "C"
56
#else
57
#define EXTERNC
58
#endif
59
60
EXTERNC struct _gamegenie {
61
	uTCHAR *rom;
54
	uTCHAR *rom;
62
	uTCHAR *patch;
55
	uTCHAR *patch;
63
	BYTE phase;
56
	BYTE phase;
Lines 65-75 EXTERNC struct _gamegenie { Link Here
65
	BYTE value;
58
	BYTE value;
66
	BYTE counter;
59
	BYTE counter;
67
	_cheat cheat[GG_CHEATS];
60
	_cheat cheat[GG_CHEATS];
68
} gamegenie;
61
} _gamegenie;
69
EXTERNC struct _cheats_list {
62
typedef struct _cheats_list {
70
	_type_cheat rom;
63
	_type_cheat rom;
71
	_type_cheat ram;
64
	_type_cheat ram;
72
} cheats_list;
65
} _cheats_list;
66
67
extern _gamegenie gamegenie;
68
extern _cheats_list cheats_list;
69
70
#if defined (__cplusplus)
71
#define EXTERNC extern "C"
72
#else
73
#define EXTERNC
74
#endif
73
75
74
EXTERNC void gamegenie_init(void);
76
EXTERNC void gamegenie_init(void);
75
EXTERNC void gamegenie_quit(void);
77
EXTERNC void gamegenie_quit(void);
(-)puNES-0.105.org/src/core/clock.h (-9 / +3 lines)
Lines 19-24 Link Here
19
#ifndef CLOCK_H_
19
#ifndef CLOCK_H_
20
#define CLOCK_H_
20
#define CLOCK_H_
21
21
22
#include "common.h"
23
22
typedef struct {
24
typedef struct {
23
	WORD type;                      /* il tipo di formato */
25
	WORD type;                      /* il tipo di formato */
24
	BYTE fps;                       /* il framerate */
26
	BYTE fps;                       /* il framerate */
Lines 104-117 static const _machine machinedb[] = { Link Here
104
	}
106
	}
105
};
107
};
106
108
107
#if defined (__cplusplus)
109
extern _machine machine;
108
#define EXTERNC extern "C"
109
#else
110
#define EXTERNC
111
#endif
112
113
EXTERNC _machine machine;
114
115
#undef EXTERNC
116
110
117
#endif /* CLOCK_H_ */
111
#endif /* CLOCK_H_ */
(-)puNES-0.105.org/src/core/compilation_unit_orphan.h (+61 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2020 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#ifndef COMPILATION_UNIT_ORPHAN_H_
20
#define COMPILATION_UNIT_ORPHAN_H_
21
22
#include "conf.h"
23
_config *cfg;
24
_config cfg_from_file;
25
26
#include "tas.h"
27
_tas tas;
28
29
void (*tas_header)(uTCHAR *file);
30
void (*tas_read)(void);
31
void (*tas_frame)(void);
32
void (*tas_rewind)(int32_t frames_to_rewind);
33
34
#include "gui.h"
35
_gui gui;
36
_gui_mouse gmouse;
37
_external_windows ext_win;
38
39
double (*gui_get_ms)(void);
40
41
#include "info.h"
42
_info info;
43
44
#include "clock.h"
45
_machine machine;
46
47
#include "vs_system.h"
48
_vs_system vs_system;
49
50
#include "mem_map.h"
51
_mmcpu mmcpu;
52
_prg prg;
53
_chr chr;
54
_nametables ntbl;
55
_mmap_palette mmap_palette;
56
_oam oam;
57
58
#include "debugger.h"
59
_debugger debugger;
60
61
#endif /* COMPILATION_UNIT_ORPHAN_H_ */
(-)puNES-0.105.org/src/core/conf.h (-10 / +2 lines)
Lines 21-27 Link Here
21
21
22
#include "apu.h"
22
#include "apu.h"
23
#include "input.h"
23
#include "input.h"
24
#include "overscan.h"
25
24
26
typedef struct _last_pos {
25
typedef struct _last_pos {
27
	int x;
26
	int x;
Lines 96-109 typedef struct _config { Link Here
96
	_last_pos last_pos_settings;
95
	_last_pos last_pos_settings;
97
} _config;
96
} _config;
98
97
99
#if defined (__cplusplus)
98
extern _config *cfg;
100
#define EXTERNC extern "C"
99
extern _config cfg_from_file;
101
#else
102
#define EXTERNC
103
#endif
104
105
EXTERNC _config cfg_from_file, *cfg;
106
107
#undef EXTERNC
108
100
109
#endif /* CONF_H_ */
101
#endif /* CONF_H_ */
(-)puNES-0.105.org/src/core/cpu.c (+4 lines)
Lines 560-565 static const BYTE table_opcode_cycles[25 Link Here
560
/*    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F     */
560
/*    0  1  2  3  4  5  6  7  8  9  A  B  C  D  E  F     */
561
};
561
};
562
562
563
_cpu cpu;
564
_irq irq;
565
_nmi nmi;
566
563
void cpu_exe_op(void) {
567
void cpu_exe_op(void) {
564
	cpu.opcode = FALSE;
568
	cpu.opcode = FALSE;
565
	DMC.tick_type = DMC_NORMAL;
569
	DMC.tick_type = DMC_NORMAL;
(-)puNES-0.105.org/src/core/cpu.h (-4 / +4 lines)
Lines 102-117 typedef struct _nmi { Link Here
102
	uint32_t cpu_cycles_from_last_nmi;
102
	uint32_t cpu_cycles_from_last_nmi;
103
} _nmi;
103
} _nmi;
104
104
105
extern _cpu cpu;
106
extern _irq irq;
107
extern _nmi nmi;
108
105
#if defined (__cplusplus)
109
#if defined (__cplusplus)
106
#define EXTERNC extern "C"
110
#define EXTERNC extern "C"
107
#else
111
#else
108
#define EXTERNC
112
#define EXTERNC
109
#endif
113
#endif
110
114
111
EXTERNC _cpu cpu;
112
EXTERNC _irq irq;
113
EXTERNC _nmi nmi;
114
115
EXTERNC void cpu_exe_op(void);
115
EXTERNC void cpu_exe_op(void);
116
EXTERNC void cpu_init_PC(void);
116
EXTERNC void cpu_init_PC(void);
117
EXTERNC void cpu_turn_on(void);
117
EXTERNC void cpu_turn_on(void);
(-)puNES-0.105.org/src/core/debugger.h (-13 / +6 lines)
Lines 23-44 Link Here
23
23
24
enum debugger_mode { DBG_NODBG, DBG_GO, DBG_STEP, DBG_BREAKPOINT, DBG_SLEEP };
24
enum debugger_mode { DBG_NODBG, DBG_GO, DBG_STEP, DBG_BREAKPOINT, DBG_SLEEP };
25
25
26
typedef struct _debugger_breakpoint {
26
typedef struct _debugger {
27
28
} _debugger_breakpoint;
29
30
#if defined (__cplusplus)
31
#define EXTERNC extern "C"
32
#else
33
#define EXTERNC
34
#endif
35
36
EXTERNC struct _debugger {
37
	BYTE mode;
27
	BYTE mode;
38
	WORD breakpoint;
28
	WORD breakpoint;
39
	BYTE breakframe;
29
	BYTE breakframe;
40
} debugger;
30
} _debugger;
31
typedef struct _debugger_breakpoint {
32
33
} _debugger_breakpoint;
41
34
42
#undef EXTERNC
35
extern _debugger debugger;
43
36
44
#endif /* DEBUGGER_H_ */
37
#endif /* DEBUGGER_H_ */
(-)puNES-0.105.org/src/core/emu.c (-12 lines)
Lines 16-22 Link Here
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
17
 */
18
18
19
#include <time.h>
20
#include <stdlib.h>
19
#include <stdlib.h>
21
#include <stdarg.h>
20
#include <stdarg.h>
22
#include <string.h>
21
#include <string.h>
Lines 27-65 Link Here
27
#include "debugger.h"
26
#include "debugger.h"
28
#include "emu.h"
27
#include "emu.h"
29
#include "rom_mem.h"
28
#include "rom_mem.h"
30
#include "info.h"
31
#include "settings.h"
29
#include "settings.h"
32
#include "audio/snd.h"
30
#include "audio/snd.h"
33
#include "clock.h"
31
#include "clock.h"
34
#include "cpu.h"
32
#include "cpu.h"
35
#include "mem_map.h"
33
#include "mem_map.h"
36
#include "mappers.h"
37
#include "fps.h"
38
#include "apu.h"
39
#include "ppu.h"
34
#include "ppu.h"
40
#include "video/gfx.h"
35
#include "video/gfx.h"
41
#include "text.h"
42
#include "sha1.h"
36
#include "sha1.h"
43
#include "database.h"
37
#include "database.h"
44
#include "input.h"
45
#include "version.h"
38
#include "version.h"
46
#include "conf.h"
39
#include "conf.h"
47
#include "save_slot.h"
40
#include "save_slot.h"
48
#include "rewind.h"
49
#include "tas.h"
41
#include "tas.h"
50
#include "ines.h"
42
#include "ines.h"
51
#include "unif.h"
43
#include "unif.h"
52
#include "fds.h"
44
#include "fds.h"
53
#include "nsf.h"
54
#include "nsfe.h"
45
#include "nsfe.h"
55
#include "patcher.h"
46
#include "patcher.h"
56
#include "cheat.h"
57
#include "overscan.h"
58
#include "recent_roms.h"
47
#include "recent_roms.h"
59
#if defined (WITH_OPENGL)
48
#if defined (WITH_OPENGL)
60
#include "opengl.h"
49
#include "opengl.h"
61
#endif
50
#endif
62
#include "uncompress.h"
63
#include "gui.h"
51
#include "gui.h"
64
#include "video/effects/pause.h"
52
#include "video/effects/pause.h"
65
#include "video/effects/tv_noise.h"
53
#include "video/effects/tv_noise.h"
(-)puNES-0.105.org/src/core/emu.h (-1 lines)
Lines 20-26 Link Here
20
#define EMU_H_
20
#define EMU_H_
21
21
22
#include "common.h"
22
#include "common.h"
23
#include "uncompress.h"
24
23
25
#define emu_irand(x) ((unsigned int)((x) * emu_drand()))
24
#define emu_irand(x) ((unsigned int)((x) * emu_drand()))
26
25
(-)puNES-0.105.org/src/core/external_calls.c (+49 lines)
Lines 18-23 Link Here
18
18
19
#include "external_calls.h"
19
#include "external_calls.h"
20
20
21
// viene chiamata dopo il map_init(), map_prg_ram_init() e map_chr_ram_init()
22
void (*extcl_after_mapper_init)(void);
23
void (*extcl_cpu_wr_mem)(WORD address, BYTE value);
24
BYTE (*extcl_cpu_rd_mem)(WORD address, BYTE openbus, BYTE before);
25
BYTE (*extcl_save_mapper)(BYTE mode, BYTE slot, FILE *fp);
26
// CPU
27
void (*extcl_cpu_every_cycle)(void);
28
// viene chiamata ogni volta si scrive qualcosa nel registro $4016
29
void (*extcl_cpu_wr_r4016)(BYTE value);
30
// PPU
31
// viene chiamata sempre, ad ogni ciclo della PPU
32
void (*extcl_ppu_000_to_34x)(void);
33
// viene chiamata se (!ppu.vblank && (ppu.screen_y < SCR_LINES))
34
// quindi per essere sicuri di essere durante il rendering della PPU
35
// nella funzione devo controllare anche se r2001.visible non e' a zero.
36
void (*extcl_ppu_000_to_255)(void);
37
// vengono chiamate solo se la PPU e' in fase di rendering
38
// (!ppu.vblank && r2001.visible && (ppu.screen_y < SCR_LINES))
39
void (*extcl_ppu_256_to_319)(void);
40
void (*extcl_ppu_320_to_34x)(void);
41
// viene chiamata ogni volta viene modificato ppu.screen_y
42
void (*extcl_ppu_update_screen_y)(void);
43
// viene chiamata dopo ogni cambiamento del $2006 in cpu_inline.h
44
void (*extcl_update_r2006)(WORD new_r2006, WORD old_r2006);
45
// viene chiamata alla lettura del $2007 in cpu_inline.h
46
void (*extcl_rd_r2007)(void);
47
// vengono chiamate in ppu_inline.h
48
void (*extcl_rd_ppu)(WORD address);
49
BYTE (*extcl_rd_nmt)(WORD address);
50
BYTE (*extcl_rd_chr)(WORD address);
51
// viene chiamata dopo il FETCHB e dopo il fetch dello sprite
52
void (*extcl_after_rd_chr)(WORD address);
53
// viene chiamato quando si tenta di scrivere nella Nametable Ram
54
void (*extcl_wr_nmt)(WORD address, BYTE value);
55
// viene chiamato quando si tenta di scrivere nella CHR Ram
56
void (*extcl_wr_chr)(WORD address, BYTE value);
57
// APU
58
void (*extcl_length_clock)(void);
59
void (*extcl_envelope_clock)(void);
60
void (*extcl_apu_tick)(void);
61
// irqA12
62
void (*extcl_irq_A12_clock)(void);
63
// battery
64
void (*extcl_battery_io)(BYTE mode, FILE *fp);
65
// snd
66
void (*extcl_snd_playback_start)(WORD samplarate);
67
// audio
68
void (*extcl_audio_samples_mod)(SWORD *samples, int count);
69
21
void extcl_init(void) {
70
void extcl_init(void) {
22
	/* Mappers */
71
	/* Mappers */
23
	extcl_after_mapper_init = NULL;
72
	extcl_after_mapper_init = NULL;
(-)puNES-0.105.org/src/core/external_calls.h (-83 / +57 lines)
Lines 22-38 Link Here
22
#include <stdio.h>
22
#include <stdio.h>
23
#include "common.h"
23
#include "common.h"
24
24
25
/* mappers */
25
// mappers
26
#define EXTCL_AFTER_MAPPER_INIT(n) extcl_after_mapper_init = extcl_after_mapper_init_##n
26
#define EXTCL_AFTER_MAPPER_INIT(n) extcl_after_mapper_init = extcl_after_mapper_init_##n
27
#define EXTCL_CPU_WR_MEM(n) extcl_cpu_wr_mem = extcl_cpu_wr_mem_##n
27
#define EXTCL_CPU_WR_MEM(n) extcl_cpu_wr_mem = extcl_cpu_wr_mem_##n
28
#define EXTCL_CPU_RD_MEM(n) extcl_cpu_rd_mem = extcl_cpu_rd_mem_##n
28
#define EXTCL_CPU_RD_MEM(n) extcl_cpu_rd_mem = extcl_cpu_rd_mem_##n
29
#define EXTCL_SAVE_MAPPER(n) extcl_save_mapper = extcl_save_mapper_##n
29
#define EXTCL_SAVE_MAPPER(n) extcl_save_mapper = extcl_save_mapper_##n
30
30
// CPU
31
/* CPU */
32
#define EXTCL_CPU_EVERY_CYCLE(n) extcl_cpu_every_cycle = extcl_cpu_every_cycle_##n
31
#define EXTCL_CPU_EVERY_CYCLE(n) extcl_cpu_every_cycle = extcl_cpu_every_cycle_##n
33
#define EXTCL_CPU_WR_R4016(n) extcl_cpu_wr_r4016 = extcl_cpu_wr_r4016_##n
32
#define EXTCL_CPU_WR_R4016(n) extcl_cpu_wr_r4016 = extcl_cpu_wr_r4016_##n
34
33
// PPU
35
/* PPU */
36
#define EXTCL_PPU_000_TO_34X(n) extcl_ppu_000_to_34x = extcl_ppu_000_to_34x_##n
34
#define EXTCL_PPU_000_TO_34X(n) extcl_ppu_000_to_34x = extcl_ppu_000_to_34x_##n
37
#define EXTCL_PPU_000_TO_255(n) extcl_ppu_000_to_255 = extcl_ppu_000_to_255_##n
35
#define EXTCL_PPU_000_TO_255(n) extcl_ppu_000_to_255 = extcl_ppu_000_to_255_##n
38
#define EXTCL_PPU_256_TO_319(n) extcl_ppu_256_to_319 = extcl_ppu_256_to_319_##n
36
#define EXTCL_PPU_256_TO_319(n) extcl_ppu_256_to_319 = extcl_ppu_256_to_319_##n
Lines 46-137 Link Here
46
#define EXTCL_RD_CHR(n) extcl_rd_chr = extcl_rd_chr_##n
44
#define EXTCL_RD_CHR(n) extcl_rd_chr = extcl_rd_chr_##n
47
#define EXTCL_WR_NMT(n) extcl_wr_nmt = extcl_wr_nmt_##n
45
#define EXTCL_WR_NMT(n) extcl_wr_nmt = extcl_wr_nmt_##n
48
#define EXTCL_WR_CHR(n) extcl_wr_chr = extcl_wr_chr_##n
46
#define EXTCL_WR_CHR(n) extcl_wr_chr = extcl_wr_chr_##n
49
47
// APU
50
/* APU */
51
#define EXTCL_LENGTH_CLOCK(n) extcl_length_clock = extcl_length_clock_##n
48
#define EXTCL_LENGTH_CLOCK(n) extcl_length_clock = extcl_length_clock_##n
52
#define EXTCL_ENVELOPE_CLOCK(n) extcl_envelope_clock = extcl_envelope_clock_##n
49
#define EXTCL_ENVELOPE_CLOCK(n) extcl_envelope_clock = extcl_envelope_clock_##n
53
#define EXTCL_APU_TICK(n) extcl_apu_tick = extcl_apu_tick_##n
50
#define EXTCL_APU_TICK(n) extcl_apu_tick = extcl_apu_tick_##n
54
51
// irqA12
55
/* irqA12 */
56
#define EXTCL_IRQ_A12_CLOCK(n) extcl_irq_A12_clock = extcl_irq_A12_clock_##n
52
#define EXTCL_IRQ_A12_CLOCK(n) extcl_irq_A12_clock = extcl_irq_A12_clock_##n
57
53
// battery
58
/* battery */
59
#define EXTCL_BATTERY_IO(n) extcl_battery_io = extcl_battery_io_##n
54
#define EXTCL_BATTERY_IO(n) extcl_battery_io = extcl_battery_io_##n
60
55
// snd
61
/* snd */
62
#define EXTCL_SND_PLAYBACK_START(n) extcl_snd_playback_start = extcl_snd_playback_start_##n
56
#define EXTCL_SND_PLAYBACK_START(n) extcl_snd_playback_start = extcl_snd_playback_start_##n
63
/* audio */
57
// audio
64
#define EXTCL_AUDIO_SAMPLES_MOD(n) extcl_audio_samples_mod = extcl_audio_samples_mod_##n
58
#define EXTCL_AUDIO_SAMPLES_MOD(n) extcl_audio_samples_mod = extcl_audio_samples_mod_##n
65
59
66
#if defined (__cplusplus)
60
// viene chiamata dopo il map_init(), map_prg_ram_init() e map_chr_ram_init()
67
#define EXTERNC extern "C"
61
extern void (*extcl_after_mapper_init)(void);
68
#else
62
extern void (*extcl_cpu_wr_mem)(WORD address, BYTE value);
69
#define EXTERNC
63
extern BYTE (*extcl_cpu_rd_mem)(WORD address, BYTE openbus, BYTE before);
70
#endif
64
extern BYTE (*extcl_save_mapper)(BYTE mode, BYTE slot, FILE *fp);
71
65
// CPU
72
EXTERNC void extcl_init(void);
66
extern void (*extcl_cpu_every_cycle)(void);
73
67
// viene chiamata ogni volta si scrive qualcosa nel registro $4016
74
/* mappers */
68
extern void (*extcl_cpu_wr_r4016)(BYTE value);
75
/* viene chiamata dopo il map_init(), map_prg_ram_init() e map_chr_ram_init() */
69
// PPU
76
EXTERNC void (*extcl_after_mapper_init)(void);
70
// viene chiamata sempre, ad ogni ciclo della PPU
77
/* */
71
extern void (*extcl_ppu_000_to_34x)(void);
78
EXTERNC void (*extcl_cpu_wr_mem)(WORD address, BYTE value);
72
// viene chiamata se (!ppu.vblank && (ppu.screen_y < SCR_LINES))
79
EXTERNC BYTE (*extcl_cpu_rd_mem)(WORD address, BYTE openbus, BYTE before);
73
// quindi per essere sicuri di essere durante il rendering della PPU
80
EXTERNC BYTE (*extcl_save_mapper)(BYTE mode, BYTE slot, FILE *fp);
74
// nella funzione devo controllare anche se r2001.visible non e' a zero.
81
75
extern void (*extcl_ppu_000_to_255)(void);
82
/* CPU */
76
// vengono chiamate solo se la PPU e' in fase di rendering
83
EXTERNC void (*extcl_cpu_every_cycle)(void);
77
// (!ppu.vblank && r2001.visible && (ppu.screen_y < SCR_LINES))
84
/* viene chiamata ogni volta si scrive qualcosa nel registro $4016 */
78
extern void (*extcl_ppu_256_to_319)(void);
85
EXTERNC void (*extcl_cpu_wr_r4016)(BYTE value);
79
extern void (*extcl_ppu_320_to_34x)(void);
86
80
// viene chiamata ogni volta viene modificato ppu.screen_y
87
/* PPU */
81
extern void (*extcl_ppu_update_screen_y)(void);
88
/* viene chiamata sempre, ad ogni ciclo della PPU */
82
// viene chiamata dopo ogni cambiamento del $2006 in cpu_inline.h
89
EXTERNC void (*extcl_ppu_000_to_34x)(void);
83
extern void (*extcl_update_r2006)(WORD new_r2006, WORD old_r2006);
90
/*
84
// viene chiamata alla lettura del $2007 in cpu_inline.h
91
 * viene chiamata se (!ppu.vblank && (ppu.screen_y < SCR_LINES))
85
extern void (*extcl_rd_r2007)(void);
92
 * quindi per essere sicuri di essere durante il rendering della PPU
86
// vengono chiamate in ppu_inline.h
93
 * nella funzione devo controllare anche se r2001.visible non e' a zero.
87
extern void (*extcl_rd_ppu)(WORD address);
94
 */
88
extern BYTE (*extcl_rd_nmt)(WORD address);
95
EXTERNC void (*extcl_ppu_000_to_255)(void);
89
extern BYTE (*extcl_rd_chr)(WORD address);
96
/*
90
// viene chiamata dopo il FETCHB e dopo il fetch dello sprite
97
 * vengono chiamate solo se la PPU e' in fase di rendering
91
extern void (*extcl_after_rd_chr)(WORD address);
98
 * (!ppu.vblank && r2001.visible && (ppu.screen_y < SCR_LINES))
92
// viene chiamato quando si tenta di scrivere nella Nametable Ram
99
 */
93
extern void (*extcl_wr_nmt)(WORD address, BYTE value);
100
EXTERNC void (*extcl_ppu_256_to_319)(void);
94
// viene chiamato quando si tenta di scrivere nella CHR Ram
101
EXTERNC void (*extcl_ppu_320_to_34x)(void);
95
extern void (*extcl_wr_chr)(WORD address, BYTE value);
102
/* viene chiamata ogni volta viene modificato ppu.screen_y */
96
// APU
103
EXTERNC void (*extcl_ppu_update_screen_y)(void);
97
extern void (*extcl_length_clock)(void);
104
/* viene chiamata dopo ogni cambiamento del $2006 in cpu_inline.h */
98
extern void (*extcl_envelope_clock)(void);
105
EXTERNC void (*extcl_update_r2006)(WORD new_r2006, WORD old_r2006);
99
extern void (*extcl_apu_tick)(void);
106
/* viene chiamata alla lettura del $2007 in cpu_inline.h */
100
// irqA12
107
EXTERNC void (*extcl_rd_r2007)(void);
101
extern void (*extcl_irq_A12_clock)(void);
108
/* vengono chiamate in ppu_inline.h */
102
// battery
109
EXTERNC void (*extcl_rd_ppu)(WORD address);
103
extern void (*extcl_battery_io)(BYTE mode, FILE *fp);
110
EXTERNC BYTE (*extcl_rd_nmt)(WORD address);
104
// snd
111
EXTERNC BYTE (*extcl_rd_chr)(WORD address);
105
extern void (*extcl_snd_playback_start)(WORD samplarate);
112
/* viene chiamata dopo il FETCHB e dopo il fetch dello sprite */
106
// audio
113
EXTERNC void (*extcl_after_rd_chr)(WORD address);
107
extern void (*extcl_audio_samples_mod)(SWORD *samples, int count);
114
/* viene chiamato quando si tenta di scrivere nella Nametable Ram */
115
EXTERNC void (*extcl_wr_nmt)(WORD address, BYTE value);
116
/* viene chiamato quando si tenta di scrivere nella CHR Ram */
117
EXTERNC void (*extcl_wr_chr)(WORD address, BYTE value);
118
119
/* APU */
120
EXTERNC void (*extcl_length_clock)(void);
121
EXTERNC void (*extcl_envelope_clock)(void);
122
EXTERNC void (*extcl_apu_tick)(void);
123
124
/* irqA12 */
125
EXTERNC void (*extcl_irq_A12_clock)(void);
126
127
/* battery */
128
EXTERNC void (*extcl_battery_io)(BYTE mode, FILE *fp);
129
130
/* snd */
131
EXTERNC void (*extcl_snd_playback_start)(WORD samplarate);
132
/* audio */
133
EXTERNC void (*extcl_audio_samples_mod)(SWORD *samples, int count);
134
108
135
#undef EXTERNC
109
void extcl_init(void);
136
110
137
#endif /* EXTERNAL_CALLS_H_ */
111
#endif /* EXTERNAL_CALLS_H_ */
(-)puNES-0.105.org/src/core/fds.c (+2 lines)
Lines 42-47 typedef struct _fds_diff_ele { Link Here
42
	uint32_t position;
42
	uint32_t position;
43
} _fds_diff_ele;
43
} _fds_diff_ele;
44
44
45
_fds fds;
46
45
void fds_init(void) {
47
void fds_init(void) {
46
	memset(&fds, 0x00, sizeof(fds));
48
	memset(&fds, 0x00, sizeof(fds));
47
49
(-)puNES-0.105.org/src/core/fds.h (-8 / +10 lines)
Lines 50-62 enum fds_misc { Link Here
50
	FDS_DISK_CRC_CHAR2 = 0x01AA
50
	FDS_DISK_CRC_CHAR2 = 0x01AA
51
};
51
};
52
52
53
#if defined (__cplusplus)
53
typedef struct _fds {
54
#define EXTERNC extern "C"
55
#else
56
#define EXTERNC
57
#endif
58
59
EXTERNC struct _fds {
60
	// generali
54
	// generali
61
	struct _fds_info {
55
	struct _fds_info {
62
		BYTE enabled;
56
		BYTE enabled;
Lines 185-191 EXTERNC struct _fds { Link Here
185
			SWORD mod;
179
			SWORD mod;
186
		} modulation;
180
		} modulation;
187
	} snd;
181
	} snd;
188
} fds;
182
} _fds;
183
184
extern _fds fds;
185
186
#if defined (__cplusplus)
187
#define EXTERNC extern "C"
188
#else
189
#define EXTERNC
190
#endif
189
191
190
EXTERNC void fds_init(void);
192
EXTERNC void fds_init(void);
191
EXTERNC void fds_quit(void);
193
EXTERNC void fds_quit(void);
(-)puNES-0.105.org/src/core/fps.c (+2 lines)
Lines 22-27 Link Here
22
#include "conf.h"
22
#include "conf.h"
23
#include "ppu.h"
23
#include "ppu.h"
24
24
25
_fps fps;
26
25
void fps_init(void) {
27
void fps_init(void) {
26
	if (machine.type == NTSC) {
28
	if (machine.type == NTSC) {
27
		machine.fps = 60;
29
		machine.fps = 60;
(-)puNES-0.105.org/src/core/fps.h (-8 / +10 lines)
Lines 26-38 enum ff_velocity_values { FF_2X = 2, FF_ Link Here
26
#define fps_machine_ms(factor)\
26
#define fps_machine_ms(factor)\
27
	machine.ms_frame = fps.frame.estimated_ms = (1000.0f / (double)machine.fps) * factor;
27
	machine.ms_frame = fps.frame.estimated_ms = (1000.0f / (double)machine.fps) * factor;
28
28
29
#if defined (__cplusplus)
29
typedef struct _fps {
30
#define EXTERNC extern "C"
31
#else
32
#define EXTERNC
33
#endif
34
35
EXTERNC struct _fps {
36
	double gfx;
30
	double gfx;
37
	uint8_t fast_forward;
31
	uint8_t fast_forward;
38
	uint32_t frames_skipped;
32
	uint32_t frames_skipped;
Lines 41-47 EXTERNC struct _fps { Link Here
41
		double estimated_ms;
35
		double estimated_ms;
42
		double expected_end;
36
		double expected_end;
43
	} frame;
37
	} frame;
44
} fps;
38
} _fps;
39
40
extern _fps fps;
41
42
#if defined (__cplusplus)
43
#define EXTERNC extern "C"
44
#else
45
#define EXTERNC
46
#endif
45
47
46
EXTERNC void fps_init(void);
48
EXTERNC void fps_init(void);
47
EXTERNC void fps_fast_forward(void);
49
EXTERNC void fps_fast_forward(void);
(-)puNES-0.105.org/src/core/ines.c (+2 lines)
Lines 35-40 Link Here
35
void nes20_submapper(void);
35
void nes20_submapper(void);
36
BYTE nes20_ram_size(BYTE mode);
36
BYTE nes20_ram_size(BYTE mode);
37
37
38
_ines ines;
39
38
BYTE ines_load_rom(void) {
40
BYTE ines_load_rom(void) {
39
	_rom_mem rom;
41
	_rom_mem rom;
40
	BYTE tmp;
42
	BYTE tmp;
(-)puNES-0.105.org/src/core/ines.h (-2 / +4 lines)
Lines 23-31 Link Here
23
23
24
enum ines_flags { FL6, FL7, FL8, FL9, FL10, FL11, FL12, FL13, FL14, FL15, TOTAL_FL };
24
enum ines_flags { FL6, FL7, FL8, FL9, FL10, FL11, FL12, FL13, FL14, FL15, TOTAL_FL };
25
25
26
struct _ines {
26
typedef struct _ines {
27
	BYTE flags[TOTAL_FL];
27
	BYTE flags[TOTAL_FL];
28
} ines;
28
} _ines;
29
30
extern _ines ines;
29
31
30
BYTE ines_load_rom(void);
32
BYTE ines_load_rom(void);
31
33
(-)puNES-0.105.org/src/core/info.h (-10 / +3 lines)
Lines 37-50 typedef struct _info_sh1sum { Link Here
37
		char string[41];
37
		char string[41];
38
	} chr;
38
	} chr;
39
} _info_sh1sum;
39
} _info_sh1sum;
40
40
typedef struct _info {
41
#if defined (__cplusplus)
42
#define EXTERNC extern "C"
43
#else
44
#define EXTERNC
45
#endif
46
47
EXTERNC struct _info {
48
	uTCHAR base_folder[LENGTH_FILE_NAME_MID];
41
	uTCHAR base_folder[LENGTH_FILE_NAME_MID];
49
	struct _info_rom {
42
	struct _info_rom {
50
		uTCHAR file[LENGTH_FILE_NAME_LONG];
43
		uTCHAR file[LENGTH_FILE_NAME_LONG];
Lines 134-141 EXTERNC struct _info { Link Here
134
#if !defined (RELEASE)
127
#if !defined (RELEASE)
135
	BYTE snd_info;
128
	BYTE snd_info;
136
#endif
129
#endif
137
} info;
130
} _info;
138
131
139
#undef EXTERNC
132
extern _info info;
140
133
141
#endif /* INFO_H_ */
134
#endif /* INFO_H_ */
(-)puNES-0.105.org/src/core/input/arkanoid.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef INPUT_ARKANOID_H
19
#ifndef INPUT_ARKANOID_H
20
#define INPUT_ARKANOID_H
20
#define INPUT_ARKANOID_H
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
void input_init_arkanoid(void);
24
void input_init_arkanoid(void);
25
void input_wr_arkanoid(BYTE *value, BYTE nport);
25
void input_wr_arkanoid(BYTE *value, BYTE nport);
(-)puNES-0.105.org/src/core/input/famicom.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef INPUT_FAMICON_H_
19
#ifndef INPUT_FAMICON_H_
20
#define INPUT_FAMICON_H_
20
#define INPUT_FAMICON_H_
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
BYTE input_wr_reg_famicom(BYTE value);
24
BYTE input_wr_reg_famicom(BYTE value);
25
BYTE input_rd_reg_famicom_r4016(BYTE openbus, BYTE nport);
25
BYTE input_rd_reg_famicom_r4016(BYTE openbus, BYTE nport);
(-)puNES-0.105.org/src/core/input/four_score.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef INPUT_FOUR_SCORE_H
19
#ifndef INPUT_FOUR_SCORE_H
20
#define INPUT_FOUR_SCORE_H
20
#define INPUT_FOUR_SCORE_H
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
void input_init_four_score(void);
24
void input_init_four_score(void);
25
BYTE input_wr_reg_four_score(BYTE value);
25
BYTE input_wr_reg_four_score(BYTE value);
(-)puNES-0.105.org/src/core/input/mouse.h (-1 lines)
Lines 19-25 Link Here
19
#ifndef INPUT_MOUSE_H_
19
#ifndef INPUT_MOUSE_H_
20
#define INPUT_MOUSE_H_
20
#define INPUT_MOUSE_H_
21
21
22
#include "../input.h"
23
#include "gui.h"
22
#include "gui.h"
24
#include "video/gfx.h"
23
#include "video/gfx.h"
25
24
(-)puNES-0.105.org/src/core/input/nes_001.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef INPUT_NES_001_H
19
#ifndef INPUT_NES_001_H
20
#define INPUT_NES_001_H
20
#define INPUT_NES_001_H
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
BYTE input_wr_reg_nes_001(BYTE value);
24
BYTE input_wr_reg_nes_001(BYTE value);
25
BYTE input_rd_reg_nes_001(BYTE openbus, BYTE nport);
25
BYTE input_rd_reg_nes_001(BYTE openbus, BYTE nport);
(-)puNES-0.105.org/src/core/input/nsf_controller.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef NSF_CONTROLLER_H_
19
#ifndef NSF_CONTROLLER_H_
20
#define NSF_CONTROLLER_H_
20
#define NSF_CONTROLLER_H_
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
void input_add_event_nsf_controller(BYTE index);
24
void input_add_event_nsf_controller(BYTE index);
25
BYTE input_decode_event_nsf_controller(BYTE mode, BYTE autorepeat, DBWORD event, BYTE type, _port *port);
25
BYTE input_decode_event_nsf_controller(BYTE mode, BYTE autorepeat, DBWORD event, BYTE type, _port *port);
(-)puNES-0.105.org/src/core/input/nsf_mouse.c (-1 lines)
Lines 20-26 Link Here
20
#include "input/nsf_mouse.h"
20
#include "input/nsf_mouse.h"
21
#include "input/mouse.h"
21
#include "input/mouse.h"
22
#include "conf.h"
22
#include "conf.h"
23
#include "gui.h"
24
#include "nsf.h"
23
#include "nsf.h"
25
24
26
struct _nsf_mouse {
25
struct _nsf_mouse {
(-)puNES-0.105.org/src/core/input/nsf_mouse.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef NSF_MOUSE_H_
19
#ifndef NSF_MOUSE_H_
20
#define NSF_MOUSE_H_
20
#define NSF_MOUSE_H_
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
void input_init_nsf_mouse(void);
24
void input_init_nsf_mouse(void);
25
void input_add_event_nsf_mouse(BYTE index);
25
void input_add_event_nsf_mouse(BYTE index);
(-)puNES-0.105.org/src/core/input/oeka_kids_tablet.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef INPUT_OEKA_KIDS_TABLET_H_
19
#ifndef INPUT_OEKA_KIDS_TABLET_H_
20
#define INPUT_OEKA_KIDS_TABLET_H_
20
#define INPUT_OEKA_KIDS_TABLET_H_
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
void input_init_oeka_kids_tablet(void);
24
void input_init_oeka_kids_tablet(void);
25
void input_wr_oeka_kids_tablet(BYTE *value, BYTE nport);
25
void input_wr_oeka_kids_tablet(BYTE *value, BYTE nport);
(-)puNES-0.105.org/src/core/input/snes_mouse.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef INPUT_SNES_MOUSE_H_
19
#ifndef INPUT_SNES_MOUSE_H_
20
#define INPUT_SNES_MOUSE_H_
20
#define INPUT_SNES_MOUSE_H_
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
void input_init_snes_mouse(void);
24
void input_init_snes_mouse(void);
25
void input_wr_snes_mouse(BYTE *value, BYTE nport);
25
void input_wr_snes_mouse(BYTE *value, BYTE nport);
(-)puNES-0.105.org/src/core/input/standard_controller.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef INPUT_STANDARD_CONTROLLER_H_
19
#ifndef INPUT_STANDARD_CONTROLLER_H_
20
#define INPUT_STANDARD_CONTROLLER_H_
20
#define INPUT_STANDARD_CONTROLLER_H_
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
void input_wr_standard_controller(BYTE *value, BYTE nport);
24
void input_wr_standard_controller(BYTE *value, BYTE nport);
25
void input_rd_standard_controller(BYTE *value, BYTE nport, BYTE shift);
25
void input_rd_standard_controller(BYTE *value, BYTE nport, BYTE shift);
(-)puNES-0.105.org/src/core/input/vs.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef INPUT_VS_H
19
#ifndef INPUT_VS_H
20
#define INPUT_VS_H
20
#define INPUT_VS_H
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
BYTE input_wr_reg_vs(BYTE value);
24
BYTE input_wr_reg_vs(BYTE value);
25
BYTE input_rd_reg_vs_r4016(BYTE openbus, BYTE nport);
25
BYTE input_rd_reg_vs_r4016(BYTE openbus, BYTE nport);
(-)puNES-0.105.org/src/core/input/zapper.c (+1 lines)
Lines 25-30 Link Here
25
#include "vs_system.h"
25
#include "vs_system.h"
26
#include "input/mouse.h"
26
#include "input/mouse.h"
27
#include "tas.h"
27
#include "tas.h"
28
#include "palette.h"
28
29
29
struct _zapper {
30
struct _zapper {
30
	BYTE data;
31
	BYTE data;
(-)puNES-0.105.org/src/core/input/zapper.h (-1 / +1 lines)
Lines 19-25 Link Here
19
#ifndef INPUT_ZAPPER_H_
19
#ifndef INPUT_ZAPPER_H_
20
#define INPUT_ZAPPER_H_
20
#define INPUT_ZAPPER_H_
21
21
22
#include "../input.h"
22
#include "input.h"
23
23
24
void input_init_zapper(void);
24
void input_init_zapper(void);
25
void input_rd_zapper(BYTE *value, BYTE nport, BYTE shift);
25
void input_rd_zapper(BYTE *value, BYTE nport, BYTE shift);
(-)puNES-0.105.org/src/core/input.c (-1 / +7 lines)
Lines 17-23 Link Here
17
 */
17
 */
18
18
19
#include <string.h>
19
#include <string.h>
20
#include "input.h"
21
#include "clock.h"
20
#include "clock.h"
22
#include "video/gfx.h"
21
#include "video/gfx.h"
23
#include "info.h"
22
#include "info.h"
Lines 45-50 Link Here
45
#define SET_DECODE_EVENT(id, funct) port_funct[id].input_decode_event = funct
44
#define SET_DECODE_EVENT(id, funct) port_funct[id].input_decode_event = funct
46
#define SET_ADD_EVENT(id, funct) port_funct[id].input_add_event = funct
45
#define SET_ADD_EVENT(id, funct) port_funct[id].input_add_event = funct
47
46
47
_r4016 r4016;
48
_port port[PORT_MAX];
49
_port_funct port_funct[PORT_MAX];
50
51
BYTE (*input_wr_reg)(BYTE value);
52
BYTE (*input_rd_reg[2])(BYTE openbus, BYTE nport);
53
48
void input_init(BYTE set_cursor) {
54
void input_init(BYTE set_cursor) {
49
	BYTE a;
55
	BYTE a;
50
56
(-)puNES-0.105.org/src/core/input.h (-7 / +7 lines)
Lines 111-126 typedef struct _port_funct { Link Here
111
	BYTE (*input_decode_event)(BYTE mode, BYTE autorepeat, DBWORD event, BYTE type, _port *port);
111
	BYTE (*input_decode_event)(BYTE mode, BYTE autorepeat, DBWORD event, BYTE type, _port *port);
112
} _port_funct;
112
} _port_funct;
113
113
114
extern _r4016 r4016;
115
extern _port port[PORT_MAX];
116
extern _port_funct port_funct[PORT_MAX];
117
118
extern BYTE (*input_wr_reg)(BYTE value);
119
extern BYTE (*input_rd_reg[2])(BYTE openbus, BYTE nport);
120
114
#if defined (__cplusplus)
121
#if defined (__cplusplus)
115
#define EXTERNC extern "C"
122
#define EXTERNC extern "C"
116
#else
123
#else
117
#define EXTERNC
124
#define EXTERNC
118
#endif
125
#endif
119
126
120
EXTERNC _r4016 r4016;
121
EXTERNC _port port[PORT_MAX];
122
EXTERNC _port_funct port_funct[PORT_MAX];
123
124
EXTERNC void input_init(BYTE set_cursor);
127
EXTERNC void input_init(BYTE set_cursor);
125
128
126
EXTERNC void input_wr_disabled(BYTE *value, BYTE nport);
129
EXTERNC void input_wr_disabled(BYTE *value, BYTE nport);
Lines 128-136 EXTERNC void input_rd_disabled(BYTE *val Link Here
128
131
129
EXTERNC BYTE input_draw_target();
132
EXTERNC BYTE input_draw_target();
130
133
131
EXTERNC BYTE (*input_wr_reg)(BYTE value);
132
EXTERNC BYTE (*input_rd_reg[2])(BYTE openbus, BYTE nport);
133
134
#undef EXTERNC
134
#undef EXTERNC
135
135
136
#endif /* INPUT_H_ */
136
#endif /* INPUT_H_ */
(-)puNES-0.105.org/src/core/input.h.orig (+136 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#ifndef INPUT_H_
20
#define INPUT_H_
21
22
#if defined (_WIN32)
23
#define INITGUID
24
#include <guiddef.h>
25
#undef INITGUID
26
#endif
27
#include "common.h"
28
29
#define TURBO_BUTTON_DELAY_DEFAULT 1
30
#define TURBO_BUTTON_DELAY_MAX     20
31
32
enum controller_modes { CTRL_MODE_NES, CTRL_MODE_FAMICOM, CTRL_MODE_FOUR_SCORE };
33
enum controller_types {
34
	CTRL_DISABLED,
35
	CTRL_STANDARD,
36
	CTRL_ZAPPER,
37
	CTRL_SNES_MOUSE,
38
	CTRL_ARKANOID_PADDLE,
39
	CTRL_OEKA_KIDS_TABLET
40
};
41
enum pad_types { CTRL_PAD_AUTO, CTRL_PAD_ORIGINAL, CTRL_PAD_3RD_PARTY };
42
enum controller_buttons {
43
	BUT_A,
44
	BUT_B,
45
	SELECT,
46
	START,
47
	UP,
48
	DOWN,
49
	LEFT,
50
	RIGHT,
51
	TRB_A,
52
	TRB_B,
53
	MAX_STD_PAD_BUTTONS
54
};
55
enum turbo_buttons { TURBOA, TURBOB };
56
enum input_types { KEYBOARD, JOYSTICK };
57
enum button_states { RELEASED = 0x00, PRESSED = 0x01 };
58
enum input_max_values { MAX_JOYSTICK = 16 };
59
enum input_set_cursor { NO_SET_CURSOR = FALSE, SET_CURSOR = TRUE};
60
enum port_controllers {
61
	PORT1,
62
	PORT2,
63
	PORT_BASE,
64
	PORT3 = PORT_BASE,
65
	PORT4,
66
	PORT_MAX
67
};
68
69
typedef struct _config_input {
70
	BYTE permit_updown_leftright;
71
	BYTE hide_zapper_cursor;
72
	BYTE controller_mode;
73
	BYTE expansion;
74
#if defined (_WIN32)
75
	GUID shcjoy_id;
76
#else
77
	BYTE shcjoy_id;
78
#endif
79
} _config_input;
80
typedef struct _r4016 {
81
	BYTE value;
82
} _r4016;
83
typedef struct _turbo_button {
84
	BYTE frequency;
85
	BYTE active;
86
	BYTE counter;
87
} _turbo_button;
88
typedef struct _port {
89
	BYTE type;
90
#if defined (_WIN32)
91
	GUID joy_id;
92
#else
93
	BYTE joy_id;
94
#endif
95
96
	// standard controller
97
	BYTE type_pad;
98
	BYTE index;
99
	BYTE data[24];
100
	DBWORD input[2][24];
101
	// turbo buttons
102
	_turbo_button turbo[2];
103
} _port;
104
typedef struct _array_pointers_port {
105
	_port *port[PORT_MAX];
106
} _array_pointers_port;
107
typedef struct _port_funct {
108
	void (*input_wr)(BYTE *value, BYTE nport);
109
	void (*input_rd)(BYTE *value, BYTE nport, BYTE shift);
110
	void (*input_add_event)(BYTE index);
111
	BYTE (*input_decode_event)(BYTE mode, BYTE autorepeat, DBWORD event, BYTE type, _port *port);
112
} _port_funct;
113
114
#if defined (__cplusplus)
115
#define EXTERNC extern "C"
116
#else
117
#define EXTERNC
118
#endif
119
120
EXTERNC _r4016 r4016;
121
EXTERNC _port port[PORT_MAX];
122
EXTERNC _port_funct port_funct[PORT_MAX];
123
124
EXTERNC void input_init(BYTE set_cursor);
125
126
EXTERNC void input_wr_disabled(BYTE *value, BYTE nport);
127
EXTERNC void input_rd_disabled(BYTE *value, BYTE nport, BYTE shift);
128
129
EXTERNC BYTE input_draw_target();
130
131
EXTERNC BYTE (*input_wr_reg)(BYTE value);
132
EXTERNC BYTE (*input_rd_reg[2])(BYTE openbus, BYTE nport);
133
134
#undef EXTERNC
135
136
#endif /* INPUT_H_ */
(-)puNES-0.105.org/src/core/irqA12.c (+3 lines)
Lines 20-25 Link Here
20
#include "ppu_inline.h"
20
#include "ppu_inline.h"
21
#include "irqA12.h"
21
#include "irqA12.h"
22
22
23
_irqA12 irqA12;
24
BYTE irqA12_delay;
25
23
void irqA12_IO(WORD value, WORD value_old) {
26
void irqA12_IO(WORD value, WORD value_old) {
24
	if (!(value_old & 0x1000) && (value & 0x1000)) {
27
	if (!(value_old & 0x1000) && (value & 0x1000)) {
25
		if (irqA12.cycles > irqA12_min_cpu_cycles_prev_rising_edge) {
28
		if (irqA12.cycles > irqA12_min_cpu_cycles_prev_rising_edge) {
(-)puNES-0.105.org/src/core/irqA12.h (-3 / +3 lines)
Lines 82-88 enum irqA12_misc_value { Link Here
82
	irqA12_min_cpu_cycles_prev_rising_edge = 18
82
	irqA12_min_cpu_cycles_prev_rising_edge = 18
83
};
83
};
84
84
85
typedef struct {
85
typedef struct _irqA12 {
86
	BYTE present;
86
	BYTE present;
87
	BYTE delay;
87
	BYTE delay;
88
	BYTE counter;
88
	BYTE counter;
Lines 104-112 typedef struct { Link Here
104
	} race;
104
	} race;
105
} _irqA12;
105
} _irqA12;
106
106
107
_irqA12 irqA12;
107
extern _irqA12 irqA12;
108
/* questo non e' necessario salvarlo */
108
/* questo non e' necessario salvarlo */
109
BYTE irqA12_delay;
109
extern BYTE irqA12_delay;
110
110
111
void irqA12_IO(WORD value, WORD value_old);
111
void irqA12_IO(WORD value, WORD value_old);
112
void irqA12_BS(void);
112
void irqA12_BS(void);
(-)puNES-0.105.org/src/core/irql2f.c (+2 lines)
Lines 18-23 Link Here
18
18
19
#include "irql2f.h"
19
#include "irql2f.h"
20
20
21
_irql2f irql2f;
22
21
void irql2f_tick(void) {
23
void irql2f_tick(void) {
22
	if (irql2f.frame_x != ppu.frame_x) {
24
	if (irql2f.frame_x != ppu.frame_x) {
23
		return;
25
		return;
(-)puNES-0.105.org/src/core/irql2f.h (-2 / +2 lines)
Lines 27-33 enum { Link Here
27
	IRQL2F_PENDING = 0x80
27
	IRQL2F_PENDING = 0x80
28
};
28
};
29
29
30
typedef struct {
30
typedef struct _irql2f {
31
	BYTE present;
31
	BYTE present;
32
	BYTE enable;
32
	BYTE enable;
33
	BYTE counter;
33
	BYTE counter;
Lines 38-44 typedef struct { Link Here
38
	BYTE pending;
38
	BYTE pending;
39
} _irql2f;
39
} _irql2f;
40
40
41
_irql2f irql2f;
41
extern _irql2f irql2f;
42
42
43
void irql2f_tick(void);
43
void irql2f_tick(void);
44
44
(-)puNES-0.105.org/src/core/main.c (-7 / +1 lines)
Lines 20-40 Link Here
20
#include <stdlib.h>
20
#include <stdlib.h>
21
#include <string.h>
21
#include <string.h>
22
#include "main.h"
22
#include "main.h"
23
#include "debugger.h"
23
#include "compilation_unit_orphan.h"
24
#include "../gui/cmd_line.h"
24
#include "../gui/cmd_line.h"
25
#include "emu.h"
25
#include "emu.h"
26
#include "emu_thread.h"
26
#include "emu_thread.h"
27
#include "info.h"
28
#include "settings.h"
27
#include "settings.h"
29
#include "mem_map.h"
30
#include "video/gfx.h"
28
#include "video/gfx.h"
31
#include "text.h"
32
#include "conf.h"
33
#include "version.h"
29
#include "version.h"
34
#include "gui.h"
35
#include "cheat.h"
30
#include "cheat.h"
36
#include "recent_roms.h"
31
#include "recent_roms.h"
37
#include "uncompress.h"
38
#include "patcher.h"
32
#include "patcher.h"
39
#include "ppu.h"
33
#include "ppu.h"
40
34
(-)puNES-0.105.org/src/core/Makefile.am (+1 lines)
Lines 7-12 libcore_a_SOURCES = \ Link Here
7
	cheat.h \
7
	cheat.h \
8
	clock.h \
8
	clock.h \
9
	common.h \
9
	common.h \
10
	compilation_unit_orphan.h \
10
	conf.h \
11
	conf.h \
11
	cpu.c \
12
	cpu.c \
12
	cpu.h \
13
	cpu.h \
(-)puNES-0.105.org/src/core/Makefile.am.orig (+488 lines)
Line 0 Link Here
1
noinst_LIBRARIES = libcore.a
2
libcore_a_SOURCES = \
3
	apu.c \
4
	apu.h \
5
	build.h \
6
	cheat.c \
7
	cheat.h \
8
	clock.h \
9
	common.h \
10
	conf.h \
11
	cpu.c \
12
	cpu.h \
13
	cpu_inline.h \
14
	database.h \
15
	debugger.h \
16
	draw_on_screen.h \
17
	draw_on_screen.c \
18
	emu.c \
19
	emu.h \
20
	emu_thread.c \
21
	emu_thread.h \
22
	external_calls.c \
23
	external_calls.h \
24
	fds.c \
25
	fds.h \
26
	font.h \
27
	fps.c \
28
	fps.h \
29
	gui.h \
30
	ines.c \
31
	ines.h \
32
	info.h \
33
	input.c \
34
	input.h \
35
	irqA12.c \
36
	irqA12.h \
37
	irql2f.c \
38
	irql2f.h \
39
	main.h \
40
	mappers.c \
41
	mappers.h \
42
	mem_map.h \
43
	miniz.h \
44
	nsf.c \
45
	nsf.h \
46
	nsfe.c \
47
	nsfe.h \
48
	overscan.c \
49
	overscan.h \
50
	patcher.c \
51
	patcher.h \
52
	patcher_xdelta3_wrap.c \
53
	patcher_xdelta3_wrap.h \
54
	paldef.h \
55
	palette.h \
56
	ppu.c \
57
	ppu.h \
58
	ppu_inline.h \
59
	rewind.c \
60
	rewind.h \
61
	rom_mem.c \
62
	rom_mem.h \
63
	save_slot.c \
64
	save_slot.h \
65
	sha1.c \
66
	sha1.h \
67
	text.c \
68
	text.h \
69
	uncompress.c \
70
	uncompress.h \
71
	uncompress_selection.h \
72
	unif.c \
73
	unif.h \
74
	version.h\
75
	vs_system.h
76
77
libcore_a_SOURCES += \
78
	input/arkanoid.h \
79
	input/arkanoid.c \
80
	input/famicom.h \
81
	input/famicom.c \
82
	input/four_score.h \
83
	input/four_score.c \
84
	input/mouse.h \
85
	input/nes_001.h \
86
	input/nes_001.c \
87
	input/nsf_controller.h \
88
	input/nsf_controller.c \
89
	input/nsf_mouse.h \
90
	input/nsf_mouse.c \
91
	input/oeka_kids_tablet.h \
92
	input/oeka_kids_tablet.c \
93
	input/snes_mouse.h \
94
	input/snes_mouse.c \
95
	input/standard_controller.h \
96
	input/standard_controller.c \
97
	input/vs.h \
98
	input/vs.c \
99
	input/zapper.h \
100
	input/zapper.c
101
102
libcore_a_SOURCES += \
103
	../extra/kiss_fft130/kiss_fft.c \
104
	../extra/kiss_fft130/_kiss_fft_guts.h \
105
	../extra/kiss_fft130/kiss_fft.h
106
107
libcore_a_SOURCES += \
108
	mappers/mapper_0.c \
109
	mappers/mapper_0.h \
110
	mappers/mapper_105.c \
111
	mappers/mapper_105.h \
112
	mappers/mapper_114.c \
113
	mappers/mapper_114.h \
114
	mappers/mapper_116.c \
115
	mappers/mapper_116.h \
116
	mappers/mapper_120.c \
117
	mappers/mapper_120.h \
118
	mappers/mapper_121.c \
119
	mappers/mapper_121.h \
120
	mappers/mapper_134.c \
121
	mappers/mapper_134.h \
122
	mappers/mapper_156.c \
123
	mappers/mapper_156.h \
124
	mappers/mapper_163.c \
125
	mappers/mapper_163.h \
126
	mappers/mapper_164.c \
127
	mappers/mapper_164.h \
128
	mappers/mapper_166.c \
129
	mappers/mapper_166.h \
130
	mappers/mapper_167.c \
131
	mappers/mapper_167.h \
132
	mappers/mapper_168.c \
133
	mappers/mapper_168.h \
134
	mappers/mapper_176.c \
135
	mappers/mapper_176.h \
136
	mappers/mapper_178.c \
137
	mappers/mapper_178.h \
138
	mappers/mapper_182.c \
139
	mappers/mapper_182.h \
140
	mappers/mapper_183.c \
141
	mappers/mapper_183.h \
142
	mappers/mapper_186.c \
143
	mappers/mapper_186.h \
144
	mappers/mapper_187.c \
145
	mappers/mapper_187.h \
146
	mappers/mapper_188.c \
147
	mappers/mapper_188.h \
148
	mappers/mapper_190.c \
149
	mappers/mapper_190.h \
150
	mappers/mapper_196.c \
151
	mappers/mapper_196.h \
152
	mappers/mapper_197.c \
153
	mappers/mapper_197.h \
154
	mappers/mapper_200.c \
155
	mappers/mapper_200.h \
156
	mappers/mapper_201.c \
157
	mappers/mapper_201.h \
158
	mappers/mapper_202.c \
159
	mappers/mapper_202.h \
160
	mappers/mapper_203.c \
161
	mappers/mapper_203.h \
162
	mappers/mapper_204.c \
163
	mappers/mapper_204.h \
164
	mappers/mapper_205.c \
165
	mappers/mapper_205.h \
166
	mappers/mapper_208.c \
167
	mappers/mapper_208.h \
168
	mappers/mapper_212.c \
169
	mappers/mapper_212.h \
170
	mappers/mapper_213.c \
171
	mappers/mapper_213.h \
172
	mappers/mapper_214.c \
173
	mappers/mapper_214.h \
174
	mappers/mapper_215.c \
175
	mappers/mapper_215.h \
176
	mappers/mapper_217.c \
177
	mappers/mapper_217.h \
178
	mappers/mapper_219.c \
179
	mappers/mapper_219.h \
180
	mappers/mapper_221.c \
181
	mappers/mapper_221.h \
182
	mappers/mapper_222.c \
183
	mappers/mapper_222.h \
184
	mappers/mapper_225.c \
185
	mappers/mapper_225.h \
186
	mappers/mapper_226.c \
187
	mappers/mapper_226.h \
188
	mappers/mapper_227.c \
189
	mappers/mapper_227.h \
190
	mappers/mapper_229.c \
191
	mappers/mapper_229.h \
192
	mappers/mapper_230.c \
193
	mappers/mapper_230.h \
194
	mappers/mapper_231.c \
195
	mappers/mapper_231.h \
196
	mappers/mapper_233.c \
197
	mappers/mapper_233.h \
198
	mappers/mapper_235.c \
199
	mappers/mapper_235.h \
200
	mappers/mapper_240.c \
201
	mappers/mapper_240.h \
202
	mappers/mapper_241.c \
203
	mappers/mapper_241.h \
204
	mappers/mapper_242.c \
205
	mappers/mapper_242.h \
206
	mappers/mapper_244.c \
207
	mappers/mapper_244.h \
208
	mappers/mapper_246.c \
209
	mappers/mapper_246.h \
210
	mappers/mapper_249.c \
211
	mappers/mapper_249.h \
212
	mappers/mapper_250.c \
213
	mappers/mapper_250.h \
214
	mappers/mapper_252.c \
215
	mappers/mapper_252.h \
216
	mappers/mapper_253.c \
217
	mappers/mapper_253.h \
218
	mappers/mapper_254.c \
219
	mappers/mapper_254.h \
220
	mappers/mapper_28.c \
221
	mappers/mapper_28.h \
222
	mappers/mapper_31.c \
223
	mappers/mapper_31.h \
224
	mappers/mapper_36.c \
225
	mappers/mapper_36.h \
226
	mappers/mapper_37.c \
227
	mappers/mapper_37.h \
228
	mappers/mapper_40.c \
229
	mappers/mapper_40.h \
230
	mappers/mapper_42.c \
231
	mappers/mapper_42.h \
232
	mappers/mapper_43.c \
233
	mappers/mapper_43.h \
234
	mappers/mapper_44.c \
235
	mappers/mapper_44.h \
236
	mappers/mapper_45.c \
237
	mappers/mapper_45.h \
238
	mappers/mapper_46.c \
239
	mappers/mapper_46.h \
240
	mappers/mapper_47.c \
241
	mappers/mapper_47.h \
242
	mappers/mapper_49.c \
243
	mappers/mapper_49.h \
244
	mappers/mapper_50.c \
245
	mappers/mapper_50.h \
246
	mappers/mapper_51.c \
247
	mappers/mapper_51.h \
248
	mappers/mapper_52.c \
249
	mappers/mapper_52.h \
250
	mappers/mapper_53.c \
251
	mappers/mapper_53.h \
252
	mappers/mapper_57.c \
253
	mappers/mapper_57.h \
254
	mappers/mapper_58.c \
255
	mappers/mapper_58.h \
256
	mappers/mapper_60.c \
257
	mappers/mapper_60.h \
258
	mappers/mapper_61.c \
259
	mappers/mapper_61.h \
260
	mappers/mapper_62.c \
261
	mappers/mapper_62.h \
262
	mappers/mapper_74x138x161.c \
263
	mappers/mapper_74x138x161.h \
264
	mappers/mapper_74x161x161x32.c \
265
	mappers/mapper_74x161x161x32.h \
266
	mappers/mapper_8_IN_1.c \
267
	mappers/mapper_8_IN_1.h \
268
	mappers/mapper_83.c \
269
	mappers/mapper_83.h \
270
	mappers/mapper_90_209_211.c \
271
	mappers/mapper_90_209_211.h \
272
	mappers/mapper_91.c \
273
	mappers/mapper_91.h \
274
	mappers/mapper_A65AS.c \
275
	mappers/mapper_A65AS.h \
276
	mappers/mapper_AC08.c \
277
	mappers/mapper_AC08.h \
278
	mappers/mapper_Active.c \
279
	mappers/mapper_Active.h \
280
	mappers/mapper_Agci.c \
281
	mappers/mapper_Agci.h \
282
	mappers/mapper_Ave.c \
283
	mappers/mapper_Ave.h \
284
	mappers/mapper_AX5705.c \
285
	mappers/mapper_AX5705.h \
286
	mappers/mapper_AxROM.c \
287
	mappers/mapper_AxROM.h \
288
	mappers/mapper_Bandai.c \
289
	mappers/mapper_Bandai.h \
290
	mappers/mapper_BB.c \
291
	mappers/mapper_BB.h \
292
	mappers/mapper_BMC11160.c \
293
	mappers/mapper_BMC11160.h \
294
	mappers/mapper_BMC12IN1.c \
295
	mappers/mapper_BMC12IN1.h \
296
	mappers/mapper_BMC411120C.c \
297
	mappers/mapper_BMC411120C.h \
298
	mappers/mapper_BMC70IN1.c \
299
	mappers/mapper_BMC70IN1.h \
300
	mappers/mapper_BMC830118C.c \
301
	mappers/mapper_BMC830118C.h \
302
	mappers/mapper_BMCFK23C.c \
303
	mappers/mapper_BMCFK23C.h \
304
	mappers/mapper_BMCG146.c \
305
	mappers/mapper_BMCG146.h \
306
	mappers/mapper_BMCGhostbusters63in1.c \
307
	mappers/mapper_BMCGhostbusters63in1.h \
308
	mappers/mapper_BMCHP898F.c \
309
	mappers/mapper_BMCHP898F.h \
310
	mappers/mapper_BMC64IN1NOREPEAT.c \
311
	mappers/mapper_BMC64IN1NOREPEAT.h \
312
	mappers/mapper_BMC810544CA1.c \
313
	mappers/mapper_BMC810544CA1.h \
314
	mappers/mapper_BMCNTD03.c \
315
	mappers/mapper_BMCNTD03.h \
316
	mappers/mapper_BOY.c \
317
	mappers/mapper_BOY.h \
318
	mappers/mapper_BS5.c \
319
	mappers/mapper_BS5.h \
320
	mappers/mapper_BxROM.c \
321
	mappers/mapper_BxROM.h \
322
	mappers/mapper_Caltron.c \
323
	mappers/mapper_Caltron.h \
324
	mappers/mapper_Camerica.c \
325
	mappers/mapper_Camerica.h \
326
	mappers/mapper_CC_21.c \
327
	mappers/mapper_CC_21.h \
328
	mappers/mapper_CITYFIGHT.c \
329
	mappers/mapper_CITYFIGHT.h \
330
	mappers/mapper_CNROM.c \
331
	mappers/mapper_CNROM.h \
332
	mappers/mapper_ColorDreams.c \
333
	mappers/mapper_ColorDreams.h \
334
	mappers/mapper_CPROM.c \
335
	mappers/mapper_CPROM.h \
336
	mappers/mapper_DRAGONFIGHTER.c \
337
	mappers/mapper_DRAGONFIGHTER.h \
338
	mappers/mapper_DREAMTECH01.c \
339
	mappers/mapper_DREAMTECH01.h \
340
	mappers/mapper_EDU2000.c \
341
	mappers/mapper_EDU2000.h \
342
	mappers/mapper_EH8813A.c \
343
	mappers/mapper_EH8813A.h \
344
	mappers/mapper_FDS.c \
345
	mappers/mapper_FDS.h \
346
	mappers/mapper_Futuremedia.c \
347
	mappers/mapper_Futuremedia.h \
348
	mappers/mapper_FS304.c \
349
	mappers/mapper_FS304.h \
350
	mappers/mapper_GameGenie.c \
351
	mappers/mapper_GameGenie.h \
352
	mappers/mapper_GxROM.c \
353
	mappers/mapper_GxROM.h \
354
	mappers/mapper_GS_2004.c \
355
	mappers/mapper_GS_2004.h \
356
	mappers/mapper_GS_2013.c \
357
	mappers/mapper_GS_2013.h \
358
	mappers/mapper_H2288.c \
359
	mappers/mapper_H2288.h \
360
	mappers/mapper_Hen.c \
361
	mappers/mapper_Hen.h \
362
	mappers/mapper_Hes.c \
363
	mappers/mapper_Hes.h \
364
	mappers/mapper_Irem.c \
365
	mappers/mapper_Irem.h \
366
	mappers/mapper_Jaleco.c \
367
	mappers/mapper_Jaleco.h \
368
	mappers/mapper_Kaiser.c \
369
	mappers/mapper_Kaiser.h \
370
	mappers/mapper_Kasing.c \
371
	mappers/mapper_Kasing.h \
372
	mappers/mapper_KOF97.c \
373
	mappers/mapper_KOF97.h \
374
	mappers/mapper_KS7012.c \
375
	mappers/mapper_KS7012.h \
376
	mappers/mapper_KS7013B.c \
377
	mappers/mapper_KS7013B.h \
378
	mappers/mapper_KS7016.c \
379
	mappers/mapper_KS7016.h \
380
	mappers/mapper_KS7017.c \
381
	mappers/mapper_KS7017.h \
382
	mappers/mapper_KS7031.c \
383
	mappers/mapper_KS7031.h \
384
	mappers/mapper_KS7032.c \
385
	mappers/mapper_KS7032.h \
386
	mappers/mapper_KS7037.c \
387
	mappers/mapper_KS7037.h \
388
	mappers/mapper_KS7057.c \
389
	mappers/mapper_KS7057.h \
390
	mappers/mapper_LH10.c \
391
	mappers/mapper_LH10.h \
392
	mappers/mapper_LH32.c \
393
	mappers/mapper_LH32.h \
394
	mappers/mapper_Magic.c \
395
	mappers/mapper_Magic.h \
396
	mappers/mapper_Malee.c \
397
	mappers/mapper_Malee.h \
398
	mappers/mapper_MALISB.c \
399
	mappers/mapper_MALISB.h \
400
	mappers/mapper_MMC1.c \
401
	mappers/mapper_MMC1.h \
402
	mappers/mapper_MMC2andMMC4.c \
403
	mappers/mapper_MMC2andMMC4.h \
404
	mappers/mapper_MMC3.c \
405
	mappers/mapper_MMC3.h \
406
	mappers/mapper_MMC5.c \
407
	mappers/mapper_MMC5.h \
408
	mappers/mapper_MTECH01.c \
409
	mappers/mapper_MTECH01.h \
410
	mappers/mapper_Namco.c \
411
	mappers/mapper_Namco.h \
412
	mappers/mapper_NovelDiamond.c \
413
	mappers/mapper_NovelDiamond.h \
414
	mappers/mapper_NSF.c \
415
	mappers/mapper_NSF.h \
416
	mappers/mapper_Ntdec.c \
417
	mappers/mapper_Ntdec.h \
418
	mappers/mapper_Rcm.c \
419
	mappers/mapper_Rcm.h \
420
	mappers/mapper_Rex.c \
421
	mappers/mapper_Rex.h \
422
	mappers/mapper_RT_01.c \
423
	mappers/mapper_RT_01.h \
424
	mappers/mapper_SA_9602B.c \
425
	mappers/mapper_SA_9602B.h \
426
	mappers/mapper_Sachen.c \
427
	mappers/mapper_Sachen.h \
428
	mappers/mapper_SC_127.c \
429
	mappers/mapper_SC_127.h \
430
	mappers/mapper_SHERO.c \
431
	mappers/mapper_SHERO.h \
432
	mappers/mapper_SL1632.c \
433
	mappers/mapper_SL1632.h \
434
	mappers/mapper_Sunsoft.c \
435
	mappers/mapper_Sunsoft.h \
436
	mappers/mapper_Super24in1.c \
437
	mappers/mapper_Super24in1.h \
438
	mappers/mapper_T262.c \
439
	mappers/mapper_T262.h \
440
	mappers/mapper_Taito.c \
441
	mappers/mapper_Taito.h \
442
	mappers/mapper_Tengen.c \
443
	mappers/mapper_Tengen.h \
444
	mappers/mapper_TF1201.c \
445
	mappers/mapper_TF1201.h \
446
	mappers/mapper_Txc.c \
447
	mappers/mapper_Txc.h \
448
	mappers/mapper_TxROM.c \
449
	mappers/mapper_TxROM.h \
450
	mappers/mapper_UNIF158B.c \
451
	mappers/mapper_UNIF158B.h \
452
	mappers/mapper_UNIF43272.c \
453
	mappers/mapper_UNIF43272.h \
454
	mappers/mapper_UNIF603_5052.c \
455
	mappers/mapper_UNIF603_5052.h \
456
	mappers/mapper_UNIF8157.c \
457
	mappers/mapper_UNIF8157.h \
458
	mappers/mapper_UNIF8237.c \
459
	mappers/mapper_UNIF8237.h \
460
	mappers/mapper_UNIFSMB2J.c \
461
	mappers/mapper_UNIFSMB2J.h \
462
	mappers/mapper_UxROM.c \
463
	mappers/mapper_UxROM.h \
464
	mappers/mapper_VRC1.c \
465
	mappers/mapper_VRC1.h \
466
	mappers/mapper_VRC2.c \
467
	mappers/mapper_VRC2.h \
468
	mappers/mapper_VRC3.c \
469
	mappers/mapper_VRC3.h \
470
	mappers/mapper_VRC4.c \
471
	mappers/mapper_VRC4.h \
472
	mappers/mapper_VRC6.c \
473
	mappers/mapper_VRC6.h \
474
	mappers/mapper_VRC7.c \
475
	mappers/mapper_VRC7.h \
476
	mappers/mapper_VRC7_snd.c \
477
	mappers/mapper_VRC7_snd.h \
478
	mappers/mapper_Vs.c \
479
	mappers/mapper_Vs.h \
480
	mappers/mapper_Waixing.c \
481
	mappers/mapper_Waixing.h \
482
	mappers/mapper_Whirlwind.c \
483
	mappers/mapper_Whirlwind.h \
484
	mappers/mapper_YOKO.c \
485
	mappers/mapper_YOKO.h
486
487
patcher_xdelta3_wrap.o: patcher_xdelta3_wrap.c patcher_xdelta3_wrap.h
488
	${CC} -w ${DEFS} ${DEFAULT_INCLUDES} ${CFLAGS} -c -o $@ $<
(-)puNES-0.105.org/src/core/mappers/mapper_105.c (-3 / +21 lines)
Lines 58-64 INLINE static void swap_prg_rom_105(void Link Here
58
58
59
enum MMC1_regs { CTRL, CHR0, CHR1, PRG0 };
59
enum MMC1_regs { CTRL, CHR0, CHR1, PRG0 };
60
60
61
uint32_t counter_must_reach;
61
struct _m105 {
62
	BYTE reg;
63
	BYTE pos;
64
	BYTE ctrl;
65
	BYTE reset;
66
	struct _prg_m105 {
67
		BYTE mode;
68
		BYTE locked;
69
		BYTE upper;
70
		BYTE reg[2];
71
	} prg;
72
	struct _irq_m105 {
73
		BYTE reg;
74
		uint32_t count;
75
	} irq;
76
} m105;
77
struct _m105tmp {
78
	uint32_t counter_must_reach;
79
} m105tmp;
62
80
63
void map_init_105(void) {
81
void map_init_105(void) {
64
	EXTCL_CPU_WR_MEM(105);
82
	EXTCL_CPU_WR_MEM(105);
Lines 67-73 void map_init_105(void) { Link Here
67
	mapper.internal_struct[0] = (BYTE *) &m105;
85
	mapper.internal_struct[0] = (BYTE *) &m105;
68
	mapper.internal_struct_size[0] = sizeof(m105);
86
	mapper.internal_struct_size[0] = sizeof(m105);
69
87
70
	counter_must_reach = M105_DIPSWITCH << 25;
88
	m105tmp.counter_must_reach = M105_DIPSWITCH << 25;
71
89
72
	if (info.reset >= HARD) {
90
	if (info.reset >= HARD) {
73
		memset(&m105, 0x00, sizeof(m105));
91
		memset(&m105, 0x00, sizeof(m105));
Lines 180-186 BYTE extcl_save_mapper_105(BYTE mode, BY Link Here
180
}
198
}
181
void extcl_cpu_every_cycle_105(void) {
199
void extcl_cpu_every_cycle_105(void) {
182
	if (!m105.irq.reg) {
200
	if (!m105.irq.reg) {
183
		if (++m105.irq.count == counter_must_reach) {
201
		if (++m105.irq.count == m105tmp.counter_must_reach) {
184
			m105.irq.count = 0;
202
			m105.irq.count = 0;
185
			irq.high |= EXT_IRQ;
203
			irq.high |= EXT_IRQ;
186
		}
204
		}
(-)puNES-0.105.org/src/core/mappers/mapper_105.h (-17 lines)
Lines 21-43 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct m105 {
25
	BYTE reg;
26
	BYTE pos;
27
	BYTE ctrl;
28
	BYTE reset;
29
	struct _prg_m105 {
30
		BYTE mode;
31
		BYTE locked;
32
		BYTE upper;
33
		BYTE reg[2];
34
	} prg;
35
	struct _irq_m105 {
36
		BYTE reg;
37
		uint32_t count;
38
	} irq;
39
} m105;
40
41
void map_init_105(void);
24
void map_init_105(void);
42
void extcl_cpu_wr_mem_105(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_105(WORD address, BYTE value);
43
BYTE extcl_save_mapper_105(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_105(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_114.c (+6 lines)
Lines 34-39 Link Here
34
	mapper.rom_map_to[2] = m114.prg_rom_bank[2];\
34
	mapper.rom_map_to[2] = m114.prg_rom_bank[2];\
35
	mapper.rom_map_to[3] = m114.prg_rom_bank[3]
35
	mapper.rom_map_to[3] = m114.prg_rom_bank[3]
36
36
37
struct _m114 {
38
	BYTE prg_rom_switch;
39
	BYTE mmc3_ctrl_change;
40
	WORD prg_rom_bank[4];
41
} m114;
42
37
void map_init_114(void) {
43
void map_init_114(void) {
38
	EXTCL_CPU_WR_MEM(114);
44
	EXTCL_CPU_WR_MEM(114);
39
	EXTCL_SAVE_MAPPER(114);
45
	EXTCL_SAVE_MAPPER(114);
(-)puNES-0.105.org/src/core/mappers/mapper_114.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m114 {
25
	BYTE prg_rom_switch;
26
	BYTE mmc3_ctrl_change;
27
	WORD prg_rom_bank[4];
28
} m114;
29
30
static const BYTE vlu114[8] = {0, 3, 1, 5, 6, 7, 2, 4};
24
static const BYTE vlu114[8] = {0, 3, 1, 5, 6, 7, 2, 4};
31
25
32
void map_init_114(void);
26
void map_init_114(void);
(-)puNES-0.105.org/src/core/mappers/mapper_116.c (+25 lines)
Lines 384-389 Link Here
384
	}\
384
	}\
385
}
385
}
386
386
387
struct _m116 {
388
	BYTE mode;
389
390
	struct {
391
		WORD chr[8];
392
		WORD prg[4];
393
		BYTE nmt;
394
		BYTE padding;
395
	} mode0;
396
	struct {
397
		WORD banks[10];
398
		BYTE ctrl;
399
		BYTE nmt;
400
	} mode1;
401
	struct {
402
		BYTE reg[4];
403
		BYTE buffer;
404
		BYTE shifter;
405
		BYTE padding[2];
406
	} mode2;
407
408
	WORD prg_map[4];
409
	WORD chr_map[8];
410
} m116;
411
387
void map_init_116(void) {
412
void map_init_116(void) {
388
	switch (info.mapper.submapper) {
413
	switch (info.mapper.submapper) {
389
		default:
414
		default:
(-)puNES-0.105.org/src/core/mappers/mapper_116.h (-25 lines)
Lines 27-57 enum { Link Here
27
	MAP116_TYPE_C
27
	MAP116_TYPE_C
28
};
28
};
29
29
30
struct _m116 {
31
	BYTE mode;
32
33
	struct {
34
		WORD chr[8];
35
		WORD prg[4];
36
		BYTE nmt;
37
		BYTE padding;
38
	} mode0;
39
	struct {
40
		WORD banks[10];
41
		BYTE ctrl;
42
		BYTE nmt;
43
	} mode1;
44
	struct {
45
		BYTE reg[4];
46
		BYTE buffer;
47
		BYTE shifter;
48
		BYTE padding[2];
49
	} mode2;
50
51
	WORD prg_map[4];
52
	WORD chr_map[8];
53
} m116;
54
55
void map_init_116(void);
30
void map_init_116(void);
56
31
57
void extcl_cpu_wr_mem_116_type_A(WORD address, BYTE value);
32
void extcl_cpu_wr_mem_116_type_A(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_120.c (+4 lines)
Lines 23-28 Link Here
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _m120 {
27
	BYTE *prg_ram_rd;
28
} m120;
29
26
void map_init_120(void) {
30
void map_init_120(void) {
27
	EXTCL_CPU_WR_MEM(120);
31
	EXTCL_CPU_WR_MEM(120);
28
	EXTCL_CPU_RD_MEM(120);
32
	EXTCL_CPU_RD_MEM(120);
(-)puNES-0.105.org/src/core/mappers/mapper_120.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m120 {
25
	BYTE *prg_ram_rd;
26
} m120;
27
28
void map_init_120(void);
24
void map_init_120(void);
29
void extcl_cpu_wr_mem_120(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_120(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_120(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_120(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_121.c (+5 lines)
Lines 79-84 INLINE static void m121_update_chr(void) Link Here
79
			break;\
79
			break;\
80
	}
80
	}
81
81
82
struct _m121 {
83
	BYTE reg[8];
84
	WORD prg_map[4];
85
	WORD chr_map[8];
86
} m121;
82
static const BYTE vlu121[4] = { 0x83, 0x83, 0x42, 0x00 };
87
static const BYTE vlu121[4] = { 0x83, 0x83, 0x42, 0x00 };
83
88
84
void map_init_121(void) {
89
void map_init_121(void) {
(-)puNES-0.105.org/src/core/mappers/mapper_121.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m121 {
25
	BYTE reg[8];
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} m121;
29
30
void map_init_121(void);
24
void map_init_121(void);
31
void extcl_cpu_wr_mem_121(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_121(WORD address, BYTE value);
32
BYTE extcl_cpu_rd_mem_121(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_121(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_134.c (+6 lines)
Lines 155-160 Link Here
155
	}\
155
	}\
156
}
156
}
157
157
158
struct _m134 {
159
	BYTE reg;
160
	WORD prg_map[4];
161
	WORD chr_map[8];
162
} m134;
163
158
void map_init_134(void) {
164
void map_init_134(void) {
159
	EXTCL_CPU_WR_MEM(134);
165
	EXTCL_CPU_WR_MEM(134);
160
	EXTCL_SAVE_MAPPER(134);
166
	EXTCL_SAVE_MAPPER(134);
(-)puNES-0.105.org/src/core/mappers/mapper_134.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m134 {
25
	BYTE reg;
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} m134;
29
30
void map_init_134(void);
24
void map_init_134(void);
31
void extcl_cpu_wr_mem_134(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_134(WORD address, BYTE value);
32
BYTE extcl_save_mapper_134(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_134(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_156.c (+7 lines)
Lines 24-29 Link Here
24
24
25
INLINE static void chr_setup_156(void);
25
INLINE static void chr_setup_156(void);
26
26
27
struct _m156 {
28
	struct _m156_chr {
29
		BYTE low[8];
30
		BYTE high[8];
31
	} chr;
32
} m156;
33
27
void map_init_156(void) {
34
void map_init_156(void) {
28
	EXTCL_CPU_WR_MEM(156);
35
	EXTCL_CPU_WR_MEM(156);
29
	EXTCL_SAVE_MAPPER(156);
36
	EXTCL_SAVE_MAPPER(156);
(-)puNES-0.105.org/src/core/mappers/mapper_156.h (-7 lines)
Lines 21-33 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m156 {
25
	struct _m156_chr {
26
		BYTE low[8];
27
		BYTE high[8];
28
	} chr;
29
} m156;
30
31
void map_init_156(void);
24
void map_init_156(void);
32
void extcl_cpu_wr_mem_156(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_156(WORD address, BYTE value);
33
BYTE extcl_save_mapper_156(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_156(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_163.c (+9 lines)
Lines 23-28 Link Here
23
#include "ppu.h"
23
#include "ppu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _m163 {
27
	BYTE prg;
28
	BYTE chr;
29
	BYTE reg;
30
	BYTE security;
31
	BYTE trigger;
32
	BYTE chr_mode;
33
} m163;
34
26
void map_init_163(void) {
35
void map_init_163(void) {
27
	EXTCL_CPU_WR_MEM(163);
36
	EXTCL_CPU_WR_MEM(163);
28
	EXTCL_CPU_RD_MEM(163);
37
	EXTCL_CPU_RD_MEM(163);
(-)puNES-0.105.org/src/core/mappers/mapper_163.h (-9 lines)
Lines 21-35 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m163 {
25
	BYTE prg;
26
	BYTE chr;
27
	BYTE reg;
28
	BYTE security;
29
	BYTE trigger;
30
	BYTE chr_mode;
31
} m163;
32
33
void map_init_163(void);
24
void map_init_163(void);
34
void extcl_cpu_wr_mem_163(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_163(WORD address, BYTE value);
35
BYTE extcl_cpu_rd_mem_163(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_163(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_164.c (+4 lines)
Lines 23-28 Link Here
23
#include "ppu.h"
23
#include "ppu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _m164 {
27
	BYTE prg;
28
} m164;
29
26
void map_init_164(void) {
30
void map_init_164(void) {
27
	EXTCL_CPU_WR_MEM(164);
31
	EXTCL_CPU_WR_MEM(164);
28
	EXTCL_CPU_RD_MEM(164);
32
	EXTCL_CPU_RD_MEM(164);
(-)puNES-0.105.org/src/core/mappers/mapper_164.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m164 {
25
	BYTE prg;
26
} m164;
27
28
void map_init_164(void);
24
void map_init_164(void);
29
void extcl_cpu_wr_mem_164(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_164(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_164(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_164(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_166.c (+4 lines)
Lines 21-26 Link Here
21
#include "info.h"
21
#include "info.h"
22
#include "save_slot.h"
22
#include "save_slot.h"
23
23
24
struct _m166 {
25
	BYTE reg[4];
26
} m166;
27
24
void map_init_166(void) {
28
void map_init_166(void) {
25
	EXTCL_CPU_WR_MEM(166);
29
	EXTCL_CPU_WR_MEM(166);
26
	EXTCL_SAVE_MAPPER(166);
30
	EXTCL_SAVE_MAPPER(166);
(-)puNES-0.105.org/src/core/mappers/mapper_166.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m166 {
25
	BYTE reg[4];
26
} m166;
27
28
void map_init_166(void);
24
void map_init_166(void);
29
void extcl_cpu_wr_mem_166(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_166(WORD address, BYTE value);
30
BYTE extcl_save_mapper_166(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_166(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_167.c (+4 lines)
Lines 21-26 Link Here
21
#include "info.h"
21
#include "info.h"
22
#include "save_slot.h"
22
#include "save_slot.h"
23
23
24
struct _m167 {
25
	BYTE reg[4];
26
} m167;
27
24
void map_init_167(void) {
28
void map_init_167(void) {
25
	EXTCL_CPU_WR_MEM(167);
29
	EXTCL_CPU_WR_MEM(167);
26
	EXTCL_SAVE_MAPPER(167);
30
	EXTCL_SAVE_MAPPER(167);
(-)puNES-0.105.org/src/core/mappers/mapper_167.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m167 {
25
	BYTE reg[4];
26
} m167;
27
28
void map_init_167(void);
24
void map_init_167(void);
29
void extcl_cpu_wr_mem_167(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_167(WORD address, BYTE value);
30
BYTE extcl_save_mapper_167(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_167(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_168.c (+4 lines)
Lines 25-30 Link Here
25
25
26
INLINE static void m168_update_chr(void);
26
INLINE static void m168_update_chr(void);
27
27
28
struct _m168 {
29
	WORD chr_map[8];
30
} m168;
31
28
void map_init_168(void) {
32
void map_init_168(void) {
29
	EXTCL_CPU_WR_MEM(168);
33
	EXTCL_CPU_WR_MEM(168);
30
	EXTCL_SAVE_MAPPER(168);
34
	EXTCL_SAVE_MAPPER(168);
(-)puNES-0.105.org/src/core/mappers/mapper_168.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m168 {
25
	WORD chr_map[8];
26
} m168;
27
28
void map_init_168(void);
24
void map_init_168(void);
29
void extcl_cpu_wr_mem_168(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_168(WORD address, BYTE value);
30
BYTE extcl_save_mapper_168(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_168(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_178.c (-7 / +13 lines)
Lines 24-30 Link Here
24
24
25
INLINE static void prg_setup_178(void);
25
INLINE static void prg_setup_178(void);
26
26
27
BYTE model;
27
struct _m178 {
28
	BYTE reg[3];
29
	BYTE prg_mode;
30
} m178;
31
struct _m178tmp {
32
	BYTE model;
33
} m178tmp;
28
34
29
void map_init_178(BYTE type) {
35
void map_init_178(BYTE type) {
30
	EXTCL_CPU_WR_MEM(178);
36
	EXTCL_CPU_WR_MEM(178);
Lines 41-47 void map_init_178(BYTE type) { Link Here
41
47
42
	info.mapper.extend_wr = TRUE;
48
	info.mapper.extend_wr = TRUE;
43
49
44
	model = type;
50
	m178tmp.model = type;
45
}
51
}
46
void extcl_cpu_wr_mem_178(WORD address, BYTE value) {
52
void extcl_cpu_wr_mem_178(WORD address, BYTE value) {
47
	switch (address) {
53
	switch (address) {
Lines 55-61 void extcl_cpu_wr_mem_178(WORD address, Link Here
55
			prg_setup_178();
61
			prg_setup_178();
56
			return;
62
			return;
57
		case 0x4801:
63
		case 0x4801:
58
			if (model == M178EC32IN1) {
64
			if (m178tmp.model == M178EC32IN1) {
59
				m178.reg[1] = value;
65
				m178.reg[1] = value;
60
			} else {
66
			} else {
61
				m178.reg[0] = value;
67
				m178.reg[0] = value;
Lines 63-69 void extcl_cpu_wr_mem_178(WORD address, Link Here
63
			prg_setup_178();
69
			prg_setup_178();
64
			return;
70
			return;
65
		case 0x4802:
71
		case 0x4802:
66
			if (model == M178EC32IN1) {
72
			if (m178tmp.model == M178EC32IN1) {
67
				m178.reg[0] = value;
73
				m178.reg[0] = value;
68
			} else {
74
			} else {
69
				m178.reg[1] = value;
75
				m178.reg[1] = value;
Lines 86-92 BYTE extcl_save_mapper_178(BYTE mode, BY Link Here
86
INLINE static void prg_setup_178(void) {
92
INLINE static void prg_setup_178(void) {
87
	DBWORD value;
93
	DBWORD value;
88
94
89
	if (model == M178EC32IN1) {
95
	if (m178tmp.model == M178EC32IN1) {
90
		value = (m178.reg[1] << 3) | ((m178.reg[0] & 0x07) << 1);
96
		value = (m178.reg[1] << 3) | ((m178.reg[0] & 0x07) << 1);
91
	} else {
97
	} else {
92
		value = (m178.reg[1] << 3) | (m178.reg[0] & 0x07);
98
		value = (m178.reg[1] << 3) | (m178.reg[0] & 0x07);
Lines 101-107 INLINE static void prg_setup_178(void) { Link Here
101
		case 1:
107
		case 1:
102
			control_bank(info.prg.rom[0].max.banks_16k)
108
			control_bank(info.prg.rom[0].max.banks_16k)
103
			map_prg_rom_8k(2, 0, value);
109
			map_prg_rom_8k(2, 0, value);
104
			if (model == M178EC32IN1) {
110
			if (m178tmp.model == M178EC32IN1) {
105
				value = (m178.reg[1] << 3) | 0x07;
111
				value = (m178.reg[1] << 3) | 0x07;
106
			} else {
112
			} else {
107
				value = (m178.reg[1] << 3) | 0x07;
113
				value = (m178.reg[1] << 3) | 0x07;
Lines 117-123 INLINE static void prg_setup_178(void) { Link Here
117
		case 3:
123
		case 3:
118
			control_bank(info.prg.rom[0].max.banks_16k)
124
			control_bank(info.prg.rom[0].max.banks_16k)
119
			map_prg_rom_8k(2, 0, value);
125
			map_prg_rom_8k(2, 0, value);
120
			if (model == M178EC32IN1) {
126
			if (m178tmp.model == M178EC32IN1) {
121
				value = (m178.reg[1] << 3) | 0x06 | ((m178.reg[0] & 0x01) << 1);
127
				value = (m178.reg[1] << 3) | 0x06 | ((m178.reg[0] & 0x01) << 1);
122
			} else {
128
			} else {
123
				value = (m178.reg[1] << 3) | 0x06 | (m178.reg[0] & 0x01);
129
				value = (m178.reg[1] << 3) | 0x06 | (m178.reg[0] & 0x01);
(-)puNES-0.105.org/src/core/mappers/mapper_178.h (-5 lines)
Lines 23-33 Link Here
23
23
24
enum { M178EC32IN1 };
24
enum { M178EC32IN1 };
25
25
26
struct _m178 {
27
	BYTE reg[3];
28
	BYTE prg_mode;
29
} m178;
30
31
void map_init_178(BYTE type);
26
void map_init_178(BYTE type);
32
void extcl_cpu_wr_mem_178(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_178(WORD address, BYTE value);
33
BYTE extcl_save_mapper_178(BYTE mode, BYTE slot, FILE *fp);
28
BYTE extcl_save_mapper_178(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_183.c (+8 lines)
Lines 23-28 Link Here
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _m183 {
27
	BYTE enabled;
28
	BYTE prescaler;
29
	BYTE count;
30
	BYTE delay;
31
	BYTE chr_rom_bank[8];
32
} m183;
33
26
void map_init_183(void) {
34
void map_init_183(void) {
27
	EXTCL_CPU_WR_MEM(183);
35
	EXTCL_CPU_WR_MEM(183);
28
	EXTCL_CPU_RD_MEM(183);
36
	EXTCL_CPU_RD_MEM(183);
(-)puNES-0.105.org/src/core/mappers/mapper_183.h (-8 lines)
Lines 21-34 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m183 {
25
	BYTE enabled;
26
	BYTE prescaler;
27
	BYTE count;
28
	BYTE delay;
29
	BYTE chr_rom_bank[8];
30
} m183;
31
32
void map_init_183(void);
24
void map_init_183(void);
33
void extcl_cpu_wr_mem_183(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_183(WORD address, BYTE value);
34
BYTE extcl_cpu_rd_mem_183(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_183(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_186.c (+4 lines)
Lines 23-28 Link Here
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _m186 {
27
	BYTE *prg_ram_bank2;
28
} m186;
29
26
void map_init_186(void) {
30
void map_init_186(void) {
27
	EXTCL_CPU_WR_MEM(186);
31
	EXTCL_CPU_WR_MEM(186);
28
	EXTCL_CPU_RD_MEM(186);
32
	EXTCL_CPU_RD_MEM(186);
(-)puNES-0.105.org/src/core/mappers/mapper_186.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m186 {
25
	BYTE *prg_ram_bank2;
26
} m186;
27
28
void map_init_186(void);
24
void map_init_186(void);
29
void extcl_cpu_wr_mem_186(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_186(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_186(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_186(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_187.c (+5 lines)
Lines 77-82 INLINE static void m187_update_chr(void) Link Here
77
			break;\
77
			break;\
78
	}
78
	}
79
79
80
struct _m187 {
81
	BYTE reg[8];
82
	WORD prg_map[4];
83
	WORD chr_map[8];
84
} m187;
80
static const BYTE vlu187[4] = { 0x83, 0x83, 0x42, 0x00 };
85
static const BYTE vlu187[4] = { 0x83, 0x83, 0x42, 0x00 };
81
86
82
void map_init_187(void) {
87
void map_init_187(void) {
(-)puNES-0.105.org/src/core/mappers/mapper_187.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m187 {
25
	BYTE reg[8];
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} m187;
29
30
void map_init_187(void);
24
void map_init_187(void);
31
void extcl_cpu_wr_mem_187(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_187(WORD address, BYTE value);
32
BYTE extcl_cpu_rd_mem_187(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_187(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_196.c (+5 lines)
Lines 43-48 INLINE static void m196_update_prg(void) Link Here
43
			break;\
43
			break;\
44
	}
44
	}
45
45
46
struct _m196 {
47
	BYTE reg[2];
48
	WORD prg_map[4];
49
} m196;
50
46
void map_init_196(void) {
51
void map_init_196(void) {
47
	EXTCL_CPU_WR_MEM(196);
52
	EXTCL_CPU_WR_MEM(196);
48
	EXTCL_SAVE_MAPPER(196);
53
	EXTCL_SAVE_MAPPER(196);
(-)puNES-0.105.org/src/core/mappers/mapper_196.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m196 {
25
	BYTE reg[2];
26
	WORD prg_map[4];
27
} m196;
28
29
void map_init_196(void);
24
void map_init_196(void);
30
void extcl_cpu_wr_mem_196(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_196(WORD address, BYTE value);
31
BYTE extcl_save_mapper_196(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_196(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_197.c (+4 lines)
Lines 63-68 INLINE static void m197_update_chr(void) Link Here
63
			break;\
63
			break;\
64
	}
64
	}
65
65
66
struct _m197 {
67
	WORD chr_map[8];
68
} m197;
69
66
void map_init_197(void) {
70
void map_init_197(void) {
67
	EXTCL_CPU_WR_MEM(197);
71
	EXTCL_CPU_WR_MEM(197);
68
	EXTCL_SAVE_MAPPER(197);
72
	EXTCL_SAVE_MAPPER(197);
(-)puNES-0.105.org/src/core/mappers/mapper_197.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m197 {
25
	WORD chr_map[8];
26
} m197;
27
28
void map_init_197(void);
24
void map_init_197(void);
29
void extcl_cpu_wr_mem_197(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_197(WORD address, BYTE value);
30
BYTE extcl_save_mapper_197(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_197(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_205.c (+2 lines)
Lines 79-84 INLINE static void m205_update_chr(void) Link Here
79
			break;\
79
			break;\
80
	}
80
	}
81
81
82
_m205 m205;
83
82
void map_init_205(void) {
84
void map_init_205(void) {
83
	EXTCL_CPU_WR_MEM(205);
85
	EXTCL_CPU_WR_MEM(205);
84
	EXTCL_SAVE_MAPPER(205);
86
	EXTCL_SAVE_MAPPER(205);
(-)puNES-0.105.org/src/core/mappers/mapper_205.h (-2 / +4 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m205 {
24
typedef struct _m205 {
25
	BYTE reg[2];
25
	BYTE reg[2];
26
	WORD prg_map[4];
26
	WORD prg_map[4];
27
	WORD chr_map[8];
27
	WORD chr_map[8];
28
} m205;
28
} _m205;
29
30
extern _m205 m205;
29
31
30
void map_init_205(void);
32
void map_init_205(void);
31
void extcl_cpu_wr_mem_205(WORD address, BYTE value);
33
void extcl_cpu_wr_mem_205(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_208.c (+4 lines)
Lines 24-29 Link Here
24
#include "irqA12.h"
24
#include "irqA12.h"
25
#include "save_slot.h"
25
#include "save_slot.h"
26
26
27
struct _m208 {
28
	BYTE ctrl;
29
	BYTE reg[4];
30
} m208;
27
static const BYTE vlu208[256] = {
31
static const BYTE vlu208[256] = {
28
		0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,
32
		0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59, 0x59,
29
		0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
33
		0x59, 0x49, 0x19, 0x09, 0x59, 0x49, 0x19, 0x09,
(-)puNES-0.105.org/src/core/mappers/mapper_208.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m208 {
25
	BYTE ctrl;
26
	BYTE reg[4];
27
} m208;
28
29
void map_init_208(void);
24
void map_init_208(void);
30
void extcl_cpu_wr_mem_208(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_208(WORD address, BYTE value);
31
BYTE extcl_cpu_rd_mem_208(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_208(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_215.c (+5 lines)
Lines 158-163 Link Here
158
	}\
158
	}\
159
}
159
}
160
160
161
struct _m215 {
162
	BYTE reg[4];
163
	WORD prg_8k_bank[4];
164
} m215;
165
161
void map_init_215(void) {
166
void map_init_215(void) {
162
	EXTCL_CPU_WR_MEM(215);
167
	EXTCL_CPU_WR_MEM(215);
163
	EXTCL_SAVE_MAPPER(215);
168
	EXTCL_SAVE_MAPPER(215);
(-)puNES-0.105.org/src/core/mappers/mapper_215.h (-5 lines)
Lines 23-33 Link Here
23
23
24
enum { M215_MK3E };
24
enum { M215_MK3E };
25
25
26
struct _m215 {
27
	BYTE reg[4];
28
	WORD prg_8k_bank[4];
29
} m215;
30
31
void map_init_215(void);
26
void map_init_215(void);
32
void extcl_cpu_wr_mem_215(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_215(WORD address, BYTE value);
33
BYTE extcl_save_mapper_215(BYTE mode, BYTE slot, FILE *fp);
28
BYTE extcl_save_mapper_215(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_217.c (+5 lines)
Lines 136-141 Link Here
136
	}\
136
	}\
137
}
137
}
138
138
139
struct _m217 {
140
	BYTE reg[4];
141
	WORD prg_8k_bank[4];
142
} m217;
143
139
void map_init_217(void) {
144
void map_init_217(void) {
140
	EXTCL_CPU_WR_MEM(217);
145
	EXTCL_CPU_WR_MEM(217);
141
	EXTCL_SAVE_MAPPER(217);
146
	EXTCL_SAVE_MAPPER(217);
(-)puNES-0.105.org/src/core/mappers/mapper_217.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m217 {
25
	BYTE reg[4];
26
	WORD prg_8k_bank[4];
27
} m217;
28
29
void map_init_217(void);
24
void map_init_217(void);
30
void extcl_cpu_wr_mem_217(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_217(WORD address, BYTE value);
31
BYTE extcl_save_mapper_217(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_217(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_219.c (+4 lines)
Lines 28-33 Link Here
28
	control_bank(info.chr.rom[0].max.banks_1k)\
28
	control_bank(info.chr.rom[0].max.banks_1k)\
29
	chr.bank_1k[b] = chr_chip_byte_pnt(0, value << 10)
29
	chr.bank_1k[b] = chr_chip_byte_pnt(0, value << 10)
30
30
31
struct _m219 {
32
	BYTE reg[3];
33
} m219;
34
31
void map_init_219(void) {
35
void map_init_219(void) {
32
	EXTCL_CPU_WR_MEM(219);
36
	EXTCL_CPU_WR_MEM(219);
33
	EXTCL_SAVE_MAPPER(219);
37
	EXTCL_SAVE_MAPPER(219);
(-)puNES-0.105.org/src/core/mappers/mapper_219.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m219 {
25
	BYTE reg[3];
26
} m219;
27
28
void map_init_219(void);
24
void map_init_219(void);
29
void extcl_cpu_wr_mem_219(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_219(WORD address, BYTE value);
30
BYTE extcl_save_mapper_219(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_219(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_221.c (+4 lines)
Lines 32-37 Link Here
32
	control_bank(info.prg.rom[0].max.banks_16k)\
32
	control_bank(info.prg.rom[0].max.banks_16k)\
33
	map_prg_rom_8k(2, 2, value)
33
	map_prg_rom_8k(2, 2, value)
34
34
35
struct _m221 {
36
	BYTE reg[2];
37
} m221;
38
35
void map_init_221(void) {
39
void map_init_221(void) {
36
	EXTCL_CPU_WR_MEM(221);
40
	EXTCL_CPU_WR_MEM(221);
37
	EXTCL_SAVE_MAPPER(221);
41
	EXTCL_SAVE_MAPPER(221);
(-)puNES-0.105.org/src/core/mappers/mapper_221.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m221 {
25
	BYTE reg[2];
26
} m221;
27
28
void map_init_221(void);
24
void map_init_221(void);
29
void extcl_cpu_wr_mem_221(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_221(WORD address, BYTE value);
30
BYTE extcl_save_mapper_221(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_221(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_222.c (+5 lines)
Lines 24-29 Link Here
24
#include "irqA12.h"
24
#include "irqA12.h"
25
#include "save_slot.h"
25
#include "save_slot.h"
26
26
27
struct _m222 {
28
	BYTE count;
29
	BYTE delay;
30
} m222;
31
27
void map_init_222(void) {
32
void map_init_222(void) {
28
	EXTCL_CPU_WR_MEM(222);
33
	EXTCL_CPU_WR_MEM(222);
29
	EXTCL_SAVE_MAPPER(222);
34
	EXTCL_SAVE_MAPPER(222);
(-)puNES-0.105.org/src/core/mappers/mapper_222.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m222 {
25
	BYTE count;
26
	BYTE delay;
27
} m222;
28
29
void map_init_222(void);
24
void map_init_222(void);
30
void extcl_cpu_wr_mem_222(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_222(WORD address, BYTE value);
31
BYTE extcl_save_mapper_222(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_222(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_226.c (+4 lines)
Lines 22-27 Link Here
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
struct _m226 {
26
	BYTE reg[2];
27
} m226;
28
25
void map_init_226(void) {
29
void map_init_226(void) {
26
	EXTCL_CPU_WR_MEM(226);
30
	EXTCL_CPU_WR_MEM(226);
27
	EXTCL_SAVE_MAPPER(226);
31
	EXTCL_SAVE_MAPPER(226);
(-)puNES-0.105.org/src/core/mappers/mapper_226.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m226 {
25
	BYTE reg[2];
26
} m226;
27
28
void map_init_226(void);
24
void map_init_226(void);
29
void extcl_cpu_wr_mem_226(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_226(WORD address, BYTE value);
30
BYTE extcl_save_mapper_226(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_226(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_230.c (+4 lines)
Lines 21-26 Link Here
21
#include "mem_map.h"
21
#include "mem_map.h"
22
#include "save_slot.h"
22
#include "save_slot.h"
23
23
24
struct _m230 {
25
	BYTE mode;
26
} m230;
27
24
void map_init_230(void) {
28
void map_init_230(void) {
25
	EXTCL_CPU_WR_MEM(230);
29
	EXTCL_CPU_WR_MEM(230);
26
	EXTCL_SAVE_MAPPER(230);
30
	EXTCL_SAVE_MAPPER(230);
(-)puNES-0.105.org/src/core/mappers/mapper_230.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m230 {
25
	BYTE mode;
26
} m230;
27
28
void map_init_230(void);
24
void map_init_230(void);
29
void extcl_cpu_wr_mem_230(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_230(WORD address, BYTE value);
30
BYTE extcl_save_mapper_230(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_230(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_235.c (-8 / +13 lines)
Lines 28-54 static const BYTE slots[4][4][2] = { Link Here
28
	{ { 0x00, 0 }, { 0x20, 0 }, { 0x40, 0 }, { 0x60, 0 } }
28
	{ { 0x00, 0 }, { 0x20, 0 }, { 0x40, 0 }, { 0x60, 0 } }
29
};
29
};
30
30
31
BYTE type;
31
struct _m235 {
32
	BYTE openbus;
33
} m235;
34
struct _m235tmp {
35
	BYTE type;
36
} m235tmp;
32
37
33
void map_init_235(void) {
38
void map_init_235(void) {
34
	switch (info.prg.rom[0].banks_16k) {
39
	switch (info.prg.rom[0].banks_16k) {
35
		case 64:
40
		case 64:
36
			type = 0;
41
			m235tmp.type = 0;
37
			break;
42
			break;
38
		case 128:
43
		case 128:
39
			type = 1;
44
			m235tmp.type = 1;
40
			break;
45
			break;
41
		case 192:
46
		case 192:
42
			type = 2;
47
			m235tmp.type = 2;
43
			break;
48
			break;
44
		case 256:
49
		case 256:
45
		default:
50
		default:
46
			type = 3;
51
			m235tmp.type = 3;
47
			break;
52
			break;
48
	}
53
	}
49
54
50
	EXTCL_CPU_WR_MEM(235);
55
	EXTCL_CPU_WR_MEM(235);
51
	if (type != 3) {
56
	if (m235tmp.type != 3) {
52
		EXTCL_CPU_RD_MEM(235);
57
		EXTCL_CPU_RD_MEM(235);
53
		EXTCL_SAVE_MAPPER(235);
58
		EXTCL_SAVE_MAPPER(235);
54
		mapper.internal_struct[0] = (BYTE *) &m235;
59
		mapper.internal_struct[0] = (BYTE *) &m235;
Lines 63-70 void map_init_235(void) { Link Here
63
	}
68
	}
64
}
69
}
65
void extcl_cpu_wr_mem_235(WORD address, BYTE value) {
70
void extcl_cpu_wr_mem_235(WORD address, BYTE value) {
66
	BYTE bank = slots[type][(address >> 8) & 0x03][0] | (address & 0x1F);
71
	BYTE bank = slots[m235tmp.type][(address >> 8) & 0x03][0] | (address & 0x1F);
67
	m235.openbus = slots[type][(address >> 8) & 0x03][1];
72
	m235.openbus = slots[m235tmp.type][(address >> 8) & 0x03][1];
68
73
69
	if (address & 0x0800) {
74
	if (address & 0x0800) {
70
		value = (bank << 1) | ((address >> 12) & 0x01);
75
		value = (bank << 1) | ((address >> 12) & 0x01);
(-)puNES-0.105.org/src/core/mappers/mapper_235.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m235 {
25
	BYTE openbus;
26
} m235;
27
28
void map_init_235(void);
24
void map_init_235(void);
29
void extcl_cpu_wr_mem_235(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_235(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_235(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_235(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_249.c (+6 lines)
Lines 64-69 Link Here
64
	}
64
	}
65
*/
65
*/
66
66
67
struct _m249 {
68
	BYTE reg;
69
	WORD prg_map[4];
70
	WORD chr_map[8];
71
} m249;
72
67
void map_init_249(void) {
73
void map_init_249(void) {
68
	EXTCL_CPU_WR_MEM(249);
74
	EXTCL_CPU_WR_MEM(249);
69
	EXTCL_CPU_RD_MEM(249);
75
	EXTCL_CPU_RD_MEM(249);
(-)puNES-0.105.org/src/core/mappers/mapper_249.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m249 {
25
	BYTE reg;
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} m249;
29
30
void map_init_249(void);
24
void map_init_249(void);
31
void extcl_cpu_wr_mem_249(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_249(WORD address, BYTE value);
32
BYTE extcl_cpu_rd_mem_249(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_249(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_252.c (+10 lines)
Lines 28-33 Link Here
28
28
29
INLINE static void m252_update_chr_extra(void);
29
INLINE static void m252_update_chr_extra(void);
30
30
31
struct _m252 {
32
	WORD chr_map[8];
33
	struct _m252_irq {
34
		BYTE active;
35
		WORD prescaler;
36
		WORD count;
37
		WORD reload;
38
	} irq;
39
} m252;
40
31
void map_init_252(void) {
41
void map_init_252(void) {
32
	EXTCL_CPU_WR_MEM(252);
42
	EXTCL_CPU_WR_MEM(252);
33
	EXTCL_SAVE_MAPPER(252);
43
	EXTCL_SAVE_MAPPER(252);
(-)puNES-0.105.org/src/core/mappers/mapper_252.h (-10 lines)
Lines 21-36 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m252 {
25
	WORD chr_map[8];
26
	struct _m252_irq {
27
		BYTE active;
28
		WORD prescaler;
29
		WORD count;
30
		WORD reload;
31
	} irq;
32
} m252;
33
34
void map_init_252(void);
24
void map_init_252(void);
35
void extcl_cpu_wr_mem_252(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_252(WORD address, BYTE value);
36
BYTE extcl_save_mapper_252(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_252(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_253.c (+12 lines)
Lines 25-30 Link Here
25
25
26
INLINE static void m253_update_chr(void);
26
INLINE static void m253_update_chr(void);
27
27
28
struct _m253 {
29
	BYTE disabled_vram;
30
	WORD chr_map_high[8];
31
	BYTE chr_map[8];
32
	struct _m253_irq {
33
		BYTE active;
34
		WORD prescaler;
35
		WORD count;
36
		WORD reload;
37
	} irq;
38
} m253;
39
28
void map_init_253(void) {
40
void map_init_253(void) {
29
	EXTCL_CPU_WR_MEM(253);
41
	EXTCL_CPU_WR_MEM(253);
30
	EXTCL_SAVE_MAPPER(253);
42
	EXTCL_SAVE_MAPPER(253);
(-)puNES-0.105.org/src/core/mappers/mapper_253.h (-12 lines)
Lines 21-38 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m253 {
25
	BYTE disabled_vram;
26
	WORD chr_map_high[8];
27
	BYTE chr_map[8];
28
	struct _m253_irq {
29
		BYTE active;
30
		WORD prescaler;
31
		WORD count;
32
		WORD reload;
33
	} irq;
34
} m253;
35
36
void map_init_253(void);
24
void map_init_253(void);
37
void extcl_cpu_wr_mem_253(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_253(WORD address, BYTE value);
38
BYTE extcl_save_mapper_253(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_253(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_254.c (+4 lines)
Lines 23-28 Link Here
23
#include "irqA12.h"
23
#include "irqA12.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _m254 {
27
	BYTE reg[2];
28
} m254;
29
26
void map_init_254(void) {
30
void map_init_254(void) {
27
	EXTCL_CPU_WR_MEM(254);
31
	EXTCL_CPU_WR_MEM(254);
28
	EXTCL_CPU_RD_MEM(254);
32
	EXTCL_CPU_RD_MEM(254);
(-)puNES-0.105.org/src/core/mappers/mapper_254.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m254 {
25
	BYTE reg[2];
26
} m254;
27
28
void map_init_254(void);
24
void map_init_254(void);
29
void extcl_cpu_wr_mem_254(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_254(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_254(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_254(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_28.c (+5 lines)
Lines 28-33 INLINE static void nmt_setup_28(void); Link Here
28
INLINE static void prg_setup_28(void);
28
INLINE static void prg_setup_28(void);
29
INLINE static BYTE calc_prg_bank_28(WORD address);
29
INLINE static BYTE calc_prg_bank_28(WORD address);
30
30
31
struct _m28 {
32
	BYTE index;
33
	BYTE mirroring;
34
	BYTE prg[3];
35
} m28;
31
static BYTE const inner_and[4] = { 0x01, 0x03, 0x07, 0x0F };
36
static BYTE const inner_and[4] = { 0x01, 0x03, 0x07, 0x0F };
32
37
33
void map_init_28(void) {
38
void map_init_28(void) {
(-)puNES-0.105.org/src/core/mappers/mapper_28.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m28 {
25
	BYTE index;
26
	BYTE mirroring;
27
	BYTE prg[3];
28
} m28;
29
30
void map_init_28(void);
24
void map_init_28(void);
31
void extcl_cpu_wr_mem_28(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_28(WORD address, BYTE value);
32
BYTE extcl_cpu_rd_mem_28(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_28(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_31.c (-1 / +5 lines)
Lines 25-30 Link Here
25
25
26
INLINE static void sync_31(void);
26
INLINE static void sync_31(void);
27
27
28
struct _m31 {
29
	WORD regs[8];
30
	BYTE *rom_4k[8];
31
} m31;
32
28
void map_init_31(void) {
33
void map_init_31(void) {
29
	EXTCL_CPU_WR_MEM(31);
34
	EXTCL_CPU_WR_MEM(31);
30
	EXTCL_CPU_RD_MEM(31);
35
	EXTCL_CPU_RD_MEM(31);
Lines 39-45 void map_init_31(void) { Link Here
39
	info.mapper.extend_wr = TRUE;
44
	info.mapper.extend_wr = TRUE;
40
	info.mapper.extend_rd = TRUE;
45
	info.mapper.extend_rd = TRUE;
41
}
46
}
42
43
void extcl_cpu_wr_mem_31(WORD address, BYTE value) {
47
void extcl_cpu_wr_mem_31(WORD address, BYTE value) {
44
	if ((address < 0x5000) && (address > 0x5FFF)) {
48
	if ((address < 0x5000) && (address > 0x5FFF)) {
45
		return;
49
		return;
(-)puNES-0.105.org/src/core/mappers/mapper_31.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m31 {
25
	WORD regs[8];
26
	BYTE *rom_4k[8];
27
} m31;
28
29
void map_init_31(void);
24
void map_init_31(void);
30
void extcl_cpu_wr_mem_31(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_31(WORD address, BYTE value);
31
BYTE extcl_cpu_rd_mem_31(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_31(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_36.c (+4 lines)
Lines 23-28 Link Here
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _m36 {
27
	BYTE regs[5];
28
} m36;
29
26
void map_init_36(void) {
30
void map_init_36(void) {
27
	EXTCL_CPU_WR_MEM(36);
31
	EXTCL_CPU_WR_MEM(36);
28
	EXTCL_CPU_RD_MEM(36);
32
	EXTCL_CPU_RD_MEM(36);
(-)puNES-0.105.org/src/core/mappers/mapper_36.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m36 {
25
	BYTE regs[5];
26
} m36;
27
28
void map_init_36(void);
24
void map_init_36(void);
29
void extcl_cpu_wr_mem_36(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_36(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_36(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_36(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_37.c (+6 lines)
Lines 157-162 Link Here
157
	}\
157
	}\
158
}
158
}
159
159
160
struct _m37 {
161
	BYTE reg;
162
	WORD prg_map[4];
163
	WORD chr_map[8];
164
} m37;
165
160
void map_init_37(void) {
166
void map_init_37(void) {
161
	EXTCL_CPU_WR_MEM(37);
167
	EXTCL_CPU_WR_MEM(37);
162
	EXTCL_SAVE_MAPPER(37);
168
	EXTCL_SAVE_MAPPER(37);
(-)puNES-0.105.org/src/core/mappers/mapper_37.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m37 {
25
	BYTE reg;
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} m37;
29
30
void map_init_37(void);
24
void map_init_37(void);
31
void extcl_cpu_wr_mem_37(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_37(WORD address, BYTE value);
32
BYTE extcl_save_mapper_37(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_37(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_40.c (-3 / +10 lines)
Lines 23-29 Link Here
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
BYTE *prg_6000;
26
struct _m40 {
27
	BYTE enabled;
28
	WORD count;
29
	BYTE delay;
30
} m40;
31
struct _m40tmp {
32
	BYTE *prg_6000;
33
} m40tmp;
27
34
28
void map_init_40(void) {
35
void map_init_40(void) {
29
	EXTCL_CPU_WR_MEM(40);
36
	EXTCL_CPU_WR_MEM(40);
Lines 39-45 void map_init_40(void) { Link Here
39
		mapper.rom_map_to[2] = 0;
46
		mapper.rom_map_to[2] = 0;
40
	}
47
	}
41
48
42
	prg_6000 = prg_chip_byte_pnt(0, 6 << 13);
49
	m40tmp.prg_6000 = prg_chip_byte_pnt(0, 6 << 13);
43
50
44
	mapper.rom_map_to[0] = 4;
51
	mapper.rom_map_to[0] = 4;
45
	mapper.rom_map_to[1] = 5;
52
	mapper.rom_map_to[1] = 5;
Lines 73-79 BYTE extcl_cpu_rd_mem_40(WORD address, B Link Here
73
		return (openbus);
80
		return (openbus);
74
	}
81
	}
75
82
76
	return (prg_6000[address & 0x1FFF]);
83
	return (m40tmp.prg_6000[address & 0x1FFF]);
77
}
84
}
78
BYTE extcl_save_mapper_40(BYTE mode, BYTE slot, FILE *fp) {
85
BYTE extcl_save_mapper_40(BYTE mode, BYTE slot, FILE *fp) {
79
	save_slot_ele(mode, slot, m40.enabled);
86
	save_slot_ele(mode, slot, m40.enabled);
(-)puNES-0.105.org/src/core/mappers/mapper_40.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m40 {
25
	BYTE enabled;
26
	WORD count;
27
	BYTE delay;
28
} m40;
29
30
void map_init_40(void);
24
void map_init_40(void);
31
void extcl_cpu_wr_mem_40(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_40(WORD address, BYTE value);
32
BYTE extcl_cpu_rd_mem_40(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_40(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_42.c (+9 lines)
Lines 22-27 Link Here
22
#include "save_slot.h"
22
#include "save_slot.h"
23
#include "cpu.h"
23
#include "cpu.h"
24
24
25
struct _m42 {
26
	WORD rom_map_to;
27
	BYTE *prg_8k_6000;
28
	struct _m42_irq {
29
		BYTE active;
30
		uint32_t count;
31
	} irq;
32
} m42;
33
25
void map_init_42(void) {
34
void map_init_42(void) {
26
	EXTCL_CPU_WR_MEM(42);
35
	EXTCL_CPU_WR_MEM(42);
27
	EXTCL_CPU_RD_MEM(42);
36
	EXTCL_CPU_RD_MEM(42);
(-)puNES-0.105.org/src/core/mappers/mapper_42.h (-9 lines)
Lines 21-35 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m42 {
25
	WORD rom_map_to;
26
	BYTE *prg_8k_6000;
27
	struct _m42_irq {
28
		BYTE active;
29
		uint32_t count;
30
	} irq;
31
} m42;
32
33
void map_init_42(void);
24
void map_init_42(void);
34
void extcl_cpu_wr_mem_42(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_42(WORD address, BYTE value);
35
BYTE extcl_cpu_rd_mem_42(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_42(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_43.c (-5 / +15 lines)
Lines 26-42 Link Here
26
#define prg_5000_43()\
26
#define prg_5000_43()\
27
	value = 8 << 1;\
27
	value = 8 << 1;\
28
	control_bank(info.prg.rom[0].max.banks_4k)\
28
	control_bank(info.prg.rom[0].max.banks_4k)\
29
	prg_5000 = prg_chip_byte_pnt(0, value << 12)
29
	m43tmp.prg_5000 = prg_chip_byte_pnt(0, value << 12)
30
#define prg_6000_swap_43()\
30
#define prg_6000_swap_43()\
31
	value = m43.swap ? 0 : 2;\
31
	value = m43.swap ? 0 : 2;\
32
	control_bank(info.prg.rom[0].max.banks_8k)\
32
	control_bank(info.prg.rom[0].max.banks_8k)\
33
	prg_6000 = prg_chip_byte_pnt(0, value << 13)
33
	m43tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13)
34
#define prg_E000_swap_43()\
34
#define prg_E000_swap_43()\
35
	value = m43.swap ? 8 : 9;\
35
	value = m43.swap ? 8 : 9;\
36
	control_bank(info.prg.rom[0].max.banks_8k)\
36
	control_bank(info.prg.rom[0].max.banks_8k)\
37
	map_prg_rom_8k(1, 3, value)
37
	map_prg_rom_8k(1, 3, value)
38
38
39
BYTE *prg_5000, *prg_6000;
39
struct _m43 {
40
	BYTE swap;
41
	struct _m43_irq {
42
		BYTE active;
43
		WORD count;
44
	} irq;
45
} m43;
46
struct _m43tmp {
47
	BYTE *prg_5000;
48
	BYTE *prg_6000;
49
} m43tmp;
40
50
41
void map_init_43(void) {
51
void map_init_43(void) {
42
	EXTCL_CPU_WR_MEM(43);
52
	EXTCL_CPU_WR_MEM(43);
Lines 93-102 BYTE extcl_cpu_rd_mem_43(WORD address, B Link Here
93
	}
103
	}
94
104
95
	if (address < 0x6000) {
105
	if (address < 0x6000) {
96
		return (prg_5000[address & 0x0FFF]);
106
		return (m43tmp.prg_5000[address & 0x0FFF]);
97
	}
107
	}
98
108
99
	return (prg_6000[address & 0x1FFF]);
109
	return (m43tmp.prg_6000[address & 0x1FFF]);
100
}
110
}
101
BYTE extcl_save_mapper_43(BYTE mode, BYTE slot, FILE *fp) {
111
BYTE extcl_save_mapper_43(BYTE mode, BYTE slot, FILE *fp) {
102
	save_slot_ele(mode, slot, m43.swap);
112
	save_slot_ele(mode, slot, m43.swap);
(-)puNES-0.105.org/src/core/mappers/mapper_43.h (-8 lines)
Lines 21-34 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m43 {
25
	BYTE swap;
26
	struct _m43_irq {
27
		BYTE active;
28
		WORD count;
29
	} irq;
30
} m43;
31
32
void map_init_43(void);
24
void map_init_43(void);
33
void extcl_cpu_wr_mem_43(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_43(WORD address, BYTE value);
34
BYTE extcl_cpu_rd_mem_43(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_43(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_44.c (+6 lines)
Lines 155-160 Link Here
155
	}\
155
	}\
156
}
156
}
157
157
158
struct _m44 {
159
	BYTE reg;
160
	WORD prg_map[4];
161
	WORD chr_map[8];
162
} m44;
163
158
void map_init_44(void) {
164
void map_init_44(void) {
159
	EXTCL_CPU_WR_MEM(44);
165
	EXTCL_CPU_WR_MEM(44);
160
	EXTCL_SAVE_MAPPER(44);
166
	EXTCL_SAVE_MAPPER(44);
(-)puNES-0.105.org/src/core/mappers/mapper_44.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m44 {
25
	BYTE reg;
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} m44;
29
30
void map_init_44(void);
24
void map_init_44(void);
31
void extcl_cpu_wr_mem_44(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_44(WORD address, BYTE value);
32
BYTE extcl_save_mapper_44(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_44(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_45.c (+8 lines)
Lines 160-165 Link Here
160
	}\
160
	}\
161
}
161
}
162
162
163
struct _m45 {
164
	BYTE reg[4];
165
	BYTE index;
166
	BYTE read;
167
	WORD prg_map[4];
168
	WORD chr_map[8];
169
} m45;
170
163
void map_init_45(void) {
171
void map_init_45(void) {
164
	EXTCL_CPU_WR_MEM(45);
172
	EXTCL_CPU_WR_MEM(45);
165
	EXTCL_CPU_RD_MEM(45);
173
	EXTCL_CPU_RD_MEM(45);
(-)puNES-0.105.org/src/core/mappers/mapper_45.h (-8 lines)
Lines 21-34 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m45 {
25
	BYTE reg[4];
26
	BYTE index;
27
	BYTE read;
28
	WORD prg_map[4];
29
	WORD chr_map[8];
30
} m45;
31
32
void map_init_45(void);
24
void map_init_45(void);
33
void extcl_cpu_wr_mem_45(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_45(WORD address, BYTE value);
34
BYTE extcl_cpu_rd_mem_45(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_45(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_46.c (+5 lines)
Lines 22-27 Link Here
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
struct _m46 {
26
	BYTE prg;
27
	BYTE chr;
28
} m46;
29
25
void map_init_46(void) {
30
void map_init_46(void) {
26
	EXTCL_CPU_WR_MEM(46);
31
	EXTCL_CPU_WR_MEM(46);
27
	EXTCL_SAVE_MAPPER(46);
32
	EXTCL_SAVE_MAPPER(46);
(-)puNES-0.105.org/src/core/mappers/mapper_46.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m46 {
25
	BYTE prg;
26
	BYTE chr;
27
} m46;
28
29
void map_init_46(void);
24
void map_init_46(void);
30
void extcl_cpu_wr_mem_46(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_46(WORD address, BYTE value);
31
BYTE extcl_save_mapper_46(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_46(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_47.c (+6 lines)
Lines 155-160 Link Here
155
	}\
155
	}\
156
}
156
}
157
157
158
struct _m47 {
159
	BYTE reg;
160
	WORD prg_map[4];
161
	WORD chr_map[8];
162
} m47;
163
158
void map_init_47(void) {
164
void map_init_47(void) {
159
	EXTCL_CPU_WR_MEM(47);
165
	EXTCL_CPU_WR_MEM(47);
160
	EXTCL_SAVE_MAPPER(47);
166
	EXTCL_SAVE_MAPPER(47);
(-)puNES-0.105.org/src/core/mappers/mapper_47.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m47 {
25
	BYTE reg;
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} m47;
29
30
void map_init_47(void);
24
void map_init_47(void);
31
void extcl_cpu_wr_mem_47(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_47(WORD address, BYTE value);
32
BYTE extcl_save_mapper_47(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_47(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_49.c (+6 lines)
Lines 159-164 Link Here
159
	}\
159
	}\
160
}
160
}
161
161
162
struct _m49 {
163
	BYTE reg;
164
	WORD prg_map[4];
165
	WORD chr_map[8];
166
} m49;
167
162
void map_init_49(void) {
168
void map_init_49(void) {
163
	EXTCL_CPU_WR_MEM(49);
169
	EXTCL_CPU_WR_MEM(49);
164
	EXTCL_SAVE_MAPPER(49);
170
	EXTCL_SAVE_MAPPER(49);
(-)puNES-0.105.org/src/core/mappers/mapper_49.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m49 {
25
	BYTE reg;
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} m49;
29
30
void map_init_49(void);
24
void map_init_49(void);
31
void extcl_cpu_wr_mem_49(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_49(WORD address, BYTE value);
32
BYTE extcl_save_mapper_49(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_49(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_50.c (-3 / +10 lines)
Lines 23-29 Link Here
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
BYTE *prg_6000;
26
struct _m50 {
27
	BYTE enabled;
28
	WORD count;
29
	BYTE delay;
30
} m50;
31
struct _m50tmp {
32
	BYTE *prg_6000;
33
} m50tmp;
27
34
28
void map_init_50(void) {
35
void map_init_50(void) {
29
	EXTCL_CPU_WR_MEM(50);
36
	EXTCL_CPU_WR_MEM(50);
Lines 39-45 void map_init_50(void) { Link Here
39
		mapper.rom_map_to[2] = 0;
46
		mapper.rom_map_to[2] = 0;
40
	}
47
	}
41
48
42
	prg_6000 = prg_chip_byte_pnt(0, info.prg.rom[0].max.banks_8k << 13);
49
	m50tmp.prg_6000 = prg_chip_byte_pnt(0, info.prg.rom[0].max.banks_8k << 13);
43
50
44
	mapper.rom_map_to[0] = 8;
51
	mapper.rom_map_to[0] = 8;
45
	mapper.rom_map_to[1] = 9;
52
	mapper.rom_map_to[1] = 9;
Lines 69-75 BYTE extcl_cpu_rd_mem_50(WORD address, B Link Here
69
		return (openbus);
76
		return (openbus);
70
	}
77
	}
71
78
72
	return (prg_6000[address & 0x1FFF]);
79
	return (m50tmp.prg_6000[address & 0x1FFF]);
73
}
80
}
74
BYTE extcl_save_mapper_50(BYTE mode, BYTE slot, FILE *fp) {
81
BYTE extcl_save_mapper_50(BYTE mode, BYTE slot, FILE *fp) {
75
	save_slot_ele(mode, slot, m50.enabled);
82
	save_slot_ele(mode, slot, m50.enabled);
(-)puNES-0.105.org/src/core/mappers/mapper_50.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m50 {
25
	BYTE enabled;
26
	WORD count;
27
	BYTE delay;
28
} m50;
29
30
void map_init_50(void);
24
void map_init_50(void);
31
void extcl_cpu_wr_mem_50(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_50(WORD address, BYTE value);
32
BYTE extcl_cpu_rd_mem_50(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_50(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_51.c (-4 / +11 lines)
Lines 22-28 Link Here
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
BYTE *prg_6000;
25
struct _m51 {
26
	BYTE mode;
27
	WORD bank;
28
	BYTE prg_6000;
29
} m51;
30
struct _m51tmp {
31
	BYTE *prg_6000;
32
} m51tmp;
26
33
27
void map_init_51(void) {
34
void map_init_51(void) {
28
	EXTCL_CPU_WR_MEM(51);
35
	EXTCL_CPU_WR_MEM(51);
Lines 76-82 void extcl_cpu_wr_mem_51(WORD address, B Link Here
76
83
77
	m51.prg_6000 = m51.prg_6000 | (m51.bank << 2);
84
	m51.prg_6000 = m51.prg_6000 | (m51.bank << 2);
78
	_control_bank(m51.prg_6000, info.prg.rom[0].max.banks_8k)
85
	_control_bank(m51.prg_6000, info.prg.rom[0].max.banks_8k)
79
	prg_6000 = prg_chip_byte_pnt(0, m51.prg_6000 << 13);
86
	m51tmp.prg_6000 = prg_chip_byte_pnt(0, m51.prg_6000 << 13);
80
87
81
	if (m51.mode == 0x03) {
88
	if (m51.mode == 0x03) {
82
		mirroring_H();
89
		mirroring_H();
Lines 89-95 BYTE extcl_cpu_rd_mem_51(WORD address, B Link Here
89
		return (openbus);
96
		return (openbus);
90
	}
97
	}
91
98
92
	return (prg_6000[address & 0x1FFF]);
99
	return (m51tmp.prg_6000[address & 0x1FFF]);
93
}
100
}
94
BYTE extcl_save_mapper_51(BYTE mode, BYTE slot, FILE *fp) {
101
BYTE extcl_save_mapper_51(BYTE mode, BYTE slot, FILE *fp) {
95
	save_slot_ele(mode, slot, m51.bank);
102
	save_slot_ele(mode, slot, m51.bank);
Lines 97-103 BYTE extcl_save_mapper_51(BYTE mode, BYT Link Here
97
	save_slot_ele(mode, slot, m51.prg_6000);
104
	save_slot_ele(mode, slot, m51.prg_6000);
98
105
99
	if (mode == SAVE_SLOT_READ) {
106
	if (mode == SAVE_SLOT_READ) {
100
		prg_6000 = prg_chip_byte_pnt(0, m51.prg_6000 << 13);
107
		m51tmp.prg_6000 = prg_chip_byte_pnt(0, m51.prg_6000 << 13);
101
	}
108
	}
102
109
103
	return (EXIT_OK);
110
	return (EXIT_OK);
(-)puNES-0.105.org/src/core/mappers/mapper_51.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m51 {
25
	BYTE mode;
26
	WORD bank;
27
	BYTE prg_6000;
28
} m51;
29
30
void map_init_51(void);
24
void map_init_51(void);
31
void extcl_cpu_wr_mem_51(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_51(WORD address, BYTE value);
32
BYTE extcl_cpu_rd_mem_51(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_51(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_52.c (-5 / +12 lines)
Lines 24-30 Link Here
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
#define m52_chr_1k(vl)\
26
#define m52_chr_1k(vl)\
27
	if (model == MARIO7IN1) {\
27
	if (m52tmp.model == MARIO7IN1) {\
28
		bank = ((((m52.reg >> 3) & 0x04) | ((m52.reg >> 1) & 0x02) |\
28
		bank = ((((m52.reg >> 3) & 0x04) | ((m52.reg >> 1) & 0x02) |\
29
			((m52.reg >> 6) & (m52.reg >> 4) & 0x01)) << 7) |\
29
			((m52.reg >> 6) & (m52.reg >> 4) & 0x01)) << 7) |\
30
			(vl & (((m52.reg & 0x40) << 1) ^ 0xFF));\
30
			(vl & (((m52.reg & 0x40) << 1) ^ 0xFF));\
Lines 34-41 Link Here
34
			(vl & (((m52.reg << 1) & 0x80) ^ 0xFF));\
34
			(vl & (((m52.reg << 1) & 0x80) ^ 0xFF));\
35
	}
35
	}
36
#define m52_prg_8k(vl)\
36
#define m52_prg_8k(vl)\
37
	value = (((m52.reg & 0x06) | ((m52.reg >> 3) & m52.reg & 0x01)) << 4) |\
37
	value = (((m52.reg & 0x06) | ((m52.reg >> 3) & m52.reg & 0x01)) << 4) | (vl & (((m52.reg << 1) & 0x10) ^ 0x1F))
38
		(vl & (((m52.reg << 1) & 0x10) ^ 0x1F))
39
#define m52_chr_1k_update()\
38
#define m52_chr_1k_update()\
40
{\
39
{\
41
	BYTE i;\
40
	BYTE i;\
Lines 166-172 Link Here
166
	}\
165
	}\
167
}
166
}
168
167
169
BYTE model;
168
struct _m52 {
169
	BYTE disabled;
170
	BYTE reg;
171
	WORD prg_map[4];
172
	WORD chr_map[8];
173
} m52;
174
struct _m52tmp {
175
	BYTE model;
176
} m52tmp;
170
177
171
void map_init_52(BYTE type) {
178
void map_init_52(BYTE type) {
172
	EXTCL_CPU_WR_MEM(52);
179
	EXTCL_CPU_WR_MEM(52);
Lines 208-214 void map_init_52(BYTE type) { Link Here
208
	irqA12.present = TRUE;
215
	irqA12.present = TRUE;
209
	irqA12_delay = 1;
216
	irqA12_delay = 1;
210
217
211
	model = type;
218
	m52tmp.model = type;
212
}
219
}
213
void extcl_cpu_wr_mem_52(WORD address, BYTE value) {
220
void extcl_cpu_wr_mem_52(WORD address, BYTE value) {
214
	switch (address & 0xE001) {
221
	switch (address & 0xE001) {
(-)puNES-0.105.org/src/core/mappers/mapper_52.h (-7 lines)
Lines 23-35 Link Here
23
23
24
enum { MARIO7IN1 };
24
enum { MARIO7IN1 };
25
25
26
struct _m52 {
27
	BYTE disabled;
28
	BYTE reg;
29
	WORD prg_map[4];
30
	WORD chr_map[8];
31
} m52;
32
33
void map_init_52(BYTE type);
26
void map_init_52(BYTE type);
34
void extcl_cpu_wr_mem_52(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_52(WORD address, BYTE value);
35
BYTE extcl_save_mapper_52(BYTE mode, BYTE slot, FILE *fp);
28
BYTE extcl_save_mapper_52(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_53.c (-4 / +10 lines)
Lines 24-30 Link Here
24
24
25
INLINE static void m53_update_6000(void);
25
INLINE static void m53_update_6000(void);
26
26
27
BYTE *prg_6000;
27
struct _m53 {
28
	BYTE reg[2];
29
	BYTE prg_6000;
30
} m53;
31
struct _m53tmp {
32
	BYTE *prg_6000;
33
} m53tmp;
28
34
29
void map_init_53(void) {
35
void map_init_53(void) {
30
	EXTCL_CPU_WR_MEM(53);
36
	EXTCL_CPU_WR_MEM(53);
Lines 99-105 BYTE extcl_cpu_rd_mem_53(WORD address, B Link Here
99
		return (openbus);
105
		return (openbus);
100
	}
106
	}
101
107
102
	return (prg_6000[address & 0x1FFF]);
108
	return (m53tmp.prg_6000[address & 0x1FFF]);
103
}
109
}
104
BYTE extcl_save_mapper_53(BYTE mode, BYTE slot, FILE *fp) {
110
BYTE extcl_save_mapper_53(BYTE mode, BYTE slot, FILE *fp) {
105
	save_slot_ele(mode, slot, m53.reg);
111
	save_slot_ele(mode, slot, m53.reg);
Lines 121-130 INLINE static void m53_update_6000(void) Link Here
121
127
122
		m53.prg_6000 = ((m53.reg[0] << 4) & 0x30) | 0x0F;
128
		m53.prg_6000 = ((m53.reg[0] << 4) & 0x30) | 0x0F;
123
		_control_bank(m53.prg_6000, info.prg.rom[chip].max.banks_8k)
129
		_control_bank(m53.prg_6000, info.prg.rom[chip].max.banks_8k)
124
		prg_6000 = prg_chip_byte_pnt(chip, m53.prg_6000 << 13);
130
		m53tmp.prg_6000 = prg_chip_byte_pnt(chip, m53.prg_6000 << 13);
125
	} else {
131
	} else {
126
		m53.prg_6000 = (((m53.reg[0] << 4) & 0xF0) | 0x0F) + 4;
132
		m53.prg_6000 = (((m53.reg[0] << 4) & 0xF0) | 0x0F) + 4;
127
		_control_bank(m53.prg_6000, info.prg.rom[0].max.banks_8k)
133
		_control_bank(m53.prg_6000, info.prg.rom[0].max.banks_8k)
128
		prg_6000 = prg_chip_byte_pnt(0, m53.prg_6000 << 13);
134
		m53tmp.prg_6000 = prg_chip_byte_pnt(0, m53.prg_6000 << 13);
129
	}
135
	}
130
}
136
}
(-)puNES-0.105.org/src/core/mappers/mapper_53.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m53 {
25
	BYTE reg[2];
26
	BYTE prg_6000;
27
} m53;
28
29
void map_init_53(void);
24
void map_init_53(void);
30
void extcl_cpu_wr_mem_53(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_53(WORD address, BYTE value);
31
BYTE extcl_cpu_rd_mem_53(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_53(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_57.c (+4 lines)
Lines 22-27 Link Here
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
struct _m57 {
26
	BYTE reg[2];
27
} m57;
28
25
void map_init_57(void) {
29
void map_init_57(void) {
26
	EXTCL_CPU_WR_MEM(57);
30
	EXTCL_CPU_WR_MEM(57);
27
	EXTCL_SAVE_MAPPER(57);
31
	EXTCL_SAVE_MAPPER(57);
(-)puNES-0.105.org/src/core/mappers/mapper_57.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m57 {
25
	BYTE reg[2];
26
} m57;
27
28
void map_init_57(void);
24
void map_init_57(void);
29
void extcl_cpu_wr_mem_57(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_57(WORD address, BYTE value);
30
BYTE extcl_save_mapper_57(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_57(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_60.c (+6 lines)
Lines 22-27 Link Here
22
#include "save_slot.h"
22
#include "save_slot.h"
23
#include "cpu.h"
23
#include "cpu.h"
24
24
25
struct _m60 {
26
	BYTE index;
27
	// per la variante vt5201
28
	WORD address;
29
} m60;
30
25
void map_init_60(void) {
31
void map_init_60(void) {
26
	EXTCL_CPU_WR_MEM(60);
32
	EXTCL_CPU_WR_MEM(60);
27
	EXTCL_SAVE_MAPPER(60);
33
	EXTCL_SAVE_MAPPER(60);
(-)puNES-0.105.org/src/core/mappers/mapper_60.h (-6 lines)
Lines 23-34 Link Here
23
23
24
enum { MAP60, MAP60_VT5201 };
24
enum { MAP60, MAP60_VT5201 };
25
25
26
struct _m60 {
27
	BYTE index;
28
	// per la variante vt5201
29
	WORD address;
30
} m60;
31
32
void map_init_60(void);
26
void map_init_60(void);
33
void extcl_cpu_wr_mem_60(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_60(WORD address, BYTE value);
34
BYTE extcl_save_mapper_60(BYTE mode, BYTE slot, FILE *fp);
28
BYTE extcl_save_mapper_60(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_74x161x161x32.c (-3 / +5 lines)
Lines 20-38 Link Here
20
#include "info.h"
20
#include "info.h"
21
#include "mem_map.h"
21
#include "mem_map.h"
22
22
23
BYTE type;
23
struct _m74x161x161x32tmp {
24
	BYTE type;
25
} m74x161x161x32tmp;
24
26
25
void map_init_74x161x161x32(BYTE model) {
27
void map_init_74x161x161x32(BYTE model) {
26
	EXTCL_CPU_WR_MEM(74x161x161x32);
28
	EXTCL_CPU_WR_MEM(74x161x161x32);
27
29
28
	type = model;
30
	m74x161x161x32tmp.type = model;
29
}
31
}
30
void extcl_cpu_wr_mem_74x161x161x32(WORD address, BYTE value) {
32
void extcl_cpu_wr_mem_74x161x161x32(WORD address, BYTE value) {
31
	/* bus conflict */
33
	/* bus conflict */
32
	const BYTE save = value &= prg_rom_rd(address);
34
	const BYTE save = value &= prg_rom_rd(address);
33
	DBWORD bank;
35
	DBWORD bank;
34
36
35
	if (type == IC74X161X161X32B) {
37
	if (m74x161x161x32tmp.type == IC74X161X161X32B) {
36
		if (value & 0x80) {
38
		if (value & 0x80) {
37
			mirroring_SCR1();
39
			mirroring_SCR1();
38
		} else {
40
		} else {
(-)puNES-0.105.org/src/core/mappers/mapper_83.c (+15 lines)
Lines 25-30 Link Here
25
25
26
INLINE static void sync_83(void);
26
INLINE static void sync_83(void);
27
27
28
struct _m83 {
29
	BYTE is2kbank;
30
	BYTE isnot2kbank;
31
	BYTE mode;
32
	BYTE bank;
33
	BYTE dip;
34
	BYTE low[4];
35
	BYTE reg[11];
36
37
	struct _m83_irq {
38
		BYTE active;
39
		WORD count;
40
	} irq;
41
} m83;
42
28
void map_init_83(void) {
43
void map_init_83(void) {
29
	EXTCL_CPU_WR_MEM(83);
44
	EXTCL_CPU_WR_MEM(83);
30
	EXTCL_CPU_RD_MEM(83);
45
	EXTCL_CPU_RD_MEM(83);
(-)puNES-0.105.org/src/core/mappers/mapper_83.h (-15 lines)
Lines 23-43 Link Here
23
23
24
enum { MAP83_REG0, MAP83_DGP };
24
enum { MAP83_REG0, MAP83_DGP };
25
25
26
struct _m83 {
27
	BYTE is2kbank;
28
	BYTE isnot2kbank;
29
	BYTE mode;
30
	BYTE bank;
31
	BYTE dip;
32
	BYTE low[4];
33
	BYTE reg[11];
34
35
	struct _m83_irq {
36
		BYTE active;
37
		WORD count;
38
	} irq;
39
} m83;
40
41
void map_init_83(void);
26
void map_init_83(void);
42
void extcl_cpu_wr_mem_83(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_83(WORD address, BYTE value);
43
BYTE extcl_cpu_rd_mem_83(WORD address, BYTE openbus, BYTE before);
28
BYTE extcl_cpu_rd_mem_83(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_8_IN_1.c (+6 lines)
Lines 77-82 INLINE static void m8in1_update_chr(void Link Here
77
			break;\
77
			break;\
78
	}
78
	}
79
79
80
struct _m8in1 {
81
	BYTE reg;
82
	WORD prg_map[4];
83
	WORD chr_map[8];
84
} m8in1;
85
80
void map_init_8_IN_1(void) {
86
void map_init_8_IN_1(void) {
81
	EXTCL_CPU_WR_MEM(8_IN_1);
87
	EXTCL_CPU_WR_MEM(8_IN_1);
82
	EXTCL_SAVE_MAPPER(8_IN_1);
88
	EXTCL_SAVE_MAPPER(8_IN_1);
(-)puNES-0.105.org/src/core/mappers/mapper_8_IN_1.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m8in1 {
25
	BYTE reg;
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} m8in1;
29
30
void map_init_8_IN_1(void);
24
void map_init_8_IN_1(void);
31
void extcl_cpu_wr_mem_8_IN_1(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_8_IN_1(WORD address, BYTE value);
32
BYTE extcl_save_mapper_8_IN_1(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_8_IN_1(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_90_209_211.c (+41 lines)
Lines 43-48 INLINE static void irq_clock_count_90_20 Link Here
43
	ntbl.bank_1k[index] = &ntbl.data[value << 10];\
43
	ntbl.bank_1k[index] = &ntbl.data[value << 10];\
44
	m90_209_211.nmt.write[index] = TRUE
44
	m90_209_211.nmt.write[index] = TRUE
45
45
46
struct _m90_209_211 {
47
	BYTE mul[2];
48
	BYTE single_byte_ram;
49
	BYTE tekker;
50
51
	BYTE mode[4];
52
53
	BYTE prg[4];
54
55
	struct _m90_209_211_chr {
56
		BYTE latch[2];
57
		BYTE low[8];
58
		BYTE high[8];
59
	} chr;
60
61
	struct _m90_209_211_nmt {
62
		BYTE extended_mode;
63
		WORD reg[4];
64
		BYTE write[4];
65
	} nmt;
66
67
	struct _m90_209_211_irq {
68
		BYTE active;
69
		BYTE mode;
70
		BYTE prescaler;
71
		BYTE count;
72
		BYTE xor_value;
73
		BYTE pre_size;
74
		BYTE premask;
75
	} irq;
76
77
/*  questi non serve salvarli  */
78
	BYTE model;
79
80
	struct _m90_209_211_m6000 {
81
		WORD prg;
82
		BYTE *rom_8k;
83
	} m6000;
84
/*                             */
85
} m90_209_211;
86
46
void map_init_90_209_211(BYTE model) {
87
void map_init_90_209_211(BYTE model) {
47
	BYTE i;
88
	BYTE i;
48
89
(-)puNES-0.105.org/src/core/mappers/mapper_90_209_211.h (-41 lines)
Lines 27-73 enum { Link Here
27
	MAP211
27
	MAP211
28
};
28
};
29
29
30
struct _m90_209_211 {
31
	BYTE mul[2];
32
	BYTE single_byte_ram;
33
	BYTE tekker;
34
35
	BYTE mode[4];
36
37
	BYTE prg[4];
38
39
	struct _m90_209_211_chr {
40
		BYTE latch[2];
41
		BYTE low[8];
42
		BYTE high[8];
43
	} chr;
44
45
	struct _m90_209_211_nmt {
46
		BYTE extended_mode;
47
		WORD reg[4];
48
		BYTE write[4];
49
	} nmt;
50
51
	struct _m90_209_211_irq {
52
		BYTE active;
53
		BYTE mode;
54
		BYTE prescaler;
55
		BYTE count;
56
		BYTE xor_value;
57
		BYTE pre_size;
58
		BYTE premask;
59
	} irq;
60
61
/*  questi non serve salvarli  */
62
	BYTE model;
63
64
	struct _m90_209_211_m6000 {
65
		WORD prg;
66
		BYTE *rom_8k;
67
	} m6000;
68
/*                             */
69
} m90_209_211;
70
71
void map_init_90_209_211(BYTE model);
30
void map_init_90_209_211(BYTE model);
72
void extcl_cpu_wr_mem_90_209_211(WORD address, BYTE value);
31
void extcl_cpu_wr_mem_90_209_211(WORD address, BYTE value);
73
BYTE extcl_cpu_rd_mem_90_209_211(WORD address, BYTE openbus, BYTE before);
32
BYTE extcl_cpu_rd_mem_90_209_211(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_91.c (+7 lines)
Lines 24-29 Link Here
24
#include "cpu.h"
24
#include "cpu.h"
25
#include "ppu.h"
25
#include "ppu.h"
26
26
27
struct _m91 {
28
	struct _m91_irq {
29
		BYTE active;
30
		BYTE count;
31
	} irq;
32
} m91;
33
27
void map_init_91(void) {
34
void map_init_91(void) {
28
	EXTCL_CPU_WR_MEM(91);
35
	EXTCL_CPU_WR_MEM(91);
29
	EXTCL_SAVE_MAPPER(91);
36
	EXTCL_SAVE_MAPPER(91);
(-)puNES-0.105.org/src/core/mappers/mapper_91.h (-7 lines)
Lines 21-33 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _m91 {
25
	struct _m91_irq {
26
		BYTE active;
27
		BYTE count;
28
	} irq;
29
} m91;
30
31
void map_init_91(void);
24
void map_init_91(void);
32
void extcl_cpu_wr_mem_91(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_91(WORD address, BYTE value);
33
BYTE extcl_save_mapper_91(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_91(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_AC08.c (-4 / +9 lines)
Lines 21-27 Link Here
21
#include "mem_map.h"
21
#include "mem_map.h"
22
#include "save_slot.h"
22
#include "save_slot.h"
23
23
24
BYTE *ac08_prg_6000;
24
struct _ac08 {
25
	BYTE reg;
26
} ac08;
27
struct _ac08tmp {
28
	BYTE *prg_6000;
29
} ac08tmp;
25
30
26
void map_init_AC08(void) {
31
void map_init_AC08(void) {
27
	EXTCL_CPU_WR_MEM(AC08);
32
	EXTCL_CPU_WR_MEM(AC08);
Lines 56-62 void extcl_cpu_wr_mem_AC08(WORD address, Link Here
56
			value = value & 0x0F;
61
			value = value & 0x0F;
57
		}
62
		}
58
		control_bank(info.prg.rom[0].max.banks_8k)
63
		control_bank(info.prg.rom[0].max.banks_8k)
59
		ac08_prg_6000 = prg_chip_byte_pnt(0, value << 13);
64
		ac08tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13);
60
		ac08.reg = value;
65
		ac08.reg = value;
61
		return;
66
		return;
62
	}
67
	}
Lines 72-78 void extcl_cpu_wr_mem_AC08(WORD address, Link Here
72
}
77
}
73
BYTE extcl_cpu_rd_mem_AC08(WORD address, BYTE openbus, UNUSED(BYTE before)) {
78
BYTE extcl_cpu_rd_mem_AC08(WORD address, BYTE openbus, UNUSED(BYTE before)) {
74
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
79
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
75
		return (ac08_prg_6000[address & 0x1FFF]);
80
		return (ac08tmp.prg_6000[address & 0x1FFF]);
76
	}
81
	}
77
	return (openbus);
82
	return (openbus);
78
}
83
}
Lines 80-86 BYTE extcl_save_mapper_AC08(BYTE mode, B Link Here
80
	save_slot_ele(mode, slot, ac08.reg);
85
	save_slot_ele(mode, slot, ac08.reg);
81
86
82
	if (mode == SAVE_SLOT_READ) {
87
	if (mode == SAVE_SLOT_READ) {
83
		ac08_prg_6000 = prg_chip_byte_pnt(0, ac08.reg << 13);
88
		ac08tmp.prg_6000 = prg_chip_byte_pnt(0, ac08.reg << 13);
84
	}
89
	}
85
90
86
	return (EXIT_OK);
91
	return (EXIT_OK);
(-)puNES-0.105.org/src/core/mappers/mapper_AC08.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _ac08 {
25
	BYTE reg;
26
} ac08;
27
28
void map_init_AC08(void);
24
void map_init_AC08(void);
29
void extcl_cpu_wr_mem_AC08(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_AC08(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_AC08(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_AC08(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_Active.c (+5 lines)
Lines 22-27 Link Here
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
struct _active {
26
	BYTE openbus;
27
	BYTE prg_ram[4];
28
} active;
29
25
void map_init_Active(void) {
30
void map_init_Active(void) {
26
	EXTCL_CPU_WR_MEM(Active);
31
	EXTCL_CPU_WR_MEM(Active);
27
	EXTCL_CPU_RD_MEM(Active);
32
	EXTCL_CPU_RD_MEM(Active);
(-)puNES-0.105.org/src/core/mappers/mapper_Active.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _active {
25
	BYTE openbus;
26
	BYTE prg_ram[4];
27
} active;
28
29
void map_init_Active(void);
24
void map_init_Active(void);
30
void extcl_cpu_wr_mem_Active(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_Active(WORD address, BYTE value);
31
BYTE extcl_cpu_rd_mem_Active(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_Active(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_Ave.c (+4 lines)
Lines 45-50 Link Here
45
	chr.bank_1k[7] = chr_chip_byte_pnt(0, bank | 0x1C00);\
45
	chr.bank_1k[7] = chr_chip_byte_pnt(0, bank | 0x1C00);\
46
}
46
}
47
47
48
struct _ave_d1012 {
49
	BYTE reg[3];
50
} ave_d1012;
51
48
void map_init_Ave(BYTE model) {
52
void map_init_Ave(BYTE model) {
49
	switch (model) {
53
	switch (model) {
50
		case NINA06:
54
		case NINA06:
(-)puNES-0.105.org/src/core/mappers/mapper_Ave.h (-4 lines)
Lines 23-32 Link Here
23
23
24
enum { NINA06, D1012, PUZZLEUNL };
24
enum { NINA06, D1012, PUZZLEUNL };
25
25
26
struct _ave_d1012 {
27
	BYTE reg[3];
28
} ave_d1012;
29
30
void map_init_Ave(BYTE model);
26
void map_init_Ave(BYTE model);
31
27
32
void extcl_cpu_wr_mem_Ave_NINA06(WORD address, BYTE value);
28
void extcl_cpu_wr_mem_Ave_NINA06(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_AX5705.c (+4 lines)
Lines 33-38 Link Here
33
	value = (ax5705.chr_map[slot] & 0xF0) | (value & 0x0F);\
33
	value = (ax5705.chr_map[slot] & 0xF0) | (value & 0x0F);\
34
	_ax5705_chr_rom_1k_update(slot)
34
	_ax5705_chr_rom_1k_update(slot)
35
35
36
struct _ax5705 {
37
	WORD chr_map[8];
38
} ax5705;
39
36
void map_init_AX5705(void) {
40
void map_init_AX5705(void) {
37
	EXTCL_CPU_WR_MEM(AX5705);
41
	EXTCL_CPU_WR_MEM(AX5705);
38
	EXTCL_SAVE_MAPPER(AX5705);
42
	EXTCL_SAVE_MAPPER(AX5705);
(-)puNES-0.105.org/src/core/mappers/mapper_AX5705.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _ax5705 {
25
	WORD chr_map[8];
26
} ax5705;
27
28
void map_init_AX5705(void);
24
void map_init_AX5705(void);
29
void extcl_cpu_wr_mem_AX5705(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_AX5705(WORD address, BYTE value);
30
BYTE extcl_save_mapper_AX5705(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_AX5705(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_Bandai.c (-21 / +49 lines)
Lines 24-32 Link Here
24
#include "ppu.h"
24
#include "ppu.h"
25
#include "save_slot.h"
25
#include "save_slot.h"
26
26
27
enum {
28
	MODE_IDLE,
29
	MODE_DATA,
30
	MODE_ADDRESS,
31
	MODE_READ,
32
	MODE_WRITE,
33
	MODE_ACK,
34
	MODE_NOT_ACK,
35
	MODE_ACK_WAIT,
36
	MODE_MAX
37
};
38
27
#define b161x02x74_chr_4k_update()\
39
#define b161x02x74_chr_4k_update()\
28
	value = (save & 0x04) | (b161x02x74.chr_rom_bank & 0x03);\
40
	value = (save & 0x04) | (b161x02x74.chr_rom_bank & 0x03);\
29
	control_bank(chr_ram_4k_max)\
41
	control_bank(bandaitmp.chr_ram_4k_max)\
30
	b161x02x74.chr_rom_bank = value;\
42
	b161x02x74.chr_rom_bank = value;\
31
	bank = value << 12;\
43
	bank = value << 12;\
32
	chr.bank_1k[0] = chr_chip_byte_pnt(0, bank);\
44
	chr.bank_1k[0] = chr_chip_byte_pnt(0, bank);\
Lines 34-40 Link Here
34
	chr.bank_1k[2] = chr_chip_byte_pnt(0, bank | 0x0800);\
46
	chr.bank_1k[2] = chr_chip_byte_pnt(0, bank | 0x0800);\
35
	chr.bank_1k[3] = chr_chip_byte_pnt(0, bank | 0x0C00);\
47
	chr.bank_1k[3] = chr_chip_byte_pnt(0, bank | 0x0C00);\
36
	value = (save & 0x04) | 0x03;\
48
	value = (save & 0x04) | 0x03;\
37
	control_bank(chr_ram_4k_max)\
49
	control_bank(bandaitmp.chr_ram_4k_max)\
38
	bank = value << 12;\
50
	bank = value << 12;\
39
	chr.bank_1k[4] = chr_chip_byte_pnt(0, bank);\
51
	chr.bank_1k[4] = chr_chip_byte_pnt(0, bank);\
40
	chr.bank_1k[5] = chr_chip_byte_pnt(0, bank | 0x0400);\
52
	chr.bank_1k[5] = chr_chip_byte_pnt(0, bank | 0x0400);\
Lines 66-90 Link Here
66
	save_slot_ele(mode, slot, epr.rw);\
78
	save_slot_ele(mode, slot, epr.rw);\
67
	save_slot_ele(mode, slot, epr.output)
79
	save_slot_ele(mode, slot, epr.output)
68
80
69
void e24C0x_set(BYTE scl, BYTE sda, _FCGXeeprom *eeprom);
81
typedef struct _FCGXeeprom {
82
	BYTE eeprom[256];
83
	WORD size;
84
	BYTE mode;
85
	BYTE next;
86
	BYTE bit;
87
	BYTE address;
88
	BYTE data;
89
	BYTE scl;
90
	BYTE sda;
91
	BYTE rw;
92
	BYTE output;
93
} _FCGXeeprom;
70
94
71
enum {
95
void e24C0x_set(BYTE scl, BYTE sda, _FCGXeeprom *eeprom);
72
	MODE_IDLE,
73
	MODE_DATA,
74
	MODE_ADDRESS,
75
	MODE_READ,
76
	MODE_WRITE,
77
	MODE_ACK,
78
	MODE_NOT_ACK,
79
	MODE_ACK_WAIT,
80
	MODE_MAX
81
};
82
96
83
WORD chr_ram_4k_max;
97
struct _b161x02x74 {
84
BYTE type;
98
	BYTE chr_rom_bank;
99
} b161x02x74;
100
struct _FCGX {
101
	BYTE reg[8];
102
	BYTE enabled;
103
	WORD count;
104
	WORD reload;
105
	BYTE delay;
106
	_FCGXeeprom e0;
107
	_FCGXeeprom e1;
108
} FCGX;
109
struct _bandaitmp {
110
	BYTE type;
111
	WORD chr_ram_4k_max;
112
} bandaitmp;
85
113
86
void map_init_Bandai(BYTE model) {
114
void map_init_Bandai(BYTE model) {
87
	chr_ram_4k_max = info.chr.rom[0].banks_4k - 1;
115
	bandaitmp.chr_ram_4k_max = info.chr.rom[0].banks_4k - 1;
88
116
89
	switch (model) {
117
	switch (model) {
90
		case B161X02X74:
118
		case B161X02X74:
Lines 162-168 void map_init_Bandai(BYTE model) { Link Here
162
			break;
190
			break;
163
	}
191
	}
164
192
165
	type = model;
193
	bandaitmp.type = model;
166
}
194
}
167
195
168
void extcl_cpu_wr_mem_Bandai_161x02x74(WORD address, BYTE value) {
196
void extcl_cpu_wr_mem_Bandai_161x02x74(WORD address, BYTE value) {
Lines 234-240 void extcl_cpu_wr_mem_Bandai_FCGX(WORD a Link Here
234
262
235
				value = FCGX.reg[slot];
263
				value = FCGX.reg[slot];
236
			}
264
			}
237
			if (type == DATACH) {
265
			if (bandaitmp.type == DATACH) {
238
				datach_set_scl((value << 2) & 0x20);
266
				datach_set_scl((value << 2) & 0x20);
239
			}
267
			}
240
			if (!mapper.write_vram) {
268
			if (!mapper.write_vram) {
Lines 282-288 void extcl_cpu_wr_mem_Bandai_FCGX(WORD a Link Here
282
		case 0x800D:
310
		case 0x800D:
283
			if (FCGX.e0.size) {
311
			if (FCGX.e0.size) {
284
				e24C0x_set(value & 0x20, value & 0x40, &FCGX.e0);
312
				e24C0x_set(value & 0x20, value & 0x40, &FCGX.e0);
285
				if (type == DATACH) {
313
				if (bandaitmp.type == DATACH) {
286
					datach_set_sda(value & 0x40);
314
					datach_set_sda(value & 0x40);
287
				}
315
				}
288
			}
316
			}
Lines 297-303 BYTE extcl_cpu_rd_mem_Bandai_FCGX(WORD a Link Here
297
	if (address & 0x0100) {
325
	if (address & 0x0100) {
298
		BYTE value = FCGX.e0.output;
326
		BYTE value = FCGX.e0.output;
299
327
300
		if (type == DATACH) {
328
		if (bandaitmp.type == DATACH) {
301
			value &= FCGX.e1.output;
329
			value &= FCGX.e1.output;
302
		}
330
		}
303
		return (value);
331
		return (value);
(-)puNES-0.105.org/src/core/mappers/mapper_Bandai.h (-26 lines)
Lines 30-61 enum { Link Here
30
	FAMICOMJUMPII = 100
30
	FAMICOMJUMPII = 100
31
};
31
};
32
32
33
typedef struct {
34
	BYTE eeprom[256];
35
	WORD size;
36
	BYTE mode;
37
	BYTE next;
38
	BYTE bit;
39
	BYTE address;
40
	BYTE data;
41
	BYTE scl;
42
	BYTE sda;
43
	BYTE rw;
44
	BYTE output;
45
} _FCGXeeprom;
46
struct _b161x02x74 {
47
	BYTE chr_rom_bank;
48
} b161x02x74;
49
struct _FCGX {
50
	BYTE reg[8];
51
	BYTE enabled;
52
	WORD count;
53
	WORD reload;
54
	BYTE delay;
55
	_FCGXeeprom e0;
56
	_FCGXeeprom e1;
57
} FCGX;
58
59
void map_init_Bandai(BYTE model);
33
void map_init_Bandai(BYTE model);
60
34
61
void extcl_cpu_wr_mem_Bandai_161x02x74(WORD address, BYTE value);
35
void extcl_cpu_wr_mem_Bandai_161x02x74(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_BB.c (-5 / +10 lines)
Lines 21-27 Link Here
21
#include "info.h"
21
#include "info.h"
22
#include "save_slot.h"
22
#include "save_slot.h"
23
23
24
BYTE *bb_prg_6000;
24
struct _bb {
25
	BYTE reg;
26
} bb;
27
struct _bbtmp {
28
	BYTE *prg_6000;
29
} bbtmp;
25
30
26
void map_init_BB(void) {
31
void map_init_BB(void) {
27
	EXTCL_CPU_WR_MEM(BB);
32
	EXTCL_CPU_WR_MEM(BB);
Lines 39-45 void map_init_BB(void) { Link Here
39
44
40
	bb.reg = 0xFF;
45
	bb.reg = 0xFF;
41
	_control_bank(bb.reg, info.prg.rom[0].max.banks_8k)
46
	_control_bank(bb.reg, info.prg.rom[0].max.banks_8k)
42
	bb_prg_6000 = prg_chip_byte_pnt(0, bb.reg << 13);
47
	bbtmp.prg_6000 = prg_chip_byte_pnt(0, bb.reg << 13);
43
}
48
}
44
void extcl_cpu_wr_mem_BB(WORD address, BYTE value) {
49
void extcl_cpu_wr_mem_BB(WORD address, BYTE value) {
45
	BYTE save = value;
50
	BYTE save = value;
Lines 48-54 void extcl_cpu_wr_mem_BB(WORD address, B Link Here
48
	if ((address & 0x9000) == 0x8000) {
53
	if ((address & 0x9000) == 0x8000) {
49
		value = value & 0x03;
54
		value = value & 0x03;
50
		control_bank(info.prg.rom[0].max.banks_8k)
55
		control_bank(info.prg.rom[0].max.banks_8k)
51
		bb_prg_6000 = prg_chip_byte_pnt(0, value << 13);
56
		bbtmp.prg_6000 = prg_chip_byte_pnt(0, value << 13);
52
		bb.reg = value;
57
		bb.reg = value;
53
		value = save;
58
		value = save;
54
	} else {
59
	} else {
Lines 68-74 void extcl_cpu_wr_mem_BB(WORD address, B Link Here
68
}
73
}
69
BYTE extcl_cpu_rd_mem_BB(WORD address, BYTE openbus, UNUSED(BYTE before)) {
74
BYTE extcl_cpu_rd_mem_BB(WORD address, BYTE openbus, UNUSED(BYTE before)) {
70
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
75
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
71
		return (bb_prg_6000[address & 0x1FFF]);
76
		return (bbtmp.prg_6000[address & 0x1FFF]);
72
	}
77
	}
73
	return (openbus);
78
	return (openbus);
74
}
79
}
Lines 76-82 BYTE extcl_save_mapper_BB(BYTE mode, BYT Link Here
76
	save_slot_ele(mode, slot, bb.reg);
81
	save_slot_ele(mode, slot, bb.reg);
77
82
78
	if (mode == SAVE_SLOT_READ) {
83
	if (mode == SAVE_SLOT_READ) {
79
		bb_prg_6000 = prg_chip_byte_pnt(0, bb.reg << 13);
84
		bbtmp.prg_6000 = prg_chip_byte_pnt(0, bb.reg << 13);
80
	}
85
	}
81
86
82
	return (EXIT_OK);
87
	return (EXIT_OK);
(-)puNES-0.105.org/src/core/mappers/mapper_BB.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _bb {
25
	BYTE reg;
26
} bb;
27
28
void map_init_BB(void);
24
void map_init_BB(void);
29
void extcl_cpu_wr_mem_BB(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_BB(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_BB(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_BB(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_BMC12IN1.c (+4 lines)
Lines 22-27 Link Here
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
struct _bmc12in1 {
26
	BYTE reg[3];
27
} bmc12in1;
28
25
void map_init_BMC12IN1(void) {
29
void map_init_BMC12IN1(void) {
26
	EXTCL_CPU_WR_MEM(BMC12IN1);
30
	EXTCL_CPU_WR_MEM(BMC12IN1);
27
	EXTCL_SAVE_MAPPER(BMC12IN1);
31
	EXTCL_SAVE_MAPPER(BMC12IN1);
(-)puNES-0.105.org/src/core/mappers/mapper_BMC12IN1.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _bmc12in1 {
25
	BYTE reg[3];
26
} bmc12in1;
27
28
void map_init_BMC12IN1(void);
24
void map_init_BMC12IN1(void);
29
void extcl_cpu_wr_mem_BMC12IN1(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_BMC12IN1(WORD address, BYTE value);
30
BYTE extcl_save_mapper_BMC12IN1(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_BMC12IN1(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_BMC411120C.c (-4 / +11 lines)
Lines 80-86 INLINE static void bmc411120c_update_chr Link Here
80
			break;\
80
			break;\
81
	}
81
	}
82
82
83
BYTE bmc411120c_reset;
83
struct _bmc411120c {
84
	BYTE reg;
85
	WORD prg_map[4];
86
	WORD chr_map[8];
87
} bmc411120c;
88
struct _bmc411120ctmp {
89
	BYTE reset;
90
} bmc411120ctmp;
84
91
85
void map_init_BMC411120C(void) {
92
void map_init_BMC411120C(void) {
86
	EXTCL_CPU_WR_MEM(BMC411120C);
93
	EXTCL_CPU_WR_MEM(BMC411120C);
Lines 115-123 void map_init_BMC411120C(void) { Link Here
115
	}
122
	}
116
123
117
	if (info.reset >= HARD) {
124
	if (info.reset >= HARD) {
118
		bmc411120c_reset = 0;
125
		bmc411120ctmp.reset = 0;
119
	} else if (info.reset == RESET) {
126
	} else if (info.reset == RESET) {
120
		bmc411120c_reset ^= 0x04;
127
		bmc411120ctmp.reset ^= 0x04;
121
	}
128
	}
122
129
123
	bmc411120c_update_prg();
130
	bmc411120c_update_prg();
Lines 170-176 BYTE extcl_save_mapper_BMC411120C(BYTE m Link Here
170
INLINE static void bmc411120c_update_prg(void) {
177
INLINE static void bmc411120c_update_prg(void) {
171
	BYTE value;
178
	BYTE value;
172
179
173
	if (bmc411120c.reg & (0x08 | bmc411120c_reset)) {
180
	if (bmc411120c.reg & (0x08 | bmc411120ctmp.reset)) {
174
		value = 0x0C | ((bmc411120c.reg >> 4) & 0x03);
181
		value = 0x0C | ((bmc411120c.reg >> 4) & 0x03);
175
		control_bank(info.prg.rom[0].max.banks_32k)
182
		control_bank(info.prg.rom[0].max.banks_32k)
176
		map_prg_rom_8k(4, 0, value);
183
		map_prg_rom_8k(4, 0, value);
(-)puNES-0.105.org/src/core/mappers/mapper_BMC411120C.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _bmc411120c {
25
	BYTE reg;
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} bmc411120c;
29
30
void map_init_BMC411120C(void);
24
void map_init_BMC411120C(void);
31
void extcl_cpu_wr_mem_BMC411120C(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_BMC411120C(WORD address, BYTE value);
32
BYTE extcl_save_mapper_BMC411120C(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_BMC411120C(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_BMC64IN1NOREPEAT.c (+4 lines)
Lines 27-32 INLINE static void bmc64in1norepeat_upda Link Here
27
#define bmc64in1norepeat_prg_8k()\
27
#define bmc64in1norepeat_prg_8k()\
28
	((bmc64in1norepeat.reg[1] & 0x1F) << 1) | ((bmc64in1norepeat.reg[1] >> 6) & 0x01);
28
	((bmc64in1norepeat.reg[1] & 0x1F) << 1) | ((bmc64in1norepeat.reg[1] >> 6) & 0x01);
29
29
30
struct _bmc64in1norepeat {
31
	BYTE reg[4];
32
} bmc64in1norepeat;
33
30
void map_init_BMC64IN1NOREPEAT(void) {
34
void map_init_BMC64IN1NOREPEAT(void) {
31
	EXTCL_CPU_WR_MEM(BMC64IN1NOREPEAT);
35
	EXTCL_CPU_WR_MEM(BMC64IN1NOREPEAT);
32
	EXTCL_SAVE_MAPPER(BMC64IN1NOREPEAT);
36
	EXTCL_SAVE_MAPPER(BMC64IN1NOREPEAT);
(-)puNES-0.105.org/src/core/mappers/mapper_BMC64IN1NOREPEAT.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _bmc64in1norepeat {
25
	BYTE reg[4];
26
} bmc64in1norepeat;
27
28
void map_init_BMC64IN1NOREPEAT(void);
24
void map_init_BMC64IN1NOREPEAT(void);
29
void extcl_cpu_wr_mem_BMC64IN1NOREPEAT(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_BMC64IN1NOREPEAT(WORD address, BYTE value);
30
BYTE extcl_save_mapper_BMC64IN1NOREPEAT(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_BMC64IN1NOREPEAT(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_BMC70IN1.c (-8 / +14 lines)
Lines 22-28 Link Here
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
BYTE bmc70in1_reset, bmc70in1_type;
25
struct _bmc70in1 {
26
	WORD reg[3];
27
} bmc70in1;
28
struct _bmc70in1tmp {
29
	BYTE type;
30
	BYTE reset;
31
} bmc70in1tmp;
26
32
27
void map_init_BMC70IN1(BYTE type) {
33
void map_init_BMC70IN1(BYTE type) {
28
	EXTCL_CPU_WR_MEM(BMC70IN1);
34
	EXTCL_CPU_WR_MEM(BMC70IN1);
Lines 37-52 void map_init_BMC70IN1(BYTE type) { Link Here
37
43
38
	if (info.reset >= HARD) {
44
	if (info.reset >= HARD) {
39
		if (type == BMC70IN1) {
45
		if (type == BMC70IN1) {
40
			bmc70in1_reset = 0x0D;
46
			bmc70in1tmp.reset = 0x0D;
41
		} else {
47
		} else {
42
			bmc70in1_reset = 0x06;
48
			bmc70in1tmp.reset = 0x06;
43
		}
49
		}
44
	} else if (info.reset == RESET) {
50
	} else if (info.reset == RESET) {
45
		bmc70in1_reset++;
51
		bmc70in1tmp.reset++;
46
		bmc70in1_reset = bmc70in1_reset & 0x0F;
52
		bmc70in1tmp.reset = bmc70in1tmp.reset & 0x0F;
47
	}
53
	}
48
54
49
	bmc70in1_type = type;
55
	bmc70in1tmp.type = type;
50
	info.mapper.extend_rd = TRUE;
56
	info.mapper.extend_rd = TRUE;
51
57
52
	extcl_cpu_wr_mem_BMC70IN1(0x0000, 0);
58
	extcl_cpu_wr_mem_BMC70IN1(0x0000, 0);
Lines 62-68 void extcl_cpu_wr_mem_BMC70IN1(WORD addr Link Here
62
			mirroring_V();
68
			mirroring_V();
63
		}
69
		}
64
70
65
		if (bmc70in1_type == BMC70IN1B) {
71
		if (bmc70in1tmp.type == BMC70IN1B) {
66
			bmc70in1.reg[2] = (address & 0x03) << 3;
72
			bmc70in1.reg[2] = (address & 0x03) << 3;
67
		} else {
73
		} else {
68
			DBWORD bank;
74
			DBWORD bank;
Lines 108-114 void extcl_cpu_wr_mem_BMC70IN1(WORD addr Link Here
108
}
114
}
109
BYTE extcl_cpu_rd_mem_BMC70IN1(WORD address, BYTE openbus, UNUSED(BYTE before)) {
115
BYTE extcl_cpu_rd_mem_BMC70IN1(WORD address, BYTE openbus, UNUSED(BYTE before)) {
110
	if ((address >= 0x8000) && (bmc70in1.reg[0] == 0x10)) {
116
	if ((address >= 0x8000) && (bmc70in1.reg[0] == 0x10)) {
111
		address = (address & 0xFFF0) | bmc70in1_reset;
117
		address = (address & 0xFFF0) | bmc70in1tmp.reset;
112
		return (prg_rom_rd(address));
118
		return (prg_rom_rd(address));
113
	}
119
	}
114
	return (openbus);
120
	return (openbus);
(-)puNES-0.105.org/src/core/mappers/mapper_BMC70IN1.h (-4 lines)
Lines 23-32 Link Here
23
23
24
enum _bmc70in1_type { BMC70IN1, BMC70IN1B };
24
enum _bmc70in1_type { BMC70IN1, BMC70IN1B };
25
25
26
struct _bmc70in1 {
27
	WORD reg[3];
28
} bmc70in1;
29
30
void map_init_BMC70IN1(BYTE type);
26
void map_init_BMC70IN1(BYTE type);
31
void extcl_cpu_wr_mem_BMC70IN1(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_BMC70IN1(WORD address, BYTE value);
32
BYTE extcl_cpu_rd_mem_BMC70IN1(WORD address, BYTE openbus, BYTE before);
28
BYTE extcl_cpu_rd_mem_BMC70IN1(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_BMC830118C.c (+6 lines)
Lines 80-85 INLINE static void bmc830118c_update_chr Link Here
80
			break;\
80
			break;\
81
	}
81
	}
82
82
83
struct _bmc830118c {
84
	BYTE reg;
85
	WORD prg_map[4];
86
	WORD chr_map[8];
87
} bmc830118c;
88
83
void map_init_BMC830118C(void) {
89
void map_init_BMC830118C(void) {
84
	EXTCL_CPU_WR_MEM(BMC830118C);
90
	EXTCL_CPU_WR_MEM(BMC830118C);
85
	EXTCL_SAVE_MAPPER(BMC830118C);
91
	EXTCL_SAVE_MAPPER(BMC830118C);
(-)puNES-0.105.org/src/core/mappers/mapper_BMC830118C.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _bmc830118c {
25
	BYTE reg;
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} bmc830118c;
29
30
void map_init_BMC830118C(void);
24
void map_init_BMC830118C(void);
31
void extcl_cpu_wr_mem_BMC830118C(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_BMC830118C(WORD address, BYTE value);
32
BYTE extcl_save_mapper_BMC830118C(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_BMC830118C(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_BMCFK23C.c (+12 lines)
Lines 28-33 static void prg_swap_BMCFK23CPW(WORD add Link Here
28
static void chr_fix_BMCFK23CPW(BYTE value);
28
static void chr_fix_BMCFK23CPW(BYTE value);
29
static void chr_swap_BMCFK23CCW(WORD address, WORD value);
29
static void chr_swap_BMCFK23CCW(WORD address, WORD value);
30
30
31
struct _bmcfk23c {
32
	uint32_t dipswitch;
33
	BYTE unromchr;
34
	BYTE A000;
35
	BYTE A001;
36
	BYTE reg[8];
37
	BYTE mmc3[8];
38
	WORD chr_map[8];
39
	/* questo posso tranquillamente non salvarlo */
40
	BYTE prg_mask;
41
} bmcfk23c;
42
31
void map_init_BMCFK23C(void) {
43
void map_init_BMCFK23C(void) {
32
	EXTCL_CPU_WR_MEM(BMCFK23C);
44
	EXTCL_CPU_WR_MEM(BMCFK23C);
33
	EXTCL_SAVE_MAPPER(BMCFK23C);
45
	EXTCL_SAVE_MAPPER(BMCFK23C);
(-)puNES-0.105.org/src/core/mappers/mapper_BMCFK23C.h (-12 lines)
Lines 23-40 Link Here
23
23
24
enum bmcfk23c_types { NOBMCFK23C, BMCFK23C_0 = 1, BMCFK23C_1 = 2, BMCFK23CA = 8 };
24
enum bmcfk23c_types { NOBMCFK23C, BMCFK23C_0 = 1, BMCFK23C_1 = 2, BMCFK23CA = 8 };
25
25
26
struct _bmcfk23c {
27
	uint32_t dipswitch;
28
	BYTE unromchr;
29
	BYTE A000;
30
	BYTE A001;
31
	BYTE reg[8];
32
	BYTE mmc3[8];
33
	WORD chr_map[8];
34
	/* questo posso tranquillamente non salvarlo */
35
	BYTE prg_mask;
36
} bmcfk23c;
37
38
void map_init_BMCFK23C(void);
26
void map_init_BMCFK23C(void);
39
void extcl_cpu_wr_mem_BMCFK23C(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_BMCFK23C(WORD address, BYTE value);
40
void extcl_wr_chr_BMCFK23C(WORD address, BYTE value);
28
void extcl_wr_chr_BMCFK23C(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_BMCGhostbusters63in1.c (+4 lines)
Lines 25-30 Link Here
25
25
26
INLINE static void bmcghostbusters63in1_update_chr(void);
26
INLINE static void bmcghostbusters63in1_update_chr(void);
27
27
28
struct _bmcghostbusters63in1 {
29
	BYTE reg[2];
30
	BYTE index;
31
} bmcghostbusters63in1;
28
static const BYTE bmcghostbusters63in1_chip[4] = { 0, 0, 1, 2 };
32
static const BYTE bmcghostbusters63in1_chip[4] = { 0, 0, 1, 2 };
29
33
30
void map_init_BMCGHOSTBUSTERS63IN1(void) {
34
void map_init_BMCGHOSTBUSTERS63IN1(void) {
(-)puNES-0.105.org/src/core/mappers/mapper_BMCGhostbusters63in1.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _bmcghostbusters63in1 {
25
	BYTE reg[2];
26
	BYTE index;
27
} bmcghostbusters63in1;
28
29
void map_init_BMCGHOSTBUSTERS63IN1(void);
24
void map_init_BMCGHOSTBUSTERS63IN1(void);
30
void extcl_cpu_wr_mem_BMCGHOSTBUSTERS63IN1(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_BMCGHOSTBUSTERS63IN1(WORD address, BYTE value);
31
//BYTE extcl_cpu_rd_mem_BMCGHOSTBUSTERS63IN1(WORD address, BYTE openbus, BYTE before);
26
//BYTE extcl_cpu_rd_mem_BMCGHOSTBUSTERS63IN1(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_BOY.c (+6 lines)
Lines 77-82 INLINE static void boy_update_chr(void); Link Here
77
			break;\
77
			break;\
78
	}
78
	}
79
79
80
struct _boy {
81
	BYTE reg[4];
82
	WORD prg_map[4];
83
	WORD chr_map[8];
84
} boy;
85
80
void map_init_BOY(void) {
86
void map_init_BOY(void) {
81
	EXTCL_CPU_WR_MEM(BOY);
87
	EXTCL_CPU_WR_MEM(BOY);
82
	EXTCL_SAVE_MAPPER(BOY);
88
	EXTCL_SAVE_MAPPER(BOY);
(-)puNES-0.105.org/src/core/mappers/mapper_BOY.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _boy {
25
	BYTE reg[4];
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} boy;
29
30
void map_init_BOY(void);
24
void map_init_BOY(void);
31
void extcl_cpu_wr_mem_BOY(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_BOY(WORD address, BYTE value);
32
BYTE extcl_save_mapper_BOY(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_BOY(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_BS5.c (-5 / +7 lines)
Lines 21-27 Link Here
21
#include "info.h"
21
#include "info.h"
22
#include "mem_map.h"
22
#include "mem_map.h"
23
23
24
BYTE bs5_reset;
24
struct _bs5mp {
25
	BYTE reset;
26
} bs5tmp;
25
27
26
void map_init_BS5(void) {
28
void map_init_BS5(void) {
27
	EXTCL_CPU_WR_MEM(BS5);
29
	EXTCL_CPU_WR_MEM(BS5);
Lines 35-44 void map_init_BS5(void) { Link Here
35
	}
37
	}
36
38
37
	if (info.reset >= HARD) {
39
	if (info.reset >= HARD) {
38
		bs5_reset = 0;
40
		bs5tmp.reset = 0;
39
	} else if (info.reset == RESET) {
41
	} else if (info.reset == RESET) {
40
		bs5_reset++;
42
		bs5tmp.reset++;
41
		bs5_reset = bs5_reset & 0x03;
43
		bs5tmp.reset = bs5tmp.reset & 0x03;
42
	}
44
	}
43
45
44
	mirroring_V();
46
	mirroring_V();
Lines 59-65 void extcl_cpu_wr_mem_BS5(WORD address, Link Here
59
			return;
61
			return;
60
		}
62
		}
61
		case 0xA000:
63
		case 0xA000:
62
			if (address & (1 << (bs5_reset + 4))) {
64
			if (address & (1 << (bs5tmp.reset + 4))) {
63
				value = address & 0x0F;
65
				value = address & 0x0F;
64
				control_bank(info.prg.rom[0].max.banks_8k)
66
				control_bank(info.prg.rom[0].max.banks_8k)
65
				map_prg_rom_8k(1, base, value);
67
				map_prg_rom_8k(1, base, value);
(-)puNES-0.105.org/src/core/mappers/mapper_Caltron.c (+4 lines)
Lines 21-26 Link Here
21
#include "mem_map.h"
21
#include "mem_map.h"
22
#include "save_slot.h"
22
#include "save_slot.h"
23
23
24
struct _caltron {
25
	BYTE reg;
26
} caltron;
27
24
void map_init_Caltron(void) {
28
void map_init_Caltron(void) {
25
	EXTCL_CPU_WR_MEM(Caltron);
29
	EXTCL_CPU_WR_MEM(Caltron);
26
	mapper.internal_struct[0] = (BYTE *) &caltron;
30
	mapper.internal_struct[0] = (BYTE *) &caltron;
(-)puNES-0.105.org/src/core/mappers/mapper_Caltron.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _caltron {
25
	BYTE reg;
26
} caltron;
27
28
void map_init_Caltron(void);
24
void map_init_Caltron(void);
29
void extcl_cpu_wr_mem_Caltron(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_Caltron(WORD address, BYTE value);
30
BYTE extcl_save_mapper_Caltron(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_Caltron(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_CITYFIGHT.c (+9 lines)
Lines 31-36 Link Here
31
31
32
INLINE static void cityfight_prg_update(void);
32
INLINE static void cityfight_prg_update(void);
33
33
34
struct _cityfight {
35
	BYTE reg[2];
36
	WORD chr_map[8];
37
	struct _cityfight_irq {
38
		BYTE enable;
39
		WORD count;
40
	} irq;
41
} cityfight;
42
34
void map_init_CITYFIGHT(void) {
43
void map_init_CITYFIGHT(void) {
35
	EXTCL_CPU_WR_MEM(CITYFIGHT);
44
	EXTCL_CPU_WR_MEM(CITYFIGHT);
36
	EXTCL_SAVE_MAPPER(CITYFIGHT);
45
	EXTCL_SAVE_MAPPER(CITYFIGHT);
(-)puNES-0.105.org/src/core/mappers/mapper_CITYFIGHT.h (-9 lines)
Lines 21-35 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _cityfight {
25
	BYTE reg[2];
26
	WORD chr_map[8];
27
	struct _cityfight_irq {
28
		BYTE enable;
29
		WORD count;
30
	} irq;
31
} cityfight;
32
33
void map_init_CITYFIGHT(void);
24
void map_init_CITYFIGHT(void);
34
void extcl_cpu_wr_mem_CITYFIGHT(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_CITYFIGHT(WORD address, BYTE value);
35
BYTE extcl_save_mapper_CITYFIGHT(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_CITYFIGHT(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_CNROM.c (-10 / +16 lines)
Lines 22-33 Link Here
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
BYTE mask, state;
25
struct _cnrom_2627 {
26
	BYTE chr_rd_enable;
27
} cnrom_2627;
28
struct _cnromtmp {
29
	BYTE mask;
30
	BYTE state;
31
} cnromtmp;
26
32
27
void map_init_CNROM() {
33
void map_init_CNROM() {
28
	EXTCL_CPU_WR_MEM(CNROM);
34
	EXTCL_CPU_WR_MEM(CNROM);
29
35
30
	mask = state = 0x00;
36
	cnromtmp.mask = cnromtmp.state = 0x00;
31
37
32
	/*
38
	/*
33
	 * "Cybernoid - The Fighting Machine (U) [!].nes" vuole
39
	 * "Cybernoid - The Fighting Machine (U) [!].nes" vuole
Lines 41-60 void map_init_CNROM() { Link Here
41
		mapper.internal_struct_size[0] = sizeof(cnrom_2627);
47
		mapper.internal_struct_size[0] = sizeof(cnrom_2627);
42
48
43
		memset(&cnrom_2627, 0x00, sizeof(cnrom_2627));
49
		memset(&cnrom_2627, 0x00, sizeof(cnrom_2627));
44
		mask = 0x03;
50
		cnromtmp.mask = 0x03;
45
51
46
		switch (info.id) {
52
		switch (info.id) {
47
			case CNROM_26CE27CE:
53
			case CNROM_26CE27CE:
48
				state = 0x03;
54
				cnromtmp.state = 0x03;
49
				break;
55
				break;
50
			case CNROM_26CE27NCE:
56
			case CNROM_26CE27NCE:
51
				state = 0x01;
57
				cnromtmp.state = 0x01;
52
				break;
58
				break;
53
			case CNROM_26NCE27CE:
59
			case CNROM_26NCE27CE:
54
				state = 0x02;
60
				cnromtmp.state = 0x02;
55
				break;
61
				break;
56
			case CNROM_26NCE27NCE:
62
			case CNROM_26NCE27NCE:
57
				state = 0x00;
63
				cnromtmp.state = 0x00;
58
				break;
64
				break;
59
		}
65
		}
60
	}
66
	}
Lines 67-79 void extcl_cpu_wr_mem_CNROM(WORD address Link Here
67
		value &= prg_rom_rd(address);
73
		value &= prg_rom_rd(address);
68
	}
74
	}
69
75
70
	if (mask) {
76
	if (cnromtmp.mask) {
71
		if ((value & mask) == state) {
77
		if ((value & cnromtmp.mask) == cnromtmp.state) {
72
			cnrom_2627.chr_rd_enable = FALSE;
78
			cnrom_2627.chr_rd_enable = FALSE;
73
		} else {
79
		} else {
74
			cnrom_2627.chr_rd_enable = TRUE;
80
			cnrom_2627.chr_rd_enable = TRUE;
75
		}
81
		}
76
		value &= ~mask;
82
		value &= ~cnromtmp.mask;
77
	}
83
	}
78
84
79
	control_bank(info.chr.rom[0].max.banks_8k)
85
	control_bank(info.chr.rom[0].max.banks_8k)
(-)puNES-0.105.org/src/core/mappers/mapper_CNROM.h (-4 lines)
Lines 30-39 enum { Link Here
30
	BAD_INES_TETRIS_BPS = 20
30
	BAD_INES_TETRIS_BPS = 20
31
};
31
};
32
32
33
struct _cnrom_2627 {
34
	BYTE chr_rd_enable;
35
} cnrom_2627;
36
37
void map_init_CNROM();
33
void map_init_CNROM();
38
void extcl_cpu_wr_mem_CNROM(WORD address, BYTE value);
34
void extcl_cpu_wr_mem_CNROM(WORD address, BYTE value);
39
BYTE extcl_save_mapper_CNROM(BYTE mode, BYTE slot, FILE *fp);
35
BYTE extcl_save_mapper_CNROM(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_DRAGONFIGHTER.c (+6 lines)
Lines 77-82 INLINE static void dragonfighter_update_ Link Here
77
			break;\
77
			break;\
78
	}
78
	}
79
79
80
struct _dragonfighter {
81
	BYTE reg[3];
82
	WORD prg_map[4];
83
	WORD chr_map[8];
84
} dragonfighter;
85
80
void map_init_DRAGONFIGHTER(void) {
86
void map_init_DRAGONFIGHTER(void) {
81
	EXTCL_CPU_WR_MEM(DRAGONFIGHTER);
87
	EXTCL_CPU_WR_MEM(DRAGONFIGHTER);
82
	EXTCL_CPU_RD_MEM(DRAGONFIGHTER);
88
	EXTCL_CPU_RD_MEM(DRAGONFIGHTER);
(-)puNES-0.105.org/src/core/mappers/mapper_DRAGONFIGHTER.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _dragonfighter {
25
	BYTE reg[3];
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} dragonfighter;
29
30
void map_init_DRAGONFIGHTER(void);
24
void map_init_DRAGONFIGHTER(void);
31
void extcl_cpu_wr_mem_DRAGONFIGHTER(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_DRAGONFIGHTER(WORD address, BYTE value);
32
BYTE extcl_cpu_rd_mem_DRAGONFIGHTER(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_DRAGONFIGHTER(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_DREAMTECH01.c (-1 lines)
Lines 29-35 void map_init_DREAMTECH01(void) { Link Here
29
		map_prg_rom_8k(2, 0, 8);
29
		map_prg_rom_8k(2, 0, 8);
30
	//}
30
	//}
31
}
31
}
32
33
void extcl_cpu_wr_mem_DREAMTECH01(WORD address, BYTE value) {
32
void extcl_cpu_wr_mem_DREAMTECH01(WORD address, BYTE value) {
34
	if (address != 0x5020) {
33
	if (address != 0x5020) {
35
		return;
34
		return;
(-)puNES-0.105.org/src/core/mappers/mapper_DREAMTECH01.h (-1 lines)
Lines 22-28 Link Here
22
#include "common.h"
22
#include "common.h"
23
23
24
void map_init_DREAMTECH01(void);
24
void map_init_DREAMTECH01(void);
25
26
void extcl_cpu_wr_mem_DREAMTECH01(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_DREAMTECH01(WORD address, BYTE value);
27
26
28
#endif /* MAPPER_DREAMTECH01_H_ */
27
#endif /* MAPPER_DREAMTECH01_H_ */
(-)puNES-0.105.org/src/core/mappers/mapper_EDU2000.c (+5 lines)
Lines 22-27 Link Here
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
struct _edu2000 {
26
	BYTE reg;
27
	uint32_t prg_ram_address;
28
} edu2000;
29
25
void map_init_EDU2000(void) {
30
void map_init_EDU2000(void) {
26
	EXTCL_CPU_WR_MEM(EDU2000);
31
	EXTCL_CPU_WR_MEM(EDU2000);
27
	EXTCL_CPU_RD_MEM(EDU2000);
32
	EXTCL_CPU_RD_MEM(EDU2000);
(-)puNES-0.105.org/src/core/mappers/mapper_EDU2000.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _edu2000 {
25
	BYTE reg;
26
	uint32_t prg_ram_address;
27
} edu2000;
28
29
void map_init_EDU2000(void);
24
void map_init_EDU2000(void);
30
void extcl_cpu_wr_mem_EDU2000(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_EDU2000(WORD address, BYTE value);
31
BYTE extcl_cpu_rd_mem_EDU2000(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_EDU2000(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_EH8813A.c (+5 lines)
Lines 21-26 Link Here
21
#include "mem_map.h"
21
#include "mem_map.h"
22
#include "save_slot.h"
22
#include "save_slot.h"
23
23
24
struct _eh8813a {
25
	WORD address;
26
	BYTE hwmode;
27
} eh88131a;
28
24
void map_init_EH8813A(void) {
29
void map_init_EH8813A(void) {
25
	EXTCL_CPU_WR_MEM(EH8813A);
30
	EXTCL_CPU_WR_MEM(EH8813A);
26
	EXTCL_CPU_RD_MEM(EH8813A);
31
	EXTCL_CPU_RD_MEM(EH8813A);
(-)puNES-0.105.org/src/core/mappers/mapper_EH8813A.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _eh8813a {
25
	WORD address;
26
	BYTE hwmode;
27
} eh88131a;
28
29
void map_init_EH8813A(void);
24
void map_init_EH8813A(void);
30
void extcl_cpu_wr_mem_EH8813A(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_EH8813A(WORD address, BYTE value);
31
BYTE extcl_cpu_rd_mem_EH8813A(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_EH8813A(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_FS304.c (+4 lines)
Lines 20-25 Link Here
20
#include "info.h"
20
#include "info.h"
21
#include "save_slot.h"
21
#include "save_slot.h"
22
22
23
struct _fs304 {
24
	BYTE reg[4];
25
} fs304;
26
23
void map_init_FS304(void) {
27
void map_init_FS304(void) {
24
	EXTCL_CPU_WR_MEM(FS304);
28
	EXTCL_CPU_WR_MEM(FS304);
25
	EXTCL_SAVE_MAPPER(FS304);
29
	EXTCL_SAVE_MAPPER(FS304);
(-)puNES-0.105.org/src/core/mappers/mapper_FS304.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _fs304 {
25
	BYTE reg[4];
26
} fs304;
27
28
void map_init_FS304(void);
24
void map_init_FS304(void);
29
void extcl_cpu_wr_mem_FS304(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_FS304(WORD address, BYTE value);
30
BYTE extcl_save_mapper_FS304(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_FS304(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_Futuremedia.c (+4 lines)
Lines 23-28 Link Here
23
#include "irqA12.h"
23
#include "irqA12.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _futuremedia {
27
	BYTE delay;
28
} futuremedia;
29
26
void map_init_Futuremedia(void) {
30
void map_init_Futuremedia(void) {
27
	EXTCL_CPU_WR_MEM(Futuremedia);
31
	EXTCL_CPU_WR_MEM(Futuremedia);
28
	EXTCL_SAVE_MAPPER(Futuremedia);
32
	EXTCL_SAVE_MAPPER(Futuremedia);
(-)puNES-0.105.org/src/core/mappers/mapper_Futuremedia.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _futuremedia {
25
	BYTE delay;
26
} futuremedia;
27
28
void map_init_Futuremedia(void);
24
void map_init_Futuremedia(void);
29
void extcl_cpu_wr_mem_Futuremedia(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_Futuremedia(WORD address, BYTE value);
30
BYTE extcl_save_mapper_Futuremedia(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_Futuremedia(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_GS_2004.c (-3 / +5 lines)
Lines 20-26 Link Here
20
#include "mem_map.h"
20
#include "mem_map.h"
21
#include "info.h"
21
#include "info.h"
22
22
23
BYTE *gs_2004_prg_6000;
23
struct _gs2004tmp {
24
	BYTE *prg_6000;
25
} gs2004tmp;
24
26
25
void map_init_GS_2004(void) {
27
void map_init_GS_2004(void) {
26
	EXTCL_CPU_WR_MEM(GS_2004);
28
	EXTCL_CPU_WR_MEM(GS_2004);
Lines 33-39 void map_init_GS_2004(void) { Link Here
33
		map_prg_rom_8k(4, 0, value);
35
		map_prg_rom_8k(4, 0, value);
34
	}
36
	}
35
37
36
	gs_2004_prg_6000 = prg_chip_byte_pnt(1, 0);
38
	gs2004tmp.prg_6000 = prg_chip_byte_pnt(1, 0);
37
}
39
}
38
void extcl_cpu_wr_mem_GS_2004(UNUSED(WORD address), BYTE value) {
40
void extcl_cpu_wr_mem_GS_2004(UNUSED(WORD address), BYTE value) {
39
	control_bank(info.prg.rom[0].max.banks_32k)
41
	control_bank(info.prg.rom[0].max.banks_32k)
Lines 42-48 void extcl_cpu_wr_mem_GS_2004(UNUSED(WOR Link Here
42
}
44
}
43
BYTE extcl_cpu_rd_mem_GS_2004(WORD address, BYTE openbus, UNUSED(BYTE before)) {
45
BYTE extcl_cpu_rd_mem_GS_2004(WORD address, BYTE openbus, UNUSED(BYTE before)) {
44
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
46
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
45
		return (gs_2004_prg_6000[address & 0x1FFF]);
47
		return (gs2004tmp.prg_6000[address & 0x1FFF]);
46
	}
48
	}
47
	return (openbus);
49
	return (openbus);
48
}
50
}
(-)puNES-0.105.org/src/core/mappers/mapper_GS_2013.c (-3 / +5 lines)
Lines 20-26 Link Here
20
#include "mem_map.h"
20
#include "mem_map.h"
21
#include "info.h"
21
#include "info.h"
22
22
23
BYTE *gs_2013_prg_6000;
23
struct _gs2013tmp {
24
	BYTE *prg_6000;
25
} gs2013tmp;
24
26
25
void map_init_GS_2013(void) {
27
void map_init_GS_2013(void) {
26
	EXTCL_CPU_WR_MEM(GS_2013);
28
	EXTCL_CPU_WR_MEM(GS_2013);
Lines 31-37 void map_init_GS_2013(void) { Link Here
31
33
32
		value = 0xFF;
34
		value = 0xFF;
33
		control_bank(info.prg.rom[0].max.banks_8k)
35
		control_bank(info.prg.rom[0].max.banks_8k)
34
		gs_2013_prg_6000 = prg_chip_byte_pnt(0, value << 13);
36
		gs2013tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13);
35
	}
37
	}
36
38
37
	extcl_cpu_wr_mem_GS_2013(0x0000, 0xFF);
39
	extcl_cpu_wr_mem_GS_2013(0x0000, 0xFF);
Lines 46-52 void extcl_cpu_wr_mem_GS_2013(UNUSED(WOR Link Here
46
}
48
}
47
BYTE extcl_cpu_rd_mem_GS_2013(WORD address, BYTE openbus, UNUSED(BYTE before)) {
49
BYTE extcl_cpu_rd_mem_GS_2013(WORD address, BYTE openbus, UNUSED(BYTE before)) {
48
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
50
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
49
		return (gs_2013_prg_6000[address & 0x1FFF]);
51
		return (gs2013tmp.prg_6000[address & 0x1FFF]);
50
	}
52
	}
51
	return (openbus);
53
	return (openbus);
52
}
54
}
(-)puNES-0.105.org/src/core/mappers/mapper_H2288.c (-209 / +215 lines)
Lines 1-209 Link Here
1
/*
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
2
 *  Copyright (C) 2010-2020 Fabio Cavallo (aka FHorse)
3
 *
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
7
 *  (at your option) any later version.
8
 *
8
 *
9
 *  This program is distributed in the hope that it will be useful,
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
12
 *  GNU General Public License for more details.
13
 *
13
 *
14
 *  You should have received a copy of the GNU General Public License
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
17
 */
18
18
19
#include <string.h>
19
#include <string.h>
20
#include "mappers.h"
20
#include "mappers.h"
21
#include "info.h"
21
#include "info.h"
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "irqA12.h"
24
#include "irqA12.h"
25
#include "save_slot.h"
25
#include "save_slot.h"
26
26
27
INLINE static void h2288_update_prg(void);
27
INLINE static void h2288_update_prg(void);
28
INLINE static void h2288_update_chr(void);
28
INLINE static void h2288_update_chr(void);
29
29
30
#define h2288_chr_1k(vl) value = vl 
30
#define h2288_chr_1k(vl) value = vl 
31
#define h2288_prg_8k(vl) value = (vl & 0x3F)
31
#define h2288_prg_8k(vl) value = (vl & 0x3F)
32
#define h2288_swap_chr_1k(a, b)\
32
#define h2288_swap_chr_1k(a, b)\
33
	chr1k = h2288.chr_map[b];\
33
	chr1k = h2288.chr_map[b];\
34
	h2288.chr_map[b] = h2288.chr_map[a];\
34
	h2288.chr_map[b] = h2288.chr_map[a];\
35
	h2288.chr_map[a] = chr1k
35
	h2288.chr_map[a] = chr1k
36
#define h2288_8000()\
36
#define h2288_8000()\
37
	if (mmc3.chr_rom_cfg != old_chr_rom_cfg) {\
37
	if (mmc3.chr_rom_cfg != old_chr_rom_cfg) {\
38
		BYTE chr1k;\
38
		BYTE chr1k;\
39
		h2288_swap_chr_1k(0, 4);\
39
		h2288_swap_chr_1k(0, 4);\
40
		h2288_swap_chr_1k(1, 5);\
40
		h2288_swap_chr_1k(1, 5);\
41
		h2288_swap_chr_1k(2, 6);\
41
		h2288_swap_chr_1k(2, 6);\
42
		h2288_swap_chr_1k(3, 7);\
42
		h2288_swap_chr_1k(3, 7);\
43
	}\
43
	}\
44
	if (mmc3.prg_rom_cfg != old_prg_rom_cfg) {\
44
	if (mmc3.prg_rom_cfg != old_prg_rom_cfg) {\
45
		mapper.rom_map_to[2] = h2288.prg_map[0];\
45
		mapper.rom_map_to[2] = h2288.prg_map[0];\
46
		mapper.rom_map_to[0] = h2288.prg_map[2];\
46
		mapper.rom_map_to[0] = h2288.prg_map[2];\
47
		h2288.prg_map[0] = mapper.rom_map_to[0];\
47
		h2288.prg_map[0] = mapper.rom_map_to[0];\
48
		h2288.prg_map[2] = mapper.rom_map_to[2];\
48
		h2288.prg_map[2] = mapper.rom_map_to[2];\
49
		h2288.prg_map[mmc3.prg_rom_cfg ^ 0x02] = info.prg.rom[0].max.banks_8k_before_last;\
49
		h2288.prg_map[mmc3.prg_rom_cfg ^ 0x02] = info.prg.rom[0].max.banks_8k_before_last;\
50
	}
50
	}
51
#define h2288_8001()\
51
#define h2288_8001()\
52
	switch (mmc3.bank_to_update) {\
52
	switch (mmc3.bank_to_update) {\
53
		case 0:\
53
		case 0:\
54
			control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\
54
			control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\
55
			h2288.chr_map[mmc3.chr_rom_cfg] = value;\
55
			h2288.chr_map[mmc3.chr_rom_cfg] = value;\
56
			h2288.chr_map[mmc3.chr_rom_cfg | 0x01] = value + 1;\
56
			h2288.chr_map[mmc3.chr_rom_cfg | 0x01] = value + 1;\
57
			break;\
57
			break;\
58
		case 1:\
58
		case 1:\
59
			control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\
59
			control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\
60
			h2288.chr_map[mmc3.chr_rom_cfg | 0x02] = value;\
60
			h2288.chr_map[mmc3.chr_rom_cfg | 0x02] = value;\
61
			h2288.chr_map[mmc3.chr_rom_cfg | 0x03] = value + 1;\
61
			h2288.chr_map[mmc3.chr_rom_cfg | 0x03] = value + 1;\
62
			break;\
62
			break;\
63
		case 2:\
63
		case 2:\
64
			h2288.chr_map[mmc3.chr_rom_cfg ^ 0x04] = value;\
64
			h2288.chr_map[mmc3.chr_rom_cfg ^ 0x04] = value;\
65
			break;\
65
			break;\
66
		case 3:\
66
		case 3:\
67
			h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x01] = value;\
67
			h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x01] = value;\
68
			break;\
68
			break;\
69
		case 4:\
69
		case 4:\
70
			h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x02] = value;\
70
			h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x02] = value;\
71
			break;\
71
			break;\
72
		case 5:\
72
		case 5:\
73
			h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x03] = value;\
73
			h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x03] = value;\
74
			break;\
74
			break;\
75
		case 6:\
75
		case 6:\
76
			h2288.prg_map[mmc3.prg_rom_cfg] = value;\
76
			h2288.prg_map[mmc3.prg_rom_cfg] = value;\
77
			break;\
77
			break;\
78
		case 7:\
78
		case 7:\
79
			h2288.prg_map[1] = value;\
79
			h2288.prg_map[1] = value;\
80
			break;\
80
			break;\
81
	}
81
	}
82
82
83
void map_init_H2288(void) {
83
struct _h2288 {
84
	EXTCL_CPU_WR_MEM(H2288);
84
	BYTE reg[2];
85
	EXTCL_SAVE_MAPPER(H2288);
85
	WORD prg_map[4];
86
	EXTCL_CPU_EVERY_CYCLE(MMC3);
86
	WORD chr_map[8];
87
	EXTCL_PPU_000_TO_34X(MMC3);
87
} h2288;
88
	EXTCL_PPU_000_TO_255(MMC3);
88
89
	EXTCL_PPU_256_TO_319(MMC3);
89
void map_init_H2288(void) {
90
	EXTCL_PPU_320_TO_34X(MMC3);
90
	EXTCL_CPU_WR_MEM(H2288);
91
	EXTCL_UPDATE_R2006(MMC3);
91
	EXTCL_SAVE_MAPPER(H2288);
92
	mapper.internal_struct[0] = (BYTE *) &h2288;
92
	EXTCL_CPU_EVERY_CYCLE(MMC3);
93
	mapper.internal_struct_size[0] = sizeof(h2288);
93
	EXTCL_PPU_000_TO_34X(MMC3);
94
	mapper.internal_struct[1] = (BYTE *) &mmc3;
94
	EXTCL_PPU_000_TO_255(MMC3);
95
	mapper.internal_struct_size[1] = sizeof(mmc3);
95
	EXTCL_PPU_256_TO_319(MMC3);
96
96
	EXTCL_PPU_320_TO_34X(MMC3);
97
	memset(&h2288, 0x00, sizeof(h2288));
97
	EXTCL_UPDATE_R2006(MMC3);
98
	memset(&mmc3, 0x00, sizeof(mmc3));
98
	mapper.internal_struct[0] = (BYTE *) &h2288;
99
	memset(&irqA12, 0x00, sizeof(irqA12));
99
	mapper.internal_struct_size[0] = sizeof(h2288);
100
100
	mapper.internal_struct[1] = (BYTE *) &mmc3;
101
	{
101
	mapper.internal_struct_size[1] = sizeof(mmc3);
102
		BYTE i;
102
103
103
	memset(&h2288, 0x00, sizeof(h2288));
104
		map_prg_rom_8k_reset();
104
	memset(&mmc3, 0x00, sizeof(mmc3));
105
		map_chr_bank_1k_reset();
105
	memset(&irqA12, 0x00, sizeof(irqA12));
106
106
107
		for (i = 0; i < 8; i++) {
107
	{
108
			if (i < 4) {
108
		BYTE i;
109
				h2288.prg_map[i] = mapper.rom_map_to[i];
109
110
			}
110
		map_prg_rom_8k_reset();
111
			h2288.chr_map[i] = i;
111
		map_chr_bank_1k_reset();
112
		}
112
113
	}
113
		for (i = 0; i < 8; i++) {
114
114
			if (i < 4) {
115
	h2288_update_prg();
115
				h2288.prg_map[i] = mapper.rom_map_to[i];
116
	h2288_update_chr();
116
			}
117
117
			h2288.chr_map[i] = i;
118
	info.mapper.extend_wr = TRUE;
118
		}
119
119
	}
120
	irqA12.present = TRUE;
120
121
	irqA12_delay = 1;
121
	h2288_update_prg();
122
}
122
	h2288_update_chr();
123
void extcl_cpu_wr_mem_H2288(WORD address, BYTE value) {
123
124
	if (address >= 0x8000) {
124
	info.mapper.extend_wr = TRUE;
125
		BYTE old_prg_rom_cfg = mmc3.prg_rom_cfg;
125
126
		BYTE old_chr_rom_cfg = mmc3.chr_rom_cfg;
126
	irqA12.present = TRUE;
127
127
	irqA12_delay = 1;
128
		switch (address & 0xE001) {
128
}
129
			case 0x8000:
129
void extcl_cpu_wr_mem_H2288(WORD address, BYTE value) {
130
				extcl_cpu_wr_mem_MMC3(address, (value & 0xC0) | vlu114[value & 7]);
130
	if (address >= 0x8000) {
131
				h2288_8000()
131
		BYTE old_prg_rom_cfg = mmc3.prg_rom_cfg;
132
				h2288_update_prg();
132
		BYTE old_chr_rom_cfg = mmc3.chr_rom_cfg;
133
				h2288_update_chr();
133
134
				return;
134
		switch (address & 0xE001) {
135
			case 0x8001:
135
			case 0x8000:
136
				extcl_cpu_wr_mem_MMC3(address, value);
136
				extcl_cpu_wr_mem_MMC3(address, (value & 0xC0) | vlu114[value & 7]);
137
				h2288_8001()
137
				h2288_8000()
138
				h2288_update_prg();
138
				h2288_update_prg();
139
				h2288_update_chr();
139
				h2288_update_chr();
140
				return;
140
				return;
141
			default:
141
			case 0x8001:
142
				extcl_cpu_wr_mem_MMC3(address, value);
142
				extcl_cpu_wr_mem_MMC3(address, value);
143
				return;
143
				h2288_8001()
144
		}
144
				h2288_update_prg();
145
	}
145
				h2288_update_chr();
146
146
				return;
147
	if ((address >= 0x5000) && (address <= 0x5FFF)) {
147
			default:
148
		if (address & 0x0800) {
148
				extcl_cpu_wr_mem_MMC3(address, value);
149
			if (address & 0x0001) {
149
				return;
150
				h2288.reg[1] = value;
150
		}
151
			} else {
151
	}
152
				h2288.reg[0] = value;
152
153
				h2288_update_prg();
153
	if ((address >= 0x5000) && (address <= 0x5FFF)) {
154
			}
154
		if (address & 0x0800) {
155
		}
155
			if (address & 0x0001) {
156
	}
156
				h2288.reg[1] = value;
157
}
157
			} else {
158
BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp) {
158
				h2288.reg[0] = value;
159
	save_slot_ele(mode, slot, h2288.reg);
159
				h2288_update_prg();
160
	save_slot_ele(mode, slot, h2288.prg_map);
160
			}
161
	save_slot_ele(mode, slot, h2288.chr_map);
161
		}
162
	extcl_save_mapper_MMC3(mode, slot, fp);
162
	}
163
163
}
164
	return (EXIT_OK);
164
BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp) {
165
}
165
	save_slot_ele(mode, slot, h2288.reg);
166
166
	save_slot_ele(mode, slot, h2288.prg_map);
167
INLINE static void h2288_update_prg(void) {
167
	save_slot_ele(mode, slot, h2288.chr_map);
168
	BYTE value;
168
	extcl_save_mapper_MMC3(mode, slot, fp);
169
169
170
	if (h2288.reg[0] & 0x40) {
170
	return (EXIT_OK);
171
		value = (h2288.reg[0] & 0x05) | ((h2288.reg[0] & 0x08) >> 2) | ((h2288.reg[0] & 0x20) >> 2);
171
}
172
		if (h2288.reg[0] & 0x02) {
172
173
			value = value >> 1;
173
INLINE static void h2288_update_prg(void) {
174
			control_bank(info.prg.rom[0].max.banks_32k)
174
	BYTE value;
175
			map_prg_rom_8k(4, 0, value);
175
176
		} else {
176
	if (h2288.reg[0] & 0x40) {
177
			control_bank(info.prg.rom[0].max.banks_16k)
177
		value = (h2288.reg[0] & 0x05) | ((h2288.reg[0] & 0x08) >> 2) | ((h2288.reg[0] & 0x20) >> 2);
178
			map_prg_rom_8k(2, 0, value);
178
		if (h2288.reg[0] & 0x02) {
179
			map_prg_rom_8k(2, 2, value);
179
			value = value >> 1;
180
		}
180
			control_bank(info.prg.rom[0].max.banks_32k)
181
	} else {
181
			map_prg_rom_8k(4, 0, value);
182
		h2288_prg_8k(h2288.prg_map[0]);
182
		} else {
183
		control_bank(info.prg.rom[0].max.banks_8k)
183
			control_bank(info.prg.rom[0].max.banks_16k)
184
		map_prg_rom_8k(1, 0, value);
184
			map_prg_rom_8k(2, 0, value);
185
185
			map_prg_rom_8k(2, 2, value);
186
		h2288_prg_8k(h2288.prg_map[1]);
186
		}
187
		control_bank(info.prg.rom[0].max.banks_8k)
187
	} else {
188
		map_prg_rom_8k(1, 1, value);
188
		h2288_prg_8k(h2288.prg_map[0]);
189
189
		control_bank(info.prg.rom[0].max.banks_8k)
190
		h2288_prg_8k(h2288.prg_map[2]);
190
		map_prg_rom_8k(1, 0, value);
191
		control_bank(info.prg.rom[0].max.banks_8k)
191
192
		map_prg_rom_8k(1, 2, value);
192
		h2288_prg_8k(h2288.prg_map[1]);
193
193
		control_bank(info.prg.rom[0].max.banks_8k)
194
		h2288_prg_8k(h2288.prg_map[3]);
194
		map_prg_rom_8k(1, 1, value);
195
		control_bank(info.prg.rom[0].max.banks_8k)
195
196
		map_prg_rom_8k(1, 3, value);
196
		h2288_prg_8k(h2288.prg_map[2]);
197
	}
197
		control_bank(info.prg.rom[0].max.banks_8k)
198
	map_prg_rom_8k_update();
198
		map_prg_rom_8k(1, 2, value);
199
}
199
200
INLINE static void h2288_update_chr(void) {
200
		h2288_prg_8k(h2288.prg_map[3]);
201
	BYTE i;
201
		control_bank(info.prg.rom[0].max.banks_8k)
202
	WORD value;
202
		map_prg_rom_8k(1, 3, value);
203
203
	}
204
	for (i = 0; i < 8; i++) {
204
	map_prg_rom_8k_update();
205
		h2288_chr_1k(h2288.chr_map[i]);
205
}
206
		control_bank(info.chr.rom[0].max.banks_1k)
206
INLINE static void h2288_update_chr(void) {
207
		chr.bank_1k[i] = chr_chip_byte_pnt(0, value << 10);
207
	BYTE i;
208
	}
208
	WORD value;
209
}
209
210
	for (i = 0; i < 8; i++) {
211
		h2288_chr_1k(h2288.chr_map[i]);
212
		control_bank(info.chr.rom[0].max.banks_1k)
213
		chr.bank_1k[i] = chr_chip_byte_pnt(0, value << 10);
214
	}
215
}
(-)puNES-0.105.org/src/core/mappers/mapper_H2288.c.orig (+209 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#include <string.h>
20
#include "mappers.h"
21
#include "info.h"
22
#include "mem_map.h"
23
#include "cpu.h"
24
#include "irqA12.h"
25
#include "save_slot.h"
26
27
INLINE static void h2288_update_prg(void);
28
INLINE static void h2288_update_chr(void);
29
30
#define h2288_chr_1k(vl) value = vl 
31
#define h2288_prg_8k(vl) value = (vl & 0x3F)
32
#define h2288_swap_chr_1k(a, b)\
33
	chr1k = h2288.chr_map[b];\
34
	h2288.chr_map[b] = h2288.chr_map[a];\
35
	h2288.chr_map[a] = chr1k
36
#define h2288_8000()\
37
	if (mmc3.chr_rom_cfg != old_chr_rom_cfg) {\
38
		BYTE chr1k;\
39
		h2288_swap_chr_1k(0, 4);\
40
		h2288_swap_chr_1k(1, 5);\
41
		h2288_swap_chr_1k(2, 6);\
42
		h2288_swap_chr_1k(3, 7);\
43
	}\
44
	if (mmc3.prg_rom_cfg != old_prg_rom_cfg) {\
45
		mapper.rom_map_to[2] = h2288.prg_map[0];\
46
		mapper.rom_map_to[0] = h2288.prg_map[2];\
47
		h2288.prg_map[0] = mapper.rom_map_to[0];\
48
		h2288.prg_map[2] = mapper.rom_map_to[2];\
49
		h2288.prg_map[mmc3.prg_rom_cfg ^ 0x02] = info.prg.rom[0].max.banks_8k_before_last;\
50
	}
51
#define h2288_8001()\
52
	switch (mmc3.bank_to_update) {\
53
		case 0:\
54
			control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\
55
			h2288.chr_map[mmc3.chr_rom_cfg] = value;\
56
			h2288.chr_map[mmc3.chr_rom_cfg | 0x01] = value + 1;\
57
			break;\
58
		case 1:\
59
			control_bank_with_AND(0xFE, info.chr.rom[0].max.banks_1k)\
60
			h2288.chr_map[mmc3.chr_rom_cfg | 0x02] = value;\
61
			h2288.chr_map[mmc3.chr_rom_cfg | 0x03] = value + 1;\
62
			break;\
63
		case 2:\
64
			h2288.chr_map[mmc3.chr_rom_cfg ^ 0x04] = value;\
65
			break;\
66
		case 3:\
67
			h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x01] = value;\
68
			break;\
69
		case 4:\
70
			h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x02] = value;\
71
			break;\
72
		case 5:\
73
			h2288.chr_map[(mmc3.chr_rom_cfg ^ 0x04) | 0x03] = value;\
74
			break;\
75
		case 6:\
76
			h2288.prg_map[mmc3.prg_rom_cfg] = value;\
77
			break;\
78
		case 7:\
79
			h2288.prg_map[1] = value;\
80
			break;\
81
	}
82
83
void map_init_H2288(void) {
84
	EXTCL_CPU_WR_MEM(H2288);
85
	EXTCL_SAVE_MAPPER(H2288);
86
	EXTCL_CPU_EVERY_CYCLE(MMC3);
87
	EXTCL_PPU_000_TO_34X(MMC3);
88
	EXTCL_PPU_000_TO_255(MMC3);
89
	EXTCL_PPU_256_TO_319(MMC3);
90
	EXTCL_PPU_320_TO_34X(MMC3);
91
	EXTCL_UPDATE_R2006(MMC3);
92
	mapper.internal_struct[0] = (BYTE *) &h2288;
93
	mapper.internal_struct_size[0] = sizeof(h2288);
94
	mapper.internal_struct[1] = (BYTE *) &mmc3;
95
	mapper.internal_struct_size[1] = sizeof(mmc3);
96
97
	memset(&h2288, 0x00, sizeof(h2288));
98
	memset(&mmc3, 0x00, sizeof(mmc3));
99
	memset(&irqA12, 0x00, sizeof(irqA12));
100
101
	{
102
		BYTE i;
103
104
		map_prg_rom_8k_reset();
105
		map_chr_bank_1k_reset();
106
107
		for (i = 0; i < 8; i++) {
108
			if (i < 4) {
109
				h2288.prg_map[i] = mapper.rom_map_to[i];
110
			}
111
			h2288.chr_map[i] = i;
112
		}
113
	}
114
115
	h2288_update_prg();
116
	h2288_update_chr();
117
118
	info.mapper.extend_wr = TRUE;
119
120
	irqA12.present = TRUE;
121
	irqA12_delay = 1;
122
}
123
void extcl_cpu_wr_mem_H2288(WORD address, BYTE value) {
124
	if (address >= 0x8000) {
125
		BYTE old_prg_rom_cfg = mmc3.prg_rom_cfg;
126
		BYTE old_chr_rom_cfg = mmc3.chr_rom_cfg;
127
128
		switch (address & 0xE001) {
129
			case 0x8000:
130
				extcl_cpu_wr_mem_MMC3(address, (value & 0xC0) | vlu114[value & 7]);
131
				h2288_8000()
132
				h2288_update_prg();
133
				h2288_update_chr();
134
				return;
135
			case 0x8001:
136
				extcl_cpu_wr_mem_MMC3(address, value);
137
				h2288_8001()
138
				h2288_update_prg();
139
				h2288_update_chr();
140
				return;
141
			default:
142
				extcl_cpu_wr_mem_MMC3(address, value);
143
				return;
144
		}
145
	}
146
147
	if ((address >= 0x5000) && (address <= 0x5FFF)) {
148
		if (address & 0x0800) {
149
			if (address & 0x0001) {
150
				h2288.reg[1] = value;
151
			} else {
152
				h2288.reg[0] = value;
153
				h2288_update_prg();
154
			}
155
		}
156
	}
157
}
158
BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp) {
159
	save_slot_ele(mode, slot, h2288.reg);
160
	save_slot_ele(mode, slot, h2288.prg_map);
161
	save_slot_ele(mode, slot, h2288.chr_map);
162
	extcl_save_mapper_MMC3(mode, slot, fp);
163
164
	return (EXIT_OK);
165
}
166
167
INLINE static void h2288_update_prg(void) {
168
	BYTE value;
169
170
	if (h2288.reg[0] & 0x40) {
171
		value = (h2288.reg[0] & 0x05) | ((h2288.reg[0] & 0x08) >> 2) | ((h2288.reg[0] & 0x20) >> 2);
172
		if (h2288.reg[0] & 0x02) {
173
			value = value >> 1;
174
			control_bank(info.prg.rom[0].max.banks_32k)
175
			map_prg_rom_8k(4, 0, value);
176
		} else {
177
			control_bank(info.prg.rom[0].max.banks_16k)
178
			map_prg_rom_8k(2, 0, value);
179
			map_prg_rom_8k(2, 2, value);
180
		}
181
	} else {
182
		h2288_prg_8k(h2288.prg_map[0]);
183
		control_bank(info.prg.rom[0].max.banks_8k)
184
		map_prg_rom_8k(1, 0, value);
185
186
		h2288_prg_8k(h2288.prg_map[1]);
187
		control_bank(info.prg.rom[0].max.banks_8k)
188
		map_prg_rom_8k(1, 1, value);
189
190
		h2288_prg_8k(h2288.prg_map[2]);
191
		control_bank(info.prg.rom[0].max.banks_8k)
192
		map_prg_rom_8k(1, 2, value);
193
194
		h2288_prg_8k(h2288.prg_map[3]);
195
		control_bank(info.prg.rom[0].max.banks_8k)
196
		map_prg_rom_8k(1, 3, value);
197
	}
198
	map_prg_rom_8k_update();
199
}
200
INLINE static void h2288_update_chr(void) {
201
	BYTE i;
202
	WORD value;
203
204
	for (i = 0; i < 8; i++) {
205
		h2288_chr_1k(h2288.chr_map[i]);
206
		control_bank(info.chr.rom[0].max.banks_1k)
207
		chr.bank_1k[i] = chr_chip_byte_pnt(0, value << 10);
208
	}
209
}
(-)puNES-0.105.org/src/core/mappers/mapper_H2288.h (-34 / +28 lines)
Lines 1-34 Link Here
1
/*
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
2
 *  Copyright (C) 2010-2020 Fabio Cavallo (aka FHorse)
3
 *
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
7
 *  (at your option) any later version.
8
 *
8
 *
9
 *  This program is distributed in the hope that it will be useful,
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
12
 *  GNU General Public License for more details.
13
 *
13
 *
14
 *  You should have received a copy of the GNU General Public License
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
17
 */
18
18
19
#ifndef MAPPER_H2288_H_
19
#ifndef MAPPER_H2288_H_
20
#define MAPPER_H2288_H_
20
#define MAPPER_H2288_H_
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _h2288 {
24
void map_init_H2288(void);
25
	BYTE reg[2];
25
void extcl_cpu_wr_mem_H2288(WORD address, BYTE value);
26
	WORD prg_map[4];
26
BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp);
27
	WORD chr_map[8];
27
28
} h2288;
28
#endif /* MAPPER_H2288_H_ */
29
30
void map_init_H2288(void);
31
void extcl_cpu_wr_mem_H2288(WORD address, BYTE value);
32
BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp);
33
34
#endif /* MAPPER_H2288_H_ */
(-)puNES-0.105.org/src/core/mappers/mapper_H2288.h.orig (+34 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#ifndef MAPPER_H2288_H_
20
#define MAPPER_H2288_H_
21
22
#include "common.h"
23
24
struct _h2288 {
25
	BYTE reg[2];
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} h2288;
29
30
void map_init_H2288(void);
31
void extcl_cpu_wr_mem_H2288(WORD address, BYTE value);
32
BYTE extcl_save_mapper_H2288(BYTE mode, BYTE slot, FILE *fp);
33
34
#endif /* MAPPER_H2288_H_ */
(-)puNES-0.105.org/src/core/mappers/mapper_Hen.c (-3 / +5 lines)
Lines 20-26 Link Here
20
#include "info.h"
20
#include "info.h"
21
#include "mem_map.h"
21
#include "mem_map.h"
22
22
23
BYTE type;
23
struct _hentmp {
24
	BYTE type;
25
} hentmp;
24
26
25
void map_init_Hen(BYTE model) {
27
void map_init_Hen(BYTE model) {
26
	switch (model) {
28
	switch (model) {
Lines 38-48 void map_init_Hen(BYTE model) { Link Here
38
		map_prg_rom_8k(4, 0, 0);
40
		map_prg_rom_8k(4, 0, 0);
39
	}
41
	}
40
42
41
	type = model;
43
	hentmp.type = model;
42
}
44
}
43
45
44
void extcl_cpu_wr_mem_Hen_177(UNUSED(WORD address), BYTE value) {
46
void extcl_cpu_wr_mem_Hen_177(UNUSED(WORD address), BYTE value) {
45
	if (type != HEN_FANKONG) {
47
	if (hentmp.type != HEN_FANKONG) {
46
		if (value & 0x20) {
48
		if (value & 0x20) {
47
			mirroring_H();
49
			mirroring_H();
48
		} else {
50
		} else {
(-)puNES-0.105.org/src/core/mappers/mapper_Irem.c (+14 lines)
Lines 41-46 Link Here
41
	chr.bank_1k[6] = &chr.extra.data[0x1000];\
41
	chr.bank_1k[6] = &chr.extra.data[0x1000];\
42
	chr.bank_1k[7] = &chr.extra.data[0x1400]
42
	chr.bank_1k[7] = &chr.extra.data[0x1400]
43
43
44
struct _irem_G101 {
45
	BYTE prg_mode;
46
	BYTE prg_reg;
47
} irem_G101;
48
struct _irem_H3000 {
49
	BYTE enable;
50
	WORD count;
51
	WORD reload;
52
	BYTE delay;
53
} irem_H3000;
54
struct _irem_LROG017 {
55
	BYTE filler;
56
} irem_LROG017;
57
44
void map_init_Irem(BYTE model) {
58
void map_init_Irem(BYTE model) {
45
	switch (model) {
59
	switch (model) {
46
		case G101:
60
		case G101:
(-)puNES-0.105.org/src/core/mappers/mapper_Irem.h (-14 lines)
Lines 31-50 enum { Link Here
31
	MAJORLEAGUE
31
	MAJORLEAGUE
32
};
32
};
33
33
34
struct _irem_G101 {
35
	BYTE prg_mode;
36
	BYTE prg_reg;
37
} irem_G101;
38
struct _irem_H3000 {
39
	BYTE enable;
40
	WORD count;
41
	WORD reload;
42
	BYTE delay;
43
} irem_H3000;
44
struct _irem_LROG017 {
45
	BYTE filler;
46
} irem_LROG017;
47
48
void map_init_Irem(BYTE model);
34
void map_init_Irem(BYTE model);
49
35
50
void extcl_cpu_wr_mem_Irem_G101(WORD address, BYTE value);
36
void extcl_cpu_wr_mem_Irem_G101(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_Jaleco.c (+9 lines)
Lines 35-40 Link Here
35
	chr.bank_1k[slot] = chr_chip_byte_pnt(0, value << 10);\
35
	chr.bank_1k[slot] = chr_chip_byte_pnt(0, value << 10);\
36
	ss8806.chr_rom_bank[slot] = value
36
	ss8806.chr_rom_bank[slot] = value
37
37
38
struct _ss8806 {
39
	BYTE chr_rom_bank[8];
40
	BYTE enabled;
41
	WORD mask;
42
	WORD reload;
43
	WORD count;
44
	BYTE delay;
45
} ss8806;
46
38
void map_init_Jaleco(BYTE model) {
47
void map_init_Jaleco(BYTE model) {
39
	switch (model) {
48
	switch (model) {
40
		case JF05:
49
		case JF05:
(-)puNES-0.105.org/src/core/mappers/mapper_Jaleco.h (-9 lines)
Lines 36-50 enum { Link Here
36
	MEZASETOPPRO,
36
	MEZASETOPPRO,
37
};
37
};
38
38
39
struct _ss8806 {
40
	BYTE chr_rom_bank[8];
41
	BYTE enabled;
42
	WORD mask;
43
	WORD reload;
44
	WORD count;
45
	BYTE delay;
46
} ss8806;
47
48
void map_init_Jaleco(BYTE model);
39
void map_init_Jaleco(BYTE model);
49
40
50
void extcl_cpu_wr_mem_Jaleco_JF05(WORD address, BYTE value);
41
void extcl_cpu_wr_mem_Jaleco_JF05(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_Kaiser.c (+12 lines)
Lines 23-28 Link Here
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _ks202 {
27
	BYTE enabled;
28
	WORD count;
29
	WORD reload;
30
	BYTE delay;
31
	BYTE reg;
32
	BYTE *prg_ram_rd;
33
} ks202;
34
struct _ks7022 {
35
	BYTE reg;
36
} ks7022;
37
26
void map_init_Kaiser(BYTE model) {
38
void map_init_Kaiser(BYTE model) {
27
	switch (model) {
39
	switch (model) {
28
		case KS202:
40
		case KS202:
(-)puNES-0.105.org/src/core/mappers/mapper_Kaiser.h (-12 lines)
Lines 28-45 enum { Link Here
28
	KS7022
28
	KS7022
29
};
29
};
30
30
31
struct _ks202 {
32
	BYTE enabled;
33
	WORD count;
34
	WORD reload;
35
	BYTE delay;
36
	BYTE reg;
37
	BYTE *prg_ram_rd;
38
} ks202;
39
struct _ks7022 {
40
	BYTE reg;
41
} ks7022;
42
43
void map_init_Kaiser(BYTE model);
31
void map_init_Kaiser(BYTE model);
44
32
45
void extcl_cpu_wr_mem_Kaiser_ks202(WORD address, BYTE value);
33
void extcl_cpu_wr_mem_Kaiser_ks202(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_Kasing.c (+8 lines)
Lines 60-65 Link Here
60
	}\
60
	}\
61
}
61
}
62
62
63
struct _kasing {
64
	BYTE prg_mode;
65
	BYTE prg_high;
66
	WORD prg_rom_bank[4];
67
	BYTE chr_high;
68
	WORD chr_rom_bank[8];
69
} kasing;
70
63
void map_init_Kasing(void) {
71
void map_init_Kasing(void) {
64
	EXTCL_CPU_WR_MEM(Kasing);
72
	EXTCL_CPU_WR_MEM(Kasing);
65
	EXTCL_SAVE_MAPPER(Kasing);
73
	EXTCL_SAVE_MAPPER(Kasing);
(-)puNES-0.105.org/src/core/mappers/mapper_Kasing.h (-8 lines)
Lines 21-34 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _kasing {
25
	BYTE prg_mode;
26
	BYTE prg_high;
27
	WORD prg_rom_bank[4];
28
	BYTE chr_high;
29
	WORD chr_rom_bank[8];
30
} kasing;
31
32
void map_init_Kasing(void);
24
void map_init_Kasing(void);
33
void extcl_cpu_wr_mem_Kasing(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_Kasing(WORD address, BYTE value);
34
BYTE extcl_save_mapper_Kasing(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_Kasing(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_KS7016.c (-3 / +8 lines)
Lines 23-29 Link Here
23
23
24
INLINE static void ks7016_6000_update(void);
24
INLINE static void ks7016_6000_update(void);
25
25
26
BYTE *ks7016_prg_6000;
26
struct _ks7016 {
27
	BYTE reg;
28
} ks7016;
29
struct _ks7016tmp {
30
	BYTE *prg_6000;
31
} ks7016tmp;
27
32
28
void map_init_KS7016(void) {
33
void map_init_KS7016(void) {
29
	EXTCL_CPU_WR_MEM(KS7016);
34
	EXTCL_CPU_WR_MEM(KS7016);
Lines 76-82 void extcl_cpu_wr_mem_KS7016(WORD addres Link Here
76
}
81
}
77
BYTE extcl_cpu_rd_mem_KS7016(WORD address, BYTE openbus, UNUSED(BYTE before)) {
82
BYTE extcl_cpu_rd_mem_KS7016(WORD address, BYTE openbus, UNUSED(BYTE before)) {
78
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
83
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
79
		return (ks7016_prg_6000[address & 0x1FFF]);
84
		return (ks7016tmp.prg_6000[address & 0x1FFF]);
80
	}
85
	}
81
	return (openbus);
86
	return (openbus);
82
}
87
}
Lines 95-99 INLINE static void ks7016_6000_update(vo Link Here
95
100
96
	value = ks7016.reg;
101
	value = ks7016.reg;
97
	control_bank(info.prg.rom[0].max.banks_8k)
102
	control_bank(info.prg.rom[0].max.banks_8k)
98
	ks7016_prg_6000 = prg_chip_byte_pnt(0, value << 13);
103
	ks7016tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13);
99
}
104
}
(-)puNES-0.105.org/src/core/mappers/mapper_KS7016.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _ks7016 {
25
	BYTE reg;
26
} ks7016;
27
28
void map_init_KS7016(void);
24
void map_init_KS7016(void);
29
void extcl_cpu_wr_mem_KS7016(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_KS7016(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_KS7016(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_KS7016(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_KS7017.c (+8 lines)
Lines 23-28 Link Here
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _ks7017 {
27
	BYTE reg;
28
	struct _ks7017_irq {
29
		BYTE active;
30
		WORD count;
31
	} irq;
32
} ks7017;
33
26
void map_init_KS7017(void) {
34
void map_init_KS7017(void) {
27
	EXTCL_CPU_WR_MEM(KS7017);
35
	EXTCL_CPU_WR_MEM(KS7017);
28
	EXTCL_CPU_RD_MEM(KS7017);
36
	EXTCL_CPU_RD_MEM(KS7017);
(-)puNES-0.105.org/src/core/mappers/mapper_KS7017.h (-8 lines)
Lines 21-34 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _ks7017 {
25
	BYTE reg;
26
	struct _ks7017_irq {
27
		BYTE active;
28
		WORD count;
29
	} irq;
30
} ks7017;
31
32
void map_init_KS7017(void);
24
void map_init_KS7017(void);
33
void extcl_cpu_wr_mem_KS7017(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_KS7017(WORD address, BYTE value);
34
BYTE extcl_cpu_rd_mem_KS7017(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_KS7017(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_KS7031.c (-60 / +65 lines)
Lines 25-50 Link Here
25
INLINE static void ks7031_init_prg(void);
25
INLINE static void ks7031_init_prg(void);
26
INLINE static void ks7031_update(void);
26
INLINE static void ks7031_update(void);
27
27
28
BYTE *ks7031_prg_6000;
28
struct _ks7031 {
29
BYTE *ks7031_prg_6800;
29
	BYTE reg[4];
30
BYTE *ks7031_prg_7000;
30
} ks7031;
31
BYTE *ks7031_prg_7800;
31
struct _ks7031tmp {
32
BYTE *ks7031_prg_8000;
32
	BYTE *prg_6000;
33
BYTE *ks7031_prg_8800;
33
	BYTE *prg_6800;
34
BYTE *ks7031_prg_9000;
34
	BYTE *prg_7000;
35
BYTE *ks7031_prg_9800;
35
	BYTE *prg_7800;
36
BYTE *ks7031_prg_A000;
36
	BYTE *prg_8000;
37
BYTE *ks7031_prg_A800;
37
	BYTE *prg_8800;
38
BYTE *ks7031_prg_B000;
38
	BYTE *prg_9000;
39
BYTE *ks7031_prg_B800;
39
	BYTE *prg_9800;
40
BYTE *ks7031_prg_C000;
40
	BYTE *prg_A000;
41
BYTE *ks7031_prg_C800;
41
	BYTE *prg_A800;
42
BYTE *ks7031_prg_D000;
42
	BYTE *prg_B000;
43
BYTE *ks7031_prg_D800;
43
	BYTE *prg_B800;
44
BYTE *ks7031_prg_E000;
44
	BYTE *prg_C000;
45
BYTE *ks7031_prg_E800;
45
	BYTE *prg_C800;
46
BYTE *ks7031_prg_F000;
46
	BYTE *prg_D000;
47
BYTE *ks7031_prg_F800;
47
	BYTE *prg_D800;
48
	BYTE *prg_E000;
49
	BYTE *prg_E800;
50
	BYTE *prg_F000;
51
	BYTE *prg_F800;
52
} ks7031tmp;
48
53
49
void map_init_KS7031(void) {
54
void map_init_KS7031(void) {
50
	EXTCL_CPU_WR_MEM(KS7031);
55
	EXTCL_CPU_WR_MEM(KS7031);
Lines 69-113 void extcl_cpu_wr_mem_KS7031(WORD addres Link Here
69
BYTE extcl_cpu_rd_mem_KS7031(WORD address, BYTE openbus, UNUSED(BYTE before)) {
74
BYTE extcl_cpu_rd_mem_KS7031(WORD address, BYTE openbus, UNUSED(BYTE before)) {
70
	switch (address & 0xF800) {
75
	switch (address & 0xF800) {
71
		case 0x6000:
76
		case 0x6000:
72
			return (ks7031_prg_6000[address & 0x07FF]);
77
			return (ks7031tmp.prg_6000[address & 0x07FF]);
73
		case 0x6800:
78
		case 0x6800:
74
			return (ks7031_prg_6800[address & 0x07FF]);
79
			return (ks7031tmp.prg_6800[address & 0x07FF]);
75
		case 0x7000:
80
		case 0x7000:
76
			return (ks7031_prg_7000[address & 0x07FF]);
81
			return (ks7031tmp.prg_7000[address & 0x07FF]);
77
		case 0x7800:
82
		case 0x7800:
78
			return (ks7031_prg_7800[address & 0x07FF]);
83
			return (ks7031tmp.prg_7800[address & 0x07FF]);
79
		case 0x8000:
84
		case 0x8000:
80
			return (ks7031_prg_8000[address & 0x07FF]);
85
			return (ks7031tmp.prg_8000[address & 0x07FF]);
81
		case 0x8800:
86
		case 0x8800:
82
			return (ks7031_prg_8800[address & 0x07FF]);
87
			return (ks7031tmp.prg_8800[address & 0x07FF]);
83
		case 0x9000:
88
		case 0x9000:
84
			return (ks7031_prg_9000[address & 0x07FF]);
89
			return (ks7031tmp.prg_9000[address & 0x07FF]);
85
		case 0x9800:
90
		case 0x9800:
86
			return (ks7031_prg_9800[address & 0x07FF]);
91
			return (ks7031tmp.prg_9800[address & 0x07FF]);
87
		case 0xA000:
92
		case 0xA000:
88
			return (ks7031_prg_A000[address & 0x07FF]);
93
			return (ks7031tmp.prg_A000[address & 0x07FF]);
89
		case 0xA800:
94
		case 0xA800:
90
			return (ks7031_prg_A800[address & 0x07FF]);
95
			return (ks7031tmp.prg_A800[address & 0x07FF]);
91
		case 0xB000:
96
		case 0xB000:
92
			return (ks7031_prg_B000[address & 0x07FF]);
97
			return (ks7031tmp.prg_B000[address & 0x07FF]);
93
		case 0xB800:
98
		case 0xB800:
94
			return (ks7031_prg_B800[address & 0x07FF]);
99
			return (ks7031tmp.prg_B800[address & 0x07FF]);
95
		case 0xC000:
100
		case 0xC000:
96
			return (ks7031_prg_C000[address & 0x07FF]);
101
			return (ks7031tmp.prg_C000[address & 0x07FF]);
97
		case 0xC800:
102
		case 0xC800:
98
			return (ks7031_prg_C800[address & 0x07FF]);
103
			return (ks7031tmp.prg_C800[address & 0x07FF]);
99
		case 0xD000:
104
		case 0xD000:
100
			return (ks7031_prg_D000[address & 0x07FF]);
105
			return (ks7031tmp.prg_D000[address & 0x07FF]);
101
		case 0xD800:
106
		case 0xD800:
102
			return (ks7031_prg_D800[address & 0x07FF]);
107
			return (ks7031tmp.prg_D800[address & 0x07FF]);
103
		case 0xE000:
108
		case 0xE000:
104
			return (ks7031_prg_E000[address & 0x07FF]);
109
			return (ks7031tmp.prg_E000[address & 0x07FF]);
105
		case 0xE800:
110
		case 0xE800:
106
			return (ks7031_prg_E800[address & 0x07FF]);
111
			return (ks7031tmp.prg_E800[address & 0x07FF]);
107
		case 0xF000:
112
		case 0xF000:
108
			return (ks7031_prg_F000[address & 0x07FF]);
113
			return (ks7031tmp.prg_F000[address & 0x07FF]);
109
		case 0xF800:
114
		case 0xF800:
110
			return (ks7031_prg_F800[address & 0x07FF]);
115
			return (ks7031tmp.prg_F800[address & 0x07FF]);
111
	}
116
	}
112
	return (openbus);
117
	return (openbus);
113
}
118
}
Lines 128-201 INLINE static void ks7031_init_prg(void) Link Here
128
	// 0x8000
133
	// 0x8000
129
	value = 15;
134
	value = 15;
130
	control_bank(info.prg.rom[0].max.banks_2k)
135
	control_bank(info.prg.rom[0].max.banks_2k)
131
	ks7031_prg_8000 = prg_chip_byte_pnt(0, value << 11);
136
	ks7031tmp.prg_8000 = prg_chip_byte_pnt(0, value << 11);
132
	// 0x8800
137
	// 0x8800
133
	value = 14;
138
	value = 14;
134
	control_bank(info.prg.rom[0].max.banks_2k)
139
	control_bank(info.prg.rom[0].max.banks_2k)
135
	ks7031_prg_8800 = prg_chip_byte_pnt(0, value << 11);
140
	ks7031tmp.prg_8800 = prg_chip_byte_pnt(0, value << 11);
136
141
137
	// 0x9000
142
	// 0x9000
138
	value = 13;
143
	value = 13;
139
	control_bank(info.prg.rom[0].max.banks_2k)
144
	control_bank(info.prg.rom[0].max.banks_2k)
140
	ks7031_prg_9000 = prg_chip_byte_pnt(0, value << 11);
145
	ks7031tmp.prg_9000 = prg_chip_byte_pnt(0, value << 11);
141
	// 0x9800
146
	// 0x9800
142
	value = 12;
147
	value = 12;
143
	control_bank(info.prg.rom[0].max.banks_2k)
148
	control_bank(info.prg.rom[0].max.banks_2k)
144
	ks7031_prg_9800 = prg_chip_byte_pnt(0, value << 11);
149
	ks7031tmp.prg_9800 = prg_chip_byte_pnt(0, value << 11);
145
150
146
	// 0xA000
151
	// 0xA000
147
	value = 11;
152
	value = 11;
148
	control_bank(info.prg.rom[0].max.banks_2k)
153
	control_bank(info.prg.rom[0].max.banks_2k)
149
	ks7031_prg_A000 = prg_chip_byte_pnt(0, value << 11);
154
	ks7031tmp.prg_A000 = prg_chip_byte_pnt(0, value << 11);
150
	// 0xA800
155
	// 0xA800
151
	value = 10;
156
	value = 10;
152
	control_bank(info.prg.rom[0].max.banks_2k)
157
	control_bank(info.prg.rom[0].max.banks_2k)
153
	ks7031_prg_A800 = prg_chip_byte_pnt(0, value << 11);
158
	ks7031tmp.prg_A800 = prg_chip_byte_pnt(0, value << 11);
154
159
155
	// 0xB000
160
	// 0xB000
156
	value = 9;
161
	value = 9;
157
	control_bank(info.prg.rom[0].max.banks_2k)
162
	control_bank(info.prg.rom[0].max.banks_2k)
158
	ks7031_prg_B000 = prg_chip_byte_pnt(0, value << 11);
163
	ks7031tmp.prg_B000 = prg_chip_byte_pnt(0, value << 11);
159
	// 0xB800
164
	// 0xB800
160
	value = 8;
165
	value = 8;
161
	control_bank(info.prg.rom[0].max.banks_2k)
166
	control_bank(info.prg.rom[0].max.banks_2k)
162
	ks7031_prg_B800 = prg_chip_byte_pnt(0, value << 11);
167
	ks7031tmp.prg_B800 = prg_chip_byte_pnt(0, value << 11);
163
168
164
	// 0xC000
169
	// 0xC000
165
	value = 7;
170
	value = 7;
166
	control_bank(info.prg.rom[0].max.banks_2k)
171
	control_bank(info.prg.rom[0].max.banks_2k)
167
	ks7031_prg_C000 = prg_chip_byte_pnt(0, value << 11);
172
	ks7031tmp.prg_C000 = prg_chip_byte_pnt(0, value << 11);
168
	// 0xC800
173
	// 0xC800
169
	value = 6;
174
	value = 6;
170
	control_bank(info.prg.rom[0].max.banks_2k)
175
	control_bank(info.prg.rom[0].max.banks_2k)
171
	ks7031_prg_C800 = prg_chip_byte_pnt(0, value << 11);
176
	ks7031tmp.prg_C800 = prg_chip_byte_pnt(0, value << 11);
172
177
173
	// 0xD000
178
	// 0xD000
174
	value = 5;
179
	value = 5;
175
	control_bank(info.prg.rom[0].max.banks_2k)
180
	control_bank(info.prg.rom[0].max.banks_2k)
176
	ks7031_prg_D000 = prg_chip_byte_pnt(0, value << 11);
181
	ks7031tmp.prg_D000 = prg_chip_byte_pnt(0, value << 11);
177
	// 0xD800
182
	// 0xD800
178
	value = 4;
183
	value = 4;
179
	control_bank(info.prg.rom[0].max.banks_2k)
184
	control_bank(info.prg.rom[0].max.banks_2k)
180
	ks7031_prg_D800 = prg_chip_byte_pnt(0, value << 11);
185
	ks7031tmp.prg_D800 = prg_chip_byte_pnt(0, value << 11);
181
186
182
	// 0xE000
187
	// 0xE000
183
	value = 3;
188
	value = 3;
184
	control_bank(info.prg.rom[0].max.banks_2k)
189
	control_bank(info.prg.rom[0].max.banks_2k)
185
	ks7031_prg_E000 = prg_chip_byte_pnt(0, value << 11);
190
	ks7031tmp.prg_E000 = prg_chip_byte_pnt(0, value << 11);
186
	// 0xE800
191
	// 0xE800
187
	value = 2;
192
	value = 2;
188
	control_bank(info.prg.rom[0].max.banks_2k)
193
	control_bank(info.prg.rom[0].max.banks_2k)
189
	ks7031_prg_E800 = prg_chip_byte_pnt(0, value << 11);
194
	ks7031tmp.prg_E800 = prg_chip_byte_pnt(0, value << 11);
190
195
191
	// 0xF000
196
	// 0xF000
192
	value = 1;
197
	value = 1;
193
	control_bank(info.prg.rom[0].max.banks_2k)
198
	control_bank(info.prg.rom[0].max.banks_2k)
194
	ks7031_prg_F000 = prg_chip_byte_pnt(0, value << 11);
199
	ks7031tmp.prg_F000 = prg_chip_byte_pnt(0, value << 11);
195
	// 0xF800
200
	// 0xF800
196
	value = 0;
201
	value = 0;
197
	control_bank(info.prg.rom[0].max.banks_2k)
202
	control_bank(info.prg.rom[0].max.banks_2k)
198
	ks7031_prg_F800 = prg_chip_byte_pnt(0, value << 11);
203
	ks7031tmp.prg_F800 = prg_chip_byte_pnt(0, value << 11);
199
}
204
}
200
INLINE static void ks7031_update(void) {
205
INLINE static void ks7031_update(void) {
201
	WORD value;
206
	WORD value;
Lines 203-220 INLINE static void ks7031_update(void) { Link Here
203
	// 0x6000
208
	// 0x6000
204
	value = ks7031.reg[0];
209
	value = ks7031.reg[0];
205
	control_bank(info.prg.rom[0].max.banks_2k)
210
	control_bank(info.prg.rom[0].max.banks_2k)
206
	ks7031_prg_6000 = prg_chip_byte_pnt(0, value << 11);
211
	ks7031tmp.prg_6000 = prg_chip_byte_pnt(0, value << 11);
207
	// 0x6800
212
	// 0x6800
208
	value = ks7031.reg[1];
213
	value = ks7031.reg[1];
209
	control_bank(info.prg.rom[0].max.banks_2k)
214
	control_bank(info.prg.rom[0].max.banks_2k)
210
	ks7031_prg_6800 = prg_chip_byte_pnt(0, value << 11);
215
	ks7031tmp.prg_6800 = prg_chip_byte_pnt(0, value << 11);
211
216
212
	// 0x7000
217
	// 0x7000
213
	value = ks7031.reg[2];
218
	value = ks7031.reg[2];
214
	control_bank(info.prg.rom[0].max.banks_2k)
219
	control_bank(info.prg.rom[0].max.banks_2k)
215
	ks7031_prg_7000 = prg_chip_byte_pnt(0, value << 11);
220
	ks7031tmp.prg_7000 = prg_chip_byte_pnt(0, value << 11);
216
	// 0x7800
221
	// 0x7800
217
	value = ks7031.reg[3];
222
	value = ks7031.reg[3];
218
	control_bank(info.prg.rom[0].max.banks_2k)
223
	control_bank(info.prg.rom[0].max.banks_2k)
219
	ks7031_prg_7800 = prg_chip_byte_pnt(0, value << 11);
224
	ks7031tmp.prg_7800 = prg_chip_byte_pnt(0, value << 11);
220
}
225
}
(-)puNES-0.105.org/src/core/mappers/mapper_KS7031.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _ks7031 {
25
	BYTE reg[4];
26
} ks7031;
27
28
void map_init_KS7031(void);
24
void map_init_KS7031(void);
29
void extcl_cpu_wr_mem_KS7031(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_KS7031(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_KS7031(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_KS7031(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_KS7032.c (-3 / +15 lines)
Lines 25-31 Link Here
25
25
26
INLINE static void ks7032_update(void);
26
INLINE static void ks7032_update(void);
27
27
28
BYTE *ks7032_prg_6000;
28
struct _ks7032 {
29
	BYTE ind;
30
	BYTE reg[8];
31
	struct _ks7032_irq {
32
		BYTE used;
33
		BYTE active;
34
		WORD count;
35
		WORD reload;
36
	} irq;
37
} ks7032;
38
struct _ks7032tmp {
39
	BYTE *prg_6000;
40
} ks7032tmp;
29
41
30
void map_init_KS7032(void) {
42
void map_init_KS7032(void) {
31
	EXTCL_CPU_WR_MEM(KS7032);
43
	EXTCL_CPU_WR_MEM(KS7032);
Lines 78-84 void extcl_cpu_wr_mem_KS7032(WORD addres Link Here
78
}
90
}
79
BYTE extcl_cpu_rd_mem_KS7032(WORD address, BYTE openbus, UNUSED(BYTE before)) {
91
BYTE extcl_cpu_rd_mem_KS7032(WORD address, BYTE openbus, UNUSED(BYTE before)) {
80
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
92
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
81
		return (ks7032_prg_6000[address & 0x1FFF]);
93
		return (ks7032tmp.prg_6000[address & 0x1FFF]);
82
	}
94
	}
83
	return (openbus);
95
	return (openbus);
84
}
96
}
Lines 113-119 INLINE static void ks7032_update(void) { Link Here
113
125
114
	value = ks7032.reg[4];
126
	value = ks7032.reg[4];
115
	control_bank(info.prg.rom[0].max.banks_8k)
127
	control_bank(info.prg.rom[0].max.banks_8k)
116
	ks7032_prg_6000 = prg_chip_byte_pnt(0, value << 13);
128
	ks7032tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13);
117
129
118
    value = ks7032.reg[1];
130
    value = ks7032.reg[1];
119
	control_bank(info.prg.rom[0].max.banks_8k)
131
	control_bank(info.prg.rom[0].max.banks_8k)
(-)puNES-0.105.org/src/core/mappers/mapper_KS7032.c.orig (+131 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#include <string.h>
20
#include "mappers.h"
21
#include "info.h"
22
#include "mem_map.h"
23
#include "cpu.h"
24
#include "save_slot.h"
25
26
INLINE static void ks7032_update(void);
27
28
BYTE *ks7032_prg_6000;
29
30
void map_init_KS7032(void) {
31
	EXTCL_CPU_WR_MEM(KS7032);
32
	EXTCL_CPU_RD_MEM(KS7032);
33
	EXTCL_SAVE_MAPPER(KS7032);
34
	EXTCL_CPU_EVERY_CYCLE(KS7032);
35
	mapper.internal_struct[0] = (BYTE *) &ks7032;
36
	mapper.internal_struct_size[0] = sizeof(ks7032);
37
38
	memset(&ks7032, 0x00, sizeof(ks7032));
39
40
	ks7032_update();
41
}
42
void extcl_cpu_wr_mem_KS7032(WORD address, BYTE value) {
43
	switch (address & 0xF000) {
44
		case 0x8000:
45
			ks7032.irq.used = 1;
46
			ks7032.irq.count = (ks7032.irq.count & 0x000F) | (value & 0x0F);
47
			irq.high &= ~EXT_IRQ;
48
			return;
49
		case 0x9000:
50
			ks7032.irq.used = 1;
51
			ks7032.irq.count = (ks7032.irq.count & 0x00F0) | (value << 4);
52
			irq.high &= ~EXT_IRQ;
53
			return;
54
		case 0xA000:
55
			ks7032.irq.used = 1;
56
			ks7032.irq.count = (ks7032.irq.count & 0x0F00) | (value << 8);
57
			irq.high &= ~EXT_IRQ;
58
			return;
59
		case 0xB000:
60
			ks7032.irq.used = 1;
61
			ks7032.irq.count = (ks7032.irq.count & 0xF000) | (value << 12);
62
			irq.high &= ~EXT_IRQ;
63
			return;
64
		case 0xC000:
65
			if (ks7032.irq.used) {
66
				ks7032.irq.active = 1;
67
				irq.high &= ~EXT_IRQ;
68
			}
69
			return;
70
		case 0xE000:
71
			ks7032.ind = value & 0x07;
72
			return;
73
		case 0xF000:
74
			ks7032.reg[ks7032.ind] = value;
75
			ks7032_update();
76
			return;
77
	}
78
}
79
BYTE extcl_cpu_rd_mem_KS7032(WORD address, BYTE openbus, UNUSED(BYTE before)) {
80
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
81
		return (ks7032_prg_6000[address & 0x1FFF]);
82
	}
83
	return (openbus);
84
}
85
BYTE extcl_save_mapper_KS7032(BYTE mode, BYTE slot, FILE *fp) {
86
	save_slot_ele(mode, slot, ks7032.ind);
87
	save_slot_ele(mode, slot, ks7032.reg);
88
	save_slot_ele(mode, slot, ks7032.irq.used);
89
	save_slot_ele(mode, slot, ks7032.irq.active);
90
	save_slot_ele(mode, slot, ks7032.irq.count);
91
	save_slot_ele(mode, slot, ks7032.irq.reload);
92
93
	if (mode == SAVE_SLOT_READ) {
94
		ks7032_update();
95
	}
96
97
	return (EXIT_OK);
98
}
99
void extcl_cpu_every_cycle_KS7032(void) {
100
	if (!ks7032.irq.active) {
101
		return;
102
	}
103
104
	if (++ks7032.irq.count == 0xFFFF) {
105
		ks7032.irq.active = ks7032.irq.count = 0;
106
		irq.delay = TRUE;
107
		irq.high |= EXT_IRQ;
108
	}
109
}
110
111
INLINE static void ks7032_update(void) {
112
	WORD value;
113
114
	value = ks7032.reg[4];
115
	control_bank(info.prg.rom[0].max.banks_8k)
116
	ks7032_prg_6000 = prg_chip_byte_pnt(0, value << 13);
117
118
    value = ks7032.reg[1];
119
	control_bank(info.prg.rom[0].max.banks_8k)
120
	map_prg_rom_8k(1, 0, value);
121
122
    value = ks7032.reg[2];
123
	control_bank(info.prg.rom[0].max.banks_8k)
124
	map_prg_rom_8k(1, 1, value);
125
126
    value = ks7032.reg[3];
127
	control_bank(info.prg.rom[0].max.banks_8k)
128
	map_prg_rom_8k(1, 2, value);
129
130
	map_prg_rom_8k_update();
131
}
(-)puNES-0.105.org/src/core/mappers/mapper_KS7032.h (-11 lines)
Lines 21-37 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _ks7032 {
25
	BYTE ind;
26
	BYTE reg[8];
27
	struct _ks7032_irq {
28
		BYTE used;
29
		BYTE active;
30
		WORD count;
31
		WORD reload;
32
	} irq;
33
} ks7032;
34
35
void map_init_KS7032(void);
24
void map_init_KS7032(void);
36
void extcl_cpu_wr_mem_KS7032(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_KS7032(WORD address, BYTE value);
37
BYTE extcl_cpu_rd_mem_KS7032(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_KS7032(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_KS7037.c (-7 / +13 lines)
Lines 24-31 Link Here
24
24
25
INLINE static void ks7037_update(void);
25
INLINE static void ks7037_update(void);
26
26
27
BYTE *ks7037_prg_7000;
27
struct _ks7037 {
28
BYTE *ks7037_prg_B000;
28
	BYTE ind;
29
	BYTE reg[8];
30
} ks7037;
31
struct _ks7037tmp {
32
	BYTE *prg_7000;
33
	BYTE *prg_B000;
34
} ks7037tmp;
29
35
30
void map_init_KS7037(void) {
36
void map_init_KS7037(void) {
31
	EXTCL_AFTER_MAPPER_INIT(KS7037);
37
	EXTCL_AFTER_MAPPER_INIT(KS7037);
Lines 60-66 void extcl_cpu_wr_mem_KS7037(WORD addres Link Here
60
			return;
66
			return;
61
		case 0xB000:
67
		case 0xB000:
62
		case 0xB001:
68
		case 0xB001:
63
			ks7037_prg_B000[address & 0x0FFF] = value;
69
			ks7037tmp.prg_B000[address & 0x0FFF] = value;
64
			return;
70
			return;
65
		case 0x8000:
71
		case 0x8000:
66
		case 0x9000:
72
		case 0x9000:
Lines 86-96 BYTE extcl_cpu_rd_mem_KS7037(WORD addres Link Here
86
		case 0x6000:
92
		case 0x6000:
87
			return (prg.ram_plus_8k[address & 0x0FFF]);
93
			return (prg.ram_plus_8k[address & 0x0FFF]);
88
		case 0x7000:
94
		case 0x7000:
89
			return (ks7037_prg_7000[address & 0x0FFF]);
95
			return (ks7037tmp.prg_7000[address & 0x0FFF]);
90
		case 0xA000:
96
		case 0xA000:
91
			return (prg.rom_8k[1][address & 0x0FFF]);
97
			return (prg.rom_8k[1][address & 0x0FFF]);
92
		case 0xB000:
98
		case 0xB000:
93
			return (ks7037_prg_B000[address & 0x0FFF]);
99
			return (ks7037tmp.prg_B000[address & 0x0FFF]);
94
	}
100
	}
95
	return (openbus);
101
	return (openbus);
96
}
102
}
Lines 111-117 INLINE static void ks7037_update(void) { Link Here
111
	// 0x7000
117
	// 0x7000
112
	value = 0x0F;
118
	value = 0x0F;
113
	control_bank(info.prg.rom[0].max.banks_4k)
119
	control_bank(info.prg.rom[0].max.banks_4k)
114
	ks7037_prg_7000 = prg_chip_byte_pnt(0, value << 12);
120
	ks7037tmp.prg_7000 = prg_chip_byte_pnt(0, value << 12);
115
121
116
	// 0x8000 - 0x9000
122
	// 0x8000 - 0x9000
117
	value = ks7037.reg[6];
123
	value = ks7037.reg[6];
Lines 125-131 INLINE static void ks7037_update(void) { Link Here
125
	prg.rom_8k[1] = prg_chip_byte_pnt(prg.rom_chip[0], value << 12);
131
	prg.rom_8k[1] = prg_chip_byte_pnt(prg.rom_chip[0], value << 12);
126
132
127
	// 0xB000
133
	// 0xB000
128
	ks7037_prg_B000 = &prg.ram_plus_8k[1 << 12];
134
	ks7037tmp.prg_B000 = &prg.ram_plus_8k[1 << 12];
129
135
130
	// 0xC000 - 0xD000
136
	// 0xC000 - 0xD000
131
	value = ks7037.reg[7];
137
	value = ks7037.reg[7];
(-)puNES-0.105.org/src/core/mappers/mapper_KS7037.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _ks7037 {
25
	BYTE ind;
26
	BYTE reg[8];
27
} ks7037;
28
29
void map_init_KS7037(void);
24
void map_init_KS7037(void);
30
void extcl_after_mapper_init_KS7037(void);
25
void extcl_after_mapper_init_KS7037(void);
31
void extcl_cpu_wr_mem_KS7037(WORD address, BYTE value);
26
void extcl_cpu_wr_mem_KS7037(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_KS7057.c (-24 / +29 lines)
Lines 24-37 Link Here
24
24
25
INLINE static void ks7057_update(void);
25
INLINE static void ks7057_update(void);
26
26
27
BYTE *ks7057_prg_6000;
27
struct _ks7057 {
28
BYTE *ks7057_prg_6800;
28
	BYTE reg[8];
29
BYTE *ks7057_prg_7000;
29
} ks7057;
30
BYTE *ks7057_prg_7800;
30
struct _ks7057tmp {
31
BYTE *ks7057_prg_8000;
31
	BYTE *prg_6000;
32
BYTE *ks7057_prg_8800;
32
	BYTE *prg_6800;
33
BYTE *ks7057_prg_9000;
33
	BYTE *prg_7000;
34
BYTE *ks7057_prg_9800;
34
	BYTE *prg_7800;
35
	BYTE *prg_8000;
36
	BYTE *prg_8800;
37
	BYTE *prg_9000;
38
	BYTE *prg_9800;
39
} ks7057tmp;
35
40
36
void map_init_KS7057(void) {
41
void map_init_KS7057(void) {
37
	EXTCL_CPU_WR_MEM(KS7057);
42
	EXTCL_CPU_WR_MEM(KS7057);
Lines 121-141 void extcl_cpu_wr_mem_KS7057(WORD addres Link Here
121
BYTE extcl_cpu_rd_mem_KS7057(WORD address, BYTE openbus, UNUSED(BYTE before)) {
126
BYTE extcl_cpu_rd_mem_KS7057(WORD address, BYTE openbus, UNUSED(BYTE before)) {
122
	switch (address & 0xF800) {
127
	switch (address & 0xF800) {
123
		case 0x6000:
128
		case 0x6000:
124
			return (ks7057_prg_6000[address & 0x07FF]);
129
			return (ks7057tmp.prg_6000[address & 0x07FF]);
125
		case 0x6800:
130
		case 0x6800:
126
			return (ks7057_prg_6800[address & 0x07FF]);
131
			return (ks7057tmp.prg_6800[address & 0x07FF]);
127
		case 0x7000:
132
		case 0x7000:
128
			return (ks7057_prg_7000[address & 0x07FF]);
133
			return (ks7057tmp.prg_7000[address & 0x07FF]);
129
		case 0x7800:
134
		case 0x7800:
130
			return (ks7057_prg_7800[address & 0x07FF]);
135
			return (ks7057tmp.prg_7800[address & 0x07FF]);
131
		case 0x8000:
136
		case 0x8000:
132
			return (ks7057_prg_8000[address & 0x07FF]);
137
			return (ks7057tmp.prg_8000[address & 0x07FF]);
133
		case 0x8800:
138
		case 0x8800:
134
			return (ks7057_prg_8800[address & 0x07FF]);
139
			return (ks7057tmp.prg_8800[address & 0x07FF]);
135
		case 0x9000:
140
		case 0x9000:
136
			return (ks7057_prg_9000[address & 0x07FF]);
141
			return (ks7057tmp.prg_9000[address & 0x07FF]);
137
		case 0x9800:
142
		case 0x9800:
138
			return (ks7057_prg_9800[address & 0x07FF]);
143
			return (ks7057tmp.prg_9800[address & 0x07FF]);
139
	}
144
	}
140
	return (openbus);
145
	return (openbus);
141
}
146
}
Lines 155-192 INLINE static void ks7057_update(void) { Link Here
155
	// 0x6000
160
	// 0x6000
156
	value = ks7057.reg[4];
161
	value = ks7057.reg[4];
157
	control_bank(info.prg.rom[0].max.banks_2k)
162
	control_bank(info.prg.rom[0].max.banks_2k)
158
	ks7057_prg_6000 = prg_chip_byte_pnt(0, value << 11);
163
	ks7057tmp.prg_6000 = prg_chip_byte_pnt(0, value << 11);
159
	// 0x6800
164
	// 0x6800
160
	value = ks7057.reg[5];
165
	value = ks7057.reg[5];
161
	control_bank(info.prg.rom[0].max.banks_2k)
166
	control_bank(info.prg.rom[0].max.banks_2k)
162
	ks7057_prg_6800 = prg_chip_byte_pnt(0, value << 11);
167
	ks7057tmp.prg_6800 = prg_chip_byte_pnt(0, value << 11);
163
168
164
	// 0x7000
169
	// 0x7000
165
	value = ks7057.reg[6];
170
	value = ks7057.reg[6];
166
	control_bank(info.prg.rom[0].max.banks_2k)
171
	control_bank(info.prg.rom[0].max.banks_2k)
167
	ks7057_prg_7000 = prg_chip_byte_pnt(0, value << 11);
172
	ks7057tmp.prg_7000 = prg_chip_byte_pnt(0, value << 11);
168
	// 0x7800
173
	// 0x7800
169
	value = ks7057.reg[7];
174
	value = ks7057.reg[7];
170
	control_bank(info.prg.rom[0].max.banks_2k)
175
	control_bank(info.prg.rom[0].max.banks_2k)
171
	ks7057_prg_7800 = prg_chip_byte_pnt(0, value << 11);
176
	ks7057tmp.prg_7800 = prg_chip_byte_pnt(0, value << 11);
172
177
173
	// 0x8000
178
	// 0x8000
174
	value = ks7057.reg[0];
179
	value = ks7057.reg[0];
175
	control_bank(info.prg.rom[0].max.banks_2k)
180
	control_bank(info.prg.rom[0].max.banks_2k)
176
	ks7057_prg_8000 = prg_chip_byte_pnt(0, value << 11);
181
	ks7057tmp.prg_8000 = prg_chip_byte_pnt(0, value << 11);
177
	// 0x8800
182
	// 0x8800
178
	value = ks7057.reg[1];
183
	value = ks7057.reg[1];
179
	control_bank(info.prg.rom[0].max.banks_2k)
184
	control_bank(info.prg.rom[0].max.banks_2k)
180
	ks7057_prg_8800 = prg_chip_byte_pnt(0, value << 11);
185
	ks7057tmp.prg_8800 = prg_chip_byte_pnt(0, value << 11);
181
186
182
	// 0x9000
187
	// 0x9000
183
	value = ks7057.reg[2];
188
	value = ks7057.reg[2];
184
	control_bank(info.prg.rom[0].max.banks_2k)
189
	control_bank(info.prg.rom[0].max.banks_2k)
185
	ks7057_prg_9000 = prg_chip_byte_pnt(0, value << 11);
190
	ks7057tmp.prg_9000 = prg_chip_byte_pnt(0, value << 11);
186
	// 0x9800
191
	// 0x9800
187
	value = ks7057.reg[3];
192
	value = ks7057.reg[3];
188
	control_bank(info.prg.rom[0].max.banks_2k)
193
	control_bank(info.prg.rom[0].max.banks_2k)
189
	ks7057_prg_9800 = prg_chip_byte_pnt(0, value << 11);
194
	ks7057tmp.prg_9800 = prg_chip_byte_pnt(0, value << 11);
190
195
191
	// 0xA000 - 0xB000
196
	// 0xA000 - 0xB000
192
	value = 0x0D;
197
	value = 0x0D;
(-)puNES-0.105.org/src/core/mappers/mapper_KS7057.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _ks7057 {
25
	BYTE reg[8];
26
} ks7057;
27
28
void map_init_KS7057(void);
24
void map_init_KS7057(void);
29
void extcl_cpu_wr_mem_KS7057(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_KS7057(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_KS7057(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_KS7057(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_LH10.c (-7 / +14 lines)
Lines 24-31 Link Here
24
24
25
INLINE static void lh10_update(void);
25
INLINE static void lh10_update(void);
26
26
27
BYTE *lh10_prg_6000;
27
struct _lh10 {
28
BYTE *lh10_prg_C000;
28
	BYTE ind;
29
	BYTE reg[8];
30
} lh10;
31
struct _lh10tmp {
32
	BYTE *prg_6000;
33
	BYTE *prg_C000;
34
} lh10tmp;
35
29
36
30
void map_init_LH10(void) {
37
void map_init_LH10(void) {
31
	EXTCL_AFTER_MAPPER_INIT(LH10);
38
	EXTCL_AFTER_MAPPER_INIT(LH10);
Lines 58-64 void extcl_cpu_wr_mem_LH10(WORD address, Link Here
58
		case 0xC001:
65
		case 0xC001:
59
		case 0xD000:
66
		case 0xD000:
60
		case 0xD001:
67
		case 0xD001:
61
			lh10_prg_C000[address & 0x1FFF] = value;
68
			lh10tmp.prg_C000[address & 0x1FFF] = value;
62
			return;
69
			return;
63
		case 0x8000:
70
		case 0x8000:
64
		case 0x9000:
71
		case 0x9000:
Lines 83-92 BYTE extcl_cpu_rd_mem_LH10(WORD address, Link Here
83
	switch (address & 0xF000) {
90
	switch (address & 0xF000) {
84
		case 0x6000:
91
		case 0x6000:
85
		case 0x7000:
92
		case 0x7000:
86
			return (lh10_prg_6000[address & 0x1FFF]);
93
			return (lh10tmp.prg_6000[address & 0x1FFF]);
87
		case 0xC000:
94
		case 0xC000:
88
		case 0xD000:
95
		case 0xD000:
89
			return (lh10_prg_C000[address & 0x1FFF]);
96
			return (lh10tmp.prg_C000[address & 0x1FFF]);
90
	}
97
	}
91
	return (openbus);
98
	return (openbus);
92
}
99
}
Lines 107-113 INLINE static void lh10_update(void) { Link Here
107
	// 0x6000 - 0x7000
114
	// 0x6000 - 0x7000
108
	value = 0xFE;
115
	value = 0xFE;
109
	control_bank(info.prg.rom[0].max.banks_8k)
116
	control_bank(info.prg.rom[0].max.banks_8k)
110
	lh10_prg_6000 = prg_chip_byte_pnt(0, value << 13);
117
	lh10tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13);
111
118
112
	// 0x8000 - 0x9000
119
	// 0x8000 - 0x9000
113
	value = lh10.reg[6];
120
	value = lh10.reg[6];
Lines 122-126 INLINE static void lh10_update(void) { Link Here
122
	prg.rom_8k[1] = prg_chip_byte_pnt(prg.rom_chip[0], mapper.rom_map_to[1] << 13);
129
	prg.rom_8k[1] = prg_chip_byte_pnt(prg.rom_chip[0], mapper.rom_map_to[1] << 13);
123
130
124
	// 0xC000 - 0xD000
131
	// 0xC000 - 0xD000
125
	lh10_prg_C000 = &prg.ram_plus_8k[0];
132
	lh10tmp.prg_C000 = &prg.ram_plus_8k[0];
126
}
133
}
(-)puNES-0.105.org/src/core/mappers/mapper_LH10.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _lh10 {
25
	BYTE ind;
26
	BYTE reg[8];
27
} lh10;
28
29
void map_init_LH10(void);
24
void map_init_LH10(void);
30
void extcl_after_mapper_init_LH10(void);
25
void extcl_after_mapper_init_LH10(void);
31
void extcl_cpu_wr_mem_LH10(WORD address, BYTE value);
26
void extcl_cpu_wr_mem_LH10(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_LH32.c (-5 / +10 lines)
Lines 21-27 Link Here
21
#include "info.h"
21
#include "info.h"
22
#include "save_slot.h"
22
#include "save_slot.h"
23
23
24
BYTE *lh32_prg_6000;
24
struct _lh32 {
25
	BYTE reg;
26
} lh32;
27
struct _lh32tmp {
28
	BYTE *prg_6000;
29
} lh32tmp;
25
30
26
void map_init_LH32(void) {
31
void map_init_LH32(void) {
27
	EXTCL_CPU_WR_MEM(LH32);
32
	EXTCL_CPU_WR_MEM(LH32);
Lines 50-56 void map_init_LH32(void) { Link Here
50
		map_prg_rom_8k_update();
55
		map_prg_rom_8k_update();
51
	}
56
	}
52
57
53
	lh32_prg_6000 = prg_chip_byte_pnt(0, lh32.reg << 13);
58
	lh32tmp.prg_6000 = prg_chip_byte_pnt(0, lh32.reg << 13);
54
59
55
	info.prg.ram.banks_8k_plus = 1;
60
	info.prg.ram.banks_8k_plus = 1;
56
61
Lines 61-67 void map_init_LH32(void) { Link Here
61
void extcl_cpu_wr_mem_LH32(WORD address, BYTE value) {
66
void extcl_cpu_wr_mem_LH32(WORD address, BYTE value) {
62
	if (address == 0x6000) {
67
	if (address == 0x6000) {
63
		control_bank(info.prg.rom[0].max.banks_8k)
68
		control_bank(info.prg.rom[0].max.banks_8k)
64
		lh32_prg_6000 = prg_chip_byte_pnt(0, value << 13);
69
		lh32tmp.prg_6000 = prg_chip_byte_pnt(0, value << 13);
65
		lh32.reg = value;
70
		lh32.reg = value;
66
		return;
71
		return;
67
	} else if ((address & 0xE000) == 0xC000) {
72
	} else if ((address & 0xE000) == 0xC000) {
Lines 71-77 void extcl_cpu_wr_mem_LH32(WORD address, Link Here
71
}
76
}
72
BYTE extcl_cpu_rd_mem_LH32(WORD address, BYTE openbus, UNUSED(BYTE before)) {
77
BYTE extcl_cpu_rd_mem_LH32(WORD address, BYTE openbus, UNUSED(BYTE before)) {
73
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
78
	if ((address >= 0x6000) && (address <= 0x7FFF)) {
74
		return (lh32_prg_6000[address & 0x1FFF]);
79
		return (lh32tmp.prg_6000[address & 0x1FFF]);
75
	} else if ((address & 0xE000) == 0xC000) {
80
	} else if ((address & 0xE000) == 0xC000) {
76
		return (prg.ram_plus_8k[address & 0x1FFF]);
81
		return (prg.ram_plus_8k[address & 0x1FFF]);
77
	}
82
	}
Lines 81-87 BYTE extcl_save_mapper_LH32(BYTE mode, B Link Here
81
	save_slot_ele(mode, slot, lh32.reg);
86
	save_slot_ele(mode, slot, lh32.reg);
82
87
83
	if (mode == SAVE_SLOT_READ) {
88
	if (mode == SAVE_SLOT_READ) {
84
		lh32_prg_6000 = prg_chip_byte_pnt(0, lh32.reg << 13);
89
		lh32tmp.prg_6000 = prg_chip_byte_pnt(0, lh32.reg << 13);
85
	}
90
	}
86
91
87
	return (EXIT_OK);
92
	return (EXIT_OK);
(-)puNES-0.105.org/src/core/mappers/mapper_LH32.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _lh32 {
25
	BYTE reg;
26
} lh32;
27
28
void map_init_LH32(void);
24
void map_init_LH32(void);
29
void extcl_cpu_wr_mem_LH32(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_LH32(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_LH32(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_LH32(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_MALISB.c (+5 lines)
Lines 81-86 INLINE static void malisb_update_chr(voi Link Here
81
			break;\
81
			break;\
82
	}
82
	}
83
83
84
struct _malisb {
85
	WORD prg_map[4];
86
	WORD chr_map[8];
87
} malisb;
88
84
void map_init_MALISB(void) {
89
void map_init_MALISB(void) {
85
	EXTCL_CPU_WR_MEM(MALISB);
90
	EXTCL_CPU_WR_MEM(MALISB);
86
	EXTCL_SAVE_MAPPER(MALISB);
91
	EXTCL_SAVE_MAPPER(MALISB);
(-)puNES-0.105.org/src/core/mappers/mapper_MALISB.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _malisb {
25
	WORD prg_map[4];
26
	WORD chr_map[8];
27
} malisb;
28
29
void map_init_MALISB(void);
24
void map_init_MALISB(void);
30
void extcl_cpu_wr_mem_MALISB(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_MALISB(WORD address, BYTE value);
31
BYTE extcl_save_mapper_MALISB(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_MALISB(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_MMC1.c (+13 lines)
Lines 69-74 enum MMC1_regs { CTRL, CHR0, CHR1, PRG0 Link Here
69
			break;\
69
			break;\
70
	}
70
	}
71
71
72
struct _mmc1 {
73
	BYTE reg;
74
	BYTE pos;
75
	BYTE prg_mode;
76
	BYTE chr_mode;
77
	BYTE ctrl;
78
	BYTE chr0;
79
	BYTE chr1;
80
	BYTE prg0;
81
	BYTE reset;
82
	BYTE prg_upper;
83
} mmc1;
84
72
void map_init_MMC1(void) {
85
void map_init_MMC1(void) {
73
	EXTCL_CPU_WR_MEM(MMC1);
86
	EXTCL_CPU_WR_MEM(MMC1);
74
	EXTCL_SAVE_MAPPER(MMC1);
87
	EXTCL_SAVE_MAPPER(MMC1);
(-)puNES-0.105.org/src/core/mappers/mapper_MMC1.h (-13 lines)
Lines 23-41 Link Here
23
23
24
enum MMC1_types { SNROM, SOROM, SUROM, SXROM, SEROM = 5, SKROM = 6, SJROM = 7, BAD_YOSHI_U = 20, MOWPC10 };
24
enum MMC1_types { SNROM, SOROM, SUROM, SXROM, SEROM = 5, SKROM = 6, SJROM = 7, BAD_YOSHI_U = 20, MOWPC10 };
25
25
26
struct _mmc1 {
27
	BYTE reg;
28
	BYTE pos;
29
	BYTE prg_mode;
30
	BYTE chr_mode;
31
	BYTE ctrl;
32
	BYTE chr0;
33
	BYTE chr1;
34
	BYTE prg0;
35
	BYTE reset;
36
	BYTE prg_upper;
37
} mmc1;
38
39
void map_init_MMC1(void);
26
void map_init_MMC1(void);
40
void extcl_cpu_wr_mem_MMC1(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_MMC1(WORD address, BYTE value);
41
BYTE extcl_save_mapper_MMC1(BYTE mode, BYTE slot, FILE *fp);
28
BYTE extcl_save_mapper_MMC1(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_MMC2andMMC4.c (+6 lines)
Lines 22-27 Link Here
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
struct _mmc2and4 {
26
	BYTE regs[4];
27
	BYTE latch0;
28
	BYTE latch1;
29
} mmc2and4;
30
25
void map_init_MMC2and4(void) {
31
void map_init_MMC2and4(void) {
26
	EXTCL_CPU_WR_MEM(MMC2and4);
32
	EXTCL_CPU_WR_MEM(MMC2and4);
27
	EXTCL_SAVE_MAPPER(MMC2and4);
33
	EXTCL_SAVE_MAPPER(MMC2and4);
(-)puNES-0.105.org/src/core/mappers/mapper_MMC2andMMC4.h (-6 lines)
Lines 24-35 Link Here
24
/* MMC4 */
24
/* MMC4 */
25
enum { BAD_INES_FWJ };
25
enum { BAD_INES_FWJ };
26
26
27
struct _mmc2and4 {
28
	BYTE regs[4];
29
	BYTE latch0;
30
	BYTE latch1;
31
} mmc2and4;
32
33
void map_init_MMC2and4(void);
27
void map_init_MMC2and4(void);
34
void extcl_cpu_wr_mem_MMC2and4(WORD address, BYTE value);
28
void extcl_cpu_wr_mem_MMC2and4(WORD address, BYTE value);
35
BYTE extcl_save_mapper_MMC2and4(BYTE mode, BYTE slot, FILE *fp);
29
BYTE extcl_save_mapper_MMC2and4(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_MMC3.c (+3 lines)
Lines 33-38 Link Here
33
	mmc3.irq_reload = FALSE;\
33
	mmc3.irq_reload = FALSE;\
34
}
34
}
35
35
36
_mmc3 mmc3;
37
_kt008 kt008;
38
36
void map_init_MMC3(void) {
39
void map_init_MMC3(void) {
37
	EXTCL_CPU_WR_MEM(MMC3);
40
	EXTCL_CPU_WR_MEM(MMC3);
38
	EXTCL_SAVE_MAPPER(MMC3);
41
	EXTCL_SAVE_MAPPER(MMC3);
(-)puNES-0.105.org/src/core/mappers/mapper_MMC3.h (-4 / +7 lines)
Lines 44-58 enum { Link Here
44
	MMC6
44
	MMC6
45
};
45
};
46
46
47
struct _mmc3 {
47
typedef struct _mmc3 {
48
	BYTE prg_ram_protect;
48
	BYTE prg_ram_protect;
49
	BYTE bank_to_update;
49
	BYTE bank_to_update;
50
	BYTE prg_rom_cfg;
50
	BYTE prg_rom_cfg;
51
	BYTE chr_rom_cfg;
51
	BYTE chr_rom_cfg;
52
} mmc3;
52
} _mmc3;
53
struct _kt008 {
53
typedef struct _kt008 {
54
	BYTE value;
54
	BYTE value;
55
} kt008;
55
} _kt008;
56
57
extern _mmc3 mmc3;
58
extern _kt008 kt008;
56
59
57
void map_init_MMC3(void);
60
void map_init_MMC3(void);
58
void extcl_cpu_wr_mem_MMC3(WORD address, BYTE value);
61
void extcl_cpu_wr_mem_MMC3(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_MMC5.c (-11 / +13 lines)
Lines 20-26 Link Here
20
#include "mappers.h"
20
#include "mappers.h"
21
#include "info.h"
21
#include "info.h"
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "apu.h"
24
#include "ppu.h"
23
#include "ppu.h"
25
#include "cpu.h"
24
#include "cpu.h"
26
#include "irql2f.h"
25
#include "irql2f.h"
Lines 36-42 Link Here
36
		map_prg_rom_8k(1, slot, value);\
35
		map_prg_rom_8k(1, slot, value);\
37
	} else {\
36
	} else {\
38
		/* modalita' ram */\
37
		/* modalita' ram */\
39
		BYTE bank = prg_ram_access[prg_ram_mode][value & 0x07];\
38
		BYTE bank = prg_ram_access[mmc5tmp.prg_ram_mode][value & 0x07];\
40
		if (bank != INVALID) {\
39
		if (bank != INVALID) {\
41
			mmc5.prg_ram_bank[slot][0] = TRUE;\
40
			mmc5.prg_ram_bank[slot][0] = TRUE;\
42
			mmc5.prg_ram_bank[slot][1] = bank << 13;\
41
			mmc5.prg_ram_bank[slot][1] = bank << 13;\
Lines 52-63 Link Here
52
		map_prg_rom_8k(2, 0, value);\
51
		map_prg_rom_8k(2, 0, value);\
53
	} else {\
52
	} else {\
54
		/* modalita' ram */\
53
		/* modalita' ram */\
55
		BYTE bank = prg_ram_access[prg_ram_mode][value & 0x07];\
54
		BYTE bank = prg_ram_access[mmc5tmp.prg_ram_mode][value & 0x07];\
56
		if (bank != INVALID) {\
55
		if (bank != INVALID) {\
57
			mmc5.prg_ram_bank[0][0] = TRUE;\
56
			mmc5.prg_ram_bank[0][0] = TRUE;\
58
			mmc5.prg_ram_bank[0][1] = (value & 0x06) << 13;\
57
			mmc5.prg_ram_bank[0][1] = (value & 0x06) << 13;\
59
		}\
58
		}\
60
		bank = prg_ram_access[prg_ram_mode][(value + 1) & 0x07];\
59
		bank = prg_ram_access[mmc5tmp.prg_ram_mode][(value + 1) & 0x07];\
61
		if (bank != INVALID) {\
60
		if (bank != INVALID) {\
62
			mmc5.prg_ram_bank[1][0] = TRUE;\
61
			mmc5.prg_ram_bank[1][0] = TRUE;\
63
			mmc5.prg_ram_bank[1][1] = (value & 0x07) << 13;\
62
			mmc5.prg_ram_bank[1][1] = (value & 0x07) << 13;\
Lines 163-169 static const BYTE prg_ram_access[6][8] = Link Here
163
	{0,1,2,3,4,4,4,4},
162
	{0,1,2,3,4,4,4,4},
164
	{0,1,2,3,4,5,6,7}
163
	{0,1,2,3,4,5,6,7}
165
};
164
};
166
BYTE prg_ram_mode;
165
_mmc5 mmc5;
166
struct _mmc5tmp {
167
	BYTE prg_ram_mode;
168
} mmc5tmp;
167
169
168
void map_init_MMC5(void) {
170
void map_init_MMC5(void) {
169
	EXTCL_CPU_WR_MEM(MMC5);
171
	EXTCL_CPU_WR_MEM(MMC5);
Lines 224-251 void map_init_MMC5(void) { Link Here
224
		case EKROM:
226
		case EKROM:
225
			info.prg.ram.banks_8k_plus = 1;
227
			info.prg.ram.banks_8k_plus = 1;
226
			info.prg.ram.bat.banks = 1;
228
			info.prg.ram.bat.banks = 1;
227
			prg_ram_mode = PRG_RAM_8K;
229
			mmc5tmp.prg_ram_mode = PRG_RAM_8K;
228
			break;
230
			break;
229
		case ELROM:
231
		case ELROM:
230
			info.prg.ram.banks_8k_plus = FALSE;
232
			info.prg.ram.banks_8k_plus = FALSE;
231
			info.prg.ram.bat.banks = FALSE;
233
			info.prg.ram.bat.banks = FALSE;
232
			prg_ram_mode = PRG_RAM_NONE;
234
			mmc5tmp.prg_ram_mode = PRG_RAM_NONE;
233
			break;
235
			break;
234
		case ETROM:
236
		case ETROM:
235
			info.prg.ram.banks_8k_plus = 2;
237
			info.prg.ram.banks_8k_plus = 2;
236
			info.prg.ram.bat.banks = 1;
238
			info.prg.ram.bat.banks = 1;
237
			info.prg.ram.bat.start = 0;
239
			info.prg.ram.bat.start = 0;
238
			prg_ram_mode = PRG_RAM_16K;
240
			mmc5tmp.prg_ram_mode = PRG_RAM_16K;
239
			break;
241
			break;
240
		case EWROM:
242
		case EWROM:
241
			info.prg.ram.banks_8k_plus = 4;
243
			info.prg.ram.banks_8k_plus = 4;
242
			info.prg.ram.bat.banks = 4;
244
			info.prg.ram.bat.banks = 4;
243
			prg_ram_mode = PRG_RAM_32K;
245
			mmc5tmp.prg_ram_mode = PRG_RAM_32K;
244
			break;
246
			break;
245
		default:
247
		default:
246
			info.prg.ram.banks_8k_plus = 8;
248
			info.prg.ram.banks_8k_plus = 8;
247
			info.prg.ram.bat.banks = FALSE;
249
			info.prg.ram.bat.banks = FALSE;
248
			prg_ram_mode = PRG_RAM_64K;
250
			mmc5tmp.prg_ram_mode = PRG_RAM_64K;
249
			break;
251
			break;
250
	}
252
	}
251
}
253
}
Lines 353-359 void extcl_cpu_wr_mem_MMC5(WORD address, Link Here
353
			memset(&mmc5.fill_table[0x3C0], filler_attrib[mmc5.fill_attr], 0x40);
355
			memset(&mmc5.fill_table[0x3C0], filler_attrib[mmc5.fill_attr], 0x40);
354
			return;
356
			return;
355
		case 0x5113: {
357
		case 0x5113: {
356
			BYTE bank = prg_ram_access[prg_ram_mode][value & 0x07];
358
			BYTE bank = prg_ram_access[mmc5tmp.prg_ram_mode][value & 0x07];
357
359
358
			if (bank != INVALID) {
360
			if (bank != INVALID) {
359
				prg.ram_plus_8k = &prg.ram_plus[bank * 0x2000];
361
				prg.ram_plus_8k = &prg.ram_plus[bank * 0x2000];
(-)puNES-0.105.org/src/core/mappers/mapper_MMC5.h (-2 / +4 lines)
Lines 23-29 Link Here
23
23
24
enum { EKROM, ELROM, ETROM, EWROM };
24
enum { EKROM, ELROM, ETROM, EWROM };
25
25
26
struct _mmc5 {
26
typedef struct _mmc5 {
27
	BYTE prg_mode;
27
	BYTE prg_mode;
28
	BYTE chr_mode;
28
	BYTE chr_mode;
29
	BYTE ext_mode;
29
	BYTE ext_mode;
Lines 63-69 struct _mmc5 { Link Here
63
	/* ------------------------------------------------------- */
63
	/* ------------------------------------------------------- */
64
	/* */ BYTE clocked;                                     /* */
64
	/* */ BYTE clocked;                                     /* */
65
	/* ------------------------------------------------------- */
65
	/* ------------------------------------------------------- */
66
} mmc5;
66
} _mmc5;
67
68
extern _mmc5 mmc5;
67
69
68
void map_init_MMC5(void);
70
void map_init_MMC5(void);
69
void map_init_NSF_MMC5(void);
71
void map_init_NSF_MMC5(void);
(-)puNES-0.105.org/src/core/mappers/mapper_Namco.c (-10 / +20 lines)
Lines 21-27 Link Here
21
#include "info.h"
21
#include "info.h"
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "apu.h"
25
#include "save_slot.h"
24
#include "save_slot.h"
26
25
27
#define n163_prg_rom_8k_update(slot)\
26
#define n163_prg_rom_8k_update(slot)\
Lines 31-37 Link Here
31
#define _n163_nmt_update(slot)\
30
#define _n163_nmt_update(slot)\
32
	ntbl.bank_1k[slot] = chr_chip_byte_pnt(0, n163.nmt_bank[slot][1])
31
	ntbl.bank_1k[slot] = chr_chip_byte_pnt(0, n163.nmt_bank[slot][1])
33
#define n163_nmt_update(slot)\
32
#define n163_nmt_update(slot)\
34
	if (hardwired) {\
33
	if (namcotmp.hardwired) {\
35
		return;\
34
		return;\
36
	}\
35
	}\
37
	if (value >= 0xE0) {\
36
	if (value >= 0xE0) {\
Lines 63-73 Link Here
63
	_n163_ch_freq((n163.ch[channel].freq & 0x3FF00) | value, channel)
62
	_n163_ch_freq((n163.ch[channel].freq & 0x3FF00) | value, channel)
64
63
65
#define n3425_nmt_update()\
64
#define n3425_nmt_update()\
66
	if (type == N3425) {\
65
	if (namcotmp.type == N3425) {\
67
		ntbl.bank_1k[n3425.bank_to_update >> 1] = &ntbl.data[((value >> 5) & 0x01) << 10];\
66
		ntbl.bank_1k[n3425.bank_to_update >> 1] = &ntbl.data[((value >> 5) & 0x01) << 10];\
68
	}
67
	}
69
68
70
BYTE hardwired, type;
69
struct _n3425 {
70
	BYTE bank_to_update;
71
} n3425;
72
struct _n3446 {
73
	BYTE bank_to_update;
74
	BYTE prg_rom_mode;
75
} n3446;
76
_n163 n163;
77
struct _namcotmp {
78
	BYTE hardwired;
79
	BYTE type;
80
} namcotmp;
71
81
72
void map_init_Namco(BYTE model) {
82
void map_init_Namco(BYTE model) {
73
	switch (model) {
83
	switch (model) {
Lines 95-109 void map_init_Namco(BYTE model) { Link Here
95
			}
105
			}
96
106
97
			info.mapper.extend_wr = TRUE;
107
			info.mapper.extend_wr = TRUE;
98
			hardwired = FALSE;
108
			namcotmp.hardwired = FALSE;
99
109
100
			switch (info.id) {
110
			switch (info.id) {
101
				case NAMCO_HARD_WIRED_V:
111
				case NAMCO_HARD_WIRED_V:
102
					hardwired = TRUE;
112
					namcotmp.hardwired = TRUE;
103
					mirroring_V();
113
					mirroring_V();
104
					break;
114
					break;
105
				case NAMCO_HARD_WIRED_H:
115
				case NAMCO_HARD_WIRED_H:
106
					hardwired = TRUE;
116
					namcotmp.hardwired = TRUE;
107
					mirroring_H();
117
					mirroring_H();
108
					break;
118
					break;
109
				case MINDSEEKER:
119
				case MINDSEEKER:
Lines 143-149 void map_init_Namco(BYTE model) { Link Here
143
			break;
153
			break;
144
	}
154
	}
145
155
146
	type = model;
156
	namcotmp.type = model;
147
}
157
}
148
void map_init_NSF_Namco(BYTE model) {
158
void map_init_NSF_Namco(BYTE model) {
149
	memset(&n163, 0x00, sizeof(n163));
159
	memset(&n163, 0x00, sizeof(n163));
Lines 151-157 void map_init_NSF_Namco(BYTE model) { Link Here
151
	n163.snd_ch_start = 7;
161
	n163.snd_ch_start = 7;
152
	n163.snd_auto_inc = 1;
162
	n163.snd_auto_inc = 1;
153
163
154
	type = model;
164
	namcotmp.type = model;
155
}
165
}
156
166
157
void extcl_cpu_wr_mem_Namco_163(WORD address, BYTE value) {
167
void extcl_cpu_wr_mem_Namco_163(WORD address, BYTE value) {
Lines 365-371 void extcl_cpu_wr_mem_Namco_3425(WORD ad Link Here
365
	switch (address & 0xA001) {
375
	switch (address & 0xA001) {
366
		case 0x8000:
376
		case 0x8000:
367
			n3425.bank_to_update = value & 0x07;
377
			n3425.bank_to_update = value & 0x07;
368
			if (type == N3453) {
378
			if (namcotmp.type == N3453) {
369
				if (value & 0x40) {
379
				if (value & 0x40) {
370
					mirroring_SCR1();
380
					mirroring_SCR1();
371
				} else {
381
				} else {
(-)puNES-0.105.org/src/core/mappers/mapper_Namco.h (-9 / +4 lines)
Lines 45-51 typedef struct _n163_snd_ch { Link Here
45
	WORD volume;
45
	WORD volume;
46
	SWORD output;
46
	SWORD output;
47
} _n163_snd_ch;
47
} _n163_snd_ch;
48
struct _n163 {
48
typedef struct _n163 {
49
	uint32_t nmt_bank[4][2];
49
	uint32_t nmt_bank[4][2];
50
	BYTE irq_delay;
50
	BYTE irq_delay;
51
	DBWORD irq_count;
51
	DBWORD irq_count;
Lines 55-68 struct _n163 { Link Here
55
	BYTE snd_ch_start;
55
	BYTE snd_ch_start;
56
	BYTE snd_wave[0x100];
56
	BYTE snd_wave[0x100];
57
	_n163_snd_ch ch[8];
57
	_n163_snd_ch ch[8];
58
} n163;
58
} _n163;
59
struct _n3425 {
59
60
	BYTE bank_to_update;
60
extern _n163 n163;
61
} n3425;
62
struct _n3446 {
63
	BYTE bank_to_update;
64
	BYTE prg_rom_mode;
65
} n3446;
66
61
67
void map_init_Namco(BYTE model);
62
void map_init_Namco(BYTE model);
68
void map_init_NSF_Namco(BYTE model);
63
void map_init_NSF_Namco(BYTE model);
(-)puNES-0.105.org/src/core/mappers/mapper_Ntdec.c (+5 lines)
Lines 38-43 Link Here
38
	bank = new_value << 10;\
38
	bank = new_value << 10;\
39
	chr.bank_1k[slot] = chr_chip_byte_pnt(0, bank)
39
	chr.bank_1k[slot] = chr_chip_byte_pnt(0, bank)
40
40
41
struct _asder {
42
	BYTE address;
43
	BYTE reg[8];
44
} asder;
45
41
void map_init_Ntdec(BYTE model) {
46
void map_init_Ntdec(BYTE model) {
42
	switch (model) {
47
	switch (model) {
43
		case ASDER:
48
		case ASDER:
(-)puNES-0.105.org/src/core/mappers/mapper_Ntdec.h (-5 lines)
Lines 23-33 Link Here
23
23
24
enum { ASDER, FHERO };
24
enum { ASDER, FHERO };
25
25
26
struct _asder {
27
	BYTE address;
28
	BYTE reg[8];
29
} asder;
30
31
void map_init_Ntdec(BYTE model);
26
void map_init_Ntdec(BYTE model);
32
27
33
void extcl_cpu_wr_mem_Ntdec_asder(WORD address, BYTE value);
28
void extcl_cpu_wr_mem_Ntdec_asder(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_Rcm.h (-1 lines)
Lines 24-30 Link Here
24
enum { GS2015 };
24
enum { GS2015 };
25
25
26
void map_init_Rcm(BYTE type);
26
void map_init_Rcm(BYTE type);
27
28
void extcl_cpu_wr_mem_GS2015(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_GS2015(WORD address, BYTE value);
29
28
30
#endif /* MAPPER_RCM_H_ */
29
#endif /* MAPPER_RCM_H_ */
(-)puNES-0.105.org/src/core/mappers/mapper_Rex.c (+5 lines)
Lines 48-53 Link Here
48
	}\
48
	}\
49
}
49
}
50
50
51
struct _rex_dbz {
52
	WORD chr_rom_bank[8];
53
	BYTE chr_high;
54
} rex_dbz;
55
51
void map_init_Rex(BYTE model) {
56
void map_init_Rex(BYTE model) {
52
	if (model == DBZ) {
57
	if (model == DBZ) {
53
		EXTCL_CPU_WR_MEM(Rex_dbz);
58
		EXTCL_CPU_WR_MEM(Rex_dbz);
(-)puNES-0.105.org/src/core/mappers/mapper_Rex.h (-5 lines)
Lines 23-33 Link Here
23
23
24
enum { DBZ };
24
enum { DBZ };
25
25
26
struct _rex_dbz {
27
	WORD chr_rom_bank[8];
28
	BYTE chr_high;
29
} rex_dbz;
30
31
void map_init_Rex(BYTE model);
26
void map_init_Rex(BYTE model);
32
void extcl_cpu_wr_mem_Rex_dbz(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_Rex_dbz(WORD address, BYTE value);
33
BYTE extcl_cpu_rd_mem_Rex_dbz(WORD address, BYTE openbus, BYTE before);
28
BYTE extcl_cpu_rd_mem_Rex_dbz(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_SA_9602B.c (+5 lines)
Lines 59-64 INLINE static void sa9602b_update_prg(vo Link Here
59
			break;\
59
			break;\
60
	}
60
	}
61
61
62
struct _sa9602b {
63
	WORD prg_chip[4];
64
	WORD prg_map[4];
65
} sa9602b;
66
62
void map_init_SA_9602B(void) {
67
void map_init_SA_9602B(void) {
63
	EXTCL_CPU_WR_MEM(SA_9602B);
68
	EXTCL_CPU_WR_MEM(SA_9602B);
64
	EXTCL_SAVE_MAPPER(SA_9602B);
69
	EXTCL_SAVE_MAPPER(SA_9602B);
(-)puNES-0.105.org/src/core/mappers/mapper_SA_9602B.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _sa9602b {
25
	WORD prg_chip[4];
26
	WORD prg_map[4];
27
} sa9602b;
28
29
void map_init_SA_9602B(void);
24
void map_init_SA_9602B(void);
30
void extcl_cpu_wr_mem_SA_9602B(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_SA_9602B(WORD address, BYTE value);
31
BYTE extcl_save_mapper_SA_9602B(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_SA_9602B(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_Sachen.c (-21 / +35 lines)
Lines 39-45 Link Here
39
	sa74374x.chr_rom_8k_bank = value;\
39
	sa74374x.chr_rom_8k_bank = value;\
40
}
40
}
41
41
42
BYTE type, shift, ored[3];
42
struct _sa8259 {
43
	BYTE ctrl;
44
	BYTE reg[8];
45
} sa8259;
46
struct _tcu02 {
47
	BYTE reg;
48
} tcu02;
49
struct _sa74374x {
50
	BYTE reg;
51
	BYTE chr_rom_8k_bank;
52
} sa74374x;
53
struct _sachentmp {
54
	BYTE type;
55
	BYTE shift;
56
	BYTE ored[3];
57
} sachentmp;
43
58
44
void map_init_Sachen(BYTE model) {
59
void map_init_Sachen(BYTE model) {
45
	switch (model) {
60
	switch (model) {
Lines 76-97 void map_init_Sachen(BYTE model) { Link Here
76
91
77
			switch (model) {
92
			switch (model) {
78
				case SA8259A:
93
				case SA8259A:
79
					shift = 1;
94
					sachentmp.shift = 1;
80
					ored[0] = 1;
95
					sachentmp.ored[0] = 1;
81
					ored[1] = 0;
96
					sachentmp.ored[1] = 0;
82
					ored[2] = 1;
97
					sachentmp.ored[2] = 1;
83
					break;
98
					break;
84
				case SA8259B:
99
				case SA8259B:
85
					shift = 0;
100
					sachentmp.shift = 0;
86
					ored[0] = 0;
101
					sachentmp.ored[0] = 0;
87
					ored[1] = 0;
102
					sachentmp.ored[1] = 0;
88
					ored[2] = 0;
103
					sachentmp.ored[2] = 0;
89
					break;
104
					break;
90
				case SA8259C:
105
				case SA8259C:
91
					shift = 2;
106
					sachentmp.shift = 2;
92
					ored[0] = 1;
107
					sachentmp.ored[0] = 1;
93
					ored[1] = 2;
108
					sachentmp.ored[1] = 2;
94
					ored[2] = 3;
109
					sachentmp.ored[2] = 3;
95
					break;
110
					break;
96
				case SA8259D:
111
				case SA8259D:
97
					if (!mapper.write_vram) {
112
					if (!mapper.write_vram) {
Lines 181-187 void map_init_Sachen(BYTE model) { Link Here
181
		}
196
		}
182
	}
197
	}
183
198
184
	type = model;
199
	sachentmp.type = model;
185
}
200
}
186
201
187
void extcl_cpu_wr_mem_Sachen_sa0036(UNUSED(WORD address), BYTE value) {
202
void extcl_cpu_wr_mem_Sachen_sa0036(UNUSED(WORD address), BYTE value) {
Lines 270-276 void extcl_cpu_wr_mem_Sachen_sa8259x(WOR Link Here
270
					if (!mapper.write_vram) {
285
					if (!mapper.write_vram) {
271
						DBWORD bank;
286
						DBWORD bank;
272
287
273
						if (type == SA8259D) {
288
						if (sachentmp.type == SA8259D) {
274
289
275
							value = sa8259.reg[0] & 0x07;
290
							value = sa8259.reg[0] & 0x07;
276
							control_bank(info.chr.rom[0].max.banks_1k)
291
							control_bank(info.chr.rom[0].max.banks_1k)
Lines 287-322 void extcl_cpu_wr_mem_Sachen_sa8259x(WOR Link Here
287
							bank = value << 10;
302
							bank = value << 10;
288
							chr.bank_1k[2] = chr_chip_byte_pnt(0, bank);
303
							chr.bank_1k[2] = chr_chip_byte_pnt(0, bank);
289
304
290
							value = (sa8259.reg[3] & 0x07) | ((sa8259.reg[4] << 2) & 0x10)
305
							value = (sa8259.reg[3] & 0x07) | ((sa8259.reg[4] << 2) & 0x10) | ((sa8259.reg[6] << 3) & 0x08);
291
									| ((sa8259.reg[6] << 3) & 0x08);
292
							control_bank(info.chr.rom[0].max.banks_1k)
306
							control_bank(info.chr.rom[0].max.banks_1k)
293
							bank = value << 10;
307
							bank = value << 10;
294
							chr.bank_1k[3] = chr_chip_byte_pnt(0, bank);
308
							chr.bank_1k[3] = chr_chip_byte_pnt(0, bank);
295
						} else {
309
						} else {
296
							const BYTE high = (sa8259.reg[4] << 3) & 0x38;
310
							const BYTE high = (sa8259.reg[4] << 3) & 0x38;
297
311
298
							value = (high | (sa8259.reg[0] & 0x07)) << shift;
312
							value = (high | (sa8259.reg[0] & 0x07)) << sachentmp.shift;
299
							control_bank(info.chr.rom[0].max.banks_2k)
313
							control_bank(info.chr.rom[0].max.banks_2k)
300
							bank = value << 11;
314
							bank = value << 11;
301
							chr.bank_1k[0] = chr_chip_byte_pnt(0, bank);
315
							chr.bank_1k[0] = chr_chip_byte_pnt(0, bank);
302
							chr.bank_1k[1] = chr_chip_byte_pnt(0, bank | 0x0400);
316
							chr.bank_1k[1] = chr_chip_byte_pnt(0, bank | 0x0400);
303
317
304
							value = ((high | (sa8259.reg[(sa8259.reg[7] & 0x01) ? 0 : 1] & 0x07))
318
							value = ((high | (sa8259.reg[(sa8259.reg[7] & 0x01) ? 0 : 1] & 0x07))
305
									<< shift) | ored[0];
319
								<< sachentmp.shift) | sachentmp.ored[0];
306
							control_bank(info.chr.rom[0].max.banks_2k)
320
							control_bank(info.chr.rom[0].max.banks_2k)
307
							bank = value << 11;
321
							bank = value << 11;
308
							chr.bank_1k[2] = chr_chip_byte_pnt(0, bank);
322
							chr.bank_1k[2] = chr_chip_byte_pnt(0, bank);
309
							chr.bank_1k[3] = chr_chip_byte_pnt(0, bank | 0x0400);
323
							chr.bank_1k[3] = chr_chip_byte_pnt(0, bank | 0x0400);
310
324
311
							value = ((high | (sa8259.reg[(sa8259.reg[7] & 0x01) ? 0 : 2] & 0x07))
325
							value = ((high | (sa8259.reg[(sa8259.reg[7] & 0x01) ? 0 : 2] & 0x07))
312
									<< shift) | ored[1];
326
								<< sachentmp.shift) | sachentmp.ored[1];
313
							control_bank(info.chr.rom[0].max.banks_2k)
327
							control_bank(info.chr.rom[0].max.banks_2k)
314
							bank = value << 11;
328
							bank = value << 11;
315
							chr.bank_1k[4] = chr_chip_byte_pnt(0, bank);
329
							chr.bank_1k[4] = chr_chip_byte_pnt(0, bank);
316
							chr.bank_1k[5] = chr_chip_byte_pnt(0, bank | 0x0400);
330
							chr.bank_1k[5] = chr_chip_byte_pnt(0, bank | 0x0400);
317
331
318
							value = ((high | (sa8259.reg[(sa8259.reg[7] & 0x01) ? 0 : 3] & 0x07))
332
							value = ((high | (sa8259.reg[(sa8259.reg[7] & 0x01) ? 0 : 3] & 0x07))
319
									<< shift) | ored[2];
333
								<< sachentmp.shift) | sachentmp.ored[2];
320
							control_bank(info.chr.rom[0].max.banks_2k)
334
							control_bank(info.chr.rom[0].max.banks_2k)
321
							bank = value << 11;
335
							bank = value << 11;
322
							chr.bank_1k[6] = chr_chip_byte_pnt(0, bank);
336
							chr.bank_1k[6] = chr_chip_byte_pnt(0, bank);
(-)puNES-0.105.org/src/core/mappers/mapper_Sachen.h (-12 lines)
Lines 37-54 enum { Link Here
37
	SA74374B,
37
	SA74374B,
38
};
38
};
39
39
40
struct _sa8259 {
41
	BYTE ctrl;
42
	BYTE reg[8];
43
} sa8259;
44
struct _tcu02 {
45
	BYTE reg;
46
} tcu02;
47
struct _sa74374x {
48
	BYTE reg;
49
	BYTE chr_rom_8k_bank;
50
} sa74374x;
51
52
static const char pokeriiichr[2][41] = {
40
static const char pokeriiichr[2][41] = {
53
	"5066c2d12ff2ac45ef395d3a4353e897fce19f78",
41
	"5066c2d12ff2ac45ef395d3a4353e897fce19f78",
54
	"c6bf926ed14c21f1a5b64fbccf3288005ff54be5"
42
	"c6bf926ed14c21f1a5b64fbccf3288005ff54be5"
(-)puNES-0.105.org/src/core/mappers/mapper_SC_127.c (+7 lines)
Lines 24-29 Link Here
24
#include "ppu.h"
24
#include "ppu.h"
25
#include "save_slot.h"
25
#include "save_slot.h"
26
26
27
struct _sc127 {
28
	struct _sc127_irq {
29
		BYTE active;
30
		WORD count;
31
	} irq;
32
} sc127;
33
27
void map_init_SC_127(void) {
34
void map_init_SC_127(void) {
28
	EXTCL_CPU_WR_MEM(SC_127);
35
	EXTCL_CPU_WR_MEM(SC_127);
29
	EXTCL_CPU_RD_MEM(SC_127);
36
	EXTCL_CPU_RD_MEM(SC_127);
(-)puNES-0.105.org/src/core/mappers/mapper_SC_127.h (-7 lines)
Lines 21-33 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _sc127 {
25
	struct _sc127_irq {
26
		BYTE active;
27
		WORD count;
28
	} irq;
29
} sc127;
30
31
void map_init_SC_127(void);
24
void map_init_SC_127(void);
32
void extcl_cpu_wr_mem_SC_127(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_SC_127(WORD address, BYTE value);
33
BYTE extcl_cpu_rd_mem_SC_127(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_SC_127(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_SHERO.c (-4 / +10 lines)
Lines 63-69 INLINE static void shero_update_chr(void Link Here
63
			break;\
63
			break;\
64
	}
64
	}
65
65
66
BYTE shero_reset;
66
struct _shero {
67
	BYTE reg;
68
	WORD chr_map[8];
69
} shero;
70
struct _sherotmp {
71
	BYTE reset;
72
} sherotmp;
67
73
68
void map_init_SHERO(void) {
74
void map_init_SHERO(void) {
69
	EXTCL_CPU_WR_MEM(SHERO);
75
	EXTCL_CPU_WR_MEM(SHERO);
Lines 86-94 void map_init_SHERO(void) { Link Here
86
	memset(&irqA12, 0x00, sizeof(irqA12));
92
	memset(&irqA12, 0x00, sizeof(irqA12));
87
93
88
	if (info.reset >= HARD) {
94
	if (info.reset >= HARD) {
89
		shero_reset = 0;
95
		sherotmp.reset = 0;
90
	} else if (info.reset == RESET) {
96
	} else if (info.reset == RESET) {
91
		shero_reset ^= 0xFF;
97
		sherotmp.reset ^= 0xFF;
92
	}
98
	}
93
99
94
	map_chr_ram_extra_init(0x2000);
100
	map_chr_ram_extra_init(0x2000);
Lines 137-143 void extcl_cpu_wr_mem_SHERO(WORD address Link Here
137
}
143
}
138
BYTE extcl_cpu_rd_mem_SHERO(WORD address, BYTE openbus, UNUSED(BYTE before)) {
144
BYTE extcl_cpu_rd_mem_SHERO(WORD address, BYTE openbus, UNUSED(BYTE before)) {
139
	if (address == 0x4100) {
145
	if (address == 0x4100) {
140
		return (shero_reset);
146
		return (sherotmp.reset);
141
	}
147
	}
142
	return (openbus);
148
	return (openbus);
143
}
149
}
(-)puNES-0.105.org/src/core/mappers/mapper_SHERO.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _shero {
25
	BYTE reg;
26
	WORD chr_map[8];
27
} shero;
28
29
void map_init_SHERO(void);
24
void map_init_SHERO(void);
30
void extcl_cpu_wr_mem_SHERO(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_SHERO(WORD address, BYTE value);
31
BYTE extcl_cpu_rd_mem_SHERO(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_SHERO(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_SL1632.c (+12 lines)
Lines 96-101 INLINE static void sl1632_update(void); Link Here
96
		mirroring_V();\
96
		mirroring_V();\
97
	}
97
	}
98
98
99
struct _sl1632 {
100
	BYTE mode;
101
	BYTE mirroring;
102
	WORD prg_map[2];
103
	WORD chr_map[8];
104
	struct _sl1632_mmc3 {
105
		BYTE mirroring;
106
		WORD prg_map[4];
107
		WORD chr_map[8];
108
	} mmc3;
109
} sl1632;
110
99
void map_init_SL1632(void) {
111
void map_init_SL1632(void) {
100
	EXTCL_CPU_WR_MEM(SL1632);
112
	EXTCL_CPU_WR_MEM(SL1632);
101
	EXTCL_SAVE_MAPPER(SL1632);
113
	EXTCL_SAVE_MAPPER(SL1632);
(-)puNES-0.105.org/src/core/mappers/mapper_SL1632.h (-12 lines)
Lines 21-38 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _sl1632 {
25
	BYTE mode;
26
	BYTE mirroring;
27
	WORD prg_map[2];
28
	WORD chr_map[8];
29
	struct _sl1632_mmc3 {
30
		BYTE mirroring;
31
		WORD prg_map[4];
32
		WORD chr_map[8];
33
	} mmc3;
34
} sl1632;
35
36
void map_init_SL1632(void);
24
void map_init_SL1632(void);
37
void extcl_cpu_wr_mem_SL1632(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_SL1632(WORD address, BYTE value);
38
BYTE extcl_save_mapper_SL1632(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_SL1632(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_Sunsoft.c (-4 / +18 lines)
Lines 94-100 Link Here
94
		fm7.square[sq].output = fm7.square[sq].volume * ((fm7.square[sq].step & 0x10) ? 1 : 0);\
94
		fm7.square[sq].output = fm7.square[sq].volume * ((fm7.square[sq].step & 0x10) ? 1 : 0);\
95
	}
95
	}
96
96
97
BYTE type;
97
struct _sunsoft3 {
98
	BYTE enable;
99
	BYTE toggle;
100
	WORD count;
101
	BYTE delay;
102
} s3;
103
struct _sunsoft4 {
104
	uint32_t chr_nmt[2];
105
	BYTE mode;
106
	BYTE mirroring;
107
} s4;
108
_sunsoft_fm7 fm7;
109
struct _sunsofttmp {
110
	BYTE type;
111
} sunsofttmp;
98
112
99
void map_init_Sunsoft(BYTE model) {
113
void map_init_Sunsoft(BYTE model) {
100
	switch (model) {
114
	switch (model) {
Lines 161-167 void map_init_Sunsoft(BYTE model) { Link Here
161
			break;
175
			break;
162
	}
176
	}
163
177
164
	type = model;
178
	sunsofttmp.type = model;
165
}
179
}
166
void map_init_NSF_Sunsoft(BYTE model) {
180
void map_init_NSF_Sunsoft(BYTE model) {
167
	memset(&fm7, 0x00, sizeof(fm7));
181
	memset(&fm7, 0x00, sizeof(fm7));
Lines 170-176 void map_init_NSF_Sunsoft(BYTE model) { Link Here
170
	fm7.square[1].timer = 1;
184
	fm7.square[1].timer = 1;
171
	fm7.square[2].timer = 1;
185
	fm7.square[2].timer = 1;
172
186
173
	type = model;
187
	sunsofttmp.type = model;
174
}
188
}
175
189
176
void extcl_cpu_wr_mem_Sunsoft_S1(WORD address, BYTE value) {
190
void extcl_cpu_wr_mem_Sunsoft_S1(WORD address, BYTE value) {
Lines 204-210 void extcl_cpu_wr_mem_Sunsoft_S2(UNUSED( Link Here
204
	const BYTE save = value;
218
	const BYTE save = value;
205
	DBWORD bank;
219
	DBWORD bank;
206
220
207
	if (type == SUN2B) {
221
	if (sunsofttmp.type == SUN2B) {
208
		if (value & 0x08) {
222
		if (value & 0x08) {
209
			mirroring_SCR1();
223
			mirroring_SCR1();
210
		} else {
224
		} else {
(-)puNES-0.105.org/src/core/mappers/mapper_Sunsoft.h (-14 / +4 lines)
Lines 41-59 typedef struct _square_fm7 { Link Here
41
	WORD volume;
41
	WORD volume;
42
	SWORD output;
42
	SWORD output;
43
} _square_fm7;
43
} _square_fm7;
44
44
typedef struct _sunsoft_fm7 {
45
struct _sunsoft3 {
46
	BYTE enable;
47
	BYTE toggle;
48
	WORD count;
49
	BYTE delay;
50
} s3;
51
struct _sunsoft4 {
52
	uint32_t chr_nmt[2];
53
	BYTE mode;
54
	BYTE mirroring;
55
} s4;
56
struct _sunsoft_fm7 {
57
	BYTE address;
45
	BYTE address;
58
	BYTE prg_ram_enable;
46
	BYTE prg_ram_enable;
59
	BYTE prg_ram_mode;
47
	BYTE prg_ram_mode;
Lines 70-76 struct _sunsoft_fm7 { Link Here
70
	/* ------------------------------------------------------- */
58
	/* ------------------------------------------------------- */
71
	/* */ BYTE clocked;                                     /* */
59
	/* */ BYTE clocked;                                     /* */
72
	/* ------------------------------------------------------- */
60
	/* ------------------------------------------------------- */
73
} fm7;
61
} _sunsoft_fm7;
62
63
extern _sunsoft_fm7 fm7;
74
64
75
void map_init_Sunsoft(BYTE model);
65
void map_init_Sunsoft(BYTE model);
76
void map_init_NSF_Sunsoft(BYTE model);
66
void map_init_NSF_Sunsoft(BYTE model);
(-)puNES-0.105.org/src/core/mappers/mapper_Super24in1.c (+6 lines)
Lines 81-86 INLINE static void super24in1_update_chr Link Here
81
81
82
static const BYTE super24in1_mask[8] = { 0x3F, 0x1F, 0x0F, 0x01, 0x03, 0x00, 0x00, 0x00 };
82
static const BYTE super24in1_mask[8] = { 0x3F, 0x1F, 0x0F, 0x01, 0x03, 0x00, 0x00, 0x00 };
83
83
84
struct _super24in1 {
85
	BYTE reg[3];
86
	WORD prg_map[4];
87
	WORD chr_map[8];
88
} super24in1;
89
84
void map_init_Super24in1(void) {
90
void map_init_Super24in1(void) {
85
	EXTCL_CPU_WR_MEM(Super24in1);
91
	EXTCL_CPU_WR_MEM(Super24in1);
86
	EXTCL_SAVE_MAPPER(Super24in1);
92
	EXTCL_SAVE_MAPPER(Super24in1);
(-)puNES-0.105.org/src/core/mappers/mapper_Super24in1.h (-6 lines)
Lines 21-32 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _super24in1 {
25
	BYTE reg[3];
26
	WORD prg_map[4];
27
	WORD chr_map[8];
28
} super24in1;
29
30
void map_init_Super24in1(void);
24
void map_init_Super24in1(void);
31
void extcl_cpu_wr_mem_Super24in1(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_Super24in1(WORD address, BYTE value);
32
BYTE extcl_save_mapper_Super24in1(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_Super24in1(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_T262.c (+4 lines)
Lines 24-29 Link Here
24
24
25
INLINE static void t262_update(BYTE value);
25
INLINE static void t262_update(BYTE value);
26
26
27
struct _t262 {
28
	BYTE reg[5];
29
} t262;
30
27
void map_init_T262(void) {
31
void map_init_T262(void) {
28
	EXTCL_CPU_WR_MEM(T262);
32
	EXTCL_CPU_WR_MEM(T262);
29
	EXTCL_SAVE_MAPPER(T262);
33
	EXTCL_SAVE_MAPPER(T262);
(-)puNES-0.105.org/src/core/mappers/mapper_T262.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _t262 {
25
	BYTE reg[5];
26
} t262;
27
28
void map_init_T262(void);
24
void map_init_T262(void);
29
void extcl_cpu_wr_mem_T262(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_T262(WORD address, BYTE value);
30
BYTE extcl_save_mapper_T262(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_T262(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_Taito.c (-5 / +17 lines)
Lines 20-29 Link Here
20
#include "mappers.h"
20
#include "mappers.h"
21
#include "info.h"
21
#include "info.h"
22
#include "mem_map.h"
22
#include "mem_map.h"
23
#include "cpu.h"
24
#include "ppu.h"
23
#include "irqA12.h"
25
#include "irqA12.h"
24
#include "save_slot.h"
26
#include "save_slot.h"
25
27
26
BYTE type;
28
struct _taito_X1005 {
29
	BYTE ram[0x80];
30
	BYTE enable;
31
} taito_X1005;
32
struct _taito_X1017 {
33
	BYTE chr[6];
34
	BYTE control;
35
} taito_X1017;
36
struct _taitotmp {
37
	BYTE type;
38
} taitotmp;
27
39
28
void map_init_Taito(BYTE model) {
40
void map_init_Taito(BYTE model) {
29
	switch (model) {
41
	switch (model) {
Lines 96-102 void map_init_Taito(BYTE model) { Link Here
96
			break;
108
			break;
97
	}
109
	}
98
110
99
	type = model;
111
	taitotmp.type = model;
100
}
112
}
101
113
102
void extcl_cpu_wr_mem_Taito_TC0190FMC(WORD address, BYTE value) {
114
void extcl_cpu_wr_mem_Taito_TC0190FMC(WORD address, BYTE value) {
Lines 247-253 void extcl_cpu_wr_mem_Taito_X1005(WORD a Link Here
247
			const BYTE slot = (address & 0x0001) << 1;
259
			const BYTE slot = (address & 0x0001) << 1;
248
			DBWORD bank;
260
			DBWORD bank;
249
261
250
			if (type == X1005B) {
262
			if (taitotmp.type == X1005B) {
251
				if (value & 0x80) {
263
				if (value & 0x80) {
252
					mirroring_SCR1();
264
					mirroring_SCR1();
253
				} else {
265
				} else {
Lines 263-269 void extcl_cpu_wr_mem_Taito_X1005(WORD a Link Here
263
		}
275
		}
264
		case 0x7EF2:
276
		case 0x7EF2:
265
		case 0x7EF4:
277
		case 0x7EF4:
266
			if (type == X1005B) {
278
			if (taitotmp.type == X1005B) {
267
				if (value & 0x80) {
279
				if (value & 0x80) {
268
					mirroring_SCR1();
280
					mirroring_SCR1();
269
				} else {
281
				} else {
Lines 274-280 void extcl_cpu_wr_mem_Taito_X1005(WORD a Link Here
274
			chr.bank_1k[(address & 0x0007) + 2] = chr_chip_byte_pnt(0, value << 10);
286
			chr.bank_1k[(address & 0x0007) + 2] = chr_chip_byte_pnt(0, value << 10);
275
			return;
287
			return;
276
		case 0x7EF6:
288
		case 0x7EF6:
277
			if (type == X1005A) {
289
			if (taitotmp.type == X1005A) {
278
				if (value & 0x01) {
290
				if (value & 0x01) {
279
					mirroring_V();
291
					mirroring_V();
280
				} else {
292
				} else {
(-)puNES-0.105.org/src/core/mappers/mapper_Taito.h (-9 lines)
Lines 31-45 enum { Link Here
31
	X1005_NO_BAT = 101
31
	X1005_NO_BAT = 101
32
};
32
};
33
33
34
struct _taito_X1005 {
35
	BYTE ram[0x80];
36
	BYTE enable;
37
} taito_X1005;
38
struct _taito_X1017 {
39
	BYTE chr[6];
40
	BYTE control;
41
} taito_X1017;
42
43
void map_init_Taito(BYTE model);
34
void map_init_Taito(BYTE model);
44
35
45
void extcl_cpu_wr_mem_Taito_TC0190FMC(WORD address, BYTE value);
36
void extcl_cpu_wr_mem_Taito_TC0190FMC(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_Tengen.c (-5 / +18 lines)
Lines 103-109 enum { Link Here
103
103
104
INLINE static void irq_clock_Tengen_Rambo(int delay);
104
INLINE static void irq_clock_Tengen_Rambo(int delay);
105
105
106
BYTE type;
106
struct _tengen_rambo {
107
	BYTE prg_mode;
108
	BYTE chr_mode;
109
	BYTE reg_index;
110
	BYTE chr[8];
111
	BYTE prg[4];
112
	BYTE irq_mode;
113
	BYTE irq_delay;
114
	BYTE irq_prescaler;
115
	BYTE irq_plus_clock;
116
} tengen_rambo;
117
struct _tengentmp {
118
	BYTE type;
119
} tengentmp;
107
120
108
void map_init_Tengen(BYTE model) {
121
void map_init_Tengen(BYTE model) {
109
	switch (model) {
122
	switch (model) {
Lines 151-157 void map_init_Tengen(BYTE model) { Link Here
151
			break;
164
			break;
152
	}
165
	}
153
166
154
	type = model;
167
	tengentmp.type = model;
155
}
168
}
156
169
157
void extcl_cpu_wr_mem_Tengen_Rambo(WORD address, BYTE value) {
170
void extcl_cpu_wr_mem_Tengen_Rambo(WORD address, BYTE value) {
Lines 171-177 void extcl_cpu_wr_mem_Tengen_Rambo(WORD Link Here
171
			switch (tengen_rambo.reg_index) {
184
			switch (tengen_rambo.reg_index) {
172
				case 0x00:
185
				case 0x00:
173
				case 0x01:
186
				case 0x01:
174
					if ((type == T800037) && !(tengen_rambo.chr_mode & 0x80)) {
187
					if ((tengentmp.type == T800037) && !(tengen_rambo.chr_mode & 0x80)) {
175
						const BYTE slot = tengen_rambo.reg_index << 1;
188
						const BYTE slot = tengen_rambo.reg_index << 1;
176
189
177
						ntbl.bank_1k[slot] = &ntbl.data[((value >> 7) ^ 0x01) << 10];
190
						ntbl.bank_1k[slot] = &ntbl.data[((value >> 7) ^ 0x01) << 10];
Lines 186-192 void extcl_cpu_wr_mem_Tengen_Rambo(WORD Link Here
186
				case 0x03:
199
				case 0x03:
187
				case 0x04:
200
				case 0x04:
188
				case 0x05:
201
				case 0x05:
189
					if ((type == T800037) && (tengen_rambo.chr_mode & 0x80)) {
202
					if ((tengentmp.type == T800037) && (tengen_rambo.chr_mode & 0x80)) {
190
						ntbl.bank_1k[tengen_rambo.reg_index - 2] = &ntbl.data[((value >> 7) ^ 0x01)
203
						ntbl.bank_1k[tengen_rambo.reg_index - 2] = &ntbl.data[((value >> 7) ^ 0x01)
191
							<< 10];
204
							<< 10];
192
					}
205
					}
Lines 229-235 void extcl_cpu_wr_mem_Tengen_Rambo(WORD Link Here
229
			return;
242
			return;
230
		}
243
		}
231
		case 0xA000:
244
		case 0xA000:
232
			if (type == T800037) {
245
			if (tengentmp.type == T800037) {
233
				return;
246
				return;
234
			}
247
			}
235
			if (value & 0x01) {
248
			if (value & 0x01) {
(-)puNES-0.105.org/src/core/mappers/mapper_Tengen.h (-12 lines)
Lines 23-40 Link Here
23
23
24
enum { TRAMBO, T800037, NOCNTPLUS };
24
enum { TRAMBO, T800037, NOCNTPLUS };
25
25
26
struct _tengen_rambo {
27
	BYTE prg_mode;
28
	BYTE chr_mode;
29
	BYTE reg_index;
30
	BYTE chr[8];
31
	BYTE prg[4];
32
	BYTE irq_mode;
33
	BYTE irq_delay;
34
	BYTE irq_prescaler;
35
	BYTE irq_plus_clock;
36
} tengen_rambo;
37
38
void map_init_Tengen(BYTE model);
26
void map_init_Tengen(BYTE model);
39
27
40
void extcl_cpu_wr_mem_Tengen_Rambo(WORD address, BYTE value);
28
void extcl_cpu_wr_mem_Tengen_Rambo(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_TF1201.c (+5 lines)
Lines 31-36 Link Here
31
	chr.bank_1k[slot] = chr_chip_byte_pnt(0, value << 10);\
31
	chr.bank_1k[slot] = chr_chip_byte_pnt(0, value << 10);\
32
	tf1201.chr_rom_bank[slot] = value
32
	tf1201.chr_rom_bank[slot] = value
33
33
34
struct _tf1201 {
35
	BYTE chr_rom_bank[8];
36
	BYTE swap_mode;
37
} tf1201;
38
34
void map_init_TF1201(void) {
39
void map_init_TF1201(void) {
35
	EXTCL_CPU_WR_MEM(TF1201);
40
	EXTCL_CPU_WR_MEM(TF1201);
36
	EXTCL_SAVE_MAPPER(TF1201);
41
	EXTCL_SAVE_MAPPER(TF1201);
(-)puNES-0.105.org/src/core/mappers/mapper_TF1201.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _tf1201 {
25
	BYTE chr_rom_bank[8];
26
	BYTE swap_mode;
27
} tf1201;
28
29
void map_init_TF1201(void);
24
void map_init_TF1201(void);
30
void extcl_cpu_wr_mem_TF1201(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_TF1201(WORD address, BYTE value);
31
BYTE extcl_save_mapper_TF1201(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_TF1201(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_Txc.c (-4 / +9 lines)
Lines 23-29 Link Here
23
#include "irqA12.h"
23
#include "irqA12.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
BYTE type;
26
struct _t22211x {
27
	BYTE reg[4];
28
} t22211x;
29
struct _txctmp {
30
	BYTE type;
31
} txctmp;
27
32
28
void map_init_Txc(BYTE model) {
33
void map_init_Txc(BYTE model) {
29
	switch (model) {
34
	switch (model) {
Lines 73-79 void map_init_Txc(BYTE model) { Link Here
73
			break;
78
			break;
74
	}
79
	}
75
80
76
	type = model;
81
	txctmp.type = model;
77
}
82
}
78
83
79
void extcl_cpu_wr_mem_Txc_tw(WORD address, BYTE value) {
84
void extcl_cpu_wr_mem_Txc_tw(WORD address, BYTE value) {
Lines 114-120 void extcl_cpu_wr_mem_Txc_t22211x(WORD a Link Here
114
	{
119
	{
115
		DBWORD bank;
120
		DBWORD bank;
116
121
117
		if (type == T22211B) {
122
		if (txctmp.type == T22211B) {
118
			value = (((save ^ t22211x.reg[2]) >> 3) & 0x02)
123
			value = (((save ^ t22211x.reg[2]) >> 3) & 0x02)
119
				| (((save ^ t22211x.reg[2]) >> 5) & 0x01);
124
				| (((save ^ t22211x.reg[2]) >> 5) & 0x01);
120
		} else {
125
		} else {
Lines 140-146 BYTE extcl_cpu_rd_mem_Txc_t22211x(WORD a Link Here
140
		return (openbus);
145
		return (openbus);
141
	}
146
	}
142
147
143
	if (type == T22211C) {
148
	if (txctmp.type == T22211C) {
144
		return ((t22211x.reg[1] ^ t22211x.reg[2]) | 0x41);
149
		return ((t22211x.reg[1] ^ t22211x.reg[2]) | 0x41);
145
	} else {
150
	} else {
146
		return ((t22211x.reg[1] ^ t22211x.reg[2]) | 0x40);
151
		return ((t22211x.reg[1] ^ t22211x.reg[2]) | 0x40);
(-)puNES-0.105.org/src/core/mappers/mapper_Txc.h (-4 lines)
Lines 23-32 Link Here
23
23
24
enum { TXCTW, T22211A, T22211B, T22211C };
24
enum { TXCTW, T22211A, T22211B, T22211C };
25
25
26
struct _t22211x {
27
	BYTE reg[4];
28
} t22211x;
29
30
void map_init_Txc(BYTE model);
26
void map_init_Txc(BYTE model);
31
27
32
void extcl_cpu_wr_mem_Txc_tw(WORD address, BYTE value);
28
void extcl_cpu_wr_mem_Txc_tw(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_TxROM.c (-3 / +9 lines)
Lines 65-71 Link Here
65
	}\
65
	}\
66
}
66
}
67
67
68
BYTE type;
68
struct _txrom {
69
	BYTE delay;
70
	uint32_t chr[8][2];
71
} txrom;
72
struct _txromtmp {
73
	BYTE type;
74
} txromtmp;
69
75
70
void map_init_TxROM(BYTE model) {
76
void map_init_TxROM(BYTE model) {
71
	switch (model) {
77
	switch (model) {
Lines 117-123 void map_init_TxROM(BYTE model) { Link Here
117
123
118
	irqA12.present = TRUE;
124
	irqA12.present = TRUE;
119
125
120
	type = model;
126
	txromtmp.type = model;
121
}
127
}
122
128
123
void extcl_cpu_wr_mem_TKSROM(WORD address, BYTE value) {
129
void extcl_cpu_wr_mem_TKSROM(WORD address, BYTE value) {
Lines 195-201 void extcl_wr_chr_TQROM(WORD address, BY Link Here
195
201
196
BYTE extcl_save_mapper_TxROM(BYTE mode, BYTE slot, FILE *fp) {
202
BYTE extcl_save_mapper_TxROM(BYTE mode, BYTE slot, FILE *fp) {
197
	save_slot_ele(mode, slot, txrom.delay);
203
	save_slot_ele(mode, slot, txrom.delay);
198
	if (type == TQROM) {
204
	if (txromtmp.type == TQROM) {
199
		save_slot_ele(mode, slot, txrom.chr);
205
		save_slot_ele(mode, slot, txrom.chr);
200
		if (mode == SAVE_SLOT_READ) {
206
		if (mode == SAVE_SLOT_READ) {
201
			BYTE i;
207
			BYTE i;
(-)puNES-0.105.org/src/core/mappers/mapper_TxROM.h (-5 lines)
Lines 23-33 Link Here
23
23
24
enum { TKSROM, TLSROM, TQROM };
24
enum { TKSROM, TLSROM, TQROM };
25
25
26
struct _txrom {
27
	BYTE delay;
28
	uint32_t chr[8][2];
29
} txrom;
30
31
void map_init_TxROM(BYTE model);
26
void map_init_TxROM(BYTE model);
32
27
33
void extcl_cpu_wr_mem_TKSROM(WORD address, BYTE value);
28
void extcl_cpu_wr_mem_TKSROM(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF158B.c (+5 lines)
Lines 45-50 INLINE static void unif158b_update_prg(v Link Here
45
45
46
static const BYTE unif158b_vlu[8] = { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0F, 0x00 };
46
static const BYTE unif158b_vlu[8] = { 0x00, 0x00, 0x00, 0x01, 0x02, 0x04, 0x0F, 0x00 };
47
47
48
struct _unif158b {
49
	BYTE reg[8];
50
	WORD prg_map[4];
51
} unif158b;
52
48
void map_init_UNIF158B(void) {
53
void map_init_UNIF158B(void) {
49
	EXTCL_CPU_WR_MEM(UNIF158B);
54
	EXTCL_CPU_WR_MEM(UNIF158B);
50
	EXTCL_CPU_RD_MEM(UNIF158B);
55
	EXTCL_CPU_RD_MEM(UNIF158B);
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF158B.h (-5 lines)
Lines 21-31 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _unif158b {
25
	BYTE reg[8];
26
	WORD prg_map[4];
27
} unif158b;
28
29
void map_init_UNIF158B(void);
24
void map_init_UNIF158B(void);
30
void extcl_cpu_wr_mem_UNIF158B(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_UNIF158B(WORD address, BYTE value);
31
BYTE extcl_cpu_rd_mem_UNIF158B(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_UNIF158B(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF43272.c (+4 lines)
Lines 21-26 Link Here
21
#include "mem_map.h"
21
#include "mem_map.h"
22
#include "save_slot.h"
22
#include "save_slot.h"
23
23
24
struct _unif43272 {
25
	WORD address;
26
} unif43272;
27
24
void map_init_UNIF43272(void) {
28
void map_init_UNIF43272(void) {
25
	EXTCL_CPU_WR_MEM(UNIF43272);
29
	EXTCL_CPU_WR_MEM(UNIF43272);
26
	EXTCL_CPU_RD_MEM(UNIF43272);
30
	EXTCL_CPU_RD_MEM(UNIF43272);
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF43272.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _unif43272 {
25
	WORD address;
26
} unif43272;
27
28
void map_init_UNIF43272(void);
24
void map_init_UNIF43272(void);
29
void extcl_cpu_wr_mem_UNIF43272(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_UNIF43272(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_UNIF43272(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_UNIF43272(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.c (-70 / +74 lines)
Lines 1-70 Link Here
1
/*
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
2
 *  Copyright (C) 2010-2020 Fabio Cavallo (aka FHorse)
3
 *
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
7
 *  (at your option) any later version.
8
 *
8
 *
9
 *  This program is distributed in the hope that it will be useful,
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
12
 *  GNU General Public License for more details.
13
 *
13
 *
14
 *  You should have received a copy of the GNU General Public License
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
17
 */
18
18
19
#include <string.h>
19
#include <string.h>
20
#include "mappers.h"
20
#include "mappers.h"
21
#include "info.h"
21
#include "info.h"
22
#include "irqA12.h"
22
#include "irqA12.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
24
25
static const BYTE unif603_5052_vlu[4] = { 0x00, 0x02, 0x02, 0x03 };
25
static const BYTE unif603_5052_vlu[4] = { 0x00, 0x02, 0x02, 0x03 };
26
26
27
void map_init_UNIF603_5052(void) {
27
struct _unif603_5052 {
28
	EXTCL_CPU_WR_MEM(UNIF603_5052);
28
	BYTE reg;
29
	EXTCL_CPU_RD_MEM(UNIF603_5052);
29
} unif603_5052;
30
	EXTCL_SAVE_MAPPER(UNIF603_5052);
30
31
	EXTCL_CPU_EVERY_CYCLE(MMC3);
31
void map_init_UNIF603_5052(void) {
32
	EXTCL_PPU_000_TO_34X(MMC3);
32
	EXTCL_CPU_WR_MEM(UNIF603_5052);
33
	EXTCL_PPU_000_TO_255(MMC3);
33
	EXTCL_CPU_RD_MEM(UNIF603_5052);
34
	EXTCL_PPU_256_TO_319(MMC3);
34
	EXTCL_SAVE_MAPPER(UNIF603_5052);
35
	EXTCL_PPU_320_TO_34X(MMC3);
35
	EXTCL_CPU_EVERY_CYCLE(MMC3);
36
	EXTCL_UPDATE_R2006(MMC3);
36
	EXTCL_PPU_000_TO_34X(MMC3);
37
	mapper.internal_struct[1] = (BYTE *) &mmc3;
37
	EXTCL_PPU_000_TO_255(MMC3);
38
	mapper.internal_struct_size[1] = sizeof(mmc3);
38
	EXTCL_PPU_256_TO_319(MMC3);
39
39
	EXTCL_PPU_320_TO_34X(MMC3);
40
	memset(&mmc3, 0x00, sizeof(mmc3));
40
	EXTCL_UPDATE_R2006(MMC3);
41
	memset(&irqA12, 0x00, sizeof(irqA12));
41
	mapper.internal_struct[1] = (BYTE *) &mmc3;
42
42
	mapper.internal_struct_size[1] = sizeof(mmc3);
43
	info.mapper.extend_wr = TRUE;
43
44
44
	memset(&mmc3, 0x00, sizeof(mmc3));
45
	irqA12.present = TRUE;
45
	memset(&irqA12, 0x00, sizeof(irqA12));
46
	irqA12_delay = 1;
46
47
}
47
	info.mapper.extend_wr = TRUE;
48
void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value) {
48
49
	if (address >= 0x8000) {
49
	irqA12.present = TRUE;
50
		extcl_cpu_wr_mem_MMC3(address, value);
50
	irqA12_delay = 1;
51
		return;
51
}
52
	}
52
void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value) {
53
53
	if (address >= 0x8000) {
54
	if ((address >= 0x4020) && (address <= 0x7FFF)) {
54
		extcl_cpu_wr_mem_MMC3(address, value);
55
		unif603_5052.reg = unif603_5052_vlu[value & 0x03];
55
		return;
56
		return;
56
	}
57
	}
57
58
}
58
	if ((address >= 0x4020) && (address <= 0x7FFF)) {
59
BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, UNUSED(BYTE before)) {
59
		unif603_5052.reg = unif603_5052_vlu[value & 0x03];
60
	if ((address >= 0x4020) && (address <= 0x7FFF)) {
60
		return;
61
		return (unif603_5052.reg);
61
	}
62
	}
62
}
63
	return (openbus);
63
BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, UNUSED(BYTE before)) {
64
}
64
	if ((address >= 0x4020) && (address <= 0x7FFF)) {
65
BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp) {
65
		return (unif603_5052.reg);
66
	save_slot_ele(mode, slot, unif603_5052.reg);
66
	}
67
	extcl_save_mapper_MMC3(mode, slot, fp);
67
	return (openbus);
68
68
}
69
	return (EXIT_OK);
69
BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp) {
70
}
70
	save_slot_ele(mode, slot, unif603_5052.reg);
71
	extcl_save_mapper_MMC3(mode, slot, fp);
72
73
	return (EXIT_OK);
74
}
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.c.orig (+70 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#include <string.h>
20
#include "mappers.h"
21
#include "info.h"
22
#include "irqA12.h"
23
#include "save_slot.h"
24
25
static const BYTE unif603_5052_vlu[4] = { 0x00, 0x02, 0x02, 0x03 };
26
27
void map_init_UNIF603_5052(void) {
28
	EXTCL_CPU_WR_MEM(UNIF603_5052);
29
	EXTCL_CPU_RD_MEM(UNIF603_5052);
30
	EXTCL_SAVE_MAPPER(UNIF603_5052);
31
	EXTCL_CPU_EVERY_CYCLE(MMC3);
32
	EXTCL_PPU_000_TO_34X(MMC3);
33
	EXTCL_PPU_000_TO_255(MMC3);
34
	EXTCL_PPU_256_TO_319(MMC3);
35
	EXTCL_PPU_320_TO_34X(MMC3);
36
	EXTCL_UPDATE_R2006(MMC3);
37
	mapper.internal_struct[1] = (BYTE *) &mmc3;
38
	mapper.internal_struct_size[1] = sizeof(mmc3);
39
40
	memset(&mmc3, 0x00, sizeof(mmc3));
41
	memset(&irqA12, 0x00, sizeof(irqA12));
42
43
	info.mapper.extend_wr = TRUE;
44
45
	irqA12.present = TRUE;
46
	irqA12_delay = 1;
47
}
48
void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value) {
49
	if (address >= 0x8000) {
50
		extcl_cpu_wr_mem_MMC3(address, value);
51
		return;
52
	}
53
54
	if ((address >= 0x4020) && (address <= 0x7FFF)) {
55
		unif603_5052.reg = unif603_5052_vlu[value & 0x03];
56
		return;
57
	}
58
}
59
BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, UNUSED(BYTE before)) {
60
	if ((address >= 0x4020) && (address <= 0x7FFF)) {
61
		return (unif603_5052.reg);
62
	}
63
	return (openbus);
64
}
65
BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp) {
66
	save_slot_ele(mode, slot, unif603_5052.reg);
67
	extcl_save_mapper_MMC3(mode, slot, fp);
68
69
	return (EXIT_OK);
70
}
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.h (-33 / +29 lines)
Lines 1-33 Link Here
1
/*
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
2
 *  Copyright (C) 2010-2020 Fabio Cavallo (aka FHorse)
3
 *
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
7
 *  (at your option) any later version.
8
 *
8
 *
9
 *  This program is distributed in the hope that it will be useful,
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
12
 *  GNU General Public License for more details.
13
 *
13
 *
14
 *  You should have received a copy of the GNU General Public License
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
17
 */
18
18
19
#ifndef MAPPER_UNIF603_5052_H_
19
#ifndef MAPPER_UNIF603_5052_H_
20
#define MAPPER_UNIF603_5052_H_
20
#define MAPPER_UNIF603_5052_H_
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _unif603_5052 {
24
void map_init_UNIF603_5052(void);
25
	BYTE reg;
25
void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value);
26
} unif603_5052;
26
BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, BYTE before);
27
27
BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp);
28
void map_init_UNIF603_5052(void);
28
29
void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value);
29
#endif /* MAPPER_UNIF603_5052_H_ */
30
BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, BYTE before);
31
BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp);
32
33
#endif /* MAPPER_UNIF603_5052_H_ */
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF603_5052.h.orig (+33 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#ifndef MAPPER_UNIF603_5052_H_
20
#define MAPPER_UNIF603_5052_H_
21
22
#include "common.h"
23
24
struct _unif603_5052 {
25
	BYTE reg;
26
} unif603_5052;
27
28
void map_init_UNIF603_5052(void);
29
void extcl_cpu_wr_mem_UNIF603_5052(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_UNIF603_5052(WORD address, BYTE openbus, BYTE before);
31
BYTE extcl_save_mapper_UNIF603_5052(BYTE mode, BYTE slot, FILE *fp);
32
33
#endif /* MAPPER_UNIF603_5052_H_ */
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF8157.c (-5 / +10 lines)
Lines 24-30 Link Here
24
24
25
INLINE static void unif8157_update(BYTE value);
25
INLINE static void unif8157_update(BYTE value);
26
26
27
BYTE unif8157_reset;
27
struct _unif8157 {
28
	WORD reg;
29
} unif8157;
30
struct _unif8157tmp {
31
	BYTE reset;
32
} unif8157tmp;
28
33
29
void map_init_UNIF8157(void) {
34
void map_init_UNIF8157(void) {
30
	EXTCL_CPU_WR_MEM(UNIF8157);
35
	EXTCL_CPU_WR_MEM(UNIF8157);
Lines 36-45 void map_init_UNIF8157(void) { Link Here
36
	memset(&unif8157, 0x00, sizeof(unif8157));
41
	memset(&unif8157, 0x00, sizeof(unif8157));
37
42
38
	if (info.reset >= HARD) {
43
	if (info.reset >= HARD) {
39
		unif8157_reset = 0;
44
		unif8157tmp.reset = 0;
40
	} else if (info.reset == RESET) {
45
	} else if (info.reset == RESET) {
41
		unif8157_reset++;
46
		unif8157tmp.reset++;
42
		unif8157_reset = unif8157_reset & 0x01F;
47
		unif8157tmp.reset = unif8157tmp.reset & 0x01F;
43
	}
48
	}
44
49
45
	info.mapper.extend_rd = TRUE;
50
	info.mapper.extend_rd = TRUE;
Lines 53-59 void extcl_cpu_wr_mem_UNIF8157(WORD addr Link Here
53
BYTE extcl_cpu_rd_mem_UNIF8157(WORD address, BYTE openbus, UNUSED(BYTE before)) {
58
BYTE extcl_cpu_rd_mem_UNIF8157(WORD address, BYTE openbus, UNUSED(BYTE before)) {
54
	if (address >= 0x8000) {
59
	if (address >= 0x8000) {
55
		if ((unif8157.reg & 0x0100) && (prg.chip[0].size < (1024 * 1024))) {
60
		if ((unif8157.reg & 0x0100) && (prg.chip[0].size < (1024 * 1024))) {
56
			address = (address & 0xFFF0) + unif8157_reset;
61
			address = (address & 0xFFF0) + unif8157tmp.reset;
57
			return (prg_rom_rd(address));
62
			return (prg_rom_rd(address));
58
		}
63
		}
59
	}
64
	}
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF8157.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _unif8157 {
25
	WORD reg;
26
} unif8157;
27
28
void map_init_UNIF8157(void);
24
void map_init_UNIF8157(void);
29
void extcl_cpu_wr_mem_UNIF8157(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_UNIF8157(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_UNIF8157(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_UNIF8157(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF8237.c (-4 / +11 lines)
Lines 85-97 INLINE static void unif8237a_update_chr( Link Here
85
			break;\
85
			break;\
86
	}
86
	}
87
#define unif8237_updt_prg()\
87
#define unif8237_updt_prg()\
88
	if (unif8237_model == U8237) {\
88
	if (unif8237tmp.model == U8237) {\
89
		unif8237_update_prg();\
89
		unif8237_update_prg();\
90
	} else {\
90
	} else {\
91
		unif8237a_update_prg();\
91
		unif8237a_update_prg();\
92
	}
92
	}
93
#define unif8237_updt_prg_and_chr()\
93
#define unif8237_updt_prg_and_chr()\
94
	if (unif8237_model == U8237) {\
94
	if (unif8237tmp.model == U8237) {\
95
		unif8237_update_prg();\
95
		unif8237_update_prg();\
96
		unif8237_update_chr();\
96
		unif8237_update_chr();\
97
	} else {\
97
	} else {\
Lines 119-125 static const BYTE unif8237_adr[8][8] = { Link Here
119
	{ 0, 1, 2, 3, 4, 5, 6, 7 },
119
	{ 0, 1, 2, 3, 4, 5, 6, 7 },
120
	{ 0, 1, 2, 3, 4, 5, 6, 7 },
120
	{ 0, 1, 2, 3, 4, 5, 6, 7 },
121
};
121
};
122
BYTE unif8237_model;
122
struct _unif8237 {
123
	BYTE reg[4];
124
	WORD prg_map[4];
125
	WORD chr_map[8];
126
} unif8237;
127
struct _unif8237tmp {
128
	BYTE model;
129
} unif8237tmp;
123
130
124
void map_init_UNIF8237(BYTE model) {
131
void map_init_UNIF8237(BYTE model) {
125
	EXTCL_CPU_WR_MEM(UNIF8237);
132
	EXTCL_CPU_WR_MEM(UNIF8237);
Lines 139-145 void map_init_UNIF8237(BYTE model) { Link Here
139
	memset(&irqA12, 0x00, sizeof(irqA12));
146
	memset(&irqA12, 0x00, sizeof(irqA12));
140
	memset(&unif8237, 0x00, sizeof(unif8237));
147
	memset(&unif8237, 0x00, sizeof(unif8237));
141
148
142
	unif8237_model = model;
149
	unif8237tmp.model = model;
143
150
144
	{
151
	{
145
		BYTE i;
152
		BYTE i;
(-)puNES-0.105.org/src/core/mappers/mapper_UNIF8237.h (-6 lines)
Lines 23-34 Link Here
23
23
24
enum _unif8237_type { U8237, U8237A };
24
enum _unif8237_type { U8237, U8237A };
25
25
26
struct _unif8237 {
27
	BYTE reg[4];
28
	WORD prg_map[4];
29
	WORD chr_map[8];
30
} unif8237;
31
32
void map_init_UNIF8237(BYTE model);
26
void map_init_UNIF8237(BYTE model);
33
void extcl_cpu_wr_mem_UNIF8237(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_UNIF8237(WORD address, BYTE value);
34
BYTE extcl_save_mapper_UNIF8237(BYTE mode, BYTE slot, FILE *fp);
28
BYTE extcl_save_mapper_UNIF8237(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_UNIFSMB2J.c (-5 / +14 lines)
Lines 23-29 Link Here
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
BYTE *unifsmb2j_prg_6000;
26
struct _unifsmb2j {
27
	BYTE reg;
28
	struct _unifsmb2j_irq {
29
		BYTE active;
30
		WORD count;
31
	} irq;
32
} unifsmb2j;
33
struct _unifsmb2jtmp {
34
	BYTE *prg_6000;
35
} unifsmb2jtmp;
27
36
28
void map_init_UNIFSMB2J(void) {
37
void map_init_UNIFSMB2J(void) {
29
	EXTCL_CPU_WR_MEM(UNIFSMB2J);
38
	EXTCL_CPU_WR_MEM(UNIFSMB2J);
Lines 36-42 void map_init_UNIFSMB2J(void) { Link Here
36
	memset(&unifsmb2j, 0x00, sizeof(unifsmb2j));
45
	memset(&unifsmb2j, 0x00, sizeof(unifsmb2j));
37
46
38
	map_prg_rom_8k(4, 0, 0);
47
	map_prg_rom_8k(4, 0, 0);
39
	unifsmb2j_prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13);
48
	unifsmb2jtmp.prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13);
40
49
41
	info.mapper.extend_wr = TRUE;
50
	info.mapper.extend_wr = TRUE;
42
}
51
}
Lines 44-50 void extcl_cpu_wr_mem_UNIFSMB2J(WORD add Link Here
44
	if (address == 0x4027) {
53
	if (address == 0x4027) {
45
		unifsmb2j.reg = value & 0x01;
54
		unifsmb2j.reg = value & 0x01;
46
		_control_bank(unifsmb2j.reg, info.prg.rom[1].max.banks_8k)
55
		_control_bank(unifsmb2j.reg, info.prg.rom[1].max.banks_8k)
47
		unifsmb2j_prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13);
56
		unifsmb2jtmp.prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13);
48
	} else if (address == 0x4068) {
57
	} else if (address == 0x4068) {
49
		unifsmb2j.irq.active = value & 0x01;
58
		unifsmb2j.irq.active = value & 0x01;
50
		unifsmb2j.irq.count = 0;
59
		unifsmb2j.irq.count = 0;
Lines 55-61 BYTE extcl_cpu_rd_mem_UNIFSMB2J(WORD add Link Here
55
	if ((address >= 0x4042) && (address <= 0x4055)) {
64
	if ((address >= 0x4042) && (address <= 0x4055)) {
56
		return (0xFF);
65
		return (0xFF);
57
	} else if ((address >= 0x6000) && (address <= 0x7FFF)) {
66
	} else if ((address >= 0x6000) && (address <= 0x7FFF)) {
58
		return (unifsmb2j_prg_6000[address & 0x1FFF]);
67
		return (unifsmb2jtmp.prg_6000[address & 0x1FFF]);
59
	}
68
	}
60
	return (openbus);
69
	return (openbus);
61
}
70
}
Lines 65-71 BYTE extcl_save_mapper_UNIFSMB2J(BYTE mo Link Here
65
	save_slot_ele(mode, slot, unifsmb2j.irq.count);
74
	save_slot_ele(mode, slot, unifsmb2j.irq.count);
66
75
67
	if (mode == SAVE_SLOT_READ) {
76
	if (mode == SAVE_SLOT_READ) {
68
		unifsmb2j_prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13);
77
		unifsmb2jtmp.prg_6000 = prg_chip_byte_pnt(1, unifsmb2j.reg << 13);
69
	}
78
	}
70
79
71
	return (EXIT_OK);
80
	return (EXIT_OK);
(-)puNES-0.105.org/src/core/mappers/mapper_UNIFSMB2J.h (-8 lines)
Lines 21-34 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _unifsmb2j {
25
	BYTE reg;
26
	struct _unifsmb2j_irq {
27
		BYTE active;
28
		WORD count;
29
	} irq;
30
} unifsmb2j;
31
32
void map_init_UNIFSMB2J(void);
24
void map_init_UNIFSMB2J(void);
33
void extcl_cpu_wr_mem_UNIFSMB2J(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_UNIFSMB2J(WORD address, BYTE value);
34
BYTE extcl_cpu_rd_mem_UNIFSMB2J(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_UNIFSMB2J(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_VRC2.c (-5 / +10 lines)
Lines 27-39 Link Here
27
	chr.bank_1k[slot] = chr_chip_byte_pnt(0, value << 10);\
27
	chr.bank_1k[slot] = chr_chip_byte_pnt(0, value << 10);\
28
	vrc2.chr_rom_bank[slot] = value
28
	vrc2.chr_rom_bank[slot] = value
29
#define chr_rom_1k_low_update(slot, mask, shift)\
29
#define chr_rom_1k_low_update(slot, mask, shift)\
30
	value = (vrc2.chr_rom_bank[slot] & mask) | (((value & 0x0F) >> type) << shift);\
30
	value = (vrc2.chr_rom_bank[slot] & mask) | (((value & 0x0F) >> vrc2tmp.type) << shift);\
31
	_chr_rom_1k_update(slot)
31
	_chr_rom_1k_update(slot)
32
#define chr_rom_1k_high_update(slot, mask, shift)\
32
#define chr_rom_1k_high_update(slot, mask, shift)\
33
	value = (vrc2.chr_rom_bank[slot] & mask) | ((value & 0x0F) << (shift - type));\
33
	value = (vrc2.chr_rom_bank[slot] & mask) | ((value & 0x0F) << (shift - vrc2tmp.type));\
34
	_chr_rom_1k_update(slot)
34
	_chr_rom_1k_update(slot)
35
35
36
BYTE type;
36
struct _vrc2 {
37
	BYTE chr_rom_bank[8];
38
} vrc2;
39
struct _vrc2tmp {
40
	BYTE type;
41
} vrc2tmp;
37
42
38
const WORD shift_VRC2[2][4] = {
43
const WORD shift_VRC2[2][4] = {
39
	{0x0000, 0x0001, 0x0002, 0x0003},
44
	{0x0000, 0x0001, 0x0002, 0x0003},
Lines 55-67 void map_init_VRC2(BYTE revision) { Link Here
55
		}
60
		}
56
	}
61
	}
57
62
58
	type = revision;
63
	vrc2tmp.type = revision;
59
}
64
}
60
void extcl_cpu_wr_mem_VRC2(WORD address, BYTE value) {
65
void extcl_cpu_wr_mem_VRC2(WORD address, BYTE value) {
61
	if (address < 0xB000) {
66
	if (address < 0xB000) {
62
		address &= 0xF000;
67
		address &= 0xF000;
63
	} else {
68
	} else {
64
		address = (address & 0xF000) | shift_VRC2[type][address & 0x0003];
69
		address = (address & 0xF000) | shift_VRC2[vrc2tmp.type][address & 0x0003];
65
	}
70
	}
66
71
67
	switch (address) {
72
	switch (address) {
(-)puNES-0.105.org/src/core/mappers/mapper_VRC2.h (-4 lines)
Lines 23-32 Link Here
23
23
24
enum { VRC2B, VRC2A };
24
enum { VRC2B, VRC2A };
25
25
26
struct _vrc2 {
27
	BYTE chr_rom_bank[8];
28
} vrc2;
29
30
void map_init_VRC2(BYTE revision);
26
void map_init_VRC2(BYTE revision);
31
void extcl_cpu_wr_mem_VRC2(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_VRC2(WORD address, BYTE value);
32
BYTE extcl_save_mapper_VRC2(BYTE mode, BYTE slot, FILE *fp);
28
BYTE extcl_save_mapper_VRC2(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_VRC3.c (+9 lines)
Lines 23-28 Link Here
23
#include "cpu.h"
23
#include "cpu.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
struct _vrc3 {
27
	BYTE enabled;
28
	WORD reload;
29
	BYTE mode;
30
	BYTE acknowledge;
31
	WORD mask;
32
	WORD count;
33
} vrc3;
34
26
void map_init_VRC3(void) {
35
void map_init_VRC3(void) {
27
	EXTCL_CPU_WR_MEM(VRC3);
36
	EXTCL_CPU_WR_MEM(VRC3);
28
	EXTCL_SAVE_MAPPER(VRC3);
37
	EXTCL_SAVE_MAPPER(VRC3);
(-)puNES-0.105.org/src/core/mappers/mapper_VRC3.h (-9 lines)
Lines 21-35 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _vrc3 {
25
	BYTE enabled;
26
	WORD reload;
27
	BYTE mode;
28
	BYTE acknowledge;
29
	WORD mask;
30
	WORD count;
31
} vrc3;
32
33
void map_init_VRC3(void);
24
void map_init_VRC3(void);
34
void extcl_cpu_wr_mem_VRC3(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_VRC3(WORD address, BYTE value);
35
BYTE extcl_save_mapper_VRC3(BYTE mode, BYTE slot, FILE *fp);
26
BYTE extcl_save_mapper_VRC3(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_VRC4.c (-4 / +16 lines)
Lines 35-41 Link Here
35
#define chr_rom_1k_update_low(slot)\
35
#define chr_rom_1k_update_low(slot)\
36
	_chr_rom_1k_update(slot, 0xF0, 0)
36
	_chr_rom_1k_update(slot, 0xF0, 0)
37
37
38
BYTE type;
38
struct _vrc4 {
39
	WORD chr_rom_high_bank[8];
40
	BYTE chr_rom_bank[8];
41
	BYTE swap_mode;
42
	BYTE irq_enabled;
43
	BYTE irq_reload;
44
	BYTE irq_mode;
45
	BYTE irq_acknowledge;
46
	BYTE irq_count;
47
	WORD irq_prescaler;
48
} vrc4;
49
struct _vrc4tmp {
50
	BYTE type;
51
} vrc4tmp;
39
52
40
const BYTE shift_VRC4[6] = { 0x01, 0x00, 0x06, 0x02, 0x02, 0x00 };
53
const BYTE shift_VRC4[6] = { 0x01, 0x00, 0x06, 0x02, 0x02, 0x00 };
41
const WORD mask_VRC4[6]  = { 0x0006, 0x0003, 0x00C0, 0x000C, 0x000C, 0x0003 };
54
const WORD mask_VRC4[6]  = { 0x0006, 0x0003, 0x00C0, 0x000C, 0x000C, 0x0003 };
Lines 72-78 void map_init_VRC4(BYTE revision) { Link Here
72
		vrc4.irq_prescaler = 0;
85
		vrc4.irq_prescaler = 0;
73
	}
86
	}
74
87
75
	type = revision;
88
	vrc4tmp.type = revision;
76
}
89
}
77
void extcl_cpu_wr_mem_VRC4(WORD address, BYTE value) {
90
void extcl_cpu_wr_mem_VRC4(WORD address, BYTE value) {
78
	WORD tmp = address & 0xF000;
91
	WORD tmp = address & 0xF000;
Lines 80-87 void extcl_cpu_wr_mem_VRC4(WORD address, Link Here
80
	if ((tmp == 0x8000) || (tmp == 0xA000)) {
93
	if ((tmp == 0x8000) || (tmp == 0xA000)) {
81
		address &= 0xF000;
94
		address &= 0xF000;
82
	} else {
95
	} else {
83
		address = (address & 0xF000)
96
		address = (address & 0xF000) | table_VRC4[vrc4tmp.type][(address & mask_VRC4[vrc4tmp.type]) >> shift_VRC4[vrc4tmp.type]];
84
			| table_VRC4[type][(address & mask_VRC4[type]) >> shift_VRC4[type]];
85
	}
97
	}
86
98
87
	switch (address) {
99
	switch (address) {
(-)puNES-0.105.org/src/core/mappers/mapper_VRC4.h (-12 lines)
Lines 23-40 Link Here
23
23
24
enum { VRC4A, VRC4B, VRC4C, VRC4D, VRC4E, VRC4UNL, VRC4BMC, VRC4T230 };
24
enum { VRC4A, VRC4B, VRC4C, VRC4D, VRC4E, VRC4UNL, VRC4BMC, VRC4T230 };
25
25
26
struct _vrc4 {
27
	WORD chr_rom_high_bank[8];
28
	BYTE chr_rom_bank[8];
29
	BYTE swap_mode;
30
	BYTE irq_enabled;
31
	BYTE irq_reload;
32
	BYTE irq_mode;
33
	BYTE irq_acknowledge;
34
	BYTE irq_count;
35
	WORD irq_prescaler;
36
} vrc4;
37
38
void map_init_VRC4(BYTE revision);
26
void map_init_VRC4(BYTE revision);
39
void extcl_cpu_wr_mem_VRC4(WORD address, BYTE value);
27
void extcl_cpu_wr_mem_VRC4(WORD address, BYTE value);
40
BYTE extcl_save_mapper_VRC4(BYTE mode, BYTE slot, FILE *fp);
28
BYTE extcl_save_mapper_VRC4(BYTE mode, BYTE slot, FILE *fp);
(-)puNES-0.105.org/src/core/mappers/mapper_VRC6.c (-7 / +11 lines)
Lines 54-60 INLINE static void vrc6_update_chr_and_m Link Here
54
	if (!vrc6.square.enabled) {\
54
	if (!vrc6.square.enabled) {\
55
		vrc6.square.output = 0;\
55
		vrc6.square.output = 0;\
56
	}
56
	}
57
58
#define vrc6_square_saveslot(square)\
57
#define vrc6_square_saveslot(square)\
59
	save_slot_ele(mode, slot, square.enabled);\
58
	save_slot_ele(mode, slot, square.enabled);\
60
	save_slot_ele(mode, slot, square.duty);\
59
	save_slot_ele(mode, slot, square.duty);\
Lines 65-71 INLINE static void vrc6_update_chr_and_m Link Here
65
	save_slot_ele(mode, slot, square.frequency);\
64
	save_slot_ele(mode, slot, square.frequency);\
66
	save_slot_ele(mode, slot, square.output)
65
	save_slot_ele(mode, slot, square.output)
67
66
68
BYTE type, delay;
67
_vrc6 vrc6;
68
struct _vrc6tmp {
69
	BYTE type;
70
	BYTE delay;
71
} vrc6tmp;
69
72
70
const WORD table_VRC6[2][4] = {
73
const WORD table_VRC6[2][4] = {
71
	{0x0000, 0x0001, 0x0002, 0x0003},
74
	{0x0000, 0x0001, 0x0002, 0x0003},
Lines 96-105 void map_init_VRC6(BYTE revision) { Link Here
96
	vrc6.S4.timer = 1;
99
	vrc6.S4.timer = 1;
97
	vrc6.S4.duty = 1;
100
	vrc6.S4.duty = 1;
98
	vrc6.saw.timer = 1;
101
	vrc6.saw.timer = 1;
99
	delay = 1;
102
	vrc6tmp.delay = 1;
100
103
101
	type = revision;
104
	vrc6tmp.type = revision;
102
}
105
}
106
103
void map_init_NSF_VRC6(BYTE revision) {
107
void map_init_NSF_VRC6(BYTE revision) {
104
	memset(&vrc6, 0x00, sizeof(vrc6));
108
	memset(&vrc6, 0x00, sizeof(vrc6));
105
109
Lines 109-118 void map_init_NSF_VRC6(BYTE revision) { Link Here
109
	vrc6.S4.duty = 1;
113
	vrc6.S4.duty = 1;
110
	vrc6.saw.timer = 1;
114
	vrc6.saw.timer = 1;
111
115
112
	type = revision;
116
	vrc6tmp.type = revision;
113
}
117
}
114
void extcl_cpu_wr_mem_VRC6(WORD address, BYTE value) {
118
void extcl_cpu_wr_mem_VRC6(WORD address, BYTE value) {
115
	address = (address & 0xF000) | table_VRC6[type][(address & 0x0003)];
119
	address = (address & 0xF000) | table_VRC6[vrc6tmp.type][(address & 0x0003)];
116
120
117
	switch (address) {
121
	switch (address) {
118
		case 0x8000:
122
		case 0x8000:
Lines 276-282 void extcl_cpu_every_cycle_VRC6(void) { Link Here
276
	}
280
	}
277
281
278
	vrc6.count = vrc6.reload;
282
	vrc6.count = vrc6.reload;
279
	vrc6.delay = delay;
283
	vrc6.delay = vrc6tmp.delay;
280
}
284
}
281
void extcl_apu_tick_VRC6(void) {
285
void extcl_apu_tick_VRC6(void) {
282
	vcr6_square_tick(S3)
286
	vcr6_square_tick(S3)
(-)puNES-0.105.org/src/core/mappers/mapper_VRC6.h (-3 / +4 lines)
Lines 42-49 typedef struct _vrc6_saw { Link Here
42
	WORD frequency;
42
	WORD frequency;
43
	SWORD output;
43
	SWORD output;
44
} _vrc6_saw;
44
} _vrc6_saw;
45
45
typedef struct _vrc6 {
46
struct _vrc6 {
47
	BYTE enabled;
46
	BYTE enabled;
48
	BYTE reload;
47
	BYTE reload;
49
	BYTE mode;
48
	BYTE mode;
Lines 61-67 struct _vrc6 { Link Here
61
	/* ------------------------------------------------------- */
60
	/* ------------------------------------------------------- */
62
	/* */ BYTE clocked;                                     /* */
61
	/* */ BYTE clocked;                                     /* */
63
	/* ------------------------------------------------------- */
62
	/* ------------------------------------------------------- */
64
} vrc6;
63
} _vrc6;
64
65
extern _vrc6 vrc6;
65
66
66
void map_init_VRC6(BYTE revision);
67
void map_init_VRC6(BYTE revision);
67
void map_init_NSF_VRC6(BYTE revision);
68
void map_init_NSF_VRC6(BYTE revision);
(-)puNES-0.105.org/src/core/mappers/mapper_VRC7.c (-13 / +17 lines)
Lines 31-38 const WORD table_VRC7[2][4] = { Link Here
31
	{0x0000, 0x0001, 0x0002, 0x0003},
31
	{0x0000, 0x0001, 0x0002, 0x0003},
32
};
32
};
33
33
34
WORD mask;
34
_vrc7 vrc7;
35
BYTE type, delay;
35
struct _vrc7tmp {
36
	WORD mask;
37
	BYTE type;
38
	BYTE delay;
39
} vrc7tmp;
36
40
37
void map_init_VRC7(BYTE revision) {
41
void map_init_VRC7(BYTE revision) {
38
	EXTCL_CPU_WR_MEM(VRC7);
42
	EXTCL_CPU_WR_MEM(VRC7);
Lines 53-79 void map_init_VRC7(BYTE revision) { Link Here
53
		vrc7.prescaler = 0;
57
		vrc7.prescaler = 0;
54
	}
58
	}
55
59
56
	mask = 0xF000;
60
	vrc7tmp.mask = 0xF000;
57
	if (revision == VRC7A) {
61
	if (revision == VRC7A) {
58
		mask = 0xF020;
62
		vrc7tmp.mask = 0xF020;
59
	}
63
	}
60
64
61
	delay = 1;
65
	vrc7tmp.delay = 1;
62
66
63
	type = revision;
67
	vrc7tmp.type = revision;
64
}
68
}
65
void map_init_NSF_VRC7(BYTE revision) {
69
void map_init_NSF_VRC7(BYTE revision) {
66
	memset(&vrc7, 0x00, sizeof(vrc7));
70
	memset(&vrc7, 0x00, sizeof(vrc7));
67
71
68
	mask = 0xF000;
72
	vrc7tmp.mask = 0xF000;
69
	if (revision == VRC7A) {
73
	if (revision == VRC7A) {
70
		mask = 0xF020;
74
		vrc7tmp.mask = 0xF020;
71
	}
75
	}
72
76
73
	type = revision;
77
	vrc7tmp.type = revision;
74
}
78
}
75
void extcl_cpu_wr_mem_VRC7(WORD address, BYTE value) {
79
void extcl_cpu_wr_mem_VRC7(WORD address, BYTE value) {
76
	address = (address & mask) | table_VRC7[type][(address & 0x0018) >> 3];
80
	address = (address & vrc7tmp.mask) | table_VRC7[vrc7tmp.type][(address & 0x0018) >> 3];
77
81
78
	switch (address) {
82
	switch (address) {
79
		case 0x8000:
83
		case 0x8000:
Lines 206-212 void extcl_cpu_every_cycle_VRC7(void) { Link Here
206
	}
210
	}
207
211
208
	vrc7.count = vrc7.reload;
212
	vrc7.count = vrc7.reload;
209
	vrc7.delay = delay;
213
	vrc7.delay = vrc7tmp.delay;
210
}
214
}
211
void extcl_snd_playback_start_VRC7(WORD samplarate) {
215
void extcl_snd_playback_start_VRC7(WORD samplarate) {
212
	opll_reset(3579545, samplarate);
216
	opll_reset(3579545, samplarate);
Lines 230-236 void map_init_VRC7UNL(void) { Link Here
230
		vrc7.prescaler = 0;
234
		vrc7.prescaler = 0;
231
	}
235
	}
232
236
233
	delay = 1;
237
	vrc7tmp.delay = 1;
234
}
238
}
235
void extcl_cpu_wr_mem_VRC7UNL(WORD address, BYTE value) {
239
void extcl_cpu_wr_mem_VRC7UNL(WORD address, BYTE value) {
236
	switch (address & 0xF008) {
240
	switch (address & 0xF008) {
Lines 358-362 void extcl_cpu_every_cycle_VRC7UNL(void) Link Here
358
	}
362
	}
359
363
360
	vrc7.count = vrc7.reload;
364
	vrc7.count = vrc7.reload;
361
	vrc7.delay = delay;
365
	vrc7.delay = vrc7tmp.delay;
362
}
366
}
(-)puNES-0.105.org/src/core/mappers/mapper_VRC7.h (-2 / +4 lines)
Lines 23-29 Link Here
23
23
24
enum { VRC7A, VRC7B, VRC7UNL };
24
enum { VRC7A, VRC7B, VRC7UNL };
25
25
26
struct _vrc7 {
26
typedef struct _vrc7 {
27
	BYTE reg;
27
	BYTE reg;
28
	BYTE enabled;
28
	BYTE enabled;
29
	BYTE reload;
29
	BYTE reload;
Lines 32-38 struct _vrc7 { Link Here
32
	BYTE count;
32
	BYTE count;
33
	BYTE delay;
33
	BYTE delay;
34
	WORD prescaler;
34
	WORD prescaler;
35
} vrc7;
35
} _vrc7;
36
37
extern _vrc7 vrc7;
36
38
37
void map_init_VRC7(BYTE revision);
39
void map_init_VRC7(BYTE revision);
38
void map_init_NSF_VRC7(BYTE revision);
40
void map_init_NSF_VRC7(BYTE revision);
(-)puNES-0.105.org/src/core/mappers/mapper_Waixing.c (-17 / +26 lines)
Lines 23-30 Link Here
23
#include "irqA12.h"
23
#include "irqA12.h"
24
#include "save_slot.h"
24
#include "save_slot.h"
25
25
26
BYTE min, max;
27
28
#define waixing_swap_chr_bank_1k(src, dst)\
26
#define waixing_swap_chr_bank_1k(src, dst)\
29
{\
27
{\
30
	BYTE *chr_bank_1k = chr.bank_1k[src];\
28
	BYTE *chr_bank_1k = chr.bank_1k[src];\
Lines 67-74 BYTE min, max; Link Here
67
}
65
}
68
66
69
#define waixing_type_ACDE_chr_1k(a)\
67
#define waixing_type_ACDE_chr_1k(a)\
70
	if ((value >= min) && (value <= max)) {\
68
	if ((value >= waixingtmp.min) && (value <= waixingtmp.max)) {\
71
		chr.bank_1k[a] = &chr.extra.data[(value - min) << 10];\
69
		chr.bank_1k[a] = &chr.extra.data[(value - waixingtmp.min) << 10];\
72
	} else {\
70
	} else {\
73
		chr.bank_1k[a] = chr_chip_byte_pnt(0, value << 10);\
71
		chr.bank_1k[a] = chr_chip_byte_pnt(0, value << 10);\
74
	}
72
	}
Lines 436-441 BYTE min, max; Link Here
436
	}\
434
	}\
437
}
435
}
438
436
437
struct _waixing {
438
	WORD prg_map[4];
439
	WORD chr_map[8];
440
	BYTE reg;
441
	WORD ctrl[8];
442
} waixing;
443
struct _waixingtmp {
444
	BYTE min;
445
	BYTE max;
446
} waixingtmp;
447
439
void map_init_Waixing(BYTE model) {
448
void map_init_Waixing(BYTE model) {
440
	switch (model) {
449
	switch (model) {
441
		case WPSX:
450
		case WPSX:
Lines 486-502 void map_init_Waixing(BYTE model) { Link Here
486
		case WTD:
495
		case WTD:
487
		case WTE:
496
		case WTE:
488
			if (model == WTA) {
497
			if (model == WTA) {
489
				min = 0x08;
498
				waixingtmp.min = 0x08;
490
				max = 0x09;
499
				waixingtmp.max = 0x09;
491
			} else if (model == WTC) {
500
			} else if (model == WTC) {
492
				min = 0x08;
501
				waixingtmp.min = 0x08;
493
				max = 0x0B;
502
				waixingtmp.max = 0x0B;
494
			} else if (model == WTD) {
503
			} else if (model == WTD) {
495
				min = 0x00;
504
				waixingtmp.min = 0x00;
496
				max = 0x01;
505
				waixingtmp.max = 0x01;
497
			} else if (model == WTE) {
506
			} else if (model == WTE) {
498
				min = 0x00;
507
				waixingtmp.min = 0x00;
499
				max = 0x03;
508
				waixingtmp.max = 0x03;
500
			}
509
			}
501
			EXTCL_CPU_WR_MEM(Waixing_type_ACDE);
510
			EXTCL_CPU_WR_MEM(Waixing_type_ACDE);
502
			EXTCL_SAVE_MAPPER(Waixing_type_ACDE);
511
			EXTCL_SAVE_MAPPER(Waixing_type_ACDE);
Lines 529-536 void map_init_Waixing(BYTE model) { Link Here
529
					for (i = 0; i < 8; i++) {
538
					for (i = 0; i < 8; i++) {
530
						waixing.chr_map[i] = i;
539
						waixing.chr_map[i] = i;
531
540
532
						if ((waixing.chr_map[i] >= min) && (waixing.chr_map[i] <= max)) {
541
						if ((waixing.chr_map[i] >= waixingtmp.min) && (waixing.chr_map[i] <= waixingtmp.max)) {
533
							chr.bank_1k[i] = &chr.extra.data[(waixing.chr_map[i] - min) << 10];
542
							chr.bank_1k[i] = &chr.extra.data[(waixing.chr_map[i] - waixingtmp.min) << 10];
534
						}
543
						}
535
					}
544
					}
536
				}
545
				}
Lines 757-764 BYTE extcl_save_mapper_Waixing_type_ACDE Link Here
757
		BYTE i;
766
		BYTE i;
758
767
759
		for (i = 0; i < 8; i++) {
768
		for (i = 0; i < 8; i++) {
760
			if ((waixing.chr_map[i] >= min) && (waixing.chr_map[i] <= max)) {
769
			if ((waixing.chr_map[i] >= waixingtmp.min) && (waixing.chr_map[i] <= waixingtmp.max)) {
761
				chr.bank_1k[i] = &chr.extra.data[(waixing.chr_map[i] - min) << 10];
770
				chr.bank_1k[i] = &chr.extra.data[(waixing.chr_map[i] - waixingtmp.min) << 10];
762
			}
771
			}
763
		}
772
		}
764
	}
773
	}
Lines 768-774 BYTE extcl_save_mapper_Waixing_type_ACDE Link Here
768
void extcl_wr_chr_Waixing_type_ACDE(WORD address, BYTE value) {
777
void extcl_wr_chr_Waixing_type_ACDE(WORD address, BYTE value) {
769
	const BYTE slot = address >> 10;
778
	const BYTE slot = address >> 10;
770
779
771
	if ((waixing.chr_map[slot] >= min) && (waixing.chr_map[slot] <= max)) {
780
	if ((waixing.chr_map[slot] >= waixingtmp.min) && (waixing.chr_map[slot] <= waixingtmp.max)) {
772
		chr.bank_1k[slot][address & 0x3FF] = value;
781
		chr.bank_1k[slot][address & 0x3FF] = value;
773
	}
782
	}
774
}
783
}
(-)puNES-0.105.org/src/core/mappers/mapper_Waixing.h (-7 lines)
Lines 34-46 enum { Link Here
34
	BAD_SUGOROQUEST
34
	BAD_SUGOROQUEST
35
};
35
};
36
36
37
struct _waixing {
38
	WORD prg_map[4];
39
	WORD chr_map[8];
40
	BYTE reg;
41
	WORD ctrl[8];
42
} waixing;
43
44
void map_init_Waixing(BYTE model);
37
void map_init_Waixing(BYTE model);
45
38
46
void extcl_cpu_wr_mem_Waixing_PSx(WORD address, BYTE value);
39
void extcl_cpu_wr_mem_Waixing_PSx(WORD address, BYTE value);
(-)puNES-0.105.org/src/core/mappers/mapper_Whirlwind.c (-3 / +8 lines)
Lines 24-30 Link Here
24
24
25
INLINE static void whirlwind_6000_update(void);
25
INLINE static void whirlwind_6000_update(void);
26
26
27
BYTE *whirlwind_prg_6000;
27
struct _whirlwind {
28
	uint32_t reg;
29
} whirlwind;
30
struct _whirlwindtmp {
31
	BYTE *prg_6000;
32
} whirlwindtmp;
28
33
29
void map_init_Whirlwind(void) {
34
void map_init_Whirlwind(void) {
30
	EXTCL_CPU_WR_MEM(Whirlwind);
35
	EXTCL_CPU_WR_MEM(Whirlwind);
Lines 56-62 BYTE extcl_cpu_rd_mem_Whirlwind(WORD add Link Here
56
	switch (address & 0xF000) {
61
	switch (address & 0xF000) {
57
		case 0x6000:
62
		case 0x6000:
58
		case 0x7000:
63
		case 0x7000:
59
			return (whirlwind_prg_6000[address & 0x1FFF]);
64
			return (whirlwindtmp.prg_6000[address & 0x1FFF]);
60
	}
65
	}
61
	return (openbus);
66
	return (openbus);
62
67
Lines 79-83 INLINE static void whirlwind_6000_update Link Here
79
84
80
	value = whirlwind.reg;
85
	value = whirlwind.reg;
81
	control_bank(info.prg.rom[0].max.banks_8k)
86
	control_bank(info.prg.rom[0].max.banks_8k)
82
	whirlwind_prg_6000 = prg_chip_byte_pnt(0, value << 13);
87
	whirlwindtmp.prg_6000 = prg_chip_byte_pnt(0, value << 13);
83
}
88
}
(-)puNES-0.105.org/src/core/mappers/mapper_Whirlwind.h (-4 lines)
Lines 21-30 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _whirlwind {
25
	uint32_t reg;
26
} whirlwind;
27
28
void map_init_Whirlwind(void);
24
void map_init_Whirlwind(void);
29
void extcl_cpu_wr_mem_Whirlwind(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_Whirlwind(WORD address, BYTE value);
30
BYTE extcl_cpu_rd_mem_Whirlwind(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_Whirlwind(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers/mapper_YOKO.c (+13 lines)
Lines 25-30 Link Here
25
25
26
INLINE static void yoko_update(void);
26
INLINE static void yoko_update(void);
27
27
28
struct _yoko {
29
	BYTE mode;
30
	BYTE bank;
31
	BYTE dip;
32
	BYTE low[4];
33
	BYTE reg[7];
34
35
	struct _yoko_irq {
36
		BYTE active;
37
		WORD count;
38
	} irq;
39
} yoko;
40
28
void map_init_YOKO(void) {
41
void map_init_YOKO(void) {
29
	EXTCL_CPU_WR_MEM(YOKO);
42
	EXTCL_CPU_WR_MEM(YOKO);
30
	EXTCL_CPU_RD_MEM(YOKO);
43
	EXTCL_CPU_RD_MEM(YOKO);
(-)puNES-0.105.org/src/core/mappers/mapper_YOKO.h (-13 lines)
Lines 21-39 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
struct _yoko {
25
	BYTE mode;
26
	BYTE bank;
27
	BYTE dip;
28
	BYTE low[4];
29
	BYTE reg[7];
30
31
	struct _yoko_irq {
32
		BYTE active;
33
		WORD count;
34
	} irq;
35
} yoko;
36
37
void map_init_YOKO(void);
24
void map_init_YOKO(void);
38
void extcl_cpu_wr_mem_YOKO(WORD address, BYTE value);
25
void extcl_cpu_wr_mem_YOKO(WORD address, BYTE value);
39
BYTE extcl_cpu_rd_mem_YOKO(WORD address, BYTE openbus, BYTE before);
26
BYTE extcl_cpu_rd_mem_YOKO(WORD address, BYTE openbus, BYTE before);
(-)puNES-0.105.org/src/core/mappers.c (+3 lines)
Lines 30-35 Link Here
30
#include "unif.h"
30
#include "unif.h"
31
#include "gui.h"
31
#include "gui.h"
32
32
33
_trainer trainer;
34
_mapper mapper;
35
33
BYTE map_init(void) {
36
BYTE map_init(void) {
34
	BYTE i;
37
	BYTE i;
35
	/*
38
	/*
(-)puNES-0.105.org/src/core/mappers.h (-4 / +4 lines)
Lines 263-274 typedef struct _mapper { Link Here
263
	BYTE *internal_struct[10];
263
	BYTE *internal_struct[10];
264
	WORD internal_struct_size[10];
264
	WORD internal_struct_size[10];
265
} _mapper;
265
} _mapper;
266
266
typedef struct _trainer {
267
struct _trainer {
268
	BYTE data[512];
267
	BYTE data[512];
269
} trainer;
268
} _trainer;
270
269
271
_mapper mapper;
270
extern _trainer trainer;
271
extern _mapper mapper;
272
272
273
BYTE map_init(void);
273
BYTE map_init(void);
274
void map_quit(void);
274
void map_quit(void);
(-)puNES-0.105.org/src/core/mem_map.h (-19 / +18 lines)
Lines 82-97 enum mirroring_type { Link Here
82
82
83
#define chr_ram_size() info.chr.rom[0].banks_8k << 13
83
#define chr_ram_size() info.chr.rom[0].banks_8k << 13
84
84
85
#if defined (__cplusplus)
85
typedef struct _mmcpu {
86
#define EXTERNC extern "C"
87
#else
88
#define EXTERNC
89
#endif
90
91
EXTERNC struct _mmcpu {
92
	BYTE ram[0x800];   // Mirrored four times
86
	BYTE ram[0x800];   // Mirrored four times
93
} mmcpu;
87
} _mmcpu;
94
EXTERNC struct _prg {
88
typedef struct _prg {
95
	struct _prg_chip {
89
	struct _prg_chip {
96
		size_t size;
90
		size_t size;
97
		BYTE *rom;
91
		BYTE *rom;
Lines 108-115 EXTERNC struct _prg { Link Here
108
	BYTE *ram_plus;    // PRG Ram extra
102
	BYTE *ram_plus;    // PRG Ram extra
109
	BYTE *ram_plus_8k;
103
	BYTE *ram_plus_8k;
110
	BYTE *ram_battery; // Battery RAM
104
	BYTE *ram_battery; // Battery RAM
111
} prg;
105
} _prg;
112
EXTERNC struct _chr {
106
typedef struct _chr {
113
	struct _chr_chip {
107
	struct _chr_chip {
114
		size_t size;
108
		size_t size;
115
		BYTE *rom;
109
		BYTE *rom;
Lines 122-136 EXTERNC struct _chr { Link Here
122
		size_t size;
116
		size_t size;
123
		BYTE *data;
117
		BYTE *data;
124
	} extra;
118
	} extra;
125
} chr;
119
} _chr;
126
EXTERNC struct _nametables {
120
typedef struct _nametables {
127
	BYTE data[0x1000];
121
	BYTE data[0x1000];
128
	BYTE *bank_1k[4];
122
	BYTE *bank_1k[4];
129
} ntbl;
123
} _nametables;
130
EXTERNC struct _mmap_palette {
124
typedef struct _mmap_palette {
131
	BYTE color[0x20];
125
	BYTE color[0x20];
132
} mmap_palette;
126
} _mmap_palette;
133
EXTERNC struct _oam {
127
typedef struct _oam {
134
	BYTE data[256];
128
	BYTE data[256];
135
	BYTE *element[64];
129
	BYTE *element[64];
136
	BYTE plus[32];
130
	BYTE plus[32];
Lines 138-145 EXTERNC struct _oam { Link Here
138
	// unlimited sprites
132
	// unlimited sprites
139
	BYTE plus_unl[224];
133
	BYTE plus_unl[224];
140
	BYTE *ele_plus_unl[56];
134
	BYTE *ele_plus_unl[56];
141
} oam;
135
} _oam;
142
136
143
#undef EXTERNC
137
extern _mmcpu mmcpu;
138
extern _prg prg;
139
extern _chr chr;
140
extern _nametables ntbl;
141
extern _mmap_palette mmap_palette;
142
extern _oam oam;
144
143
145
#endif /* MEM_MAP_H_ */
144
#endif /* MEM_MAP_H_ */
(-)puNES-0.105.org/src/core/nsf.c (-2 / +2 lines)
Lines 33-44 Link Here
33
#include "mappers/mapper_VRC7_snd.h"
33
#include "mappers/mapper_VRC7_snd.h"
34
#include "emu.h"
34
#include "emu.h"
35
#include "video/gfx.h"
35
#include "video/gfx.h"
36
#include "conf.h"
37
#include "clock.h"
36
#include "clock.h"
38
#include "info.h"
37
#include "info.h"
39
#include "vs_system.h"
38
#include "vs_system.h"
40
#include "ppu.h"
39
#include "ppu.h"
41
#include "apu.h"
42
#include "cpu.h"
40
#include "cpu.h"
43
#include "fds.h"
41
#include "fds.h"
44
#include "conf.h"
42
#include "conf.h"
Lines 125-130 typedef struct _nsf_option_data { Link Here
125
	int x1, x2;
123
	int x1, x2;
126
} _nsf_option_data;
124
} _nsf_option_data;
127
125
126
_nsf nsf;
127
128
extern void cpu_wr_mem(WORD address, BYTE value);
128
extern void cpu_wr_mem(WORD address, BYTE value);
129
static void nsf_effect_set_coords(_nsf_effect_coords *coords, int x, int y, int w, int h);
129
static void nsf_effect_set_coords(_nsf_effect_coords *coords, int x, int y, int w, int h);
130
static void nsf_effect_raw(BYTE solid);
130
static void nsf_effect_raw(BYTE solid);
(-)puNES-0.105.org/src/core/nsfe.c (-1 lines)
Lines 28-34 Link Here
28
#include "gui.h"
28
#include "gui.h"
29
#include "audio/blipbuf.h"
29
#include "audio/blipbuf.h"
30
#include "patcher.h"
30
#include "patcher.h"
31
#include "external_calls.h"
32
31
33
enum nsfe_phase_type { NSFE_COUNT, NSFE_READ };
32
enum nsfe_phase_type { NSFE_COUNT, NSFE_READ };
34
enum nsfe_flags {
33
enum nsfe_flags {
(-)puNES-0.105.org/src/core/nsf.h (-11 / +12 lines)
Lines 113-126 typedef struct _nsf_effect_coords { Link Here
113
	int w, h;
113
	int w, h;
114
	int y_center;
114
	int y_center;
115
} _nsf_effect_coords;
115
} _nsf_effect_coords;
116
116
typedef struct _nsf {
117
#if defined (__cplusplus)
118
#define EXTERNC extern "C"
119
#else
120
#define EXTERNC
121
#endif
122
123
EXTERNC struct _nsf {
124
	BYTE enabled;
117
	BYTE enabled;
125
	BYTE version;
118
	BYTE version;
126
	BYTE draw_mask_frames;
119
	BYTE draw_mask_frames;
Lines 212-222 EXTERNC struct _nsf { Link Here
212
	_nsf_text_scroll scroll_title_song;
205
	_nsf_text_scroll scroll_title_song;
213
	_nsf_text_curtain curtain_title_song;
206
	_nsf_text_curtain curtain_title_song;
214
	_nsf_text_curtain curtain_info;
207
	_nsf_text_curtain curtain_info;
215
} nsf;
208
} _nsf;
216
209
217
#if defined (_NSF_STATIC_)
210
#if defined (_NSF_STATIC_)
218
EXTERNC static char nsf_default_label[4] = {"<?>"};
211
static char nsf_default_label[4] = {"<?>"};
219
EXTERNC static const BYTE nsf_routine[17] = {
212
static const BYTE nsf_routine[17] = {
220
//	0     1
213
//	0     1
221
	0xA9, 0x00,       // 0x2500 : LDA [current song]
214
	0xA9, 0x00,       // 0x2500 : LDA [current song]
222
//	2     3
215
//	2     3
Lines 234-239 EXTERNC static const BYTE nsf_routine[17 Link Here
234
};
227
};
235
#endif
228
#endif
236
229
230
extern _nsf nsf;
231
232
#if defined (__cplusplus)
233
#define EXTERNC extern "C"
234
#else
235
#define EXTERNC
236
#endif
237
237
EXTERNC void nsf_init(void);
238
EXTERNC void nsf_init(void);
238
EXTERNC void nsf_quit(void);
239
EXTERNC void nsf_quit(void);
239
EXTERNC void nsf_reset(void);
240
EXTERNC void nsf_reset(void);
(-)puNES-0.105.org/src/core/overscan.c (-1 / +3 lines)
Lines 16-25 Link Here
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
17
 */
18
18
19
#include "common.h"
20
#include "overscan.h"
19
#include "overscan.h"
21
#include "video/gfx.h"
20
#include "video/gfx.h"
22
21
22
_overscan_borders overscan_borders[2];
23
_overscan overscan;
24
23
BYTE overscan_set_mode(BYTE mode) {
25
BYTE overscan_set_mode(BYTE mode) {
24
	_overscan_borders save = (*overscan.borders);
26
	_overscan_borders save = (*overscan.borders);
25
27
(-)puNES-0.105.org/src/core/overscan.h (-8 / +8 lines)
Lines 25-36 enum overscan_limit { Link Here
25
	OVERSCAN_BORDERS_MIN = 0, OVERSCAN_BORDERS_MAX = 17
25
	OVERSCAN_BORDERS_MIN = 0, OVERSCAN_BORDERS_MAX = 17
26
};
26
};
27
27
28
typedef struct {
28
typedef struct _overscan_borders {
29
	BYTE up;
29
	BYTE up;
30
	BYTE down;
30
	BYTE down;
31
	BYTE left;
31
	BYTE left;
32
	BYTE right;
32
	BYTE right;
33
} _overscan_borders;
33
} _overscan_borders;
34
typedef struct _overscan {
35
	BYTE enabled;
36
	_overscan_borders *borders;
37
} _overscan;
38
39
extern _overscan_borders overscan_borders[2];
40
extern _overscan overscan;
34
41
35
#if defined (__cplusplus)
42
#if defined (__cplusplus)
36
#define EXTERNC extern "C"
43
#define EXTERNC extern "C"
Lines 38-50 typedef struct { Link Here
38
#define EXTERNC
45
#define EXTERNC
39
#endif
46
#endif
40
47
41
EXTERNC struct overscan {
42
	BYTE enabled;
43
	_overscan_borders *borders;
44
} overscan;
45
46
EXTERNC _overscan_borders overscan_borders[2];
47
48
EXTERNC BYTE overscan_set_mode(BYTE mode);
48
EXTERNC BYTE overscan_set_mode(BYTE mode);
49
49
50
#undef EXTERNC
50
#undef EXTERNC
(-)puNES-0.105.org/src/core/palette.c (-1 / +3 lines)
Lines 18-26 Link Here
18
18
19
#include <stdio.h>
19
#include <stdio.h>
20
#include <string.h>
20
#include <string.h>
21
#include "common.h"
22
#include "palette.h"
21
#include "palette.h"
23
22
23
_color_RGB palette_base_file[64];
24
_palette_RGB palette_RGB;
25
24
void palette_save_on_file(const uTCHAR *file) {
26
void palette_save_on_file(const uTCHAR *file) {
25
	FILE *fp;
27
	FILE *fp;
26
28
(-)puNES-0.105.org/src/core/palette.h (-7 / +10 lines)
Lines 19-24 Link Here
19
#ifndef PALETTE_H_
19
#ifndef PALETTE_H_
20
#define PALETTE_H_
20
#define PALETTE_H_
21
21
22
#include "common.h"
23
22
#define NUM_COLORS 512
24
#define NUM_COLORS 512
23
25
24
enum palettes_types {
26
enum palettes_types {
Lines 37-42 typedef struct _color_RGB { Link Here
37
	BYTE g;
39
	BYTE g;
38
	BYTE b;
40
	BYTE b;
39
} _color_RGB;
41
} _color_RGB;
42
typedef struct _palette_RGB {
43
	_color_RGB *in_use;
44
	_color_RGB noswap[NUM_COLORS];
45
	_color_RGB swapped[NUM_COLORS];
46
} _palette_RGB;
47
48
extern _color_RGB palette_base_file[64];
49
extern _palette_RGB palette_RGB;
40
50
41
#if defined (__cplusplus)
51
#if defined (__cplusplus)
42
#define EXTERNC extern "C"
52
#define EXTERNC extern "C"
Lines 44-56 typedef struct _color_RGB { Link Here
44
#define EXTERNC
54
#define EXTERNC
45
#endif
55
#endif
46
56
47
EXTERNC _color_RGB palette_base_file[64];
48
EXTERNC struct _palette_RGB {
49
	_color_RGB *in_use;
50
	_color_RGB noswap[NUM_COLORS];
51
	_color_RGB swapped[NUM_COLORS];
52
} palette_RGB;
53
54
EXTERNC void palette_save_on_file(const uTCHAR *file);
57
EXTERNC void palette_save_on_file(const uTCHAR *file);
55
EXTERNC BYTE palette_load_from_file(const uTCHAR *file);
58
EXTERNC BYTE palette_load_from_file(const uTCHAR *file);
56
59
(-)puNES-0.105.org/src/core/patcher.c (-1 / +2 lines)
Lines 26-32 Link Here
26
#include "emu.h"
26
#include "emu.h"
27
#include "gui.h"
27
#include "gui.h"
28
#include "text.h"
28
#include "text.h"
29
#include "uncompress.h"
30
#include "cheat.h"
29
#include "cheat.h"
31
#include "conf.h"
30
#include "conf.h"
32
31
Lines 45-50 static BYTE patcher_ips(_rom_mem *patch, Link Here
45
static BYTE patcher_bps_decode(_rom_mem *patch, size_t *size);
44
static BYTE patcher_bps_decode(_rom_mem *patch, size_t *size);
46
static BYTE patcher_bps(_rom_mem *patch, _rom_mem *rom);
45
static BYTE patcher_bps(_rom_mem *patch, _rom_mem *rom);
47
46
47
_patcher patcher;
48
48
void patcher_init(void) {
49
void patcher_init(void) {
49
	memset(&patcher, 0x00, sizeof(patcher));
50
	memset(&patcher, 0x00, sizeof(patcher));
50
}
51
}
(-)puNES-0.105.org/src/core/patcher.h (-5 / +7 lines)
Lines 21-37 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
typedef struct _patcher {
25
	uTCHAR *file;
26
	BYTE patched;
27
} _patcher;
28
29
extern _patcher patcher;
30
24
#if defined (__cplusplus)
31
#if defined (__cplusplus)
25
#define EXTERNC extern "C"
32
#define EXTERNC extern "C"
26
#else
33
#else
27
#define EXTERNC
34
#define EXTERNC
28
#endif
35
#endif
29
36
30
EXTERNC struct _patcher {
31
	uTCHAR *file;
32
	BYTE patched;
33
} patcher;
34
35
EXTERNC void patcher_init(void);
37
EXTERNC void patcher_init(void);
36
EXTERNC void patcher_quit(void);
38
EXTERNC void patcher_quit(void);
37
EXTERNC BYTE patcher_ctrl_if_exist(uTCHAR *patch);
39
EXTERNC BYTE patcher_ctrl_if_exist(uTCHAR *patch);
(-)puNES-0.105.org/src/core/ppu.c (+16 lines)
Lines 170-175 static const BYTE palette_init[0x20] = { Link Here
170
	0x08, 0x3A, 0x00, 0x02, 0x00, 0x20, 0x2C, 0x08
170
	0x08, 0x3A, 0x00, 0x02, 0x00, 0x20, 0x2C, 0x08
171
};
171
};
172
172
173
_ppu ppu;
174
_screen screen;
175
_ppu_openbus ppu_openbus;
176
_r2000 r2000;
177
_r2001 r2001;
178
_r2002 r2002;
179
_r2006 r2006;
180
_r2xxx r2003, r2004, r2007;
181
_spr_evaluate spr_ev;
182
_spr sprite[8], sprite_plus[8];
183
_spr_evaluate spr_ev_unl;
184
_spr sprite_unl[56], sprite_plus_unl[56];
185
_tile tile_render, tile_fetch;
186
_ppu_sclines ppu_sclines;
187
_overclock overclock;
188
173
void ppu_init(void) {
189
void ppu_init(void) {
174
	memset(&screen, 0x00, sizeof(screen));
190
	memset(&screen, 0x00, sizeof(screen));
175
}
191
}
(-)puNES-0.105.org/src/core/ppu.h (-24 / +25 lines)
Lines 257-276 typedef struct _tile { Link Here
257
	WORD l_byte;
257
	WORD l_byte;
258
	DBWORD h_byte;
258
	DBWORD h_byte;
259
} _tile;
259
} _tile;
260
260
typedef struct _ppu_sclines {
261
#if defined (__cplusplus)
262
#define EXTERNC extern "C"
263
#else
264
#define EXTERNC
265
#endif
266
267
EXTERNC struct _ppu_sclines {
268
	WORD total;
261
	WORD total;
269
	WORD frame;
262
	WORD frame;
270
	WORD vint;
263
	WORD vint;
271
	WORD vint_extra;
264
	WORD vint_extra;
272
} ppu_sclines;
265
} _ppu_sclines;
273
EXTERNC struct _overclock {
266
typedef struct _overclock {
274
	BYTE in_extra_sclines;
267
	BYTE in_extra_sclines;
275
	BYTE DMC_in_use;
268
	BYTE DMC_in_use;
276
	struct _extra_sclines {
269
	struct _extra_sclines {
Lines 278-298 EXTERNC struct _overclock { Link Here
278
		WORD pr;
271
		WORD pr;
279
		WORD total;
272
		WORD total;
280
	} sclines;
273
	} sclines;
281
} overclock;
274
} _overclock;
282
275
283
EXTERNC _ppu ppu;
276
extern _ppu ppu;
284
EXTERNC _screen screen;
277
extern _screen screen;
285
EXTERNC _ppu_openbus ppu_openbus;
278
extern _ppu_openbus ppu_openbus;
286
EXTERNC _r2000 r2000;
279
extern _r2000 r2000;
287
EXTERNC _r2001 r2001;
280
extern _r2001 r2001;
288
EXTERNC _r2002 r2002;
281
extern _r2002 r2002;
289
EXTERNC _r2006 r2006;
282
extern _r2006 r2006;
290
EXTERNC _r2xxx r2003, r2004, r2007;
283
extern _r2xxx r2003, r2004, r2007;
291
EXTERNC _spr_evaluate spr_ev;
284
extern _spr_evaluate spr_ev;
292
EXTERNC _spr sprite[8], sprite_plus[8];
285
extern _spr sprite[8], sprite_plus[8];
293
EXTERNC _spr_evaluate spr_ev_unl;
286
extern _spr_evaluate spr_ev_unl;
294
EXTERNC _spr sprite_unl[56], sprite_plus_unl[56];
287
extern _spr sprite_unl[56], sprite_plus_unl[56];
295
EXTERNC _tile tile_render, tile_fetch;
288
extern _tile tile_render, tile_fetch;
289
extern _ppu_sclines ppu_sclines;
290
extern _overclock overclock;
291
292
#if defined (__cplusplus)
293
#define EXTERNC extern "C"
294
#else
295
#define EXTERNC
296
#endif
296
297
297
EXTERNC void ppu_init(void);
298
EXTERNC void ppu_init(void);
298
EXTERNC void ppu_quit(void);
299
EXTERNC void ppu_quit(void);
(-)puNES-0.105.org/src/core/rewind.c (-2 / +2 lines)
Lines 24-36 Link Here
24
#include "mem_map.h"
24
#include "mem_map.h"
25
#include "cpu.h"
25
#include "cpu.h"
26
#include "ppu.h"
26
#include "ppu.h"
27
#include "apu.h"
28
#include "mappers.h"
27
#include "mappers.h"
29
#include "irqA12.h"
28
#include "irqA12.h"
30
#include "irql2f.h"
29
#include "irql2f.h"
31
#include "fds.h"
30
#include "fds.h"
32
#include "gui.h"
31
#include "gui.h"
33
#include "input.h"
34
#include "clock.h"
32
#include "clock.h"
35
#include "tas.h"
33
#include "tas.h"
36
#include "emu_thread.h"
34
#include "emu_thread.h"
Lines 138-143 struct _rewind_internal { Link Here
138
	} size;
136
	} size;
139
} rwint;
137
} rwint;
140
138
139
_rewind rwnd;
140
141
BYTE rewind_init(void) {
141
BYTE rewind_init(void) {
142
	// in caso di riavvio del rewind
142
	// in caso di riavvio del rewind
143
	rewind_quit();
143
	rewind_quit();
(-)puNES-0.105.org/src/core/rewind.c.orig (+707 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#include <stdio.h>
20
#include <string.h>
21
#include <stdlib.h>
22
#include "rewind.h"
23
#include "info.h"
24
#include "mem_map.h"
25
#include "cpu.h"
26
#include "ppu.h"
27
#include "apu.h"
28
#include "mappers.h"
29
#include "irqA12.h"
30
#include "irql2f.h"
31
#include "fds.h"
32
#include "gui.h"
33
#include "input.h"
34
#include "clock.h"
35
#include "tas.h"
36
#include "emu_thread.h"
37
#include "video/gfx_thread.h"
38
#include "clock.h"
39
#include "conf.h"
40
#include "audio/snd.h"
41
42
enum rewind_misc {
43
	REWIND_CHUNK_TYPE_SEGMENT,
44
	REWIND_CHUNK_TYPE_CHUNK_BUFFER,
45
	REWIND_SNAPS_FOR_CHUNK = 15,
46
	REWIND_SNAPS_FOR_FACTOR = 4
47
};
48
49
#define rewind_on_struct(_mode, _strct, _size_buff)\
50
	switch (_mode) {\
51
	case REWIND_OP_SAVE:\
52
		memcpy(snap->data + index, &_strct, sizeof(_strct));\
53
		index += sizeof(_strct);\
54
		break;\
55
	case REWIND_OP_READ:\
56
		memcpy(&_strct, snap->data + index, sizeof(_strct));\
57
		index += sizeof(_strct);\
58
		break;\
59
	case REWIND_OP_COUNT:\
60
		rwint.size._size_buff += sizeof(_strct);\
61
		break;\
62
	}
63
#define rewind_on_mem(_mode, _mem, _size, _size_buff)\
64
	switch (_mode) {\
65
	case REWIND_OP_SAVE:\
66
		memcpy(snap->data + index, _mem, _size);\
67
		index += _size;\
68
		break;\
69
	case REWIND_OP_READ:\
70
		memcpy(_mem, snap->data + index, _size);\
71
		index += _size;\
72
		break;\
73
	case REWIND_OP_COUNT:\
74
		rwint.size._size_buff += _size;\
75
		break;\
76
	}
77
78
typedef struct _rewind_index {
79
	int32_t segment;
80
	int32_t chunk;
81
	int32_t snap;
82
} _rewind_index;
83
typedef struct _rewind_snapshoot {
84
	_rewind_index index;
85
	BYTE *data;
86
} _rewind_snapshoot;
87
typedef struct _rewind_chunk {
88
	BYTE type;
89
	BYTE *data;
90
	_rewind_snapshoot *snaps;
91
} _rewind_chunk;
92
93
INLINE static BYTE rewind_is_disabled(void);
94
INLINE static void rewind_increment_count_chunks(void);
95
INLINE static void rewind_update_chunk_snaps( _rewind_chunk *chunk, int32_t chunk_index, BYTE *src);
96
INLINE static void rewind_operation(BYTE mode, BYTE save_input, _rewind_snapshoot *snap);
97
INLINE static void rewind_free_chunk(_rewind_chunk *chunk);
98
INLINE static void rewind_execute_frame(void);
99
INLINE static char *rewind_convert_time_in_text(char *txt, size_t size, char *color, int32_t counter);
100
101
static BYTE _rewind_frames(int32_t frames_to_rewind, BYTE exec_last_frame);
102
103
struct _rewind_internal {
104
	uTCHAR file_name[LENGTH_FILE_NAME_LONG];
105
	FILE *file;
106
107
	int32_t chunks_for_segment;
108
	int32_t first_valid_snap;
109
	int32_t snap_cursor;
110
111
	_rewind_chunk segment;
112
	_rewind_chunk cbuffer;
113
114
	_rewind_index index;
115
116
	struct _rewind_info_max_buffered {
117
		int32_t segments;
118
		int32_t snaps;
119
	} max_buffered;
120
	struct _rewind_info_range {
121
		struct _rewind_info_cunk_range {
122
			int32_t first;
123
			int32_t last;
124
		} chunk;
125
	} range;
126
	struct _rewind_info_count {
127
		int32_t segments;
128
		int32_t chunks;
129
		int32_t snaps;
130
	} count;
131
	struct _rewind_info_size {
132
		size_t keyframe;
133
		size_t screen;
134
		size_t input;
135
		size_t chunk;
136
		size_t first_chunk;
137
		size_t total;
138
	} size;
139
} rwint;
140
141
BYTE rewind_init(void) {
142
	// in caso di riavvio del rewind
143
	rewind_quit();
144
145
	memset(&rwnd, 0, sizeof(rwnd));
146
	memset(&rwint, 0, sizeof(rwint));
147
148
	rwint.count.snaps = -1;
149
	rwint.chunks_for_segment = (machine.fps * 60) / REWIND_SNAPS_FOR_CHUNK;
150
151
	{
152
		size_t size = sizeof(_rewind_snapshoot) * REWIND_SNAPS_FOR_CHUNK;
153
154
		if (rewind_is_disabled() == FALSE) {
155
			if ((rwint.segment.snaps = (_rewind_snapshoot *)malloc(size)) == NULL) {
156
				fprintf(stderr, "rewind : Out of memory\n");
157
				return (EXIT_ERROR);
158
			}
159
			memset(rwint.segment.snaps, 0, size);
160
		}
161
162
		if ((rwint.cbuffer.snaps = (_rewind_snapshoot *)malloc(size)) == NULL) {
163
			fprintf(stderr, "rewind : Out of memory\n");
164
			return (EXIT_ERROR);
165
		}
166
		memset(rwint.cbuffer.snaps, 0, size);
167
	}
168
169
	{
170
		_rewind_snapshoot snap;
171
172
		snap.index.chunk = 0;
173
		snap.index.snap = 0;
174
		rewind_operation(REWIND_OP_COUNT, TRUE, &snap);
175
	}
176
177
	rwint.size.chunk = rwint.size.keyframe + (rwint.size.input * REWIND_SNAPS_FOR_CHUNK);
178
	rwint.size.first_chunk = rwint.size.screen + rwint.size.chunk;
179
	rwint.size.total = rwint.size.screen + (rwint.size.chunk * rwint.chunks_for_segment);
180
181
	if (rewind_is_disabled() == FALSE) {
182
		if ((rwint.segment.data = (BYTE *)malloc(rwint.size.total)) == NULL) {
183
			fprintf(stderr, "rewind : Out of memory\n");
184
			return (EXIT_ERROR);
185
		}
186
		memset(rwint.segment.data, 0, rwint.size.chunk);
187
		rwint.segment.type = REWIND_CHUNK_TYPE_SEGMENT;
188
		rewind_update_chunk_snaps(&rwint.segment, 0, NULL);
189
	}
190
	if ((rwint.cbuffer.data = (BYTE *)malloc(rwint.size.first_chunk)) == NULL) {
191
		fprintf(stderr, "rewind : Out of memory\n");
192
		return (EXIT_ERROR);
193
	}
194
	memset(rwint.cbuffer.data, 0, rwint.size.first_chunk);
195
	rwint.cbuffer.type = REWIND_CHUNK_TYPE_CHUNK_BUFFER;
196
	rewind_update_chunk_snaps(&rwint.cbuffer, 0, NULL);
197
198
	// (se non ho limiti allora devo impostare rwint.max_buffered.segments a 0)
199
	// lo incremento di 1 perche' se, per esempio, sono 3 i segmenti che devono
200
	// sempre essere bufferizzati, quando sto trattando il segmento 3 (cioe' il quarto),
201
	// chunk 0, snap 15, per poter fare il rewindw completo di 3 segmenti devo caricare
202
	// il segmento 0, chunk 0, snap 15 percio' devo sempre bufferizzarne 3 + 1.
203
	switch (cfg->rewind_minutes) {
204
		case RWND_0_MINUTES:
205
			rwint.max_buffered.segments = 1;
206
			break;
207
		case RWND_2_MINUTES:
208
			rwint.max_buffered.segments = 2 + 1;
209
			break;
210
		case RWND_5_MINUTES:
211
			rwint.max_buffered.segments = 5 + 1;
212
			break;
213
		default:
214
		case RWND_15_MINUTES:
215
			rwint.max_buffered.segments = 15 + 1;
216
			break;
217
		case RWND_30_MINUTES:
218
			rwint.max_buffered.segments = 30 + 1;
219
			break;
220
		case RWND_60_MINUTES:
221
			rwint.max_buffered.segments = 60 + 1;
222
			break;
223
		case RWND_UNLIMITED_MINUTES:
224
			rwint.max_buffered.segments = 0;
225
			break;
226
	}
227
228
	if (rwint.max_buffered.segments > 0) {
229
		rwint.max_buffered.snaps = (rwint.max_buffered.segments - 1) * rwint.chunks_for_segment * REWIND_SNAPS_FOR_CHUNK;
230
	}
231
232
	rwint.range.chunk.first = 0;
233
	rwint.range.chunk.last = rwint.range.chunk.first + rwint.chunks_for_segment;
234
235
	rwint.index.segment = 0;
236
	rwint.index.chunk = 0;
237
	rwint.index.snap = -1;
238
239
	// creo il file temporaneo
240
	if (rewind_is_disabled() == FALSE) {
241
		uTCHAR basename[255], *last_dot;;
242
243
		gui_utf_basename(info.rom.file, basename, usizeof(basename));
244
245
		// rintraccio l'ultimo '.' nel nome
246
		if ((last_dot = ustrrchr(basename, uL('.')))) {
247
			// elimino l'estensione
248
			(*last_dot) = 0x00;
249
		};
250
251
#if defined (__WIN32__)
252
		usnprintf(rwint.file_name, usizeof(rwint.file_name), uL("" uPERCENTs uPERCENTs "_" uPERCENTs ".rwd"), gui.ostmp,
253
			basename, emu_rand_str());
254
#else
255
		usnprintf(rwint.file_name, usizeof(rwint.file_name), uL("" uPERCENTs "/" uPERCENTs "_" uPERCENTs ".rwd"), gui.ostmp,
256
			basename, emu_rand_str());
257
#endif
258
259
		if ((rwint.file = ufopen(rwint.file_name, uL("w+b"))) == NULL) {
260
			return (EXIT_ERROR);
261
		}
262
	}
263
264
	return (EXIT_OK);
265
}
266
void rewind_quit(void) {
267
	rewind_free_chunk(&rwint.segment);
268
	rewind_free_chunk(&rwint.cbuffer);
269
	if (rwint.file) {
270
		fclose(rwint.file);
271
		rwint.file = NULL;
272
		if (emu_file_exist(rwint.file_name) == EXIT_OK) {
273
			uremove(rwint.file_name);
274
		}
275
	}
276
}
277
void rewind_snapshoot(void) {
278
	_rewind_snapshoot *snap;
279
280
	// se non ci sono rom caricate, non faccio niente
281
	if (rewind_is_disabled()) {
282
		return;
283
	}
284
285
	if (++rwint.index.snap == REWIND_SNAPS_FOR_CHUNK) {
286
		rwint.index.snap = 0;
287
		rewind_increment_count_chunks();
288
	}
289
290
	snap = rwint.segment.snaps + rwint.index.snap;
291
292
	snap->index.chunk = rwint.index.chunk;
293
	snap->index.snap = rwint.index.snap;
294
295
	rewind_operation(REWIND_OP_SAVE, TRUE, snap);
296
297
	rwint.count.snaps++;
298
299
	if (rwint.max_buffered.segments > 0) {
300
		int32_t first_valid_snap = rwint.count.snaps - rwint.max_buffered.snaps;
301
302
		if (first_valid_snap > rwint.first_valid_snap) {
303
			rwint.first_valid_snap = first_valid_snap;
304
		}
305
	}
306
}
307
void rewind_frames(int32_t frames_to_rewind) {
308
	if (_rewind_frames(frames_to_rewind, FALSE) == EXIT_OK) {
309
		if (tas.type != NOTAS) {
310
			tas_rewind(frames_to_rewind);
311
		}
312
	}
313
}
314
315
void rewind_save_state_snap(BYTE mode) {
316
	_rewind_snapshoot *snap = rwint.cbuffer.snaps;
317
318
	snap->index.segment = 0;
319
	snap->index.chunk = 0;
320
	snap->index.snap = 0;
321
322
	rewind_update_chunk_snaps(&rwint.cbuffer, 0, NULL);
323
324
	rewind_operation(mode, FALSE, snap);
325
}
326
327
void rewind_init_operation(void) {
328
	emu_thread_pause();
329
	gfx_thread_pause();
330
	ppu_draw_screen_pause();
331
332
	snd_playback_stop();
333
334
	rwint.snap_cursor = rwint.count.snaps;
335
336
	rwnd.active = TRUE;
337
	emu_ctrl_doublebuffer();
338
	gui_update();
339
340
	gfx_thread_continue();
341
}
342
void rewind_close_operation(void) {
343
	gfx_thread_pause();
344
345
	rwint.count.snaps = rwint.snap_cursor;
346
	rwint.count.segments = rwint.index.segment;
347
348
	rwnd.active = FALSE;
349
	emu_ctrl_doublebuffer();
350
	gui_update();
351
352
	snd_playback_start();
353
354
	ppu_draw_screen_continue();
355
	gfx_thread_continue();
356
	emu_thread_continue();
357
}
358
359
BYTE rewind_is_first_snap(void) {
360
	return (rwint.snap_cursor == 0);
361
}
362
BYTE rewind_is_last_snap(void) {
363
	return ((rwint.snap_cursor + 1) > rwint.count.snaps);
364
}
365
366
int32_t rewind_count_snaps(void) {
367
	return (rwint.count.snaps);
368
}
369
int32_t rewind_snap_cursor(void) {
370
	return (rwint.snap_cursor);
371
}
372
int32_t rewind_calculate_snap_cursor(int factor, BYTE direction) {
373
	int32_t snaps = factor * REWIND_SNAPS_FOR_FACTOR;
374
375
	if (direction == RWND_BACKWARD) {
376
		snaps = -snaps;
377
378
		if ((rwint.snap_cursor + snaps) < rwint.first_valid_snap) {
379
			snaps = -rwint.snap_cursor;
380
		}
381
	} else {
382
		if ((rwint.snap_cursor + snaps) > rwint.count.snaps) {
383
			snaps = (rwint.count.snaps - rwint.snap_cursor);
384
		}
385
	}
386
387
	return (snaps);
388
}
389
390
char *rewind_text_time_count_snaps(void) {
391
	static char txt[100];
392
393
	return (rewind_convert_time_in_text((char *)&txt, sizeof(txt), "[normal]", rwint.count.snaps));
394
}
395
char *rewind_text_time_snap_cursor(void) {
396
	static char txt[100];
397
398
	return (rewind_convert_time_in_text((char *)&txt, sizeof(txt), "[yellow]", rwint.snap_cursor));
399
}
400
char *rewind_text_time_backward(void) {
401
	static char txt[100];
402
403
	return (rewind_convert_time_in_text((char *)&txt, sizeof(txt), "[cyan]", rwint.count.snaps - rwint.snap_cursor));
404
}
405
406
INLINE static BYTE rewind_is_disabled(void) {
407
	return((info.no_rom | info.turn_off) || (cfg->rewind_minutes == RWND_0_MINUTES));
408
}
409
INLINE static void rewind_increment_count_chunks(void) {
410
	if (++rwint.index.chunk == rwint.chunks_for_segment) {
411
		int32_t segment_to_save = rwint.index.segment;
412
413
		if (rwint.max_buffered.segments > 0) {
414
			segment_to_save = rwint.index.segment % rwint.max_buffered.segments;
415
		}
416
417
		fseek(rwint.file, segment_to_save * rwint.size.total, SEEK_SET);
418
		fwrite(rwint.segment.data, rwint.size.total, 1, rwint.file);
419
		rwint.index.chunk = 0;
420
		rwint.range.chunk.first = rwint.range.chunk.last;
421
		rwint.range.chunk.last = rwint.range.chunk.first + rwint.chunks_for_segment;
422
		rwint.index.segment = ++rwint.count.segments;
423
	}
424
	rewind_update_chunk_snaps(&rwint.segment, rwint.index.chunk, NULL);
425
	rwint.count.chunks++;
426
}
427
INLINE static void rewind_update_chunk_snaps( _rewind_chunk *chunk, int32_t chunk_index, BYTE *src) {
428
	BYTE *start;
429
	uint32_t i;
430
431
	if (chunk_index == 0) {
432
		start = chunk->data + rwint.size.screen + (rwint.size.chunk * chunk_index);
433
		chunk->snaps->data = chunk->data;
434
	} else {
435
		if (chunk->type == REWIND_CHUNK_TYPE_SEGMENT) {
436
			start = chunk->data + rwint.size.screen + (rwint.size.chunk * chunk_index);
437
		} else {
438
			start = chunk->data;
439
		}
440
		chunk->snaps->data = start;
441
	}
442
443
	for (i = 1; i < REWIND_SNAPS_FOR_CHUNK; i++) {
444
		(chunk->snaps + i)->data = (start + rwint.size.keyframe) + (rwint.size.input * i);
445
	}
446
447
	if (src != NULL) {
448
		if (chunk_index == 0) {
449
			memcpy(chunk->data, src, rwint.size.first_chunk);
450
		} else {
451
			memcpy(start, src, rwint.size.chunk);
452
		}
453
	}
454
}
455
INLINE static void rewind_operation(BYTE mode, BYTE save_input, _rewind_snapshoot *snap) {
456
	size_t index = 0;
457
	BYTE i;
458
459
	if (snap->index.snap == 0) {
460
		if (snap->index.chunk == 0) {
461
			rewind_on_mem(mode, screen.rd->data, screen_size(), screen);
462
		}
463
464
		// CPU
465
		rewind_on_struct(mode, cpu, keyframe);
466
		rewind_on_struct(mode, irq, keyframe);
467
		rewind_on_struct(mode, nmi, keyframe);
468
469
		// PPU
470
		rewind_on_struct(mode, ppu, keyframe);
471
		rewind_on_struct(mode, ppu_openbus, keyframe);
472
		rewind_on_struct(mode, r2000, keyframe);
473
		rewind_on_struct(mode, r2001, keyframe);
474
		rewind_on_struct(mode, r2002, keyframe);
475
		rewind_on_struct(mode, r2003, keyframe);
476
		rewind_on_struct(mode, r2004, keyframe);
477
		rewind_on_struct(mode, r2006, keyframe);
478
		rewind_on_struct(mode, r2007, keyframe);
479
		rewind_on_struct(mode, spr_ev, keyframe);
480
		rewind_on_struct(mode, sprite, keyframe);
481
		rewind_on_struct(mode, sprite_plus, keyframe);
482
		rewind_on_struct(mode, tile_render, keyframe);
483
		rewind_on_struct(mode, tile_fetch, keyframe);
484
485
		// APU
486
		rewind_on_struct(mode, apu, keyframe);
487
		rewind_on_struct(mode, r4011, keyframe);
488
		rewind_on_struct(mode, r4015, keyframe);
489
		rewind_on_struct(mode, r4017, keyframe);
490
		rewind_on_struct(mode, S1, keyframe);
491
		rewind_on_struct(mode, S2, keyframe);
492
		rewind_on_struct(mode, TR, keyframe);
493
		rewind_on_struct(mode, NS, keyframe);
494
		rewind_on_struct(mode, DMC, keyframe);
495
496
		// mem map
497
		rewind_on_struct(mode, mmcpu, keyframe);
498
		rewind_on_struct(mode, prg, keyframe);
499
		rewind_on_mem(mode, prg.ram.data, prg.ram.size, keyframe);
500
		if (prg.ram_plus) {
501
			rewind_on_mem(mode, prg.ram_plus, prg_ram_plus_size(), keyframe);
502
		}
503
		rewind_on_struct(mode, chr, keyframe);
504
		if (mapper.write_vram) {
505
			rewind_on_mem(mode, chr_chip(0), chr_ram_size(), keyframe);
506
		}
507
		if (chr.extra.size) {
508
			rewind_on_mem(mode, chr.extra.data, chr.extra.size, keyframe);
509
		}
510
		rewind_on_struct(mode, ntbl, keyframe);
511
		rewind_on_struct(mode, mmap_palette, keyframe);
512
		rewind_on_struct(mode, oam, keyframe);
513
514
		// mapper
515
		rewind_on_struct(mode, mapper, keyframe);
516
		for (i = 0; i < LENGTH(mapper.internal_struct); i++) {
517
			if (mapper.internal_struct[i]) {
518
				rewind_on_mem(mode, mapper.internal_struct[i], mapper.internal_struct_size[i], keyframe);
519
			}
520
		}
521
522
		// irqA12
523
		if (irqA12.present) {
524
			rewind_on_struct(mode, irqA12, keyframe);
525
		}
526
527
		// irql2f
528
		if (irql2f.present) {
529
			rewind_on_struct(mode, irql2f, keyframe);
530
		}
531
532
		// FDS
533
		if (fds.info.enabled) {
534
			BYTE old_side_inserted = fds.drive.side_inserted;
535
536
			rewind_on_struct(mode, fds.drive, keyframe);
537
			rewind_on_struct(mode, fds.snd, keyframe);
538
			rewind_on_struct(mode, fds.info.last_operation, keyframe);
539
540
			// in caso di ripristino di una snapshot, se era caricato
541
			// un'altro side del disco, devo ricaricarlo.
542
			if ((mode == REWIND_OP_READ) && (old_side_inserted != fds.drive.side_inserted)) {
543
				fds_disk_op(FDS_DISK_SELECT_FROM_REWIND, fds.drive.side_inserted);
544
				gui_update();
545
			}
546
		}
547
	}
548
549
	// input
550
	if (save_input == TRUE) {
551
		// standard controller
552
		for (i = PORT1; i < PORT_MAX; i++) {
553
			rewind_on_struct(mode, port[i].type_pad, input);
554
			rewind_on_struct(mode, port[i].index, input);
555
			rewind_on_struct(mode, port[i].data, input);
556
			rewind_on_struct(mode, port[i].input, input);
557
			rewind_on_struct(mode, port[i].turbo, input);
558
		}
559
560
		// zapper, mouse, arkanoid, oeka_kids_tablet
561
		rewind_on_struct(mode, gmouse.x, input);
562
		rewind_on_struct(mode, gmouse.y, input);
563
		rewind_on_struct(mode, gmouse.left, input);
564
		rewind_on_struct(mode, gmouse.right, input);
565
566
		rewind_on_struct(mode, tas.total_lag_frames, input);
567
	}
568
}
569
INLINE static void rewind_free_chunk(_rewind_chunk *chunk) {
570
	if (chunk->snaps) {
571
		free(chunk->snaps);
572
		chunk->snaps = NULL;
573
	}
574
	if (chunk->data) {
575
		free(chunk->data);
576
		chunk->data = NULL;
577
	}
578
}
579
INLINE static void rewind_execute_frame(void) {
580
	if (info.frame_status == FRAME_FINISHED) {
581
		info.frame_status = FRAME_STARTED;
582
	}
583
584
	while (info.frame_status == FRAME_STARTED) {
585
		cpu_exe_op();
586
	}
587
}
588
INLINE static char *rewind_convert_time_in_text(char *txt, size_t size, char *color, int32_t counter) {
589
	int32_t seconds, ms, s, m, h;
590
591
	seconds = counter / machine.fps;
592
	h = (seconds / 3600);
593
	m = (seconds -(3600 * h)) / 60;
594
	s = (seconds -(3600 * h) - (m * 60));
595
	ms = (counter % machine.fps) * (1000 / machine.fps);
596
597
	memset(txt, 0, size);
598
	snprintf(txt, size, "%s%d[normal]:%s%02d[normal]:%s%02d[normal].%s%03d[normal]", color, h, color, m, color, s, color, ms);
599
600
	return (txt);
601
}
602
603
static BYTE _rewind_frames(int32_t frames_to_rewind, BYTE exec_last_frame) {
604
	int32_t cursor, segment, chunk, snaps;
605
	_rewind_snapshoot *snap = NULL;
606
	_rewind_index index;
607
	BYTE *src;
608
609
	cursor = rwint.snap_cursor + frames_to_rewind;
610
611
	if (frames_to_rewind < 0) {
612
		// backward
613
		if (cursor < rwint.first_valid_snap) {
614
			return (EXIT_ERROR);
615
		}
616
	} else if (frames_to_rewind > 0) {
617
		// forward
618
		if (cursor > rwint.count.snaps) {
619
			return (EXIT_ERROR);
620
		}
621
	} else {
622
		return (EXIT_ERROR);
623
	}
624
625
	chunk = cursor / REWIND_SNAPS_FOR_CHUNK;
626
	snaps = cursor % REWIND_SNAPS_FOR_CHUNK;
627
	segment = chunk / rwint.chunks_for_segment;
628
629
	index.chunk = chunk % rwint.chunks_for_segment;
630
	index.snap = 0;
631
632
	rwint.snap_cursor = cursor;
633
634
	// se non sono nel segmento corrente carico da disco
635
	if ((chunk < rwint.range.chunk.first) || (chunk >= rwint.range.chunk.last)) {
636
		int32_t segment_to_load = segment, segment_to_save = rwint.index.segment;
637
638
		if (rwint.max_buffered.segments > 0) {
639
			segment_to_load %= rwint.max_buffered.segments;
640
			segment_to_save %= rwint.max_buffered.segments;
641
		}
642
643
		if (rwint.index.segment == rwint.count.segments) {
644
			fseek(rwint.file, segment_to_save * rwint.size.total, SEEK_SET);
645
			fwrite(rwint.segment.data, rwint.size.total, 1, rwint.file);
646
		}
647
648
		fseek(rwint.file, segment_to_load * rwint.size.total, SEEK_SET);
649
		if (fread(rwint.segment.data, rwint.size.total, 1, rwint.file) < 1) {
650
			return (EXIT_ERROR);
651
		}
652
653
		rwint.index.segment = segment;
654
		rwint.range.chunk.first = segment * rwint.chunks_for_segment;
655
		rwint.range.chunk.last = rwint.range.chunk.first + rwint.chunks_for_segment;
656
	}
657
658
	if (index.chunk == 0) {
659
		src = rwint.segment.data;
660
	} else {
661
		src = rwint.segment.data + rwint.size.screen + (rwint.size.chunk * index.chunk);
662
	}
663
664
	if (snaps == 0) {
665
		if (index.chunk > 0) {
666
			// visto che lo screen lo salvo solo per il primo chunk della serie
667
			// se facessi solo il rewind_operation ripristinerei il keyframe ma
668
			// non avrei lo screen aggiornato quindi sono costretto ad eseguire
669
			// prima tutti gli snaps del chunk precedente compreso l'ultimo frame.
670
			_rewind_frames(-1, TRUE);
671
		}
672
673
		rewind_update_chunk_snaps(&rwint.cbuffer, index.chunk, src);
674
675
		snap = rwint.cbuffer.snaps;
676
		snap->index.chunk = index.chunk;
677
		snap->index.snap = index.snap;
678
679
		rewind_operation(REWIND_OP_READ, TRUE, rwint.cbuffer.snaps);
680
	} else {
681
		rewind_update_chunk_snaps(&rwint.cbuffer, index.chunk, src);
682
683
		while (index.snap <= snaps) {
684
			snap = rwint.cbuffer.snaps + index.snap;
685
			snap->index.chunk = index.chunk;
686
			snap->index.snap = index.snap;
687
688
			rewind_operation(REWIND_OP_READ, TRUE, snap);
689
690
			if ((index.snap == snaps) && (exec_last_frame == FALSE)) {
691
				break;
692
			}
693
694
			rewind_execute_frame();
695
			index.snap++;
696
		}
697
	}
698
699
	rewind_update_chunk_snaps(&rwint.segment, index.chunk, rwint.cbuffer.data);
700
701
	rwint.index.chunk = index.chunk;
702
	rwint.index.snap = index.snap;
703
704
	rwint.snap_cursor = cursor;
705
706
	return (EXIT_OK);
707
}
(-)puNES-0.105.org/src/core/rewind.h (-8 / +10 lines)
Lines 48-60 enum rewind_action { Link Here
48
	RWND_ACT_FAST_FORWARD
48
	RWND_ACT_FAST_FORWARD
49
};
49
};
50
50
51
#if defined (__cplusplus)
51
typedef struct _rewind {
52
#define EXTERNC extern "C"
53
#else
54
#define EXTERNC
55
#endif
56
57
EXTERNC struct _rewind {
58
	BYTE active;
52
	BYTE active;
59
	BYTE direction;
53
	BYTE direction;
60
	BYTE action;
54
	BYTE action;
Lines 64-70 EXTERNC struct _rewind { Link Here
64
		int backward;
58
		int backward;
65
		int forward;
59
		int forward;
66
	} factor;
60
	} factor;
67
} rwnd;
61
} _rewind;
62
63
extern _rewind rwnd;
64
65
#if defined (__cplusplus)
66
#define EXTERNC extern "C"
67
#else
68
#define EXTERNC
69
#endif
68
70
69
EXTERNC BYTE rewind_init(void);
71
EXTERNC BYTE rewind_init(void);
70
EXTERNC void rewind_quit(void);
72
EXTERNC void rewind_quit(void);
(-)puNES-0.105.org/src/core/rewind.h.orig (+93 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#ifndef REWIND_H_
20
#define REWIND_H_
21
22
#include "common.h"
23
24
enum rewind_operations_mode {
25
	REWIND_OP_SAVE,
26
	REWIND_OP_READ,
27
	REWIND_OP_COUNT
28
};
29
enum rewind_options {
30
	RWND_0_MINUTES,
31
	RWND_2_MINUTES,
32
	RWND_5_MINUTES,
33
	RWND_15_MINUTES,
34
	RWND_30_MINUTES,
35
	RWND_60_MINUTES,
36
	RWND_UNLIMITED_MINUTES,
37
};
38
enum rewind_directions {
39
	RWND_BACKWARD,
40
	RWND_FORWARD
41
};
42
enum rewind_action {
43
	RWND_ACT_PLAY,
44
	RWND_ACT_PAUSE,
45
	RWND_ACT_STEP_BACKWARD,
46
	RWND_ACT_FAST_BACKWARD,
47
	RWND_ACT_STEP_FORWARD,
48
	RWND_ACT_FAST_FORWARD
49
};
50
51
#if defined (__cplusplus)
52
#define EXTERNC extern "C"
53
#else
54
#define EXTERNC
55
#endif
56
57
EXTERNC struct _rewind {
58
	BYTE active;
59
	BYTE direction;
60
	BYTE action;
61
	BYTE action_before_pause;
62
63
	struct _rewind_factor {
64
		int backward;
65
		int forward;
66
	} factor;
67
} rwnd;
68
69
EXTERNC BYTE rewind_init(void);
70
EXTERNC void rewind_quit(void);
71
72
EXTERNC void rewind_snapshoot(void);
73
EXTERNC void rewind_frames(int32_t frames_to_rewind);
74
75
EXTERNC void rewind_save_state_snap(BYTE mode);
76
77
EXTERNC void rewind_init_operation(void);
78
EXTERNC void rewind_close_operation(void);
79
80
EXTERNC BYTE rewind_is_first_snap(void);
81
EXTERNC BYTE rewind_is_last_snap(void);
82
83
EXTERNC int32_t rewind_count_snaps(void);
84
EXTERNC int32_t rewind_snap_cursor(void);
85
EXTERNC int32_t rewind_calculate_snap_cursor(int factor, BYTE direction);
86
87
EXTERNC char *rewind_text_time_count_snaps(void);
88
EXTERNC char *rewind_text_time_snap_cursor(void);
89
EXTERNC char *rewind_text_time_backward(void);
90
91
#undef EXTERNC
92
93
#endif /* REWIND_H_ */
(-)puNES-0.105.org/src/core/save_slot.c (-2 / +2 lines)
Lines 25-31 Link Here
25
#include "mem_map.h"
25
#include "mem_map.h"
26
#include "cpu.h"
26
#include "cpu.h"
27
#include "ppu.h"
27
#include "ppu.h"
28
#include "apu.h"
29
#include "mappers.h"
28
#include "mappers.h"
30
#include "irqA12.h"
29
#include "irqA12.h"
31
#include "irql2f.h"
30
#include "irql2f.h"
Lines 37-49 Link Here
37
#include "fds.h"
36
#include "fds.h"
38
#include "nsf.h"
37
#include "nsf.h"
39
#include "cheat.h"
38
#include "cheat.h"
40
#include "info.h"
41
39
42
#define SAVE_VERSION 22
40
#define SAVE_VERSION 22
43
41
44
static BYTE slot_operation(BYTE mode, BYTE slot, FILE *fp);
42
static BYTE slot_operation(BYTE mode, BYTE slot, FILE *fp);
45
static uTCHAR *name_slot_file(BYTE slot);
43
static uTCHAR *name_slot_file(BYTE slot);
46
44
45
_save_slot save_slot;
46
47
BYTE save_slot_save(BYTE slot) {
47
BYTE save_slot_save(BYTE slot) {
48
	uTCHAR *file;
48
	uTCHAR *file;
49
	FILE *fp;
49
	FILE *fp;
(-)puNES-0.105.org/src/core/save_slot.c.orig (+793 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#include <libgen.h>
20
#include <string.h>
21
#include <unistd.h>
22
#include <sys/stat.h>
23
#include "save_slot.h"
24
#include "conf.h"
25
#include "mem_map.h"
26
#include "cpu.h"
27
#include "ppu.h"
28
#include "apu.h"
29
#include "mappers.h"
30
#include "irqA12.h"
31
#include "irql2f.h"
32
#include "rewind.h"
33
#include "video/gfx.h"
34
#include "gui.h"
35
#include "tas.h"
36
#include "text.h"
37
#include "fds.h"
38
#include "nsf.h"
39
#include "cheat.h"
40
#include "info.h"
41
42
#define SAVE_VERSION 22
43
44
static BYTE slot_operation(BYTE mode, BYTE slot, FILE *fp);
45
static uTCHAR *name_slot_file(BYTE slot);
46
47
BYTE save_slot_save(BYTE slot) {
48
	uTCHAR *file;
49
	FILE *fp;
50
51
	// game genie
52
	if (info.mapper.id == GAMEGENIE_MAPPER) {
53
		text_add_line_info(1, "[yellow]save is impossible in Game Genie menu");
54
		return (EXIT_ERROR);
55
	}
56
57
	if (slot < SAVE_SLOT_FILE) {
58
		if ((file = name_slot_file(slot)) == NULL) {
59
			return (EXIT_ERROR);
60
		}
61
	} else {
62
		file = cfg->save_file;
63
	}
64
65
	if ((fp = ufopen(file, uL("wb"))) == NULL) {
66
		fprintf(stderr, "error on write save state\n");
67
		return (EXIT_ERROR);
68
	}
69
70
	slot_operation(SAVE_SLOT_SAVE, slot, fp);
71
72
	fflush(fp);
73
74
	// aggiorno la posizione della preview e il totalsize
75
	slot_operation(SAVE_SLOT_COUNT, slot, fp);
76
77
	save_slot.state[slot] = TRUE;
78
79
	fclose(fp);
80
81
	if (slot < SAVE_SLOT_FILE) {
82
		text_save_slot(SAVE_SLOT_SAVE);
83
	}
84
85
	return (EXIT_OK);
86
}
87
BYTE save_slot_load(BYTE slot) {
88
	uTCHAR *file;
89
	FILE *fp;
90
91
	if (tas.type) {
92
		text_add_line_info(1, "[yellow]movie playback interrupted[normal]");
93
		tas_quit();
94
	}
95
96
	// game genie
97
	if (info.mapper.id == GAMEGENIE_MAPPER) {
98
		gamegenie_reset();
99
		gamegenie.phase = GG_LOAD_ROM;
100
		emu_reset(CHANGE_ROM);
101
		gamegenie.phase = GG_FINISH;
102
	}
103
104
	if (slot < SAVE_SLOT_FILE) {
105
		if ((file = name_slot_file(slot)) == NULL) {
106
			return (EXIT_ERROR);
107
		}
108
	} else {
109
		file = cfg->save_file;
110
	}
111
112
	if ((fp = ufopen(file, uL("rb"))) == NULL) {
113
		text_add_line_info(1, "[red]error[normal] loading state");
114
		fprintf(stderr, "error loading state\n");
115
		return (EXIT_ERROR);
116
	}
117
118
	// mi salvo lo stato attuale da ripristinare in caso
119
	// di un file di salvataggio corrotto.
120
	rewind_save_state_snap(REWIND_OP_SAVE);
121
122
	if (slot == SAVE_SLOT_FILE) {
123
		slot_operation(SAVE_SLOT_COUNT, slot, fp);
124
125
		if (memcmp(info.sha1sum.prg.value, save_slot.sha1sum.prg.value,
126
			sizeof(info.sha1sum.prg.value)) != 0) {
127
			text_add_line_info(1, "[red]state file is not for this rom[normal]");
128
			fprintf(stderr, "state file is not for this rom.\n");
129
			rewind_save_state_snap(REWIND_OP_READ);
130
			fclose(fp);
131
			return (EXIT_ERROR);
132
		}
133
	}
134
135
	if (slot_operation(SAVE_SLOT_READ, slot, fp)) {
136
		fprintf(stderr, "error loading state, corrupted file.\n");
137
		rewind_save_state_snap(REWIND_OP_READ);
138
		fclose(fp);
139
		return (EXIT_ERROR);
140
	}
141
142
	fclose(fp);
143
144
	if (slot < SAVE_SLOT_FILE) {
145
		text_save_slot(SAVE_SLOT_READ);
146
	}
147
148
	//riavvio il rewind
149
	rewind_init();
150
151
	return (EXIT_OK);
152
}
153
void save_slot_count_load(void) {
154
	uTCHAR *file;
155
	BYTE i;
156
157
	for (i = 0; i < SAVE_SLOTS; i++) {
158
		save_slot.tot_size[i] = 0;
159
160
		save_slot.state[i] = FALSE;
161
		file = name_slot_file(i);
162
163
		if (emu_file_exist(file) == EXIT_OK) {
164
			FILE *fp;
165
166
			save_slot.state[i] = TRUE;
167
168
			if ((fp = ufopen(file, uL("rb"))) == NULL) {
169
				continue;
170
			}
171
172
			slot_operation(SAVE_SLOT_COUNT, i, fp);
173
			fclose(fp);
174
		}
175
	}
176
177
	if (!save_slot.state[save_slot.slot]) {
178
		BYTE i;
179
180
		save_slot.slot = 0;
181
182
		for (i = 0; i < SAVE_SLOTS; i++) {
183
			if (save_slot.state[i]) {
184
				save_slot.slot = i;
185
			}
186
		}
187
	}
188
189
	gui_save_slot(save_slot.slot);
190
}
191
BYTE save_slot_element_struct(BYTE mode, BYTE slot, uintptr_t *src, DBWORD size, FILE *fp, BYTE preview) {
192
	DBWORD bytes;
193
194
	switch (mode) {
195
		case SAVE_SLOT_SAVE:
196
			bytes = fwrite(src, size, 1, fp);
197
			save_slot.tot_size[slot] += size;
198
			break;
199
		case SAVE_SLOT_READ:
200
			bytes = fread(src, size, 1, fp);
201
			if ((bytes != 1) && (preview == FALSE)) {
202
				return (EXIT_ERROR);
203
			}
204
			break;
205
		case SAVE_SLOT_COUNT:
206
			save_slot.tot_size[slot] += size;
207
			break;
208
	}
209
	return (EXIT_OK);
210
}
211
212
static BYTE slot_operation(BYTE mode, BYTE slot, FILE *fp) {
213
	uint32_t tmp = 0;
214
	WORD i = 0;
215
216
	fseek(fp, 0L, SEEK_SET);
217
218
	save_slot.version = SAVE_VERSION;
219
220
	if (mode == SAVE_SLOT_COUNT) {
221
		save_slot.tot_size[slot] = 0;
222
		// forzo la lettura perche' devo sapere la
223
		// versione del file di salvataggio e le informazioni
224
		// della rom.
225
		save_slot_int(SAVE_SLOT_READ, slot, save_slot.version)
226
		if (save_slot.version < 16) {
227
			_save_slot_ele(SAVE_SLOT_READ, slot, save_slot.rom_file, 1024)
228
		} else if (save_slot.version < 21) {
229
			_save_slot_ele(SAVE_SLOT_READ, slot, save_slot.rom_file, (1024 * sizeof(uTCHAR)))
230
		} else {
231
			save_slot_ele(SAVE_SLOT_READ, slot, save_slot.rom_file)
232
		}
233
		save_slot_ele(SAVE_SLOT_READ, slot, save_slot.sha1sum.prg.value)
234
		save_slot_ele(SAVE_SLOT_READ, slot, save_slot.sha1sum.prg.string)
235
		if (save_slot.version >= 11) {
236
			save_slot_ele(SAVE_SLOT_READ, slot, save_slot.sha1sum.chr.value)
237
			save_slot_ele(SAVE_SLOT_READ, slot, save_slot.sha1sum.chr.string)
238
		}
239
	} else if (mode == SAVE_SLOT_READ) {
240
		save_slot_int(mode, slot, save_slot.version)
241
		if (save_slot.version < 16) {
242
			_save_slot_ele(mode, slot, save_slot.rom_file, 1024)
243
		} else if (save_slot.version < 21) {
244
			_save_slot_ele(mode, slot, save_slot.rom_file, (1024 * sizeof(uTCHAR)))
245
		} else {
246
			save_slot_ele(mode, slot, save_slot.rom_file)
247
		}
248
		save_slot_ele(mode, slot, save_slot.sha1sum.prg.value)
249
		save_slot_ele(mode, slot, save_slot.sha1sum.prg.string)
250
		if (save_slot.version >= 11) {
251
			save_slot_ele(mode, slot, save_slot.sha1sum.chr.value)
252
			save_slot_ele(mode, slot, save_slot.sha1sum.chr.string)
253
		}
254
	} else {
255
		save_slot_int(mode, slot, save_slot.version)
256
		if (save_slot.version < 16) {
257
			_save_slot_ele(mode, slot, info.rom.file, 1024)
258
		} else if (save_slot.version < 21) {
259
			_save_slot_ele(mode, slot, info.rom.file, (1024 * sizeof(uTCHAR)))
260
		} else {
261
			save_slot_ele(mode, slot, info.rom.file)
262
		}
263
		save_slot_ele(mode, slot, info.sha1sum.prg.value)
264
		save_slot_ele(mode, slot, info.sha1sum.prg.string)
265
		if (save_slot.version >= 11) {
266
			save_slot_ele(mode, slot, info.sha1sum.chr.value)
267
			save_slot_ele(mode, slot, info.sha1sum.chr.string)
268
		}
269
	}
270
271
	// cpu
272
	save_slot_ele(mode, slot, cpu.PC)
273
	save_slot_ele(mode, slot, cpu.SP)
274
	save_slot_ele(mode, slot, cpu.AR)
275
	save_slot_ele(mode, slot, cpu.XR)
276
	save_slot_ele(mode, slot, cpu.YR)
277
	save_slot_ele(mode, slot, cpu.SR)
278
	save_slot_ele(mode, slot, cpu.cf)
279
	save_slot_ele(mode, slot, cpu.zf)
280
	save_slot_ele(mode, slot, cpu.im)
281
	save_slot_ele(mode, slot, cpu.df)
282
	save_slot_ele(mode, slot, cpu.bf)
283
	save_slot_ele(mode, slot, cpu.of)
284
	save_slot_ele(mode, slot, cpu.sf)
285
	save_slot_ele(mode, slot, cpu.opcode)
286
	save_slot_ele(mode, slot, cpu.opcode_PC)
287
	save_slot_ele(mode, slot, cpu.odd_cycle)
288
	save_slot_ele(mode, slot, cpu.openbus)
289
	save_slot_ele(mode, slot, cpu.cycles)
290
	save_slot_ele(mode, slot, cpu.opcode_cycle)
291
	save_slot_ele(mode, slot, cpu.double_rd)
292
	save_slot_ele(mode, slot, cpu.double_wr)
293
	save_slot_ele(mode, slot, cpu.prg_ram_rd_active)
294
	save_slot_ele(mode, slot, cpu.prg_ram_wr_active)
295
	// questo dato e' stato aggiunto solo dalla versione 9 in poi
296
	if (save_slot.version >= 9) {
297
		save_slot_ele(mode, slot, cpu.base_opcode_cycles)
298
	}
299
300
	// irq
301
	save_slot_ele(mode, slot, irq.high)
302
	save_slot_ele(mode, slot, irq.delay)
303
	save_slot_ele(mode, slot, irq.before)
304
	save_slot_ele(mode, slot, irq.inhibit)
305
	// nmi
306
	save_slot_ele(mode, slot, nmi.high)
307
	save_slot_ele(mode, slot, nmi.delay)
308
	save_slot_ele(mode, slot, nmi.before)
309
	save_slot_ele(mode, slot, nmi.inhibit)
310
	save_slot_ele(mode, slot, nmi.frame_x)
311
	// questo dato e' stato aggiunto solo dalla versione 9 in poi
312
	if (save_slot.version >= 9) {
313
		save_slot_ele(mode, slot, nmi.cpu_cycles_from_last_nmi)
314
	}
315
316
	// ppu
317
	save_slot_ele(mode, slot, ppu.frame_x)
318
	save_slot_ele(mode, slot, ppu.frame_y)
319
	save_slot_ele(mode, slot, ppu.fine_x)
320
	save_slot_ele(mode, slot, ppu.screen_y)
321
	save_slot_ele(mode, slot, ppu.pixel_tile)
322
	save_slot_ele(mode, slot, ppu.sline_cycles)
323
	save_slot_ele(mode, slot, ppu.tmp_vram)
324
	save_slot_ele(mode, slot, ppu.spr_adr)
325
	save_slot_ele(mode, slot, ppu.bck_adr)
326
	save_slot_ele(mode, slot, ppu.openbus)
327
	save_slot_ele(mode, slot, ppu.odd_frame)
328
	save_slot_ele(mode, slot, ppu.cycles)
329
	save_slot_ele(mode, slot, ppu.frames)
330
	if (save_slot.version >= 13) {
331
		save_slot_ele(mode, slot, ppu.sf.actual)
332
		save_slot_ele(mode, slot, ppu.sf.prev)
333
		// questo byte ormai non serve piu'
334
		save_slot_ele(mode, slot, ppu.sf.first_of_tick)
335
	}
336
	if (save_slot.version >= 14) {
337
		save_slot_ele(mode, slot, ppu.rnd_adr)
338
	}
339
	// ppu_openbus
340
	save_slot_ele(mode, slot, ppu_openbus.bit0)
341
	save_slot_ele(mode, slot, ppu_openbus.bit1)
342
	save_slot_ele(mode, slot, ppu_openbus.bit2)
343
	save_slot_ele(mode, slot, ppu_openbus.bit3)
344
	save_slot_ele(mode, slot, ppu_openbus.bit4)
345
	save_slot_ele(mode, slot, ppu_openbus.bit5)
346
	save_slot_ele(mode, slot, ppu_openbus.bit6)
347
	save_slot_ele(mode, slot, ppu_openbus.bit7)
348
	// r2000
349
	save_slot_ele(mode, slot, r2000.value)
350
	save_slot_ele(mode, slot, r2000.nmi_enable)
351
	save_slot_ele(mode, slot, r2000.size_spr)
352
	save_slot_ele(mode, slot, r2000.r2006_inc)
353
	save_slot_ele(mode, slot, r2000.spt_adr)
354
	save_slot_ele(mode, slot, r2000.bpt_adr)
355
	if (save_slot.version >= 13) {
356
		save_slot_ele(mode, slot, r2000.race.ctrl)
357
		save_slot_ele(mode, slot, r2000.race.value)
358
	}
359
	// r2001
360
	save_slot_ele(mode, slot, r2001.value)
361
	save_slot_ele(mode, slot, r2001.emphasis)
362
	save_slot_ele(mode, slot, r2001.visible)
363
	save_slot_ele(mode, slot, r2001.bck_visible)
364
	save_slot_ele(mode, slot, r2001.spr_visible)
365
	save_slot_ele(mode, slot, r2001.bck_clipping)
366
	save_slot_ele(mode, slot, r2001.spr_clipping)
367
	save_slot_ele(mode, slot, r2001.color_mode)
368
	if (save_slot.version >= 13) {
369
		save_slot_ele(mode, slot, r2001.race.ctrl)
370
		save_slot_ele(mode, slot, r2001.race.value)
371
	}
372
	// r2002
373
	save_slot_ele(mode, slot, r2002.vblank)
374
	save_slot_ele(mode, slot, r2002.sprite0_hit)
375
	save_slot_ele(mode, slot, r2002.sprite_overflow)
376
	save_slot_ele(mode, slot, r2002.toggle)
377
	if (save_slot.version >= 17) {
378
		save_slot_ele(mode, slot, r2002.race.sprite_overflow)
379
	}
380
	// r2003
381
	save_slot_ele(mode, slot, r2003.value)
382
	// r2004
383
	save_slot_ele(mode, slot, r2004.value)
384
	// r2006
385
	save_slot_ele(mode, slot, r2006.value)
386
	save_slot_ele(mode, slot, r2006.changed_from_op)
387
	if (save_slot.version >= 12) {
388
		save_slot_ele(mode, slot, r2006.race.ctrl)
389
		save_slot_ele(mode, slot, r2006.race.value)
390
	}
391
	// r2007
392
	save_slot_ele(mode, slot, r2007.value)
393
	// spr_ev
394
	save_slot_ele(mode, slot, spr_ev.range)
395
	save_slot_ele(mode, slot, spr_ev.count)
396
	save_slot_ele(mode, slot, spr_ev.count_plus)
397
	save_slot_ele(mode, slot, spr_ev.tmp_spr_plus)
398
	save_slot_ele(mode, slot, spr_ev.evaluate)
399
	save_slot_ele(mode, slot, spr_ev.byte_OAM)
400
	save_slot_ele(mode, slot, spr_ev.index_plus)
401
	save_slot_ele(mode, slot, spr_ev.index)
402
	save_slot_ele(mode, slot, spr_ev.timing)
403
	save_slot_ele(mode, slot, spr_ev.phase)
404
	if (save_slot.version >= 13) {
405
		save_slot_ele(mode, slot, spr_ev.real)
406
	}
407
	// sprite
408
	for (i = 0; i < LENGTH(sprite); i++) {
409
		save_slot_ele(mode, slot, sprite[i].y_C)
410
		save_slot_ele(mode, slot, sprite[i].tile)
411
		save_slot_ele(mode, slot, sprite[i].attrib)
412
		save_slot_ele(mode, slot, sprite[i].x_C)
413
		save_slot_ele(mode, slot, sprite[i].number)
414
		save_slot_ele(mode, slot, sprite[i].flip_v)
415
		save_slot_ele(mode, slot, sprite[i].l_byte)
416
		save_slot_ele(mode, slot, sprite[i].h_byte)
417
	}
418
	// sprite_plus
419
	for (i = 0; i < LENGTH(sprite_plus); i++) {
420
		save_slot_ele(mode, slot, sprite_plus[i].y_C)
421
		save_slot_ele(mode, slot, sprite_plus[i].tile)
422
		save_slot_ele(mode, slot, sprite_plus[i].attrib)
423
		save_slot_ele(mode, slot, sprite_plus[i].x_C)
424
		save_slot_ele(mode, slot, sprite_plus[i].number)
425
		save_slot_ele(mode, slot, sprite_plus[i].flip_v)
426
		save_slot_ele(mode, slot, sprite_plus[i].l_byte)
427
		save_slot_ele(mode, slot, sprite_plus[i].h_byte)
428
	}
429
	// tile_render
430
	save_slot_ele(mode, slot, tile_render.attrib)
431
	save_slot_ele(mode, slot, tile_render.l_byte)
432
	save_slot_ele(mode, slot, tile_render.h_byte)
433
	// tile_fetch
434
	save_slot_ele(mode, slot, tile_fetch.attrib)
435
	save_slot_ele(mode, slot, tile_fetch.l_byte)
436
	save_slot_ele(mode, slot, tile_fetch.h_byte)
437
438
	// apu
439
	save_slot_ele(mode, slot, apu.mode)
440
	save_slot_ele(mode, slot, apu.type)
441
	save_slot_ele(mode, slot, apu.step)
442
	save_slot_ele(mode, slot, apu.length_clocked)
443
	save_slot_ele(mode, slot, apu.DMC)
444
	save_slot_ele(mode, slot, apu.cycles)
445
	// r4015
446
	save_slot_ele(mode, slot, r4015.value)
447
	// r4017
448
	save_slot_ele(mode, slot, r4017.value)
449
	save_slot_ele(mode, slot, r4017.jitter.value)
450
	save_slot_ele(mode, slot, r4017.jitter.delay)
451
	if (save_slot.version >= 13) {
452
		save_slot_ele(mode, slot, r4017.reset_frame_delay)
453
	}
454
	// S1
455
	save_slot_square(S1, slot)
456
	// S2
457
	save_slot_square(S2, slot)
458
	// TR
459
	save_slot_ele(mode, slot, TR.timer)
460
	save_slot_ele(mode, slot, TR.frequency)
461
	save_slot_ele(mode, slot, TR.linear.value)
462
	save_slot_ele(mode, slot, TR.linear.reload)
463
	save_slot_ele(mode, slot, TR.linear.halt)
464
	save_slot_ele(mode, slot, TR.length.value)
465
	save_slot_ele(mode, slot, TR.length.enabled)
466
	save_slot_ele(mode, slot, TR.length.halt)
467
	save_slot_ele(mode, slot, TR.sequencer)
468
	save_slot_ele(mode, slot, TR.output)
469
	// NS
470
	save_slot_ele(mode, slot, NS.timer)
471
	save_slot_ele(mode, slot, NS.frequency)
472
	save_slot_ele(mode, slot, NS.envelope.enabled)
473
	save_slot_ele(mode, slot, NS.envelope.divider)
474
	save_slot_ele(mode, slot, NS.envelope.counter)
475
	save_slot_ele(mode, slot, NS.envelope.constant_volume)
476
	save_slot_ele(mode, slot, NS.envelope.delay)
477
	save_slot_ele(mode, slot, NS.mode)
478
	save_slot_ele(mode, slot, NS.volume)
479
	// ho portato da DBWORD a WORD NS.shift e per mantenere
480
	// la compatibilita' con i vecchi salvataggi faccio questa
481
	// conversione.
482
	if (save_slot.version < 7) {
483
		if (mode == SAVE_SLOT_READ) {
484
			DBWORD old_nsshift;
485
486
			save_slot_ele(mode, slot, old_nsshift)
487
488
			NS.shift = old_nsshift;
489
		} else if (mode == SAVE_SLOT_COUNT) {
490
			save_slot.tot_size[slot] += sizeof(DBWORD);
491
		}
492
	} else {
493
		save_slot_ele(mode, slot, NS.shift)
494
	}
495
	save_slot_ele(mode, slot, NS.length.value)
496
	save_slot_ele(mode, slot, NS.length.enabled)
497
	save_slot_ele(mode, slot, NS.length.halt)
498
	save_slot_ele(mode, slot, NS.sequencer)
499
	save_slot_ele(mode, slot, NS.output)
500
	// DMC
501
	save_slot_ele(mode, slot, DMC.frequency)
502
	save_slot_ele(mode, slot, DMC.remain)
503
	save_slot_ele(mode, slot, DMC.irq_enabled)
504
	save_slot_ele(mode, slot, DMC.loop)
505
	save_slot_ele(mode, slot, DMC.rate_index)
506
	save_slot_ele(mode, slot, DMC.address_start)
507
	save_slot_ele(mode, slot, DMC.address)
508
	save_slot_ele(mode, slot, DMC.length)
509
	save_slot_ele(mode, slot, DMC.counter)
510
	save_slot_ele(mode, slot, DMC.empty)
511
	save_slot_ele(mode, slot, DMC.buffer)
512
	save_slot_ele(mode, slot, DMC.dma_cycle)
513
	save_slot_ele(mode, slot, DMC.silence)
514
	save_slot_ele(mode, slot, DMC.shift)
515
	save_slot_ele(mode, slot, DMC.counter_out)
516
	save_slot_ele(mode, slot, DMC.output)
517
	save_slot_ele(mode, slot, DMC.tick_type)
518
519
	// mem map
520
	save_slot_ele(mode, slot, mmcpu.ram)
521
	save_slot_mem(mode, slot, prg.ram.data, prg.ram.size, FALSE)
522
	if (mode == SAVE_SLOT_READ) {
523
		save_slot_int(mode, slot, tmp)
524
		if (tmp) {
525
			save_slot_mem(mode, slot, prg.ram_plus, prg_ram_plus_size(), FALSE)
526
			save_slot_pos(mode, slot, prg.ram_plus, prg.ram_plus_8k)
527
			save_slot_int(mode, slot, tmp)
528
			if (tmp) {
529
				save_slot_pos(mode, slot, prg.ram_plus, prg.ram_battery)
530
			}
531
		}
532
	} else {
533
		if (prg.ram_plus) {
534
			tmp = TRUE;
535
			save_slot_int(mode, slot, tmp)
536
			save_slot_mem(mode, slot, prg.ram_plus, prg_ram_plus_size(), FALSE)
537
			save_slot_pos(mode, slot, prg.ram_plus, prg.ram_plus_8k)
538
			if (prg.ram_battery) {
539
				tmp = TRUE;
540
				save_slot_int(mode, slot, tmp)
541
				save_slot_pos(mode, slot, prg.ram_plus, prg.ram_battery)
542
			} else {
543
				tmp = FALSE;
544
				save_slot_int(mode, slot, tmp)
545
			}
546
		} else {
547
			tmp = FALSE;
548
			save_slot_int(mode, slot, tmp)
549
		}
550
	}
551
552
	// e' fondamentale che il salvataggio avvenga qui
553
	if (save_slot.version >= 14) {
554
		save_slot_ele(mode, slot, prg.rom_chip)
555
	}
556
	for (i = 0; i < LENGTH(prg.rom_8k); i++) {
557
		if (mode == SAVE_SLOT_SAVE) {
558
			uint32_t bank = mapper.rom_map_to[i] << 13;
559
			save_slot_int(mode, slot, bank)
560
		} else {
561
			if (save_slot.version >= 14) {
562
				save_slot_pos(mode, slot, prg_chip(prg.rom_chip[i]), prg.rom_8k[i])
563
			} else {
564
				save_slot_pos(mode, slot, prg_chip(0), prg.rom_8k[i])
565
			}
566
		}
567
	}
568
	save_slot_int(mode, slot, mapper.write_vram)
569
	if (mapper.write_vram) {
570
		save_slot_mem(mode, slot, chr_chip(0), chr_ram_size(), FALSE)
571
	}
572
	if (save_slot.version >= 14) {
573
		save_slot_ele(mode, slot, chr.rom_chip)
574
	}
575
	for (i = 0; i < LENGTH(chr.bank_1k); i++) {
576
		if (save_slot.version >= 14) {
577
			save_slot_pos(mode, slot, chr_chip(chr.rom_chip[i]), chr.bank_1k[i])
578
		} else {
579
			save_slot_pos(mode, slot, chr_chip(0), chr.bank_1k[i])
580
		}
581
	}
582
	save_slot_ele(mode, slot, ntbl.data)
583
	for (i = 0; i < LENGTH(ntbl.bank_1k); i++) {
584
		if (mode == SAVE_SLOT_SAVE) {
585
			uint32_t diff = ntbl.bank_1k[i] - ntbl.data;
586
			if (diff > 0x1000) {
587
				tmp = 0;
588
				save_slot_int(mode, slot, tmp)
589
			} else {
590
				save_slot_pos(mode, slot, ntbl.data, ntbl.bank_1k[i])
591
			}
592
		} else {
593
			save_slot_pos(mode, slot, ntbl.data, ntbl.bank_1k[i])
594
		}
595
	}
596
	save_slot_ele(mode, slot, mmap_palette.color)
597
	save_slot_ele(mode, slot, oam.data)
598
	save_slot_ele(mode, slot, oam.plus)
599
	for (i = 0; i < LENGTH(oam.ele_plus); i++) {
600
		save_slot_pos(mode, slot, oam.plus, oam.ele_plus[i])
601
	}
602
603
	// mapper
604
	save_slot_ele(mode, slot, mapper.mirroring)
605
	// ho portato da BYTE a WORD mapper.rom_map_to e per mantenere
606
	// la compatibilita' con i vecchi salvataggi faccio questa
607
	// conversione.
608
	if (save_slot.version < 2) {
609
		if (mode == SAVE_SLOT_READ) {
610
			BYTE old_romMapTo[4], i;
611
612
			save_slot_ele(mode, slot, old_romMapTo)
613
614
			for (i = 0; i < 4; i++) {
615
				mapper.rom_map_to[i] = old_romMapTo[i];
616
			}
617
		} else if (mode == SAVE_SLOT_COUNT) {
618
			save_slot.tot_size[slot] += sizeof(BYTE) * 4;
619
		}
620
	} else {
621
		save_slot_ele(mode, slot, mapper.rom_map_to)
622
	}
623
624
	if (mapper.internal_struct[0]) {
625
		extcl_save_mapper(mode, slot, fp);
626
	}
627
628
	// irqA12
629
	if (irqA12.present) {
630
		save_slot_ele(mode, slot, irqA12.present)
631
		save_slot_ele(mode, slot, irqA12.delay)
632
		save_slot_ele(mode, slot, irqA12.counter)
633
		save_slot_ele(mode, slot, irqA12.latch)
634
		save_slot_ele(mode, slot, irqA12.reload)
635
		save_slot_ele(mode, slot, irqA12.enable)
636
		save_slot_ele(mode, slot, irqA12.save_counter)
637
		save_slot_ele(mode, slot, irqA12.a12BS)
638
		save_slot_ele(mode, slot, irqA12.a12SB)
639
		save_slot_ele(mode, slot, irqA12.b_adr_old)
640
		save_slot_ele(mode, slot, irqA12.s_adr_old)
641
		if (save_slot.version >= 10) {
642
			save_slot_ele(mode, slot, irqA12.cycles)
643
		}
644
		if (save_slot.version >= 14) {
645
			save_slot_ele(mode, slot, irqA12.race.C001)
646
			save_slot_ele(mode, slot, irqA12.race.counter)
647
			save_slot_ele(mode, slot, irqA12.race.reload)
648
		}
649
	}
650
651
	// irql2f
652
	if (irql2f.present) {
653
		save_slot_ele(mode, slot, irql2f.present)
654
		save_slot_ele(mode, slot, irql2f.enable)
655
		save_slot_ele(mode, slot, irql2f.counter)
656
		save_slot_ele(mode, slot, irql2f.scanline)
657
		save_slot_ele(mode, slot, irql2f.frame_x)
658
		save_slot_ele(mode, slot, irql2f.delay)
659
		save_slot_ele(mode, slot, irql2f.in_frame)
660
		save_slot_ele(mode, slot, irql2f.pending)
661
	}
662
663
	if (fds.info.enabled) {
664
		// libero la zona di memoria gia' occupata
665
		BYTE old_side_inserted = fds.drive.side_inserted;
666
667
		// salvo, leggo o conto quello che serve
668
		save_slot_ele(mode, slot, fds.drive.disk_position)
669
		save_slot_ele(mode, slot, fds.drive.delay)
670
		save_slot_ele(mode, slot, fds.drive.disk_ejected)
671
		save_slot_ele(mode, slot, fds.drive.side_inserted)
672
		save_slot_ele(mode, slot, fds.drive.gap_ended)
673
		save_slot_ele(mode, slot, fds.drive.scan)
674
		save_slot_ele(mode, slot, fds.drive.crc_char)
675
		save_slot_ele(mode, slot, fds.drive.enabled_dsk_reg)
676
		save_slot_ele(mode, slot, fds.drive.enabled_snd_reg)
677
		save_slot_ele(mode, slot, fds.drive.data_readed)
678
		save_slot_ele(mode, slot, fds.drive.data_to_write)
679
		save_slot_ele(mode, slot, fds.drive.transfer_flag)
680
		save_slot_ele(mode, slot, fds.drive.motor_on)
681
		save_slot_ele(mode, slot, fds.drive.transfer_reset)
682
		save_slot_ele(mode, slot, fds.drive.read_mode)
683
		save_slot_ele(mode, slot, fds.drive.mirroring)
684
		save_slot_ele(mode, slot, fds.drive.crc_control)
685
		save_slot_ele(mode, slot, fds.drive.unknow)
686
		save_slot_ele(mode, slot, fds.drive.drive_ready)
687
		save_slot_ele(mode, slot, fds.drive.irq_disk_enabled)
688
		save_slot_ele(mode, slot, fds.drive.irq_disk_high)
689
		save_slot_ele(mode, slot, fds.drive.irq_timer_enabled)
690
		save_slot_ele(mode, slot, fds.drive.irq_timer_reload_enabled)
691
		save_slot_ele(mode, slot, fds.drive.irq_timer_high)
692
		save_slot_ele(mode, slot, fds.drive.irq_timer_reload)
693
		save_slot_ele(mode, slot, fds.drive.irq_timer_counter)
694
		save_slot_ele(mode, slot, fds.drive.irq_timer_delay)
695
		save_slot_ele(mode, slot, fds.drive.data_external_connector)
696
		save_slot_ele(mode, slot, fds.drive.filler)
697
698
		// l'fds drive l'ho aggiunto nella versione 3, mentre il
699
		// sound dalla 4 in poi.
700
		if (save_slot.version >= 4) {
701
			save_slot_ele(mode, slot, fds.snd.wave.data)
702
			save_slot_ele(mode, slot, fds.snd.wave.writable)
703
			save_slot_ele(mode, slot, fds.snd.wave.volume)
704
			save_slot_ele(mode, slot, fds.snd.wave.index)
705
			save_slot_ele(mode, slot, fds.snd.wave.counter)
706
707
			save_slot_ele(mode, slot, fds.snd.envelope.speed)
708
			save_slot_ele(mode, slot, fds.snd.envelope.disabled)
709
710
			save_slot_ele(mode, slot, fds.snd.main.silence)
711
			save_slot_ele(mode, slot, fds.snd.main.frequency)
712
			save_slot_ele(mode, slot, fds.snd.main.output)
713
714
			save_slot_ele(mode, slot, fds.snd.volume.speed)
715
			save_slot_ele(mode, slot, fds.snd.volume.mode)
716
			save_slot_ele(mode, slot, fds.snd.volume.increase)
717
			save_slot_ele(mode, slot, fds.snd.volume.gain)
718
			save_slot_ele(mode, slot, fds.snd.volume.counter)
719
720
			save_slot_ele(mode, slot, fds.snd.sweep.bias)
721
			save_slot_ele(mode, slot, fds.snd.sweep.mode)
722
			save_slot_ele(mode, slot, fds.snd.sweep.increase)
723
			save_slot_ele(mode, slot, fds.snd.sweep.speed)
724
			save_slot_ele(mode, slot, fds.snd.sweep.gain)
725
			save_slot_ele(mode, slot, fds.snd.sweep.counter)
726
727
			save_slot_ele(mode, slot, fds.snd.modulation.data)
728
			save_slot_ele(mode, slot, fds.snd.modulation.frequency)
729
			save_slot_ele(mode, slot, fds.snd.modulation.disabled)
730
			save_slot_ele(mode, slot, fds.snd.modulation.index)
731
			save_slot_ele(mode, slot, fds.snd.modulation.counter)
732
			save_slot_ele(mode, slot, fds.snd.modulation.mod)
733
		}
734
735
		if (save_slot.version >= 19) {
736
			save_slot_ele(mode, slot, r2006.second_write.delay)
737
			save_slot_ele(mode, slot, r2006.second_write.value)
738
		}
739
740
		if (save_slot.version >= 20) {
741
			save_slot_ele(mode, slot, r2001.grayscale_bit.delay)
742
		}
743
744
		// in caso di ripristino di una salvataggio, se era caricato
745
		// un'altro side del disco, devo ricaricarlo.
746
		if ((mode == SAVE_SLOT_READ) && (old_side_inserted != fds.drive.side_inserted)) {
747
			fds_disk_op(FDS_DISK_SELECT_FROM_REWIND, fds.drive.side_inserted);
748
			gui_update();
749
		}
750
	}
751
752
	save_slot_mem(mode, slot, screen.rd->data, screen_size(), TRUE)
753
754
	return (EXIT_OK);
755
}
756
static uTCHAR *name_slot_file(BYTE slot) {
757
	static uTCHAR file[LENGTH_FILE_NAME_LONG];
758
	uTCHAR ext[10], bname[255], *last_dot, *fl = NULL;
759
760
	umemset(file, 0x00, LENGTH_FILE_NAME_LONG);
761
762
	// game genie
763
	if (info.mapper.id == GAMEGENIE_MAPPER) {
764
		fl = gamegenie.rom;
765
	}
766
767
	if (!fl) {
768
		fl = info.rom.file;
769
	}
770
771
	if (!fl[0]) {
772
		return (NULL);
773
	}
774
775
	gui_utf_basename(fl, bname, usizeof(bname));
776
	usnprintf(file, usizeof(file), uL("" uPERCENTs SAVE_FOLDER "/" uPERCENTs), info.base_folder, bname);
777
778
	if (nsf.enabled == TRUE) {
779
		usnprintf(ext, usizeof(ext), uL(".n%02d"), slot);
780
	} else {
781
		usnprintf(ext, usizeof(ext), uL(".p%02d"), slot);
782
	}
783
784
	// rintraccio l'ultimo '.' nel nome
785
	if ((last_dot = ustrrchr(file, uL('.')))) {
786
		// elimino l'estensione
787
		*last_dot = 0x00;
788
	}
789
	// aggiungo l'estensione
790
	ustrcat(file, ext);
791
792
	return (file);
793
}
(-)puNES-0.105.org/src/core/save_slot.h (-10 / +12 lines)
Lines 31-43 enum save_slot_misc { Link Here
31
enum save_slot_mode { SAVE_SLOT_SAVE, SAVE_SLOT_READ, SAVE_SLOT_COUNT, SAVE_SLOT_INCDEC };
31
enum save_slot_mode { SAVE_SLOT_SAVE, SAVE_SLOT_READ, SAVE_SLOT_COUNT, SAVE_SLOT_INCDEC };
32
32
33
#define _save_slot_ele(mode, slot, src, size)\
33
#define _save_slot_ele(mode, slot, src, size)\
34
	if (save_slot_element_struct(mode, slot, (uintptr_t *) &src, size, fp, FALSE)) {\
34
	if (save_slot_element_struct(mode, slot, (uintptr_t *)&src, size, fp, FALSE)) {\
35
		return (EXIT_ERROR);\
35
		return (EXIT_ERROR);\
36
	}
36
	}
37
#define save_slot_ele(mode, slot, src)\
37
#define save_slot_ele(mode, slot, src)\
38
	_save_slot_ele(mode, slot, src, sizeof(src))
38
	_save_slot_ele(mode, slot, src, sizeof(src))
39
#define save_slot_mem(mode, slot, src, size, preview)\
39
#define save_slot_mem(mode, slot, src, size, preview)\
40
	if (save_slot_element_struct(mode, slot, (uintptr_t *) src, size, fp, preview)) {\
40
	if (save_slot_element_struct(mode, slot, (uintptr_t *)src, size, fp, preview)) {\
41
		return (EXIT_ERROR);\
41
		return (EXIT_ERROR);\
42
	}
42
	}
43
#define save_slot_int(mode, slot, value)\
43
#define save_slot_int(mode, slot, value)\
Lines 101-120 enum save_slot_mode { SAVE_SLOT_SAVE, SA Link Here
101
	save_slot_ele(mode, slot, square.length.halt);\
101
	save_slot_ele(mode, slot, square.length.halt);\
102
	save_slot_ele(mode, slot, square.output)
102
	save_slot_ele(mode, slot, square.output)
103
103
104
#if defined (__cplusplus)
104
typedef struct _save_slot {
105
#define EXTERNC extern "C"
106
#else
107
#define EXTERNC
108
#endif
109
110
EXTERNC struct _save_slot {
111
	uint32_t version;
105
	uint32_t version;
112
	DBWORD slot;
106
	DBWORD slot;
113
	BYTE state[SAVE_SLOTS_TOTAL];
107
	BYTE state[SAVE_SLOTS_TOTAL];
114
	DBWORD tot_size[SAVE_SLOTS_TOTAL];
108
	DBWORD tot_size[SAVE_SLOTS_TOTAL];
115
	uTCHAR rom_file[LENGTH_FILE_NAME_LONG];
109
	uTCHAR rom_file[LENGTH_FILE_NAME_LONG];
116
	_info_sh1sum sha1sum;
110
	_info_sh1sum sha1sum;
117
} save_slot;
111
} _save_slot;
112
113
extern _save_slot save_slot;
114
115
#if defined (__cplusplus)
116
#define EXTERNC extern "C"
117
#else
118
#define EXTERNC
119
#endif
118
120
119
EXTERNC BYTE save_slot_save(BYTE slot);
121
EXTERNC BYTE save_slot_save(BYTE slot);
120
EXTERNC BYTE save_slot_load(BYTE slot);
122
EXTERNC BYTE save_slot_load(BYTE slot);
(-)puNES-0.105.org/src/core/text.c (-6 / +6 lines)
Lines 16-33 Link Here
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
17
 */
18
18
19
#if defined (WITH_OPENGL)
20
#include <time.h>
21
#endif
22
#include <string.h>
19
#include <string.h>
23
#include <stdarg.h>
20
#include <stdarg.h>
24
#include <stdlib.h>
21
#include <stdlib.h>
25
#include <stdio.h>
26
#include "text.h"
27
#include "video/gfx.h"
22
#include "video/gfx.h"
28
#include "font.h"
23
#include "font.h"
29
#include "tas.h"
24
#include "tas.h"
30
#include "input.h"
31
#include "fds.h"
25
#include "fds.h"
32
#include "fps.h"
26
#include "fps.h"
33
#include "conf.h"
27
#include "conf.h"
Lines 62-67 static char txt_tags[][10] = { Link Here
62
	"[floppy]"
56
	"[floppy]"
63
};
57
};
64
58
59
_text text;
60
uint32_t txt_table[TXT_BLACK + 1];
61
62
void (*text_clear)(_txt_element *ele);
63
void (*text_blit)(_txt_element *ele, _txt_rect *rect);
64
65
void text_init(void) {
65
void text_init(void) {
66
	_txt_element *ele;
66
	_txt_element *ele;
67
	uint8_t i;
67
	uint8_t i;
(-)puNES-0.105.org/src/core/text.h (-13 / +13 lines)
Lines 91-104 typedef struct _txt_element { Link Here
91
	void *blank;
91
	void *blank;
92
#endif
92
#endif
93
} _txt_element;
93
} _txt_element;
94
94
typedef struct _text {
95
#if defined (__cplusplus)
96
#define EXTERNC extern "C"
97
#else
98
#define EXTERNC
99
#endif
100
101
EXTERNC struct _text {
102
	BYTE on_screen;
95
	BYTE on_screen;
103
	uint32_t w;
96
	uint32_t w;
104
	uint32_t h;
97
	uint32_t h;
Lines 124-132 EXTERNC struct _text { Link Here
124
		BYTE operation;
117
		BYTE operation;
125
		_txt_element slot;
118
		_txt_element slot;
126
	} save_slot;
119
	} save_slot;
127
} text;
120
} _text;
121
122
extern _text text;
123
extern uint32_t txt_table[TXT_BLACK + 1];
128
124
129
EXTERNC uint32_t txt_table[TXT_BLACK + 1];
125
extern void (*text_clear)(_txt_element *ele);
126
extern void (*text_blit)(_txt_element *ele, _txt_rect *rect);
127
128
#if defined (__cplusplus)
129
#define EXTERNC extern "C"
130
#else
131
#define EXTERNC
132
#endif
130
133
131
EXTERNC void text_init(void);
134
EXTERNC void text_init(void);
132
EXTERNC void text_save_slot(BYTE operation);
135
EXTERNC void text_save_slot(BYTE operation);
Lines 135-143 EXTERNC void text_rendering(BYTE render) Link Here
135
EXTERNC void text_calculate_real_x_y(_txt_element *ele, int *x, int *y);
138
EXTERNC void text_calculate_real_x_y(_txt_element *ele, int *x, int *y);
136
EXTERNC void text_quit(void);
139
EXTERNC void text_quit(void);
137
140
138
EXTERNC void (*text_clear)(_txt_element *ele);
139
EXTERNC void (*text_blit)(_txt_element *ele, _txt_rect *rect);
140
141
#undef EXTERNC
141
#undef EXTERNC
142
142
143
#endif /* TEXT_H_ */
143
#endif /* TEXT_H_ */
(-)puNES-0.105.org/src/core/uncompress.c (-5 / +4 lines)
Lines 22-28 Link Here
22
#if defined (__OpenBSD__)
22
#if defined (__OpenBSD__)
23
#include <stdio.h>
23
#include <stdio.h>
24
#endif
24
#endif
25
#include "uncompress.h"
26
#include "info.h"
25
#include "info.h"
27
#include "c++/l7zip/l7z.h"
26
#include "c++/l7zip/l7z.h"
28
#include "gui.h"
27
#include "gui.h"
Lines 47-52 static BYTE mz_zip_extract_from_archive( Link Here
47
static uTCHAR *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type);
46
static uTCHAR *mz_zip_item_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type);
48
#endif
47
#endif
49
48
49
_uncompress_storage uncstorage;
50
50
BYTE uncompress_init(void) {
51
BYTE uncompress_init(void) {
51
	l7z_init();
52
	l7z_init();
52
53
Lines 183-190 BYTE uncompress_archive_extract_file(_un Link Here
183
184
184
	return (rc);
185
	return (rc);
185
}
186
}
186
_uncompress_archive_item *uncompress_archive_find_item(_uncompress_archive *archive,
187
_uncompress_archive_item *uncompress_archive_find_item(_uncompress_archive *archive, uint32_t selected, BYTE type) {
187
	uint32_t selected, BYTE type) {
188
	uint32_t i, index = 0;
188
	uint32_t i, index = 0;
189
189
190
	for (i = 0; i < archive->list.count; i++) {
190
	for (i = 0; i < archive->list.count; i++) {
Lines 240-247 uTCHAR *uncompress_storage_archive_name( Link Here
240
240
241
	return (NULL);
241
	return (NULL);
242
}
242
}
243
uint32_t uncompress_storage_add_to_list(_uncompress_archive *archive,
243
uint32_t uncompress_storage_add_to_list(_uncompress_archive *archive, _uncompress_archive_item *aitem, uTCHAR *file) {
244
	_uncompress_archive_item *aitem, uTCHAR *file) {
245
	_uncompress_storage_item *sitem, *si = NULL;
244
	_uncompress_storage_item *sitem, *si = NULL;
246
	BYTE found = FALSE;
245
	BYTE found = FALSE;
247
	uint32_t i;
246
	uint32_t i;
(-)puNES-0.105.org/src/core/uncompress.h (-11 / +10 lines)
Lines 72-83 typedef struct _uncompress_storage { Link Here
72
	_uncompress_storage_item *item;
72
	_uncompress_storage_item *item;
73
} _uncompress_storage;
73
} _uncompress_storage;
74
74
75
#if defined (__cplusplus)
76
#define EXTERNC extern "C"
77
#else
78
#define EXTERNC
79
#endif
80
81
static const _uncompress_extension uncompress_exts[] = {
75
static const _uncompress_extension uncompress_exts[] = {
82
	{ UNCOMPRESS_TYPE_ROM, uL(".nes")  },
76
	{ UNCOMPRESS_TYPE_ROM, uL(".nes")  },
83
	{ UNCOMPRESS_TYPE_ROM, uL(".fds")  },
77
	{ UNCOMPRESS_TYPE_ROM, uL(".fds")  },
Lines 89-95 static const _uncompress_extension uncom Link Here
89
	{ UNCOMPRESS_TYPE_PATCH, uL(".bps") },
83
	{ UNCOMPRESS_TYPE_PATCH, uL(".bps") },
90
	{ UNCOMPRESS_TYPE_PATCH, uL(".xdelta") }
84
	{ UNCOMPRESS_TYPE_PATCH, uL(".xdelta") }
91
};
85
};
92
EXTERNC _uncompress_storage uncstorage;
86
87
extern _uncompress_storage uncstorage;
88
89
#if defined (__cplusplus)
90
#define EXTERNC extern "C"
91
#else
92
#define EXTERNC
93
#endif
93
94
94
EXTERNC BYTE uncompress_init(void);
95
EXTERNC BYTE uncompress_init(void);
95
EXTERNC void uncompress_quit(void);
96
EXTERNC void uncompress_quit(void);
Lines 98-111 EXTERNC _uncompress_archive *uncompress_ Link Here
98
EXTERNC void uncompress_archive_free(_uncompress_archive *archive) ;
99
EXTERNC void uncompress_archive_free(_uncompress_archive *archive) ;
99
EXTERNC uint32_t uncompress_archive_counter(_uncompress_archive *archive, BYTE type);
100
EXTERNC uint32_t uncompress_archive_counter(_uncompress_archive *archive, BYTE type);
100
EXTERNC BYTE uncompress_archive_extract_file(_uncompress_archive *archive, BYTE type);
101
EXTERNC BYTE uncompress_archive_extract_file(_uncompress_archive *archive, BYTE type);
101
EXTERNC _uncompress_archive_item *uncompress_archive_find_item(_uncompress_archive *archive,
102
EXTERNC _uncompress_archive_item *uncompress_archive_find_item(_uncompress_archive *archive, uint32_t selected, BYTE type);
102
	uint32_t selected, BYTE type);
103
EXTERNC uTCHAR *uncompress_archive_extracted_file_name(_uncompress_archive *archive, BYTE type);
103
EXTERNC uTCHAR *uncompress_archive_extracted_file_name(_uncompress_archive *archive, BYTE type);
104
EXTERNC uTCHAR *uncompress_archive_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type);
104
EXTERNC uTCHAR *uncompress_archive_file_name(_uncompress_archive *archive, uint32_t selected, BYTE type);
105
105
106
EXTERNC uTCHAR *uncompress_storage_archive_name(uTCHAR *file);
106
EXTERNC uTCHAR *uncompress_storage_archive_name(uTCHAR *file);
107
EXTERNC uint32_t uncompress_storage_add_to_list(_uncompress_archive *archive,
107
EXTERNC uint32_t uncompress_storage_add_to_list(_uncompress_archive *archive, _uncompress_archive_item *aitem, uTCHAR *file);
108
	_uncompress_archive_item *aitem, uTCHAR *file);
109
108
110
#undef EXTERNC
109
#undef EXTERNC
111
110
(-)puNES-0.105.org/src/core/unif.c (+3 lines)
Lines 51-56 typedef struct _unif_board { Link Here
51
	WORD extra;
51
	WORD extra;
52
} _unif_board;
52
} _unif_board;
53
53
54
_unif unif;
55
54
static const _unif_board unif_boards[] = {
56
static const _unif_board unif_boards[] = {
55
	{"NROM", 0 , NO_UNIF, DEFAULT, DEFAULT, NOEXTRA},
57
	{"NROM", 0 , NO_UNIF, DEFAULT, DEFAULT, NOEXTRA},
56
	{"NROM-128", 0, NO_UNIF, DEFAULT, DEFAULT, NOEXTRA},
58
	{"NROM-128", 0, NO_UNIF, DEFAULT, DEFAULT, NOEXTRA},
Lines 379-384 BYTE unif_load_rom(void) { Link Here
379
	free(rom.data);
381
	free(rom.data);
380
	return (EXIT_OK);
382
	return (EXIT_OK);
381
}
383
}
384
382
BYTE unif_NONE(_rom_mem *rom, BYTE phase) {
385
BYTE unif_NONE(_rom_mem *rom, BYTE phase) {
383
	if (phase == UNIF_COUNT) {
386
	if (phase == UNIF_COUNT) {
384
		if ((rom->position + unif.chunk.length) > rom->size) {
387
		if ((rom->position + unif.chunk.length) > rom->size) {
(-)puNES-0.105.org/src/core/unif.h (-2 / +4 lines)
Lines 23-29 Link Here
23
23
24
enum { UNIF_MAPPER = 0x1002 };
24
enum { UNIF_MAPPER = 0x1002 };
25
25
26
struct _unif {
26
typedef struct _unif {
27
	BYTE finded;
27
	BYTE finded;
28
	WORD internal_mapper;
28
	WORD internal_mapper;
29
	char board[64];
29
	char board[64];
Lines 46-52 struct _unif { Link Here
46
		char id[4];
46
		char id[4];
47
		uint32_t length;
47
		uint32_t length;
48
	} chunk;
48
	} chunk;
49
} unif;
49
} _unif;
50
51
extern _unif unif;
50
52
51
BYTE unif_load_rom(void);
53
BYTE unif_load_rom(void);
52
54
(-)puNES-0.105.org/src/core/vs_system.h (-33 / +26 lines)
Lines 75-111 typedef struct _r4020_type { Link Here
75
	_r4020_base old;
75
	_r4020_base old;
76
	_r4020_base actual;
76
	_r4020_base actual;
77
} _r4020_type;
77
} _r4020_type;
78
78
typedef struct _vs_system {
79
static const BYTE vs_protection_data[2][32] = {
80
	{
81
		0xFF, 0xBF, 0xB7, 0x97,
82
		0x97, 0x17, 0x57, 0x4F,
83
		0x6F, 0x6B, 0xEB, 0xA9,
84
		0xB1, 0x90, 0x94, 0x14,
85
		0x56, 0x4E, 0x6F, 0x6B,
86
		0xEB, 0xA9, 0xB1, 0x90,
87
		0xD4, 0x5C, 0x3E, 0x26,
88
		0x87, 0x83, 0x13, 0x00
89
	},
90
	{
91
		0x00, 0x00, 0x00, 0x00,
92
		0xB4, 0x00, 0x00, 0x00,
93
		0x00, 0x6F, 0x00, 0x00,
94
		0x00, 0x00, 0x94, 0x00,
95
		0x00, 0x00, 0x00, 0x00,
96
		0x00, 0x00, 0x00, 0x00,
97
		0x00, 0x00, 0x00, 0x00,
98
		0x00, 0x00, 0x00, 0x00
99
	}
100
};
101
102
#if defined (__cplusplus)
103
#define EXTERNC extern "C"
104
#else
105
#define EXTERNC
106
#endif
107
108
EXTERNC struct _vs_system {
109
	BYTE enabled;
79
	BYTE enabled;
110
	BYTE ppu;
80
	BYTE ppu;
111
	BYTE shared_mem;
81
	BYTE shared_mem;
Lines 133-140 EXTERNC struct _vs_system { Link Here
133
		DBWORD left;
103
		DBWORD left;
134
		DBWORD right;
104
		DBWORD right;
135
	} coins;
105
	} coins;
136
} vs_system;
106
} _vs_system;
107
108
static const BYTE vs_protection_data[2][32] = {
109
	{
110
		0xFF, 0xBF, 0xB7, 0x97,
111
		0x97, 0x17, 0x57, 0x4F,
112
		0x6F, 0x6B, 0xEB, 0xA9,
113
		0xB1, 0x90, 0x94, 0x14,
114
		0x56, 0x4E, 0x6F, 0x6B,
115
		0xEB, 0xA9, 0xB1, 0x90,
116
		0xD4, 0x5C, 0x3E, 0x26,
117
		0x87, 0x83, 0x13, 0x00
118
	},
119
	{
120
		0x00, 0x00, 0x00, 0x00,
121
		0xB4, 0x00, 0x00, 0x00,
122
		0x00, 0x6F, 0x00, 0x00,
123
		0x00, 0x00, 0x94, 0x00,
124
		0x00, 0x00, 0x00, 0x00,
125
		0x00, 0x00, 0x00, 0x00,
126
		0x00, 0x00, 0x00, 0x00,
127
		0x00, 0x00, 0x00, 0x00
128
	}
129
};
137
130
138
#undef EXTERNC
131
extern _vs_system vs_system;
139
132
140
#endif /* VS_SYSTEM_H_ */
133
#endif /* VS_SYSTEM_H_ */
(-)puNES-0.105.org/src/gui/cmd_line.cpp (-1 lines)
Lines 23-29 Link Here
23
#include "cmd_line.h"
23
#include "cmd_line.h"
24
#include "conf.h"
24
#include "conf.h"
25
#include "version.h"
25
#include "version.h"
26
#include "video/gfx.h"
27
#include "gui.h"
26
#include "gui.h"
28
27
29
#define req_arg true
28
#define req_arg true
(-)puNES-0.105.org/src/gui/dlgVsSystem.cpp (-2 lines)
Lines 22-29 Link Here
22
#include "mainWindow.hpp"
22
#include "mainWindow.hpp"
23
#include "dlgSettings.hpp"
23
#include "dlgSettings.hpp"
24
#include "vs_system.h"
24
#include "vs_system.h"
25
#include "conf.h"
26
#include "info.h"
27
#include "clock.h"
25
#include "clock.h"
28
#include "gui.h"
26
#include "gui.h"
29
27
(-)puNES-0.105.org/src/gui/linux/jstick.c (-2 / +2 lines)
Lines 24-31 Link Here
24
#include <string.h>
24
#include <string.h>
25
#include <stdio.h>
25
#include <stdio.h>
26
#include <errno.h>
26
#include <errno.h>
27
#include "jstick.h"
28
#include "input.h"
29
#include "gui.h"
27
#include "gui.h"
30
#include "conf.h"
28
#include "conf.h"
31
29
Lines 80-85 Link Here
80
static void js_open(_js *joy);
78
static void js_open(_js *joy);
81
static void js_close(_js *joy);
79
static void js_close(_js *joy);
82
80
81
_js js[PORT_MAX], js_shcut;
82
83
void js_init(UNUSED(BYTE first_time)) {
83
void js_init(UNUSED(BYTE first_time)) {
84
	BYTE i;
84
	BYTE i;
85
85
(-)puNES-0.105.org/src/gui/linux/jstick.h (-7 / +7 lines)
Lines 61-72 typedef struct _js_sch { Link Here
61
	BYTE mode;
61
	BYTE mode;
62
} _js_sch;
62
} _js_sch;
63
63
64
#if defined (__cplusplus)
65
#define EXTERNC extern "C"
66
#else
67
#define EXTERNC
68
#endif
69
70
static const _js_element jsn_list[] = {
64
static const _js_element jsn_list[] = {
71
	{ 0x0FF,  uL("NULL")        },
65
	{ 0x0FF,  uL("NULL")        },
72
	{ 0x000,  uL("JOYSTICKID1") },
66
	{ 0x000,  uL("JOYSTICKID1") },
Lines 100-106 static const _js_element jsv_list[] = { Link Here
100
	{ 0x416, uL("JB22")   }, { 0x417, uL("JB23")   },
94
	{ 0x416, uL("JB22")   }, { 0x417, uL("JB23")   },
101
};
95
};
102
96
103
EXTERNC _js js[PORT_MAX], js_shcut;
97
extern _js js[PORT_MAX], js_shcut;
98
99
#if defined (__cplusplus)
100
#define EXTERNC extern "C"
101
#else
102
#define EXTERNC
103
#endif
104
104
105
EXTERNC void js_init(BYTE first_time);
105
EXTERNC void js_init(BYTE first_time);
106
EXTERNC void js_quit(BYTE last_time);
106
EXTERNC void js_quit(BYTE last_time);
(-)puNES-0.105.org/src/gui/objSettings.cpp (-1 lines)
Lines 22-28 Link Here
22
#include "clock.h"
22
#include "clock.h"
23
#include "save_slot.h"
23
#include "save_slot.h"
24
#include "emu.h"
24
#include "emu.h"
25
#include "jstick.h"
26
#include "shaders.h"
25
#include "shaders.h"
27
#if defined (__unix__)
26
#if defined (__unix__)
28
#define XK_MISCELLANY
27
#define XK_MISCELLANY
(-)puNES-0.105.org/src/gui/objSettings.hpp (-2 / +1 lines)
Lines 19-32 Link Here
19
#ifndef OBJSETTINGS_HPP_
19
#ifndef OBJSETTINGS_HPP_
20
#define OBJSETTINGS_HPP_
20
#define OBJSETTINGS_HPP_
21
21
22
#include "settings.h"
23
#include <QtCore/QSettings>
22
#include <QtCore/QSettings>
24
#include <QtCore/QFile>
23
#include <QtCore/QFile>
25
#include <QtGui/QKeySequence>
24
#include <QtGui/QKeySequence>
26
#include <QtCore/QStringList>
25
#include <QtCore/QStringList>
27
#include <QtGui/QKeyEvent>
26
#include <QtGui/QKeyEvent>
27
#include "settings.h"
28
#include "conf.h"
28
#include "conf.h"
29
#include "overscan.h"
30
#include "gui.h"
29
#include "gui.h"
31
30
32
class objSettings : public QSettings {
31
class objSettings : public QSettings {
(-)puNES-0.105.org/src/gui/openbsd/jstick.c (-3 / +3 lines)
Lines 24-33 Link Here
24
#include <errno.h>
24
#include <errno.h>
25
#include <pthread.h>
25
#include <pthread.h>
26
#include <sys/stat.h>
26
#include <sys/stat.h>
27
#include "jstick.h"
28
#include "input.h"
29
#include "conf.h"
30
#include "gui.h"
27
#include "gui.h"
28
#include "conf.h"
31
29
32
#ifndef __FreeBSD_kernel_version
30
#ifndef __FreeBSD_kernel_version
33
#define __FreeBSD_kernel_version __FreeBSD_version
31
#define __FreeBSD_kernel_version __FreeBSD_version
Lines 236-241 static struct _jstick { Link Here
236
	} jdd;
234
	} jdd;
237
} jstick;
235
} jstick;
238
236
237
_js js[PORT_MAX], js_shcut;
238
239
void js_init(BYTE first_time) {
239
void js_init(BYTE first_time) {
240
	int i;
240
	int i;
241
241
(-)puNES-0.105.org/src/gui/openbsd/jstick.h (-7 / +7 lines)
Lines 45-56 typedef struct _js_sch { Link Here
45
	BYTE mode;
45
	BYTE mode;
46
} _js_sch;
46
} _js_sch;
47
47
48
#if defined (__cplusplus)
49
#define EXTERNC extern "C"
50
#else
51
#define EXTERNC
52
#endif
53
54
static const _js_element jsv_list[] = {
48
static const _js_element jsv_list[] = {
55
	{ 0x000, uL("NULL")   },
49
	{ 0x000, uL("NULL")   },
56
	{ 0x001, uL("JA0MIN") }, { 0x002, uL("JA0PLS") },
50
	{ 0x001, uL("JA0MIN") }, { 0x002, uL("JA0PLS") },
Lines 89-95 static const _js_element jsv_list[] = { Link Here
89
	{ 0x422, uL("JB34")   }, { 0x423, uL("JB35")   },
83
	{ 0x422, uL("JB34")   }, { 0x423, uL("JB35")   },
90
};
84
};
91
85
92
EXTERNC _js js[PORT_MAX], js_shcut;
86
extern _js js[PORT_MAX], js_shcut;
87
88
#if defined (__cplusplus)
89
#define EXTERNC extern "C"
90
#else
91
#define EXTERNC
92
#endif
93
93
94
EXTERNC void js_init(BYTE first_time);
94
EXTERNC void js_init(BYTE first_time);
95
EXTERNC void js_quit(BYTE last_time);
95
EXTERNC void js_quit(BYTE last_time);
(-)puNES-0.105.org/src/gui/qt.h (-14 / +18 lines)
Lines 47-59 Link Here
47
#define dlgsettings ((dlgSettings *)gui_dlgsettings_get_ptr())
47
#define dlgsettings ((dlgSettings *)gui_dlgsettings_get_ptr())
48
#define objcheat ((objCheat *)gui_objcheat_get_ptr())
48
#define objcheat ((objCheat *)gui_objcheat_get_ptr())
49
49
50
#if defined (__cplusplus)
50
typedef struct _gui {
51
#define EXTERNC extern "C"
52
#else
53
#define EXTERNC
54
#endif
55
56
EXTERNC struct _gui {
57
#if defined (_WIN32)
51
#if defined (_WIN32)
58
	uTCHAR home[MAX_PATH];
52
	uTCHAR home[MAX_PATH];
59
	const uTCHAR *ostmp;
53
	const uTCHAR *ostmp;
Lines 78-85 EXTERNC struct _gui { Link Here
78
	uint8_t main_win_lfp;
72
	uint8_t main_win_lfp;
79
73
80
	int dlg_rc;
74
	int dlg_rc;
81
} gui;
75
} _gui;
82
EXTERNC struct _gui_mouse {
76
typedef struct _gui_mouse {
83
	int x;
77
	int x;
84
	int y;
78
	int y;
85
	uint8_t left;
79
	uint8_t left;
Lines 88-97 EXTERNC struct _gui_mouse { Link Here
88
	uint8_t hidden;
82
	uint8_t hidden;
89
83
90
	double timer;
84
	double timer;
91
} gmouse;
85
} _gui_mouse;
92
EXTERNC struct _external_windows {
86
typedef struct _external_windows {
93
	uint8_t vs_system;
87
	uint8_t vs_system;
94
} ext_win;
88
} _external_windows;
89
90
extern _gui gui;
91
extern _gui_mouse gmouse;
92
extern _external_windows ext_win;
93
94
extern double (*gui_get_ms)(void);
95
96
#if defined (__cplusplus)
97
#define EXTERNC extern "C"
98
#else
99
#define EXTERNC
100
#endif
95
101
96
EXTERNC void gui_quit(void);
102
EXTERNC void gui_quit(void);
97
EXTERNC BYTE gui_create(void);
103
EXTERNC BYTE gui_create(void);
Lines 165-172 EXTERNC void gui_utf_dirname(uTCHAR *pat Link Here
165
EXTERNC void gui_utf_basename(uTCHAR *path, uTCHAR *dst, size_t len);
171
EXTERNC void gui_utf_basename(uTCHAR *path, uTCHAR *dst, size_t len);
166
EXTERNC int gui_utf_strcasecmp(uTCHAR *s0, uTCHAR *s1);
172
EXTERNC int gui_utf_strcasecmp(uTCHAR *s0, uTCHAR *s1);
167
173
168
EXTERNC double (*gui_get_ms)(void);
169
170
EXTERNC void gui_init(int *argc, char **argv);
174
EXTERNC void gui_init(int *argc, char **argv);
171
EXTERNC void gui_sleep(double ms);
175
EXTERNC void gui_sleep(double ms);
172
#if defined (_WIN32)
176
#if defined (_WIN32)
(-)puNES-0.105.org/src/gui/qt.h.orig (+183 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#ifndef QT_H_
20
#define QT_H_
21
22
#if defined (_WIN32)
23
#include "win.h"
24
#else
25
#include <sys/time.h>
26
#endif
27
#include "common.h"
28
#include "emu.h"
29
#include "uncompress.h"
30
#include "jstick.h"
31
32
#define tools_stylesheet()\
33
	"QGroupBox {"\
34
	"	border-radius: 10px;"\
35
	"	border: 1px solid black;"\
36
	"	border: 2px groove gray;"\
37
	"	font-weight: bold;"\
38
	"}"\
39
	"QGroupBox::title {"\
40
	"	subcontrol-origin: margin;"\
41
	"	subcontrol-position: top center;"\
42
	"	padding: 0 0px;"\
43
	"}"
44
45
#define mainwin ((mainWindow *)gui_mainwindow_get_ptr())
46
#define wdgrewind ((wdgRewind *)gui_wdgrewind_get_ptr())
47
#define dlgsettings ((dlgSettings *)gui_dlgsettings_get_ptr())
48
#define objcheat ((objCheat *)gui_objcheat_get_ptr())
49
50
#if defined (__cplusplus)
51
#define EXTERNC extern "C"
52
#else
53
#define EXTERNC
54
#endif
55
56
EXTERNC struct _gui {
57
#if defined (_WIN32)
58
	uTCHAR home[MAX_PATH];
59
	const uTCHAR *ostmp;
60
	DWORD version_os;
61
	double frequency;
62
	uint64_t counter_start;
63
#else
64
	const uTCHAR *home;
65
	const uTCHAR *ostmp;
66
	struct timeval counterStart;
67
#endif
68
69
	uTCHAR last_open_path[LENGTH_FILE_NAME_MAX];
70
	uTCHAR last_open_patch_path[LENGTH_FILE_NAME_MAX];
71
72
	//int8_t cpu_cores;
73
74
	uint8_t start;
75
	uint8_t in_update;
76
77
	// lost focus pause
78
	uint8_t main_win_lfp;
79
80
	int dlg_rc;
81
} gui;
82
EXTERNC struct _gui_mouse {
83
	int x;
84
	int y;
85
	uint8_t left;
86
	uint8_t right;
87
88
	uint8_t hidden;
89
90
	double timer;
91
} gmouse;
92
EXTERNC struct _external_windows {
93
	uint8_t vs_system;
94
} ext_win;
95
96
EXTERNC void gui_quit(void);
97
EXTERNC BYTE gui_create(void);
98
EXTERNC void gui_start(void);
99
100
EXTERNC void gui_set_video_mode(void);
101
102
EXTERNC void gui_update(void);
103
EXTERNC void gui_update_gps_settings(void);
104
105
EXTERNC void gui_fullscreen(void);
106
EXTERNC void gui_save_slot(BYTE slot);
107
108
EXTERNC void gui_print_usage(char *usage);
109
EXTERNC int gui_uncompress_selection_dialog(_uncompress_archive *archive, BYTE type);
110
111
EXTERNC void gui_control_pause_bck(WORD event);
112
113
EXTERNC void gui_active_window(void);
114
EXTERNC void gui_set_focus(void);
115
116
EXTERNC void *gui_objcheat_get_ptr(void);
117
EXTERNC void gui_objcheat_init(void);
118
EXTERNC void gui_objcheat_read_game_cheats(void);
119
120
EXTERNC void gui_cursor_init(void);
121
EXTERNC void gui_cursor_set(void);
122
EXTERNC void gui_cursor_hide(BYTE hide);
123
EXTERNC void gui_control_visible_cursor(void);
124
125
EXTERNC void *gui_mainwindow_get_ptr(void);
126
127
EXTERNC void *gui_wdgrewind_get_ptr(void);
128
EXTERNC void gui_wdgrewind_play(void);
129
130
EXTERNC void gui_emit_et_gg_reset(void);
131
EXTERNC void gui_emit_et_vs_reset(void);
132
EXTERNC void gui_emit_et_external_control_windows_show(void);
133
134
EXTERNC void gui_screen_update(void);
135
136
EXTERNC void *gui_dlgsettings_get_ptr(void);
137
138
EXTERNC void *gui_dlgdebugger_get_ptr(void);
139
EXTERNC void gui_dlgdebugger_click_step(void);
140
141
EXTERNC void gui_external_control_windows_show(void);
142
EXTERNC void gui_external_control_windows_update_pos(void);
143
144
EXTERNC void gui_vs_system_update_dialog(void);
145
EXTERNC void gui_vs_system_insert_coin(void);
146
147
EXTERNC void gui_apu_channels_widgets_update(void);
148
149
EXTERNC void gui_ppu_hacks_widgets_update(void);
150
151
#if defined (WITH_OPENGL)
152
EXTERNC void gui_wdgopengl_make_current(void);
153
EXTERNC unsigned int gui_wdgopengl_framebuffer_id(void);
154
155
EXTERNC void gui_screen_info(void);
156
157
EXTERNC uint32_t gui_color(BYTE a, BYTE r, BYTE g, BYTE b);
158
#endif
159
160
EXTERNC BYTE gui_load_lut(void *l, const uTCHAR *path);
161
EXTERNC void gui_save_screenshot(int w, int h, char *buffer, BYTE flip);
162
163
EXTERNC void gui_utf_printf(const uTCHAR *fmt, ...);
164
EXTERNC void gui_utf_dirname(uTCHAR *path, uTCHAR *dst, size_t len);
165
EXTERNC void gui_utf_basename(uTCHAR *path, uTCHAR *dst, size_t len);
166
EXTERNC int gui_utf_strcasecmp(uTCHAR *s0, uTCHAR *s1);
167
168
EXTERNC double (*gui_get_ms)(void);
169
170
EXTERNC void gui_init(int *argc, char **argv);
171
EXTERNC void gui_sleep(double ms);
172
#if defined (_WIN32)
173
EXTERNC HWND gui_screen_id(void);
174
#else
175
EXTERNC int gui_screen_id(void);
176
#endif
177
178
//EXTERNC void gui_add_event(void *funct, void *args);
179
//EXTERNC void gui_set_thread_affinity(uint8_t core);
180
181
#undef EXTERNC
182
183
#endif /* QT_H_ */
(-)puNES-0.105.org/src/gui/recent_roms.cpp (-2 lines)
Lines 23-32 Link Here
23
#include "recent_roms.h"
23
#include "recent_roms.h"
24
#include "info.h"
24
#include "info.h"
25
#include "conf.h"
25
#include "conf.h"
26
#include "cheat.h"
27
#include "settings.h"
26
#include "settings.h"
28
#include "gui.h"
27
#include "gui.h"
29
#include "uncompress.h"
30
28
31
#define RECENT_ROMS_FILE "recent.cfg"
29
#define RECENT_ROMS_FILE "recent.cfg"
32
30
(-)puNES-0.105.org/src/gui/settings.h (+1 lines)
Lines 30-35 Link Here
30
#include "input.h"
30
#include "input.h"
31
#include "nsf.h"
31
#include "nsf.h"
32
#include "rewind.h"
32
#include "rewind.h"
33
#include "palette.h"
33
34
34
#if defined (_WIN32)
35
#if defined (_WIN32)
35
#define NEWLINE "\r\n"
36
#define NEWLINE "\r\n"
(-)puNES-0.105.org/src/gui/tas.h (-14 / +15 lines)
Lines 32-45 typedef struct _tas_input_log { Link Here
32
	BYTE state;
32
	BYTE state;
33
	BYTE port[PORT_MAX][8];
33
	BYTE port[PORT_MAX][8];
34
} _tas_input_log;
34
} _tas_input_log;
35
35
typedef struct _tas {
36
#if defined (__cplusplus)
37
#define EXTERNC extern "C"
38
#else
39
#define EXTERNC
40
#endif
41
42
EXTERNC struct _tas {
43
	uTCHAR file[LENGTH_FILE_NAME_LONG];
36
	uTCHAR file[LENGTH_FILE_NAME_LONG];
44
	FILE *fp;
37
	FILE *fp;
45
	uint8_t emulator;
38
	uint8_t emulator;
Lines 54-60 EXTERNC struct _tas { Link Here
54
	int32_t frame;
47
	int32_t frame;
55
	uint32_t total_lag_frames;
48
	uint32_t total_lag_frames;
56
	_tas_input_log il[TAS_CACHE];
49
	_tas_input_log il[TAS_CACHE];
57
} tas;
50
} _tas;
51
52
extern _tas tas;
53
54
extern void (*tas_header)(uTCHAR *file);
55
extern void (*tas_read)(void);
56
extern void (*tas_frame)(void);
57
extern void (*tas_rewind)(int32_t frames_to_rewind);
58
59
#if defined (__cplusplus)
60
#define EXTERNC extern "C"
61
#else
62
#define EXTERNC
63
#endif
58
64
59
EXTERNC BYTE tas_file(uTCHAR *ext, uTCHAR *file);
65
EXTERNC BYTE tas_file(uTCHAR *ext, uTCHAR *file);
60
EXTERNC void tas_quit(void);
66
EXTERNC void tas_quit(void);
Lines 64-74 EXTERNC void tas_read_FM2(void); Link Here
64
EXTERNC void tas_frame_FM2(void);
70
EXTERNC void tas_frame_FM2(void);
65
EXTERNC void tas_rewind_FM2(int32_t frames_to_rewind);
71
EXTERNC void tas_rewind_FM2(int32_t frames_to_rewind);
66
72
67
EXTERNC void (*tas_header)(uTCHAR *file);
68
EXTERNC void (*tas_read)(void);
69
EXTERNC void (*tas_frame)(void);
70
EXTERNC void (*tas_rewind)(int32_t frames_to_rewind);
71
72
#undef EXTERNC
73
#undef EXTERNC
73
74
74
#endif /* TAS_H_ */
75
#endif /* TAS_H_ */
(-)puNES-0.105.org/src/gui/wdgOpenGL.hpp (-2 / +4 lines)
Lines 19-29 Link Here
19
#ifndef WDGOPENGL_HPP_
19
#ifndef WDGOPENGL_HPP_
20
#define WDGOPENGL_HPP_
20
#define WDGOPENGL_HPP_
21
21
22
#include <QtWidgets/QWidget>
23
#if defined (_WIN32)
22
// gui.h e' importante che stia in mezzo per non
24
// gui.h e' importante che stia in mezzo per non
23
// avere problemi di compilazione legati ai vari
25
// avere problemi di compilazione legati ai vari
24
// nested #include nella versione Windows
26
// nested #include nella versione Windows
25
#include <QtWidgets/QWidget>
27
#include "win.h"
26
#include "gui.h"
28
#endif
27
#include <QtWidgets/QOpenGLWidget>
29
#include <QtWidgets/QOpenGLWidget>
28
#include <QtCore/QElapsedTimer>
30
#include <QtCore/QElapsedTimer>
29
31
(-)puNES-0.105.org/src/gui/wdgSettingsInput.cpp (-1 lines)
Lines 27-33 Link Here
27
#include "dlgSettings.hpp"
27
#include "dlgSettings.hpp"
28
#include "dlgStdPad.hpp"
28
#include "dlgStdPad.hpp"
29
#include "emu_thread.h"
29
#include "emu_thread.h"
30
#include "conf.h"
31
30
32
typedef struct _cb_ports {
31
typedef struct _cb_ports {
33
	QString desc;
32
	QString desc;
(-)puNES-0.105.org/src/gui/windows/jstick.c (+2 lines)
Lines 325-330 struct _jstick { Link Here
325
	DWORD (WINAPI *XInputGetCapabilities_proc)(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES *pCapabilities);
325
	DWORD (WINAPI *XInputGetCapabilities_proc)(DWORD dwUserIndex, DWORD dwFlags, XINPUT_CAPABILITIES *pCapabilities);
326
} jstick;
326
} jstick;
327
327
328
_js js[PORT_MAX], js_shcut;
329
328
void js_init(BYTE first_time) {
330
void js_init(BYTE first_time) {
329
	int i;
331
	int i;
330
332
(-)puNES-0.105.org/src/gui/windows/jstick.h (-7 / +7 lines)
Lines 58-69 typedef struct _js_sch { Link Here
58
	BYTE mode;
58
	BYTE mode;
59
} _js_sch;
59
} _js_sch;
60
60
61
#if defined (__cplusplus)
62
#define EXTERNC extern "C"
63
#else
64
#define EXTERNC
65
#endif
66
67
static const _js_element jsn_list[] = { { 0xFF, uL("NULL") } };
61
static const _js_element jsn_list[] = { { 0xFF, uL("NULL") } };
68
static const _js_element jsv_list[] = {
62
static const _js_element jsv_list[] = {
69
	{ 0x000, uL("NULL")    },
63
	{ 0x000, uL("NULL")    },
Lines 98-104 static const _js_element jsv_list[] = { Link Here
98
	{ 0x41E, uL("JB30")    }, { 0x41F, uL("JB31")    }
92
	{ 0x41E, uL("JB30")    }, { 0x41F, uL("JB31")    }
99
};
93
};
100
94
101
EXTERNC _js js[PORT_MAX], js_shcut;
95
extern _js js[PORT_MAX], js_shcut;
96
97
#if defined (__cplusplus)
98
#define EXTERNC extern "C"
99
#else
100
#define EXTERNC
101
#endif
102
102
103
EXTERNC void js_init(BYTE first_time);
103
EXTERNC void js_init(BYTE first_time);
104
EXTERNC void js_quit(BYTE last_time);
104
EXTERNC void js_quit(BYTE last_time);
(-)puNES-0.105.org/src/video/d3d9/d3d9.c (-1 / +2 lines)
Lines 20-26 Link Here
20
 */
20
 */
21
21
22
#include "d3d9.h"
22
#include "d3d9.h"
23
#include "video/gfx_thread.h"
24
#include "info.h"
23
#include "info.h"
25
#include "gui.h"
24
#include "gui.h"
26
#include "conf.h"
25
#include "conf.h"
Lines 56-61 INLINE D3DTEXTUREFILTERTYPE d3d9_shader_ Link Here
56
INLINE static void d3d9_shader_params_text_set(_shader *shd);
55
INLINE static void d3d9_shader_params_text_set(_shader *shd);
57
INLINE static void d3d9_shader_param_set(const _texture *texture, UINT fcountmod, UINT fcount);
56
INLINE static void d3d9_shader_param_set(const _texture *texture, UINT fcountmod, UINT fcount);
58
57
58
_d3d9 d3d9;
59
59
BYTE d3d9_init(void) {
60
BYTE d3d9_init(void) {
60
	memset(&d3d9, 0x00, sizeof(d3d9));
61
	memset(&d3d9, 0x00, sizeof(d3d9));
61
62
(-)puNES-0.105.org/src/video/d3d9/d3d9.c.orig (+1899 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *  for some codes :
4
 *  Copyright (C) 2010-2015 The RetroArch team
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 *
20
 */
21
22
#include "d3d9.h"
23
#include "video/gfx_thread.h"
24
#include "info.h"
25
#include "gui.h"
26
#include "conf.h"
27
#include "ppu.h"
28
#include "overscan.h"
29
30
#define _SCR_ROWS_BRD\
31
	((float)(SCR_ROWS - (overscan.borders->left + overscan.borders->right)) * gfx.pixel_aspect_ratio)
32
#define _SCR_LINES_BRD\
33
	(float)(SCR_LINES - (overscan.borders->up + overscan.borders->down))
34
#define _SCR_ROWS_NOBRD\
35
	((float)SCR_ROWS * gfx.pixel_aspect_ratio)
36
#define _SCR_LINES_NOBRD\
37
	(float)SCR_LINES
38
39
static void d3d9_shader_cg_error_handler(void);
40
static BYTE d3d9_device_create(UINT width, UINT height);
41
static void d3d9_context_delete(void);
42
static BYTE d3d9_texture_create(_texture *texture, UINT index);
43
static BYTE d3d9_texture_simple_create(_texture_simple *texture, UINT w, UINT h, BOOL text);
44
static BYTE d3d9_texture_lut_create(_lut *lut, UINT index);
45
static void d3d9_surface_clean(LPDIRECT3DSURFACE9 *surface, UINT width, UINT height);
46
static BYTE d3d9_shader_init(UINT pass, _shader *shd, const uTCHAR *path, const char *code);
47
static void d3d9_shader_delete(_shader *shd);
48
static void d3d9_shader_uniform_ctrl(CGparameter *dst, CGparameter *param, const char *semantic);
49
static void d3d9_shader_uni_texture_clear(_shader_uniforms_tex *sut);
50
static void d3d9_shader_uni_texture(_shader_uniforms_tex *sut, _shader_prg_cg *prg, char *fmt, ...);
51
static CGparameter d3d9_cg_find_param(CGparameter prm, const char *name);
52
static BYTE d3d9_vertex_declaration_create(_shader *shd);
53
static void d3d9_vertex_buffer_set(_shader *shd,  _viewport *vp, _texture_rect *prev);
54
INLINE static void d3d9_viewport_set(DWORD x, DWORD y, DWORD w, DWORD h);
55
INLINE D3DTEXTUREFILTERTYPE d3d9_shader_filter(UINT type);
56
INLINE static void d3d9_shader_params_text_set(_shader *shd);
57
INLINE static void d3d9_shader_param_set(const _texture *texture, UINT fcountmod, UINT fcount);
58
59
BYTE d3d9_init(void) {
60
	memset(&d3d9, 0x00, sizeof(d3d9));
61
62
	if ((d3d9.d3d = Direct3DCreate9(D3D_SDK_VERSION)) == NULL) {
63
		MessageBox(NULL, "Unable to create d3d object", "Error!", MB_ICONEXCLAMATION | MB_OK);
64
		return (EXIT_ERROR);
65
	}
66
67
	// mi passo in rassegna tutti gli adapter presenti sul sistema
68
	d3d9.adapters_on_system = IDirect3D9_GetAdapterCount(d3d9.d3d);
69
70
	if (!(d3d9.array = malloc(d3d9.adapters_on_system * sizeof(_d3d9_adapter)))) {
71
		MessageBox(NULL, "Unable to create devices array", "Error!", MB_ICONEXCLAMATION | MB_OK);
72
		return (EXIT_ERROR);
73
	}
74
75
	{
76
		unsigned int adapt;
77
78
#define dev_error(s) fprintf(stderr, "D3D9 adapter %d : "s, dev->id)
79
#define dev_info(s) printf("D3D9 adapter %d : "s, dev->id)
80
#define dev_info_args(s, ...) printf("D3D9 adapter %d : "s, dev->id, __VA_ARGS__)
81
82
		for (adapt = 0; adapt < d3d9.adapters_on_system; adapt++) {
83
			_d3d9_adapter *dev = D3D9_ADAPTER(d3d9.adapters_in_use);
84
			D3DADAPTER_IDENTIFIER9 info;
85
			D3DCAPS9 d3dcaps;
86
87
			memset(dev, 0x00, sizeof(_d3d9_adapter));
88
89
			dev->id = adapt;
90
91
			if (IDirect3D9_GetAdapterIdentifier(d3d9.d3d, dev->id, 0, &info)!= D3D_OK) {
92
				dev_error("unable to get adapter display info\n");
93
				continue;
94
			}
95
96
			dev_info_args("%s\n", info.Description);
97
98
			if (IDirect3D9_GetAdapterDisplayMode(d3d9.d3d, dev->id, &dev->display_mode) != D3D_OK) {
99
				dev_error("unable to get adapter display mode\n");
100
				continue;
101
			}
102
103
			if ((dev->display_mode.Format == D3DFMT_X8R8G8B8) ||
104
				(dev->display_mode.Format == D3DFMT_A8R8G8B8)) {
105
				dev->bit_per_pixel = 32;
106
			}
107
			if (dev->bit_per_pixel < 32) {
108
				dev_error("video mode < 32 bits are not supported\n");
109
				continue;
110
			}
111
112
			// Check for hardware T&L
113
			if (IDirect3D9_GetDeviceCaps(d3d9.d3d, dev->id, D3DDEVTYPE_HAL, &d3dcaps) != D3D_OK) {
114
				dev_error("unable to get device caps\n");
115
				continue;
116
			}
117
118
			if (d3dcaps.Caps2 & D3DCAPS2_DYNAMICTEXTURES) {
119
				dev->dynamic_texture = TRUE;
120
			} else {
121
				dev->dynamic_texture = FALSE;
122
				dev_info("don't support dynamic texture\n");
123
			}
124
125
			if (d3dcaps.TextureCaps & D3DPTEXTURECAPS_SQUAREONLY) {
126
				dev->texture_square_only = TRUE;
127
				dev_info("support only square texture\n");
128
			} else {
129
				dev->texture_square_only = FALSE;
130
			}
131
132
		 	// Device can accelerate a memory copy from system memory to local video memory.
133
		 	// This cap guarantees that UpdateSurface and UpdateTexture calls will be hardware
134
		 	// accelerated. If this cap is absent, these calls will succeed but will be slower.
135
			if (!(d3dcaps.Caps3 & D3DCAPS3_COPY_TO_VIDMEM)) {
136
				dev_info("don't support accelerated texture update\n");
137
			}
138
139
			if (d3dcaps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
140
				dev->flags = D3DCREATE_HARDWARE_VERTEXPROCESSING;
141
				// se abilito il PURE DEVICE, non posso utilizzare il
142
				// IDirect3DDevice9_GetTransform quando uso le shaders.
143
				if (d3dcaps.DevCaps & D3DDEVCAPS_PUREDEVICE) {
144
					dev->flags |= D3DCREATE_PUREDEVICE;
145
				}
146
			} else {
147
				dev_info("don't support hardware accelaration\n");
148
				dev->flags = D3DCREATE_SOFTWARE_VERTEXPROCESSING;
149
			}
150
151
			if (!(d3dcaps.MaxSimultaneousTextures > 1)) { //number of textures
152
				dev_info("single pass multitexturing not supported\n");
153
			} else {
154
				dev_info_args("MaxSimultaneousTextures %ld\n", d3dcaps.MaxSimultaneousTextures);
155
			}
156
157
			dev->number_of_monitors = d3dcaps.NumberOfAdaptersInGroup;
158
159
			//if (dev->number_of_monitors > 1) {
160
				dev_info_args("MasterAdapterOrdinal    %d\n", d3dcaps.MasterAdapterOrdinal);
161
				dev_info_args("AdapterOrdinalInGroup   %d\n", d3dcaps.AdapterOrdinalInGroup);
162
				dev_info_args("NumberOfAdaptersInGroup %d\n", dev->number_of_monitors);
163
				//dev->flags |= D3DCREATE_ADAPTERGROUP_DEVICE;
164
			//}
165
166
			{
167
				d3d9.adapter = dev;
168
169
				// per poter verificare se le shaders sono utilizzabili devo creare il dev d3d
170
				if (d3d9_device_create(1, 1) != EXIT_OK) {
171
					continue;
172
				}
173
174
				dev->hlsl_compliant = FALSE;
175
176
				if (d3dcaps.PixelShaderVersion < D3DPS_VERSION(2, 0) ||
177
					(d3dcaps.VertexShaderVersion < D3DVS_VERSION(2, 0))) {
178
					dev_info("don't support shaders >= 2.0\n");
179
				} else {
180
					dev->hlsl_compliant = TRUE;
181
				}
182
183
				if (dev->hlsl_compliant == FALSE) {
184
					dev_info("shaders are not supported\n");
185
				}
186
187
				d3d9.adapter = NULL;
188
			}
189
190
			d3d9.adapters_in_use++;
191
		}
192
193
#undef dev_error
194
#undef dev_info
195
#undef dev_info_args
196
	}
197
198
	if (d3d9.adapters_in_use == 0) {
199
		MessageBox(NULL, "Unable find usable adapter", "Error!", MB_ICONEXCLAMATION | MB_OK);
200
		return (EXIT_ERROR);
201
	}
202
203
	d3d9.adapter = D3D9_ADAPTER(0);
204
	if (d3d9.adapter->hlsl_compliant == FALSE) {
205
		MessageBox(NULL, "Adapter is not hlsl compliant", "Error!", MB_ICONEXCLAMATION | MB_OK);
206
		return (EXIT_ERROR);
207
	}
208
209
	gfx.bit_per_pixel = d3d9.adapter->bit_per_pixel;
210
211
	return (EXIT_OK);
212
}
213
BYTE d3d9_context_create(void) {
214
	D3DXMATRIX identity;
215
	WORD w, h;
216
	UINT i;
217
218
	d3d9_context_delete();
219
220
	if (overscan.enabled && (!cfg->oscan_black_borders && !cfg->fullscreen)) {
221
		// visto che lavorero' con texture piu' grandi del video mode
222
		// setto un backbuffer piu' grande.
223
		w = gfx.w[VIDEO_MODE] * 2;
224
		h = gfx.h[VIDEO_MODE] * 2;
225
	} else {
226
		w = gfx.w[VIDEO_MODE];
227
		h = gfx.h[VIDEO_MODE];
228
	}
229
230
	if (d3d9_device_create(w, h) == EXIT_ERROR) {
231
		d3d9_context_delete();
232
		return (EXIT_ERROR);
233
	}
234
235
	if ((d3d9.cgctx = cgCreateContext()) == NULL) {
236
		d3d9_context_delete();
237
		return (EXIT_ERROR);
238
	}
239
240
	cgSetErrorCallback(d3d9_shader_cg_error_handler);
241
242
	cgD3D9SetDevice(d3d9.adapter->dev);
243
244
	w = gfx.w[PASS0];
245
	h = gfx.h[PASS0];
246
247
	D3DXMatrixIdentity(&identity);
248
	IDirect3DDevice9_SetTransform(d3d9.adapter->dev, D3DTS_WORLD, &identity);
249
	IDirect3DDevice9_SetTransform(d3d9.adapter->dev, D3DTS_VIEW, &identity);
250
251
	// screen
252
	d3d9_texture_simple_create(&d3d9.screen.tex[0], w, h, FALSE);
253
254
	// lut (devo farlo prima di elaborare le shaders)
255
	for (i = 0; i < shader_effect.luts; i++) {
256
		if (d3d9_texture_lut_create(&d3d9.lut[i], i) == EXIT_ERROR) {
257
			d3d9_context_delete();
258
			return (EXIT_ERROR_SHADER);
259
		}
260
	}
261
262
	// devo precalcolarmi il viewport finale
263
	{
264
		_viewport *vp = &gfx.vp;
265
266
		vp->x = 0;
267
		vp->y = 0;
268
		vp->w = gfx.w[VIDEO_MODE];
269
		vp->h = gfx.h[VIDEO_MODE];
270
271
		if (overscan.enabled && (!cfg->oscan_black_borders && !cfg->fullscreen)) {
272
			vp->x = (-overscan.borders->left * gfx.width_pixel) * gfx.pixel_aspect_ratio;
273
			vp->y = (-overscan.borders->up * cfg->scale);
274
			vp->w = gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio;
275
			vp->h = gfx.h[NO_OVERSCAN];
276
		}
277
278
		// configuro l'aspect ratio del fullscreen
279
		if (cfg->fullscreen) {
280
			if (!cfg->stretch) {
281
				if (cfg->integer_scaling) {
282
					int mw = _SCR_ROWS_NOBRD;
283
					int mh = _SCR_LINES_NOBRD;
284
					int mul = gfx.w[VIDEO_MODE] > gfx.h[VIDEO_MODE] ?
285
						(gfx.h[VIDEO_MODE] - (gfx.h[VIDEO_MODE] % mh)) / mh :
286
						(gfx.w[VIDEO_MODE] - (gfx.w[VIDEO_MODE] % mw)) / mw;
287
288
					vp->w = mw * mul;
289
					vp->h = mh * mul;
290
				} else {
291
					float mw = _SCR_ROWS_NOBRD;
292
					float mh = _SCR_LINES_NOBRD;
293
					float mul = mw / mh ;
294
295
					if (gfx.w[VIDEO_MODE] > gfx.h[VIDEO_MODE]) {
296
						vp->w = (int)((float)gfx.h[VIDEO_MODE] * mul);
297
					} else {
298
						vp->h = (int)((float)gfx.w[VIDEO_MODE] / mul);
299
					}
300
				}
301
				vp->x = (gfx.w[VIDEO_MODE] - vp->w) >> 1;
302
				vp->y = (gfx.h[VIDEO_MODE] - vp->h) >> 1;
303
			}
304
305
			if (overscan.enabled && (cfg->oscan_black_borders_fscr == FALSE)) {
306
				float brd_l_x, brd_r_x, brd_u_y, brd_d_y;
307
				float ratio_x, ratio_y;
308
309
				ratio_x = (float)vp->w / _SCR_ROWS_NOBRD;
310
				ratio_y = (float)vp->h / _SCR_LINES_NOBRD;
311
				brd_l_x = (float)overscan.borders->left * ratio_x;
312
				brd_r_x = (float)overscan.borders->right * ratio_x;
313
				brd_u_y = (float)overscan.borders->up * ratio_y;
314
				brd_d_y = (float)overscan.borders->down * ratio_y;
315
316
				d3d9.viewp.left = brd_l_x;
317
				d3d9.viewp.top = brd_u_y;
318
				d3d9.viewp.right = gfx.w[VIDEO_MODE] - brd_r_x;
319
				d3d9.viewp.bottom = gfx.h[VIDEO_MODE] - brd_d_y;
320
			} else {
321
				d3d9.viewp.left = 0;
322
				d3d9.viewp.top = 0;
323
				d3d9.viewp.right = gfx.w[VIDEO_MODE];
324
				d3d9.viewp.bottom = gfx.h[VIDEO_MODE];
325
			}
326
		} else {
327
			d3d9.viewp.left = -vp->x;
328
			d3d9.viewp.top = -vp->y;
329
			d3d9.viewp.right = gfx.w[VIDEO_MODE] + d3d9.viewp.left;
330
			d3d9.viewp.bottom = gfx.h[VIDEO_MODE] + d3d9.viewp.top;
331
		}
332
	}
333
334
	// texture
335
	for (i = 0; i < shader_effect.pass; i++) {
336
		fprintf(stderr, "D3D9: Setting pass %d.\n", i);
337
338
		if (d3d9_texture_create(&d3d9.texture[i], i) == EXIT_ERROR) {
339
			d3d9_context_delete();
340
			return (EXIT_ERROR);
341
		}
342
343
		if (d3d9_shader_init(i, &d3d9.texture[i].shader, shader_effect.sp[i].path, shader_effect.sp[i].code) == EXIT_ERROR) {
344
			d3d9_context_delete();
345
			return (EXIT_ERROR_SHADER);
346
		}
347
	}
348
349
	// PREV (calcolo il numero di screen da utilizzare)
350
	// deve essere fatto dopo il d3d9_shader_init().
351
	for (i = 0; i < shader_effect.pass; i++) {
352
		UINT a;
353
354
		for (a = 0; a < LENGTH(d3d9.texture[i].shader.uni.prev); a++) {
355
			if (d3d9.texture[i].shader.uni.prev[a].f.texture) {
356
				if (d3d9.screen.in_use < (a + 1)) {
357
					d3d9.screen.in_use = (a + 1);
358
				}
359
			}
360
		}
361
	}
362
363
	d3d9.screen.in_use++;
364
365
	// PREV
366
	for (i = 1; i < d3d9.screen.in_use; i++) {
367
		d3d9_texture_simple_create(&d3d9.screen.tex[i], w, h, FALSE);
368
	}
369
370
	// FEEDBACK
371
	if ((shader_effect.feedback_pass >= 0) && (shader_effect.feedback_pass < shader_effect.pass)) {
372
		d3d9.feedback.in_use = TRUE;
373
374
		if (d3d9_texture_create(&d3d9.feedback.tex, shader_effect.feedback_pass) == EXIT_ERROR) {
375
			d3d9_context_delete();
376
			return (EXIT_ERROR);
377
		}
378
	}
379
380
	// testo
381
	{
382
		int tw, th;
383
384
		// setto il necessario per il blending
385
		IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_BLENDOP, D3DBLENDOP_ADD);
386
		IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_SRCBLEND, D3DBLEND_SRCALPHA);
387
		IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA);
388
389
		if (cfg->fullscreen) {
390
			float div = (float)gfx.w[VIDEO_MODE] / 1024.0f;
391
392
			if (div < 1.0f) {
393
				div = 1.0f;
394
			}
395
396
			tw = gfx.w[VIDEO_MODE] / div;
397
			th = gfx.h[VIDEO_MODE] / div;
398
		} else if (cfg->scale == 1) {
399
			tw = gfx.w[VIDEO_MODE];
400
			th = gfx.h[VIDEO_MODE];
401
		} else {
402
			tw = _SCR_ROWS_NOBRD * 2;
403
			th = _SCR_LINES_NOBRD * 2;
404
		}
405
406
		d3d9_texture_simple_create(&d3d9.text, tw, th, TRUE);
407
408
		text.w = d3d9.text.rect.w;
409
		text.h = d3d9.text.rect.h;
410
411
		gfx_text_reset();
412
413
		fprintf(stderr, "D3D9: Setting text pass.\n");
414
415
		if (d3d9_shader_init(0, &d3d9.text.shader, NULL, shader_code_blend()) == EXIT_ERROR) {
416
			d3d9_context_delete();
417
			return (EXIT_ERROR);
418
		}
419
	}
420
421
	// setto tutto quello che mi serve per il rendering
422
	for (i = 0; i < shader_effect.pass; i++) {
423
		_texture *texture = &d3d9.texture[i];
424
		_shader *shd = &texture->shader;
425
		_texture_rect *prev = NULL;
426
427
		if (i == 0) {
428
			prev = &d3d9.screen.tex[0].rect;
429
		} else {
430
			prev = &d3d9.texture[i - 1].rect;
431
		}
432
433
		shd->info.video_size.x = (FLOAT)prev->base.w;
434
		shd->info.video_size.y = (FLOAT)prev->base.h;
435
		shd->info.texture_size.x = prev->w,
436
		shd->info.texture_size.y = prev->h;
437
		shd->info.output_size.x = (FLOAT)texture->vp.w;
438
		shd->info.output_size.y = (FLOAT)texture->vp.h;
439
440
		d3d9_vertex_buffer_set(shd, &texture->vp, prev);
441
	}
442
443
	umemcpy(gfx.last_shader_file, cfg->shader_file, usizeof(gfx.last_shader_file));
444
445
	return (EXIT_OK);
446
}
447
void d3d9_draw_scene(void) {
448
	const _texture_simple *scrtex = &d3d9.screen.tex[d3d9.screen.index];
449
	LPDIRECT3DSURFACE9 back_buffer;
450
	UINT i;
451
452
	if (gui.start == FALSE) {
453
		return;
454
	}
455
456
	IDirect3DDevice9_GetRenderTarget(d3d9.adapter->dev, 0, &back_buffer);
457
458
	// texture
459
	for (i = 0; i < shader_effect.pass; i++) {
460
		const _texture *texture = &d3d9.texture[i];
461
		const _shader_pass *sp = &shader_effect.sp[i];
462
		D3DTEXTUREFILTERTYPE filter = d3d9_shader_filter(sp->linear);
463
464
		shader_effect.running_pass = i;
465
466
		if (i == shader_effect.last_pass) {
467
			IDirect3DDevice9_SetRenderTarget(d3d9.adapter->dev, 0, back_buffer);
468
			// pulisco l'intero schermo
469
			d3d9_viewport_set(0, 0, gfx.w[VIDEO_MODE], gfx.h[VIDEO_MODE]);
470
		} else {
471
			IDirect3DDevice9_SetRenderTarget(d3d9.adapter->dev, 0, texture->map0);
472
			// pulisco l'fbo
473
			d3d9_viewport_set(0, 0, texture->rect.w, texture->rect.h);
474
		}
475
		IDirect3DDevice9_Clear(d3d9.adapter->dev, 0, NULL, D3DCLEAR_TARGET,
476
			D3DCOLOR_ARGB(255, 0, 0, 0), 1.0f, 0);
477
478
		// ora setto il viewport corretto
479
		if (cfg->fullscreen) {
480
			d3d9_viewport_set(texture->vp.x, texture->vp.y, texture->vp.w, texture->vp.h);
481
		} else {
482
			d3d9_viewport_set(0, 0, texture->vp.w, texture->vp.h);
483
		}
484
485
		cgD3D9BindProgram(texture->shader.prg.f);
486
		cgD3D9BindProgram(texture->shader.prg.v);
487
488
		if (i == 0) {
489
			IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 * )scrtex->data);
490
		} else {
491
			IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 * )d3d9.texture[i - 1].data);
492
		}
493
494
		IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MAGFILTER, filter);
495
		IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MINFILTER, filter);
496
497
		IDirect3DDevice9_SetVertexDeclaration(d3d9.adapter->dev, texture->shader.vd);
498
499
		d3d9_shader_param_set(texture, sp->frame_count_mod, ppu.frames);
500
501
		IDirect3DDevice9_BeginScene(d3d9.adapter->dev);
502
		IDirect3DDevice9_DrawPrimitive(d3d9.adapter->dev, D3DPT_TRIANGLESTRIP, 0, 2);
503
		IDirect3DDevice9_EndScene(d3d9.adapter->dev);
504
	}
505
506
	IDirect3DSurface9_Release(back_buffer);
507
508
	d3d9.screen.index = ((d3d9.screen.index + 1) % d3d9.screen.in_use);
509
510
	if (d3d9.feedback.in_use) {
511
		LPDIRECT3DTEXTURE9 data = d3d9.feedback.tex.data;
512
		LPDIRECT3DSURFACE9 map0 = d3d9.feedback.tex.map0;
513
514
		d3d9.feedback.tex.data = d3d9.texture[shader_effect.feedback_pass].data;
515
		d3d9.feedback.tex.map0 = d3d9.texture[shader_effect.feedback_pass].map0;
516
		d3d9.texture[shader_effect.feedback_pass].data = data;
517
		d3d9.texture[shader_effect.feedback_pass].map0 = map0;
518
	}
519
520
	// rendering del testo
521
	text_rendering(TRUE);
522
523
	// text
524
	if (cfg->txt_on_screen && text.on_screen) {
525
		float vpx, vpy, vpw, vph;
526
527
		// aggiorno la texture del testo
528
		IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, d3d9.text.offscreen, NULL, d3d9.text.map0, NULL);
529
530
		vpx = d3d9.viewp.left * gfx.device_pixel_ratio;
531
		vpy = d3d9.viewp.top * gfx.device_pixel_ratio;
532
		vpw = (d3d9.viewp.right - d3d9.viewp.left) * gfx.device_pixel_ratio;
533
		vph = (d3d9.viewp.bottom - d3d9.viewp.top) * gfx.device_pixel_ratio;
534
535
		d3d9_viewport_set(vpx, vpy, vpw, vph);
536
537
		cgD3D9BindProgram(d3d9.text.shader.prg.f);
538
		cgD3D9BindProgram(d3d9.text.shader.prg.v);
539
540
		IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *)d3d9.text.data);
541
542
		IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MAGFILTER, D3DTEXF_LINEAR);
543
		IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MINFILTER, D3DTEXF_LINEAR);
544
545
		IDirect3DDevice9_SetVertexDeclaration(d3d9.adapter->dev, d3d9.text.shader.vd);
546
547
		d3d9_shader_params_text_set(&d3d9.text.shader);
548
549
		IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_ALPHABLENDENABLE, TRUE);
550
		IDirect3DDevice9_BeginScene(d3d9.adapter->dev);
551
		IDirect3DDevice9_DrawPrimitive(d3d9.adapter->dev, D3DPT_TRIANGLESTRIP, 0, 2);
552
		IDirect3DDevice9_EndScene(d3d9.adapter->dev);
553
		IDirect3DDevice9_SetRenderState(d3d9.adapter->dev, D3DRS_ALPHABLENDENABLE, FALSE);
554
	}
555
556
	IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL);
557
558
	// swap buffers
559
	{
560
		if (IDirect3DDevice9_Present(d3d9.adapter->dev, &d3d9.viewp, NULL, NULL, NULL) == D3DERR_DEVICELOST) {
561
			if (IDirect3DDevice9_TestCooperativeLevel(d3d9.adapter->dev) == D3DERR_DEVICENOTRESET) {
562
				emu_pause(TRUE);
563
564
				if (d3d9_context_create() == EXIT_ERROR) {
565
					fprintf(stderr, "D3D9 : Unable to initialize d3d context\n");
566
				}
567
568
				emu_pause(FALSE);
569
			}
570
		}
571
572
		// screenshot
573
		if (gfx.save_screenshot == TRUE) {
574
			IDirect3DSurface9 *back_buffer, *surface;
575
576
			if (IDirect3DDevice9_GetBackBuffer(d3d9.adapter->dev, 0, 0, D3DBACKBUFFER_TYPE_MONO, &back_buffer) == D3D_OK) {
577
				D3DSURFACE_DESC sd;
578
579
				IDirect3DSurface9_GetDesc(back_buffer, &sd);
580
581
				if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev, sd.Width,
582
					sd.Height, sd.Format, D3DPOOL_SYSTEMMEM, &surface, NULL) == D3D_OK) {
583
					if (IDirect3DDevice9_GetRenderTargetData(d3d9.adapter->dev, back_buffer, surface) == D3D_OK) {
584
						D3DLOCKED_RECT lrect;
585
586
						if (overscan.enabled && ((!cfg->fullscreen && !cfg->oscan_black_borders) ||
587
							(cfg->fullscreen && !cfg->oscan_black_borders_fscr))) {
588
							int w = d3d9.viewp.right - d3d9.viewp.left;
589
							int h = d3d9.viewp.bottom - d3d9.viewp.top;
590
							IDirect3DSurface9 *zone;
591
592
							if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev,
593
								w, h, sd.Format, D3DPOOL_DEFAULT, &zone, NULL) == D3D_OK) {
594
								if (IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, surface, &d3d9.viewp, zone, NULL) == D3D_OK) {
595
									IDirect3DSurface9_LockRect(zone, &lrect, NULL, 0);
596
									gui_save_screenshot(w, h, lrect.pBits, FALSE);
597
									IDirect3DSurface9_UnlockRect(zone);
598
								}
599
								IDirect3DSurface9_Release(zone);
600
							}
601
						} else {
602
							IDirect3DSurface9_LockRect(surface, &lrect, NULL, 0);
603
							gui_save_screenshot(sd.Width, sd.Height, lrect.pBits, FALSE);
604
							IDirect3DSurface9_UnlockRect(surface);
605
						}
606
					}
607
					IDirect3DSurface9_Release(surface);
608
				}
609
				IDirect3DSurface9_Release(back_buffer);
610
			}
611
			gfx.save_screenshot = FALSE;
612
		}
613
	}
614
}
615
void d3d9_quit(void) {
616
	d3d9_context_delete();
617
618
	{
619
		UINT i;
620
621
		for (i = 0; i < d3d9.adapters_in_use; i++) {
622
			_d3d9_adapter *dev = D3D9_ADAPTER(i);
623
624
			if (dev->dev) {
625
				IDirect3DDevice9_Release(dev->dev);
626
				dev->dev = NULL;
627
			}
628
629
		}
630
	}
631
632
	if (d3d9.d3d) {
633
		IDirect3D9_Release(d3d9.d3d);
634
		d3d9.d3d = NULL;
635
	}
636
637
	if (d3d9.array) {
638
		free(d3d9.array);
639
		d3d9.array = d3d9.adapter = NULL;
640
	}
641
}
642
643
static void d3d9_shader_cg_error_handler(void) {
644
	CGerror error = cgGetError();
645
646
	if (error == (CGerror) cgD3D9Failed) {
647
		fprintf(stderr, "D3D9: Error '%s' occurred.\n", cgD3D9TranslateHRESULT(cgD3D9GetLastError()));
648
	} else {
649
		fprintf(stderr, "CG: Error '%s' occurred.\n", cgD3D9TranslateCGerror(error));
650
	}
651
}
652
static BYTE d3d9_device_create(UINT width, UINT height) {
653
	D3DPRESENT_PARAMETERS d3dpp;
654
655
	if (d3d9.adapter->dev) {
656
		IDirect3DDevice9_Release(d3d9.adapter->dev);
657
		d3d9.adapter->dev = NULL;
658
	}
659
660
	ZeroMemory(&d3dpp, sizeof(D3DPRESENT_PARAMETERS));
661
	d3dpp.Windowed = TRUE;
662
	d3dpp.SwapEffect = D3DSWAPEFFECT_COPY;
663
	d3dpp.hDeviceWindow = gui_screen_id();
664
	d3dpp.BackBufferCount = 1;
665
	d3dpp.BackBufferFormat = d3d9.adapter->display_mode.Format;
666
	d3dpp.BackBufferWidth = width;
667
	d3dpp.BackBufferHeight = height;
668
	if (cfg->vsync == TRUE) {
669
		//d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_DEFAULT;
670
		d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_ONE;
671
	} else {
672
		d3dpp.PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE;
673
	}
674
675
	if (IDirect3D9_CreateDevice(d3d9.d3d,
676
		d3d9.adapter->id,
677
		D3DDEVTYPE_HAL,
678
		gui_screen_id(),
679
		d3d9.adapter->flags | D3DCREATE_MULTITHREADED | D3DCREATE_FPU_PRESERVE,
680
		&d3dpp,
681
		&d3d9.adapter->dev) != D3D_OK) {
682
		MessageBox(NULL, "Unable to create d3d device", "Error!", MB_ICONEXCLAMATION | MB_OK);
683
		return (EXIT_ERROR);
684
	}
685
686
	return (EXIT_OK);
687
}
688
static void d3d9_context_delete(void) {
689
	UINT i;
690
691
	d3d9.screen.in_use = 0;
692
	d3d9.screen.index = 0;
693
694
	for (i = 0; i < LENGTH(d3d9.screen.tex); i++) {
695
		_texture_simple *texture = &d3d9.screen.tex[i];
696
		if (texture->offscreen) {
697
			IDirect3DSurface9_Release(texture->offscreen);
698
			texture->offscreen = NULL;
699
		}
700
		if (texture->map0) {
701
			IDirect3DSurface9_Release(texture->map0);
702
			texture->map0 = NULL;
703
		}
704
		if (texture->data) {
705
			IDirect3DTexture9_Release(texture->data);
706
			texture->data = NULL;
707
		}
708
		if (texture->shader.vd) {
709
			IDirect3DVertexDeclaration9_Release(texture->shader.vd);
710
			texture->shader.vd = NULL;
711
		}
712
		if (texture->shader.quad) {
713
			IDirect3DVertexBuffer9_Release(texture->shader.quad);
714
			texture->shader.quad = NULL;
715
		}
716
	}
717
718
	{
719
		if (d3d9.text.offscreen) {
720
			IDirect3DSurface9_Release(d3d9.text.offscreen);
721
			d3d9.text.offscreen = NULL;
722
		}
723
		if (d3d9.text.map0) {
724
			IDirect3DSurface9_Release(d3d9.text.map0);
725
			d3d9.text.map0 = NULL;
726
		}
727
		if (d3d9.text.data) {
728
			IDirect3DTexture9_Release(d3d9.text.data);
729
			d3d9.text.data = NULL;
730
		}
731
		if (d3d9.text.shader.vd) {
732
			IDirect3DVertexDeclaration9_Release(d3d9.text.shader.vd);
733
			d3d9.text.shader.vd = NULL;
734
		}
735
		if (d3d9.text.shader.quad) {
736
			IDirect3DVertexBuffer9_Release(d3d9.text.shader.quad);
737
			d3d9.text.shader.quad = NULL;
738
		}
739
		d3d9_shader_delete(&d3d9.text.shader);
740
	}
741
742
	{
743
		d3d9.feedback.in_use = FALSE;
744
745
		if (d3d9.feedback.tex.map0) {
746
			IDirect3DSurface9_Release(d3d9.feedback.tex.map0);
747
			d3d9.feedback.tex.map0 = NULL;
748
		}
749
		if (d3d9.feedback.tex.data) {
750
			IDirect3DTexture9_Release(d3d9.feedback.tex.data);
751
			d3d9.feedback.tex.data = NULL;
752
		}
753
		if (d3d9.feedback.tex.shader.quad) {
754
			IDirect3DVertexBuffer9_Release(d3d9.feedback.tex.shader.quad);
755
			d3d9.feedback.tex.shader.quad = NULL;
756
		}
757
		if (d3d9.feedback.tex.shader.vd) {
758
			IDirect3DVertexDeclaration9_Release(d3d9.feedback.tex.shader.vd);
759
			d3d9.feedback.tex.shader.vd = NULL;
760
		}
761
		d3d9_shader_delete(&d3d9.feedback.tex.shader);
762
	}
763
764
	for (i = 0; i < LENGTH(d3d9.texture); i++) {
765
		_texture *texture = &d3d9.texture[i];
766
767
		if (texture->map0) {
768
			IDirect3DSurface9_Release(texture->map0);
769
			texture->map0 = NULL;
770
		}
771
		if (texture->data) {
772
			IDirect3DTexture9_Release(texture->data);
773
			texture->data = NULL;
774
		}
775
		if (texture->shader.quad) {
776
			IDirect3DVertexBuffer9_Release(texture->shader.quad);
777
			texture->shader.quad = NULL;
778
		}
779
		if (texture->shader.vd) {
780
			IDirect3DVertexDeclaration9_Release(texture->shader.vd);
781
			texture->shader.vd = NULL;
782
		}
783
		d3d9_shader_delete(&d3d9.texture[i].shader);
784
	}
785
786
	for (i = 0; i < LENGTH(d3d9.lut); i++) {
787
		if (d3d9.lut[i].data) {
788
			IDirect3DTexture9_Release(d3d9.lut[i].data);
789
			d3d9.lut[i].data = NULL;
790
		}
791
	}
792
793
	if (d3d9.cgctx) {
794
		cgD3D9UnloadAllPrograms();
795
		cgD3D9SetDevice(NULL);
796
		cgDestroyContext(d3d9.cgctx);
797
		d3d9.cgctx = NULL;
798
	}
799
800
	if (d3d9.adapter && d3d9.adapter->dev) {
801
		IDirect3DDevice9_Release(d3d9.adapter->dev);
802
		d3d9.adapter->dev = NULL;
803
	}
804
}
805
static BYTE d3d9_texture_create(_texture *texture, UINT index) {
806
	_shader_pass *sp = &shader_effect.sp[index];
807
	_shader_scale *sc = &sp->sc;
808
	const _texture_rect *prev;
809
	_texture_rect *rect = &texture->rect;
810
	_viewport *vp = &texture->vp;
811
812
	if (index == 0) {
813
		prev = &d3d9.screen.tex[0].rect;
814
	} else {
815
		prev = &d3d9.texture[index - 1].rect;
816
	}
817
818
	if (index == shader_effect.last_pass) {
819
		sc->scale.x = 1.0f;
820
		sc->scale.y = 1.0f;
821
		sc->type.x = SHADER_SCALE_VIEWPORT;
822
		sc->type.y = SHADER_SCALE_VIEWPORT;
823
	}
824
825
#if defined (FH_SHADERS_GEST)
826
	switch (sc->type.x) {
827
		case SHADER_SCALE_DEFAULT:
828
		case SHADER_SCALE_INPUT:
829
			rect->base.w = (FLOAT)prev->base.w * sc->scale.x;
830
			break;
831
		case SHADER_SCALE_ABSOLUTE:
832
			rect->base.w = sc->abs.x;
833
			break;
834
		case SHADER_SCALE_VIEWPORT:
835
			rect->base.w = (FLOAT)gfx.vp.w * sc->scale.x;
836
			break;
837
	}
838
	switch (sc->type.y) {
839
		case SHADER_SCALE_DEFAULT:
840
		case SHADER_SCALE_INPUT:
841
			rect->base.h = (FLOAT)prev->base.h * sc->scale.y;
842
			break;
843
		case SHADER_SCALE_ABSOLUTE:
844
			rect->base.h = sc->abs.y;
845
			break;
846
		case SHADER_SCALE_VIEWPORT:
847
			rect->base.h = (FLOAT)gfx.vp.h * sc->scale.y;
848
			break;
849
	}
850
851
	rect->w = emu_power_of_two(rect->base.w);
852
	rect->h = emu_power_of_two(rect->base.h);
853
#else
854
	switch (sc->type.x) {
855
		case SHADER_SCALE_DEFAULT:
856
		case SHADER_SCALE_INPUT:
857
			rect->w = (FLOAT)prev->w * sc->scale.x;
858
			rect->base.w = (FLOAT)prev->base.w * sc->scale.x;
859
			break;
860
		case SHADER_SCALE_ABSOLUTE:
861
			rect->w = rect->base.w = sc->abs.x;
862
			break;
863
		case SHADER_SCALE_VIEWPORT:
864
			rect->w = rect->base.w = (FLOAT)gfx.vp.w * sc->scale.x;
865
			break;
866
	}
867
	switch (sc->type.y) {
868
		case SHADER_SCALE_DEFAULT:
869
		case SHADER_SCALE_INPUT:
870
			rect->h = (FLOAT)prev->h * sc->scale.y;
871
			rect->base.h = (FLOAT)prev->base.h * sc->scale.y;
872
			break;
873
		case SHADER_SCALE_ABSOLUTE:
874
			rect->h = rect->base.h = sc->abs.y;
875
			break;
876
		case SHADER_SCALE_VIEWPORT:
877
			rect->h = rect->base.h = (FLOAT)gfx.vp.h * sc->scale.y;
878
			break;
879
	}
880
881
	rect->w = emu_power_of_two(rect->w);
882
	rect->h = emu_power_of_two(rect->h);
883
#endif
884
885
	// se la scheda video supporta solo texture quadre allore devo crearle quadre
886
	if (d3d9.adapter->texture_square_only == TRUE) {
887
		if (rect->w < rect->h) {
888
			rect->w = rect->h;
889
		} else {
890
			rect->h = rect->w;
891
		}
892
	}
893
894
	if (index == shader_effect.last_pass) {
895
		vp->x = gfx.vp.x * gfx.device_pixel_ratio;
896
		vp->y = gfx.vp.y * gfx.device_pixel_ratio;
897
		vp->w = gfx.vp.w * gfx.device_pixel_ratio;
898
		vp->h = gfx.vp.h * gfx.device_pixel_ratio;
899
	} else {
900
		vp->x = 0;
901
		vp->y = 0;
902
		vp->w = rect->base.w;
903
		vp->h = rect->base.h;
904
	}
905
906
	if (IDirect3DDevice9_CreateVertexBuffer(d3d9.adapter->dev, sizeof(_vertex_buffer) * 4, 0, 0,
907
		D3DPOOL_DEFAULT, &texture->shader.quad, NULL) != D3D_OK) {
908
		MessageBox(NULL, "Unable to create the vertex buffer", "Error!", MB_ICONEXCLAMATION | MB_OK);
909
		return (EXIT_ERROR);
910
	}
911
912
	if (IDirect3DDevice9_CreateTexture(d3d9.adapter->dev,
913
		(UINT)rect->w, (UINT)rect->h, 1,
914
		D3DUSAGE_RENDERTARGET,
915
		sp->fbo_flt ? D3DFMT_A32B32G32R32F : D3DFMT_A8R8G8B8,
916
		D3DPOOL_DEFAULT,
917
		&texture->data,
918
		NULL) != D3D_OK) {
919
		MessageBox(NULL, "Unable to create the texture", "Error!", MB_ICONEXCLAMATION | MB_OK);
920
		return (EXIT_ERROR);
921
	}
922
923
	IDirect3DTexture9_GetSurfaceLevel(texture->data, 0, &texture->map0);
924
	// cancello la superficie map0 perche' alcuni driver (tipo intel) nella
925
	// versione per windows XP non mi passano una superficia "pulita".
926
	d3d9_surface_clean(&texture->map0, rect->w, rect->h);
927
928
	IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *) texture->data);
929
	IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
930
	IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
931
	IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL);
932
933
	return (EXIT_OK);
934
}
935
static BYTE d3d9_texture_simple_create(_texture_simple *texture, UINT w, UINT h, BOOL text) {
936
	_texture_rect *rect = &texture->rect;
937
	_shader *shd = &texture->shader;
938
	_viewport vp = { 0, 0, w, h };
939
	UINT flt;
940
941
	rect->base.w = w;
942
	rect->base.h = h;
943
944
	if (!text) {
945
#if defined (FH_SHADERS_GEST)
946
		rect->w = emu_power_of_two(rect->base.w);
947
		rect->h = emu_power_of_two(rect->base.h);
948
#else
949
		// rect->w = 1024 e rect->h = 1024 sono
950
		// le dimensioni che imposta retroarch
951
		// ma su alcune shader l'effetto e' piu'
952
		// sgranato ("mudlord/emboss.h" e
953
		// "antialiasing/fx-aa.h" sono un esempio)
954
		rect->w = 1024;
955
		rect->h = 1024;
956
#endif
957
		flt = (cfg->interpolation || gfx.PSS) ? D3DTEXF_LINEAR : D3DTEXF_POINT;
958
	} else {
959
		rect->w = rect->base.w;
960
		rect->h = rect->base.h;
961
		flt = D3DTEXF_POINT;
962
	}
963
964
	// se la scheda video supporta solo texture quadre allore devo crearle quadre
965
	if (d3d9.adapter->texture_square_only == TRUE) {
966
		if (rect->w < rect->h) {
967
			rect->w = rect->h;
968
		} else {
969
			rect->h = rect->w;
970
		}
971
	}
972
973
	shd->info.video_size.x = (FLOAT)rect->base.w;
974
	shd->info.video_size.y = (FLOAT)rect->base.h;
975
	shd->info.texture_size.x = rect->w;
976
	shd->info.texture_size.y = rect->h;
977
978
	if (IDirect3DDevice9_CreateVertexBuffer(d3d9.adapter->dev,
979
		sizeof(_vertex_buffer) * 4,
980
		D3DUSAGE_WRITEONLY,
981
		0,
982
		D3DPOOL_DEFAULT,
983
		&texture->shader.quad,
984
		NULL) != D3D_OK) {
985
		MessageBox(NULL, "Unable to create the vertex buffer", "Error!", MB_ICONEXCLAMATION | MB_OK);
986
		return (EXIT_ERROR);
987
	}
988
989
	if (IDirect3DDevice9_CreateTexture(d3d9.adapter->dev,
990
		(UINT)rect->w, (UINT)rect->h, 1,
991
		d3d9.adapter->dynamic_texture ? D3DUSAGE_DYNAMIC : 0,
992
		D3DFMT_A8R8G8B8,
993
		D3DPOOL_DEFAULT,
994
		&texture->data,
995
		NULL) != D3D_OK) {
996
		MessageBox(NULL, "Unable to create the texture", "Error!", MB_ICONEXCLAMATION | MB_OK);
997
		return (EXIT_ERROR);
998
	}
999
1000
	IDirect3DTexture9_GetSurfaceLevel(texture->data, 0, &texture->map0);
1001
	// cancello la superficie map0 perche' alcuni driver (tipo intel) nella
1002
	// versione per windows XP non mi passano una superficia "pulita".
1003
	d3d9_surface_clean(&texture->map0, rect->w, rect->h);
1004
1005
	// creo la superficie temporanea le cui dimensioni non devono essere "POWerate"
1006
	if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev,
1007
		rect->base.w,
1008
		rect->base.h,
1009
		D3DFMT_A8R8G8B8,
1010
		D3DPOOL_SYSTEMMEM,
1011
		&texture->offscreen,
1012
		NULL) != D3D_OK) {
1013
		MessageBox(NULL, "Unable to create the memory surface", "Error!", MB_ICONEXCLAMATION | MB_OK);
1014
		return (EXIT_ERROR);
1015
	}
1016
1017
	// cancello la superficie
1018
	d3d9_surface_clean(&texture->offscreen, rect->base.w, rect->base.h);
1019
1020
	IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *) texture->data);
1021
	IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
1022
	IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
1023
	IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MINFILTER, flt);
1024
	IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_MAGFILTER, flt);
1025
	IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL);
1026
1027
	d3d9_vertex_buffer_set(shd, &vp, rect);
1028
1029
	return (EXIT_OK);
1030
}
1031
static BYTE d3d9_texture_lut_create(_lut *lut, UINT index) {
1032
	_lut_pass *lp = &shader_effect.lp[index];
1033
	LPDIRECT3DSURFACE9 map0, offscreen;
1034
	D3DLOCKED_RECT lrect;
1035
	UINT width, height;
1036
1037
	if (gui_load_lut(lut, lp->path) == EXIT_ERROR) {
1038
		return (EXIT_ERROR);
1039
	}
1040
1041
	width = lut->w;
1042
	height = lut->h;
1043
1044
	lut->name = lp->name;
1045
	lut->filter = d3d9_shader_filter(lp->linear);
1046
1047
	if (d3d9.adapter->texture_square_only == TRUE) {
1048
		if (width < height) {
1049
			width = height;
1050
		} else {
1051
			height = width;
1052
		}
1053
	}
1054
1055
	if (IDirect3DDevice9_CreateTexture(d3d9.adapter->dev,
1056
		width, height, 1,
1057
		0,
1058
		D3DFMT_A8R8G8B8,
1059
		D3DPOOL_DEFAULT,
1060
		&lut->data,
1061
		NULL) != D3D_OK) {
1062
		MessageBox(NULL, "Unable to create the texture", "Error!", MB_ICONEXCLAMATION | MB_OK);
1063
		return (EXIT_ERROR);
1064
	}
1065
1066
	if (IDirect3DDevice9_CreateOffscreenPlainSurface(d3d9.adapter->dev,
1067
		lut->w, lut->h,
1068
		D3DFMT_A8R8G8B8,
1069
		D3DPOOL_SYSTEMMEM,
1070
		&offscreen,
1071
		NULL) != D3D_OK) {
1072
		MessageBox(NULL, "Unable to create the memory surface", "Error!", MB_ICONEXCLAMATION | MB_OK);
1073
		return (EXIT_ERROR);
1074
	}
1075
1076
	IDirect3DTexture9_GetSurfaceLevel(lut->data, 0, &map0);
1077
1078
	if (IDirect3DSurface9_LockRect(offscreen, &lrect, NULL, D3DLOCK_DISCARD) != D3D_OK) {
1079
		if (map0) {
1080
			IDirect3DSurface9_Release(map0);
1081
		}
1082
		if (offscreen) {
1083
			IDirect3DSurface9_Release(offscreen);
1084
		}
1085
		return (EXIT_ERROR);
1086
	} else {
1087
		UINT w = 0, h = 0;
1088
		uint32_t *sbits = (uint32_t *)lut->bits;
1089
		uint32_t *dbits = (uint32_t *)lrect.pBits;
1090
1091
		for (h = 0; h < lut->h; h++) {
1092
			for (w = 0; w < lut->w; w++) {
1093
				(*(dbits + w)) = (*(sbits + w));
1094
			}
1095
			sbits += lrect.Pitch / (gfx.bit_per_pixel / 8);
1096
			dbits += lrect.Pitch / (gfx.bit_per_pixel / 8);
1097
		}
1098
1099
		IDirect3DSurface9_UnlockRect(offscreen);
1100
		IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, offscreen, NULL, map0, NULL);
1101
1102
		IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, (IDirect3DBaseTexture9 *)lut->data);
1103
		IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
1104
		IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, 0, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
1105
		IDirect3DDevice9_SetTexture(d3d9.adapter->dev, 0, NULL);
1106
1107
		IDirect3DSurface9_Release(map0);
1108
		IDirect3DSurface9_Release(offscreen);
1109
	}
1110
1111
	return (EXIT_OK);
1112
}
1113
static void d3d9_surface_clean(LPDIRECT3DSURFACE9 *surface, UINT width, UINT height) {
1114
	D3DLOCKED_RECT lock_dst;
1115
1116
	if (IDirect3DSurface9_LockRect((*surface), &lock_dst, NULL, D3DLOCK_DISCARD) == D3D_OK) {
1117
		uint32_t *pbits;
1118
		UINT w, h;
1119
1120
		pbits = (uint32_t *)lock_dst.pBits;
1121
1122
		for (h = 0; h < height; h++) {
1123
			for (w = 0; w < width; w++) {
1124
				(*(pbits + w)) = 0;
1125
			}
1126
			pbits += lock_dst.Pitch / (gfx.bit_per_pixel / 8);
1127
		}
1128
1129
		IDirect3DSurface9_UnlockRect((*surface));
1130
	}
1131
}
1132
static BYTE d3d9_shader_init(UINT pass, _shader *shd, const uTCHAR *path, const char *code) {
1133
	const char *list;
1134
	const char *argv[128];
1135
	const char **fopts = cgD3D9GetOptimalOptions(cgD3D9GetLatestPixelProfile());
1136
	const char **vopts = cgD3D9GetOptimalOptions(cgD3D9GetLatestVertexProfile());
1137
	char alias[MAX_PASS][128];
1138
	uTCHAR base[LENGTH_FILE_NAME_MID];
1139
	uTCHAR dname[LENGTH_FILE_NAME_MID];
1140
	char bname[LENGTH_FILE_NAME_MID];
1141
	UINT i, argc;
1142
1143
	if ((path != NULL) && path[0]) {
1144
		uTCHAR buffer[LENGTH_FILE_NAME_MID];
1145
1146
		umemset(base, 0x00, usizeof(base));
1147
		if (ugetcwd(base, usizeof(base)) == NULL) { ; };
1148
1149
		umemset(dname, 0x00, usizeof(dname));
1150
		gui_utf_dirname((uTCHAR *) path, dname, usizeof(buffer) - 1);
1151
1152
		umemset(buffer, 0x00, usizeof(buffer));
1153
		gui_utf_basename((uTCHAR *) path, buffer, usizeof(buffer) - 1);
1154
		memset(bname, 0x00, sizeof(bname));
1155
		wcstombs(bname, buffer, sizeof(bname) - 1);
1156
	}
1157
1158
	// fragment
1159
	{
1160
		memset(alias, 0x00, sizeof(alias));
1161
		memset(argv, 0x00, sizeof(argv));
1162
1163
		argc = 0;
1164
		argv[argc++] = "-DPARAMETER_UNIFORM";
1165
		for (i = 0; i < pass; i++) {
1166
			_shader_pass *sp = &shader_effect.sp[i];
1167
1168
			if (sp->alias[0]) {
1169
				snprintf(alias[i], 128, "-D%s_ALIAS", sp->alias);
1170
				argv[argc++] = alias[i];
1171
			}
1172
		}
1173
		for (i = 0; i < 128; i++) {
1174
			if (!fopts[i]) {
1175
				break;
1176
			}
1177
			argv[argc] = fopts[i];
1178
1179
			if (argc++ == 126) {
1180
				break;
1181
			}
1182
		}
1183
		argv[argc] = NULL;
1184
1185
		if ((path == NULL) || !path[0]) {
1186
			shd->prg.f = cgCreateProgram(d3d9.cgctx, CG_SOURCE, code, cgD3D9GetLatestPixelProfile(), "main_fragment", argv);
1187
		} else {
1188
			if (uchdir(dname) == -1) { ; }
1189
			shd->prg.f = cgCreateProgramFromFile(d3d9.cgctx, CG_SOURCE, bname, cgD3D9GetLatestPixelProfile(), "main_fragment", argv);
1190
			if (uchdir(base) == -1) { ; }
1191
		}
1192
		if (!shd->prg.f && (list = cgGetLastListing(d3d9.cgctx))) {
1193
			printf("CG: fragment program errors :\n%s\n", list);
1194
		}
1195
	}
1196
1197
	// vertex
1198
	{
1199
		memset(alias, 0x00, sizeof(alias));
1200
		memset(argv, 0x00, sizeof(argv));
1201
1202
		argc = 0;
1203
		argv[argc++] = "-DPARAMETER_UNIFORM";
1204
		for (i = 0; i < pass; i++) {
1205
			_shader_pass *sp = &shader_effect.sp[i];
1206
1207
			if (sp->alias[0]) {
1208
				snprintf(alias[i], 128, "-D%s_ALIAS", sp->alias);
1209
				argv[argc++] = alias[i];
1210
			}
1211
		}
1212
		for (i = 0; i < 128; i++) {
1213
			if (!vopts[i]) {
1214
				break;
1215
			}
1216
			argv[argc] = vopts[i];
1217
1218
			if (argc++ == 126) {
1219
				break;
1220
			}
1221
		}
1222
		argv[argc] = NULL;
1223
1224
		if ((path == NULL) || !path[0]) {
1225
			shd->prg.v = cgCreateProgram(d3d9.cgctx, CG_SOURCE, code, cgD3D9GetLatestVertexProfile(), "main_vertex", argv);
1226
		} else {
1227
			if (uchdir(dname) == -1) { ; }
1228
			shd->prg.v = cgCreateProgramFromFile(d3d9.cgctx, CG_SOURCE, bname, cgD3D9GetLatestVertexProfile(), "main_vertex", argv);
1229
			if (uchdir(base) == -1) { ; }
1230
		}
1231
		if (!shd->prg.v && (list = cgGetLastListing(d3d9.cgctx))) {
1232
			printf("CG: vertex program errors :\n%s\n", list);
1233
		}
1234
	}
1235
1236
	if (!shd->prg.f || !shd->prg.v) {
1237
		fprintf(stderr, "CG: %s\n", cgGetErrorString(cgGetError()));
1238
		return (EXIT_ERROR);
1239
	}
1240
1241
	if (cgD3D9LoadProgram(shd->prg.f, TRUE, 0) != D3D_OK) {
1242
		fprintf(stderr, "CG: Error on loading fragment program\n");
1243
		return (EXIT_ERROR);
1244
	}
1245
	if (cgD3D9LoadProgram(shd->prg.v, TRUE, 0) != D3D_OK) {
1246
		fprintf(stderr, "CG: Error on loading vertex program\n");
1247
		return (EXIT_ERROR);
1248
	}
1249
1250
	shd->uni.mvp = cgGetNamedParameter(shd->prg.v, "modelViewProj");
1251
	if (!shd->uni.mvp) {
1252
		shd->uni.mvp = cgGetNamedParameter(shd->prg.v, "IN.mvp_matrix");
1253
	}
1254
1255
	shd->uni.v.video_size = cgGetNamedParameter(shd->prg.v, "IN.video_size");
1256
	shd->uni.f.video_size = cgGetNamedParameter(shd->prg.f, "IN.video_size");
1257
	shd->uni.v.texture_size = cgGetNamedParameter(shd->prg.v, "IN.texture_size");
1258
	shd->uni.f.texture_size = cgGetNamedParameter(shd->prg.f, "IN.texture_size");
1259
	shd->uni.v.output_size = cgGetNamedParameter(shd->prg.v, "IN.output_size");
1260
	shd->uni.f.output_size = cgGetNamedParameter(shd->prg.f, "IN.output_size");
1261
1262
	shd->uni.v.frame_count = cgGetNamedParameter(shd->prg.v, "IN.frame_count");
1263
	shd->uni.f.frame_count = cgGetNamedParameter(shd->prg.f, "IN.frame_count");
1264
1265
	shd->uni.v.frame_direction = cgGetNamedParameter(shd->prg.v, "IN.frame_direction");
1266
	shd->uni.f.frame_direction = cgGetNamedParameter(shd->prg.f, "IN.frame_direction");
1267
1268
	if (d3d9_vertex_declaration_create(shd) == EXIT_ERROR) {
1269
		return (EXIT_ERROR);
1270
	}
1271
1272
	for (i = 0; i < shader_effect.luts; i++) {
1273
		shd->uni.v.lut[i] = cgGetNamedParameter(shd->prg.v, d3d9.lut[i].name);
1274
		shd->uni.f.lut[i] = cgGetNamedParameter(shd->prg.f, d3d9.lut[i].name);
1275
	}
1276
1277
	for (i = 0; i < shader_effect.params; i++) {
1278
		shd->uni.v.param[i] = cgGetNamedParameter(shd->prg.v, shader_effect.param[i].name);
1279
		shd->uni.f.param[i] = cgGetNamedParameter(shd->prg.f, shader_effect.param[i].name);
1280
	}
1281
1282
	d3d9_shader_uni_texture_clear(&shd->uni.orig);
1283
	d3d9_shader_uni_texture(&shd->uni.orig, &shd->prg, "ORIG");
1284
	d3d9_shader_uni_texture(&shd->uni.orig, &shd->prg, "PASSPREV%u", pass + 1);
1285
1286
	d3d9_shader_uni_texture_clear(&shd->uni.feedback);
1287
	d3d9_shader_uni_texture(&shd->uni.feedback, &shd->prg, "FEEDBACK");
1288
1289
	for (i = 0; i < pass; i++) {
1290
		d3d9_shader_uni_texture_clear(&shd->uni.passprev[i]);
1291
1292
		d3d9_shader_uni_texture(&shd->uni.passprev[i], &shd->prg, "PASS%u", i + 1);
1293
		d3d9_shader_uni_texture(&shd->uni.passprev[i], &shd->prg, "PASSPREV%u", pass - i);
1294
1295
		if (shader_effect.sp[i].alias[0]) {
1296
			d3d9_shader_uni_texture(&shd->uni.passprev[i], &shd->prg, shader_effect.sp[i].alias);
1297
		}
1298
	}
1299
1300
	d3d9_shader_uni_texture_clear(&shd->uni.prev[0]);
1301
	d3d9_shader_uni_texture(&shd->uni.prev[0], &shd->prg, "PREV");
1302
1303
	for (i = 1; i < LENGTH(shd->uni.prev); i++) {
1304
		d3d9_shader_uni_texture_clear(&shd->uni.prev[i]);
1305
		d3d9_shader_uni_texture(&shd->uni.prev[i], &shd->prg, "PREV%u", i);
1306
	}
1307
1308
	return (EXIT_OK);
1309
}
1310
static void d3d9_shader_delete(_shader *shd) {
1311
	if (shd->prg.f) {
1312
		cgDestroyProgram(shd->prg.f);
1313
		shd->prg.f = NULL;
1314
	}
1315
	if (shd->prg.v) {
1316
		cgDestroyProgram(shd->prg.v);
1317
		shd->prg.v = NULL;
1318
	}
1319
}
1320
static void d3d9_shader_uniform_ctrl(CGparameter *dst, CGparameter *param, const char *semantic) {
1321
	static const FLOAT f2[2] = {1.0f, 1.0f};
1322
1323
	if (!(*param)) {
1324
		return;
1325
	}
1326
1327
	if (cgD3D9SetUniform((*param), &f2) != D3D_OK) {
1328
		(*dst) = 0;
1329
		fprintf(stderr, "CG: Parameter \"%s\" disabled.\n", semantic);
1330
	} else {
1331
		(*dst) = (*param);
1332
	}
1333
}
1334
static void d3d9_shader_uni_texture_clear(_shader_uniforms_tex *sut) {
1335
	sut->f.texture = NULL;
1336
	sut->v.video_size = NULL;
1337
	sut->f.video_size = NULL;
1338
	sut->v.texture_size = NULL;
1339
	sut->f.texture_size = NULL;
1340
	sut->v.tex_coord = NULL;
1341
}
1342
static void d3d9_shader_uni_texture(_shader_uniforms_tex *sut, _shader_prg_cg *prg, char *fmt, ...) {
1343
	CGparameter param;
1344
	char type[50], buff[100];
1345
	va_list ap;
1346
1347
	va_start(ap, fmt);
1348
	vsnprintf(type, sizeof(type), fmt, ap);
1349
	va_end(ap);
1350
1351
	snprintf(buff, sizeof(buff), "%s%s", type, ".texture");
1352
	if (!sut->f.texture) {
1353
		sut->f.texture = cgGetNamedParameter(prg->f, buff);
1354
	}
1355
	snprintf(buff, sizeof(buff), "%s%s", type, ".video_size");
1356
	if (!sut->v.video_size) {
1357
		param = cgGetNamedParameter(prg->v, buff);
1358
		d3d9_shader_uniform_ctrl(&sut->v.video_size, &param, buff);
1359
	}
1360
	if (!sut->f.video_size) {
1361
		param = cgGetNamedParameter(prg->f, buff);
1362
		d3d9_shader_uniform_ctrl(&sut->f.video_size, &param, buff);
1363
	}
1364
	snprintf(buff, sizeof(buff), "%s%s", type, ".texture_size");
1365
	if (!sut->v.texture_size) {
1366
		param = cgGetNamedParameter(prg->v, buff);
1367
		d3d9_shader_uniform_ctrl(&sut->v.texture_size, &param, buff);
1368
	}
1369
	if (!sut->f.texture_size) {
1370
		param = cgGetNamedParameter(prg->f, buff);
1371
		d3d9_shader_uniform_ctrl(&sut->f.texture_size, &param, buff);
1372
	}
1373
	snprintf(buff, sizeof(buff), "%s%s", type, ".tex_coord");
1374
	if (!sut->v.tex_coord) {
1375
		sut->v.tex_coord = cgGetNamedParameter(prg->v, buff);
1376
	}
1377
}
1378
static BYTE d3d9_vertex_declaration_create(_shader *shd) {
1379
	UINT i, count, index, tex_index = 0;
1380
	CGparameter param;
1381
	BYTE texcoord[2] = { FALSE };
1382
	BYTE stream[4] = { FALSE };
1383
	BYTE indices[LENGTH(shd->attribs.attrib)] = { FALSE };
1384
	static const D3DVERTEXELEMENT9 end = D3DDECL_END();
1385
	D3DVERTEXELEMENT9 decl[MAXD3DDECLLENGTH];
1386
1387
	if (cgD3D9GetVertexDeclaration(shd->prg.v, decl) == CG_FALSE) {
1388
		return (EXIT_ERROR);
1389
	}
1390
1391
	for (count = 0; count < MAXD3DDECLLENGTH; count++) {
1392
		if (memcmp(&end, &decl[count], sizeof(end)) == 0) {
1393
			break;
1394
		}
1395
	}
1396
1397
	if (!(param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "POSITION"))) {
1398
		param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "POSITION0");
1399
	}
1400
	if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) {
1401
		stream[0] = TRUE;
1402
		index = cgGetParameterResourceIndex(param);
1403
		indices[index] = TRUE;
1404
		decl[index] = (D3DVERTEXELEMENT9) {
1405
			0, 0,
1406
			D3DDECLTYPE_FLOAT3,
1407
			D3DDECLMETHOD_DEFAULT,
1408
			D3DDECLUSAGE_POSITION, 0
1409
		};
1410
1411
		fprintf(stderr, "CG: semantic POSITION found (%d)\n", index);
1412
	}
1413
1414
	if (!(param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "TEXCOORD"))) {
1415
		param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "TEXCOORD0");
1416
	}
1417
	if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) {
1418
		stream[1] = TRUE;
1419
		texcoord[0] = TRUE;
1420
		index = cgGetParameterResourceIndex(param);
1421
		indices[index]  = TRUE;
1422
		decl[index] = (D3DVERTEXELEMENT9) {
1423
			1, sizeof(float) * 3,
1424
			D3DDECLTYPE_FLOAT2,
1425
			D3DDECLMETHOD_DEFAULT,
1426
			D3DDECLUSAGE_TEXCOORD, 0
1427
		};
1428
1429
		fprintf(stderr, "CG: semantic TEXCOORD0 found (%d)\n", index);
1430
	}
1431
1432
	param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "TEXCOORD1");
1433
	if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) {
1434
		stream[2] = TRUE;
1435
		texcoord[1] = TRUE;
1436
		index = cgGetParameterResourceIndex(param);
1437
		indices[index]  = TRUE;
1438
		decl[index] = (D3DVERTEXELEMENT9) {
1439
			2, sizeof(float) * 5,
1440
			D3DDECLTYPE_FLOAT2,
1441
			D3DDECLMETHOD_DEFAULT,
1442
			D3DDECLUSAGE_TEXCOORD, 1
1443
		};
1444
1445
		fprintf(stderr, "CG: semantic TEXCOORD1 found (%d)\n", index);
1446
	}
1447
1448
	if (!(param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "COLOR"))) {
1449
		param = d3d9_cg_find_param(cgGetFirstParameter(shd->prg.v, CG_PROGRAM), "COLOR0");
1450
	}
1451
	if (param && (indices[cgGetParameterResourceIndex(param)] == FALSE)) {
1452
		stream[3] = TRUE;
1453
		index = cgGetParameterResourceIndex(param);
1454
		indices[index] = TRUE;
1455
		decl[index] = (D3DVERTEXELEMENT9) {
1456
			3, sizeof(float) * 7,
1457
			D3DDECLTYPE_FLOAT4,
1458
			D3DDECLMETHOD_DEFAULT,
1459
			D3DDECLUSAGE_COLOR, 0
1460
		};
1461
1462
		fprintf(stderr, "CG: semantic COLOR found (%d)\n", index);
1463
	}
1464
1465
	// Stream {0, 1, 2, 3} might be already taken. Find first vacant stream
1466
	for (index = 0; index < 4; index++) {
1467
		if (stream[index] == FALSE) {
1468
			break;
1469
		}
1470
	}
1471
1472
	// Find first vacant texcoord declaration
1473
	if (texcoord[0] && texcoord[1]) {
1474
		tex_index = 2;
1475
	} else if (texcoord[1] && !texcoord[0]) {
1476
		tex_index = 0;
1477
	} else if (texcoord[0] && !texcoord[1]) {
1478
		tex_index = 1;
1479
	}
1480
1481
	shd->attribs.count = 0;
1482
1483
	for (i = 0; i < count; i++) {
1484
		if (indices[i]) {
1485
			shd->attribs.attrib[shd->attribs.count++] = 0;
1486
		} else {
1487
			fprintf(stderr, "CG: attrib found (%d %d %d %d)\n", i, shd->attribs.count, index, tex_index);
1488
1489
			shd->attribs.attrib[shd->attribs.count++] = index;
1490
			decl[i] = (D3DVERTEXELEMENT9) {
1491
				index, sizeof(float) * 3,
1492
				D3DDECLTYPE_FLOAT2,
1493
				D3DDECLMETHOD_DEFAULT,
1494
				D3DDECLUSAGE_TEXCOORD, tex_index
1495
			};
1496
			while ((++index < 4) && stream[index]) {
1497
				index++;
1498
			}
1499
			if ((++tex_index == 1) && texcoord[1]) {
1500
				tex_index++;
1501
			}
1502
		}
1503
	}
1504
1505
	if (IDirect3DDevice9_CreateVertexDeclaration(d3d9.adapter->dev, decl, &shd->vd)) {
1506
		return (EXIT_ERROR);
1507
	}
1508
1509
	return (EXIT_OK);
1510
}
1511
static void d3d9_vertex_buffer_set(_shader *shd, _viewport *vp, _texture_rect *prev) {
1512
	D3DXMATRIX proj, ortho, rot;
1513
	FLOAT u = (FLOAT)prev->base.w / prev->w;
1514
	FLOAT v = (FLOAT)prev->base.h / prev->h;
1515
	void *buffer;
1516
	const UINT rotation = 0;
1517
	UINT i;
1518
1519
	shd->vb[0].x = 0.0f;
1520
	shd->vb[0].y = vp->h;
1521
	shd->vb[0].z = 0.5f;
1522
	shd->vb[0].u = 0.0f;
1523
	shd->vb[0].v = 0.0f;
1524
	shd->vb[0].lut_u = 0.0f;
1525
	shd->vb[0].lut_v = 0.0f;
1526
	shd->vb[0].r = 1.0f;
1527
	shd->vb[0].g = 1.0f;
1528
	shd->vb[0].b = 1.0f;
1529
	shd->vb[0].a = 1.0f;
1530
1531
	shd->vb[1].x = vp->w;
1532
	shd->vb[1].y = vp->h;
1533
	shd->vb[1].z = 0.5f;
1534
	shd->vb[1].u = u;
1535
	shd->vb[1].v = 0.0f;
1536
	shd->vb[1].lut_u = 1.0f;
1537
	shd->vb[1].lut_v = 0.0f;
1538
	shd->vb[1].r = 1.0f;
1539
	shd->vb[1].g = 1.0f;
1540
	shd->vb[1].b = 1.0f;
1541
	shd->vb[1].a = 1.0f;
1542
1543
	shd->vb[2].x = 0.0f;
1544
	shd->vb[2].y = 0.0f;
1545
	shd->vb[2].z = 0.5f;
1546
	shd->vb[2].u = 0.0f;
1547
	shd->vb[2].v = v;
1548
	shd->vb[2].lut_u = 0.0f;
1549
	shd->vb[2].lut_v = 1.0f;
1550
	shd->vb[2].r = 1.0f;
1551
	shd->vb[2].g = 1.0f;
1552
	shd->vb[2].b = 1.0f;
1553
	shd->vb[2].a = 1.0f;
1554
1555
	shd->vb[3].x = vp->w;
1556
	shd->vb[3].y = 0.0f;
1557
	shd->vb[3].z = 0.5f;
1558
	shd->vb[3].u = u;
1559
	shd->vb[3].v = v;
1560
	shd->vb[3].lut_u = 1.0f;
1561
	shd->vb[3].lut_v = 1.0f;
1562
	shd->vb[3].r = 1.0f;
1563
	shd->vb[3].g = 1.0f;
1564
	shd->vb[3].b = 1.0f;
1565
	shd->vb[3].a = 1.0f;
1566
1567
	// problema dell'infamous half-texel offset of D3D9 (corretto dalle D3D10 in poi) :
1568
	// http://msdn.microsoft.com/en-us/library/bb219690%28VS.85%29.aspx.
1569
	for (i = 0; i < 4; i++) {
1570
		shd->vb[i].x -= 0.5f;
1571
		shd->vb[i].y += 0.5f;
1572
	}
1573
1574
	IDirect3DVertexBuffer9_Lock(shd->quad, 0, 0, (void**) &buffer, 0);
1575
	memcpy(buffer, shd->vb, sizeof(shd->vb));
1576
	IDirect3DVertexBuffer9_Unlock(shd->quad);
1577
1578
	D3DXMatrixOrthoOffCenterLH(&ortho, 0, vp->w, 0, vp->h, 0, 1);
1579
	D3DXMatrixIdentity(&rot);
1580
	D3DXMatrixRotationZ(&rot, rotation * (M_PI / 2.0));
1581
1582
	D3DXMatrixMultiply(&proj, &ortho, &rot);
1583
	D3DXMatrixTranspose(&shd->mvp, &proj);
1584
}
1585
static CGparameter d3d9_cg_find_param(CGparameter prm, const char *name) {
1586
	UINT i;
1587
	static const char *illegal[] = {
1588
		"IN.",
1589
		"ORIG.",
1590
		"PASS",
1591
		"PREV.",
1592
		"PREV1.", "PREV2.",
1593
		"PREV3.", "PREV4.",
1594
		"PREV5.", "PREV6.",
1595
	};
1596
1597
	for (; prm; prm = cgGetNextParameter(prm)) {
1598
		const char *semantic = NULL;
1599
1600
		if (cgGetParameterType(prm) == CG_STRUCT) {
1601
			CGparameter ret;
1602
1603
			if ((ret = d3d9_cg_find_param(cgGetFirstStructParameter(prm), name))) {
1604
				return (ret);
1605
			}
1606
		}
1607
		if (cgGetParameterDirection(prm) != CG_IN || cgGetParameterVariability(prm) != CG_VARYING) {
1608
			continue;
1609
		}
1610
		if (!(semantic = cgGetParameterSemantic(prm))) {
1611
			continue;
1612
		}
1613
		if (strcmp(name, semantic) == 0) {
1614
			const char *pname = cgGetParameterName(prm);
1615
1616
			if (!pname) {
1617
				return (NULL);
1618
			}
1619
1620
			for (i = 0; i < LENGTH(illegal); i++) {
1621
				if (strstr(pname, illegal[i]) == pname) {
1622
					return (NULL);
1623
				}
1624
			}
1625
1626
			return (prm);
1627
		}
1628
	}
1629
	return (NULL);
1630
}
1631
INLINE static void d3d9_viewport_set(DWORD x, DWORD y, DWORD w, DWORD h) {
1632
	static D3DVIEWPORT9 vp;
1633
1634
	vp.X = x;
1635
	vp.Y = y;
1636
	vp.Width = w;
1637
	vp.Height = h;
1638
	vp.MinZ = 0.0f;
1639
	vp.MaxZ = 1.0f;
1640
	IDirect3DDevice9_SetViewport(d3d9.adapter->dev, &vp);
1641
}
1642
INLINE D3DTEXTUREFILTERTYPE d3d9_shader_filter(UINT type) {
1643
	switch (type) {
1644
		case TEXTURE_LINEAR_ENAB:
1645
			return D3DTEXF_LINEAR;
1646
		case TEXTURE_LINEAR_DISAB:
1647
			return D3DTEXF_POINT;
1648
		default:
1649
			if (cfg->interpolation || gfx.PSS) {
1650
				return D3DTEXF_LINEAR;
1651
			}
1652
			return D3DTEXF_POINT;
1653
	}
1654
}
1655
INLINE static void d3d9_shader_params_text_set(_shader *shd) {
1656
	UINT i;
1657
1658
	if (shd->uni.mvp) {
1659
		// posso tranquillamente utilizzare l'mvp dell'ultimo pass
1660
		cgD3D9SetUniformMatrix(shd->uni.mvp, &shd->mvp);
1661
	}
1662
1663
	for (i = 0; i < 4; i++) {
1664
		IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, i, shd->quad, 0, sizeof(_vertex_buffer));
1665
	}
1666
}
1667
INLINE static void d3d9_shader_param_set(const _texture *texture, UINT fcountmod, UINT fcount) {
1668
	const _shader *shd = &texture->shader;
1669
	UINT i, index;
1670
1671
	if (shd->uni.mvp) {
1672
		cgD3D9SetUniformMatrix(shd->uni.mvp, &shd->mvp);
1673
	}
1674
1675
	for (i = 0; i < 4; i++) {
1676
		IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev, i, shd->quad, 0, sizeof(_vertex_buffer));
1677
	}
1678
1679
	// IN
1680
	{
1681
		// IN.video_size
1682
		if (shd->uni.v.video_size) {
1683
			cgD3D9SetUniform(shd->uni.v.video_size, &shd->info.video_size);
1684
		}
1685
		if (shd->uni.f.video_size) {
1686
			cgD3D9SetUniform(shd->uni.f.video_size, &shd->info.video_size);
1687
		}
1688
		// IN.texture_size
1689
		if (shd->uni.v.texture_size) {
1690
			cgD3D9SetUniform(shd->uni.v.texture_size, &shd->info.texture_size);
1691
		}
1692
		if (shd->uni.f.texture_size) {
1693
			cgD3D9SetUniform(shd->uni.f.texture_size, &shd->info.texture_size);
1694
		}
1695
		// IN.output_size
1696
		if (shd->uni.v.output_size) {
1697
			cgD3D9SetUniform(shd->uni.v.output_size, &shd->info.output_size);
1698
		}
1699
		if (shd->uni.f.output_size) {
1700
			cgD3D9SetUniform(shd->uni.f.output_size, &shd->info.output_size);
1701
		}
1702
		// IN.frame_count
1703
		{
1704
			FLOAT fc = (FLOAT)fcount;
1705
1706
			if (fcountmod) {
1707
				fc = (FLOAT)(fcount % fcountmod);
1708
			}
1709
1710
			if (shd->uni.v.frame_count) {
1711
				cgD3D9SetUniform(shd->uni.v.frame_count, &fc);
1712
			}
1713
			if (shd->uni.f.frame_count) {
1714
				cgD3D9SetUniform(shd->uni.f.frame_count, &fc);
1715
			}
1716
		}
1717
		// IN.frame_direction
1718
		{
1719
			FLOAT frame_direction = -1;
1720
1721
			if (shd->uni.v.frame_direction) {
1722
				cgD3D9SetUniform(shd->uni.v.frame_direction, &frame_direction);
1723
			}
1724
			if (shd->uni.f.frame_direction) {
1725
				cgD3D9SetUniform(shd->uni.f.frame_direction, &frame_direction);
1726
			}
1727
		}
1728
	}
1729
1730
	// param
1731
	for (i = 0; i < shader_effect.params; i++) {
1732
		if (shd->uni.v.param[i]) {
1733
			cgD3D9SetUniform(shd->uni.v.param[i], &shader_effect.param[i].value);
1734
		}
1735
		if (shd->uni.f.param[i]) {
1736
			cgD3D9SetUniform(shd->uni.f.param[i], &shader_effect.param[i].value);
1737
		}
1738
	}
1739
1740
	// lut
1741
	for (i = 0; i < shader_effect.luts; i++) {
1742
		_lut *lut = &d3d9.lut[i];
1743
		UINT bound_index = (UINT)-1;
1744
1745
		if (shd->uni.v.lut[i]) {
1746
			index = cgGetParameterResourceIndex(shd->uni.v.lut[i]);
1747
			bound_index = index;
1748
			IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )lut->data);
1749
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, lut->filter);
1750
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, lut->filter);
1751
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
1752
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
1753
		}
1754
		if (shd->uni.f.lut[i]) {
1755
			index = cgGetParameterResourceIndex(shd->uni.f.lut[i]);
1756
			if (index == bound_index) {
1757
				continue;
1758
			}
1759
			IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )lut->data);
1760
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, lut->filter);
1761
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, lut->filter);
1762
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
1763
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
1764
		}
1765
	}
1766
1767
	// ORIG
1768
	{
1769
		// ORIG.texture
1770
		if (shd->uni.orig.f.texture) {
1771
			index = cgGetParameterResourceIndex(shd->uni.orig.f.texture);
1772
			IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )d3d9.screen.tex[d3d9.screen.index].data);
1773
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
1774
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, D3DTEXF_POINT);
1775
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
1776
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
1777
		}
1778
		// ORIG.video_size
1779
		if (shd->uni.orig.v.video_size) {
1780
			cgD3D9SetUniform(shd->uni.orig.v.video_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.video_size);
1781
		}
1782
		if (shd->uni.orig.f.video_size) {
1783
			cgD3D9SetUniform(shd->uni.orig.f.video_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.video_size);
1784
		}
1785
		// ORIG.texture_size
1786
		if (shd->uni.orig.v.texture_size) {
1787
			cgD3D9SetUniform(shd->uni.orig.v.texture_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.texture_size);
1788
		}
1789
		if (shd->uni.orig.f.texture_size) {
1790
			cgD3D9SetUniform(shd->uni.orig.f.texture_size, &d3d9.screen.tex[d3d9.screen.index].shader.info.texture_size);
1791
		}
1792
		// ORIG.tex_coord
1793
		if (shd->uni.orig.v.tex_coord) {
1794
			IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev,
1795
				shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.orig.v.tex_coord)],
1796
				d3d9.screen.tex[d3d9.screen.index].shader.quad, 0, sizeof(_vertex_buffer));
1797
		}
1798
	}
1799
1800
	// FEEDBACK
1801
	if (d3d9.feedback.in_use) {
1802
		// FEEDBACK.texture
1803
		if (shd->uni.feedback.f.texture) {
1804
			D3DTEXTUREFILTERTYPE filter = d3d9_shader_filter(shader_effect.sp[shader_effect.feedback_pass].linear);
1805
1806
			index = cgGetParameterResourceIndex(shd->uni.feedback.f.texture);
1807
			IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 * )d3d9.feedback.tex.data);
1808
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, filter);
1809
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, filter);
1810
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
1811
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
1812
		}
1813
		// FEEDBACK.video_size
1814
		if (shd->uni.feedback.v.video_size) {
1815
			cgD3D9SetUniform(shd->uni.feedback.v.video_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.video_size);
1816
		}
1817
		if (shd->uni.feedback.f.video_size) {
1818
			cgD3D9SetUniform(shd->uni.feedback.f.video_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.video_size);
1819
		}
1820
		// FEEDBACK.texture_size
1821
		if (shd->uni.feedback.v.texture_size) {
1822
			cgD3D9SetUniform(shd->uni.feedback.v.texture_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.texture_size);
1823
		}
1824
		if (shd->uni.feedback.f.texture_size) {
1825
			cgD3D9SetUniform(shd->uni.feedback.f.texture_size, &d3d9.texture[shader_effect.feedback_pass].shader.info.texture_size);
1826
		}
1827
		// FEEDBACK.tex_coord
1828
		if (shd->uni.feedback.v.tex_coord) {
1829
			IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev,
1830
				shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.feedback.v.tex_coord)],
1831
				d3d9.texture[shader_effect.feedback_pass].shader.quad, 0,
1832
				sizeof(_vertex_buffer));
1833
		}
1834
	}
1835
1836
	// PREV
1837
	{
1838
		INT circle_index = d3d9.screen.index - 1;
1839
1840
		for (i = 0; i < (d3d9.screen.in_use - 1); i++) {
1841
			if (circle_index < 0) {
1842
				circle_index = d3d9.screen.in_use - 1;
1843
			}
1844
			// PREV[x].texture
1845
			if (shd->uni.prev[i].f.texture) {
1846
				index = cgGetParameterResourceIndex(shd->uni.prev[i].f.texture);
1847
				IDirect3DDevice9_SetTexture(d3d9.adapter->dev, index, (IDirect3DBaseTexture9 *)d3d9.screen.tex[circle_index].data);
1848
				IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MAGFILTER, D3DTEXF_POINT);
1849
				IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_MINFILTER, D3DTEXF_POINT);
1850
				IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
1851
				IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, index, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
1852
			}
1853
			// PREV[x].tex_coord
1854
			if (shd->uni.prev[i].v.tex_coord) {
1855
				IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev,
1856
					shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.prev[i].v.tex_coord)],
1857
					d3d9.screen.tex[circle_index].shader.quad, 0, sizeof(_vertex_buffer));
1858
			}
1859
			circle_index--;
1860
		}
1861
	}
1862
1863
	// PASS
1864
	for (i = 0; i < shader_effect.running_pass; i++) {
1865
		UINT next = i + 1;
1866
1867
		// PASS[x].texture
1868
		if (shd->uni.passprev[i].f.texture) {
1869
			D3DTEXTUREFILTERTYPE filter = d3d9_shader_filter(shader_effect.sp[i].linear);
1870
			UINT resind = cgGetParameterResourceIndex(shd->uni.passprev[i].f.texture);
1871
1872
			IDirect3DDevice9_SetTexture(d3d9.adapter->dev, resind, (IDirect3DBaseTexture9 *)d3d9.texture[i].data);
1873
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_MAGFILTER, filter);
1874
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_MINFILTER, filter);
1875
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_ADDRESSU, D3DTADDRESS_BORDER);
1876
			IDirect3DDevice9_SetSamplerState(d3d9.adapter->dev, resind, D3DSAMP_ADDRESSV, D3DTADDRESS_BORDER);
1877
		}
1878
		// PASS[x].video_size
1879
		if (shd->uni.passprev[i].v.video_size) {
1880
			cgD3D9SetUniform(shd->uni.passprev[i].v.video_size, &d3d9.texture[next].shader.info.video_size);
1881
		}
1882
		if (shd->uni.passprev[i].f.video_size) {
1883
			cgD3D9SetUniform(shd->uni.passprev[i].f.video_size, &d3d9.texture[next].shader.info.video_size);
1884
		}
1885
		// PASS[x].texture_size
1886
		if (shd->uni.passprev[i].v.texture_size) {
1887
			cgD3D9SetUniform(shd->uni.passprev[i].v.texture_size, &d3d9.texture[next].shader.info.texture_size);
1888
		}
1889
		if (shd->uni.passprev[i].f.texture_size) {
1890
			cgD3D9SetUniform(shd->uni.passprev[i].f.texture_size, &d3d9.texture[next].shader.info.texture_size);
1891
		}
1892
		// PASS[x].tex_coord
1893
		if (shd->uni.passprev[i].v.tex_coord) {
1894
			IDirect3DDevice9_SetStreamSource(d3d9.adapter->dev,
1895
				shd->attribs.attrib[cgGetParameterResourceIndex(shd->uni.passprev[i].v.tex_coord)],
1896
				d3d9.texture[next].shader.quad, 0, sizeof(_vertex_buffer));
1897
		}
1898
	}
1899
}
(-)puNES-0.105.org/src/video/d3d9/d3d9.h (-2 / +2 lines)
Lines 167-180 typedef struct _d3d9 { Link Here
167
	_lut lut[MAX_PASS];
167
	_lut lut[MAX_PASS];
168
} _d3d9;
168
} _d3d9;
169
169
170
extern _d3d9 d3d9;
171
170
#if defined (__cplusplus)
172
#if defined (__cplusplus)
171
#define EXTERNC extern "C"
173
#define EXTERNC extern "C"
172
#else
174
#else
173
#define EXTERNC
175
#define EXTERNC
174
#endif
176
#endif
175
177
176
EXTERNC _d3d9 d3d9;
177
178
EXTERNC BYTE d3d9_init(void);
178
EXTERNC BYTE d3d9_init(void);
179
EXTERNC BYTE d3d9_context_create(void);
179
EXTERNC BYTE d3d9_context_create(void);
180
EXTERNC void d3d9_draw_scene(void);
180
EXTERNC void d3d9_draw_scene(void);
(-)puNES-0.105.org/src/video/d3d9/gfx.c (-4 / +3 lines)
Lines 21-29 Link Here
21
21
22
#include "d3d9.h"
22
#include "d3d9.h"
23
#include "video/gfx_thread.h"
23
#include "video/gfx_thread.h"
24
#include "fps.h"
25
#include "gui.h"
24
#include "gui.h"
26
#include "info.h"
27
#include "conf.h"
25
#include "conf.h"
28
#include "ppu.h"
26
#include "ppu.h"
29
#include "clock.h"
27
#include "clock.h"
Lines 34-39 Link Here
34
#include "video/effects/pause.h"
32
#include "video/effects/pause.h"
35
#include "video/effects/tv_noise.h"
33
#include "video/effects/tv_noise.h"
36
34
35
_gfx gfx;
36
37
BYTE gfx_init(void) {
37
BYTE gfx_init(void) {
38
	gfx.save_screenshot = FALSE;
38
	gfx.save_screenshot = FALSE;
39
39
Lines 109-116 void gfx_quit(void) { Link Here
109
109
110
	d3d9_quit();
110
	d3d9_quit();
111
}
111
}
112
void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette,
112
void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, BYTE force_scale, BYTE force_palette) {
113
	BYTE force_scale, BYTE force_palette) {
114
	BYTE set_mode;
113
	BYTE set_mode;
115
	WORD width, height;
114
	WORD width, height;
116
	DBWORD old_shader = cfg->shader;
115
	DBWORD old_shader = cfg->shader;
(-)puNES-0.105.org/src/video/d3d9/gfx.c.orig (+697 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *  for some codes :
4
 *  Copyright (C) 2010-2015 The RetroArch team
5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
18
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19
 *
20
 */
21
22
#include "d3d9.h"
23
#include "video/gfx_thread.h"
24
#include "fps.h"
25
#include "gui.h"
26
#include "info.h"
27
#include "conf.h"
28
#include "ppu.h"
29
#include "clock.h"
30
#include "palette.h"
31
#include "paldef.h"
32
#include "vs_system.h"
33
#include "settings.h"
34
#include "video/effects/pause.h"
35
#include "video/effects/tv_noise.h"
36
37
BYTE gfx_init(void) {
38
	gfx.save_screenshot = FALSE;
39
40
	if (gui_create() == EXIT_ERROR) {
41
		MessageBox(NULL, "Gui initialization failed", "Error!", MB_ICONEXCLAMATION | MB_OK);
42
		return (EXIT_ERROR);
43
	}
44
45
	if (gfx_thread_init() == EXIT_ERROR) {
46
		MessageBox(NULL, "Unable to allocate the gfx thread", "Error!", MB_ICONEXCLAMATION | MB_OK);
47
		return (EXIT_ERROR);
48
	}
49
50
	if (d3d9_init() == EXIT_ERROR) {
51
		MessageBox(NULL, "Unable to initiliazed d3d9", "Error!", MB_ICONEXCLAMATION | MB_OK);
52
		return (EXIT_ERROR);
53
	}
54
55
	// inizializzo l'ntsc che utilizzero' non solo
56
	// come filtro ma anche nel gfx_set_screen() per
57
	// generare la paletta dei colori.
58
	if (ntsc_init(0, 0, 0, 0, 0) == EXIT_ERROR) {
59
		MessageBox(NULL, "Unable to initialize palette", "Error!", MB_ICONEXCLAMATION | MB_OK);
60
		return (EXIT_ERROR);
61
	}
62
63
	// mi alloco una zona di memoria dove conservare la
64
	// paletta nel formato di visualizzazione.
65
	if (!(gfx.palette = malloc(NUM_COLORS * sizeof(uint32_t)))) {
66
		MessageBox(NULL, "Unable to allocate the palette", "Error!", MB_ICONEXCLAMATION | MB_OK);
67
		return (EXIT_ERROR);
68
	}
69
70
	if (pause_init() == EXIT_ERROR) {
71
		MessageBox(NULL, "pause initialization failed", "Error!", MB_ICONEXCLAMATION | MB_OK);
72
		return (EXIT_ERROR);
73
	}
74
75
	if (tv_noise_init() == EXIT_ERROR) {
76
		MessageBox(NULL, "tv_noise initialization failed", "Error!", MB_ICONEXCLAMATION | MB_OK);
77
		return (EXIT_ERROR);
78
	}
79
80
	// casi particolari provenienti dal settings_file_parse() e cmd_line_parse()
81
	if (cfg->fullscreen == FULLSCR) {
82
		gfx.scale_before_fscreen = cfg->scale;
83
	}
84
85
	if (cfg->fullscreen) {
86
		gfx_set_screen(cfg->scale, cfg->filter, cfg->shader, NO_FULLSCR, cfg->palette, FALSE, FALSE);
87
		cfg->fullscreen = NO_FULLSCR;
88
		cfg->scale = gfx.scale_before_fscreen;
89
		gui_fullscreen();
90
	} else {
91
		gfx_set_screen(cfg->scale, cfg->filter, cfg->shader, NO_FULLSCR, cfg->palette, FALSE, FALSE);
92
	}
93
94
	return (EXIT_OK);
95
}
96
void gfx_quit(void) {
97
	gfx_thread_quit();
98
99
	pause_quit();
100
	tv_noise_quit();
101
102
	ntsc_quit();
103
	text_quit();
104
105
	if (gfx.palette) {
106
		free(gfx.palette);
107
		gfx.palette = NULL;
108
	}
109
110
	d3d9_quit();
111
}
112
void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette,
113
	BYTE force_scale, BYTE force_palette) {
114
	BYTE set_mode;
115
	WORD width, height;
116
	DBWORD old_shader = cfg->shader;
117
118
	gfx_thread_pause();
119
120
	if (shader_effect.params > 0) {
121
		settings_shp_save();
122
	}
123
124
	gfx_set_screen_start:
125
	set_mode = FALSE;
126
	width = 0, height = 0;
127
128
	// l'ordine dei vari controlli non deve essere cambiato:
129
	// 0) overscan
130
	// 1) filtro
131
	// 2) fullscreen
132
	// 3) fattore di scala
133
	// 4) tipo di paletta
134
135
	// overscan
136
	{
137
		overscan.enabled = cfg->oscan;
138
139
		gfx.rows = SCR_ROWS;
140
		gfx.lines = SCR_LINES;
141
142
		if (overscan.enabled == OSCAN_DEFAULT) {
143
			overscan.enabled = cfg->oscan_default;
144
		}
145
146
		if (overscan.enabled) {
147
			gfx.rows -= (overscan.borders->left + overscan.borders->right);
148
			gfx.lines -= (overscan.borders->up + overscan.borders->down);
149
		}
150
	}
151
152
	// filtro
153
	if (filter == NO_CHANGE) {
154
		filter = cfg->filter;
155
	}
156
157
	if ((filter != cfg->filter) || info.on_cfg || force_scale) {
158
		switch (filter) {
159
			case NO_FILTER:
160
			default:
161
				gfx.filter.func = scale_surface;
162
				gfx.filter.factor = X1;
163
				break;
164
			case SCALE2X:
165
			case SCALE3X:
166
			case SCALE4X:
167
				gfx.filter.func = scaleNx;
168
				gfx.filter.factor = filter + 1;
169
				break;
170
			case HQ2X:
171
			case HQ3X:
172
			case HQ4X:
173
				gfx.filter.func = hqNx;
174
				gfx.filter.factor = filter - 2;
175
				break;
176
			case XBRZ2X:
177
			case XBRZ3X:
178
			case XBRZ4X:
179
			case XBRZ5X:
180
			case XBRZ6X:
181
				gfx.filter.func = xBRZ;
182
				gfx.filter.factor = filter - 6;
183
				break;
184
			case XBRZ2XMT:
185
			case XBRZ3XMT:
186
			case XBRZ4XMT:
187
			case XBRZ5XMT:
188
			case XBRZ6XMT:
189
				gfx.filter.func = xBRZ_mt;
190
				gfx.filter.factor = filter - 11;
191
				break;
192
			case NTSC_FILTER:
193
				gfx.filter.func = ntsc_surface;
194
				gfx.filter.factor = X2;
195
				break;
196
		}
197
		// forzo il controllo del fattore di scale
198
		force_scale = TRUE;
199
		// indico che devo cambiare il video mode
200
		set_mode = TRUE;
201
	}
202
203
	/* shader */
204
	if (shader == NO_CHANGE) {
205
		shader = cfg->shader;
206
	}
207
208
	// fullscreen
209
	if (fullscreen == NO_CHANGE) {
210
		fullscreen = cfg->fullscreen;
211
	}
212
	if ((fullscreen != cfg->fullscreen) || info.on_cfg) {
213
		// forzo il controllo del fattore di scale
214
		force_scale = TRUE;
215
		// indico che devo cambiare il video mode
216
		set_mode = TRUE;
217
	}
218
219
	// fattore di scala
220
	if (scale == NO_CHANGE) {
221
		scale = cfg->scale;
222
	}
223
	if ((scale != cfg->scale) || info.on_cfg || force_scale) {
224
		if (filter == NTSC_FILTER) {
225
			width = gfx.w[PASS0] = gfx.w[NO_OVERSCAN] = NES_NTSC_OUT_WIDTH(SCR_ROWS);
226
			gfx.filter.width_pixel = (float)nes_ntsc_out_chunk / (float)nes_ntsc_in_chunk;
227
			if (overscan.enabled) {
228
				width -= ((float)(overscan.borders->left + overscan.borders->right) * gfx.filter.width_pixel);
229
			}
230
			switch (scale) {
231
				case X2:
232
					gfx.width_pixel = gfx.filter.width_pixel;
233
					break;
234
				default:
235
					width = ((float)width / 2.0f) * (float)scale;
236
					gfx.w[NO_OVERSCAN] = ((float)gfx.w[NO_OVERSCAN] / 2.0f) * (float)scale;
237
					gfx.width_pixel = (gfx.filter.width_pixel / 2.0f) * (float)scale;
238
					break;
239
			}
240
		} else {
241
			width = gfx.rows * scale;
242
			gfx.w[NO_OVERSCAN] = SCR_ROWS * scale;
243
			gfx.w[PASS0] = SCR_ROWS * gfx.filter.factor;
244
			gfx.filter.width_pixel = gfx.filter.factor;
245
			gfx.width_pixel = scale;
246
		}
247
		gfx.w[CURRENT] = width;
248
249
		height = gfx.lines * scale;
250
		gfx.h[CURRENT] = height;
251
		gfx.h[NO_OVERSCAN] = SCR_LINES * scale;
252
		gfx.h[PASS0] = SCR_LINES * gfx.filter.factor;
253
254
		set_mode = TRUE;
255
	}
256
257
	// paletta
258
	if (palette == NO_CHANGE) {
259
		palette = cfg->palette;
260
	}
261
	if ((palette != cfg->palette) || info.on_cfg || force_palette) {
262
		if (palette == PALETTE_FILE) {
263
			if (ustrlen(cfg->palette_file) != 0) {
264
				if (palette_load_from_file(cfg->palette_file) == EXIT_ERROR) {
265
					umemset(cfg->palette_file, 0x00, usizeof(cfg->palette_file));
266
					text_add_line_info(1, "[red]error on palette file");
267
					if (cfg->palette != PALETTE_FILE) {
268
						palette = cfg->palette;
269
					} else if (machine.type == NTSC) {
270
						palette = PALETTE_NTSC;
271
					} else {
272
						palette = PALETTE_SONY;
273
					}
274
				} else {
275
					ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_base_file, 0, (BYTE *)palette_RGB.noswap);
276
				}
277
			}
278
		}
279
280
		switch (palette) {
281
			case PALETTE_PAL:
282
				ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_base_pal, 0, (BYTE *)palette_RGB.noswap);
283
				break;
284
			case PALETTE_NTSC:
285
				ntsc_set(NULL, cfg->ntsc_format, FALSE, 0, 0, (BYTE *)palette_RGB.noswap);
286
				break;
287
			case PALETTE_FRBX_NOSTALGIA:
288
				ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_firebrandx_nostalgia_FBX, 0, (BYTE *)palette_RGB.noswap);
289
				break;
290
			case PALETTE_FRBX_YUV:
291
				ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_firebrandx_YUV_v3, 0, (BYTE *)palette_RGB.noswap);
292
				break;
293
			case PALETTE_GREEN:
294
				rgb_modifier(NULL, palette_RGB.noswap, 0x00, -0x20, 0x20, -0x20);
295
				break;
296
			case PALETTE_FILE:
297
				break;
298
			default:
299
				ntsc_set(NULL, cfg->ntsc_format, palette, 0, 0, (BYTE *)palette_RGB.noswap);
300
				break;
301
		}
302
303
		if (vs_system.enabled) {
304
			switch (vs_system.ppu) {
305
				case RP2C03B:
306
				case RP2C03G:
307
					break;
308
				case RP2C04:
309
					ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0001, 0, (BYTE *)palette_RGB.noswap);
310
					break;
311
				case RP2C04_0002:
312
					ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0002, 0, (BYTE *)palette_RGB.noswap);
313
					break;
314
				case RP2C04_0003:
315
					ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0003, 0, (BYTE *)palette_RGB.noswap);
316
					break;
317
				case RP2C04_0004:
318
					ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0004, 0, (BYTE *)palette_RGB.noswap);
319
					break;
320
				case RC2C03B:
321
				case RC2C03C:
322
				case RC2C05_01:
323
				case RC2C05_02:
324
				case RC2C05_03:
325
				case RC2C05_04:
326
				case RC2C05_05:
327
				default:
328
					break;
329
			}
330
		}
331
	}
332
333
	gfx_palette_update();
334
335
	// salvo il nuovo fattore di scala
336
	cfg->scale = scale;
337
	// salvo il nuovo filtro
338
	cfg->filter = filter;
339
	// salvo la nuova shader
340
	cfg->shader = shader;
341
	// salvo il nuovo stato del fullscreen
342
	cfg->fullscreen = fullscreen;
343
	// salvo il nuovo tipo di paletta
344
	cfg->palette = palette;
345
346
	// Pixel Aspect Ratio
347
	if (cfg->filter == NTSC_FILTER) {
348
		gfx.pixel_aspect_ratio = 1.0f;
349
	} else {
350
		switch (cfg->pixel_aspect_ratio) {
351
			default:
352
			case PAR11:
353
				gfx.pixel_aspect_ratio = 1.0f;
354
				break;
355
			case PAR54:
356
				gfx.pixel_aspect_ratio = 5.0f / 4.0f;
357
				break;
358
			case PAR87:
359
				gfx.pixel_aspect_ratio = 8.0f / 7.0f;
360
				break;
361
			case PAR118:
362
				gfx.pixel_aspect_ratio = 2950000.0f / 2128137.0f;
363
				break;
364
		}
365
	}
366
367
	{
368
		gfx.PSS = ((cfg->pixel_aspect_ratio != PAR11) && cfg->PAR_soft_stretch) ? TRUE : FALSE;
369
370
		if (shaders_set(shader) == EXIT_ERROR) {
371
			umemcpy(cfg->shader_file, gfx.last_shader_file, usizeof(cfg->shader_file));
372
			if (old_shader == shader) {
373
				shader = NO_SHADER;
374
			} else {
375
				shader = old_shader;
376
			}
377
			goto gfx_set_screen_start;
378
		}
379
380
		if (shader_effect.params > 0) {
381
			settings_shp_parse();
382
		}
383
384
		if (set_mode) {
385
			if (fullscreen == TRUE) {
386
				gfx.w[VIDEO_MODE] = gfx.w[MONITOR];
387
				gfx.h[VIDEO_MODE] = gfx.h[MONITOR];
388
			} else if (cfg->oscan_black_borders) {
389
				gfx.w[VIDEO_MODE] = gfx.w[NO_OVERSCAN];
390
				gfx.h[VIDEO_MODE] = gfx.h[NO_OVERSCAN];
391
			} else {
392
				gfx.w[VIDEO_MODE] = width;
393
				gfx.h[VIDEO_MODE] = height;
394
			}
395
396
			// Pixel Aspect Ratio
397
			if (cfg->pixel_aspect_ratio && !fullscreen) {
398
				gfx.w[VIDEO_MODE] = (gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio);
399
400
				if (overscan.enabled && !cfg->oscan_black_borders) {
401
					float brd = 0;
402
403
					brd = (float)gfx.w[VIDEO_MODE] / (float)SCR_ROWS;
404
					brd *= (overscan.borders->right + overscan.borders->left);
405
406
					gfx.w[VIDEO_MODE] -= brd;
407
				}
408
			}
409
410
			// faccio quello che serve prima del setvideo
411
			gui_set_video_mode();
412
		}
413
414
		switch (d3d9_context_create()) {
415
			case EXIT_ERROR:
416
				fprintf(stderr, "D3D9: Unable to initialize d3d context\n");
417
				gfx_thread_continue();
418
				return;
419
			case EXIT_ERROR_SHADER:
420
				text_add_line_info(1, "[red]errors[normal] on shader, use [green]'No shader'");
421
				fprintf(stderr, "CG: Error on loading the shaders, switch to \"No shader\"\n");
422
				umemcpy(cfg->shader_file, gfx.last_shader_file, usizeof(cfg->shader_file));
423
				shader = NO_SHADER;
424
				goto gfx_set_screen_start;
425
		}
426
	}
427
428
	// calcolo le proporzioni tra il disegnato a video (overscan e schermo
429
	// con le dimensioni per il filtro NTSC compresi) e quello che dovrebbe
430
	// essere (256 x 240). Mi serve per calcolarmi la posizione del puntatore
431
	// dello zapper.
432
	if (cfg->fullscreen) {
433
		gfx.w_pr = (float)gfx.vp.w / (float)SCR_ROWS;
434
		gfx.h_pr = (float)gfx.vp.h / (float)SCR_LINES;
435
	} else {
436
		gfx.w_pr = (float)(gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio) / (float)SCR_ROWS;
437
		gfx.h_pr = (float)gfx.h[NO_OVERSCAN] / (float)SCR_LINES;
438
	}
439
440
	gfx_thread_continue();
441
442
	// setto il titolo della finestra
443
	gui_update();
444
445
	if (info.on_cfg == TRUE) {
446
		info.on_cfg = FALSE;
447
	}
448
}
449
void gfx_draw_screen(void) {
450
	if (gfx_thread_public.filtering == TRUE) {
451
		fps.frames_skipped++;
452
		return;
453
	}
454
455
	screen.rd = screen.wr;
456
457
	if (info.doublebuffer == TRUE) {
458
		screen.index = !screen.index;
459
		screen.last_completed_wr = screen.wr;
460
		screen.wr = &screen.buff[screen.index];
461
	} else {
462
		screen.rd = screen.wr = screen.last_completed_wr;
463
	}
464
465
	if (screen.rd->ready == FALSE) {
466
		screen.rd->ready = TRUE;
467
	}
468
}
469
470
void gfx_control_changed_adapter(void *monitor) {
471
	_d3d9_adapter *old_adapter = d3d9.adapter;
472
	HMONITOR *in_use = monitor;
473
	unsigned int i;
474
475
	if ((*in_use) == IDirect3D9_GetAdapterMonitor(d3d9.d3d, d3d9.adapter->id)) {
476
		return;
477
	}
478
479
	for (i = 0; i < d3d9.adapters_in_use; i++) {
480
		_d3d9_adapter *adapter = D3D9_ADAPTER(i);
481
482
		if ((*in_use) == IDirect3D9_GetAdapterMonitor(d3d9.d3d, adapter->id)) {
483
			d3d9.adapter = adapter;
484
			if (d3d9_context_create() == EXIT_OK) {
485
				return;
486
			}
487
			fprintf(stderr, "D3D9 : Unable to initialize new d3d context\n");
488
489
			d3d9.adapter = old_adapter;
490
			if (d3d9_context_create() == EXIT_OK) {
491
				return;
492
			}
493
			fprintf(stderr, "D3D9 : Unable to initialize old d3d context\n");
494
			break;
495
		}
496
	}
497
}
498
499
uint32_t gfx_color(BYTE a, BYTE r, BYTE g, BYTE b) {
500
	return (D3DCOLOR_ARGB(a, r, g, b));
501
}
502
void gfx_palette_update(void) {
503
	WORD i;
504
505
	if ((cfg->disable_swap_emphasis_pal == FALSE) && ((machine.type == PAL) || (machine.type == DENDY))) {
506
		palette_RGB.in_use = &palette_RGB.swapped[0];
507
	} else {
508
		palette_RGB.in_use = &palette_RGB.noswap[0];
509
	}
510
511
	// inizializzo in ogni caso la tabella YUV dell'hqx
512
	hqx_init();
513
514
	// memorizzo i colori della paletta nel formato di visualizzazione
515
	for (i = 0; i < NUM_COLORS; i++) {
516
		gfx.palette[i] = gfx_os_color(palette_RGB.in_use[i].r, palette_RGB.in_use[i].g, palette_RGB.in_use[i].b);
517
	}
518
}
519
520
void gfx_cursor_init(void) {
521
	gui_cursor_init();
522
	gui_cursor_set();
523
};
524
void gfx_cursor_set(void) {
525
	gui_cursor_set();
526
};
527
528
void gfx_text_create_surface(_txt_element *ele) {
529
	size_t size = (ele->h * ele->w) * (gfx.bit_per_pixel / 8);
530
531
	ele->surface = malloc(size);
532
	memset(ele->surface, 0x00, size);
533
}
534
void gfx_text_release_surface(_txt_element *ele) {
535
	if (ele->surface) {
536
		free(ele->surface);
537
		ele->surface = NULL;
538
	}
539
}
540
void gfx_text_rect_fill(_txt_element *ele, _txt_rect *rect, uint32_t color) {
541
	uint32_t *pbits;
542
	LONG pitch;
543
	int w, h;
544
545
	pitch = ele->w;
546
	pbits = (uint32_t *)ele->surface;
547
	pbits += (rect->y * ele->w) + rect->x;
548
549
	for (h = 0; h < rect->h; h++) {
550
		for (w = 0; w < rect->w; w++) {
551
			(*(pbits + w)) = color;
552
		}
553
		pbits += pitch;
554
	}
555
}
556
void gfx_text_reset(void) {
557
	txt_table[TXT_NORMAL] = D3DCOLOR_ARGB(0, 0xFF, 0xFF, 0xFF);
558
	txt_table[TXT_RED]    = D3DCOLOR_ARGB(0, 0xFF, 0x4C, 0x3E);
559
	txt_table[TXT_YELLOW] = D3DCOLOR_ARGB(0, 0xFF, 0xFF, 0   );
560
	txt_table[TXT_GREEN]  = D3DCOLOR_ARGB(0, 0   , 0xFF, 0   );
561
	txt_table[TXT_CYAN]   = D3DCOLOR_ARGB(0, 0   , 0xFF, 0xFF);
562
	txt_table[TXT_BROWN]  = D3DCOLOR_ARGB(0, 0xEB, 0x89, 0x31);
563
	txt_table[TXT_BLUE]   = D3DCOLOR_ARGB(0, 0x2D, 0x8D, 0xBD);
564
	txt_table[TXT_GRAY]   = D3DCOLOR_ARGB(0, 0xA0, 0xA0, 0xA0);
565
	txt_table[TXT_BLACK]  = D3DCOLOR_ARGB(0, 0   , 0   , 0   );
566
}
567
void gfx_text_clear(_txt_element *ele) {
568
	D3DLOCKED_RECT lock_dst;
569
	RECT dst;
570
	uint32_t *pbits;
571
	int w, h, x, y;
572
573
	if (!d3d9.text.data) {
574
		return;
575
	}
576
577
	text_calculate_real_x_y(ele, &x, &y);
578
579
	dst.left = x;
580
	dst.top = y;
581
	dst.right = x + ele->w;
582
	dst.bottom = y + ele->h;
583
584
	if (IDirect3DSurface9_LockRect(d3d9.text.offscreen, &lock_dst, &dst, D3DLOCK_DISCARD) != D3D_OK) {
585
		printf("D3D9 : LockRect text surface error\n");
586
		return;
587
	}
588
589
	pbits = (uint32_t *)lock_dst.pBits;
590
591
	for (h = 0; h < ele->h; h++) {
592
		for (w = 0; w < ele->w; w++) {
593
			(*(pbits + w)) = 0;
594
		}
595
		pbits += lock_dst.Pitch / (gfx.bit_per_pixel / 8);
596
	}
597
598
	IDirect3DSurface9_UnlockRect(d3d9.text.offscreen);
599
}
600
void gfx_text_blit(_txt_element *ele, _txt_rect *rect) {
601
	D3DLOCKED_RECT lock_dst;
602
	RECT dst;
603
	LONG pitch;
604
	unsigned char *psrc, *pdst;
605
	int h;
606
607
	if (!cfg->txt_on_screen) {
608
		return;
609
	}
610
611
	dst.left = rect->x;
612
	dst.top = rect->y;
613
	dst.right = rect->x + rect->w;
614
	dst.bottom = rect->y + rect->h;
615
616
	if (IDirect3DSurface9_LockRect(d3d9.text.offscreen, &lock_dst, &dst, D3DLOCK_DISCARD) != D3D_OK) {
617
		printf("D3D9 : LockRect text surface error\n");
618
		return;
619
	}
620
621
	pitch = rect->w * (gfx.bit_per_pixel / 8);
622
	psrc = (unsigned char *)ele->surface;
623
	pdst = (unsigned char *)lock_dst.pBits;
624
625
	for (h = 0; h < rect->h; h++) {
626
		memcpy(pdst, psrc, pitch);
627
		psrc += pitch;
628
		pdst += lock_dst.Pitch;
629
	}
630
631
	IDirect3DSurface9_UnlockRect(d3d9.text.offscreen);
632
}
633
634
void gfx_apply_filter(void) {
635
	gfx.filter.data.palette = (void *)gfx.palette;
636
637
	//applico la paletta adeguata.
638
	if (cfg->filter == NTSC_FILTER) {
639
		gfx.filter.data.palette = NULL;
640
	}
641
	if (info.no_rom | info.turn_off) {
642
		if (cfg->filter == NTSC_FILTER) {
643
			gfx.filter.data.palette = turn_off_effect.ntsc;
644
		} else {
645
			gfx.filter.data.palette = (void *)turn_off_effect.palette;
646
		}
647
	} else if (info.pause) {
648
		if (!cfg->disable_sepia_color) {
649
			if (cfg->filter == NTSC_FILTER) {
650
				gfx.filter.data.palette = pause_effect.ntsc;
651
			} else {
652
				gfx.filter.data.palette = pause_effect.palette;
653
			}
654
		}
655
	}
656
657
	gfx_thread_lock();
658
659
	{
660
		const _texture_simple *scrtex = &d3d9.screen.tex[d3d9.screen.index];
661
		D3DLOCKED_RECT lrect;
662
663
		// lock della surface in memoria
664
		IDirect3DSurface9_LockRect(scrtex->offscreen, &lrect, NULL, D3DLOCK_DISCARD);
665
		// applico l'effetto
666
		gfx.filter.data.pitch = lrect.Pitch;
667
		gfx.filter.data.pix = lrect.pBits;
668
		gfx.filter.data.width = scrtex->rect.base.w;
669
		gfx.filter.data.height = scrtex->rect.base.h;
670
		gfx.filter.func();
671
		// unlock della surface in memoria
672
		IDirect3DSurface9_UnlockRect(scrtex->offscreen);
673
674
		// aggiorno la texture dello schermo
675
		if (overscan.enabled) {
676
			POINT point;
677
			RECT rect;
678
679
			rect.left = overscan.borders->left * gfx.filter.width_pixel;
680
			rect.top = overscan.borders->up * gfx.filter.factor;
681
			rect.right = scrtex->rect.base.w - (overscan.borders->right * gfx.filter.width_pixel);
682
			rect.bottom = scrtex->rect.base.h - (overscan.borders->down * gfx.filter.factor);
683
684
			point.x = rect.left;
685
			point.y = rect.top;
686
687
			IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, scrtex->offscreen, &rect, scrtex->map0, &point);
688
		} else {
689
			IDirect3DDevice9_UpdateSurface(d3d9.adapter->dev, scrtex->offscreen, NULL, scrtex->map0, NULL);
690
		}
691
	}
692
693
	gfx_thread_unlock();
694
	gui_screen_update();
695
696
	return;
697
}
(-)puNES-0.105.org/src/video/effects/pause.c (-1 / +3 lines)
Lines 21-27 Link Here
21
#include "pause.h"
21
#include "pause.h"
22
#include "conf.h"
22
#include "conf.h"
23
#include "video/gfx.h"
23
#include "video/gfx.h"
24
#include "video/filters/ntsc.h"
24
#include "palette.h"
25
26
_pause_effect pause_effect;
25
27
26
BYTE pause_init(void) {
28
BYTE pause_init(void) {
27
	uint32_t *palette;
29
	uint32_t *palette;
(-)puNES-0.105.org/src/video/effects/pause.h (-5 / +7 lines)
Lines 21-37 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
typedef struct _pause_effect {
25
	void *palette;
26
	void *ntsc;
27
} _pause_effect;
28
29
extern _pause_effect pause_effect;
30
24
#if defined (__cplusplus)
31
#if defined (__cplusplus)
25
#define EXTERNC extern "C"
32
#define EXTERNC extern "C"
26
#else
33
#else
27
#define EXTERNC
34
#define EXTERNC
28
#endif
35
#endif
29
36
30
EXTERNC struct _pause_effect {
31
	void *palette;
32
	void *ntsc;
33
} pause_effect;
34
35
EXTERNC BYTE pause_init(void);
37
EXTERNC BYTE pause_init(void);
36
EXTERNC void pause_quit(void);
38
EXTERNC void pause_quit(void);
37
39
(-)puNES-0.105.org/src/video/effects/tv_noise.c (-1 / +3 lines)
Lines 23-29 Link Here
23
#include "conf.h"
23
#include "conf.h"
24
#include "video/gfx.h"
24
#include "video/gfx.h"
25
#include "emu.h"
25
#include "emu.h"
26
#include "video/filters/ntsc.h"
26
#include "palette.h"
27
28
_turn_off_effect turn_off_effect;
27
29
28
BYTE tv_noise_init(void) {
30
BYTE tv_noise_init(void) {
29
	uint32_t *palette;
31
	uint32_t *palette;
(-)puNES-0.105.org/src/video/effects/tv_noise.h (-5 / +7 lines)
Lines 21-37 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
typedef struct _turn_off_effect {
25
	void *palette;
26
	void *ntsc;
27
} _turn_off_effect;
28
29
extern _turn_off_effect turn_off_effect;
30
24
#if defined (__cplusplus)
31
#if defined (__cplusplus)
25
#define EXTERNC extern "C"
32
#define EXTERNC extern "C"
26
#else
33
#else
27
#define EXTERNC
34
#define EXTERNC
28
#endif
35
#endif
29
36
30
EXTERNC struct _turn_off_effect {
31
	void *palette;
32
	void *ntsc;
33
} turn_off_effect;
34
35
EXTERNC BYTE tv_noise_init(void);
37
EXTERNC BYTE tv_noise_init(void);
36
EXTERNC void tv_noise_quit(void);
38
EXTERNC void tv_noise_quit(void);
37
EXTERNC void tv_noise_effect(void);
39
EXTERNC void tv_noise_effect(void);
(-)puNES-0.105.org/src/video/filters/hq2x.c (+1 lines)
Lines 19-24 Link Here
19
 */
19
 */
20
20
21
#include "video/filters/hqx.h"
21
#include "video/filters/hqx.h"
22
#include "palette.h"
22
#define _HQ2X_
23
#define _HQ2X_
23
#include "video/filters/hqx_inline.h"
24
#include "video/filters/hqx_inline.h"
24
#undef  _HQ2X_
25
#undef  _HQ2X_
(-)puNES-0.105.org/src/video/filters/hq3x.c (+1 lines)
Lines 19-24 Link Here
19
 */
19
 */
20
20
21
#include "video/filters/hqx.h"
21
#include "video/filters/hqx.h"
22
#include "palette.h"
22
#define _HQ3X_
23
#define _HQ3X_
23
#include "video/filters/hqx_inline.h"
24
#include "video/filters/hqx_inline.h"
24
#undef  _HQ3X_
25
#undef  _HQ3X_
(-)puNES-0.105.org/src/video/filters/hq4x.c (+1 lines)
Lines 19-24 Link Here
19
 */
19
 */
20
20
21
#include "video/filters/hqx.h"
21
#include "video/filters/hqx.h"
22
#include "palette.h"
22
#define _HQ4X_
23
#define _HQ4X_
23
#include "video/filters/hqx_inline.h"
24
#include "video/filters/hqx_inline.h"
24
#undef  _HQ4X_
25
#undef  _HQ4X_
(-)puNES-0.105.org/src/video/filters/hqx.c (-1 / +4 lines)
Lines 16-27 Link Here
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
17
 */
18
18
19
#include "video/filters/hqx.h"
19
#include "video/gfx.h"
20
#include "palette.h"
20
#include "ppu.h"
21
#include "ppu.h"
21
22
22
uint32_t RGBtoYUV[NUM_COLORS];
23
uint32_t RGBtoYUV[NUM_COLORS];
23
uint32_t YUV1, YUV2;
24
uint32_t YUV1, YUV2;
24
25
26
_hqnx hqnx;
27
25
void hqx_init(void) {
28
void hqx_init(void) {
26
	/* Initalize RGB to YUV lookup table */
29
	/* Initalize RGB to YUV lookup table */
27
	uint32_t i, r, g, b, y, u, v;
30
	uint32_t i, r, g, b, y, u, v;
(-)puNES-0.105.org/src/video/filters/hqx.h (-10 / +10 lines)
Lines 23-45 Link Here
23
#define __HQX_H_
23
#define __HQX_H_
24
24
25
#include "common.h"
25
#include "common.h"
26
#include "video/gfx.h"
27
#include "palette.h"
28
26
29
#if defined (__cplusplus)
27
typedef struct _hqnx {
30
#define EXTERNC extern "C"
31
#else
32
#define EXTERNC
33
#endif
34
35
EXTERNC struct _hqx {
36
	WORD sx;
28
	WORD sx;
37
	WORD sy;
29
	WORD sy;
38
	WORD startx;
30
	WORD startx;
39
	WORD rows;
31
	WORD rows;
40
	WORD lines;
32
	WORD lines;
41
	WORD dst_rows;
33
	WORD dst_rows;
42
} hqnx;
34
} _hqnx;
35
36
extern _hqnx hqnx;
37
38
#if defined (__cplusplus)
39
#define EXTERNC extern "C"
40
#else
41
#define EXTERNC
42
#endif
43
43
44
EXTERNC void hqx_init(void);
44
EXTERNC void hqx_init(void);
45
EXTERNC void hqNx(void);
45
EXTERNC void hqNx(void);
(-)puNES-0.105.org/src/video/filters/nes_ntsc.c (-1 lines)
Lines 1-6 Link Here
1
/* nes_ntsc 0.2.2. http://www.slack.net/~ant/ */
1
/* nes_ntsc 0.2.2. http://www.slack.net/~ant/ */
2
2
3
#include "video/filters/nes_ntsc.h"
4
#include "video/gfx.h"
3
#include "video/gfx.h"
5
#include "conf.h"
4
#include "conf.h"
6
#include "clock.h"
5
#include "clock.h"
(-)puNES-0.105.org/src/video/filters/ntsc.c (-1 / +2 lines)
Lines 18-26 Link Here
18
18
19
#include <stdio.h>
19
#include <stdio.h>
20
#include <stdlib.h>
20
#include <stdlib.h>
21
#include "video/filters/ntsc.h"
21
#include "video/gfx.h"
22
#include "ppu.h"
22
#include "ppu.h"
23
#include "overscan.h"
23
#include "overscan.h"
24
#include "palette.h"
24
25
25
nes_ntsc_t *ntsc;
26
nes_ntsc_t *ntsc;
26
nes_ntsc_setup_t format[3];
27
nes_ntsc_setup_t format[3];
(-)puNES-0.105.org/src/video/filters/ntsc.h (-2 lines)
Lines 21-28 Link Here
21
21
22
#include "video/filters/nes_ntsc.h"
22
#include "video/filters/nes_ntsc.h"
23
#include "common.h"
23
#include "common.h"
24
#include "video/gfx.h"
25
#include "palette.h"
26
24
27
enum ntsc_mode { COMPOSITE, SVIDEO, RGBMODE };
25
enum ntsc_mode { COMPOSITE, SVIDEO, RGBMODE };
28
26
(-)puNES-0.105.org/src/video/filters/scale2x.c (-1 / +1 lines)
Lines 18-24 Link Here
18
18
19
#include <stdio.h>
19
#include <stdio.h>
20
#include <stdlib.h>
20
#include <stdlib.h>
21
#include "video/filters/scale2x.h"
21
#include "video/gfx.h"
22
#include "ppu.h"
22
#include "ppu.h"
23
23
24
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
24
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
(-)puNES-0.105.org/src/video/filters/scale2x.h (-2 lines)
Lines 20-27 Link Here
20
#define SCALE2X_H_
20
#define SCALE2X_H_
21
21
22
#include "common.h"
22
#include "common.h"
23
#include "video/gfx.h"
24
#include "palette.h"
25
23
26
void scaleNx(void);
24
void scaleNx(void);
27
25
(-)puNES-0.105.org/src/video/filters/scale.c (-1 / +1 lines)
Lines 16-22 Link Here
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
17
 */
18
18
19
#include "video/filters/scale.h"
19
#include "video/gfx.h"
20
#include "ppu.h"
20
#include "ppu.h"
21
21
22
#define put_pixel(type, p0, p1)\
22
#define put_pixel(type, p0, p1)\
(-)puNES-0.105.org/src/video/filters/scale.h (-2 lines)
Lines 20-27 Link Here
20
#define SCALE_H_
20
#define SCALE_H_
21
21
22
#include "common.h"
22
#include "common.h"
23
#include "video/gfx.h"
24
#include "palette.h"
25
23
26
void scale_surface(void);
24
void scale_surface(void);
27
25
(-)puNES-0.105.org/src/video/filters/xBRZ.c (-1 / +1 lines)
Lines 16-22 Link Here
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
17
 */
18
18
19
#include "video/filters/xBRZ.h"
19
#include "video/gfx.h"
20
#include "ppu.h"
20
#include "ppu.h"
21
21
22
void xBRZ_init(void) {}
22
void xBRZ_init(void) {}
(-)puNES-0.105.org/src/video/filters/xBRZ.h (-5 / +4 lines)
Lines 20-26 Link Here
20
#define XBRZ_H_
20
#define XBRZ_H_
21
21
22
#include "common.h"
22
#include "common.h"
23
#include "video/gfx.h"
23
24
void xBRZ_init(void);
25
void xBRZ(void);
26
void xBRZ_mt(void);
24
27
25
#if defined (__cplusplus)
28
#if defined (__cplusplus)
26
#define EXTERNC extern "C"
29
#define EXTERNC extern "C"
Lines 28-37 Link Here
28
#define EXTERNC
31
#define EXTERNC
29
#endif
32
#endif
30
33
31
void xBRZ_init(void);
32
void xBRZ(void);
33
void xBRZ_mt(void);
34
35
EXTERNC void xbrz_scale(BYTE factor, const WORD *src, uint32_t *trg, uint32_t *palette, int width, int height);
34
EXTERNC void xbrz_scale(BYTE factor, const WORD *src, uint32_t *trg, uint32_t *palette, int width, int height);
36
EXTERNC void xbrz_scale_mt(BYTE factor, const WORD *src, uint32_t *trg, uint32_t *palette, int width, int height);
35
EXTERNC void xbrz_scale_mt(BYTE factor, const WORD *src, uint32_t *trg, uint32_t *palette, int width, int height);
37
36
(-)puNES-0.105.org/src/video/gfx.h (-11 / +11 lines)
Lines 98-111 typedef struct _viewport { Link Here
98
	int x, y;
98
	int x, y;
99
	int w, h;
99
	int w, h;
100
} _viewport;
100
} _viewport;
101
101
typedef struct _gfx {
102
#if defined (__cplusplus)
103
#define EXTERNC extern "C"
104
#else
105
#define EXTERNC
106
#endif
107
108
EXTERNC struct _gfx {
109
	BYTE PSS;
102
	BYTE PSS;
110
	BYTE save_screenshot;
103
	BYTE save_screenshot;
111
	BYTE scale_before_fscreen;
104
	BYTE scale_before_fscreen;
Lines 134-145 EXTERNC struct _gfx { Link Here
134
			WORD height;
127
			WORD height;
135
		} data;
128
		} data;
136
	} filter;
129
	} filter;
137
} gfx;
130
} _gfx;
131
132
extern _gfx gfx;
133
134
#if defined (__cplusplus)
135
#define EXTERNC extern "C"
136
#else
137
#define EXTERNC
138
#endif
138
139
139
EXTERNC BYTE gfx_init(void);
140
EXTERNC BYTE gfx_init(void);
140
EXTERNC void gfx_quit(void);
141
EXTERNC void gfx_quit(void);
141
EXTERNC void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette,
142
EXTERNC void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, BYTE force_scale, BYTE force_palette);
142
	BYTE force_scale, BYTE force_palette);
143
EXTERNC void gfx_draw_screen(void);
143
EXTERNC void gfx_draw_screen(void);
144
144
145
#if defined (WITH_D3D9)
145
#if defined (WITH_D3D9)
(-)puNES-0.105.org/src/video/gfx.h.orig (+166 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#ifndef GFX_H_
20
#define GFX_H_
21
22
#include "common.h"
23
#include "text.h"
24
#include "video/filters/scale.h"
25
#include "video/filters/scale2x.h"
26
#include "video/filters/hqx.h"
27
#include "video/filters/ntsc.h"
28
#include "video/filters/xBRZ.h"
29
30
#define FH_SHADERS_GEST
31
#define change_color(plt, blck, index, color, operation)\
32
	tmp = plt[index].color + operation;\
33
	plt[index].color = (tmp < 0 ? blck : (tmp > 0xFF ? 0xFF : tmp))
34
#define rgb_modifier(ntscin, plt, blck, red, green, blue)\
35
	/* prima ottengo la paletta monocromatica */\
36
	ntsc_set(ntscin, cfg->ntsc_format, PALETTE_MONO, 0, 0, (BYTE *)plt);\
37
	/* quindi la modifico */\
38
	{\
39
		WORD i;\
40
		SWORD tmp;\
41
		for (i = 0; i < NUM_COLORS; i++) {\
42
			/* rosso */\
43
			change_color(plt, blck, i, r, red);\
44
			/* green */\
45
			change_color(plt, blck, i, g, green);\
46
			/* blue */\
47
			change_color(plt, blck, i, b, blue);\
48
		}\
49
	}\
50
	/* ed infine utilizzo la nuova */\
51
	ntsc_set(ntscin, cfg->ntsc_format, FALSE, 0, (BYTE *)plt,(BYTE *)plt)
52
#if defined (__unix__)
53
#define	gfx_os_color(r, g, b) gfx_color(0, r, g, b);
54
#else
55
#define	gfx_os_color(r, g, b) gfx_color(255, r, g, b);
56
#endif
57
58
enum fullscreen_type { NO_FULLSCR, FULLSCR, FULLSCR_IN_WINDOW };
59
enum scale_type { X1 = 1, X2, X3, X4, X5, X6 };
60
enum par_type { PAR11, PAR54, PAR87, PAR118 };
61
enum filters_type {
62
	NO_FILTER,
63
	SCALE2X,
64
	SCALE3X,
65
	SCALE4X,
66
	HQ2X,
67
	HQ3X,
68
	HQ4X,
69
	NTSC_FILTER,
70
	XBRZ2X,
71
	XBRZ3X,
72
	XBRZ4X,
73
	XBRZ5X,
74
	XBRZ6X,
75
	XBRZ2XMT,
76
	XBRZ3XMT,
77
	XBRZ4XMT,
78
	XBRZ5XMT,
79
	XBRZ6XMT
80
};
81
enum shader_type {
82
	NO_SHADER,
83
	SHADER_CRTDOTMASK,
84
	SHADER_CRTSCANLINES,
85
	SHADER_CRTWITHCURVE,
86
	SHADER_EMBOSS,
87
	SHADER_NOISE,
88
	SHADER_NTSC2PHASECOMPOSITE,
89
	SHADER_OLDTV,
90
	SHADER_FILE,
91
	SHADER_LAST = SHADER_FILE,
92
};
93
enum overcan_type { OSCAN_OFF, OSCAN_ON, OSCAN_DEFAULT };
94
enum gfx_info_type { CURRENT, NO_OVERSCAN, MONITOR, VIDEO_MODE, PASS0 };
95
enum no_change { NO_CHANGE = 255 };
96
97
typedef struct _viewport {
98
	int x, y;
99
	int w, h;
100
} _viewport;
101
102
#if defined (__cplusplus)
103
#define EXTERNC extern "C"
104
#else
105
#define EXTERNC
106
#endif
107
108
EXTERNC struct _gfx {
109
	BYTE PSS;
110
	BYTE save_screenshot;
111
	BYTE scale_before_fscreen;
112
	BYTE type_of_fscreen_in_use;
113
	BYTE bit_per_pixel;
114
	float width_pixel;
115
	WORD rows, lines;
116
	SDBWORD w[5], h[5];
117
	float w_pr, h_pr;
118
	float pixel_aspect_ratio;
119
	float device_pixel_ratio;
120
	uint32_t *palette;
121
	uTCHAR last_shader_file[LENGTH_FILE_NAME_LONG];
122
	_viewport vp;
123
	struct _gfx_filter {
124
		void (*func)(void);
125
126
		float width_pixel;
127
		BYTE factor;
128
129
		struct _gfx_filter_data {
130
			void *palette;
131
			uint32_t pitch;
132
			void *pix;
133
			WORD width;
134
			WORD height;
135
		} data;
136
	} filter;
137
} gfx;
138
139
EXTERNC BYTE gfx_init(void);
140
EXTERNC void gfx_quit(void);
141
EXTERNC void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette,
142
	BYTE force_scale, BYTE force_palette);
143
EXTERNC void gfx_draw_screen(void);
144
145
#if defined (WITH_D3D9)
146
EXTERNC void gfx_control_changed_adapter(void *monitor);
147
#endif
148
149
EXTERNC uint32_t gfx_color(BYTE alpha, BYTE r, BYTE g, BYTE b);
150
EXTERNC void gfx_palette_update(void);
151
152
EXTERNC void gfx_cursor_init(void);
153
EXTERNC void gfx_cursor_set(void);
154
155
EXTERNC void gfx_text_create_surface(_txt_element *ele);
156
EXTERNC void gfx_text_release_surface(_txt_element *ele);
157
EXTERNC void gfx_text_rect_fill(_txt_element *ele, _txt_rect *rect, uint32_t color);
158
EXTERNC void gfx_text_reset(void);
159
EXTERNC void gfx_text_clear(_txt_element *ele);
160
EXTERNC void gfx_text_blit(_txt_element *ele, _txt_rect *rect);
161
162
EXTERNC void gfx_apply_filter(void);
163
164
#undef EXTERNC
165
166
#endif /* GFX_H_ */
(-)puNES-0.105.org/src/video/gfx_thread.c (+2 lines)
Lines 54-59 struct _gfx_thread { Link Here
54
	int pause_calls;
54
	int pause_calls;
55
} gfx_thread;
55
} gfx_thread;
56
56
57
_gfx_thread_public gfx_thread_public;
58
57
BYTE gfx_thread_init(void) {
59
BYTE gfx_thread_init(void) {
58
	memset(&gfx_thread_public, 0x00, sizeof(gfx_thread_public));
60
	memset(&gfx_thread_public, 0x00, sizeof(gfx_thread_public));
59
	memset(&gfx_thread, 0x00, sizeof(gfx_thread));
61
	memset(&gfx_thread, 0x00, sizeof(gfx_thread));
(-)puNES-0.105.org/src/video/gfx_thread.h (-4 / +6 lines)
Lines 21-36 Link Here
21
21
22
#include "common.h"
22
#include "common.h"
23
23
24
typedef struct _gfx_thread_public {
25
	BYTE filtering;
26
} _gfx_thread_public;
27
28
extern _gfx_thread_public gfx_thread_public;
29
24
#if defined (__cplusplus)
30
#if defined (__cplusplus)
25
#define EXTERNC extern "C"
31
#define EXTERNC extern "C"
26
#else
32
#else
27
#define EXTERNC
33
#define EXTERNC
28
#endif
34
#endif
29
35
30
EXTERNC struct _gfx_thread_public {
31
	BYTE filtering;
32
} gfx_thread_public;
33
34
EXTERNC BYTE gfx_thread_init(void);
36
EXTERNC BYTE gfx_thread_init(void);
35
EXTERNC void gfx_thread_quit(void);
37
EXTERNC void gfx_thread_quit(void);
36
38
(-)puNES-0.105.org/src/video/opengl/gfx.c (-5 / +4 lines)
Lines 22-33 Link Here
22
#include <stdlib.h>
22
#include <stdlib.h>
23
#include <string.h>
23
#include <string.h>
24
#include <unistd.h>
24
#include <unistd.h>
25
#include "video/gfx.h"
25
#include "opengl.h"
26
#include "video/gfx_thread.h"
26
#include "video/gfx_thread.h"
27
#include "fps.h"
28
#include "info.h"
27
#include "info.h"
29
#include "conf.h"
28
#include "conf.h"
30
#include "opengl.h"
31
#include "clock.h"
29
#include "clock.h"
32
#include "ppu.h"
30
#include "ppu.h"
33
#include "gui.h"
31
#include "gui.h"
Lines 38-43 Link Here
38
#include "video/effects/pause.h"
36
#include "video/effects/pause.h"
39
#include "video/effects/tv_noise.h"
37
#include "video/effects/tv_noise.h"
40
38
39
_gfx gfx;
40
41
BYTE gfx_init(void) {
41
BYTE gfx_init(void) {
42
	gfx.save_screenshot = FALSE;
42
	gfx.save_screenshot = FALSE;
43
43
Lines 113-120 void gfx_quit(void) { Link Here
113
	ntsc_quit();
113
	ntsc_quit();
114
	text_quit();
114
	text_quit();
115
}
115
}
116
void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette,
116
void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette, BYTE force_scale, BYTE force_palette) {
117
	BYTE force_scale, BYTE force_palette) {
118
	BYTE set_mode;
117
	BYTE set_mode;
119
	WORD width, height;
118
	WORD width, height;
120
	DBWORD old_shader = cfg->shader;
119
	DBWORD old_shader = cfg->shader;
(-)puNES-0.105.org/src/video/opengl/gfx.c.orig (+605 lines)
Line 0 Link Here
1
/*
2
 *  Copyright (C) 2010-2019 Fabio Cavallo (aka FHorse)
3
 *
4
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
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
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
17
 */
18
19
#if defined (__unix__)
20
#include <pthread.h>
21
#endif
22
#include <stdlib.h>
23
#include <string.h>
24
#include <unistd.h>
25
#include "video/gfx.h"
26
#include "video/gfx_thread.h"
27
#include "fps.h"
28
#include "info.h"
29
#include "conf.h"
30
#include "opengl.h"
31
#include "clock.h"
32
#include "ppu.h"
33
#include "gui.h"
34
#include "palette.h"
35
#include "paldef.h"
36
#include "vs_system.h"
37
#include "settings.h"
38
#include "video/effects/pause.h"
39
#include "video/effects/tv_noise.h"
40
41
BYTE gfx_init(void) {
42
	gfx.save_screenshot = FALSE;
43
44
	gui_screen_info();
45
46
	if (gui_create() == EXIT_ERROR) {
47
		fprintf(stderr, "gui initialization failed\n");
48
		return (EXIT_ERROR);
49
	}
50
51
	if (gfx_thread_init() == EXIT_ERROR) {
52
		fprintf(stderr, "Unable to allocate the gfx thread\n");
53
		return (EXIT_ERROR);
54
	}
55
56
	if (opengl_init() == EXIT_ERROR) {
57
		fprintf(stderr, "OpenGL not supported.\n");
58
		return (EXIT_ERROR);
59
	}
60
61
	// inizializzo l'ntsc che utilizzero' non solo
62
	// come filtro ma anche nel gfx_set_screen() per
63
	// generare la paletta dei colori.
64
	if (ntsc_init(0, 0, 0, 0, 0) == EXIT_ERROR) {
65
		return (EXIT_ERROR);
66
	}
67
68
	// mi alloco una zona di memoria dove conservare la
69
	// paletta nel formato di visualizzazione.
70
	if (!(gfx.palette = (uint32_t *) malloc(NUM_COLORS * sizeof(uint32_t)))) {
71
		fprintf(stderr, "Unable to allocate the palette\n");
72
		return (EXIT_ERROR);
73
	}
74
75
	if (pause_init() == EXIT_ERROR) {
76
		fprintf(stderr, "pause initialization failed\n");
77
		return (EXIT_ERROR);
78
	}
79
80
	if (tv_noise_init() == EXIT_ERROR) {
81
		fprintf(stderr, "tv_noise initialization failed\n");
82
		return (EXIT_ERROR);
83
	}
84
85
	// casi particolari provenienti dal settings_file_parse() e cmd_line_parse()
86
	if (cfg->fullscreen == FULLSCR) {
87
		gfx.scale_before_fscreen = cfg->scale;
88
	}
89
90
	if (cfg->fullscreen) {
91
		gfx_set_screen(cfg->scale, cfg->filter, cfg->shader, NO_FULLSCR, cfg->palette, FALSE, FALSE);
92
		cfg->fullscreen = NO_FULLSCR;
93
		cfg->scale = gfx.scale_before_fscreen;
94
		gui_fullscreen();
95
	} else {
96
		gfx_set_screen(cfg->scale, cfg->filter, cfg->shader, NO_FULLSCR, cfg->palette, FALSE, FALSE);
97
	}
98
99
	return (EXIT_OK);
100
}
101
void gfx_quit(void) {
102
	gfx_thread_quit();
103
104
	if (gfx.palette) {
105
		free(gfx.palette);
106
		gfx.palette = NULL;
107
	}
108
109
	pause_quit();
110
	tv_noise_quit();
111
112
	opengl_quit();
113
	ntsc_quit();
114
	text_quit();
115
}
116
void gfx_set_screen(BYTE scale, DBWORD filter, DBWORD shader, BYTE fullscreen, BYTE palette,
117
	BYTE force_scale, BYTE force_palette) {
118
	BYTE set_mode;
119
	WORD width, height;
120
	DBWORD old_shader = cfg->shader;
121
122
	gfx_thread_pause();
123
124
	if (shader_effect.params > 0) {
125
		settings_shp_save();
126
	}
127
128
	gfx_set_screen_start:
129
	set_mode = FALSE;
130
	width = 0, height = 0;
131
132
	// l'ordine dei vari controlli non deve essere cambiato:
133
	// 0) overscan
134
	// 1) filtro
135
	// 2) fullscreen
136
	// 3) fattore di scala
137
	// 4) tipo di paletta
138
139
	// overscan
140
	{
141
		overscan.enabled = cfg->oscan;
142
143
		gfx.rows = SCR_ROWS;
144
		gfx.lines = SCR_LINES;
145
146
		if (overscan.enabled == OSCAN_DEFAULT) {
147
			overscan.enabled = cfg->oscan_default;
148
		}
149
		if (overscan.enabled) {
150
			gfx.rows -= (overscan.borders->left + overscan.borders->right);
151
			gfx.lines -= (overscan.borders->up + overscan.borders->down);
152
		}
153
	}
154
155
	// filtro
156
	if (filter == NO_CHANGE) {
157
		filter = cfg->filter;
158
	}
159
	if ((filter != cfg->filter) || info.on_cfg || force_scale) {
160
		switch (filter) {
161
			default:
162
			case NO_FILTER:
163
				gfx.filter.func = scale_surface;
164
				gfx.filter.factor = X1;
165
				break;
166
			case SCALE2X:
167
			case SCALE3X:
168
			case SCALE4X:
169
				gfx.filter.func = scaleNx;
170
				gfx.filter.factor = filter + 1;
171
				break;
172
			case HQ2X:
173
			case HQ3X:
174
			case HQ4X:
175
				gfx.filter.func = hqNx;
176
				gfx.filter.factor = filter - 2;
177
				break;
178
			case XBRZ2X:
179
			case XBRZ3X:
180
			case XBRZ4X:
181
			case XBRZ5X:
182
			case XBRZ6X:
183
				gfx.filter.func = xBRZ;
184
				gfx.filter.factor = filter - 6;
185
				break;
186
			case XBRZ2XMT:
187
			case XBRZ3XMT:
188
			case XBRZ4XMT:
189
			case XBRZ5XMT:
190
			case XBRZ6XMT:
191
				gfx.filter.func = xBRZ_mt;
192
				gfx.filter.factor = filter - 11;
193
				break;
194
			case NTSC_FILTER:
195
				gfx.filter.func = ntsc_surface;
196
				gfx.filter.factor = X2;
197
				break;
198
		}
199
		// forzo il controllo del fattore di scale
200
		force_scale = TRUE;
201
		// indico che devo cambiare il video mode
202
		set_mode = TRUE;
203
	}
204
205
	// shader
206
	if (shader == NO_CHANGE) {
207
		shader = cfg->shader;
208
	}
209
210
	// fullscreen
211
	if (fullscreen == NO_CHANGE) {
212
		fullscreen = cfg->fullscreen;
213
	}
214
	if ((fullscreen != cfg->fullscreen) || info.on_cfg) {
215
		// forzo il controllo del fattore di scale
216
		force_scale = TRUE;
217
		// indico che devo cambiare il video mode
218
		set_mode = TRUE;
219
	}
220
221
	// fattore di scala
222
	if (scale == NO_CHANGE) {
223
		scale = cfg->scale;
224
	}
225
	if ((scale != cfg->scale) || info.on_cfg || force_scale) {
226
		if (filter == NTSC_FILTER) {
227
			width = gfx.w[PASS0] = gfx.w[NO_OVERSCAN] = NES_NTSC_OUT_WIDTH(SCR_ROWS);
228
			gfx.filter.width_pixel = (float)nes_ntsc_out_chunk / (float)nes_ntsc_in_chunk;
229
			if (overscan.enabled) {
230
				width -= ((float)(overscan.borders->left + overscan.borders->right) * gfx.filter.width_pixel);
231
			}
232
			switch (scale) {
233
				case X2:
234
					gfx.width_pixel = gfx.filter.width_pixel;
235
					break;
236
				default:
237
					width = ((float)width / 2.0f) * (float)scale;
238
					gfx.w[NO_OVERSCAN] = ((float)gfx.w[NO_OVERSCAN] / 2.0f) * (float)scale;
239
					gfx.width_pixel = (gfx.filter.width_pixel / 2.0f) * (float)scale;
240
					break;
241
			}
242
		} else {
243
			width = gfx.rows * scale;
244
			gfx.w[NO_OVERSCAN] = SCR_ROWS * scale;
245
			gfx.w[PASS0] = SCR_ROWS * gfx.filter.factor;
246
			gfx.filter.width_pixel = gfx.filter.factor;
247
			gfx.width_pixel = scale;
248
		}
249
		gfx.w[CURRENT] = width;
250
251
		height = gfx.lines * scale;
252
		gfx.h[CURRENT] = height;
253
		gfx.h[NO_OVERSCAN] = SCR_LINES * scale;
254
		gfx.h[PASS0] = SCR_LINES * gfx.filter.factor;
255
256
		set_mode = TRUE;
257
	}
258
259
	// paletta
260
	if (palette == NO_CHANGE) {
261
		palette = cfg->palette;
262
	}
263
	if ((palette != cfg->palette) || info.on_cfg || force_palette) {
264
		if (palette == PALETTE_FILE) {
265
			if (ustrlen(cfg->palette_file) != 0) {
266
				if (palette_load_from_file(cfg->palette_file) == EXIT_ERROR) {
267
					umemset(cfg->palette_file, 0x00, usizeof(cfg->palette_file));
268
					text_add_line_info(1, "[red]error on palette file");
269
					if (cfg->palette != PALETTE_FILE) {
270
						palette = cfg->palette;
271
					} else if (machine.type == NTSC) {
272
						palette = PALETTE_NTSC;
273
					} else {
274
						palette = PALETTE_SONY;
275
					}
276
				} else {
277
					ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_base_file, 0, (BYTE *)palette_RGB.noswap);
278
				}
279
			}
280
		}
281
282
		switch (palette) {
283
			case PALETTE_PAL:
284
				ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_base_pal, 0, (BYTE *)palette_RGB.noswap);
285
				break;
286
			case PALETTE_NTSC:
287
				ntsc_set(NULL, cfg->ntsc_format, FALSE, 0, 0, (BYTE *)palette_RGB.noswap);
288
				break;
289
			case PALETTE_FRBX_NOSTALGIA:
290
				ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_firebrandx_nostalgia_FBX, 0, (BYTE *)palette_RGB.noswap);
291
				break;
292
			case PALETTE_FRBX_YUV:
293
				ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_firebrandx_YUV_v3, 0, (BYTE *)palette_RGB.noswap);
294
				break;
295
			case PALETTE_GREEN:
296
				rgb_modifier(NULL, palette_RGB.noswap, 0x00, -0x20, 0x20, -0x20);
297
				break;
298
			case PALETTE_FILE:
299
				break;
300
			default:
301
				ntsc_set(NULL, cfg->ntsc_format, palette, 0, 0, (BYTE *)palette_RGB.noswap);
302
				break;
303
		}
304
305
		if (vs_system.enabled) {
306
			switch (vs_system.ppu) {
307
				case RP2C03B:
308
				case RP2C03G:
309
					break;
310
				case RP2C04:
311
					ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0001, 0, (BYTE *)palette_RGB.noswap);
312
					break;
313
				case RP2C04_0002:
314
					ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0002, 0, (BYTE *)palette_RGB.noswap);
315
					break;
316
				case RP2C04_0003:
317
					ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0003, 0, (BYTE *)palette_RGB.noswap);
318
					break;
319
				case RP2C04_0004:
320
					ntsc_set(NULL, cfg->ntsc_format, FALSE, (BYTE *)palette_RP2C04_0004, 0, (BYTE *)palette_RGB.noswap);
321
					break;
322
				case RC2C03B:
323
				case RC2C03C:
324
				case RC2C05_01:
325
				case RC2C05_02:
326
				case RC2C05_03:
327
				case RC2C05_04:
328
				case RC2C05_05:
329
				default:
330
					break;
331
			}
332
		}
333
	}
334
335
	gfx_palette_update();
336
337
	// salvo il nuovo fattore di scala
338
	cfg->scale = scale;
339
	// salvo il nuovo filtro
340
	cfg->filter = filter;
341
	// salvo la nuova shader
342
	cfg->shader = shader;
343
	// salvo il nuovo stato del fullscreen
344
	cfg->fullscreen = fullscreen;
345
	// salvo il nuovo tipo di paletta
346
	cfg->palette = palette;
347
348
	// Pixel Aspect Ratio
349
	if (cfg->filter == NTSC_FILTER) {
350
		gfx.pixel_aspect_ratio = 1.0f;
351
	} else {
352
		switch (cfg->pixel_aspect_ratio) {
353
			default:
354
			case PAR11:
355
				gfx.pixel_aspect_ratio = 1.0f;
356
				break;
357
			case PAR54:
358
				gfx.pixel_aspect_ratio = 5.0f / 4.0f;
359
				break;
360
			case PAR87:
361
				gfx.pixel_aspect_ratio = 8.0f / 7.0f;
362
				break;
363
			case PAR118:
364
				gfx.pixel_aspect_ratio = 2950000.0f / 2128137.0f;
365
				break;
366
		}
367
	}
368
369
	{
370
		gfx.PSS = ((cfg->pixel_aspect_ratio != PAR11) && cfg->PAR_soft_stretch) ? TRUE : FALSE;
371
372
		if (shaders_set(shader) == EXIT_ERROR) {
373
			umemcpy(cfg->shader_file, gfx.last_shader_file, usizeof(cfg->shader_file));
374
			if (old_shader == shader) {
375
				shader = NO_SHADER;
376
			} else {
377
				shader = old_shader;
378
			}
379
			goto gfx_set_screen_start;
380
		}
381
382
		if (shader_effect.params > 0) {
383
			settings_shp_parse();
384
		}
385
386
		if (set_mode) {
387
			if (fullscreen == TRUE) {
388
				gfx.w[VIDEO_MODE] = gfx.w[MONITOR];
389
				gfx.h[VIDEO_MODE] = gfx.h[MONITOR];
390
			} else if (cfg->oscan_black_borders) {
391
				gfx.w[VIDEO_MODE] = gfx.w[NO_OVERSCAN];
392
				gfx.h[VIDEO_MODE] = gfx.h[NO_OVERSCAN];
393
			} else {
394
				gfx.w[VIDEO_MODE] = width;
395
				gfx.h[VIDEO_MODE] = height;
396
			}
397
398
			// Pixel Aspect Ratio
399
			if (cfg->pixel_aspect_ratio && !fullscreen) {
400
				gfx.w[VIDEO_MODE] = (gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio);
401
402
				if (overscan.enabled && !cfg->oscan_black_borders) {
403
					float brd = 0;
404
405
					brd = (float)gfx.w[VIDEO_MODE] / (float)SCR_ROWS;
406
					brd *= (overscan.borders->right + overscan.borders->left);
407
408
					gfx.w[VIDEO_MODE] -= brd;
409
				}
410
			}
411
412
			// faccio quello che serve prima del setvideo
413
			gui_set_video_mode();
414
		}
415
416
		switch (opengl_context_create()) {
417
			case EXIT_ERROR:
418
				fprintf(stderr, "OPENGL: Unable to initialize opengl context\n");
419
				break;
420
			case EXIT_ERROR_SHADER:
421
				text_add_line_info(1, "[red]errors[normal] on shader, use [green]'No shader'");
422
				fprintf(stderr, "OPENGL: Error on loading the shaders, switch to \"No shader\"\n");
423
				umemcpy(cfg->shader_file, gfx.last_shader_file, usizeof(cfg->shader_file));
424
				shader = NO_SHADER;
425
				goto gfx_set_screen_start;
426
		}
427
428
	}
429
430
	// calcolo le proporzioni tra il disegnato a video (overscan e schermo
431
	// con le dimensioni per il filtro NTSC compresi) e quello che dovrebbe
432
	// essere (256 x 240). Mi serve per calcolarmi la posizione del puntatore
433
	// dello zapper.
434
	if (cfg->fullscreen) {
435
		gfx.w_pr = (float)gfx.vp.w / (float)SCR_ROWS;
436
		gfx.h_pr = (float)gfx.vp.h / (float)SCR_LINES;
437
	} else {
438
		gfx.w_pr = (float)(gfx.w[NO_OVERSCAN] * gfx.pixel_aspect_ratio) / (float)SCR_ROWS;
439
		gfx.h_pr = (float)gfx.h[NO_OVERSCAN] / (float)SCR_LINES;
440
	}
441
442
	gfx_thread_continue();
443
444
	// setto il titolo della finestra
445
	gui_update();
446
447
	if (info.on_cfg == TRUE) {
448
		info.on_cfg = FALSE;
449
	}
450
}
451
void gfx_draw_screen(void) {
452
	if (gfx_thread_public.filtering == TRUE) {
453
		fps.frames_skipped++;
454
		return;
455
	}
456
457
	screen.rd = screen.wr;
458
459
	if (info.doublebuffer == TRUE) {
460
		screen.index = !screen.index;
461
		screen.last_completed_wr = screen.wr;
462
		screen.wr = &screen.buff[screen.index];
463
	} else {
464
		screen.rd = screen.wr = screen.last_completed_wr;
465
	}
466
467
	if (screen.rd->ready == FALSE) {
468
		screen.rd->ready = TRUE;
469
	}
470
}
471
472
uint32_t gfx_color(BYTE a, BYTE r, BYTE g, BYTE b) {
473
	return (gui_color(a, r, g, b));
474
}
475
void gfx_palette_update(void) {
476
	WORD i;
477
478
	if ((cfg->disable_swap_emphasis_pal == FALSE) && ((machine.type == PAL) || (machine.type == DENDY))) {
479
		palette_RGB.in_use = &palette_RGB.swapped[0];
480
	} else {
481
		palette_RGB.in_use = &palette_RGB.noswap[0];
482
	}
483
484
	// inizializzo in ogni caso la tabella YUV dell'hqx
485
	hqx_init();
486
487
	// memorizzo i colori della paletta nel formato di visualizzazione
488
	for (i = 0; i < NUM_COLORS; i++) {
489
		gfx.palette[i] = gfx_os_color(palette_RGB.in_use[i].r, palette_RGB.in_use[i].g, palette_RGB.in_use[i].b);
490
	}
491
}
492
493
void gfx_cursor_init(void) {
494
	gui_cursor_init();
495
	gui_cursor_set();
496
}
497
void gfx_cursor_set(void) {
498
	gui_cursor_set();
499
}
500
501
void gfx_text_create_surface(_txt_element *ele) {
502
	uint32_t size = (ele->h * ele->w) * sizeof(uint32_t);
503
504
	ele->surface = malloc(size);
505
	memset(ele->surface, 0x00, size);
506
507
	ele->blank = malloc(size);
508
	memset(ele->blank, 0x00, size);
509
}
510
void gfx_text_release_surface(_txt_element *ele) {
511
	if (ele->surface) {
512
		free(ele->surface);
513
		ele->surface = NULL;
514
	}
515
	if (ele->blank) {
516
		free(ele->blank);
517
		ele->blank = NULL;
518
	}
519
}
520
void gfx_text_rect_fill(_txt_element *ele, _txt_rect *rect, uint32_t color) {
521
	uint32_t *pbits;
522
	uint32_t pitch;
523
	int w, h;
524
525
	pitch = ele->w;
526
	pbits = (uint32_t *)ele->surface;
527
	pbits += (rect->y * ele->w) + rect->x;
528
529
	for (h = 0; h < rect->h; h++) {
530
		for (w = 0; w < rect->w; w++) {
531
			(*(pbits + w)) = color;
532
		}
533
		pbits += pitch;
534
	}
535
}
536
void gfx_text_reset(void) {
537
	txt_table[TXT_NORMAL] = gfx_color(0, 0xFF, 0xFF, 0xFF);
538
	txt_table[TXT_RED]    = gfx_color(0, 0xFF, 0x4C, 0x3E);
539
	txt_table[TXT_YELLOW] = gfx_color(0, 0xFF, 0xFF, 0   );
540
	txt_table[TXT_GREEN]  = gfx_color(0, 0   , 0xFF, 0   );
541
	txt_table[TXT_CYAN]   = gfx_color(0, 0   , 0xFF, 0xFF);
542
	txt_table[TXT_BROWN]  = gfx_color(0, 0xEB, 0x89, 0x31);
543
	txt_table[TXT_BLUE]   = gfx_color(0, 0x2D, 0x8D, 0xBD);
544
	txt_table[TXT_GRAY]   = gfx_color(0, 0xA0, 0xA0, 0xA0);
545
	txt_table[TXT_BLACK]  = gfx_color(0, 0   , 0   , 0   );
546
}
547
void gfx_text_clear(_txt_element *ele) {
548
	int x, y;
549
550
	if (!ele->blank) {
551
		return;
552
	}
553
554
	text_calculate_real_x_y(ele, &x, &y);
555
556
	glBindTexture(GL_TEXTURE_2D, opengl.text.id);
557
	glPixelStorei(GL_UNPACK_ROW_LENGTH, ele->w);
558
	glTexSubImage2D(GL_TEXTURE_2D, 0, x, y, ele->w, ele->h, TI_FRM, TI_TYPE, ele->blank);
559
	glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
560
}
561
void gfx_text_blit(_txt_element *ele, _txt_rect *rect) {
562
	if (!cfg->txt_on_screen) {
563
		return;
564
	}
565
	glBindTexture(GL_TEXTURE_2D, opengl.text.id);
566
	glPixelStorei(GL_UNPACK_ROW_LENGTH, rect->w);
567
	glTexSubImage2D(GL_TEXTURE_2D, 0, rect->x, rect->y, rect->w, rect->h, TI_FRM, TI_TYPE, ele->surface);
568
	glPixelStorei(GL_UNPACK_ROW_LENGTH, 0);
569
}
570
571
void gfx_apply_filter(void) {
572
	gfx.filter.data.palette = (void *)gfx.palette;
573
574
	//applico la paletta adeguata.
575
	if (cfg->filter == NTSC_FILTER) {
576
		gfx.filter.data.palette = NULL;
577
	}
578
	if (info.no_rom | info.turn_off) {
579
		if (cfg->filter == NTSC_FILTER) {
580
			gfx.filter.data.palette = turn_off_effect.ntsc;
581
		} else {
582
			gfx.filter.data.palette = (void *)turn_off_effect.palette;
583
		}
584
	} else if (info.pause) {
585
		if (!cfg->disable_sepia_color) {
586
			if (cfg->filter == NTSC_FILTER) {
587
				gfx.filter.data.palette = pause_effect.ntsc;
588
			} else {
589
				gfx.filter.data.palette = pause_effect.palette;
590
			}
591
		}
592
	}
593
594
	gfx_thread_lock();
595
596
	// applico l'effetto desiderato
597
	gfx.filter.data.pitch = opengl.surface.pitch;
598
	gfx.filter.data.pix = opengl.surface.pixels;
599
	gfx.filter.data.width = opengl.surface.w;
600
	gfx.filter.data.height = opengl.surface.h;
601
	gfx.filter.func();
602
603
	gfx_thread_unlock();
604
	gui_screen_update();
605
}
(-)puNES-0.105.org/src/video/opengl/opengl.c (+3 lines)
Lines 23-28 Link Here
23
#include <unistd.h>
23
#include <unistd.h>
24
#include "opengl.h"
24
#include "opengl.h"
25
#include "video/gfx_thread.h"
25
#include "video/gfx_thread.h"
26
#include "overscan.h"
26
#include "info.h"
27
#include "info.h"
27
#include "conf.h"
28
#include "conf.h"
28
#include "emu.h"
29
#include "emu.h"
Lines 42-47 Link Here
42
#define _SCR_LINES_NOBRD\
43
#define _SCR_LINES_NOBRD\
43
	(float)SCR_LINES
44
	(float)SCR_LINES
44
45
46
_opengl opengl;
47
45
static void opengl_context_delete(void);
48
static void opengl_context_delete(void);
46
static void opengl_screenshot(void);
49
static void opengl_screenshot(void);
47
50
(-)puNES-0.105.org/src/video/opengl/opengl.h (-11 / +11 lines)
Lines 28-33 Link Here
28
#include "common.h"
28
#include "common.h"
29
#include "video/gfx.h"
29
#include "video/gfx.h"
30
30
31
enum _opengl_texture_format {
32
	TI_INTFRM = GL_RGBA8,
33
	TI_FRM = GL_BGRA,
34
	TI_TYPE = GL_UNSIGNED_BYTE,
35
	TI_F_INTFRM = GL_RGBA32F,
36
	TI_F_TYPE = GL_FLOAT,
37
	TI_S_INTFRM = GL_SRGB8_ALPHA8,
38
	TI_S_TYPE = GL_UNSIGNED_BYTE
39
};
40
31
#if defined (WITH_OPENGL_CG)
41
#if defined (WITH_OPENGL_CG)
32
typedef struct _shader_prg_cg {
42
typedef struct _shader_prg_cg {
33
	CGprogram v, f;
43
	CGprogram v, f;
Lines 219-233 typedef struct _opengl { Link Here
219
#endif
229
#endif
220
} _opengl;
230
} _opengl;
221
231
222
enum _opengl_texture_format {
232
extern _opengl opengl;
223
	TI_INTFRM = GL_RGBA8,
224
	TI_FRM = GL_BGRA,
225
	TI_TYPE = GL_UNSIGNED_BYTE,
226
	TI_F_INTFRM = GL_RGBA32F,
227
	TI_F_TYPE = GL_FLOAT,
228
	TI_S_INTFRM = GL_SRGB8_ALPHA8,
229
	TI_S_TYPE = GL_UNSIGNED_BYTE
230
};
231
233
232
#if defined (__cplusplus)
234
#if defined (__cplusplus)
233
#define EXTERNC extern "C"
235
#define EXTERNC extern "C"
Lines 235-242 enum _opengl_texture_format { Link Here
235
#define EXTERNC
237
#define EXTERNC
236
#endif
238
#endif
237
239
238
EXTERNC _opengl opengl;
239
240
EXTERNC BYTE opengl_init(void);
240
EXTERNC BYTE opengl_init(void);
241
EXTERNC void opengl_quit(void);
241
EXTERNC void opengl_quit(void);
242
EXTERNC BYTE opengl_context_create(void);
242
EXTERNC BYTE opengl_context_create(void);
(-)puNES-0.105.org/src/video/shaders/shaders.c (+2 lines)
Lines 40-45 static void lp_set_default(_lut_pass *lp Link Here
40
static void ps_set_default(_param_shd *ps);
40
static void ps_set_default(_param_shd *ps);
41
static void se_soft_stretch(void);
41
static void se_soft_stretch(void);
42
42
43
_shader_effect shader_effect;
44
43
BYTE shaders_set(int shader) {
45
BYTE shaders_set(int shader) {
44
	_shader_effect *se = &shader_effect;
46
	_shader_effect *se = &shader_effect;
45
	_shader_pass *sp = NULL;
47
	_shader_pass *sp = NULL;
(-)puNES-0.105.org/src/video/shaders/shaders.h (-2 / +2 lines)
Lines 109-122 typedef struct _shader_effect { Link Here
109
	int8_t feedback_pass;
109
	int8_t feedback_pass;
110
} _shader_effect;
110
} _shader_effect;
111
111
112
extern _shader_effect shader_effect;
113
112
#if defined (__cplusplus)
114
#if defined (__cplusplus)
113
#define EXTERNC extern "C"
115
#define EXTERNC extern "C"
114
#else
116
#else
115
#define EXTERNC
117
#define EXTERNC
116
#endif
118
#endif
117
119
118
EXTERNC _shader_effect shader_effect;
119
120
EXTERNC BYTE shaders_set(int shader);
120
EXTERNC BYTE shaders_set(int shader);
121
EXTERNC void shader_se_set_default(_shader_effect *se);
121
EXTERNC void shader_se_set_default(_shader_effect *se);
122
EXTERNC char *shader_code_blend(void);
122
EXTERNC char *shader_code_blend(void);

Return to bug 710612