annotate gen_player.c @ 2274:bf1bb893f104

Properly ignore low bits of SP start address in disassembler
author Michael Pavone <pavone@retrodev.com>
date Thu, 29 Dec 2022 22:44:35 -0800
parents 01ff005b08f6
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1986
a042e046f7f2 Fix libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1967
diff changeset
1 #include <stdlib.h>
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include "gen_player.h"
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include "event_log.h"
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4 #include "render.h"
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5
1986
a042e046f7f2 Fix libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1967
diff changeset
6 #define MCLKS_NTSC 53693175
a042e046f7f2 Fix libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1967
diff changeset
7 #define MCLKS_PAL 53203395
a042e046f7f2 Fix libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1967
diff changeset
8 #define MCLKS_PER_YM 7
a042e046f7f2 Fix libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1967
diff changeset
9 #define MCLKS_PER_Z80 15
a042e046f7f2 Fix libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1967
diff changeset
10 #define MCLKS_PER_PSG (MCLKS_PER_Z80*16)
a042e046f7f2 Fix libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1967
diff changeset
11
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 #ifdef IS_LIB
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 #define MAX_SOUND_CYCLES (MCLKS_PER_YM*NUM_OPERATORS*6*4)
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 #else
2194
01ff005b08f6 Very rudimentary support for Game Gear VDP emulation
Michael Pavone <pavone@retrodev.com>
parents: 1986
diff changeset
15 #define MAX_SOUND_CYCLES 100000
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 #endif
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 static void sync_sound(gen_player *gen, uint32_t target)
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 //printf("YM | Cycle: %d, bpos: %d, PSG | Cycle: %d, bpos: %d\n", gen->ym->current_cycle, gen->ym->buffer_pos, gen->psg->cycles, gen->psg->buffer_pos * 2);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 while (target > gen->psg->cycles && target - gen->psg->cycles > MAX_SOUND_CYCLES) {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 uint32_t cur_target = gen->psg->cycles + MAX_SOUND_CYCLES;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 //printf("Running PSG to cycle %d\n", cur_target);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 psg_run(gen->psg, cur_target);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 //printf("Running YM-2612 to cycle %d\n", cur_target);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 ym_run(gen->ym, cur_target);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 psg_run(gen->psg, target);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 ym_run(gen->ym, target);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 //printf("Target: %d, YM bufferpos: %d, PSG bufferpos: %d\n", target, gen->ym->buffer_pos, gen->psg->buffer_pos * 2);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33
1967
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
34 static void run(gen_player *player)
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 while(player->reader.socket || player->reader.buffer.cur_pos < player->reader.buffer.size)
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 uint32_t cycle;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 uint8_t event = reader_next_event(&player->reader, &cycle);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 switch (event)
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 case EVENT_FLUSH:
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 sync_sound(player, cycle);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 vdp_run_context(player->vdp, cycle);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 break;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 case EVENT_ADJUST: {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 sync_sound(player, cycle);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 vdp_run_context(player->vdp, cycle);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 uint32_t deduction = load_int32(&player->reader.buffer);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 ym_adjust_cycles(player->ym, deduction);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 vdp_adjust_cycles(player->vdp, deduction);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 player->psg->cycles -= deduction;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 break;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 case EVENT_PSG_REG:
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 sync_sound(player, cycle);
1957
ba06346611a1 Fix some netplay issues
Mike Pavone <pavone@retrodev.com>
parents: 1947
diff changeset
56 reader_ensure_data(&player->reader, 1);
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 psg_write(player->psg, load_int8(&player->reader.buffer));
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 break;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 case EVENT_YM_REG: {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 sync_sound(player, cycle);
1957
ba06346611a1 Fix some netplay issues
Mike Pavone <pavone@retrodev.com>
parents: 1947
diff changeset
61 reader_ensure_data(&player->reader, 3);
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 uint8_t part = load_int8(&player->reader.buffer);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 uint8_t reg = load_int8(&player->reader.buffer);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 uint8_t value = load_int8(&player->reader.buffer);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65 if (part) {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 ym_address_write_part2(player->ym, reg);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 } else {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 ym_address_write_part1(player->ym, reg);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 ym_data_write(player->ym, value);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
71 break;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
72 case EVENT_STATE: {
1957
ba06346611a1 Fix some netplay issues
Mike Pavone <pavone@retrodev.com>
parents: 1947
diff changeset
73 reader_ensure_data(&player->reader, 3);
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
74 uint32_t size = load_int8(&player->reader.buffer) << 16;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
75 size |= load_int16(&player->reader.buffer);
1957
ba06346611a1 Fix some netplay issues
Mike Pavone <pavone@retrodev.com>
parents: 1947
diff changeset
76 reader_ensure_data(&player->reader, size);
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
77 deserialize_buffer buffer;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
78 init_deserialize(&buffer, player->reader.buffer.data + player->reader.buffer.cur_pos, size);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
79 register_section_handler(&buffer, (section_handler){.fun = vdp_deserialize, .data = player->vdp}, SECTION_VDP);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 register_section_handler(&buffer, (section_handler){.fun = ym_deserialize, .data = player->ym}, SECTION_YM2612);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 register_section_handler(&buffer, (section_handler){.fun = psg_deserialize, .data = player->psg}, SECTION_PSG);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 while (buffer.cur_pos < buffer.size)
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 load_section(&buffer);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
85 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 player->reader.buffer.cur_pos += size;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
87 free(buffer.handlers);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
88 break;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
89 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
90 default:
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
91 vdp_run_context(player->vdp, cycle);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
92 vdp_replay_event(player->vdp, event, &player->reader);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94 }
2194
01ff005b08f6 Very rudimentary support for Game Gear VDP emulation
Michael Pavone <pavone@retrodev.com>
parents: 1986
diff changeset
95
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 }
1958
9c01945b5d20 Use zlib to compress event log streams
Mike Pavone <pavone@retrodev.com>
parents: 1957
diff changeset
97 if (!player->reader.socket) {
9c01945b5d20 Use zlib to compress event log streams
Mike Pavone <pavone@retrodev.com>
parents: 1957
diff changeset
98 reader_ensure_data(&player->reader, 1);
9c01945b5d20 Use zlib to compress event log streams
Mike Pavone <pavone@retrodev.com>
parents: 1957
diff changeset
99 }
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
100 }
1967
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
101 }
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
102
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
103 static int thread_main(void *player)
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
104 {
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
105 run(player);
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
106 return 0;
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
107 }
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
108
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
109 void start_context(system_header *sys, char *statefile)
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
110 {
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
111 gen_player *player = (gen_player *)sys;
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
112 if (player->reader.socket) {
1986
a042e046f7f2 Fix libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1967
diff changeset
113 #ifndef IS_LIB
1967
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
114 render_create_thread(&player->thread, "player", thread_main, player);
1986
a042e046f7f2 Fix libretro target
Michael Pavone <pavone@retrodev.com>
parents: 1967
diff changeset
115 #endif
1967
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
116 } else {
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
117 run(player);
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
118 }
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
119 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
120
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
121 static void gamepad_down(system_header *system, uint8_t gamepad_num, uint8_t button)
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
122 {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
123 gen_player *player = (gen_player *)system;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
124 reader_send_gamepad_event(&player->reader, gamepad_num, button, 1);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
125 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
126
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
127 static void gamepad_up(system_header *system, uint8_t gamepad_num, uint8_t button)
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
128 {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
129 gen_player *player = (gen_player *)system;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
130 reader_send_gamepad_event(&player->reader, gamepad_num, button, 0);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
131 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
132
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
133 static void config_common(gen_player *player)
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
134 {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
135 uint8_t vid_std = load_int8(&player->reader.buffer);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
136 uint8_t name_len = load_int8(&player->reader.buffer);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
137 player->header.info.name = calloc(1, name_len + 1);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
138 load_buffer8(&player->reader.buffer, player->header.info.name, name_len);
2194
01ff005b08f6 Very rudimentary support for Game Gear VDP emulation
Michael Pavone <pavone@retrodev.com>
parents: 1986
diff changeset
139
01ff005b08f6 Very rudimentary support for Game Gear VDP emulation
Michael Pavone <pavone@retrodev.com>
parents: 1986
diff changeset
140 player->vdp = init_vdp_context(vid_std == VID_PAL, 0, VDP_GENESIS);
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
141 render_set_video_standard(vid_std);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
142 uint32_t master_clock = vid_std == VID_NTSC ? MCLKS_NTSC : MCLKS_PAL;
2194
01ff005b08f6 Very rudimentary support for Game Gear VDP emulation
Michael Pavone <pavone@retrodev.com>
parents: 1986
diff changeset
143
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
144 player->ym = malloc(sizeof(ym2612_context));
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
145 ym_init(player->ym, master_clock, MCLKS_PER_YM, 0);
2194
01ff005b08f6 Very rudimentary support for Game Gear VDP emulation
Michael Pavone <pavone@retrodev.com>
parents: 1986
diff changeset
146
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
147 player->psg = malloc(sizeof(psg_context));
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
148 psg_init(player->psg, master_clock, MCLKS_PER_PSG);
2194
01ff005b08f6 Very rudimentary support for Game Gear VDP emulation
Michael Pavone <pavone@retrodev.com>
parents: 1986
diff changeset
149
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
150 player->header.start_context = start_context;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
151 player->header.gamepad_down = gamepad_down;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
152 player->header.gamepad_up = gamepad_up;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
153 player->header.type = SYSTEM_GENESIS_PLAYER;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
154 player->header.info.save_type = SAVE_NONE;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
155 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
156
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
157 gen_player *alloc_config_gen_player(void *stream, uint32_t rom_size)
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
158 {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
159 uint8_t *data = stream;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
160 gen_player *player = calloc(1, sizeof(gen_player));
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
161 init_event_reader(&player->reader, data + 9, rom_size - 9);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
162 config_common(player);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
163 return player;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
164 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
165
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
166 gen_player *alloc_config_gen_player_reader(event_reader *reader)
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
167 {
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
168 gen_player *player = calloc(1, sizeof(gen_player));
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
169 player->reader = *reader;
1958
9c01945b5d20 Use zlib to compress event log streams
Mike Pavone <pavone@retrodev.com>
parents: 1957
diff changeset
170 inflateCopy(&player->reader.input_stream, &reader->input_stream);
1967
bd70f1e15684 Make netplay remote sync to network rather than audio or video so it doesn't drift out of sync with the host
Michael Pavone <pavone@retrodev.com>
parents: 1958
diff changeset
171 render_set_external_sync(1);
1947
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
172 config_common(player);
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
173 return player;
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
174 }
c36102d09351 Add missing netplay files and add in support for sending gamepad commands back to host
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
175