diff --git a/.circleci/config.yml b/.circleci/config.yml index 6b258f649..13f35221e 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -18,6 +18,10 @@ jobs: name: Build command: | make -j 2 + make -C src/mips/serial -j 2 + make -C src/mips/hello -j 2 + make -C src/mips/pshittyload -j 2 + make -C src/mips/tinyload -j 2 make -C src/mips/shell -j 2 make -C src/mips/openbios -j 2 diff --git a/.gitignore b/.gitignore index e29229618..3f65a1e22 100644 --- a/.gitignore +++ b/.gitignore @@ -33,3 +33,4 @@ vsprojects/packages /memcard1.mcd /memcard2.mcd +src/.clang-format diff --git a/env.list b/env.list index 115ec8b60..cdc646d19 100644 --- a/env.list +++ b/env.list @@ -4,3 +4,4 @@ LD=clang++-9 XDG_DATA_HOME=/home/coder XDG_CACHE_HOME=/home/coder HOME=/home/coder +PS1SDK=/project/src/mips/ps1sdk diff --git a/src/.clang-format-asm b/src/.clang-format-asm new file mode 100644 index 000000000..e6a83c755 --- /dev/null +++ b/src/.clang-format-asm @@ -0,0 +1,4 @@ +BasedOnStyle: WebKit +IndentWidth: 4 +ColumnLimit: 120 +AccessModifierOffset: -2 diff --git a/src/.clang-format b/src/.clang-format-commit similarity index 100% rename from src/.clang-format rename to src/.clang-format-commit diff --git a/src/core/cdriso.cc b/src/core/cdriso.cc index 11ed14a92..6f16fe4e7 100644 --- a/src/core/cdriso.cc +++ b/src/core/cdriso.cc @@ -98,12 +98,12 @@ extern "C" { //////////////////////////////////////////////////////////////////////////////// -uint32_t PCSX::CDRiso::get32lsb(const uint8_t *src) { +uint32_t PCSX::CDRiso::get32lsb(const uint8_t* src) { return (((uint32_t)(src[0])) << 0) | (((uint32_t)(src[1])) << 8) | (((uint32_t)(src[2])) << 16) | (((uint32_t)(src[3])) << 24); } -void PCSX::CDRiso::put32lsb(uint8_t *dest, uint32_t value) { +void PCSX::CDRiso::put32lsb(uint8_t* dest, uint32_t value) { dest[0] = (uint8_t)(value); dest[1] = (uint8_t)(value >> 8); dest[2] = (uint8_t)(value >> 16); @@ -128,7 +128,7 @@ void PCSX::CDRiso::eccedc_init() { // // Compute EDC for a block // -uint32_t PCSX::CDRiso::edc_compute(uint32_t edc, const uint8_t *src, size_t size) { +uint32_t PCSX::CDRiso::edc_compute(uint32_t edc, const uint8_t* src, size_t size) { for (; size; size--) { edc = (edc >> 8) ^ m_edc_lut[(edc ^ (*src++)) & 0xFF]; } @@ -138,8 +138,8 @@ uint32_t PCSX::CDRiso::edc_compute(uint32_t edc, const uint8_t *src, size_t size // // Write ECC block (either P or Q) // -void PCSX::CDRiso::ecc_writepq(const uint8_t *address, const uint8_t *data, size_t major_count, size_t minor_count, - size_t major_mult, size_t minor_inc, uint8_t *ecc) { +void PCSX::CDRiso::ecc_writepq(const uint8_t* address, const uint8_t* data, size_t major_count, size_t minor_count, + size_t major_mult, size_t minor_inc, uint8_t* ecc) { size_t size = major_count * minor_count; size_t major; for (major = 0; major < major_count; major++) { @@ -171,7 +171,7 @@ void PCSX::CDRiso::ecc_writepq(const uint8_t *address, const uint8_t *data, size // // Write ECC P and Q codes for a sector // -void PCSX::CDRiso::ecc_writesector(const uint8_t *address, const uint8_t *data, uint8_t *ecc) { +void PCSX::CDRiso::ecc_writesector(const uint8_t* address, const uint8_t* data, uint8_t* ecc) { ecc_writepq(address, data, 86, 24, 2, 86, ecc); // P ecc_writepq(address, data, 52, 43, 86, 88, ecc + 0xAC); // Q } @@ -180,7 +180,7 @@ void PCSX::CDRiso::ecc_writesector(const uint8_t *address, const uint8_t *data, // // Reconstruct a sector based on type // -void PCSX::CDRiso::reconstruct_sector(uint8_t *sector, // must point to a full 2352-byte sector +void PCSX::CDRiso::reconstruct_sector(uint8_t* sector, // must point to a full 2352-byte sector int8_t type) { // // Sync @@ -265,8 +265,8 @@ void PCSX::CDRiso::reconstruct_sector(uint8_t *sector, // must point to a full } // divide a string of xx:yy:zz into m, s, f -void PCSX::CDRiso::tok2msf(char *time, char *msf) { - char *token; +void PCSX::CDRiso::tok2msf(char* time, char* msf) { + char* token; token = strtok(time, ":"); if (token) { @@ -290,7 +290,7 @@ void PCSX::CDRiso::tok2msf(char *time, char *msf) { } } -PCSX::CDRiso::trackinfo::cddatype_t PCSX::CDRiso::get_cdda_type(const char *str) { +PCSX::CDRiso::trackinfo::cddatype_t PCSX::CDRiso::get_cdda_type(const char* str) { const size_t lenstr = strlen(str); if (strncmp((str + lenstr - 3), "bin", 3) == 0) { return trackinfo::BIN; @@ -302,11 +302,11 @@ PCSX::CDRiso::trackinfo::cddatype_t PCSX::CDRiso::get_cdda_type(const char *str) /* ffmpeg-related code */ -static int get_compressed_cdda_track_length(const char *filepath) { +static int get_compressed_cdda_track_length(const char* filepath) { int seconds = -1; av_log_set_level(AV_LOG_QUIET); - AVFormatContext *inAudioFormat = NULL; + AVFormatContext* inAudioFormat = NULL; inAudioFormat = avformat_alloc_context(); int errorCode = avformat_open_input(&inAudioFormat, filepath, NULL, NULL); avformat_find_stream_info(inAudioFormat, NULL); @@ -315,8 +315,8 @@ static int get_compressed_cdda_track_length(const char *filepath) { return seconds; } -static int decode_packet(int *got_frame, AVPacket pkt, int audio_stream_idx, AVFrame *frame, - AVCodecContext *audio_dec_ctx, void *buf, int *size, SwrContext *swr) { +static int decode_packet(int* got_frame, AVPacket pkt, int audio_stream_idx, AVFrame* frame, + AVCodecContext* audio_dec_ctx, void* buf, int* size, SwrContext* swr) { int ret = 0; int decoded = pkt.size; *got_frame = 0; @@ -345,17 +345,17 @@ static int decode_packet(int *got_frame, AVPacket pkt, int audio_stream_idx, AVF if (*got_frame) { size_t unpadded_linesize = frame->nb_samples * av_get_bytes_per_sample(AVSampleFormat(frame->format)); - swr_convert(swr, (uint8_t **)&buf, frame->nb_samples, (const uint8_t **)frame->data, frame->nb_samples); + swr_convert(swr, (uint8_t**)&buf, frame->nb_samples, (const uint8_t**)frame->data, frame->nb_samples); (*size) += (unpadded_linesize * 2); } } return decoded; } -static int open_codec_context(int *stream_idx, AVFormatContext *fmt_ctx, enum AVMediaType type) { +static int open_codec_context(int* stream_idx, AVFormatContext* fmt_ctx, enum AVMediaType type) { int ret, stream_index; - AVStream *st; - AVDictionary *opts = NULL; + AVStream* st; + AVDictionary* opts = NULL; ret = av_find_best_stream(fmt_ctx, type, -1, -1, NULL, 0); @@ -366,13 +366,13 @@ static int open_codec_context(int *stream_idx, AVFormatContext *fmt_ctx, enum AV stream_index = ret; st = fmt_ctx->streams[stream_index]; - AVCodec *dec = avcodec_find_decoder(st->codecpar->codec_id); + AVCodec* dec = avcodec_find_decoder(st->codecpar->codec_id); if (!dec) { PCSX::g_system->printf(_("Failed to find %s codec\n"), av_get_media_type_string(type)); return AVERROR(EINVAL); } - AVCodecContext *dec_ctx = avcodec_alloc_context3(dec); + AVCodecContext* dec_ctx = avcodec_alloc_context3(dec); if (!dec_ctx) { PCSX::g_system->printf(_("Failed to find %s codec\n"), av_get_media_type_string(type)); return AVERROR(EINVAL); @@ -391,15 +391,15 @@ static int open_codec_context(int *stream_idx, AVFormatContext *fmt_ctx, enum AV return 0; } -static int decode_compressed_cdda_track(char *buf, char *src_filename, int *size) { - AVFormatContext *fmt_ctx = NULL; - AVCodecContext *audio_dec_ctx = NULL; - AVCodec *audio_codec = NULL; - AVStream *audio_stream = NULL; +static int decode_compressed_cdda_track(char* buf, char* src_filename, int* size) { + AVFormatContext* fmt_ctx = NULL; + AVCodecContext* audio_dec_ctx = NULL; + AVCodec* audio_codec = NULL; + AVStream* audio_stream = NULL; int audio_stream_idx = -1; - AVFrame *frame = NULL; + AVFrame* frame = NULL; AVPacket pkt; - SwrContext *resample_context; + SwrContext* resample_context; int ret = 0, got_frame; if (avformat_open_input(&fmt_ctx, src_filename, NULL, NULL) < 0) { @@ -503,8 +503,8 @@ static int decode_compressed_cdda_track(char *buf, char *src_filename, int *size /* end of ffmpeg-only code */ -int PCSX::CDRiso::do_decode_cdda(struct trackinfo *tri, uint32_t tracknumber) { - tri->decoded_buffer = (char *)malloc(tri->len_decoded_buffer); +int PCSX::CDRiso::do_decode_cdda(struct trackinfo* tri, uint32_t tracknumber) { + tri->decoded_buffer = (char*)malloc(tri->len_decoded_buffer); memset(tri->decoded_buffer, 0, tri->len_decoded_buffer - 1); if (tri->decoded_buffer == NULL) { @@ -540,12 +540,12 @@ int PCSX::CDRiso::do_decode_cdda(struct trackinfo *tri, uint32_t tracknumber) { // this function tries to get the .toc file of the given .bin // the necessary data is put into the ti (trackinformation)-array -int PCSX::CDRiso::parsetoc(const char *isofileStr) { +int PCSX::CDRiso::parsetoc(const char* isofileStr) { std::filesystem::path isofile = std::filesystem::u8path(isofileStr); std::filesystem::path tocname, filename; - File *fi; + File* fi; char linebuf[256], tmp[256], name[256]; - char *token; + char* token; char time[20], time2[20]; unsigned int t, sector_offs, sector_size; unsigned int current_zero_gap = 0; @@ -618,21 +618,21 @@ int PCSX::CDRiso::parsetoc(const char *isofileStr) { sscanf(linebuf, "DATAFILE \"%[^\"]\" #%d %8s", name, &t, time2); m_ti[m_numtracks].start_offset = t; t = t / sector_size + sector_offs; - sec2msf(t, (uint8_t *)&m_ti[m_numtracks].start); - tok2msf((char *)&time2, (char *)&m_ti[m_numtracks].length); + sec2msf(t, (uint8_t*)&m_ti[m_numtracks].start); + tok2msf((char*)&time2, (char*)&m_ti[m_numtracks].length); } else { sscanf(linebuf, "DATAFILE \"%[^\"]\" %8s", name, time); - tok2msf((char *)&time, (char *)&m_ti[m_numtracks].length); + tok2msf((char*)&time, (char*)&m_ti[m_numtracks].length); m_ti[m_numtracks].handle = new File(filename / name); } } else if (!strcmp(token, "FILE")) { sscanf(linebuf, "FILE \"%[^\"]\" #%d %8s %8s", name, &t, time, time2); - tok2msf((char *)&time, (char *)&m_ti[m_numtracks].start); + tok2msf((char*)&time, (char*)&m_ti[m_numtracks].start); t += msf2sec(m_ti[m_numtracks].start) * sector_size; m_ti[m_numtracks].start_offset = t; t = t / sector_size + sector_offs; - sec2msf(t, (uint8_t *)&m_ti[m_numtracks].start); - tok2msf((char *)&time2, (char *)&m_ti[m_numtracks].length); + sec2msf(t, (uint8_t*)&m_ti[m_numtracks].start); + tok2msf((char*)&time2, (char*)&m_ti[m_numtracks].length); } else if (!strcmp(token, "ZERO") || !strcmp(token, "SILENCE")) { // skip unneeded optional fields while (token != NULL) { @@ -641,7 +641,7 @@ int PCSX::CDRiso::parsetoc(const char *isofileStr) { } if (token != NULL) { tok2msf(token, tmp); - current_zero_gap = msf2sec(reinterpret_cast(tmp)); + current_zero_gap = msf2sec(reinterpret_cast(tmp)); } if (m_numtracks > 1) { t = m_ti[m_numtracks - 1].start_offset; @@ -652,10 +652,10 @@ int PCSX::CDRiso::parsetoc(const char *isofileStr) { token = strtok(NULL, " "); if (token != NULL && strchr(token, ':')) { tok2msf(token, tmp); - t = msf2sec(reinterpret_cast(tmp)); + t = msf2sec(reinterpret_cast(tmp)); m_ti[m_numtracks].start_offset += (t - current_zero_gap) * sector_size; t = msf2sec(m_ti[m_numtracks].start) + t; - sec2msf(t, (uint8_t *)&m_ti[m_numtracks].start); + sec2msf(t, (uint8_t*)&m_ti[m_numtracks].start); } } } @@ -669,13 +669,13 @@ int PCSX::CDRiso::parsetoc(const char *isofileStr) { // this function tries to get the .cue file of the given .bin // the necessary data is put into the ti (trackinformation)-array -int PCSX::CDRiso::parsecue(const char *isofileString) { +int PCSX::CDRiso::parsecue(const char* isofileString) { std::filesystem::path isofile = std::filesystem::u8path(isofileString); std::filesystem::path cuename, filepath; - File *fi; - char *token; + File* fi; + char* token; char time[20]; - char *tmp; + char* tmp; char linebuf[256], tmpb[256], dummy[256]; unsigned int t, file_len, mode, sector_offs; unsigned int sector_size = 2352; @@ -762,7 +762,7 @@ int PCSX::CDRiso::parsecue(const char *isofileString) { } else if (!strcmp(token, "INDEX")) { if (sscanf(linebuf, " INDEX %02d %8s", &t, time) != 2) PCSX::g_system->printf(".cue: failed to parse INDEX\n"); - tok2msf(time, (char *)&m_ti[m_numtracks].start); + tok2msf(time, (char*)&m_ti[m_numtracks].start); t = msf2sec(m_ti[m_numtracks].start); m_ti[m_numtracks].start_offset = t * sector_size; @@ -783,7 +783,7 @@ int PCSX::CDRiso::parsecue(const char *isofileString) { } else if (!strcmp(token, "PREGAP")) { if (sscanf(linebuf, " PREGAP %8s", time) == 1) { tok2msf(time, dummy); - sector_offs += msf2sec(reinterpret_cast(dummy)); + sector_offs += msf2sec(reinterpret_cast(dummy)); } m_pregapOffset = -1; // mark to fill track start_offset } else if (!strcmp(token, "FILE")) { @@ -797,7 +797,8 @@ int PCSX::CDRiso::parsecue(const char *isofileString) { m_ti[m_numtracks + 1].handle = new File(filepath / tmpb); } - strcpy(m_ti[m_numtracks + 1].filepath, reinterpret_cast(m_ti[m_numtracks + 1].handle->filename().u8string().c_str())); + strcpy(m_ti[m_numtracks + 1].filepath, + reinterpret_cast(m_ti[m_numtracks + 1].handle->filename().u8string().c_str())); // update global offset if this is not first file in this .cue if (m_numtracks + 1 > 1) { @@ -807,7 +808,8 @@ int PCSX::CDRiso::parsecue(const char *isofileString) { file_len = 0; if (m_ti[m_numtracks + 1].handle->failed()) { - PCSX::g_system->message(_("\ncould not open: %s\n"), m_ti[m_numtracks + 1].handle->filename().u8string().c_str()); + PCSX::g_system->message(_("\ncould not open: %s\n"), + m_ti[m_numtracks + 1].handle->filename().u8string().c_str()); delete m_ti[m_numtracks + 1].handle; m_ti[m_numtracks + 1].handle = nullptr; continue; @@ -834,9 +836,9 @@ int PCSX::CDRiso::parsecue(const char *isofileString) { // this function tries to get the .ccd file of the given .img // the necessary data is put into the ti (trackinformation)-array -int PCSX::CDRiso::parseccd(const char *isofileString) { +int PCSX::CDRiso::parseccd(const char* isofileString) { std::filesystem::path ccdname, isofile = std::filesystem::u8path(isofileString); - File *fi; + File* fi; char linebuf[256]; unsigned int t; @@ -887,9 +889,9 @@ int PCSX::CDRiso::parseccd(const char *isofileString) { // this function tries to get the .mds file of the given .mdf // the necessary data is put into the ti (trackinformation)-array -int PCSX::CDRiso::parsemds(const char *isofileString) { +int PCSX::CDRiso::parsemds(const char* isofileString) { std::filesystem::path mdsname, isofile = std::filesystem::u8path(isofileString); - File *fi; + File* fi; unsigned int offset, extra_offset, l, i; unsigned short s; @@ -988,7 +990,7 @@ int PCSX::CDRiso::parsemds(const char *isofileString) { return 0; } -int PCSX::CDRiso::handlepbp(const char *isofile) { +int PCSX::CDRiso::handlepbp(const char* isofile) { struct { unsigned int sig; unsigned int dontcare[8]; @@ -1010,7 +1012,7 @@ int PCSX::CDRiso::handlepbp(const char *isofile) { char psar_sig[11]; unsigned int t, cd_length, cdimg_base; unsigned int offsettab[8], psisoimg_offs; - const char *ext = NULL; + const char* ext = NULL; int i, ret; if (strlen(isofile) >= 4) ext = isofile + strlen(isofile) - 4; @@ -1119,7 +1121,7 @@ int PCSX::CDRiso::handlepbp(const char *isofile) { goto fail_io; } - m_compr_img = (compr_img_t *)calloc(1, sizeof(*m_compr_img)); + m_compr_img = (compr_img_t*)calloc(1, sizeof(*m_compr_img)); if (m_compr_img == NULL) goto fail_io; m_compr_img->block_shift = 4; @@ -1127,7 +1129,7 @@ int PCSX::CDRiso::handlepbp(const char *isofile) { m_compr_img->index_len = (0x100000 - 0x4000) / sizeof(index_entry); m_compr_img->index_table = - (unsigned int *)malloc((m_compr_img->index_len + 1) * sizeof(m_compr_img->index_table[0])); + (unsigned int*)malloc((m_compr_img->index_len + 1) * sizeof(m_compr_img->index_table[0])); if (m_compr_img->index_table == NULL) goto fail_io; cdimg_base = psisoimg_offs + 0x100000; @@ -1157,7 +1159,7 @@ int PCSX::CDRiso::handlepbp(const char *isofile) { return -1; } -int PCSX::CDRiso::handlecbin(const char *isofile) { +int PCSX::CDRiso::handlecbin(const char* isofile) { struct { char magic[4]; unsigned int header_size; @@ -1167,7 +1169,7 @@ int PCSX::CDRiso::handlecbin(const char *isofile) { unsigned char align; unsigned char rsv_06[2]; } ciso_hdr; - const char *ext = NULL; + const char* ext = NULL; unsigned int index = 0, plain; int i, ret; size_t read_len = 0; @@ -1195,7 +1197,7 @@ int PCSX::CDRiso::handlecbin(const char *isofile) { } } - m_compr_img = (compr_img_t *)calloc(1, sizeof(*m_compr_img)); + m_compr_img = (compr_img_t*)calloc(1, sizeof(*m_compr_img)); if (m_compr_img == NULL) goto fail_io; m_compr_img->block_shift = 0; @@ -1203,7 +1205,7 @@ int PCSX::CDRiso::handlecbin(const char *isofile) { m_compr_img->index_len = ciso_hdr.total_bytes / ciso_hdr.block_size; m_compr_img->index_table = - (unsigned int *)malloc((m_compr_img->index_len + 1) * sizeof(m_compr_img->index_table[0])); + (unsigned int*)malloc((m_compr_img->index_len + 1) * sizeof(m_compr_img->index_table[0])); if (m_compr_img->index_table == NULL) goto fail_io; read_len = sizeof(m_compr_img->index_table[0]) * m_compr_img->index_len; @@ -1237,7 +1239,7 @@ int PCSX::CDRiso::handlecbin(const char *isofile) { } // this function tries to get the .sub file of the given .img -int PCSX::CDRiso::opensubfile(const char *isoname) { +int PCSX::CDRiso::opensubfile(const char* isoname) { char subname[MAXPATHLEN]; // copy name of the iso and change extension from .img to .sub @@ -1268,8 +1270,8 @@ int PCSX::CDRiso::opensubfile(const char *isoname) { return 0; } -int PCSX::CDRiso::LoadSBI(const char *filename) { - File *sbihandle; +int PCSX::CDRiso::LoadSBI(const char* filename) { + File* sbihandle; char buffer[16], sbifile[MAXPATHLEN]; if (filename == NULL) { @@ -1321,7 +1323,7 @@ int PCSX::CDRiso::LoadSBI(const char *filename) { return 0; } -bool PCSX::CDRiso::CheckSBI(const uint8_t *time) { +bool PCSX::CDRiso::CheckSBI(const uint8_t* time) { int lcv; // both BCD format @@ -1334,7 +1336,7 @@ bool PCSX::CDRiso::CheckSBI(const uint8_t *time) { void PCSX::CDRiso::UnloadSBI() { sbicount = 0; } -int PCSX::CDRiso::opensbifile(const char *isoname) { +int PCSX::CDRiso::opensbifile(const char* isoname) { char sbiname[MAXPATHLEN]; strncpy(sbiname, isoname, sizeof(sbiname)); @@ -1348,12 +1350,12 @@ int PCSX::CDRiso::opensbifile(const char *isoname) { return LoadSBI(sbiname); } -ssize_t PCSX::CDRiso::cdread_normal(File *f, unsigned int base, void *dest, int sector) { +ssize_t PCSX::CDRiso::cdread_normal(File* f, unsigned int base, void* dest, int sector) { f->seek(base + sector * PCSX::CDRom::CD_FRAMESIZE_RAW, SEEK_SET); return f->read(dest, PCSX::CDRom::CD_FRAMESIZE_RAW); } -ssize_t PCSX::CDRiso::cdread_sub_mixed(File *f, unsigned int base, void *dest, int sector) { +ssize_t PCSX::CDRiso::cdread_sub_mixed(File* f, unsigned int base, void* dest, int sector) { int ret; f->seek(base + sector * (PCSX::CDRom::CD_FRAMESIZE_RAW + PCSX::CDRom::SUB_FRAMESIZE), SEEK_SET); @@ -1365,7 +1367,7 @@ ssize_t PCSX::CDRiso::cdread_sub_mixed(File *f, unsigned int base, void *dest, i return ret; } -static int uncompress2_internal(void *out, unsigned long *out_size, void *in, unsigned long in_size) { +static int uncompress2_internal(void* out, unsigned long* out_size, void* in, unsigned long in_size) { static z_stream z; int ret = 0; @@ -1381,9 +1383,9 @@ static int uncompress2_internal(void *out, unsigned long *out_size, void *in, un ret = inflateReset(&z); if (ret != Z_OK) return ret; - z.next_in = reinterpret_cast(in); + z.next_in = reinterpret_cast(in); z.avail_in = in_size; - z.next_out = reinterpret_cast(out); + z.next_out = reinterpret_cast(out); z.avail_out = *out_size; ret = inflate(&z, Z_NO_FLUSH); @@ -1393,7 +1395,7 @@ static int uncompress2_internal(void *out, unsigned long *out_size, void *in, un return ret == 1 ? 0 : ret; } -ssize_t PCSX::CDRiso::cdread_compressed(File *f, unsigned int base, void *dest, int sector) { +ssize_t PCSX::CDRiso::cdread_compressed(File* f, unsigned int base, void* dest, int sector) { unsigned long cdbuffer_size, cdbuffer_size_expect; unsigned int start_byte, size; int is_compressed; @@ -1456,29 +1458,29 @@ ssize_t PCSX::CDRiso::cdread_compressed(File *f, unsigned int base, void *dest, return PCSX::CDRom::CD_FRAMESIZE_RAW; } -ssize_t PCSX::CDRiso::cdread_2048(File *f, unsigned int base, void *dest, int sector) { +ssize_t PCSX::CDRiso::cdread_2048(File* f, unsigned int base, void* dest, int sector) { int ret; f->seek(base + sector * 2048, SEEK_SET); - ret = f->read((char *)dest + 12 * 2, 2048); + ret = f->read((char*)dest + 12 * 2, 2048); // not really necessary, fake mode 2 header memset(m_cdbuffer, 0, 12 * 2); - sec2msf(sector + 2 * 75, (uint8_t *)&m_cdbuffer[12]); + sec2msf(sector + 2 * 75, (uint8_t*)&m_cdbuffer[12]); m_cdbuffer[12 + 3] = 1; return ret; } /* Adapted from ecm.c:unecmify() (C) Neill Corlett */ -ssize_t PCSX::CDRiso::cdread_ecm_decode(File *f, unsigned int base, void *dest, int sector) { +ssize_t PCSX::CDRiso::cdread_ecm_decode(File* f, unsigned int base, void* dest, int sector) { uint32_t output_edc = 0, b = 0, writebytecount = 0, num; uint32_t sectorcount = 0; int8_t type = 0; // mode type 0 (META) or 1, 2 or 3 for CDROM type uint8_t sector_buffer[PCSX::CDRom::CD_FRAMESIZE_RAW]; bool processsectors = (bool)m_decoded_ecm_sectors; // this flag tells if to decode all sectors or just skip to wanted sector - ECMFILELUT *pos = &(m_ecm_savetable[0]); // points always to beginning of ECM DATA + ECMFILELUT* pos = &(m_ecm_savetable[0]); // points always to beginning of ECM DATA // If not pointing to ECM file but CDDA file or some other track if (f != m_cdHandle) { @@ -1662,7 +1664,7 @@ ssize_t PCSX::CDRiso::cdread_ecm_decode(File *f, unsigned int base, void *dest, return -1; } -int PCSX::CDRiso::handleecm(const char *isoname, File *cdh, int32_t *accurate_length) { +int PCSX::CDRiso::handleecm(const char* isoname, File* cdh, int32_t* accurate_length) { // Rewind to start and check ECM header and filename suffix validity cdh->seek(0, SEEK_SET); if ((cdh->getc() == 'E') && (cdh->getc() == 'C') && (cdh->getc() == 'M') && (cdh->getc() == 0x00) && @@ -1692,7 +1694,7 @@ int PCSX::CDRiso::handleecm(const char *isoname, File *cdh, int32_t *accurate_le m_len_ecm_savetable = 75 * 80 * 60; // 2*(accurate_length/PCSX::CDRomCD_FRAMESIZE_RAW); // Index 0 always points to beginning of ECM data - m_ecm_savetable = (ECMFILELUT *)calloc(m_len_ecm_savetable, sizeof(ECMFILELUT)); // calloc returns nulled data + m_ecm_savetable = (ECMFILELUT*)calloc(m_len_ecm_savetable, sizeof(ECMFILELUT)); // calloc returns nulled data m_ecm_savetable[0].filepos = ECM_HEADER_SIZE; if (accurate_length || m_decoded_ecm_sectors) { @@ -1715,17 +1717,17 @@ int PCSX::CDRiso::handleecm(const char *isoname, File *cdh, int32_t *accurate_le #include #include -struct archive *a = NULL; +struct archive* a = NULL; uint32_t len_uncompressed_buffer = 0; -void *cdimage_buffer_mem = NULL; -FILE *cdimage_buffer = NULL; // m_cdHandle to store file +void* cdimage_buffer_mem = NULL; +FILE* cdimage_buffer = NULL; // m_cdHandle to store file -int aropen(FILE *fparchive, const char *_fn) { +int aropen(FILE* fparchive, const char* _fn) { int32_t r; uint64_t length = 0, length_peek; bool use_temp_file = false; // TODO make a config param - static struct archive_entry *ae = NULL; - struct archive_entry *ae_peek; + static struct archive_entry* ae = NULL; + struct archive_entry* ae_peek; if (a == NULL && cdimage_buffer == NULL) { // We open file twice. First to peek sizes. This nastyness due used interface. @@ -1792,12 +1794,12 @@ int aropen(FILE *fparchive, const char *_fn) { return 0; } -static int cdread_archive(FILE *f, unsigned int base, void *dest, int sector) { +static int cdread_archive(FILE* f, unsigned int base, void* dest, int sector) { int32_t r; size_t size; size_t readsize; static off_t offset = 0; // w/o read always or static/ftell - const void *buff; + const void* buff; // If not pointing to archive file but CDDA file or some other track if (f != m_cdHandle) { @@ -1831,7 +1833,7 @@ static int cdread_archive(FILE *f, unsigned int base, void *dest, int sector) { r = m_cdimg_read_func_archive(cdimage_buffer, base, dest, sector); return r; } -int handlearchive(const char *isoname, int32_t *accurate_length) { +int handlearchive(const char* isoname, int32_t* accurate_length) { uint32_t read_size = accurate_length ? MSF2SECT(70, 70, 16) : MSF2SECT(0, 0, 16); int ret = -1; if ((ret = aropen(m_cdHandle, isoname)) == 0) { @@ -1853,12 +1855,12 @@ int handlearchive(const char *isoname, int32_t *accurate_length) { return ret; } #else -int PCSX::CDRiso::aropen(FILE *fparchive, const char *_fn) { return -1; } -int PCSX::CDRiso::cdread_archive(FILE *f, unsigned int base, void *dest, int sector) { return -1; } -int PCSX::CDRiso::handlearchive(const char *isoname, int32_t *accurate_length) { return -1; } +int PCSX::CDRiso::aropen(FILE* fparchive, const char* _fn) { return -1; } +int PCSX::CDRiso::cdread_archive(FILE* f, unsigned int base, void* dest, int sector) { return -1; } +int PCSX::CDRiso::handlearchive(const char* isoname, int32_t* accurate_length) { return -1; } #endif -uint8_t *PCSX::CDRiso::getBuffer() { +uint8_t* PCSX::CDRiso::getBuffer() { if (m_useCompressed) { return m_compr_img->buff_raw[m_compr_img->sector_in_blk] + 12; } else { @@ -2059,7 +2061,7 @@ void PCSX::CDRiso::shutdown() { // buffer: // byte 0 - start track // byte 1 - end track -bool PCSX::CDRiso::getTN(uint8_t *buffer) { +bool PCSX::CDRiso::getTN(uint8_t* buffer) { buffer[0] = 1; if (m_numtracks > 0) { @@ -2076,12 +2078,12 @@ bool PCSX::CDRiso::getTN(uint8_t *buffer) { // byte 0 - frame // byte 1 - second // byte 2 - minute -bool PCSX::CDRiso::getTD(uint8_t track, uint8_t *buffer) { +bool PCSX::CDRiso::getTD(uint8_t track, uint8_t* buffer) { if (track == 0) { unsigned int sect; unsigned char time[3]; sect = msf2sec(m_ti[m_numtracks].start) + msf2sec(m_ti[m_numtracks].length); - sec2msf(sect, (uint8_t *)time); + sec2msf(sect, (uint8_t*)time); buffer[2] = time[0]; buffer[1] = time[1]; buffer[0] = time[2]; @@ -2117,7 +2119,7 @@ void PCSX::CDRiso::DecodeRawSubData() { // read track // time: byte 0 - minute; byte 1 - second; byte 2 - frame // uses bcd format -bool PCSX::CDRiso::readTrack(uint8_t *time) { +bool PCSX::CDRiso::readTrack(uint8_t* time) { int sector = CDRom::MSF2SECT(CDRom::btoi(time[0]), CDRom::btoi(time[1]), CDRom::btoi(time[2])); long ret; @@ -2149,13 +2151,13 @@ bool PCSX::CDRiso::readTrack(uint8_t *time) { // plays cdda audio // sector: byte 0 - minute; byte 1 - second; byte 2 - frame // does NOT uses bcd format -void PCSX::CDRiso::play(uint8_t *time) { m_playing = true; } +void PCSX::CDRiso::play(uint8_t* time) { m_playing = true; } // stops cdda audio void PCSX::CDRiso::stop(void) { m_playing = false; } // gets subchannel data -uint8_t *PCSX::CDRiso::getBufferSub() { +uint8_t* PCSX::CDRiso::getBufferSub() { if ((m_subHandle != NULL || m_subChanMixed) && !m_subChanMissing) { return m_subbuffer; } @@ -2163,7 +2165,7 @@ uint8_t *PCSX::CDRiso::getBufferSub() { return NULL; } -bool PCSX::CDRiso::getStatus(CdrStat *stat) { +bool PCSX::CDRiso::getStatus(CdrStat* stat) { uint32_t sect; if (isLidOpened()) { @@ -2181,13 +2183,13 @@ bool PCSX::CDRiso::getStatus(CdrStat *stat) { // relative -> absolute time sect = m_cddaCurPos; - sec2msf(sect, (uint8_t *)stat->Time); + sec2msf(sect, (uint8_t*)stat->Time); return true; } // read CDDA sector into buffer -bool PCSX::CDRiso::readCDDA(unsigned char m, unsigned char s, unsigned char f, unsigned char *buffer) { +bool PCSX::CDRiso::readCDDA(unsigned char m, unsigned char s, unsigned char f, unsigned char* buffer) { unsigned char msf[3] = {m, s, f}; unsigned int file, track, track_start = 0; int ret; diff --git a/src/core/cdrom.cc b/src/core/cdrom.cc index 54ba29d81..14902b57c 100644 --- a/src/core/cdrom.cc +++ b/src/core/cdrom.cc @@ -65,7 +65,7 @@ class CDRomImpl : public PCSX::CDRom { CdlReadToc = 30, }; - static const inline char *CmdName[] = { + static const inline char* CmdName[] = { "CdlSync", "CdlNop", "CdlSetloc", "CdlPlay", "CdlForward", "CdlBackward", "CdlReadN", "CdlStandby", "CdlStop", "CdlPause", "CdlInit", "CdlMute", "CdlDemute", "CdlSetfilter", "CdlSetmode", "CdlGetmode", "CdlGetlocL", "CdlGetlocP", "CdlReadT", "CdlGetTN", "CdlGetTD", "CdlSeekL", "CdlSeekP", "CdlSetclock", @@ -141,8 +141,8 @@ class CDRomImpl : public PCSX::CDRom { struct CdrStat cdr_stat; - static constexpr unsigned int msf2sec(const uint8_t *msf) { return ((msf[0] * 60 + msf[1]) * 75) + msf[2]; } - static constexpr void sec2msf(unsigned int s, uint8_t *msf) { + static constexpr unsigned int msf2sec(const uint8_t* msf) { return ((msf[0] * 60 + msf[1]) * 75) + msf[2]; } + static constexpr void sec2msf(unsigned int s, uint8_t* msf) { msf[0] = s / 75 / 60; s = s - msf[0] * 75 * 60; msf[1] = s / 75; @@ -150,7 +150,7 @@ class CDRomImpl : public PCSX::CDRom { msf[2] = s; } // for that weird psemu API.. - static constexpr unsigned int fsm2sec(const uint8_t *msf) { return ((msf[2] * 60 + msf[1]) * 75) + msf[0]; } + static constexpr unsigned int fsm2sec(const uint8_t* msf) { return ((msf[2] * 60 + msf[1]) * 75) + msf[0]; } static const uint32_t H_SPUirqAddr = 0x1f801da4; static const uint32_t H_SPUaddr = 0x1f801da6; @@ -334,7 +334,7 @@ class CDRomImpl : public PCSX::CDRom { } } - void Find_CurTrack(const uint8_t *time) { + void Find_CurTrack(const uint8_t* time) { int current, sect; current = msf2sec(time); @@ -347,7 +347,7 @@ class CDRomImpl : public PCSX::CDRom { CDR_LOG("Find_CurTrack *** %02d %02d\n", m_curTrack, current); } - void generate_subq(const uint8_t *time) { + void generate_subq(const uint8_t* time) { unsigned char start[3], next[3]; unsigned int this_s, start_s, next_s, pregap; int relative_s; @@ -394,9 +394,9 @@ class CDRomImpl : public PCSX::CDRom { m_subq.absolute[2] = itob(time[2]); } - void ReadTrack(const uint8_t *time) { + void ReadTrack(const uint8_t* time) { unsigned char tmp[3]; - struct SubQ *subq; + struct SubQ* subq; uint16_t crc; tmp[0] = itob(time[0]); @@ -410,9 +410,9 @@ class CDRomImpl : public PCSX::CDRom { m_suceeded = m_iso.readTrack(tmp); memcpy(m_prev, tmp, 3); - subq = (struct SubQ *)m_iso.getBufferSub(); + subq = (struct SubQ*)m_iso.getBufferSub(); if (subq != NULL && m_curTrack == 1) { - crc = calcCrc((uint8_t *)subq + 12, 10); + crc = calcCrc((uint8_t*)subq + 12, 10); if (crc == (((uint16_t)subq->CRC[0] << 8) | subq->CRC[1])) { m_subq.track = subq->TrackNumber; m_subq.index = subq->IndexNumber; @@ -526,8 +526,8 @@ class CDRomImpl : public PCSX::CDRom { if (!m_muted) { m_iso.readCDDA(m_setSectorPlay[0], m_setSectorPlay[1], m_setSectorPlay[2], m_transfer); - attenuate((int16_t *)m_transfer, CD_FRAMESIZE_RAW / 4, 1); - PCSX::g_emulator.m_spu->playCDDAchannel((short *)m_transfer, CD_FRAMESIZE_RAW); + attenuate((int16_t*)m_transfer, CD_FRAMESIZE_RAW / 4, 1); + PCSX::g_emulator.m_spu->playCDDAchannel((short*)m_transfer, CD_FRAMESIZE_RAW); } m_setSectorPlay[2]++; @@ -891,7 +891,7 @@ class CDRomImpl : public PCSX::CDRom { } m_result[0] |= (m_result[1] >> 4) & 0x08; - strncpy((char *)&m_result[4], "PCSX", 4); + strncpy((char*)&m_result[4], "PCSX", 4); m_stat = Complete; break; @@ -943,7 +943,7 @@ class CDRomImpl : public PCSX::CDRom { // Crusaders of Might and Magic - update getlocl now // - fixes cutscene speech { - uint8_t *buf = m_iso.getBuffer(); + uint8_t* buf = m_iso.getBuffer(); if (buf != NULL) memcpy(m_transfer, buf, 8); } @@ -1024,7 +1024,7 @@ class CDRomImpl : public PCSX::CDRom { return v; } - void attenuate(int16_t *buf, int samples, int stereo) final { + void attenuate(int16_t* buf, int samples, int stereo) final { int i, l, r; int ll = m_attenuatorLeftToLeft; int lr = m_attenuatorLeftToRight; @@ -1054,7 +1054,7 @@ class CDRomImpl : public PCSX::CDRom { } void readInterrupt() final { - uint8_t *buf; + uint8_t* buf; if (!m_reading) return; @@ -1353,7 +1353,7 @@ class CDRomImpl : public PCSX::CDRom { void dma(uint32_t madr, uint32_t bcr, uint32_t chcr) final { uint32_t cdsize; unsigned i; - uint8_t *ptr; + uint8_t* ptr; CDR_LOG("dma() Log: *** DMA 3 *** %x addr = %x size = %x\n", chcr, madr, bcr); @@ -1384,7 +1384,7 @@ class CDRomImpl : public PCSX::CDRom { } } - ptr = (uint8_t *)PSXM(madr); + ptr = (uint8_t*)PSXM(madr); if (ptr == NULL) { CDR_LOG("dma() Log: *** DMA 3 *** NULL Pointer!\n"); break; @@ -1568,4 +1568,4 @@ class CDRomImpl : public PCSX::CDRom { } // namespace -PCSX::CDRom *PCSX::CDRom::factory() { return new CDRomImpl; } +PCSX::CDRom* PCSX::CDRom::factory() { return new CDRomImpl; } diff --git a/src/core/cheat.cc b/src/core/cheat.cc index c64a8bf03..2d33e0fd9 100644 --- a/src/core/cheat.cc +++ b/src/core/cheat.cc @@ -43,8 +43,8 @@ void PCSX::Cheats::ClearAllCheats() { } // load cheats from the specific filename -void PCSX::Cheats::LoadCheats(const char *filename) { - FILE *fp; +void PCSX::Cheats::LoadCheats(const char* filename) { + FILE* fp; char buf[256]; int count = 0; unsigned int t1, t2; @@ -73,9 +73,9 @@ void PCSX::Cheats::LoadCheats(const char *filename) { if (g_cheats == NULL) { assert(g_numCheats == 0); assert(s_numCheatsAllocated == ALLOC_INCREMENT); - g_cheats = (Cheat *)malloc(sizeof(Cheat) * s_numCheatsAllocated); + g_cheats = (Cheat*)malloc(sizeof(Cheat) * s_numCheatsAllocated); } else { - g_cheats = (Cheat *)realloc(g_cheats, sizeof(Cheat) * s_numCheatsAllocated); + g_cheats = (Cheat*)realloc(g_cheats, sizeof(Cheat) * s_numCheatsAllocated); } } @@ -104,9 +104,9 @@ void PCSX::Cheats::LoadCheats(const char *filename) { if (g_cheatCodes == NULL) { assert(g_numCodes == 0); assert(s_numCodesAllocated == ALLOC_INCREMENT); - g_cheatCodes = (CheatCode *)malloc(sizeof(CheatCode) * s_numCodesAllocated); + g_cheatCodes = (CheatCode*)malloc(sizeof(CheatCode) * s_numCodesAllocated); } else { - g_cheatCodes = (CheatCode *)realloc(g_cheatCodes, sizeof(CheatCode) * s_numCodesAllocated); + g_cheatCodes = (CheatCode*)realloc(g_cheatCodes, sizeof(CheatCode) * s_numCodesAllocated); } } @@ -127,8 +127,8 @@ void PCSX::Cheats::LoadCheats(const char *filename) { } // save all cheats to the specified filename -void PCSX::Cheats::SaveCheats(const char *filename) { - FILE *fp; +void PCSX::Cheats::SaveCheats(const char* filename) { + FILE* fp; int i, j; fp = fopen(filename, "w"); @@ -269,7 +269,7 @@ void PCSX::Cheats::ApplyCheats() { } } -int PCSX::Cheats::AddCheat(const char *descr, char *code) { +int PCSX::Cheats::AddCheat(const char* descr, char* code) { int c = 1; char *p1, *p2; @@ -279,9 +279,9 @@ int PCSX::Cheats::AddCheat(const char *descr, char *code) { if (g_cheats == NULL) { assert(g_numCheats == 0); assert(s_numCheatsAllocated == ALLOC_INCREMENT); - g_cheats = (Cheat *)malloc(sizeof(Cheat) * s_numCheatsAllocated); + g_cheats = (Cheat*)malloc(sizeof(Cheat) * s_numCheatsAllocated); } else { - g_cheats = (Cheat *)realloc(g_cheats, sizeof(Cheat) * s_numCheatsAllocated); + g_cheats = (Cheat*)realloc(g_cheats, sizeof(Cheat) * s_numCheatsAllocated); } } @@ -314,9 +314,9 @@ int PCSX::Cheats::AddCheat(const char *descr, char *code) { if (g_cheatCodes == NULL) { assert(g_numCodes == 0); assert(s_numCodesAllocated == ALLOC_INCREMENT); - g_cheatCodes = (CheatCode *)malloc(sizeof(CheatCode) * s_numCodesAllocated); + g_cheatCodes = (CheatCode*)malloc(sizeof(CheatCode) * s_numCodesAllocated); } else { - g_cheatCodes = (CheatCode *)realloc(g_cheatCodes, sizeof(CheatCode) * s_numCodesAllocated); + g_cheatCodes = (CheatCode*)realloc(g_cheatCodes, sizeof(CheatCode) * s_numCodesAllocated); } } @@ -350,7 +350,7 @@ void PCSX::Cheats::RemoveCheat(int index) { g_numCheats--; } -int PCSX::Cheats::EditCheat(int index, const char *descr, char *code) { +int PCSX::Cheats::EditCheat(int index, const char* descr, char* code) { int c = 1; int prev = g_numCodes; char *p1, *p2; @@ -381,9 +381,9 @@ int PCSX::Cheats::EditCheat(int index, const char *descr, char *code) { if (g_cheatCodes == NULL) { assert(g_numCodes == 0); assert(s_numCodesAllocated == ALLOC_INCREMENT); - g_cheatCodes = (CheatCode *)malloc(sizeof(CheatCode) * s_numCodesAllocated); + g_cheatCodes = (CheatCode*)malloc(sizeof(CheatCode) * s_numCodesAllocated); } else { - g_cheatCodes = (CheatCode *)realloc(g_cheatCodes, sizeof(CheatCode) * s_numCodesAllocated); + g_cheatCodes = (CheatCode*)realloc(g_cheatCodes, sizeof(CheatCode) * s_numCodesAllocated); } } @@ -432,7 +432,7 @@ void PCSX::Cheats::CheatSearchBackupMemory() { void PCSX::Cheats::CheatSearchInitBackupMemory() { if (g_prevM == NULL) { - g_prevM = (int8_t *)malloc(0x200000); + g_prevM = (int8_t*)malloc(0x200000); CheatSearchBackupMemory(); } } @@ -442,9 +442,9 @@ void PCSX::Cheats::CheatSearchAddResult(uint32_t addr) { s_numSearchResultsAllocated += ALLOC_INCREMENT; if (g_searchResults == NULL) { - g_searchResults = (uint32_t *)malloc(sizeof(uint32_t) * s_numSearchResultsAllocated); + g_searchResults = (uint32_t*)malloc(sizeof(uint32_t) * s_numSearchResultsAllocated); } else { - g_searchResults = (uint32_t *)realloc(g_searchResults, sizeof(uint32_t) * s_numSearchResultsAllocated); + g_searchResults = (uint32_t*)realloc(g_searchResults, sizeof(uint32_t) * s_numSearchResultsAllocated); } } diff --git a/src/core/cheat.h b/src/core/cheat.h index 1cb92b62c..5b3527e76 100644 --- a/src/core/cheat.h +++ b/src/core/cheat.h @@ -30,7 +30,7 @@ class Cheats { } CheatCode; typedef struct { - char *Descr; + char* Descr; int First; // index of the first cheat code int n; // number of cheat codes for this cheat int Enabled; @@ -38,14 +38,14 @@ class Cheats { void ClearAllCheats(); - void LoadCheats(const char *filename); - void SaveCheats(const char *filename); + void LoadCheats(const char* filename); + void SaveCheats(const char* filename); void ApplyCheats(); - int AddCheat(const char *descr, char *code); + int AddCheat(const char* descr, char* code); void RemoveCheat(int index); - int EditCheat(int index, const char *descr, char *code); + int EditCheat(int index, const char* descr, char* code); void FreeCheatSearchResults(); void FreeCheatSearchMem(); @@ -80,9 +80,9 @@ class Cheats { void CheatSearchNoChange32(); #define PREVM(mem) (&g_prevM[mem]) -#define PrevMu8(mem) (*(uint8_t *)PREVM(mem)) -#define PrevMu16(mem) (SWAP_LE16(*(uint16_t *)PREVM(mem))) -#define PrevMu32(mem) (SWAP_LE32(*(uint32_t *)PREVM(mem))) +#define PrevMu8(mem) (*(uint8_t*)PREVM(mem)) +#define PrevMu16(mem) (SWAP_LE16(*(uint16_t*)PREVM(mem))) +#define PrevMu32(mem) (SWAP_LE32(*(uint32_t*)PREVM(mem))) // cheat types enum { @@ -106,12 +106,12 @@ class Cheats { }; private: - Cheat *g_cheats = NULL; - CheatCode *g_cheatCodes = NULL; + Cheat* g_cheats = NULL; + CheatCode* g_cheatCodes = NULL; int g_numCodes = 0; - int8_t *g_prevM = NULL; - uint32_t *g_searchResults = NULL; + int8_t* g_prevM = NULL; + uint32_t* g_searchResults = NULL; int g_numSearchResults = 0; int g_numCheats = 0; diff --git a/src/core/debug.cc b/src/core/debug.cc index ae5b2204f..c5b27ef12 100644 --- a/src/core/debug.cc +++ b/src/core/debug.cc @@ -95,7 +95,7 @@ void PCSX::Debug::processAfter() { if (m_stepping) { const bool gotException = pc == 0x80000080 || pc == 0xbfc00180; - if (gotException) m_steppingJumps += 2; // there ought to be two jr $k0 + if (gotException) m_steppingJumps += 2; // there ought to be two jr $k0 auto none = m_breakpoints.end(); switch (m_stepType) { diff --git a/src/core/decode_xa.cc b/src/core/decode_xa.cc index 3c4b3fa30..d24212c78 100644 --- a/src/core/decode_xa.cc +++ b/src/core/decode_xa.cc @@ -52,7 +52,7 @@ static const int s_K1[4] = {0.0 * (1 << SHC), 0.0 * (1 << SHC), -0.8125 * (1 << #define BLKSIZ 28 /* block size (32 - 4 nibbles) */ //=========================================== -static void ADPCM_InitDecode(ADPCM_Decode_t *decp) { +static void ADPCM_InitDecode(ADPCM_Decode_t* decp) { decp->y0 = 0; decp->y1 = 0; } @@ -66,14 +66,14 @@ static void ADPCM_InitDecode(ADPCM_Decode_t *decp) { #define IK1(fid) (-s_K1[fid]) #endif -static inline void ADPCM_DecodeBlock16(ADPCM_Decode_t *decp, uint8_t filter_range, const void *vblockp, short *destp, +static inline void ADPCM_DecodeBlock16(ADPCM_Decode_t* decp, uint8_t filter_range, const void* vblockp, short* destp, int inc) { int i; int range, filterid; int32_t fy0, fy1; - const uint16_t *blockp; + const uint16_t* blockp; - blockp = (const unsigned short *)vblockp; + blockp = (const unsigned short*)vblockp; filterid = (filter_range >> 4) & 0x0f; range = (filter_range >> 0) & 0x0f; @@ -127,12 +127,12 @@ static inline void ADPCM_DecodeBlock16(ADPCM_Decode_t *decp, uint8_t filter_rang static const int s_headtable[4] = {0, 2, 8, 10}; //=========================================== -static void xa_decode_data(xa_decode_t *xdp, unsigned char *srcp) { - const uint8_t *sound_groupsp; +static void xa_decode_data(xa_decode_t* xdp, unsigned char* srcp) { + const uint8_t* sound_groupsp; const uint8_t *sound_datap, *sound_datap2; int i, j, k, nbits; uint16_t data[4096], *datap; - short *destp; + short* destp; destp = xdp->pcm; nbits = xdp->nbits == 4 ? 4 : 2; @@ -285,7 +285,7 @@ typedef struct { #define SUB_AUDIO 2 //============================================ -static int parse_xa_audio_sector(xa_decode_t *xdp, xa_subheader_t *subheadp, unsigned char *sectorp, +static int parse_xa_audio_sector(xa_decode_t* xdp, xa_subheader_t* subheadp, unsigned char* sectorp, int is_first_sector) { if (is_first_sector) { switch (AUDIO_CODING_GET_FREQ(subheadp->coding)) { @@ -344,8 +344,8 @@ static int parse_xa_audio_sector(xa_decode_t *xdp, xa_subheader_t *subheadp, uns //=== - 0 for any other successive sector //=== return -1 if error //================================================================ -int32_t xa_decode_sector(xa_decode_t *xdp, unsigned char *sectorp, int is_first_sector) { - if (parse_xa_audio_sector(xdp, (xa_subheader_t *)sectorp, sectorp + sizeof(xa_subheader_t), is_first_sector)) +int32_t xa_decode_sector(xa_decode_t* xdp, unsigned char* sectorp, int is_first_sector) { + if (parse_xa_audio_sector(xdp, (xa_subheader_t*)sectorp, sectorp + sizeof(xa_subheader_t), is_first_sector)) return -1; return 0; diff --git a/src/core/decode_xa.h b/src/core/decode_xa.h index 9607a55a4..f4bf48ac2 100644 --- a/src/core/decode_xa.h +++ b/src/core/decode_xa.h @@ -34,4 +34,4 @@ struct xa_decode_t { short pcm[16384]; }; -int32_t xa_decode_sector(xa_decode_t *xdp, unsigned char *sectorp, int is_first_sector); +int32_t xa_decode_sector(xa_decode_t* xdp, unsigned char* sectorp, int is_first_sector); diff --git a/src/core/disr3000a.cc b/src/core/disr3000a.cc index 8eb545b1e..9614a88b2 100644 --- a/src/core/disr3000a.cc +++ b/src/core/disr3000a.cc @@ -28,28 +28,28 @@ #include "core/r3000a.h" // Names of registers -const char *PCSX::Disasm::s_disRNameGPR[] = { +const char* PCSX::Disasm::s_disRNameGPR[] = { "r0", "at", "v0", "v1", "a0", "a1", "a2", "a3", // 00 "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7", // 08 "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7", // 10 "t8", "t9", "k0", "k1", "gp", "sp", "fp", "ra", // 18 }; -const char *PCSX::Disasm::s_disRNameCP2D[] = { +const char* PCSX::Disasm::s_disRNameCP2D[] = { "vxy0", "vz0", "vxy1", "vz1", "vxy2", "vz2", "rgb", "otz", // 00 "ir0", "ir1", "ir2", "ir3", "sxy0", "sxy1", "sxy2", "sxyp", // 08 "sz0", "sz1", "sz2", "sz3", "rgb0", "rgb1", "rgb2", "res1", // 10 "mac0", "mac1", "mac2", "mac3", "irgb", "orgb", "lzcs", "lzcr", // 18 }; -const char *PCSX::Disasm::s_disRNameCP2C[] = { +const char* PCSX::Disasm::s_disRNameCP2C[] = { "r11r12", "r13r21", "r22r23", "r31r32", "r33", "trx", "try", "trz", // 00 "l11l12", "l13l21", "l22l23", "l31l32", "l33", "rbk", "bbk", "gbk", // 08 "lr1lr2", "lr3lg1", "lg2lg3", "lb1lb2", "lb3", "rfc", "gfc", "bfc", // 10 "ofx", "ofy", "h", "dqa", "dqb", "zsf3", "zsf4", "flag", // 18 }; -const char *PCSX::Disasm::s_disRNameCP0[] = { +const char* PCSX::Disasm::s_disRNameCP0[] = { "Index", "Random", "EntryLo0", "EntryLo1", // 00 "Context", "PageMask", "Wired", "+Checkme", // 04 "BadVAddr", "Count", "EntryHi", "Compare", // 08 @@ -70,7 +70,7 @@ const char *PCSX::Disasm::s_disRNameCP0[] = { #undef _Target_ #define declare(n) \ - void PCSX::Disasm::n(uint32_t code, uint32_t nextCode, uint32_t pc, bool *skipNext, bool *delaySlotNext) + void PCSX::Disasm::n(uint32_t code, uint32_t nextCode, uint32_t pc, bool* skipNext, bool* delaySlotNext) #define _Funct_ ((code)&0x3F) // The funct part of the instruction register #define _Rd_ ((code >> 11) & 0x1F) // The rd part of the instruction register #define _Rt_ ((code >> 16) & 0x1F) // The rt part of the instruction register @@ -84,8 +84,8 @@ const char *PCSX::Disasm::s_disRNameCP0[] = { namespace { struct StringDisasm : public PCSX::Disasm { - uint8_t *ptr(uint32_t addr) { - uint8_t *lut = PCSX::g_emulator.m_psxMem->g_psxMemRLUT[addr >> 16]; + uint8_t* ptr(uint32_t addr) { + uint8_t* lut = PCSX::g_emulator.m_psxMem->g_psxMemRLUT[addr >> 16]; if (lut) { return lut + (addr & 0xffff); } else { @@ -94,9 +94,9 @@ struct StringDisasm : public PCSX::Disasm { } } uint8_t mem8(uint32_t addr) { return *ptr(addr); } - uint16_t mem16(uint32_t addr) { return SWAP_LE16(*(int16_t *)ptr(addr)); } - uint32_t mem32(uint32_t addr) { return SWAP_LE32(*(int32_t *)ptr(addr)); } - void append(const char *str, ...) { + uint16_t mem16(uint32_t addr) { return SWAP_LE16(*(int16_t*)ptr(addr)); } + uint32_t mem32(uint32_t addr) { return SWAP_LE32(*(int32_t*)ptr(addr)); } + void append(const char* str, ...) { va_list va; va_start(va, str); char buf[64]; @@ -111,7 +111,7 @@ struct StringDisasm : public PCSX::Disasm { m_gotArg = true; } virtual void Invalid() final { strcpy(m_buf, "*** Bad OP ***"); } - virtual void OpCode(const char *name) final { + virtual void OpCode(const char* name) final { std::sprintf(m_buf, "%-7s", name); m_gotArg = false; m_len = 7; @@ -996,7 +996,7 @@ const PCSX::Disasm::TdisR3000AF PCSX::Disasm::s_disR3000A[] = { &Disasm::disNULL, &Disasm::disNULL, &Disasm::disNULL, &Disasm::disNULL, // 3c }; -std::string PCSX::Disasm::asString(uint32_t code, uint32_t nextCode, uint32_t pc, bool *skipNext, bool withValues) { +std::string PCSX::Disasm::asString(uint32_t code, uint32_t nextCode, uint32_t pc, bool* skipNext, bool withValues) { StringDisasm strd; strd.setValues(withValues); strd.process(code, nextCode, pc, skipNext); diff --git a/src/core/disr3000a.h b/src/core/disr3000a.h index ea04e2ab5..b4f4a81de 100644 --- a/src/core/disr3000a.h +++ b/src/core/disr3000a.h @@ -30,13 +30,13 @@ namespace PCSX { class Disasm { public: - static const char *s_disRNameGPR[]; - static const char *s_disRNameCP2D[]; - static const char *s_disRNameCP2C[]; - static const char *s_disRNameCP0[]; + static const char* s_disRNameGPR[]; + static const char* s_disRNameCP2D[]; + static const char* s_disRNameCP2C[]; + static const char* s_disRNameCP0[]; #define declare(n) \ - void n(uint32_t code, uint32_t nextCode, uint32_t pc, bool *skipNext = nullptr, bool *delaySlotNext = nullptr) + void n(uint32_t code, uint32_t nextCode, uint32_t pc, bool* skipNext = nullptr, bool* delaySlotNext = nullptr) declare(process) { if (skipNext && *skipNext) { @@ -49,12 +49,13 @@ class Disasm { (*this.*ptr)(code, nextCode, pc, skipNext, delaySlotNext); } - static std::string asString(uint32_t code, uint32_t nextCode, uint32_t pc, bool *skipNext = nullptr, bool withValues = false); + static std::string asString(uint32_t code, uint32_t nextCode, uint32_t pc, bool* skipNext = nullptr, + bool withValues = false); virtual void reset() {} protected: virtual void Invalid() = 0; - virtual void OpCode(const char *str) = 0; + virtual void OpCode(const char* str) = 0; virtual void GPR(uint8_t reg) = 0; virtual void CP0(uint8_t reg) = 0; virtual void CP2C(uint8_t reg) = 0; @@ -71,8 +72,8 @@ class Disasm { private: // Type definition of our functions - typedef void (Disasm::*TdisR3000AF)(uint32_t code, uint32_t nextCode, uint32_t pc, bool *skipNext, - bool *delaySlotNext); + typedef void (Disasm::*TdisR3000AF)(uint32_t code, uint32_t nextCode, uint32_t pc, bool* skipNext, + bool* delaySlotNext); typedef const TdisR3000AF cTdisR3000AF; static const TdisR3000AF s_disR3000A[]; static const TdisR3000AF s_disR3000A_COP0[]; diff --git a/src/core/file.cc b/src/core/file.cc index 0ad7037bb..871d4a4d0 100644 --- a/src/core/file.cc +++ b/src/core/file.cc @@ -51,9 +51,9 @@ ssize_t PCSX::File::tell() { void PCSX::File::flush() { if (m_handle) fflush(m_handle); } -PCSX::File::File(void *data, ssize_t size) { +PCSX::File::File(void* data, ssize_t size) { if (data) { - m_data = static_cast(data); + m_data = static_cast(data); } else { assert(size == 1); m_data = &m_internalBuffer; @@ -61,7 +61,7 @@ PCSX::File::File(void *data, ssize_t size) { m_size = size; } #ifdef _WIN32 -PCSX::File::File(const char *filename) : m_filename(filename) { +PCSX::File::File(const char* filename) : m_filename(filename) { #ifdef UNICODE int needed; LPWSTR str; @@ -79,14 +79,14 @@ PCSX::File::File(const char *filename) : m_filename(filename) { #endif } #else -PCSX::File::File(const char *filename) { m_handle = fopen(filename, "rb"); } +PCSX::File::File(const char* filename) { m_handle = fopen(filename, "rb"); } #endif -char *PCSX::File::gets(char *s, int size) { +char* PCSX::File::gets(char* s, int size) { if (m_handle) return fgets(s, size, m_handle); if (!m_data) return nullptr; if (m_size == m_ptr) return nullptr; int c; - char *ptr = s; + char* ptr = s; if (!size) return nullptr; size--; while (true) { @@ -114,7 +114,7 @@ std::string PCSX::File::gets() { ret += c; } } -ssize_t PCSX::File::read(void *dest, ssize_t size) { +ssize_t PCSX::File::read(void* dest, ssize_t size) { if (m_handle) return fread(dest, 1, size, m_handle); if (!m_data) return -1; size = std::max(m_size - m_ptr, size); @@ -123,7 +123,7 @@ ssize_t PCSX::File::read(void *dest, ssize_t size) { m_ptr += size; return size; } -ssize_t PCSX::File::write(const void *dest, size_t size) { +ssize_t PCSX::File::write(const void* dest, size_t size) { abort(); return -1; } diff --git a/src/core/gpu.cc b/src/core/gpu.cc index 0915c8e5e..0c061dc11 100644 --- a/src/core/gpu.cc +++ b/src/core/gpu.cc @@ -93,13 +93,13 @@ int PCSX::GPU::gpuReadStatus() { } void PCSX::GPU::dma(uint32_t madr, uint32_t bcr, uint32_t chcr) { // GPU - uint32_t *ptr; + uint32_t* ptr; uint32_t size, bs; switch (chcr) { case 0x01000200: // vram2mem PSXDMA_LOG("*** DMA2 GPU - vram2mem *** %lx addr = %lx size = %lx\n", chcr, madr, bcr); - ptr = (uint32_t *)PSXM(madr); + ptr = (uint32_t*)PSXM(madr); if (ptr == NULL) { PSXDMA_LOG("*** DMA2 GPU - vram2mem *** NULL Pointer!!!\n"); break; @@ -122,7 +122,7 @@ void PCSX::GPU::dma(uint32_t madr, uint32_t bcr, uint32_t chcr) { // GPU size = (bcr >> 16) * bs; // BA blocks * BS words (word = 32-bits) PSXDMA_LOG("*** DMA 2 - GPU mem2vram *** %lx addr = %lxh, BCR %lxh => size %d = BA(%d) * BS(%xh)\n", chcr, madr, bcr, size, size / bs, size / (bcr >> 16)); - ptr = (uint32_t *)PSXM(madr); + ptr = (uint32_t*)PSXM(madr); if (ptr == NULL) { PSXDMA_LOG("*** DMA2 GPU - mem2vram *** NULL Pointer!!!\n"); break; @@ -144,7 +144,7 @@ void PCSX::GPU::dma(uint32_t madr, uint32_t bcr, uint32_t chcr) { // GPU PSXDMA_LOG("*** DMA 2 - GPU dma chain *** %8.8lx addr = %lx size = %lx\n", chcr, madr, bcr); size = gpuDmaChainSize(madr); - dmaChain((uint32_t *)PCSX::g_emulator.m_psxMem->g_psxM, madr & 0x1fffff); + dmaChain((uint32_t*)PCSX::g_emulator.m_psxMem->g_psxM, madr & 0x1fffff); // Tekken 3 = use 1.0 only (not 1.5x) diff --git a/src/core/gpu.h b/src/core/gpu.h index adfc76381..7ce6ff7a5 100644 --- a/src/core/gpu.h +++ b/src/core/gpu.h @@ -46,25 +46,25 @@ class GPU { public: virtual int32_t init() = 0; virtual int32_t shutdown() = 0; - virtual int32_t open(GUI *) = 0; + virtual int32_t open(GUI*) = 0; virtual int32_t close() = 0; virtual uint32_t readData() = 0; - virtual void readDataMem(uint32_t *pMem, int iSize) = 0; + virtual void readDataMem(uint32_t* pMem, int iSize) = 0; virtual uint32_t readStatus() = 0; virtual void writeData(uint32_t gdata) = 0; - virtual void writeDataMem(uint32_t *pMem, int iSize) = 0; + virtual void writeDataMem(uint32_t* pMem, int iSize) = 0; virtual void writeStatus(uint32_t gdata) = 0; - virtual int32_t dmaChain(uint32_t *baseAddrL, uint32_t addr) = 0; + virtual int32_t dmaChain(uint32_t* baseAddrL, uint32_t addr) = 0; virtual void updateLace() = 0; - virtual void save(SaveStates::GPU &gpu) = 0; - virtual void load(const SaveStates::GPU &gpu) = 0; + virtual void save(SaveStates::GPU& gpu) = 0; + virtual void load(const SaveStates::GPU& gpu) = 0; virtual void keypressed(int key) {} - virtual void displayText(char *pText) { PCSX::g_system->printf("%s\n", pText); } + virtual void displayText(char* pText) { PCSX::g_system->printf("%s\n", pText); } virtual void makeSnapshot(void) {} virtual void toggleDebug(void) {} - virtual int32_t getScreenPic(unsigned char *pMem) { return -1; } - virtual int32_t showScreenPic(unsigned char *pMem) { return -1; } + virtual int32_t getScreenPic(unsigned char* pMem) { return -1; } + virtual int32_t showScreenPic(unsigned char* pMem) { return -1; } virtual void clearDynarec(void (*callback)(void)) {} virtual void hSync(int val) {} virtual void vBlank(int val) {} @@ -72,8 +72,8 @@ class GPU { virtual void cursor(int player, int x, int y) {} virtual void addVertex(short sx, short sy, int64_t fx, int64_t fy, int64_t fz) {} virtual void setSpeed(float newSpeed) {} - virtual void pgxpMemory(unsigned int addr, unsigned char *pVRAM) {} - virtual void pgxpCacheVertex(short sx, short sy, const unsigned char *_pVertex) {} + virtual void pgxpMemory(unsigned int addr, unsigned char* pVRAM) {} + virtual void pgxpCacheVertex(short sx, short sy, const unsigned char* _pVertex) {} virtual int32_t test(void) { return 0; } virtual void about(void) {} }; diff --git a/src/core/ix86/iR3000A.cc b/src/core/ix86/iR3000A.cc index efd0a9aec..33fe254ec 100644 --- a/src/core/ix86/iR3000A.cc +++ b/src/core/ix86/iR3000A.cc @@ -94,16 +94,16 @@ class X86DynaRecCPU : public PCSX::R3000Acpu { virtual void Shutdown() final; virtual void SetPGXPMode(uint32_t pgxpMode) final; - static void recClearWrapper(X86DynaRecCPU *that, uint32_t a, uint32_t s) { that->Clear(a, s); } + static void recClearWrapper(X86DynaRecCPU* that, uint32_t a, uint32_t s) { that->Clear(a, s); } PCSX::ix86 gen; - uintptr_t *m_psxRecLUT; + uintptr_t* m_psxRecLUT; static const size_t RECMEM_SIZE = 8 * 1024 * 1024; - int8_t *m_recMem; /* the recompiled blocks will be here */ - char *m_recRAM; /* and the s_ptr to the blocks here */ - char *m_recROM; /* and here */ + int8_t* m_recMem; /* the recompiled blocks will be here */ + char* m_recRAM; /* and the s_ptr to the blocks here */ + char* m_recROM; /* and here */ uint32_t m_pc; /* recompiler pc */ @@ -125,12 +125,12 @@ class X86DynaRecCPU : public PCSX::R3000Acpu { iRegisters m_iRegs[32]; iRegisters m_iRegsSaved[32]; - cfunc_t *m_pRecBSC = NULL; - cfunc_t *m_pRecSPC = NULL; - cfunc_t *m_pRecREG = NULL; - cfunc_t *m_pRecCP0 = NULL; - cfunc_t *m_pRecCP2 = NULL; - cfunc_t *m_pRecCP2BSC = NULL; + cfunc_t* m_pRecBSC = NULL; + cfunc_t* m_pRecSPC = NULL; + cfunc_t* m_pRecREG = NULL; + cfunc_t* m_pRecCP0 = NULL; + cfunc_t* m_pRecCP2 = NULL; + cfunc_t* m_pRecCP2BSC = NULL; static const func_t m_recBSC[64]; static const func_t m_recSPC[64]; @@ -262,7 +262,7 @@ class X86DynaRecCPU : public PCSX::R3000Acpu { gen.CALLFunc((uint32_t)gteMFC2Wrapper); gen.MOV32RtoR(PCSX::ix86::EDI, PCSX::ix86::EAX); m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = _Rt_; } @@ -271,7 +271,7 @@ class X86DynaRecCPU : public PCSX::R3000Acpu { gen.CALLFunc((uint32_t)gteCFC2Wrapper); gen.MOV32RtoR(PCSX::ix86::EDI, PCSX::ix86::EAX); m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = _Rt_; } @@ -631,17 +631,17 @@ void X86DynaRecCPU::iPushReg(unsigned reg) { bool X86DynaRecCPU::Init() { int i; - m_psxRecLUT = (uintptr_t *)calloc(0x010000, sizeof(uintptr_t)); + m_psxRecLUT = (uintptr_t*)calloc(0x010000, sizeof(uintptr_t)); #ifndef _WIN32 - m_recMem = (int8_t *)mmap(0, ALLOC_SIZE, PROT_EXEC | PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); + m_recMem = (int8_t*)mmap(0, ALLOC_SIZE, PROT_EXEC | PROT_WRITE | PROT_READ, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); #else - m_recMem = (int8_t *)VirtualAlloc(NULL, ALLOC_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); + m_recMem = (int8_t*)VirtualAlloc(NULL, ALLOC_SIZE, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE); #endif memset(m_recMem, 0, ALLOC_SIZE); - m_recRAM = (char *)calloc(0x200000, 1); - m_recROM = (char *)calloc(0x080000, 1); + m_recRAM = (char*)calloc(0x200000, 1); + m_recROM = (char*)calloc(0x080000, 1); if (m_recRAM == NULL || m_recROM == NULL || m_recMem == NULL || m_psxRecLUT == NULL) { PCSX::g_system->message("Error allocating memory"); return false; @@ -693,11 +693,11 @@ void X86DynaRecCPU::recError() { void X86DynaRecCPU::execute() { uint32_t (**recFunc)() = NULL; - char *p; + char* p; InterceptBIOS(); - p = (char *)PC_REC(m_psxRegs.pc); + p = (char*)PC_REC(m_psxRegs.pc); if (p != NULL && IsPcValid(m_psxRegs.pc)) { recFunc = (uint32_t(**)())(uint32_t)p; @@ -706,7 +706,7 @@ void X86DynaRecCPU::execute() { return; } - const bool &debug = PCSX::g_emulator.settings.get(); + const bool& debug = PCSX::g_emulator.settings.get(); if (debug) PCSX::g_emulator.m_debug->processBefore(); if (*recFunc == 0) recRecompile(); @@ -743,12 +743,12 @@ void X86DynaRecCPU::Clear(uint32_t Addr, uint32_t Size) { offset &= 0x1fffff; if (offset >= DYNAREC_BLOCK * 4) - memset((void *)PC_REC(Addr - DYNAREC_BLOCK * 4), 0, DYNAREC_BLOCK * 4); + memset((void*)PC_REC(Addr - DYNAREC_BLOCK * 4), 0, DYNAREC_BLOCK * 4); else - memset((void *)PC_REC(Addr - offset), 0, offset); + memset((void*)PC_REC(Addr - offset), 0, offset); } - memset((void *)PC_REC(Addr), 0, Size * 4); + memset((void*)PC_REC(Addr), 0, Size * 4); } void X86DynaRecCPU::recNULL() { @@ -1469,7 +1469,7 @@ void X86DynaRecCPU::recLB() { if (_Rt_) { m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = _Rt_; } @@ -1506,7 +1506,7 @@ void X86DynaRecCPU::recLBU() { if (_Rt_) { m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = _Rt_; } @@ -1543,7 +1543,7 @@ void X86DynaRecCPU::recLH() { if (_Rt_) { m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = _Rt_; } @@ -1580,7 +1580,7 @@ void X86DynaRecCPU::recLHU() { if (_Rt_) { m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = _Rt_; } @@ -1658,7 +1658,7 @@ void X86DynaRecCPU::recLW() { if (_Rt_) { m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = _Rt_; } @@ -1739,7 +1739,7 @@ void X86DynaRecCPU::recLWL() { if (_Rt_) { m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = _Rt_; } @@ -1800,7 +1800,7 @@ void X86DynaRecCPU::recLWR() { if (_Rt_) { m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = _Rt_; } @@ -2471,7 +2471,7 @@ void X86DynaRecCPU::recBLTZAL() { if (IsConst(_Rs_)) { if ((int32_t)m_iRegs[_Rs_].k < 0) { m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = 31; gen.MOV32ItoR(PCSX::ix86::EDI, m_pc + 4); @@ -2484,7 +2484,7 @@ void X86DynaRecCPU::recBLTZAL() { iFlushReg(31); m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = 31; gen.MOV32MtoR(PCSX::ix86::EDI, (uint32_t)&m_psxRegs.GPR.n.ra); @@ -2506,7 +2506,7 @@ void X86DynaRecCPU::recBGEZAL() { if (IsConst(_Rs_)) { if ((int32_t)m_iRegs[_Rs_].k >= 0) { m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = 31; gen.MOV32ItoR(PCSX::ix86::EDI, m_pc + 4); @@ -2519,7 +2519,7 @@ void X86DynaRecCPU::recBGEZAL() { iFlushReg(31); m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = 31; gen.MOV32MtoR(PCSX::ix86::EDI, (uint32_t)&m_psxRegs.GPR.n.ra); @@ -2545,7 +2545,7 @@ void X86DynaRecCPU::recJ() { void X86DynaRecCPU::recJAL() { // jal target m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = 31; gen.MOV32ItoR(PCSX::ix86::EDI, m_pc + 4); @@ -2571,7 +2571,7 @@ void X86DynaRecCPU::recJR() { void X86DynaRecCPU::recJALR() { // jalr Rs m_needsStackFrame = true; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = _Rd_; gen.MOV32ItoR(PCSX::ix86::EDI, m_pc + 4); @@ -3026,7 +3026,7 @@ const func_t X86DynaRecCPU::m_pgxpRecBSCMem[64] = { }; void X86DynaRecCPU::recRecompile() { - char *p; + char* p; /* if gen.m_x86Ptr reached the mem limit reset whole mem */ if (((uint32_t)gen.x86GetPtr() - (uint32_t)m_recMem) >= RECMEM_SIZE) { @@ -3037,8 +3037,8 @@ void X86DynaRecCPU::recRecompile() { m_pc = m_psxRegs.pc; uint32_t old_pc = m_pc; - int8_t *startPtr = gen.x86GetPtr(); - (*(uint32_t *)PC_REC(m_pc)) = (uint32_t)startPtr; + int8_t* startPtr = gen.x86GetPtr(); + (*(uint32_t*)PC_REC(m_pc)) = (uint32_t)startPtr; m_needsStackFrame = false; m_pcInEBP = false; m_nextIsDelaySlot = false; @@ -3053,7 +3053,7 @@ void X86DynaRecCPU::recRecompile() { gen.XOR32RtoR(PCSX::ix86::EBX, PCSX::ix86::EBX); gen.PUSH32R(PCSX::ix86::ESI); gen.PUSH32R(PCSX::ix86::EDI); - int8_t *endStackFramePtr = gen.x86GetPtr(); + int8_t* endStackFramePtr = gen.x86GetPtr(); auto shouldContinue = [&]() { if (m_nextIsDelaySlot) { @@ -3070,7 +3070,7 @@ void X86DynaRecCPU::recRecompile() { auto processDelayedLoad = [&]() { m_currentDelayedLoad ^= 1; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; if (delayedLoad.active) { delayedLoad.active = false; const unsigned index = delayedLoad.index; @@ -3095,12 +3095,12 @@ void X86DynaRecCPU::recRecompile() { m_inDelaySlot = true; m_nextIsDelaySlot = false; } - p = (char *)PSXM(m_pc); + p = (char*)PSXM(m_pc); if (p == NULL) { recError(); return; } - m_psxRegs.code = *(uint32_t *)p; + m_psxRegs.code = *(uint32_t*)p; m_pc += 4; count++; func_t func = m_pRecBSC[m_psxRegs.code >> 26]; @@ -3138,7 +3138,7 @@ void X86DynaRecCPU::recRecompile() { gen.RET(); } else { ptrdiff_t count = endStackFramePtr - startPtr; - (*(uint32_t *)PC_REC(old_pc)) = (uint32_t)endStackFramePtr; + (*(uint32_t*)PC_REC(old_pc)) = (uint32_t)endStackFramePtr; gen.NOP(count, startPtr); gen.RET(); } diff --git a/src/core/logger.h b/src/core/logger.h index 04fb0040a..c5d0302d8 100644 --- a/src/core/logger.h +++ b/src/core/logger.h @@ -26,20 +26,20 @@ namespace PCSX { struct LogName { - const char *name; + const char* name; }; -template +template class Logger { public: - static void Log(const char *fmt, ...) { + static void Log(const char* fmt, ...) { if (!enabled) return; va_list a; va_start(a, fmt); g_system->log(name.name, fmt, a); va_end(a); } - static void LogVA(const char *fmt, va_list a) { + static void LogVA(const char* fmt, va_list a) { if (!enabled) return; g_system->log(name.name, fmt, a); } diff --git a/src/core/mdec.cc b/src/core/mdec.cc index 62cb32275..e8bb3c91f 100644 --- a/src/core/mdec.cc +++ b/src/core/mdec.cc @@ -43,20 +43,20 @@ #define FIX_1_847759065 SCALER(31000253, AAN_CONST_SCALE) // A2 #define FIX_2_613125930 SCALER(43840978, AAN_CONST_SCALE) // B2 -static inline void fillcol(int *blk, int val) { +static inline void fillcol(int* blk, int val) { blk[0 * PCSX::MDEC::DSIZE] = blk[1 * PCSX::MDEC::DSIZE] = blk[2 * PCSX::MDEC::DSIZE] = blk[3 * PCSX::MDEC::DSIZE] = blk[4 * PCSX::MDEC::DSIZE] = blk[5 * PCSX::MDEC::DSIZE] = blk[6 * PCSX::MDEC::DSIZE] = blk[7 * PCSX::MDEC::DSIZE] = val; } -static inline void fillrow(int *blk, int val) { +static inline void fillrow(int* blk, int val) { blk[0] = blk[1] = blk[2] = blk[3] = blk[4] = blk[5] = blk[6] = blk[7] = val; } -static void idct(int *block, int used_col) { +static void idct(int* block, int used_col) { int tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7; int z5, z10, z11, z12, z13; - int *ptr; + int* ptr; int i; // the block has only the DC coefficient @@ -187,7 +187,7 @@ enum { MDEC1_RESET = 0x80000000, }; -void PCSX::MDEC::iqtab_init(int *iqtab, unsigned char *iq_y) { +void PCSX::MDEC::iqtab_init(int* iqtab, unsigned char* iq_y) { int i; for (i = 0; i < DSIZE2; i++) { @@ -197,9 +197,9 @@ void PCSX::MDEC::iqtab_init(int *iqtab, unsigned char *iq_y) { #define MDEC_END_OF_DATA 0xfe00 -unsigned short *PCSX::MDEC::rl2blk(int *blk, unsigned short *mdec_rl) { +unsigned short* PCSX::MDEC::rl2blk(int* blk, unsigned short* mdec_rl) { int i, k, q_scale, rl, used_col; - int *iqtab; + int* iqtab; memset(blk, 0, 6 * DSIZE2 * sizeof(int)); iqtab = iq_uv; @@ -260,7 +260,7 @@ unsigned short *PCSX::MDEC::rl2blk(int *blk, unsigned short *mdec_rl) { #define CLAMP_SCALE8(a) (CLAMP8(SCALE8(a))) #define CLAMP_SCALE5(a) (CLAMP5(SCALE5(a))) -inline void PCSX::MDEC::putlinebw15(uint16_t *image, int *Yblk) { +inline void PCSX::MDEC::putlinebw15(uint16_t* image, int* Yblk) { int i; int A = (mdec.reg0 & MDEC0_STP) ? 0x8000 : 0; @@ -271,7 +271,7 @@ inline void PCSX::MDEC::putlinebw15(uint16_t *image, int *Yblk) { } } -inline void PCSX::MDEC::putquadrgb15(uint16_t *image, int *Yblk, int Cr, int Cb) { +inline void PCSX::MDEC::putquadrgb15(uint16_t* image, int* Yblk, int Cr, int Cb) { int Y, R, G, B; int A = (mdec.reg0 & MDEC0_STP) ? 0x8000 : 0; R = MULR(Cr); @@ -289,11 +289,11 @@ inline void PCSX::MDEC::putquadrgb15(uint16_t *image, int *Yblk, int Cr, int Cb) image[17] = MAKERGB15(CLAMP_SCALE5(Y + R), CLAMP_SCALE5(Y + G), CLAMP_SCALE5(Y + B), A); } -inline void PCSX::MDEC::yuv2rgb15(int *blk, unsigned short *image) { +inline void PCSX::MDEC::yuv2rgb15(int* blk, unsigned short* image) { int x, y; - int *Yblk = blk + DSIZE2 * 2; - int *Crblk = blk; - int *Cbblk = blk + DSIZE2; + int* Yblk = blk + DSIZE2 * 2; + int* Crblk = blk; + int* Cbblk = blk + DSIZE2; if (!PCSX::g_emulator.settings.get()) { for (y = 0; y < 16; y += 2, Crblk += 4, Cbblk += 4, Yblk += 8, image += 24) { @@ -312,7 +312,7 @@ inline void PCSX::MDEC::yuv2rgb15(int *blk, unsigned short *image) { } } -static inline void putlinebw24(uint8_t *image, int *Yblk) { +static inline void putlinebw24(uint8_t* image, int* Yblk) { int i; unsigned char Y; for (i = 0; i < 8 * 3; i += 3, Yblk++) { @@ -323,7 +323,7 @@ static inline void putlinebw24(uint8_t *image, int *Yblk) { } } -static inline void putquadrgb24(uint8_t *image, int *Yblk, int Cr, int Cb) { +static inline void putquadrgb24(uint8_t* image, int* Yblk, int Cr, int Cb) { int Y, R, G, B; R = MULR(Cr); @@ -348,11 +348,11 @@ static inline void putquadrgb24(uint8_t *image, int *Yblk, int Cr, int Cb) { image[17 * 3 + 2] = CLAMP_SCALE8(Y + B); } -void yuv2rgb24(int *blk, uint8_t *image) { +void yuv2rgb24(int* blk, uint8_t* image) { int x, y; - int *Yblk = blk + PCSX::MDEC::DSIZE2 * 2; - int *Crblk = blk; - int *Cbblk = blk + PCSX::MDEC::DSIZE2; + int* Yblk = blk + PCSX::MDEC::DSIZE2 * 2; + int* Crblk = blk; + int* Cbblk = blk + PCSX::MDEC::DSIZE2; if (!PCSX::g_emulator.settings.get()) { for (y = 0; y < 16; y += 2, Crblk += 4, Cbblk += 4, Yblk += 8, image += 8 * 3 * 3) { @@ -375,7 +375,7 @@ void PCSX::MDEC::mdecInit(void) { memset(&mdec, 0, sizeof(mdec)); memset(iq_y, 0, sizeof(iq_y)); memset(iq_uv, 0, sizeof(iq_uv)); - mdec.rl = (uint16_t *)&PCSX::g_emulator.m_psxMem->g_psxM[0x100000]; + mdec.rl = (uint16_t*)&PCSX::g_emulator.m_psxMem->g_psxM[0x100000]; } // command register @@ -413,7 +413,7 @@ void PCSX::MDEC::psxDma0(uint32_t adr, uint32_t bcr, uint32_t chcr) { switch (cmd >> 28) { case 0x3: // decode - mdec.rl = (uint16_t *)PSXM(adr); + mdec.rl = (uint16_t*)PSXM(adr); /* now the mdec is busy till all data are decoded */ mdec.reg1 |= MDEC1_BUSY; /* detect the end of decoding */ @@ -434,7 +434,7 @@ void PCSX::MDEC::psxDma0(uint32_t adr, uint32_t bcr, uint32_t chcr) { case 0x4: // quantization table upload { - uint8_t *p = (uint8_t *)PSXM(adr); + uint8_t* p = (uint8_t*)PSXM(adr); // printf("uploading new quantization table\n"); // printmatrixu8(p); // printmatrixu8(p + 64); @@ -470,7 +470,7 @@ void PCSX::MDEC::mdec0Interrupt() { void PCSX::MDEC::psxDma1(uint32_t adr, uint32_t bcr, uint32_t chcr) { int blk[DSIZE2 * 6]; - uint8_t *image; + uint8_t* image; int size; int dmacnt; @@ -489,7 +489,7 @@ void PCSX::MDEC::psxDma1(uint32_t adr, uint32_t bcr, uint32_t chcr) { mdec.pending_dma1.chcr = chcr; /* do not free the dma */ } else { - image = (uint8_t *)PSXM(adr); + image = (uint8_t*)PSXM(adr); if (mdec.reg0 & MDEC0_RGB24) { /* 16 bits decoding @@ -508,14 +508,14 @@ void PCSX::MDEC::psxDma1(uint32_t adr, uint32_t bcr, uint32_t chcr) { while (size >= SIZE_OF_16B_BLOCK) { mdec.rl = rl2blk(blk, mdec.rl); - yuv2rgb15(blk, (uint16_t *)image); + yuv2rgb15(blk, (uint16_t*)image); image += SIZE_OF_16B_BLOCK; size -= SIZE_OF_16B_BLOCK; } if (size != 0) { mdec.rl = rl2blk(blk, mdec.rl); - yuv2rgb15(blk, (uint16_t *)mdec.block_buffer); + yuv2rgb15(blk, (uint16_t*)mdec.block_buffer); memcpy(image, mdec.block_buffer, size); mdec.block_buffer_pos = mdec.block_buffer + size; } @@ -598,14 +598,14 @@ void PCSX::MDEC::mdec1Interrupt() { return; } -void PCSX::MDEC::save(PCSX::SaveStates::MDEC & mdecSave) { - uint8_t *base = (uint8_t *)&PCSX::g_emulator.m_psxMem->g_psxM[0x100000]; +void PCSX::MDEC::save(PCSX::SaveStates::MDEC& mdecSave) { + uint8_t* base = (uint8_t*)&PCSX::g_emulator.m_psxMem->g_psxM[0x100000]; uint32_t v; mdecSave.get().value = mdec.reg0; mdecSave.get().value = mdec.reg1; - mdecSave.get().value = reinterpret_cast(mdec.rl) - base; - mdecSave.get().value = reinterpret_cast(mdec.rl_end) - base; + mdecSave.get().value = reinterpret_cast(mdec.rl) - base; + mdecSave.get().value = reinterpret_cast(mdec.rl_end) - base; mdecSave.get().value = mdec.block_buffer_pos ? mdec.block_buffer_pos - base : 0; mdecSave.get().copyFrom(mdec.block_buffer); mdecSave.get().value = mdec.pending_dma1.adr; @@ -617,15 +617,15 @@ void PCSX::MDEC::save(PCSX::SaveStates::MDEC & mdecSave) { } } -void PCSX::MDEC::load(const PCSX::SaveStates::MDEC & mdecSave) { - uint8_t *base = (uint8_t *)&PCSX::g_emulator.m_psxMem->g_psxM[0x100000]; +void PCSX::MDEC::load(const PCSX::SaveStates::MDEC& mdecSave) { + uint8_t* base = (uint8_t*)&PCSX::g_emulator.m_psxMem->g_psxM[0x100000]; uint32_t v; mdec.reg0 = mdecSave.get().value; mdec.reg1 = mdecSave.get().value; mdec.rl = reinterpret_cast(mdecSave.get().value + base); mdec.rl_end = reinterpret_cast(mdecSave.get().value + base); - const auto & pos = mdecSave.get().value; + const auto& pos = mdecSave.get().value; mdec.block_buffer_pos = pos ? pos + base : nullptr; mdecSave.get().copyTo(mdec.block_buffer); mdec.pending_dma1.adr = mdecSave.get().value; diff --git a/src/core/mdec.h b/src/core/mdec.h index aac00c5a0..a4115e40c 100644 --- a/src/core/mdec.h +++ b/src/core/mdec.h @@ -42,8 +42,8 @@ class MDEC { static const unsigned DSIZE = 8; static const unsigned DSIZE2 = DSIZE * DSIZE; - void save(SaveStates::MDEC & mdecSave); - void load(const SaveStates::MDEC & mdecSave); + void save(SaveStates::MDEC& mdecSave); + void load(const SaveStates::MDEC& mdecSave); private: /* memory speed is 1 byte per MDEC_BIAS psx clock @@ -69,9 +69,9 @@ class MDEC { struct { uint32_t reg0; uint32_t reg1; - uint16_t *rl; - uint16_t *rl_end; - uint8_t *block_buffer_pos; + uint16_t* rl; + uint16_t* rl_end; + uint8_t* block_buffer_pos; uint8_t block_buffer[16 * 16 * 3]; struct _pending_dma1 pending_dma1; } mdec; @@ -96,11 +96,11 @@ class MDEC { 289301, 401273, 377991, 340183, 289301, 227303, 156569, 79818 // 38 }; - void putlinebw15(uint16_t *image, int *Yblk); - void putquadrgb15(uint16_t *image, int *Yblk, int Cr, int Cb); - void yuv2rgb15(int *blk, unsigned short *image); - void iqtab_init(int *iqtab, unsigned char *iq_y); - unsigned short *rl2blk(int *blk, unsigned short *mdec_rl); + void putlinebw15(uint16_t* image, int* Yblk); + void putquadrgb15(uint16_t* image, int* Yblk, int Cr, int Cb); + void yuv2rgb15(int* blk, unsigned short* image); + void iqtab_init(int* iqtab, unsigned char* iq_y); + unsigned short* rl2blk(int* blk, unsigned short* mdec_rl); }; } // namespace PCSX diff --git a/src/core/misc.cc b/src/core/misc.cc index 8a1d66e02..ba43e5527 100644 --- a/src/core/misc.cc +++ b/src/core/misc.cc @@ -60,15 +60,15 @@ struct iso_directory_record { }; // local extern -static void trim_key(char *str, char key); -static void split(char *str, char key, char *pout); +static void trim_key(char* str, char key); +static void split(char* str, char key, char* pout); -void mmssdd(char *b, char *p) { +void mmssdd(char* b, char* p) { int m, s, d; #if defined(__BIGENDIAN__) int block = (b[0] & 0xff) | ((b[1] & 0xff) << 8) | ((b[2] & 0xff) << 16) | (b[3] << 24); #else - int block = *((int *)b); + int block = *((int*)b); #endif block += 150; @@ -119,10 +119,10 @@ void mmssdd(char *b, char *p) { READTRACK(); \ memcpy(_dir + 2048, buf + 12, 2048); -int GetCdromFile(uint8_t *mdir, uint8_t *time, const char *filename) { - struct iso_directory_record *dir; +int GetCdromFile(uint8_t* mdir, uint8_t* time, const char* filename) { + struct iso_directory_record* dir; uint8_t ddir[4096]; - uint8_t *buf; + uint8_t* buf; int i; // only try to scan if a filename is given @@ -130,26 +130,26 @@ int GetCdromFile(uint8_t *mdir, uint8_t *time, const char *filename) { i = 0; while (i < 4096) { - dir = (struct iso_directory_record *)&mdir[i]; + dir = (struct iso_directory_record*)&mdir[i]; if (dir->length[0] == 0) { return -1; } i += dir->length[0]; if (dir->flags[0] & 0x2) { // it's a dir - if (!strnicmp((char *)&dir->name[0], filename, dir->name_len[0])) { + if (!strnicmp((char*)&dir->name[0], filename, dir->name_len[0])) { if (filename[dir->name_len[0]] != '\\') continue; filename += dir->name_len[0] + 1; - mmssdd(dir->extent, (char *)time); + mmssdd(dir->extent, (char*)time); READDIR(ddir); i = 0; mdir = ddir; } } else { - if (!strnicmp((char *)&dir->name[0], filename, strlen(filename))) { - mmssdd(dir->extent, (char *)time); + if (!strnicmp((char*)&dir->name[0], filename, strlen(filename))) { + mmssdd(dir->extent, (char*)time); break; } } @@ -159,7 +159,7 @@ int GetCdromFile(uint8_t *mdir, uint8_t *time, const char *filename) { bool LoadCdrom() { EXE_HEADER tmpHead; - struct iso_directory_record *dir; + struct iso_directory_record* dir; uint8_t time[4], *buf; uint8_t mdir[4096]; char exename[256]; @@ -175,9 +175,9 @@ bool LoadCdrom() { READTRACK(); // skip head and sub, and go to the root directory record - dir = (struct iso_directory_record *)&buf[12 + 156]; + dir = (struct iso_directory_record*)&buf[12 + 156]; - mmssdd(dir->extent, (char *)time); + mmssdd(dir->extent, (char*)time); READDIR(mdir); @@ -191,11 +191,11 @@ bool LoadCdrom() { // read the SYSTEM.CNF READTRACK(); - sscanf((char *)buf + 12, "BOOT = cdrom:\\%255s", exename); + sscanf((char*)buf + 12, "BOOT = cdrom:\\%255s", exename); if (GetCdromFile(mdir, time, exename) == -1) { - sscanf((char *)buf + 12, "BOOT = cdrom:%255s", exename); + sscanf((char*)buf + 12, "BOOT = cdrom:%255s", exename); if (GetCdromFile(mdir, time, exename) == -1) { - char *ptr = strstr(reinterpret_cast(buf + 12), "cdrom:"); + char* ptr = strstr(reinterpret_cast(buf + 12), "cdrom:"); if (ptr != NULL) { ptr += 6; while (*ptr == '\\' || *ptr == '/') ptr++; @@ -226,7 +226,7 @@ bool LoadCdrom() { // Read the rest of the main executable while (tmpHead.t_size) { - void *ptr = (void *)PSXM(tmpHead.t_addr); + void* ptr = (void*)PSXM(tmpHead.t_addr); incTime(); READTRACK(); @@ -240,13 +240,13 @@ bool LoadCdrom() { return true; } -bool LoadCdromFile(const char *filename, EXE_HEADER *head) { - struct iso_directory_record *dir; +bool LoadCdromFile(const char* filename, EXE_HEADER* head) { + struct iso_directory_record* dir; uint8_t time[4], *buf; uint8_t mdir[4096]; char exename[256]; uint32_t size, addr; - void *psxaddr; + void* psxaddr; if (sscanf(filename, "cdrom:\\%255s", exename) <= 0) { // Some games omit backslash (NFS4) @@ -263,9 +263,9 @@ bool LoadCdromFile(const char *filename, EXE_HEADER *head) { READTRACK(); // skip head and sub, and go to the root directory record - dir = (struct iso_directory_record *)&buf[12 + 156]; + dir = (struct iso_directory_record*)&buf[12 + 156]; - mmssdd(dir->extent, (char *)time); + mmssdd(dir->extent, (char*)time); READDIR(mdir); @@ -285,7 +285,7 @@ bool LoadCdromFile(const char *filename, EXE_HEADER *head) { incTime(); READTRACK(); - psxaddr = (void *)PSXM(addr); + psxaddr = (void*)PSXM(addr); assert(psxaddr != NULL); memcpy(psxaddr, buf + 12, 2048); @@ -297,9 +297,9 @@ bool LoadCdromFile(const char *filename, EXE_HEADER *head) { } bool CheckCdrom() { - struct iso_directory_record *dir; + struct iso_directory_record* dir; unsigned char time[4]; - unsigned char *buf; + unsigned char* buf; unsigned char mdir[4096]; char exename[256]; int i, len, c; @@ -316,24 +316,24 @@ bool CheckCdrom() { memset(PCSX::g_emulator.m_cdromId, 0, sizeof(PCSX::g_emulator.m_cdromId)); memset(exename, 0, sizeof(exename)); - strncpy(PCSX::g_emulator.m_cdromLabel, reinterpret_cast(buf + 52), 32); + strncpy(PCSX::g_emulator.m_cdromLabel, reinterpret_cast(buf + 52), 32); // skip head and sub, and go to the root directory record - dir = (struct iso_directory_record *)&buf[12 + 156]; + dir = (struct iso_directory_record*)&buf[12 + 156]; - mmssdd(dir->extent, (char *)time); + mmssdd(dir->extent, (char*)time); READDIR(mdir); if (GetCdromFile(mdir, time, "SYSTEM.CNF;1") != -1) { READTRACK(); - sscanf((char *)buf + 12, "BOOT = cdrom:\\%255s", exename); + sscanf((char*)buf + 12, "BOOT = cdrom:\\%255s", exename); if (GetCdromFile(mdir, time, exename) == -1) { - sscanf((char *)buf + 12, "BOOT = cdrom:%255s", exename); + sscanf((char*)buf + 12, "BOOT = cdrom:%255s", exename); if (GetCdromFile(mdir, time, exename) == -1) { - char *ptr = - strstr(reinterpret_cast(buf + 12), "cdrom:"); // possibly the executable is in some subdir + char* ptr = + strstr(reinterpret_cast(buf + 12), "cdrom:"); // possibly the executable is in some subdir if (ptr != NULL) { ptr += 6; while (*ptr == '\\' || *ptr == '/') ptr++; @@ -407,11 +407,11 @@ bool CheckCdrom() { return true; } -static int PSXGetFileType(FILE *f) { +static int PSXGetFileType(FILE* f) { unsigned long current; uint8_t mybuf[sizeof(EXE_HEADER)]; // EXE_HEADER currently biggest - EXE_HEADER *exe_hdr; - FILHDR *coff_hdr; + EXE_HEADER* exe_hdr; + FILHDR* coff_hdr; size_t amt; memset(mybuf, 0, sizeof(mybuf)); @@ -420,12 +420,12 @@ static int PSXGetFileType(FILE *f) { amt = fread(mybuf, sizeof(mybuf), 1, f); fseek(f, current, SEEK_SET); - exe_hdr = (EXE_HEADER *)mybuf; + exe_hdr = (EXE_HEADER*)mybuf; if (memcmp(exe_hdr->id, "PS-X EXE", 8) == 0) return PSX_EXE; if (mybuf[0] == 'C' && mybuf[1] == 'P' && mybuf[2] == 'E') return CPE_EXE; - coff_hdr = (FILHDR *)mybuf; + coff_hdr = (FILHDR*)mybuf; if (SWAP_LEu16(coff_hdr->f_magic) == 0x0162) return COFF_EXE; return INVALID_EXE; @@ -433,7 +433,7 @@ static int PSXGetFileType(FILE *f) { static void LoadLibPS() { char buf[MAXPATHLEN]; - FILE *f; + FILE* f; // Load Net Yaroze runtime library (if exists) sprintf(buf, "%s/libps.exe", @@ -447,8 +447,8 @@ static void LoadLibPS() { } } -int Load(const char *ExePath) { - FILE *tmpFile; +int Load(const char* ExePath) { + FILE* tmpFile; EXE_HEADER tmpHead; FILHDR coffHead; AOUTHDR optHead; @@ -457,7 +457,7 @@ int Load(const char *ExePath) { int retval = 0; uint8_t opcode; uint32_t section_address, section_size; - void *psxmaddr; + void* psxmaddr; strncpy(PCSX::g_emulator.m_cdromId, "SLUS99999", 9); strncpy(PCSX::g_emulator.m_cdromLabel, "SLUS_999.99", 11); @@ -552,10 +552,10 @@ int Load(const char *ExePath) { return retval; } -static int LoadBin(unsigned long addr, char *filename) { +static int LoadBin(unsigned long addr, char* filename) { int result = -1; - FILE *f; + FILE* f; long len; unsigned long mem = addr & 0x001fffff; @@ -582,8 +582,8 @@ static int LoadBin(unsigned long addr, char *filename) { return result; } -int LoadLdrFile(const char *LdrPath) { - FILE *tmpFile; +int LoadLdrFile(const char* LdrPath) { + FILE* tmpFile; int retval = 0; //-1 is error, 0 is success tmpFile = fopen(LdrPath, "rt"); @@ -599,9 +599,9 @@ int LoadLdrFile(const char *LdrPath) { while (index <= 15 && fgets(&sztext[index][0], 254, tmpFile)) { char szaddr[256]; char szpath[256]; - char *psrc = &sztext[index][0]; - char *paddr; - char *ppath; + char* psrc = &sztext[index][0]; + char* paddr; + char* ppath; int len; unsigned long addr = 0L; @@ -692,11 +692,11 @@ int RecvPcsxInfo() { } // remove the leading and trailing spaces in a string -void trim(char *str) { trim_key(str, ' '); } +void trim(char* str) { trim_key(str, ' '); } -static void trim_key(char *str, char key) { +static void trim_key(char* str, char key) { int pos = 0; - char *dest = str; + char* dest = str; // skip leading blanks while (str[pos] <= key && str[pos] > 0) pos++; @@ -713,9 +713,9 @@ static void trim_key(char *str, char key) { } // split by the keys codes in strings -static void split(char *str, char key, char *pout) { - char *psrc = str; - char *pdst = pout; +static void split(char* str, char key, char* pout) { + char* psrc = str; + char* pdst = pout; int len = strlen(str); int i; for (i = 0; i < len; i++) { @@ -764,7 +764,7 @@ static unsigned short crctab[256] = { 0x6E17, 0x7E36, 0x4E55, 0x5E74, 0x2E93, 0x3EB2, 0x0ED1, 0x1EF0, // f8 }; -uint16_t calcCrc(uint8_t *d, int len) { +uint16_t calcCrc(uint8_t* d, int len) { uint16_t crc = 0; int i; diff --git a/src/core/misc.h b/src/core/misc.h index 1ba0dd09d..b9df0eb51 100644 --- a/src/core/misc.h +++ b/src/core/misc.h @@ -45,13 +45,13 @@ typedef struct { } EXE_HEADER; bool LoadCdrom(); -bool LoadCdromFile(const char *filename, EXE_HEADER *head); +bool LoadCdromFile(const char* filename, EXE_HEADER* head); bool CheckCdrom(); -int Load(const char *ExePath); -int LoadLdrFile(const char *LdrPath); +int Load(const char* ExePath); +int LoadLdrFile(const char* LdrPath); int SendPcsxInfo(); int RecvPcsxInfo(); -void trim(char *str); -uint16_t calcCrc(uint8_t *d, int len); +void trim(char* str); +uint16_t calcCrc(uint8_t* d, int len); diff --git a/src/core/pad.h b/src/core/pad.h index 6647c3bd4..642eefa2b 100644 --- a/src/core/pad.h +++ b/src/core/pad.h @@ -37,8 +37,8 @@ class PAD { unsigned char poll(unsigned char); private: - void readPort(PadDataS *pad); - unsigned char startPoll(PadDataS *pad); + void readPort(PadDataS* pad); + unsigned char startPoll(PadDataS* pad); uint16_t getButtons(); pad_t m_padIdx = PAD1; @@ -47,7 +47,7 @@ class PAD { bool m_isKeyboard = false; int m_joystick = -1; int m_scancodes[16]; - SDL_GameController *m_pad = NULL; + SDL_GameController* m_pad = NULL; unsigned char m_buf[256]; unsigned char m_stdpar[10] = {0x00, 0x41, 0x5a, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff}; diff --git a/src/core/pgxp_value.cc b/src/core/pgxp_value.cc index 431fb73dc..3387ffaa2 100644 --- a/src/core/pgxp_value.cc +++ b/src/core/pgxp_value.cc @@ -2,7 +2,7 @@ #include "core/pgxp_value.h" -void SetValue(PGXP_value *pV, uint32_t psxV) { +void SetValue(PGXP_value* pV, uint32_t psxV) { psx_value psx; psx.d = psxV; @@ -13,7 +13,7 @@ void SetValue(PGXP_value *pV, uint32_t psxV) { pV->value = psx.d; } -void MakeValid(PGXP_value *pV, uint32_t psxV) { +void MakeValid(PGXP_value* pV, uint32_t psxV) { psx_value psx; psx.d = psxV; if (VALID_01 != (pV->flags & VALID_01)) { @@ -25,17 +25,17 @@ void MakeValid(PGXP_value *pV, uint32_t psxV) { } } -void Validate(PGXP_value *pV, uint32_t psxV) { +void Validate(PGXP_value* pV, uint32_t psxV) { // assume pV is not NULL pV->flags &= (pV->value == psxV) ? ALL : INV_VALID_ALL; } -void MaskValidate(PGXP_value *pV, uint32_t psxV, uint32_t mask, uint32_t validMask) { +void MaskValidate(PGXP_value* pV, uint32_t psxV, uint32_t mask, uint32_t validMask) { // assume pV is not NULL pV->flags &= ((pV->value & mask) == (psxV & mask)) ? ALL : (ALL ^ (validMask)); } -uint32_t ValueToTolerance(PGXP_value *pV, uint32_t psxV, float tolerance) { +uint32_t ValueToTolerance(PGXP_value* pV, uint32_t psxV, float tolerance) { psx_value psx; psx.d = psxV; uint32_t retFlags = VALID_ALL; @@ -51,7 +51,7 @@ uint32_t ValueToTolerance(PGXP_value *pV, uint32_t psxV, float tolerance) { double f16Sign(double in) { uint32_t s = in * (double)((uint32_t)1 << 16); - return ((double)*((int32_t *)&s)) / (double)((int32_t)1 << 16); + return ((double)*((int32_t*)&s)) / (double)((int32_t)1 << 16); } double f16Unsign(double in) { return (in >= 0) ? in : ((double)in + (double)USHRT_MAX + 1); } double fu16Trunc(double in) { diff --git a/src/core/pgxp_value.h b/src/core/pgxp_value.h index 13d04e508..47d337dc9 100644 --- a/src/core/pgxp_value.h +++ b/src/core/pgxp_value.h @@ -109,11 +109,11 @@ typedef enum { VALID_HALF = (1 << 0) } PGXP_half_flags; static const PGXP_value PGXP_value_invalid_address = {0.f, 0.f, 0.f, 0, 0, 0, INVALID_ADDRESS, 0, 0}; static const PGXP_value PGXP_value_zero = {0.f, 0.f, 0.f, 0, 0, VALID_ALL, 0, 0, 0}; -void SetValue(PGXP_value *pV, uint32_t psxV); -void MakeValid(PGXP_value *pV, uint32_t psxV); -void Validate(PGXP_value *pV, uint32_t psxV); -void MaskValidate(PGXP_value *pV, uint32_t psxV, uint32_t mask, uint32_t validMask); -uint32_t ValueToTolerance(PGXP_value *pV, uint32_t psxV, float tolerance); +void SetValue(PGXP_value* pV, uint32_t psxV); +void MakeValid(PGXP_value* pV, uint32_t psxV); +void Validate(PGXP_value* pV, uint32_t psxV); +void MaskValidate(PGXP_value* pV, uint32_t psxV, uint32_t mask, uint32_t validMask); +uint32_t ValueToTolerance(PGXP_value* pV, uint32_t psxV, float tolerance); double f16Sign(double in); double f16Unsign(double in); diff --git a/src/core/plugins.cc b/src/core/plugins.cc index 1ff88b50f..4d2593a3d 100644 --- a/src/core/plugins.cc +++ b/src/core/plugins.cc @@ -221,7 +221,7 @@ SIO1registerCallback SIO1_registerCallback; #endif -static const char *err; +static const char* err; #define CheckErr(func) \ { \ @@ -598,7 +598,7 @@ void SIO1__registerCallback(void (*callback)(void)){}; LoadSym(SIO1_##dest, SIO1##dest, name, false); \ if (SIO1_##dest == NULL) SIO1_##dest = (SIO1##dest)SIO1__##dest; -static int LoadSIO1plugin(const char *SIO1dll) { +static int LoadSIO1plugin(const char* SIO1dll) { LoadSio1Sym0(init, "SIO1init"); LoadSio1Sym0(shutdown, "SIO1shutdown"); LoadSio1Sym0(open, "SIO1open"); @@ -686,7 +686,7 @@ void ReleasePlugins() { #endif } -void SetIsoFile(const char *filename) { +void SetIsoFile(const char* filename) { if (filename == NULL) { IsoFile[0] = '\0'; return; @@ -694,7 +694,7 @@ void SetIsoFile(const char *filename) { strncpy(IsoFile, filename, MAXPATHLEN); } -void SetExeFile(const char *filename) { +void SetExeFile(const char* filename) { if (filename == NULL) { ExeFile[0] = '\0'; return; @@ -703,7 +703,7 @@ void SetExeFile(const char *filename) { } // Set pcsxr.exe directory. This is not contain filename(and ext)). -void SetAppPath(const char *apppath) { +void SetAppPath(const char* apppath) { if (apppath == NULL) { AppPath[0] = '\0'; return; @@ -711,7 +711,7 @@ void SetAppPath(const char *apppath) { strncpy(AppPath, apppath, MAXPATHLEN); } -void SetLdrFile(const char *ldrfile) { +void SetLdrFile(const char* ldrfile) { if (ldrfile == NULL) { LdrFile[0] = '\0'; return; @@ -719,10 +719,10 @@ void SetLdrFile(const char *ldrfile) { strncpy(LdrFile, ldrfile, MAXPATHLEN); } -const char *GetIsoFile(void) { return IsoFile; } +const char* GetIsoFile(void) { return IsoFile; } -const char *GetExeFile(void) { return ExeFile; } +const char* GetExeFile(void) { return ExeFile; } -const char *GetAppPath(void) { return AppPath; } +const char* GetAppPath(void) { return AppPath; } -const char *GetLdrFile(void) { return LdrFile; } +const char* GetLdrFile(void) { return LdrFile; } diff --git a/src/core/ppf.cc b/src/core/ppf.cc index 09cd5a4db..6a76c8e84 100644 --- a/src/core/ppf.cc +++ b/src/core/ppf.cc @@ -26,8 +26,8 @@ // using a linked data list, and address array void PCSX::PPF::FillPPFCache() { - PPF_DATA *p; - PPF_CACHE *pc; + PPF_DATA* p; + PPF_CACHE* pc; int32_t lastaddr; p = s_ppfHead; @@ -42,7 +42,7 @@ void PCSX::PPF::FillPPFCache() { if (s_iPPFNum <= 0) return; - pc = s_ppfCache = (PPF_CACHE *)malloc(s_iPPFNum * sizeof(PPF_CACHE)); + pc = s_ppfCache = (PPF_CACHE*)malloc(s_iPPFNum * sizeof(PPF_CACHE)); s_iPPFNum--; p = s_ppfHead; @@ -60,13 +60,13 @@ void PCSX::PPF::FillPPFCache() { } void PCSX::PPF::FreePPFCache() { - PPF_DATA *p = s_ppfHead; - void *pn; + PPF_DATA* p = s_ppfHead; + void* pn; while (p != NULL) { pn = p->pNext; free(p); - p = (PPF_DATA *)pn; + p = (PPF_DATA*)pn; } s_ppfHead = NULL; s_ppfLast = NULL; @@ -75,7 +75,7 @@ void PCSX::PPF::FreePPFCache() { s_ppfCache = NULL; } -void PCSX::PPF::CheckPPFCache(uint8_t *pB, uint8_t m, uint8_t s, uint8_t f) { +void PCSX::PPF::CheckPPFCache(uint8_t* pB, uint8_t m, uint8_t s, uint8_t f) { PPF_CACHE *pcstart, *pcend, *pcpos; int addr = PCSX::CDRom::MSF2SECT(PCSX::CDRom::btoi(m), PCSX::CDRom::btoi(s), PCSX::CDRom::btoi(f)), pos, anz, start; @@ -106,7 +106,7 @@ void PCSX::PPF::CheckPPFCache(uint8_t *pB, uint8_t m, uint8_t s, uint8_t f) { } if (addr == pcpos->addr) { - PPF_DATA *p = pcpos->pNext; + PPF_DATA* p = pcpos->pNext; while (p != NULL && p->addr == addr) { pos = p->pos - (PCSX::CDRom::CD_FRAMESIZE_RAW - PCSX::CDRom::DATA_SIZE); anz = p->anz; @@ -116,15 +116,15 @@ void PCSX::PPF::CheckPPFCache(uint8_t *pB, uint8_t m, uint8_t s, uint8_t f) { anz -= start; } else start = 0; - memcpy(pB + pos, (unsigned char *)(p + 1) + start, anz); + memcpy(pB + pos, (unsigned char*)(p + 1) + start, anz); p = p->pNext; } } } -void PCSX::PPF::AddToPPF(int32_t ladr, int32_t pos, int32_t anz, uint8_t *ppfmem) { +void PCSX::PPF::AddToPPF(int32_t ladr, int32_t pos, int32_t anz, uint8_t* ppfmem) { if (s_ppfHead == NULL) { - s_ppfHead = (PPF_DATA *)malloc(sizeof(PPF_DATA) + anz); + s_ppfHead = (PPF_DATA*)malloc(sizeof(PPF_DATA) + anz); s_ppfHead->addr = ladr; s_ppfHead->pNext = NULL; s_ppfHead->pos = pos; @@ -133,9 +133,9 @@ void PCSX::PPF::AddToPPF(int32_t ladr, int32_t pos, int32_t anz, uint8_t *ppfmem s_iPPFNum = 1; s_ppfLast = s_ppfHead; } else { - PPF_DATA *p = s_ppfHead; - PPF_DATA *plast = NULL; - PPF_DATA *padd; + PPF_DATA* p = s_ppfHead; + PPF_DATA* plast = NULL; + PPF_DATA* padd; if (ladr > s_ppfLast->addr || (ladr == s_ppfLast->addr && pos > s_ppfLast->pos)) { p = NULL; @@ -155,7 +155,7 @@ void PCSX::PPF::AddToPPF(int32_t ladr, int32_t pos, int32_t anz, uint8_t *ppfmem } } - padd = (PPF_DATA *)malloc(sizeof(PPF_DATA) + anz); + padd = (PPF_DATA*)malloc(sizeof(PPF_DATA) + anz); padd->addr = ladr; padd->pNext = p; padd->pos = pos; @@ -172,7 +172,7 @@ void PCSX::PPF::AddToPPF(int32_t ladr, int32_t pos, int32_t anz, uint8_t *ppfmem } void PCSX::PPF::BuildPPFCache() { - FILE *ppffile; + FILE* ppffile; char buffer[12]; char method, undo = 0, blockcheck = 0; int dizlen = 0, dizyn; diff --git a/src/core/ppf.h b/src/core/ppf.h index 99a23a7db..aa0bcd894 100644 --- a/src/core/ppf.h +++ b/src/core/ppf.h @@ -26,27 +26,27 @@ class PPF { public: void BuildPPFCache(); void FreePPFCache(); - void CheckPPFCache(uint8_t *pB, uint8_t m, uint8_t s, uint8_t f); + void CheckPPFCache(uint8_t* pB, uint8_t m, uint8_t s, uint8_t f); private: struct PPF_DATA { int32_t addr; int32_t pos; int32_t anz; - struct PPF_DATA *pNext; + struct PPF_DATA* pNext; }; struct PPF_CACHE { int32_t addr; - struct PPF_DATA *pNext; + struct PPF_DATA* pNext; }; - PPF_CACHE *s_ppfCache = nullptr; + PPF_CACHE* s_ppfCache = nullptr; PPF_DATA *s_ppfHead = nullptr, *s_ppfLast = nullptr; int s_iPPFNum = 0; void FillPPFCache(); - void AddToPPF(int32_t ladr, int32_t pos, int32_t anz, uint8_t *ppfmem); + void AddToPPF(int32_t ladr, int32_t pos, int32_t anz, uint8_t* ppfmem); }; } // namespace PCSX diff --git a/src/core/protobuf.h b/src/core/protobuf.h index 7f718bb3a..45fb19771 100644 --- a/src/core/protobuf.h +++ b/src/core/protobuf.h @@ -41,7 +41,7 @@ namespace Protobuf { class InSlice { public: constexpr uint64_t bytesLeft() { return m_size - m_ptr; } - InSlice(const uint8_t *data, uint64_t size) : m_data(data), m_size(size) {} + InSlice(const uint8_t* data, uint64_t size) : m_data(data), m_size(size) {} InSlice getSubSlice(uint64_t size) { boundsCheck(size); m_ptr += size; @@ -79,9 +79,9 @@ class InSlice { } std::string getBytes(uint64_t size) { skipBytes(size); - return std::string(reinterpret_cast(m_data + m_ptr - size), size); + return std::string(reinterpret_cast(m_data + m_ptr - size), size); } - void getBytes(uint8_t *data, uint64_t size) { + void getBytes(uint8_t* data, uint64_t size) { skipBytes(size); memcpy(data, m_data + m_ptr - size, size); } @@ -102,7 +102,7 @@ class InSlice { } private: - const uint8_t *m_data; + const uint8_t* m_data; const uint64_t m_size; uint64_t m_ptr = 0; @@ -115,7 +115,7 @@ class InSlice { class OutSlice { public: - void putU8(uint8_t value) { m_data += std::string(reinterpret_cast(&value), 1); } + void putU8(uint8_t value) { m_data += std::string(reinterpret_cast(&value), 1); } void putU16(uint16_t value) { putU8(value & 0xff); value >>= 8; @@ -131,11 +131,11 @@ class OutSlice { value >>= 32; putU32(value & 0xffffffff); } - void putBytes(const uint8_t *bytes, uint64_t size) { - m_data += std::string(reinterpret_cast(bytes), size); + void putBytes(const uint8_t* bytes, uint64_t size) { + m_data += std::string(reinterpret_cast(bytes), size); } - void putBytes(const std::string &str) { m_data += str; } - void putSlice(OutSlice *slice) { m_data += slice->m_data; } + void putBytes(const std::string& str) { m_data += str; } + void putSlice(OutSlice* slice) { m_data += slice->m_data; } void putVarInt(uint64_t value) { uint8_t b = 0; do { @@ -154,8 +154,8 @@ template struct FieldType { typedef innerType type; FieldType() {} - FieldType(const type &init) : value(init) {} - FieldType(type &&init) : value(init) {} + FieldType(const type& init) : value(init) {} + FieldType(type&& init) : value(init) {} type value = innerType(); void reset() { value = type(); } static constexpr unsigned wireType = wireTypeValue; @@ -173,57 +173,57 @@ struct Int8 : public FieldType { struct Int16 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putVarInt(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = static_cast(slice->getVarInt()); } + void serialize(OutSlice* slice) const { slice->putVarInt(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = static_cast(slice->getVarInt()); } static constexpr char const typeName[] = "int32"; }; struct Int32 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putVarInt(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = static_cast(slice->getVarInt()); } + void serialize(OutSlice* slice) const { slice->putVarInt(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = static_cast(slice->getVarInt()); } static constexpr char const typeName[] = "int32"; }; struct Int64 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putVarInt(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = slice->getVarInt(); } + void serialize(OutSlice* slice) const { slice->putVarInt(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = slice->getVarInt(); } static constexpr char const typeName[] = "int64"; }; struct UInt8 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putVarInt(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = static_cast(slice->getVarInt()); } + void serialize(OutSlice* slice) const { slice->putVarInt(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = static_cast(slice->getVarInt()); } static constexpr char const typeName[] = "uint32"; }; struct UInt16 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putVarInt(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = static_cast(slice->getVarInt()); } + void serialize(OutSlice* slice) const { slice->putVarInt(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = static_cast(slice->getVarInt()); } static constexpr char const typeName[] = "uint32"; }; struct UInt32 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putVarInt(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = static_cast(slice->getVarInt()); } + void serialize(OutSlice* slice) const { slice->putVarInt(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = static_cast(slice->getVarInt()); } static constexpr char const typeName[] = "uint32"; }; struct UInt64 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putVarInt(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = slice->getVarInt(); } + void serialize(OutSlice* slice) const { slice->putVarInt(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = slice->getVarInt(); } static constexpr char const typeName[] = "uint64"; }; struct SInt32 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putVarInt((value << 1) ^ (value >> 31)); } - constexpr void deserialize(InSlice *slice, unsigned) { + void serialize(OutSlice* slice) const { slice->putVarInt((value << 1) ^ (value >> 31)); } + constexpr void deserialize(InSlice* slice, unsigned) { value = static_cast(slice->getVarInt()); value = (value >> 1) ^ -(value & 1); } @@ -232,8 +232,8 @@ struct SInt32 : public FieldType { struct SInt64 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putVarInt((value << 1) ^ (value >> 63)); } - constexpr void deserialize(InSlice *slice, unsigned) { + void serialize(OutSlice* slice) const { slice->putVarInt((value << 1) ^ (value >> 63)); } + constexpr void deserialize(InSlice* slice, unsigned) { value = slice->getVarInt(); value = (value >> 1) ^ -(value & 1); } @@ -242,35 +242,35 @@ struct SInt64 : public FieldType { struct Bool : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putVarInt(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = slice->getVarInt(); } + void serialize(OutSlice* slice) const { slice->putVarInt(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = slice->getVarInt(); } static constexpr char const typeName[] = "bool"; }; struct Fixed64 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putU64(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = slice->getU64(); } + void serialize(OutSlice* slice) const { slice->putU64(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = slice->getU64(); } static constexpr char const typeName[] = "fixed64"; }; struct SFixed64 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putU64(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = slice->getU64(); } + void serialize(OutSlice* slice) const { slice->putU64(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = slice->getU64(); } static constexpr char const typeName[] = "sfixed64"; }; struct Double : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { + void serialize(OutSlice* slice) const { union { double d; uint64_t v; } u = {value}; slice->putU64(u.v); } - constexpr void deserialize(InSlice *slice, unsigned) { + constexpr void deserialize(InSlice* slice, unsigned) { union { uint64_t v; double d; @@ -282,21 +282,21 @@ struct Double : public FieldType { struct String : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { + void serialize(OutSlice* slice) const { slice->putVarInt(value.size()); slice->putBytes(value); } - void deserialize(InSlice *slice, unsigned) { value = slice->getBytes(slice->getVarInt()); } + void deserialize(InSlice* slice, unsigned) { value = slice->getBytes(slice->getVarInt()); } static constexpr char const typeName[] = "string"; }; struct Bytes : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { + void serialize(OutSlice* slice) const { slice->putVarInt(value.size()); slice->putBytes(value); } - void deserialize(InSlice *slice, unsigned) { value = slice->getBytes(slice->getVarInt()); } + void deserialize(InSlice* slice, unsigned) { value = slice->getBytes(slice->getVarInt()); } static constexpr char const typeName[] = "bytes"; }; @@ -304,40 +304,40 @@ template struct FixedBytes { ~FixedBytes() { delete[] value; } FixedBytes() {} - FixedBytes(const FixedBytes &s) { + FixedBytes(const FixedBytes& s) { delete[] value; value = nullptr; if (!s.value) return; allocate(); memcpy(value, s.value, amount); } - FixedBytes(FixedBytes &&s) { + FixedBytes(FixedBytes&& s) { if (!s.value) return; value = s.value; s.value = nullptr; } static constexpr bool needsToSerializeHeader() { return false; } - constexpr void serialize(OutSlice *slice) const { + constexpr void serialize(OutSlice* slice) const { slice->putVarInt(amount); slice->putBytes(value, amount); } - constexpr void deserialize(InSlice *slice, unsigned) { + constexpr void deserialize(InSlice* slice, unsigned) { uint64_t size = slice->getVarInt(); if (size > amount) throw OutOfBoundError(); allocate(); slice->getBytes(value, size); } static constexpr char const typeName[] = "bytes"; - uint8_t *value = nullptr; + uint8_t* value = nullptr; constexpr void allocate() { if (!value) value = new uint8_t[amount]; } - void copyFrom(const uint8_t *src) { + void copyFrom(const uint8_t* src) { allocate(); memcpy(value, src, amount); } - constexpr void copyTo(uint8_t *dst) const { memcpy(dst, value, amount); } - typedef uint8_t *type; + constexpr void copyTo(uint8_t* dst) const { memcpy(dst, value, amount); } + typedef uint8_t* type; constexpr void reset() { allocate(); memset(value, 0, amount); @@ -349,28 +349,28 @@ struct FixedBytes { struct Fixed32 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putU32(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = slice->getU32(); } + void serialize(OutSlice* slice) const { slice->putU32(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = slice->getU32(); } static constexpr char const typeName[] = "fixed32"; }; struct SFixed32 : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { slice->putU32(value); } - constexpr void deserialize(InSlice *slice, unsigned) { value = slice->getU32(); } + void serialize(OutSlice* slice) const { slice->putU32(value); } + constexpr void deserialize(InSlice* slice, unsigned) { value = slice->getU32(); } static constexpr char const typeName[] = "sfixed32"; }; struct Float : public FieldType { static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { + void serialize(OutSlice* slice) const { union { float f; uint32_t v; } u = {value}; slice->putU32(u.v); } - constexpr void deserialize(InSlice *slice, unsigned) { + constexpr void deserialize(InSlice* slice, unsigned) { union { uint64_t v; float f; @@ -394,7 +394,7 @@ struct Field, fieldNumberValue> : public Fiel Field(type init) { FieldType::value = init; } static constexpr uint64_t fieldNumber = fieldNumberValue; typedef irqus::typestring fieldName; - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { stream << " " << FieldType::typeName << " " << fieldName::data() << " = " << fieldNumberValue << ";" << std::endl; } @@ -409,33 +409,33 @@ struct FieldRef, fieldNumberValue> { using type = typename FieldType::type; public: - FieldRef(type &dest) : ref(dest) {} + FieldRef(type& dest) : ref(dest) {} static constexpr uint64_t fieldNumber = fieldNumberValue; typedef irqus::typestring fieldName; - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { stream << " " << FieldType::typeName << " " << fieldName::data() << " = " << fieldNumberValue << ";" << std::endl; } static constexpr bool needsToSerializeHeader() { return false; } - constexpr void serialize(OutSlice *slice) const { - const FieldType *field = reinterpret_cast(&ref); + constexpr void serialize(OutSlice* slice) const { + const FieldType* field = reinterpret_cast(&ref); field->serialize(slice); } - constexpr void deserialize(InSlice *slice, unsigned wireType) { - FieldType *field = reinterpret_cast(©); + constexpr void deserialize(InSlice* slice, unsigned wireType) { + FieldType* field = reinterpret_cast(©); field->deserialize(slice, wireType); } constexpr void reset() {} constexpr void commit() { ref = copy; } constexpr bool hasData() const { - const FieldType *field = reinterpret_cast(&ref); + const FieldType* field = reinterpret_cast(&ref); return field->hasData(); } static constexpr bool matches(unsigned wireType) { return FieldType::matches(wireType); } static constexpr unsigned wireType = FieldType::wireType; private: - type &ref; + type& ref; type copy = type(); }; @@ -447,26 +447,26 @@ struct FieldPtr, fieldNumberValue> { using type = typename FieldType::type; public: - FieldPtr(const type &dest) : ref(dest) {} + FieldPtr(const type& dest) : ref(dest) {} static constexpr uint64_t fieldNumber = fieldNumberValue; typedef irqus::typestring fieldName; - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { stream << " " << FieldType::typeName << " " << fieldName::data() << " = " << fieldNumberValue << ";" << std::endl; } static constexpr bool needsToSerializeHeader() { return false; } - constexpr void serialize(OutSlice *slice) const { - const FieldType *field = reinterpret_cast(&ref); + constexpr void serialize(OutSlice* slice) const { + const FieldType* field = reinterpret_cast(&ref); field->serialize(slice); } - constexpr void deserialize(InSlice *slice, unsigned wireType) { copy.deserialize(slice, wireType); } + constexpr void deserialize(InSlice* slice, unsigned wireType) { copy.deserialize(slice, wireType); } constexpr void reset() {} constexpr void commit() { - FieldType *field = reinterpret_cast(&ref); + FieldType* field = reinterpret_cast(&ref); field->copyFrom(copy.value); } constexpr bool hasData() const { - const FieldType *field = reinterpret_cast(&ref); + const FieldType* field = reinterpret_cast(&ref); return field->hasData(); } static constexpr bool matches(unsigned wireType) { return FieldType::matches(wireType); } @@ -485,7 +485,7 @@ struct RepeatedField, fieldNumberValu static constexpr uint64_t fieldNumber = fieldNumberValue; static constexpr unsigned wireType = 2; typedef irqus::typestring fieldName; - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { stream << " repeated " << FieldType::typeName << " " << fieldName::data() << " = " << fieldNumberValue << ";" << std::endl; } @@ -498,9 +498,9 @@ struct RepeatedField, fieldNumberValu } static constexpr bool matches(unsigned wireType) { return wireType == 2 || FieldType::matches(wireType); } static constexpr bool needsToSerializeHeader() { return FieldType::wireType == 2; } - void serialize(OutSlice *slice) const { + void serialize(OutSlice* slice) const { if (FieldType::wireType == 2) { - for (const auto &v : value) { + for (const auto& v : value) { OutSlice subSlice; v.serialize(&subSlice); std::string subSliceData = subSlice.finalize(); @@ -510,7 +510,7 @@ struct RepeatedField, fieldNumberValu } } else { OutSlice subSlice; - for (const auto &v : value) { + for (const auto& v : value) { v.serialize(&subSlice); } std::string subSliceData = subSlice.finalize(); @@ -518,7 +518,7 @@ struct RepeatedField, fieldNumberValu slice->putBytes(subSliceData); } } - void deserialize(InSlice *slice, unsigned wireType) { + void deserialize(InSlice* slice, unsigned wireType) { if (FieldType::wireType != wireType) { InSlice subSlice = slice->getSubSlice(slice->getVarInt()); while (subSlice.bytesLeft()) { @@ -532,7 +532,7 @@ struct RepeatedField, fieldNumberValu constexpr void commit() {} private: - void deserializeOne(InSlice *slice, unsigned wireType) { + void deserializeOne(InSlice* slice, unsigned wireType) { if (count >= amount) throw OutOfBoundError(); if (FieldType::wireType == 2) { InSlice subSlice = slice->getSubSlice(slice->getVarInt()); @@ -548,17 +548,17 @@ struct RepeatedFieldRef; template struct RepeatedFieldRef, fieldNumberValue> { using innerType = typename FieldType::type; - RepeatedFieldRef(const RepeatedFieldRef &s) : ref(s.ref), count(s.count) {} - RepeatedFieldRef(RepeatedFieldRef &&s) : ref(s.ref), count(s.count) {} - RepeatedFieldRef(innerType *init) : ref(init) {} + RepeatedFieldRef(const RepeatedFieldRef& s) : ref(s.ref), count(s.count) {} + RepeatedFieldRef(RepeatedFieldRef&& s) : ref(s.ref), count(s.count) {} + RepeatedFieldRef(innerType* init) : ref(init) {} static constexpr uint64_t fieldNumber = fieldNumberValue; static constexpr unsigned wireType = 2; typedef irqus::typestring fieldName; - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { stream << " repeated " << FieldType::typeName << " " << fieldName::data() << " = " << fieldNumberValue << ";" << std::endl; } - innerType *ref; + innerType* ref; innerType copy[amount]; size_t count = 0; constexpr void reset() { @@ -567,11 +567,11 @@ struct RepeatedFieldRef, fieldNumberV } static constexpr bool matches(unsigned wireType) { return wireType == 2 || FieldType::matches(wireType); } static constexpr bool needsToSerializeHeader() { return FieldType::wireType == 2; } - void serialize(OutSlice *slice) const { + void serialize(OutSlice* slice) const { if (FieldType::wireType == 2) { for (size_t i = 0; i < amount; i++) { OutSlice subSlice; - FieldType *field = reinterpret_cast(ref + i); + FieldType* field = reinterpret_cast(ref + i); field->serialize(&subSlice); std::string subSliceData = subSlice.finalize(); slice->putVarInt((fieldNumber << 3) | FieldType::wireType); @@ -581,7 +581,7 @@ struct RepeatedFieldRef, fieldNumberV } else { OutSlice subSlice; for (size_t i = 0; i < amount; i++) { - FieldType *field = reinterpret_cast(ref + i); + FieldType* field = reinterpret_cast(ref + i); field->serialize(&subSlice); } std::string subSliceData = subSlice.finalize(); @@ -589,7 +589,7 @@ struct RepeatedFieldRef, fieldNumberV slice->putBytes(subSliceData); } } - void deserialize(InSlice *slice, unsigned wireType) { + void deserialize(InSlice* slice, unsigned wireType) { if (FieldType::wireType != wireType) { InSlice subSlice = slice->getSubSlice(slice->getVarInt()); while (subSlice.bytesLeft()) { @@ -603,9 +603,9 @@ struct RepeatedFieldRef, fieldNumberV constexpr void commit() { memcpy(ref, copy, amount * sizeof(innerType)); } private: - void deserializeOne(InSlice *slice, unsigned wireType) { + void deserializeOne(InSlice* slice, unsigned wireType) { if (count >= amount) throw OutOfBoundError(); - FieldType *field = reinterpret_cast(copy + count++); + FieldType* field = reinterpret_cast(copy + count++); if (FieldType::wireType == 2) { InSlice subSlice = slice->getSubSlice(slice->getVarInt()); field->deserialize(&subSlice, FieldType::wireType); @@ -620,29 +620,29 @@ struct MessageField; template struct MessageField, fieldNumberValue> : public MessageType { MessageField() : MessageType() {} - MessageField(const MessageType &value) : MessageType(value) {} - MessageField(MessageType &value) : MessageType(value) {} + MessageField(const MessageType& value) : MessageType(value) {} + MessageField(MessageType& value) : MessageType(value) {} template - MessageField(const fields &... values) : MessageType(values...) {} + MessageField(const fields&... values) : MessageType(values...) {} template - MessageField(fields &&... values) : MessageType(values...) {} + MessageField(fields&&... values) : MessageType(values...) {} static constexpr bool matches(unsigned wireType) { return wireType == 2; } static constexpr unsigned wireType = 2; static constexpr uint64_t fieldNumber = fieldNumberValue; typedef irqus::typestring fieldName; - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { stream << " " << MessageType::name::data() << " " << fieldName::data() << " = " << fieldNumberValue << ";" << std::endl; } static constexpr bool needsToSerializeHeader() { return false; } - void serialize(OutSlice *slice) const { + void serialize(OutSlice* slice) const { OutSlice subSlice; MessageType::serialize(&subSlice); std::string subSliceData = subSlice.finalize(); slice->putVarInt(subSliceData.size()); slice->putBytes(subSliceData); } - void deserialize(InSlice *slice, unsigned wireType) { + void deserialize(InSlice* slice, unsigned wireType) { InSlice subSlice = slice->getSubSlice(slice->getVarInt()); MessageType::deserialize(&subSlice, wireType); } @@ -661,28 +661,28 @@ class Message, fields...> : private std::tuple(); } - Message(const fields &... values) : base(values...) { verifyIntegrity<0, fields...>(); } - Message(fields &&... values) : base(values...) { verifyIntegrity<0, fields...>(); } + Message(const fields&... values) : base(values...) { verifyIntegrity<0, fields...>(); } + Message(fields&&... values) : base(values...) { verifyIntegrity<0, fields...>(); } using name = irqus::typestring; static constexpr char const typeName[sizeof...(C) + 1] = {C..., '\0'}; - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { stream << "message " << name::data() << " {" << std::endl; dumpSchema<0, fields...>(stream); } constexpr void reset() { reset<0, fields...>(); } template - constexpr const FieldType &get() const { + constexpr const FieldType& get() const { static_assert(hasFieldType()); return std::get(*this); } template - constexpr FieldType &get() { + constexpr FieldType& get() { static_assert(hasFieldType()); return std::get(*this); } static constexpr bool needsToSerializeHeader() { return false; } - constexpr void serialize(OutSlice *slice) const { serialize<0, fields...>(slice); } - constexpr void deserialize(InSlice *slice, unsigned wireType) { + constexpr void serialize(OutSlice* slice) const { serialize<0, fields...>(slice); } + constexpr void deserialize(InSlice* slice, unsigned wireType) { while (slice->bytesLeft()) { uint64_t fieldNumber = slice->getVarInt(); unsigned wireType = fieldNumber & 7; @@ -695,11 +695,11 @@ class Message, fields...> : private std::tuple - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { stream << "}" << std::endl << std::endl; } template - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { FieldType::dumpSchema(stream); dumpSchema(stream); } @@ -731,10 +731,10 @@ class Message, fields...> : private std::tuple...>::value; } template - constexpr void serialize(OutSlice *slice) const {} + constexpr void serialize(OutSlice* slice) const {} template - constexpr void serialize(OutSlice *slice) const { - const FieldType &field = std::get(*this); + constexpr void serialize(OutSlice* slice) const { + const FieldType& field = std::get(*this); if (field.hasData()) { if (!FieldType::needsToSerializeHeader()) { slice->putVarInt((FieldType::fieldNumber << 3) | FieldType::wireType); @@ -744,7 +744,7 @@ class Message, fields...> : private std::tuple(slice); } template - constexpr void deserialize(uint64_t fieldNumber, unsigned wireType, InSlice *slice) { + constexpr void deserialize(uint64_t fieldNumber, unsigned wireType, InSlice* slice) { // Unknown field, skip it. switch (wireType) { case 0: @@ -764,8 +764,8 @@ class Message, fields...> : private std::tuple - constexpr void deserialize(uint64_t fieldNumber, unsigned wireType, InSlice *slice) { - FieldType &field = std::get(*this); + constexpr void deserialize(uint64_t fieldNumber, unsigned wireType, InSlice* slice) { + FieldType& field = std::get(*this); if (FieldType::fieldNumber == fieldNumber) { if (!FieldType::matches(wireType)) throw CorruptedWireFormat(); field.deserialize(slice, wireType); @@ -779,7 +779,7 @@ class Message, fields...> : private std::tuple constexpr bool hasData() const { - const FieldType &field = std::get(*this); + const FieldType& field = std::get(*this); if (field.hasData()) return true; return hasData(); } @@ -788,7 +788,7 @@ class Message, fields...> : private std::tuple constexpr void commit() { - FieldType &field = std::get(*this); + FieldType& field = std::get(*this); field.commit(); commit(); } @@ -806,13 +806,13 @@ class EmptyMessage> { using type = myself; using name = irqus::typestring; static constexpr char const typeName[sizeof...(C) + 1] = {C..., '\0'}; - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { stream << "message " << name::data() << " { }" << std::endl << std::endl; } constexpr void reset() {} static constexpr bool needsToSerializeHeader() { return false; } - constexpr void serialize(OutSlice *slice) const {} - constexpr void deserialize(InSlice *slice, unsigned wireType) {} + constexpr void serialize(OutSlice* slice) const {} + constexpr void deserialize(InSlice* slice, unsigned wireType) {} constexpr bool hasData() const { return false; } constexpr void commit() {} }; @@ -820,7 +820,7 @@ class EmptyMessage> { template class ProtoFile : private std::tuple { public: - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { stream << "syntax = \"proto3\";" << std::endl << std::endl; dumpSchema<0, fields...>(stream); } @@ -828,9 +828,9 @@ class ProtoFile : private std::tuple { private: static constexpr bool isMessage = false; template - static constexpr void dumpSchema(std::ostream &stream) {} + static constexpr void dumpSchema(std::ostream& stream) {} template - static constexpr void dumpSchema(std::ostream &stream) { + static constexpr void dumpSchema(std::ostream& stream) { FieldType::dumpSchema(stream); dumpSchema(stream); } diff --git a/src/core/psxbios.cc b/src/core/psxbios.cc index b924bdf24..7279f1382 100644 --- a/src/core/psxbios.cc +++ b/src/core/psxbios.cc @@ -107,7 +107,7 @@ static const char *B0names[] = { }; // clang-format on -static const char *C0names[] = { +static const char* C0names[] = { "InitRCnt", "InitException", "SysEnqIntRP", "SysDeqIntRP", // 00 "get_free_EvCB_slot", "get_free_TCB_slot", "ExceptionHandler", "InstallExeptionHandler", // 04 "SysInitMemory", "SysInitKMem", "ChangeClearRCnt", "SystemError", // 08 @@ -118,7 +118,7 @@ static const char *C0names[] = { "PatchAOTable", "GetDeviceStatus" // 1c }; -const char *PCSX::Bios::getA0name(uint8_t call) { +const char* PCSX::Bios::getA0name(uint8_t call) { unsigned count = sizeof(A0names) / sizeof(A0names[0]); if (call < count) { return A0names[call]; @@ -126,7 +126,7 @@ const char *PCSX::Bios::getA0name(uint8_t call) { return nullptr; } } -const char *PCSX::Bios::getB0name(uint8_t call) { +const char* PCSX::Bios::getB0name(uint8_t call) { unsigned count = sizeof(B0names) / sizeof(B0names[0]); if (call < count) { return B0names[call]; @@ -134,7 +134,7 @@ const char *PCSX::Bios::getB0name(uint8_t call) { return nullptr; } } -const char *PCSX::Bios::getC0name(uint8_t call) { +const char* PCSX::Bios::getC0name(uint8_t call) { unsigned count = sizeof(C0names) / sizeof(C0names[0]); if (call < count) { return C0names[call]; @@ -177,12 +177,12 @@ const char *PCSX::Bios::getC0name(uint8_t call) { #define ra (PCSX::g_emulator.m_psxCpu->m_psxRegs.GPR.n.ra) #define pc0 (PCSX::g_emulator.m_psxCpu->m_psxRegs.pc) -#define Ra0 (assert(PSXM(a0) != NULL), (char *)PSXM(a0)) -#define Ra1 (assert(PSXM(a1) != NULL), (char *)PSXM(a1)) -#define Ra2 (assert(PSXM(a2) != NULL), (char *)PSXM(a2)) -#define Ra3 (assert(PSXM(a3) != NULL), (char *)PSXM(a3)) -#define Rv0 (assert(PSXM(v0) != NULL), (char *)PSXM(v0)) -#define Rsp (assert(PSXM(sp) != NULL), (char *)PSXM(sp)) +#define Ra0 (assert(PSXM(a0) != NULL), (char*)PSXM(a0)) +#define Ra1 (assert(PSXM(a1) != NULL), (char*)PSXM(a1)) +#define Ra2 (assert(PSXM(a2) != NULL), (char*)PSXM(a2)) +#define Ra3 (assert(PSXM(a3) != NULL), (char*)PSXM(a3)) +#define Rv0 (assert(PSXM(v0) != NULL), (char*)PSXM(v0)) +#define Rsp (assert(PSXM(sp) != NULL), (char*)PSXM(sp)) class BiosImpl : public PCSX::Bios { typedef struct { @@ -247,21 +247,21 @@ class BiosImpl : public PCSX::Bios { uint32_t mcfile; } FileDesc; - uint32_t *s_jmp_int = NULL; - int *s_pad_buf = NULL; + uint32_t* s_jmp_int = NULL; + int* s_pad_buf = NULL; char *s_pad_buf1 = NULL, *s_pad_buf2 = NULL; int s_pad_buf1len, s_pad_buf2len; uint32_t s_regs[35]; - EvCB *s_Event; - EvCB *s_HwEV; // 0xf0 - EvCB *s_EvEV; // 0xf1 - EvCB *s_RcEV; // 0xf2 - EvCB *s_UeEV; // 0xf3 - EvCB *s_SwEV; // 0xf4 - EvCB *s_ThEV; // 0xff - uint32_t *s_heap_addr = NULL; - uint32_t *s_heap_end = NULL; + EvCB* s_Event; + EvCB* s_HwEV; // 0xf0 + EvCB* s_EvEV; // 0xf1 + EvCB* s_RcEV; // 0xf2 + EvCB* s_UeEV; // 0xf3 + EvCB* s_SwEV; // 0xf4 + EvCB* s_ThEV; // 0xff + uint32_t* s_heap_addr = NULL; + uint32_t* s_heap_end = NULL; uint32_t s_SysIntRP[8]; int s_CardState = -1; TCB s_Thread[8]; @@ -337,7 +337,7 @@ class BiosImpl : public PCSX::Bios { void psxBios_atoi() { // 0x10 int32_t n = 0, f = 0; - char *p = (char *)Ra0; + char* p = (char*)Ra0; for (;; p++) { switch (*p) { @@ -365,7 +365,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_setjmp() { // 0x13 - uint32_t *jmp_buf = (uint32_t *)Ra0; + uint32_t* jmp_buf = (uint32_t*)Ra0; int i; PSXBIOS_LOG("psxBios_%s\n", A0names[0x13]); @@ -382,7 +382,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_longjmp() { // 0x14 - uint32_t *jmp_buf = (uint32_t *)Ra0; + uint32_t* jmp_buf = (uint32_t*)Ra0; int i; PSXBIOS_LOG("psxBios_%s\n", A0names[0x14]); @@ -399,7 +399,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_strcat() { // 0x15 - char *p1 = (char *)Ra0, *p2 = (char *)Ra1; + char *p1 = (char*)Ra0, *p2 = (char*)Ra1; PSXBIOS_LOG("psxBios_%s: %s, %s\n", A0names[0x15], Ra0, Ra1); @@ -414,7 +414,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_strncat() { // 0x16 - char *p1 = (char *)Ra0, *p2 = (char *)Ra1; + char *p1 = (char*)Ra0, *p2 = (char*)Ra1; int32_t n = a2; PSXBIOS_LOG("psxBios_%s: %s (%x), %s (%x), %d\n", A0names[0x16], Ra0, a0, Ra1, a1, a2); @@ -434,7 +434,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_strcmp() { // 0x17 - char *p1 = (char *)Ra0, *p2 = (char *)Ra1; + char *p1 = (char*)Ra0, *p2 = (char*)Ra1; PSXBIOS_LOG("psxBios_%s: %s (%x), %s (%x)\n", A0names[0x17], Ra0, a0, Ra1, a1); @@ -451,7 +451,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_strncmp() { // 0x18 - char *p1 = (char *)Ra0, *p2 = (char *)Ra1; + char *p1 = (char*)Ra0, *p2 = (char*)Ra1; int32_t n = a2; PSXBIOS_LOG("psxBios_%s: %s (%x), %s (%x), %d\n", A0names[0x18], Ra0, a0, Ra1, a1, a2); @@ -469,7 +469,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_strcpy() { // 0x19 - char *p1 = (char *)Ra0, *p2 = (char *)Ra1; + char *p1 = (char*)Ra0, *p2 = (char*)Ra1; while ((*p1++ = *p2++) != '\0') ; @@ -478,7 +478,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_strncpy() { // 0x1a - char *p1 = (char *)Ra0, *p2 = (char *)Ra1; + char *p1 = (char*)Ra0, *p2 = (char*)Ra1; int32_t n = a2, i; for (i = 0; i < n; i++) { @@ -497,18 +497,18 @@ class BiosImpl : public PCSX::Bios { } void psxBios_strlen() { // 0x1b - char *p = (char *)Ra0; + char* p = (char*)Ra0; v0 = 0; while (*p++) v0++; pc0 = ra; } void psxBios_index() { // 0x1c - char *p = (char *)Ra0; + char* p = (char*)Ra0; do { if (*p == a1) { - v0 = a0 + (p - (char *)Ra0); + v0 = a0 + (p - (char*)Ra0); pc0 = ra; return; } @@ -519,12 +519,12 @@ class BiosImpl : public PCSX::Bios { } void psxBios_rindex() { // 0x1d - char *p = (char *)Ra0; + char* p = (char*)Ra0; v0 = 0; do { - if (*p == a1) v0 = a0 + (p - (char *)Ra0); + if (*p == a1) v0 = a0 + (p - (char*)Ra0); } while (*p++ != '\0'); pc0 = ra; @@ -539,12 +539,12 @@ class BiosImpl : public PCSX::Bios { } void psxBios_strpbrk() { // 0x20 - char *p1 = (char *)Ra0, *p2 = (char *)Ra1, *scanp, c, sc; + char *p1 = (char*)Ra0, *p2 = (char*)Ra1, *scanp, c, sc; while ((c = *p1++) != '\0') { for (scanp = p2; (sc = *scanp++) != '\0';) { if (sc == c) { - v0 = a0 + (p1 - 1 - (char *)Ra0); + v0 = a0 + (p1 - 1 - (char*)Ra0); pc0 = ra; return; } @@ -559,32 +559,32 @@ class BiosImpl : public PCSX::Bios { void psxBios_strspn() { // 0x21 char *p1, *p2; - for (p1 = (char *)Ra0; *p1 != '\0'; p1++) { - for (p2 = (char *)Ra1; *p2 != '\0' && *p2 != *p1; p2++) + for (p1 = (char*)Ra0; *p1 != '\0'; p1++) { + for (p2 = (char*)Ra1; *p2 != '\0' && *p2 != *p1; p2++) ; if (*p2 == '\0') break; } - v0 = p1 - (char *)Ra0; + v0 = p1 - (char*)Ra0; pc0 = ra; } void psxBios_strcspn() { // 0x22 char *p1, *p2; - for (p1 = (char *)Ra0; *p1 != '\0'; p1++) { - for (p2 = (char *)Ra1; *p2 != '\0' && *p2 != *p1; p2++) + for (p1 = (char*)Ra0; *p1 != '\0'; p1++) { + for (p2 = (char*)Ra1; *p2 != '\0' && *p2 != *p1; p2++) ; if (*p2 != '\0') break; } - v0 = p1 - (char *)Ra0; + v0 = p1 - (char*)Ra0; pc0 = ra; } void psxBios_strtok() { // 0x23 - char *pcA0 = (char *)Ra0; - char *pcRet = strtok(pcA0, (char *)Ra1); + char* pcA0 = (char*)Ra0; + char* pcRet = strtok(pcA0, (char*)Ra1); if (pcRet) v0 = a0 + pcRet - pcA0; else @@ -593,11 +593,11 @@ class BiosImpl : public PCSX::Bios { } void psxBios_strstr() { // 0x24 - char *p = (char *)Ra0, *p1, *p2; + char *p = (char*)Ra0, *p1, *p2; while (*p != '\0') { p1 = p; - p2 = (char *)Ra1; + p2 = (char*)Ra1; while (*p1 != '\0' && *p2 != '\0' && *p1 == *p2) { p1++; @@ -605,7 +605,7 @@ class BiosImpl : public PCSX::Bios { } if (*p2 == '\0') { - v0 = a0 + (p - (char *)Ra0); + v0 = a0 + (p - (char*)Ra0); pc0 = ra; return; } @@ -630,21 +630,21 @@ class BiosImpl : public PCSX::Bios { } void psxBios_bcopy() { // 0x27 - char *p1 = (char *)Ra1, *p2 = (char *)Ra0; + char *p1 = (char*)Ra1, *p2 = (char*)Ra0; while ((int32_t)a2-- > 0) *p1++ = *p2++; pc0 = ra; } void psxBios_bzero() { // 0x28 - char *p = (char *)Ra0; + char* p = (char*)Ra0; while ((int32_t)a1-- > 0) *p++ = '\0'; pc0 = ra; } void psxBios_bcmp() { // 0x29 - char *p1 = (char *)Ra0, *p2 = (char *)Ra1; + char *p1 = (char*)Ra0, *p2 = (char*)Ra1; if (a0 == 0 || a1 == 0) { v0 = 0; @@ -665,7 +665,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_memcpy() { // 0x2a - char *p1 = (char *)Ra0, *p2 = (char *)Ra1; + char *p1 = (char*)Ra0, *p2 = (char*)Ra1; while ((int32_t)a2-- > 0) *p1++ = *p2++; v0 = a0; @@ -673,7 +673,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_memset() { // 0x2b - char *p = (char *)Ra0; + char* p = (char*)Ra0; while ((int32_t)a2-- > 0) *p++ = (char)a1; a2 = 0; v0 = a0; @@ -683,7 +683,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_memmove() { // 0x2c - char *p1 = (char *)Ra0, *p2 = (char *)Ra1; + char *p1 = (char*)Ra0, *p2 = (char*)Ra1; if (p2 <= p1 && p2 + a2 > p1) { a2++; // BUG: copy one more byte here @@ -703,11 +703,11 @@ class BiosImpl : public PCSX::Bios { } void psxBios_memchr() { // 0x2e - char *p = (char *)Ra0; + char* p = (char*)Ra0; while ((int32_t)a2-- > 0) { if (*p++ != (int8_t)a1) continue; - v0 = a0 + (p - (char *)Ra0 - 1); + v0 = a0 + (p - (char*)Ra0 - 1); pc0 = ra; return; } @@ -730,11 +730,11 @@ class BiosImpl : public PCSX::Bios { uint32_t qscmpfunc, qswidth; - inline int qscmp(char *a, char *b) { + inline int qscmp(char* a, char* b) { uint32_t sa0 = a0; - a0 = sa0 + (a - (char *)PSXM(sa0)); - a1 = sa0 + (b - (char *)PSXM(sa0)); + a0 = sa0 + (a - (char*)PSXM(sa0)); + a1 = sa0 + (b - (char*)PSXM(sa0)); softCall2(qscmpfunc); @@ -742,7 +742,7 @@ class BiosImpl : public PCSX::Bios { return (int32_t)v0; } - inline void qexchange(char *i, char *j) { + inline void qexchange(char* i, char* j) { char t; int n = qswidth; @@ -753,7 +753,7 @@ class BiosImpl : public PCSX::Bios { } while (--n); } - inline void q3exchange(char *i, char *j, char *k) { + inline void q3exchange(char* i, char* j, char* k) { char t; int n = qswidth; @@ -765,7 +765,7 @@ class BiosImpl : public PCSX::Bios { } while (--n); } - void qsort_main(char *a, char *l) { + void qsort_main(char* a, char* l) { char *i, *j, *lp, *hp; int c; unsigned int n; @@ -828,7 +828,7 @@ class BiosImpl : public PCSX::Bios { void psxBios_qsort() { // 0x31 qswidth = a2; qscmpfunc = a3; - qsort_main((char *)Ra0, (char *)Ra0 + a1 * a2); + qsort_main((char*)Ra0, (char*)Ra0 + a1 * a2); pc0 = ra; } @@ -865,7 +865,7 @@ class BiosImpl : public PCSX::Bios { } // next chunk - chunk = (uint32_t *)((uintptr_t)chunk + csize + 4); + chunk = (uint32_t*)((uintptr_t)chunk + csize + 4); } // if neccessary free memory on end of heap if (colflag == 1) *newchunk = SWAP_LE32(dsize | 1); @@ -885,7 +885,7 @@ class BiosImpl : public PCSX::Bios { // search an unused chunk that is big enough until the end of the heap while ((dsize > csize || cstat == 0) && chunk < s_heap_end) { - chunk = (uint32_t *)((uintptr_t)chunk + csize + 4); + chunk = (uint32_t*)((uintptr_t)chunk + csize + 4); csize = ((uint32_t)*chunk) & 0xfffffffc; cstat = ((uint32_t)*chunk) & 1; } @@ -905,7 +905,7 @@ class BiosImpl : public PCSX::Bios { } else { // split free chunk *chunk = SWAP_LE32(dsize); - newchunk = (uint32_t *)((uintptr_t)chunk + dsize + 4); + newchunk = (uint32_t*)((uintptr_t)chunk + dsize + 4); *newchunk = SWAP_LE32((csize - dsize - 4) & 0xfffffffc | 1); } @@ -919,9 +919,9 @@ class BiosImpl : public PCSX::Bios { void psxBios_free() { // 0x34 PSXBIOS_LOG("psxBios_%s\n", A0names[0x34]); - PCSX::g_system->biosPrintf("free %x: %x bytes\n", a0, *(uint32_t *)(Ra0 - 4)); + PCSX::g_system->biosPrintf("free %x: %x bytes\n", a0, *(uint32_t*)(Ra0 - 4)); - *(uint32_t *)(Ra0 - 4) |= 1; // set chunk to free + *(uint32_t*)(Ra0 - 4) |= 1; // set chunk to free pc0 = ra; } @@ -957,8 +957,8 @@ class BiosImpl : public PCSX::Bios { size &= 0xfffffffc; - s_heap_addr = (uint32_t *)Ra0; - s_heap_end = (uint32_t *)((uint8_t *)s_heap_addr + size); + s_heap_addr = (uint32_t*)Ra0; + s_heap_end = (uint32_t*)((uint8_t*)s_heap_addr + size); *s_heap_addr = SWAP_LE32(size | 1); PCSX::g_system->biosPrintf("InitHeap %x,%x : %lx %x\n", a0, a1, @@ -976,7 +976,7 @@ class BiosImpl : public PCSX::Bios { char tmp[1024]; char tmp2[1024]; uint32_t save[4]; - char *ptmp = tmp; + char* ptmp = tmp; int n = 1, i = 0, j; memcpy(save, Rsp, 4 * 4); @@ -1038,7 +1038,7 @@ class BiosImpl : public PCSX::Bios { n++; break; case 's': - ptmp += sprintf(ptmp, tmp2, (char *)PSXM(psxMu32(sp + n * 4))); + ptmp += sprintf(ptmp, tmp2, (char*)PSXM(psxMu32(sp + n * 4))); n++; break; case '%': @@ -1089,7 +1089,7 @@ class BiosImpl : public PCSX::Bios { PSXBIOS_LOG("psxBios_%s: %s, %x\n", A0names[0x42], Ra0, a1); if (LoadCdromFile(Ra0, &eheader) == 0) { - memcpy(Ra1, ((char *)&eheader) + 16, sizeof(EXEC)); + memcpy(Ra1, ((char*)&eheader) + 16, sizeof(EXEC)); v0 = 1; } else v0 = 0; @@ -1102,7 +1102,7 @@ class BiosImpl : public PCSX::Bios { */ void psxBios_Exec() { // 43 - EXEC *header = (EXEC *)Ra0; + EXEC* header = (EXEC*)Ra0; uint32_t tmp; PSXBIOS_LOG("psxBios_%s: %x, %x, %x\n", A0names[0x43], a0, a1, a2); @@ -1141,7 +1141,7 @@ class BiosImpl : public PCSX::Bios { void psxBios_GPU_dw() { // 0x46 int size; - int32_t *ptr; + int32_t* ptr; PSXBIOS_LOG("psxBios_%s\n", A0names[0x46]); @@ -1149,7 +1149,7 @@ class BiosImpl : public PCSX::Bios { PCSX::g_emulator.m_gpu->writeData((a1 << 16) | (a0 & 0xffff)); PCSX::g_emulator.m_gpu->writeData((a3 << 16) | (a2 & 0xffff)); size = (a2 * a3 + 1) / 2; - ptr = (int32_t *)PSXM(Rsp[4]); // that is correct? + ptr = (int32_t*)PSXM(Rsp[4]); // that is correct? do { PCSX::g_emulator.m_gpu->writeData(SWAP_LE32(*ptr)); ptr++; @@ -1186,7 +1186,7 @@ class BiosImpl : public PCSX::Bios { } void psxBios_GPU_cwb() { // 0x4a - int32_t *ptr = (int32_t *)Ra0; + int32_t* ptr = (int32_t*)Ra0; int size = a1; while (size--) { PCSX::g_emulator.m_gpu->writeData(SWAP_LE32(*ptr)); @@ -1223,7 +1223,7 @@ class BiosImpl : public PCSX::Bios { #undef s_addr void psxBios_LoadExec() { // 51 - EXEC *header = (EXEC *)PSXM(0xf000); + EXEC* header = (EXEC*)PSXM(0xf000); uint32_t s_addr, s_size; PSXBIOS_LOG("psxBios_%s: %s: %x,%x\n", A0names[0x51], Ra0, a1, a2); @@ -1612,9 +1612,9 @@ class BiosImpl : public PCSX::Bios { void psxBios_InitPAD() { // 0x12 PSXBIOS_LOG("psxBios_%s\n", B0names[0x12]); - s_pad_buf1 = (char *)Ra0; + s_pad_buf1 = (char*)Ra0; s_pad_buf1len = a1; - s_pad_buf2 = (char *)Ra2; + s_pad_buf2 = (char*)Ra2; s_pad_buf2len = a3; v0 = 1; @@ -1643,7 +1643,7 @@ class BiosImpl : public PCSX::Bios { PCSX::g_emulator.m_hw->psxHwWrite16(0x1f801074, (uint16_t)(PCSX::g_emulator.m_hw->psxHwRead16(0x1f801074) | 0x1)); - s_pad_buf = (int *)Ra1; + s_pad_buf = (int*)Ra1; *s_pad_buf = -1; PCSX::g_emulator.m_psxCpu->m_psxRegs.CP0.n.Status |= 0x401; pc0 = ra; @@ -1677,7 +1677,7 @@ class BiosImpl : public PCSX::Bios { void psxBios_HookEntryInt() { // 19 PSXBIOS_LOG("psxBios_%s\n", B0names[0x19]); - s_jmp_int = (uint32_t *)Ra0; + s_jmp_int = (uint32_t*)Ra0; pc0 = ra; } @@ -1696,9 +1696,9 @@ class BiosImpl : public PCSX::Bios { pc0 = ra; } - void buopen(int mcd, char *ptr, const PCSX::u8string cfg) { + void buopen(int mcd, char* ptr, const PCSX::u8string cfg) { int i; - uint8_t *fptr = reinterpret_cast(ptr); + uint8_t* fptr = reinterpret_cast(ptr); strcpy(s_FDesc[1 + mcd].name, Ra0 + 5); s_FDesc[1 + mcd].offset = 0; @@ -1707,14 +1707,14 @@ class BiosImpl : public PCSX::Bios { for (i = 1; i < 16; i++) { fptr += 128; if ((*fptr & 0xF0) != 0x50) continue; - if (strcmp(s_FDesc[1 + mcd].name, reinterpret_cast(fptr) + 0xa)) continue; + if (strcmp(s_FDesc[1 + mcd].name, reinterpret_cast(fptr) + 0xa)) continue; s_FDesc[1 + mcd].mcfile = i; PCSX::g_system->biosPrintf("open %s\n", fptr + 0xa); v0 = 1 + mcd; break; } if (a1 & 0x200 && v0 == -1) { /* FCREAT */ - fptr = reinterpret_cast(ptr); + fptr = reinterpret_cast(ptr); for (i = 1; i < 16; i++) { int j, checksum, nblk = a1 >> 16; uint8_t *pptr, *fptr2; @@ -1728,7 +1728,7 @@ class BiosImpl : public PCSX::Bios { fptr[5] = 0x20 * nblk; fptr[6] = 0x00; fptr[7] = 0x00; - strcpy(reinterpret_cast(fptr) + 0xa, s_FDesc[1 + mcd].name); + strcpy(reinterpret_cast(fptr) + 0xa, s_FDesc[1 + mcd].name); pptr = fptr2 = fptr; for (j = 2; j <= nblk; j++) { int k; @@ -1752,7 +1752,7 @@ class BiosImpl : public PCSX::Bios { PCSX::g_system->biosPrintf("openC %s %d\n", ptr, nblk); v0 = 1 + mcd; /* just go ahead and resave them all */ - PCSX::g_emulator.m_sio->SaveMcd(cfg, reinterpret_cast(ptr), 128, 128 * 15); + PCSX::g_emulator.m_sio->SaveMcd(cfg, reinterpret_cast(ptr), 128, 128 * 15); break; } /* shouldn't this return ENOSPC if i == 16? */ @@ -1806,7 +1806,7 @@ class BiosImpl : public PCSX::Bios { } template - char *getmcdData() { + char* getmcdData() { if (mcd == 1) { return PCSX::g_emulator.m_sio->g_mcd1Data; } else if (mcd == 2) { @@ -1829,7 +1829,7 @@ class BiosImpl : public PCSX::Bios { void buread() { PCSX::g_system->biosPrintf("read %d: %x,%x (%s)\n", s_FDesc[1 + mcd].mcfile, s_FDesc[1 + mcd].offset, a2, getmcdData() + 128 * s_FDesc[1 + mcd].mcfile + 0xa); - char *ptr = getmcdData() + 8192 * s_FDesc[1 + mcd].mcfile + s_FDesc[1 + mcd].offset; + char* ptr = getmcdData() + 8192 * s_FDesc[1 + mcd].mcfile + s_FDesc[1 + mcd].offset; memcpy(Ra1, ptr, a2); if (s_FDesc[1 + mcd].mode & 0x8000) v0 = 0; @@ -1865,7 +1865,7 @@ class BiosImpl : public PCSX::Bios { void buwrite() { uint32_t offset = +8192 * s_FDesc[1 + mcd].mcfile + s_FDesc[1 + mcd].offset; PCSX::g_system->biosPrintf("write %d: %x,%x\n", s_FDesc[1 + mcd].mcfile, s_FDesc[1 + mcd].offset, a2); - char *ptr = getmcdData() + offset; + char* ptr = getmcdData() + offset; memcpy(ptr, Ra1, a2); s_FDesc[1 + mcd].offset += a2; PCSX::g_emulator.m_sio->SaveMcd(getmcdName(), getmcdData(), offset, a2); @@ -1883,7 +1883,7 @@ class BiosImpl : public PCSX::Bios { void psxBios_write() { // 0x35/0x03 if (a0 == 1) { // stdout - char *ptr = Ra1; + char* ptr = Ra1; while (a2 > 0) { PCSX::g_system->biosPrintf("%c", *ptr++); @@ -1945,11 +1945,11 @@ class BiosImpl : public PCSX::Bios { int nfile; template - void bufile(struct DIRENTRY *dir) { + void bufile(struct DIRENTRY* dir) { while (nfile < 16) { int match = 1; - char *ptr = getmcdData() + 128 * (nfile + 1); + char* ptr = getmcdData() + 128 * (nfile + 1); nfile++; if ((*ptr & 0xF0) != 0x50) continue; /* Bug link files show up as free block. */ @@ -1990,7 +1990,7 @@ class BiosImpl : public PCSX::Bios { */ void psxBios_firstfile() { // 42 - struct DIRENTRY *dir = (struct DIRENTRY *)Ra1; + struct DIRENTRY* dir = (struct DIRENTRY*)Ra1; PSXBIOS_LOG("psxBios_%s: %s\n", B0names[0x42], Ra0); @@ -2016,7 +2016,7 @@ class BiosImpl : public PCSX::Bios { */ void psxBios_nextfile() { // 43 - struct DIRENTRY *dir = (struct DIRENTRY *)Ra0; + struct DIRENTRY* dir = (struct DIRENTRY*)Ra0; PSXBIOS_LOG("psxBios_%s: %s\n", B0names[0x43], dir->name); @@ -2037,7 +2037,7 @@ class BiosImpl : public PCSX::Bios { void burename() { for (int i = 1; i < 16; i++) { int namelen, j, chksum = 0; - char *ptr = getmcdData() + 128 * i; + char* ptr = getmcdData() + 128 * i; if ((*ptr & 0xF0) != 0x50) continue; if (strcmp(Ra0 + 5, ptr + 0xa)) continue; namelen = strlen(Ra1 + 5); @@ -2074,7 +2074,7 @@ class BiosImpl : public PCSX::Bios { template void budelete() { for (int i = 1; i < 16; i++) { - char *ptr = getmcdData() + 128 * i; + char* ptr = getmcdData() + 128 * i; if ((*ptr & 0xF0) != 0x50) continue; if (strcmp(Ra0 + 5, ptr + 0xa)) continue; *ptr = (*ptr & 0xf) | 0xA0; @@ -2294,11 +2294,11 @@ class BiosImpl : public PCSX::Bios { } void psxBios_ChangeClearRCnt() { // 0a - uint32_t *ptr; + uint32_t* ptr; PSXBIOS_LOG("psxBios_%s: %x, %x\n", C0names[0x0a], a0, a1); - ptr = (uint32_t *)PSXM((a0 << 2) + 0x8600); + ptr = (uint32_t*)PSXM((a0 << 2) + 0x8600); v0 = *ptr; *ptr = a1; @@ -2331,7 +2331,7 @@ class BiosImpl : public PCSX::Bios { #include "sjisfont.h" void psxBiosInit() final { - uint32_t *ptr; + uint32_t* ptr; int i; uLongf len; @@ -2649,10 +2649,10 @@ class BiosImpl : public PCSX::Bios { // m_biosC0[0x1c] = &BiosImpl::psxBios_PatchAOTable; //************** THE END *************************************** /**/ - ptr = (uint32_t *)&PCSX::g_emulator.m_psxMem->g_psxM[0x0874]; // b0 table + ptr = (uint32_t*)&PCSX::g_emulator.m_psxMem->g_psxM[0x0874]; // b0 table ptr[0] = SWAP_LEu32(0x4c54 - 0x884); - ptr = (uint32_t *)&PCSX::g_emulator.m_psxMem->g_psxM[0x0674]; // c0 table + ptr = (uint32_t*)&PCSX::g_emulator.m_psxMem->g_psxM[0x0674]; // c0 table ptr[6] = SWAP_LEu32(0xc80); memset(s_SysIntRP, 0, sizeof(s_SysIntRP)); @@ -2674,7 +2674,7 @@ class BiosImpl : public PCSX::Bios { psxMu32ref(0x0150) = SWAP_LEu32(0x160); psxMu32ref(0x0154) = SWAP_LEu32(0x320); psxMu32ref(0x0160) = SWAP_LEu32(0x248); - strcpy((char *)&PCSX::g_emulator.m_psxMem->g_psxM[0x248], "bu"); + strcpy((char*)&PCSX::g_emulator.m_psxMem->g_psxM[0x248], "bu"); /* psxMu32ref(0x0ca8) = SWAP_LEu32(0x1f410004); psxMu32ref(0x0cf0) = SWAP_LEu32(0x3c020000); psxMu32ref(0x0cf4) = SWAP_LEu32(0x2442641c); @@ -2732,7 +2732,7 @@ class BiosImpl : public PCSX::Bios { uint32_t base = 0x1000; uint32_t size = sizeof(EvCB) * 32; - s_Event = reinterpret_cast(&PCSX::g_emulator.m_psxMem->g_psxR[base]); + s_Event = reinterpret_cast(&PCSX::g_emulator.m_psxMem->g_psxR[base]); s_HwEV = s_Event; s_EvEV = s_Event + 32; s_RcEV = s_Event + 32 * 2; @@ -2755,9 +2755,9 @@ class BiosImpl : public PCSX::Bios { psxRu32ref(0x0184) = SWAP_LEu32((0x3b << 26) | 6); // fonts len = 0x80000 - 0x66000; - uncompress((Bytef *)(PCSX::g_emulator.m_psxMem->g_psxR + 0x66000), &len, font_8140, sizeof(font_8140)); + uncompress((Bytef*)(PCSX::g_emulator.m_psxMem->g_psxR + 0x66000), &len, font_8140, sizeof(font_8140)); len = 0x80000 - 0x69d68; - uncompress((Bytef *)(PCSX::g_emulator.m_psxMem->g_psxR + 0x69d68), &len, font_889f, sizeof(font_889f)); + uncompress((Bytef*)(PCSX::g_emulator.m_psxMem->g_psxR + 0x69d68), &len, font_889f, sizeof(font_889f)); } void psxBiosShutdown() final {} @@ -2784,7 +2784,7 @@ class BiosImpl : public PCSX::Bios { // if (psxHu32(0x1070) & 0x1) { // Vsync if (s_pad_buf != NULL) { - uint32_t *buf = (uint32_t *)s_pad_buf; + uint32_t* buf = (uint32_t*)s_pad_buf; PCSX::g_emulator.m_pad1->startPoll(); if (PCSX::g_emulator.m_pad1->poll(0x42) == 0x23) { @@ -2857,7 +2857,7 @@ class BiosImpl : public PCSX::Bios { for (i = 0; i < 8; i++) { if (s_SysIntRP[i]) { - uint32_t *queue = (uint32_t *)PSXM(s_SysIntRP[i]); + uint32_t* queue = (uint32_t*)PSXM(s_SysIntRP[i]); s0 = queue[2]; softCall(queue[1]); @@ -2917,24 +2917,24 @@ class BiosImpl : public PCSX::Bios { } template - static uint32_t fromMemory(T *ptr) { + static uint32_t fromMemory(T* ptr) { if (ptr) { - return reinterpret_cast(ptr) - PCSX::g_emulator.m_psxMem->g_psxM; + return reinterpret_cast(ptr) - PCSX::g_emulator.m_psxMem->g_psxM; } else { return 0; } } template - static T *toMemory(uint32_t val) { + static T* toMemory(uint32_t val) { if (val) { - return reinterpret_cast(PCSX::g_emulator.m_psxMem->g_psxM + val); + return reinterpret_cast(PCSX::g_emulator.m_psxMem->g_psxM + val); } else { return nullptr; } } - void save(PCSX::SaveStates::BiosHLE &state) { + void save(PCSX::SaveStates::BiosHLE& state) { state.get().value = fromMemory(s_jmp_int); state.get().value = fromMemory(s_pad_buf); state.get().value = fromMemory(s_pad_buf1); @@ -2950,7 +2950,7 @@ class BiosImpl : public PCSX::Bios { } state.get().value = s_CardState; for (unsigned i = 0; i < 8; i++) { - auto &thread = state.get().value[i]; + auto& thread = state.get().value[i]; thread.get().value = s_Thread[i].status; thread.get().value = s_Thread[i].mode; for (unsigned j = 0; j < 32; j++) { @@ -2960,7 +2960,7 @@ class BiosImpl : public PCSX::Bios { } state.get().value = s_CurThread; for (unsigned int i = 0; i < 32; i++) { - auto &fd = state.get().value[i]; + auto& fd = state.get().value[i]; fd.get().value = s_FDesc[i].name; fd.get().value = s_FDesc[i].mode; fd.get().value = s_FDesc[i].offset; @@ -2970,7 +2970,7 @@ class BiosImpl : public PCSX::Bios { state.get().value = s_card_active_chan; } - void load(const PCSX::SaveStates::BiosHLE &state) { + void load(const PCSX::SaveStates::BiosHLE& state) { s_jmp_int = toMemory(state.get().value); s_pad_buf = toMemory(state.get().value); s_pad_buf1 = toMemory(state.get().value); @@ -2986,7 +2986,7 @@ class BiosImpl : public PCSX::Bios { } s_CardState = state.get().value; for (unsigned i = 0; i < 8; i++) { - const auto &thread = state.get().value[i]; + const auto& thread = state.get().value[i]; s_Thread[i].status = thread.get().value; s_Thread[i].mode = thread.get().value; for (unsigned j = 0; j < 32; j++) { @@ -2996,7 +2996,7 @@ class BiosImpl : public PCSX::Bios { } s_CurThread = state.get().value; for (unsigned int i = 0; i < 32; i++) { - const auto &fd = state.get().value[i]; + const auto& fd = state.get().value[i]; std::strncpy(s_FDesc[i].name, fd.get().value.c_str(), 32); s_FDesc[i].mode = fd.get().value; s_FDesc[i].offset = fd.get().value; @@ -3007,4 +3007,4 @@ class BiosImpl : public PCSX::Bios { } }; -PCSX::Bios *PCSX::Bios::factory() { return new BiosImpl(); } +PCSX::Bios* PCSX::Bios::factory() { return new BiosImpl(); } diff --git a/src/core/psxbios.h b/src/core/psxbios.h index 840bf6695..7bb2f39dd 100644 --- a/src/core/psxbios.h +++ b/src/core/psxbios.h @@ -29,9 +29,9 @@ class Bios { public: Bios() {} virtual ~Bios() {} - static const char *getA0name(uint8_t call); - static const char *getB0name(uint8_t call); - static const char *getC0name(uint8_t call); + static const char* getA0name(uint8_t call); + static const char* getB0name(uint8_t call); + static const char* getC0name(uint8_t call); virtual void psxBiosInit() = 0; virtual void psxBiosShutdown() = 0; @@ -41,12 +41,12 @@ class Bios { virtual bool callB0(unsigned index) = 0; virtual bool callC0(unsigned index) = 0; - virtual void save(SaveStates::BiosHLE &state) = 0; - virtual void load(const SaveStates::BiosHLE &state) = 0; + virtual void save(SaveStates::BiosHLE& state) = 0; + virtual void load(const SaveStates::BiosHLE& state) = 0; bool inSoftCall() { return m_hleSoftCall; } - static Bios *factory(); + static Bios* factory(); bool m_realBiosLoaded = false; diff --git a/src/core/psxcounters.cc b/src/core/psxcounters.cc index 84f1857e1..0bbd74b04 100644 --- a/src/core/psxcounters.cc +++ b/src/core/psxcounters.cc @@ -28,7 +28,7 @@ /******************************************************************************/ -void PCSX::Counters::verboseLog(int32_t level, const char *str, ...) { +void PCSX::Counters::verboseLog(int32_t level, const char* str, ...) { va_list va; va_start(va, str); PSXHW_LOGV(str, va); @@ -382,7 +382,7 @@ void PCSX::Counters::psxRcntInit() { /******************************************************************************/ -void PCSX::Counters::save(PCSX::SaveStates::Counters &counters) { +void PCSX::Counters::save(PCSX::SaveStates::Counters& counters) { for (unsigned i = 0; i < CounterQuantity; i++) { counters.get().value[i].get().value = m_rcnts[i].mode; counters.get().value[i].get().value = m_rcnts[i].target; @@ -399,14 +399,14 @@ void PCSX::Counters::save(PCSX::SaveStates::Counters &counters) { counters.get().value = m_psxNextsCounter; } -void PCSX::Counters::load(const PCSX::SaveStates::Counters &counters) { +void PCSX::Counters::load(const PCSX::SaveStates::Counters& counters) { for (unsigned i = 0; i < CounterQuantity; i++) { m_rcnts[i].mode = counters.get().value[i].get().value; m_rcnts[i].target = counters.get().value[i].get().value; m_rcnts[i].rate = counters.get().value[i].get().value; m_rcnts[i].irq = counters.get().value[i].get().value; m_rcnts[i].counterState = counters.get().value[i].get().value; - m_rcnts[i].irqState = counters.get().value[i].get().value; + m_rcnts[i].irqState = counters.get().value[i].get().value; m_rcnts[i].cycle = counters.get().value[i].get().value; m_rcnts[i].cycleStart = counters.get().value[i].get().value; } @@ -418,10 +418,10 @@ void PCSX::Counters::load(const PCSX::SaveStates::Counters &counters) { psxHsyncCalculate(); // iCB: recalculate target count in case overclock is changed m_rcnts[3].target = (PCSX::g_emulator.m_psxClockSpeed / - (FrameRate[PCSX::g_emulator.settings.get()] * - m_HSyncTotal[PCSX::g_emulator.settings.get()])); + (FrameRate[PCSX::g_emulator.settings.get()] * + m_HSyncTotal[PCSX::g_emulator.settings.get()])); if (m_rcnts[1].rate != 1) m_rcnts[1].rate = (PCSX::g_emulator.m_psxClockSpeed / - (FrameRate[PCSX::g_emulator.settings.get()] * + (FrameRate[PCSX::g_emulator.settings.get()] * m_HSyncTotal[PCSX::g_emulator.settings.get()])); } diff --git a/src/core/psxcounters.h b/src/core/psxcounters.h index 7f2c25eb8..bb2a7a52c 100644 --- a/src/core/psxcounters.h +++ b/src/core/psxcounters.h @@ -31,7 +31,7 @@ class Counters { private: /******************************************************************************/ static inline void setIrq(uint32_t irq) { psxHu32ref(0x1070) |= SWAP_LEu32(irq); } - static void verboseLog(int32_t level, const char *str, ...); + static void verboseLog(int32_t level, const char* str, ...); uint32_t psxRcntRcountInternal(uint32_t index); void psxRcntWcountInternal(uint32_t index, uint32_t value); @@ -107,8 +107,8 @@ class Counters { uint32_t psxRcntRmode(uint32_t index); uint32_t psxRcntRtarget(uint32_t index); - void save(PCSX::SaveStates::Counters &counters); - void load(const PCSX::SaveStates::Counters & counters); + void save(PCSX::SaveStates::Counters& counters); + void load(const PCSX::SaveStates::Counters& counters); }; } // namespace PCSX diff --git a/src/core/psxdma.cc b/src/core/psxdma.cc index 39882a9a9..034e12e3f 100644 --- a/src/core/psxdma.cc +++ b/src/core/psxdma.cc @@ -34,13 +34,13 @@ void spuInterrupt() { } void psxDma4(uint32_t madr, uint32_t bcr, uint32_t chcr) { // SPU - uint16_t *ptr; + uint16_t* ptr; uint32_t size; switch (chcr) { case 0x01000201: // cpu to spu transfer PSXDMA_LOG("*** DMA4 SPU - mem2spu *** %x addr = %x size = %x\n", chcr, madr, bcr); - ptr = (uint16_t *)PSXM(madr); + ptr = (uint16_t*)PSXM(madr); if (ptr == NULL) { PSXDMA_LOG("*** DMA4 SPU - mem2spu *** NULL Pointer!!!\n"); break; @@ -56,7 +56,7 @@ void psxDma4(uint32_t madr, uint32_t bcr, uint32_t chcr) { // SPU case 0x01000200: // spu to cpu transfer PSXDMA_LOG("*** DMA4 SPU - spu2mem *** %x addr = %x size = %x\n", chcr, madr, bcr); - ptr = (uint16_t *)PSXM(madr); + ptr = (uint16_t*)PSXM(madr); if (ptr == NULL) { PSXDMA_LOG("*** DMA4 SPU - spu2mem *** NULL Pointer!!!\n"); break; @@ -84,7 +84,7 @@ void psxDma4(uint32_t madr, uint32_t bcr, uint32_t chcr) { // SPU void psxDma6(uint32_t madr, uint32_t bcr, uint32_t chcr) { uint32_t size; - uint32_t *mem = (uint32_t *)PSXM(madr); + uint32_t* mem = (uint32_t*)PSXM(madr); PSXDMA_LOG("*** DMA6 OT *** %x addr = %x size = %x\n", chcr, madr, bcr); diff --git a/src/core/psxemulator.cc b/src/core/psxemulator.cc index 902cdc9a0..378339847 100644 --- a/src/core/psxemulator.cc +++ b/src/core/psxemulator.cc @@ -98,7 +98,7 @@ void PCSX::Emulator::EmuUpdate() { } if (m_config.RewindInterval > 0 && !(++m_rewind_counter % m_config.RewindInterval)) { - //CreateRewindState(); + // CreateRewindState(); } } diff --git a/src/core/psxhle.cc b/src/core/psxhle.cc index d00bffcf2..f669129ba 100644 --- a/src/core/psxhle.cc +++ b/src/core/psxhle.cc @@ -88,7 +88,7 @@ typedef struct { } EXEC; static void hleExecRet() { - EXEC *header = (EXEC *)PSXM(PCSX::g_emulator.m_psxCpu->m_psxRegs.GPR.n.s0); + EXEC* header = (EXEC*)PSXM(PCSX::g_emulator.m_psxCpu->m_psxRegs.GPR.n.s0); PCSX::g_system->biosPrintf("ExecRet %x: %x\n", PCSX::g_emulator.m_psxCpu->m_psxRegs.GPR.n.s0, header->ret); @@ -102,8 +102,6 @@ static void hleExecRet() { PCSX::g_emulator.m_psxCpu->m_psxRegs.pc = PCSX::g_emulator.m_psxCpu->m_psxRegs.GPR.n.ra; } -static void hleException() { - PCSX::g_emulator.m_psxBios->psxBiosException(); -} +static void hleException() { PCSX::g_emulator.m_psxBios->psxBiosException(); } const HLE_t psxHLEt[8] = {hleDummy, hleA0, hleB0, hleC0, hleBootstrap, hleExecRet, hleException, hleDummy}; diff --git a/src/core/psxinterpreter.cc b/src/core/psxinterpreter.cc index c1ba646cb..fce308687 100644 --- a/src/core/psxinterpreter.cc +++ b/src/core/psxinterpreter.cc @@ -50,12 +50,12 @@ class InterpretedCPU : public PCSX::R3000Acpu { typedef void (InterpretedCPU::*intFunc_t)(); typedef const intFunc_t cIntFunc_t; - cIntFunc_t *s_pPsxBSC = NULL; - cIntFunc_t *s_pPsxSPC = NULL; - cIntFunc_t *s_pPsxREG = NULL; - cIntFunc_t *s_pPsxCP0 = NULL; - cIntFunc_t *s_pPsxCP2 = NULL; - cIntFunc_t *s_pPsxCP2BSC = NULL; + cIntFunc_t* s_pPsxBSC = NULL; + cIntFunc_t* s_pPsxSPC = NULL; + cIntFunc_t* s_pPsxREG = NULL; + cIntFunc_t* s_pPsxCP0 = NULL; + cIntFunc_t* s_pPsxCP2 = NULL; + cIntFunc_t* s_pPsxCP2BSC = NULL; bool execI(); void doBranch(uint32_t tar); @@ -527,7 +527,7 @@ void InterpretedCPU::psxBREAK() { PCSX::g_emulator.m_psxCpu->m_psxRegs.pc -= 4; PCSX::g_emulator.m_psxCpu->psxException(0x30, m_inDelaySlot); if (m_inDelaySlot) { - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; if (!delayedLoad.pcActive) abort(); delayedLoad.pcActive = false; } @@ -537,7 +537,7 @@ void InterpretedCPU::psxSYSCALL() { PCSX::g_emulator.m_psxCpu->m_psxRegs.pc -= 4; PCSX::g_emulator.m_psxCpu->psxException(0x20, m_inDelaySlot); if (m_inDelaySlot) { - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; if (!delayedLoad.pcActive) abort(); delayedLoad.pcActive = false; } @@ -684,8 +684,7 @@ void InterpretedCPU::psxSWL() { uint32_t shift = addr & 3; uint32_t mem = PCSX::g_emulator.m_psxMem->psxMemRead32(addr & ~3); - PCSX::g_emulator.m_psxMem->psxMemWrite32(addr & ~3, - (_u32(_rRt_) >> SWL_SHIFT[shift]) | (mem & SWL_MASK[shift])); + PCSX::g_emulator.m_psxMem->psxMemWrite32(addr & ~3, (_u32(_rRt_) >> SWL_SHIFT[shift]) | (mem & SWL_MASK[shift])); /* Mem = 1234. Reg = abcd @@ -701,8 +700,7 @@ void InterpretedCPU::psxSWR() { uint32_t shift = addr & 3; uint32_t mem = PCSX::g_emulator.m_psxMem->psxMemRead32(addr & ~3); - PCSX::g_emulator.m_psxMem->psxMemWrite32(addr & ~3, - (_u32(_rRt_) << SWR_SHIFT[shift]) | (mem & SWR_MASK[shift])); + PCSX::g_emulator.m_psxMem->psxMemWrite32(addr & ~3, (_u32(_rRt_) << SWR_SHIFT[shift]) | (mem & SWR_MASK[shift])); /* Mem = 1234. Reg = abcd @@ -1298,9 +1296,9 @@ inline bool InterpretedCPU::execI() { m_nextIsDelaySlot = false; } InterceptBIOS(); - uint32_t *code = PCSX::g_emulator.m_psxCpu->Read_ICache(PCSX::g_emulator.m_psxCpu->m_psxRegs.pc, false); + uint32_t* code = PCSX::g_emulator.m_psxCpu->Read_ICache(PCSX::g_emulator.m_psxCpu->m_psxRegs.pc, false); PCSX::g_emulator.m_psxCpu->m_psxRegs.code = ((code == NULL) ? 0 : SWAP_LE32(*code)); - const bool &debug = PCSX::g_emulator.settings.get(); + const bool& debug = PCSX::g_emulator.settings.get(); debugI(); @@ -1313,7 +1311,7 @@ inline bool InterpretedCPU::execI() { (*this.*func)(); m_currentDelayedLoad ^= 1; - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; if (delayedLoad.active) { if (delayedLoad.index >= 32) abort(); m_psxRegs.GPR.r[delayedLoad.index] &= delayedLoad.mask; diff --git a/src/core/psxmem.cc b/src/core/psxmem.cc index 8d6d6ed91..dbe34b9d0 100644 --- a/src/core/psxmem.cc +++ b/src/core/psxmem.cc @@ -30,13 +30,13 @@ int PCSX::Memory::psxMemInit() { int i; - g_psxMemRLUT = (uint8_t **)calloc(0x10000, sizeof(void *)); - g_psxMemWLUT = (uint8_t **)calloc(0x10000, sizeof(void *)); + g_psxMemRLUT = (uint8_t**)calloc(0x10000, sizeof(void*)); + g_psxMemWLUT = (uint8_t**)calloc(0x10000, sizeof(void*)); - g_psxM = (uint8_t *)calloc(0x00200000, 1); - g_psxP = (uint8_t *)calloc(0x00010000, 1); - g_psxH = (uint8_t *)calloc(0x00010000, 1); - g_psxR = (uint8_t *)calloc(0x00080000, 1); + g_psxM = (uint8_t*)calloc(0x00200000, 1); + g_psxP = (uint8_t*)calloc(0x00010000, 1); + g_psxH = (uint8_t*)calloc(0x00010000, 1); + g_psxR = (uint8_t*)calloc(0x00080000, 1); if (g_psxMemRLUT == NULL || g_psxMemWLUT == NULL || g_psxM == NULL || g_psxP == NULL || g_psxH == NULL) { PCSX::g_system->message("%s", _("Error allocating memory!")); @@ -44,27 +44,27 @@ int PCSX::Memory::psxMemInit() { } // MemR - for (i = 0; i < 0x80; i++) g_psxMemRLUT[i + 0x0000] = (uint8_t *)&g_psxM[(i & 0x1f) << 16]; + for (i = 0; i < 0x80; i++) g_psxMemRLUT[i + 0x0000] = (uint8_t*)&g_psxM[(i & 0x1f) << 16]; - memcpy(g_psxMemRLUT + 0x8000, g_psxMemRLUT, 0x80 * sizeof(void *)); - memcpy(g_psxMemRLUT + 0xa000, g_psxMemRLUT, 0x80 * sizeof(void *)); + memcpy(g_psxMemRLUT + 0x8000, g_psxMemRLUT, 0x80 * sizeof(void*)); + memcpy(g_psxMemRLUT + 0xa000, g_psxMemRLUT, 0x80 * sizeof(void*)); - g_psxMemRLUT[0x1f00] = (uint8_t *)g_psxP; - g_psxMemRLUT[0x1f80] = (uint8_t *)g_psxH; + g_psxMemRLUT[0x1f00] = (uint8_t*)g_psxP; + g_psxMemRLUT[0x1f80] = (uint8_t*)g_psxH; - for (i = 0; i < 0x08; i++) g_psxMemRLUT[i + 0x1fc0] = (uint8_t *)&g_psxR[i << 16]; + for (i = 0; i < 0x08; i++) g_psxMemRLUT[i + 0x1fc0] = (uint8_t*)&g_psxR[i << 16]; - memcpy(g_psxMemRLUT + 0x9fc0, g_psxMemRLUT + 0x1fc0, 0x08 * sizeof(void *)); - memcpy(g_psxMemRLUT + 0xbfc0, g_psxMemRLUT + 0x1fc0, 0x08 * sizeof(void *)); + memcpy(g_psxMemRLUT + 0x9fc0, g_psxMemRLUT + 0x1fc0, 0x08 * sizeof(void*)); + memcpy(g_psxMemRLUT + 0xbfc0, g_psxMemRLUT + 0x1fc0, 0x08 * sizeof(void*)); // MemW - for (i = 0; i < 0x80; i++) g_psxMemWLUT[i + 0x0000] = (uint8_t *)&g_psxM[(i & 0x1f) << 16]; + for (i = 0; i < 0x80; i++) g_psxMemWLUT[i + 0x0000] = (uint8_t*)&g_psxM[(i & 0x1f) << 16]; - memcpy(g_psxMemWLUT + 0x8000, g_psxMemWLUT, 0x80 * sizeof(void *)); - memcpy(g_psxMemWLUT + 0xa000, g_psxMemWLUT, 0x80 * sizeof(void *)); + memcpy(g_psxMemWLUT + 0x8000, g_psxMemWLUT, 0x80 * sizeof(void*)); + memcpy(g_psxMemWLUT + 0xa000, g_psxMemWLUT, 0x80 * sizeof(void*)); - g_psxMemWLUT[0x1f00] = (uint8_t *)g_psxP; - g_psxMemWLUT[0x1f80] = (uint8_t *)g_psxH; + g_psxMemWLUT[0x1f00] = (uint8_t*)g_psxP; + g_psxMemWLUT[0x1f80] = (uint8_t*)g_psxH; return 0; } @@ -79,7 +79,7 @@ void PCSX::Memory::psxMemReset() { // Load BIOS PCSX::u8string biosPath = PCSX::g_emulator.settings.get().string(); if (!PCSX::g_emulator.settings.get()) { - File *f = new File(biosPath); + File* f = new File(biosPath); if (f->failed()) { PCSX::g_system->message(_("Could not open BIOS:\"%s\". Enabling HLE Bios!\n"), biosPath.c_str()); PCSX::g_emulator.settings.get() = true; @@ -92,14 +92,14 @@ void PCSX::Memory::psxMemReset() { delete f; if (g_emulator.m_psxBios->m_realBiosLoaded) { - for (auto &overlay : g_emulator.settings.get()) { + for (auto& overlay : g_emulator.settings.get()) { if (!overlay.get()) continue; - const auto &filename = overlay.get(); + const auto& filename = overlay.get(); auto foffset = overlay.get(); auto loffset = overlay.get(); auto lsize = overlay.get(); bool failed = false; - File *f = new File(filename); + File* f = new File(filename); if (f->failed()) { PCSX::g_system->message(_("Could not open BIOS Overlay:\"%s\"!\n"), filename.string().c_str()); @@ -195,7 +195,7 @@ void PCSX::Memory::psxMemShutdown() { static int m_writeok = 1; uint8_t PCSX::Memory::psxMemRead8(uint32_t mem) { - char *p; + char* p; uint32_t t; if (!PCSX::g_emulator.config().MemHack) { @@ -209,12 +209,12 @@ uint8_t PCSX::Memory::psxMemRead8(uint32_t mem) { else return PCSX::g_emulator.m_hw->psxHwRead8(mem); } else { - p = (char *)(g_psxMemRLUT[t]); + p = (char*)(g_psxMemRLUT[t]); if (p != NULL) { if (PCSX::g_emulator.settings.get()) { PCSX::g_emulator.m_debug->checkBP(mem, PCSX::Debug::BR1); } - return *(uint8_t *)(p + (mem & 0xffff)); + return *(uint8_t*)(p + (mem & 0xffff)); } else { PSXMEM_LOG("err lb %8.8lx\n", mem); return 0; @@ -223,7 +223,7 @@ uint8_t PCSX::Memory::psxMemRead8(uint32_t mem) { } uint16_t PCSX::Memory::psxMemRead16(uint32_t mem) { - char *p; + char* p; uint32_t t; if (!PCSX::g_emulator.config().MemHack) { @@ -237,12 +237,12 @@ uint16_t PCSX::Memory::psxMemRead16(uint32_t mem) { else return PCSX::g_emulator.m_hw->psxHwRead16(mem); } else { - p = (char *)(g_psxMemRLUT[t]); + p = (char*)(g_psxMemRLUT[t]); if (p != NULL) { if (PCSX::g_emulator.settings.get()) { PCSX::g_emulator.m_debug->checkBP(mem, PCSX::Debug::BR2); } - return SWAP_LEu16(*(uint16_t *)(p + (mem & 0xffff))); + return SWAP_LEu16(*(uint16_t*)(p + (mem & 0xffff))); } else { PSXMEM_LOG("err lh %8.8lx\n", mem); return 0; @@ -251,7 +251,7 @@ uint16_t PCSX::Memory::psxMemRead16(uint32_t mem) { } uint32_t PCSX::Memory::psxMemRead32(uint32_t mem) { - char *p; + char* p; uint32_t t; if (!PCSX::g_emulator.config().MemHack) { @@ -265,12 +265,12 @@ uint32_t PCSX::Memory::psxMemRead32(uint32_t mem) { else return PCSX::g_emulator.m_hw->psxHwRead32(mem); } else { - p = (char *)(g_psxMemRLUT[t]); + p = (char*)(g_psxMemRLUT[t]); if (p != NULL) { if (PCSX::g_emulator.settings.get()) { PCSX::g_emulator.m_debug->checkBP(mem, PCSX::Debug::BR4); } - return SWAP_LEu32(*(uint32_t *)(p + (mem & 0xffff))); + return SWAP_LEu32(*(uint32_t*)(p + (mem & 0xffff))); } else { if (m_writeok) { PSXMEM_LOG("err lw %8.8lx\n", mem); @@ -281,7 +281,7 @@ uint32_t PCSX::Memory::psxMemRead32(uint32_t mem) { } void PCSX::Memory::psxMemWrite8(uint32_t mem, uint8_t value) { - char *p; + char* p; uint32_t t; if (!PCSX::g_emulator.config().MemHack) { @@ -295,12 +295,12 @@ void PCSX::Memory::psxMemWrite8(uint32_t mem, uint8_t value) { else PCSX::g_emulator.m_hw->psxHwWrite8(mem, value); } else { - p = (char *)(g_psxMemWLUT[t]); + p = (char*)(g_psxMemWLUT[t]); if (p != NULL) { if (PCSX::g_emulator.settings.get()) { PCSX::g_emulator.m_debug->checkBP(mem, PCSX::Debug::BW1); } - *(uint8_t *)(p + (mem & 0xffff)) = value; + *(uint8_t*)(p + (mem & 0xffff)) = value; PCSX::g_emulator.m_psxCpu->Clear((mem & (~3)), 1); } else { PSXMEM_LOG("err sb %8.8lx\n", mem); @@ -309,7 +309,7 @@ void PCSX::Memory::psxMemWrite8(uint32_t mem, uint8_t value) { } void PCSX::Memory::psxMemWrite16(uint32_t mem, uint16_t value) { - char *p; + char* p; uint32_t t; if (!PCSX::g_emulator.config().MemHack) { @@ -323,12 +323,12 @@ void PCSX::Memory::psxMemWrite16(uint32_t mem, uint16_t value) { else PCSX::g_emulator.m_hw->psxHwWrite16(mem, value); } else { - p = (char *)(g_psxMemWLUT[t]); + p = (char*)(g_psxMemWLUT[t]); if (p != NULL) { if (PCSX::g_emulator.settings.get()) { PCSX::g_emulator.m_debug->checkBP(mem, PCSX::Debug::BW2); } - *(uint16_t *)(p + (mem & 0xffff)) = SWAP_LEu16(value); + *(uint16_t*)(p + (mem & 0xffff)) = SWAP_LEu16(value); PCSX::g_emulator.m_psxCpu->Clear((mem & (~3)), 1); } else { PSXMEM_LOG("err sh %8.8lx\n", mem); @@ -337,7 +337,7 @@ void PCSX::Memory::psxMemWrite16(uint32_t mem, uint16_t value) { } void PCSX::Memory::psxMemWrite32(uint32_t mem, uint32_t value) { - char *p; + char* p; uint32_t t; if (!PCSX::g_emulator.config().MemHack) { @@ -352,12 +352,12 @@ void PCSX::Memory::psxMemWrite32(uint32_t mem, uint32_t value) { else PCSX::g_emulator.m_hw->psxHwWrite32(mem, value); } else { - p = (char *)(g_psxMemWLUT[t]); + p = (char*)(g_psxMemWLUT[t]); if (p != NULL) { if (PCSX::g_emulator.settings.get()) { PCSX::g_emulator.m_debug->checkBP(mem, PCSX::Debug::BW4); } - *(uint32_t *)(p + (mem & 0xffff)) = SWAP_LEu32(value); + *(uint32_t*)(p + (mem & 0xffff)) = SWAP_LEu32(value); PCSX::g_emulator.m_psxCpu->Clear(mem, 1); } else { if (mem != 0xfffe0130) { @@ -375,9 +375,9 @@ void PCSX::Memory::psxMemWrite32(uint32_t mem, uint32_t value) { case 0x804: if (m_writeok == 0) break; m_writeok = 0; - memset(g_psxMemWLUT + 0x0000, 0, 0x80 * sizeof(void *)); - memset(g_psxMemWLUT + 0x8000, 0, 0x80 * sizeof(void *)); - memset(g_psxMemWLUT + 0xa000, 0, 0x80 * sizeof(void *)); + memset(g_psxMemWLUT + 0x0000, 0, 0x80 * sizeof(void*)); + memset(g_psxMemWLUT + 0x8000, 0, 0x80 * sizeof(void*)); + memset(g_psxMemWLUT + 0xa000, 0, 0x80 * sizeof(void*)); PCSX::g_emulator.m_psxCpu->m_psxRegs.ICache_valid = false; break; @@ -385,9 +385,9 @@ void PCSX::Memory::psxMemWrite32(uint32_t mem, uint32_t value) { case 0x1e988: if (m_writeok == 1) break; m_writeok = 1; - for (i = 0; i < 0x80; i++) g_psxMemWLUT[i + 0x0000] = (uint8_t *)&g_psxM[(i & 0x1f) << 16]; - memcpy(g_psxMemWLUT + 0x8000, g_psxMemWLUT, 0x80 * sizeof(void *)); - memcpy(g_psxMemWLUT + 0xa000, g_psxMemWLUT, 0x80 * sizeof(void *)); + for (i = 0; i < 0x80; i++) g_psxMemWLUT[i + 0x0000] = (uint8_t*)&g_psxM[(i & 0x1f) << 16]; + memcpy(g_psxMemWLUT + 0x8000, g_psxMemWLUT, 0x80 * sizeof(void*)); + memcpy(g_psxMemWLUT + 0xa000, g_psxMemWLUT, 0x80 * sizeof(void*)); break; default: PSXMEM_LOG("unk %8.8lx = %x\n", mem, value); @@ -398,20 +398,20 @@ void PCSX::Memory::psxMemWrite32(uint32_t mem, uint32_t value) { } } -void *PCSX::Memory::psxMemPointer(uint32_t mem) { - char *p; +void* PCSX::Memory::psxMemPointer(uint32_t mem) { + char* p; uint32_t t; t = mem >> 16; if (t == 0x1f80 || t == 0x9f80 || t == 0xbf80) { if ((mem & 0xffff) < 0x400) - return (void *)&g_psxH[mem]; + return (void*)&g_psxH[mem]; else return NULL; } else { - p = (char *)(g_psxMemWLUT[t]); + p = (char*)(g_psxMemWLUT[t]); if (p != NULL) { - return (void *)(p + (mem & 0xffff)); + return (void*)(p + (mem & 0xffff)); } return NULL; } diff --git a/src/core/psxmem.h b/src/core/psxmem.h index 00f7d177e..7bcad4b9a 100644 --- a/src/core/psxmem.h +++ b/src/core/psxmem.h @@ -42,13 +42,13 @@ namespace PCSX { class Memory { public: - uint8_t *g_psxM = NULL; // Kernel & User Memory (2 Meg) - uint8_t *g_psxP = NULL; // Parallel Port (64K) - uint8_t *g_psxR = NULL; // BIOS ROM (512K) - uint8_t *g_psxH = NULL; // Scratch Pad (1K) & Hardware Registers (8K) + uint8_t* g_psxM = NULL; // Kernel & User Memory (2 Meg) + uint8_t* g_psxP = NULL; // Parallel Port (64K) + uint8_t* g_psxR = NULL; // BIOS ROM (512K) + uint8_t* g_psxH = NULL; // Scratch Pad (1K) & Hardware Registers (8K) - uint8_t **g_psxMemWLUT = NULL; - uint8_t **g_psxMemRLUT = NULL; + uint8_t** g_psxMemWLUT = NULL; + uint8_t** g_psxMemRLUT = NULL; /* Playstation Memory Map (from Playstation doc by Joshua Walker) 0x0000_0000-0x0000_ffff Kernel (64K) @@ -71,64 +71,64 @@ class Memory { public: #define psxMs8(mem) PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff] -#define psxMs16(mem) (SWAP_LE16(*(int16_t *)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff])) -#define psxMs32(mem) (SWAP_LE32(*(int32_t *)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff])) -#define psxMu8(mem) (*(uint8_t *)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) -#define psxMu16(mem) (SWAP_LE16(*(uint16_t *)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff])) -#define psxMu32(mem) (SWAP_LE32(*(uint32_t *)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff])) +#define psxMs16(mem) (SWAP_LE16(*(int16_t*)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff])) +#define psxMs32(mem) (SWAP_LE32(*(int32_t*)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff])) +#define psxMu8(mem) (*(uint8_t*)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) +#define psxMu16(mem) (SWAP_LE16(*(uint16_t*)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff])) +#define psxMu32(mem) (SWAP_LE32(*(uint32_t*)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff])) #define psxMs8ref(mem) PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff] -#define psxMs16ref(mem) (*(int16_t *)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) -#define psxMs32ref(mem) (*(int32_t *)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) -#define psxMu8ref(mem) (*(uint8_t *)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) -#define psxMu16ref(mem) (*(uint16_t *)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) -#define psxMu32ref(mem) (*(uint32_t *)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) +#define psxMs16ref(mem) (*(int16_t*)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) +#define psxMs32ref(mem) (*(int32_t*)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) +#define psxMu8ref(mem) (*(uint8_t*)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) +#define psxMu16ref(mem) (*(uint16_t*)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) +#define psxMu32ref(mem) (*(uint32_t*)&PCSX::g_emulator.m_psxMem->g_psxM[(mem)&0x1fffff]) #define psxPs8(mem) PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff] -#define psxPs16(mem) (SWAP_LE16(*(int16_t *)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff])) -#define psxPs32(mem) (SWAP_LE32(*(int32_t *)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff])) -#define psxPu8(mem) (*(uint8_t *)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) -#define psxPu16(mem) (SWAP_LE16(*(uint16_t *)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff])) -#define psxPu32(mem) (SWAP_LE32(*(uint32_t *)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff])) +#define psxPs16(mem) (SWAP_LE16(*(int16_t*)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff])) +#define psxPs32(mem) (SWAP_LE32(*(int32_t*)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff])) +#define psxPu8(mem) (*(uint8_t*)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) +#define psxPu16(mem) (SWAP_LE16(*(uint16_t*)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff])) +#define psxPu32(mem) (SWAP_LE32(*(uint32_t*)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff])) #define psxPs8ref(mem) PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff] -#define psxPs16ref(mem) (*(int16_t *)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) -#define psxPs32ref(mem) (*(int32_t *)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) -#define psxPu8ref(mem) (*(uint8_t *)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) -#define psxPu16ref(mem) (*(uint16_t *)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) -#define psxPu32ref(mem) (*(uint32_t *)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) +#define psxPs16ref(mem) (*(int16_t*)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) +#define psxPs32ref(mem) (*(int32_t*)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) +#define psxPu8ref(mem) (*(uint8_t*)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) +#define psxPu16ref(mem) (*(uint16_t*)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) +#define psxPu32ref(mem) (*(uint32_t*)&PCSX::g_emulator.m_psxMem->g_psxP[(mem)&0xffff]) #define psxRs8(mem) PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff] -#define psxRs16(mem) (SWAP_LE16(*(int16_t *)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff])) -#define psxRs32(mem) (SWAP_LE32(*(int32_t *)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff])) -#define psxRu8(mem) (*(uint8_t *)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) -#define psxRu16(mem) (SWAP_LE16(*(uint16_t *)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff])) -#define psxRu32(mem) (SWAP_LE32(*(uint32_t *)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff])) +#define psxRs16(mem) (SWAP_LE16(*(int16_t*)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff])) +#define psxRs32(mem) (SWAP_LE32(*(int32_t*)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff])) +#define psxRu8(mem) (*(uint8_t*)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) +#define psxRu16(mem) (SWAP_LE16(*(uint16_t*)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff])) +#define psxRu32(mem) (SWAP_LE32(*(uint32_t*)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff])) #define psxRs8ref(mem) PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff] -#define psxRs16ref(mem) (*(int16_t *)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) -#define psxRs32ref(mem) (*(int32_t *)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) -#define psxRu8ref(mem) (*(uint8_t *)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) -#define psxRu16ref(mem) (*(uint16_t *)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) -#define psxRu32ref(mem) (*(uint32_t *)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) +#define psxRs16ref(mem) (*(int16_t*)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) +#define psxRs32ref(mem) (*(int32_t*)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) +#define psxRu8ref(mem) (*(uint8_t*)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) +#define psxRu16ref(mem) (*(uint16_t*)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) +#define psxRu32ref(mem) (*(uint32_t*)&PCSX::g_emulator.m_psxMem->g_psxR[(mem)&0x7ffff]) #define psxHs8(mem) PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff] -#define psxHs16(mem) (SWAP_LE16(*(int16_t *)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff])) -#define psxHs32(mem) (SWAP_LE32(*(int32_t *)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff])) -#define psxHu8(mem) (*(uint8_t *)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) -#define psxHu16(mem) (SWAP_LE16(*(uint16_t *)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff])) -#define psxHu32(mem) (SWAP_LE32(*(uint32_t *)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff])) +#define psxHs16(mem) (SWAP_LE16(*(int16_t*)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff])) +#define psxHs32(mem) (SWAP_LE32(*(int32_t*)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff])) +#define psxHu8(mem) (*(uint8_t*)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) +#define psxHu16(mem) (SWAP_LE16(*(uint16_t*)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff])) +#define psxHu32(mem) (SWAP_LE32(*(uint32_t*)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff])) #define psxHs8ref(mem) PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff] -#define psxHs16ref(mem) (*(int16_t *)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) -#define psxHs32ref(mem) (*(int32_t *)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) -#define psxHu8ref(mem) (*(uint8_t *)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) -#define psxHu16ref(mem) (*(uint16_t *)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) -#define psxHu32ref(mem) (*(uint32_t *)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) +#define psxHs16ref(mem) (*(int16_t*)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) +#define psxHs32ref(mem) (*(int32_t*)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) +#define psxHu8ref(mem) (*(uint8_t*)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) +#define psxHu16ref(mem) (*(uint16_t*)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) +#define psxHu32ref(mem) (*(uint32_t*)&PCSX::g_emulator.m_psxMem->g_psxH[(mem)&0xffff]) #define PSXM(mem) \ (PCSX::g_emulator.m_psxMem->g_psxMemRLUT[(mem) >> 16] == 0 \ ? NULL \ - : (uint8_t *)(PCSX::g_emulator.m_psxMem->g_psxMemRLUT[(mem) >> 16] + ((mem)&0xffff))) -#define PSXMs8(mem) (*(int8_t *)PSXM(mem)) -#define PSXMs16(mem) (SWAP_LE16(*(int16_t *)PSXM(mem))) -#define PSXMs32(mem) (SWAP_LE32(*(int32_t *)PSXM(mem))) -#define PSXMu8(mem) (*(uint8_t *)PSXM(mem)) -#define PSXMu16(mem) (SWAP_LE16(*(uint16_t *)PSXM(mem))) -#define PSXMu32(mem) (SWAP_LE32(*(uint32_t *)PSXM(mem))) -#define PSXMu32ref(mem) (*(uint32_t *)PSXM(mem)) + : (uint8_t*)(PCSX::g_emulator.m_psxMem->g_psxMemRLUT[(mem) >> 16] + ((mem)&0xffff))) +#define PSXMs8(mem) (*(int8_t*)PSXM(mem)) +#define PSXMs16(mem) (SWAP_LE16(*(int16_t*)PSXM(mem))) +#define PSXMs32(mem) (SWAP_LE32(*(int32_t*)PSXM(mem))) +#define PSXMu8(mem) (*(uint8_t*)PSXM(mem)) +#define PSXMu16(mem) (SWAP_LE16(*(uint16_t*)PSXM(mem))) +#define PSXMu32(mem) (SWAP_LE32(*(uint32_t*)PSXM(mem))) +#define PSXMu32ref(mem) (*(uint32_t*)PSXM(mem)) int psxMemInit(); void psxMemReset(); @@ -140,7 +140,7 @@ class Memory { void psxMemWrite8(uint32_t mem, uint8_t value); void psxMemWrite16(uint32_t mem, uint16_t value); void psxMemWrite32(uint32_t mem, uint32_t value); - void *psxMemPointer(uint32_t mem); + void* psxMemPointer(uint32_t mem); }; } // namespace PCSX diff --git a/src/core/r3000a.h b/src/core/r3000a.h index 91b308c5c..f0fe1ea7c 100644 --- a/src/core/r3000a.h +++ b/src/core/r3000a.h @@ -185,25 +185,25 @@ typedef struct { #if defined(__BIGENDIAN__) -#define _i32(x) reinterpret_cast(&x)[0] -#define _u32(x) reinterpret_cast(&x)[0] +#define _i32(x) reinterpret_cast(&x)[0] +#define _u32(x) reinterpret_cast(&x)[0] -#define _i16(x) reinterpret_cast(&x)[1] -#define _u16(x) reinterpret_cast(&x)[1] +#define _i16(x) reinterpret_cast(&x)[1] +#define _u16(x) reinterpret_cast(&x)[1] -#define _i8(x) reinterpret_cast(&x)[3] -#define _u8(x) reinterpret_cast(&x)[3] +#define _i8(x) reinterpret_cast(&x)[3] +#define _u8(x) reinterpret_cast(&x)[3] #else -#define _i32(x) reinterpret_cast(&x)[0] -#define _u32(x) reinterpret_cast(&x)[0] +#define _i32(x) reinterpret_cast(&x)[0] +#define _u32(x) reinterpret_cast(&x)[0] -#define _i16(x) reinterpret_cast(&x)[0] -#define _u16(x) reinterpret_cast(&x)[0] +#define _i16(x) reinterpret_cast(&x)[0] +#define _u16(x) reinterpret_cast(&x)[0] -#define _i8(x) reinterpret_cast(&x)[0] -#define _u8(x) reinterpret_cast(&x)[0] +#define _i8(x) reinterpret_cast(&x)[0] +#define _u8(x) reinterpret_cast(&x)[0] #endif @@ -291,7 +291,7 @@ class R3000Acpu { virtual void SetPGXPMode(uint32_t pgxpMode) = 0; virtual bool Implemented() = 0; - const std::string &getName() { return m_name; } + const std::string& getName() { return m_name; } public: static int psxInit(); @@ -324,30 +324,30 @@ class R3000Acpu { bool pcActive = false; } m_delayedLoadInfo[2]; unsigned m_currentDelayedLoad = 0; - uint32_t &delayedLoadRef(unsigned reg, uint32_t mask = 0) { + uint32_t& delayedLoadRef(unsigned reg, uint32_t mask = 0) { if (reg >= 32) abort(); - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.active = true; delayedLoad.index = reg; delayedLoad.mask = mask; return delayedLoad.value; } void delayedLoad(unsigned reg, uint32_t value, uint32_t mask = 0) { - auto &ref = delayedLoadRef(reg, mask); + auto& ref = delayedLoadRef(reg, mask); ref = value; } - uint32_t &delayedPCLoad() { - auto &delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; + uint32_t& delayedPCLoad() { + auto& delayedLoad = m_delayedLoadInfo[m_currentDelayedLoad]; delayedLoad.pcActive = true; return delayedLoad.pcValue; } void delayedPCLoad(uint32_t value) { - auto &ref = delayedPCLoad(); + auto& ref = delayedPCLoad(); ref = value; } protected: - R3000Acpu(const std::string &name) : m_name(name) {} + R3000Acpu(const std::string& name) : m_name(name) {} static inline const uint32_t MASKS[7] = {0, 0xffffff, 0xffff, 0xff, 0xff000000, 0xffff0000, 0xffffff00}; static inline const uint32_t LWL_MASK[4] = {0xffffff, 0xffff, 0xff, 0}; static inline const uint32_t LWL_MASK_INDEX[4] = {1, 2, 3, 0}; @@ -362,7 +362,7 @@ class R3000Acpu { inline bool hasToRun() { if (!g_system->running()) return false; if (!m_booted) { - uint32_t &pc = m_psxRegs.pc; + uint32_t& pc = m_psxRegs.pc; if (pc == 0x80030000) { m_booted = true; if (g_emulator.settings.get()) pc = m_psxRegs.GPR.n.ra; @@ -394,7 +394,7 @@ class R3000Acpu { if (m_savedCounters[0][call] == 0) { if (m_breakpointOnNew) g_system->pause(); if (m_logNewSyscalls) { - const char *name = Bios::getA0name(call); + const char* name = Bios::getA0name(call); g_system->printf("Bios call a0: %s (%x) %x,%x,%x,%x\n", name, call, r.a0, r.a1, r.a2, r.a3); } m_counters[0][call]++; @@ -418,7 +418,7 @@ class R3000Acpu { if (m_savedCounters[1][call] == 0) { if (m_breakpointOnNew) g_system->pause(); if (m_logNewSyscalls) { - const char *name = Bios::getB0name(call); + const char* name = Bios::getB0name(call); g_system->printf("Bios call b0: %s (%x) %x,%x,%x,%x\n", name, call, r.a0, r.a1, r.a2, r.a3); } } @@ -455,7 +455,7 @@ class R3000Acpu { if (m_savedCounters[2][call] == 0) { if (m_breakpointOnNew) g_system->pause(); if (m_logNewSyscalls) { - const char *name = Bios::getC0name(call); + const char* name = Bios::getC0name(call); g_system->printf("Bios call c0: %s (%x) %x,%x,%x,%x\n", name, call, r.a0, r.a1, r.a2, r.a3); } } @@ -515,7 +515,7 @@ class R3000Acpu { bool m_breakpointOnNew = false; bool m_debugKernel = false; bool m_logEvents = false; - const uint64_t *getCounters(int syscall) { return m_counters[syscall]; } + const uint64_t* getCounters(int syscall) { return m_counters[syscall]; } /* Formula One 2001 - Use old CPU cache code when the RAM location is @@ -526,7 +526,7 @@ Formula One 2001 - Isolate D-cache from RAM */ - inline uint32_t *Read_ICache(uint32_t pc, bool isolate) { + inline uint32_t* Read_ICache(uint32_t pc, bool isolate) { uint32_t pc_bank, pc_offset, pc_cache; uint8_t *IAddr, *ICode; @@ -546,13 +546,13 @@ Formula One 2001 } // uncached - if (pc_bank >= 0xa0) return (uint32_t *)PSXM(pc); + if (pc_bank >= 0xa0) return (uint32_t*)PSXM(pc); // cached - RAM if (pc_bank == 0x80 || pc_bank == 0x00) { - if (SWAP_LE32(*(uint32_t *)(IAddr + pc_cache)) == pc_offset) { + if (SWAP_LE32(*(uint32_t*)(IAddr + pc_cache)) == pc_offset) { // Cache hit - return last opcode used - return (uint32_t *)(ICode + pc_cache); + return (uint32_t*)(ICode + pc_cache); } else { // Cache miss - addresses don't match // - default: 0xffffffff (not init) @@ -563,21 +563,21 @@ Formula One 2001 pc_cache &= ~0xf; // address line - *(uint32_t *)(IAddr + pc_cache + 0x0) = SWAP_LE32(pc_offset + 0x0); - *(uint32_t *)(IAddr + pc_cache + 0x4) = SWAP_LE32(pc_offset + 0x4); - *(uint32_t *)(IAddr + pc_cache + 0x8) = SWAP_LE32(pc_offset + 0x8); - *(uint32_t *)(IAddr + pc_cache + 0xc) = SWAP_LE32(pc_offset + 0xc); + *(uint32_t*)(IAddr + pc_cache + 0x0) = SWAP_LE32(pc_offset + 0x0); + *(uint32_t*)(IAddr + pc_cache + 0x4) = SWAP_LE32(pc_offset + 0x4); + *(uint32_t*)(IAddr + pc_cache + 0x8) = SWAP_LE32(pc_offset + 0x8); + *(uint32_t*)(IAddr + pc_cache + 0xc) = SWAP_LE32(pc_offset + 0xc); // opcode line pc_offset = pc & ~0xf; - *(uint32_t *)(ICode + pc_cache + 0x0) = psxMu32ref(pc_offset + 0x0); - *(uint32_t *)(ICode + pc_cache + 0x4) = psxMu32ref(pc_offset + 0x4); - *(uint32_t *)(ICode + pc_cache + 0x8) = psxMu32ref(pc_offset + 0x8); - *(uint32_t *)(ICode + pc_cache + 0xc) = psxMu32ref(pc_offset + 0xc); + *(uint32_t*)(ICode + pc_cache + 0x0) = psxMu32ref(pc_offset + 0x0); + *(uint32_t*)(ICode + pc_cache + 0x4) = psxMu32ref(pc_offset + 0x4); + *(uint32_t*)(ICode + pc_cache + 0x8) = psxMu32ref(pc_offset + 0x8); + *(uint32_t*)(ICode + pc_cache + 0xc) = psxMu32ref(pc_offset + 0xc); } // normal code - return (uint32_t *)PSXM(pc); + return (uint32_t*)PSXM(pc); } } @@ -586,7 +586,7 @@ Formula One 2001 */ // default - return (uint32_t *)PSXM(pc); + return (uint32_t*)PSXM(pc); } private: diff --git a/src/core/sio.cc b/src/core/sio.cc index d7751cf6e..49627c300 100644 --- a/src/core/sio.cc +++ b/src/core/sio.cc @@ -396,9 +396,9 @@ void PCSX::SIO::interrupt() { } void PCSX::SIO::LoadMcd(int mcd, const PCSX::u8string str) { - FILE *f; - char *data = NULL; - const char * fname = reinterpret_cast(str.c_str()); + FILE* f; + char* data = NULL; + const char* fname = reinterpret_cast(str.c_str()); if (mcd == 1) { data = g_mcd1Data; @@ -446,9 +446,9 @@ void PCSX::SIO::LoadMcds(const PCSX::u8string mcd1, const PCSX::u8string mcd2) { LoadMcd(2, mcd2); } -void PCSX::SIO::SaveMcd(const PCSX::u8string mcd, const char *data, uint32_t adr, size_t size) { - FILE *f; - const char * fname = reinterpret_cast(mcd.c_str()); +void PCSX::SIO::SaveMcd(const PCSX::u8string mcd, const char* data, uint32_t adr, size_t size) { + FILE* f; + const char* fname = reinterpret_cast(mcd.c_str()); f = fopen(fname, "r+b"); if (f != NULL) { @@ -483,8 +483,8 @@ void PCSX::SIO::SaveMcd(const PCSX::u8string mcd, const char *data, uint32_t adr } void PCSX::SIO::CreateMcd(const PCSX::u8string mcd) { - FILE *f; - const char * fname = reinterpret_cast(mcd.c_str()); + FILE* f; + const char* fname = reinterpret_cast(mcd.c_str()); struct stat buf; int s = MCD_SIZE; int i = 0, j; @@ -634,9 +634,9 @@ void PCSX::SIO::CreateMcd(const PCSX::u8string mcd) { fclose(f); } -void PCSX::SIO::ConvertMcd(const PCSX::u8string mcd, const char *data) { - FILE *f; - const char * fname = reinterpret_cast(mcd.c_str()); +void PCSX::SIO::ConvertMcd(const PCSX::u8string mcd, const char* data) { + FILE* f; + const char* fname = reinterpret_cast(mcd.c_str()); int i = 0; int s = MCD_SIZE; @@ -733,7 +733,7 @@ void PCSX::SIO::ConvertMcd(const PCSX::u8string mcd, const char *data) { } } -void PCSX::SIO::GetMcdBlockInfo(int mcd, int block, McdBlock *Info) { +void PCSX::SIO::GetMcdBlockInfo(int mcd, int block, McdBlock* Info) { char *data = NULL, *ptr, *str, *sstr; unsigned short clut[16]; unsigned short c; @@ -810,12 +810,12 @@ void PCSX::SIO::GetMcdBlockInfo(int mcd, int block, McdBlock *Info) { ptr = data + block * 8192 + 0x60; // icon palette data for (i = 0; i < 16; i++) { - clut[i] = *((unsigned short *)ptr); + clut[i] = *((unsigned short*)ptr); ptr += 2; } for (i = 0; i < Info->IconCount; i++) { - uint16_t *icon = &Info->Icon[i * 16 * 16]; + uint16_t* icon = &Info->Icon[i * 16 * 16]; ptr = data + block * 8192 + 128 + 128 * i; // icon data diff --git a/src/core/sio.h b/src/core/sio.h index 4b6766c13..a43aab4c6 100644 --- a/src/core/sio.h +++ b/src/core/sio.h @@ -131,9 +131,9 @@ class SIO { void LoadMcd(int mcd, const PCSX::u8string str); void LoadMcds(const PCSX::u8string mcd1, const PCSX::u8string mcd2); - void SaveMcd(const PCSX::u8string mcd, const char *data, uint32_t adr, size_t size); + void SaveMcd(const PCSX::u8string mcd, const char* data, uint32_t adr, size_t size); void CreateMcd(const PCSX::u8string mcd); - void ConvertMcd(const PCSX::u8string mcd, const char *data); + void ConvertMcd(const PCSX::u8string mcd, const char* data); typedef struct { char Title[48 + 1]; // Title in ASCII @@ -145,7 +145,7 @@ class SIO { uint8_t Flags; } McdBlock; - void GetMcdBlockInfo(int mcd, int block, McdBlock *info); + void GetMcdBlockInfo(int mcd, int block, McdBlock* info); static void SIO1irq(void) { psxHu32ref(0x1070) |= SWAP_LEu32(0x100); } diff --git a/src/core/spu.cc b/src/core/spu.cc index 0598ba9d1..e919b6e86 100644 --- a/src/core/spu.cc +++ b/src/core/spu.cc @@ -21,8 +21,8 @@ * Sound (SPU) functions. */ -#include "core/r3000a.h" #include "core/spu.h" +#include "core/r3000a.h" void PCSX::SPUInterface::interrupt() { psxHu32ref(0x1070) |= SWAP_LEu32(0x200); } void PCSX::SPUInterface::scheduleInterrupt() { PCSX::g_emulator.m_psxCpu->m_psxRegs.spuInterrupt = true; } diff --git a/src/core/spu.h b/src/core/spu.h index 98d7312bf..a02864a58 100644 --- a/src/core/spu.h +++ b/src/core/spu.h @@ -53,22 +53,21 @@ class SPUInterface { virtual long close(void) = 0; virtual uint16_t readRegister(uint32_t) = 0; virtual void writeRegister(uint32_t, uint16_t) = 0; - virtual void playCDDAchannel(int16_t *, int) = 0; - virtual void playADPCMchannel(xa_decode_t *) = 0; + virtual void playCDDAchannel(int16_t*, int) = 0; + virtual void playADPCMchannel(xa_decode_t*) = 0; virtual void async(uint32_t) = 0; - virtual void writeDMAMem(uint16_t *, int) = 0; - virtual void readDMAMem(uint16_t *, int) = 0; + virtual void writeDMAMem(uint16_t*, int) = 0; + virtual void readDMAMem(uint16_t*, int) = 0; virtual json getCfg() = 0; - virtual void setCfg(const json &j) = 0; + virtual void setCfg(const json& j) = 0; virtual void debug() = 0; virtual bool configure() = 0; - virtual void save(SaveStates::SPU &) = 0; - virtual void load(const SaveStates::SPU &) = 0; + virtual void save(SaveStates::SPU&) = 0; + virtual void load(const SaveStates::SPU&) = 0; bool m_showDebug = false; bool m_showCfg = false; - protected: void scheduleInterrupt(); }; diff --git a/src/core/system.h b/src/core/system.h index 2dbe0e0b9..70d3da9d6 100644 --- a/src/core/system.h +++ b/src/core/system.h @@ -35,7 +35,7 @@ typedef std::u8string u8string; #define MAKEU8(x) x #else typedef std::string u8string; -#define MAKEU8(x) reinterpret_cast(x) +#define MAKEU8(x) reinterpret_cast(x) #endif class System { @@ -45,15 +45,15 @@ class System { virtual void softReset() = 0; virtual void hardReset() = 0; // Printf used by bios syscalls - virtual void biosPrintf(const char *fmt, ...) = 0; - virtual void vbiosPrintf(const char *fmt, va_list va) = 0; + virtual void biosPrintf(const char* fmt, ...) = 0; + virtual void vbiosPrintf(const char* fmt, va_list va) = 0; // Printf used by the code in general, to indicate errors most of the time // TODO: convert them all to logs - virtual void printf(const char *fmt, ...) = 0; + virtual void printf(const char* fmt, ...) = 0; // Add a log line - virtual void log(const char *facility, const char *fmt, va_list a) = 0; + virtual void log(const char* facility, const char* fmt, va_list a) = 0; // Message used to print msg to users - virtual void message(const char *fmt, ...) = 0; + virtual void message(const char* fmt, ...) = 0; // Called on VBlank (to update i.e. pads) virtual void update() = 0; // Returns to the Gui @@ -82,10 +82,10 @@ class System { static inline constexpr uint64_t ctHash(const char (&str)[S]) { return djbProcess(5381, str, S - 1); } - static inline constexpr uint64_t hash(const char *str, size_t n) { return djbProcess(5381, str, n); } - static inline uint64_t hash(const std::string &str) { return djbProcess(5381, str.c_str(), str.length()); } + static inline constexpr uint64_t hash(const char* str, size_t n) { return djbProcess(5381, str, n); } + static inline uint64_t hash(const std::string& str) { return djbProcess(5381, str.c_str(), str.length()); } - const char *getStr(uint64_t hash, const char *str) { + const char* getStr(uint64_t hash, const char* str) { auto ret = m_i18n.find(hash); if (ret == m_i18n.end()) return str; return ret->second.c_str(); @@ -94,7 +94,7 @@ class System { void loadAllLocales() { static const std::map locales = {{"Français", "fr.po"}, {"Deutsch", "de.po"}}; - for (auto &l : locales) { + for (auto& l : locales) { if (loadLocale(l.first, m_binDir / "i18n" / l.second)) { } else if (loadLocale(l.first, std::filesystem::current_path() / "i18n" / l.second)) { } else if (loadLocale(l.first, m_binDir / l.second)) { @@ -104,8 +104,8 @@ class System { } } - bool loadLocale(const std::string &name, const std::filesystem::path &path); - void activateLocale(const std::string &name) { + bool loadLocale(const std::string& name, const std::filesystem::path& path); + void activateLocale(const std::string& name) { if (name == "English") { m_currentLocale = "English"; m_i18n = {}; @@ -119,7 +119,7 @@ class System { std::string localeName() { return m_currentLocale; } std::vector localesNames() { std::vector locales; - for (auto &l : m_locales) { + for (auto& l : m_locales) { locales.push_back(l.first); } return locales; @@ -134,7 +134,7 @@ class System { std::filesystem::path m_binDir; }; -extern System *g_system; +extern System* g_system; } // namespace PCSX diff --git a/src/gpu/soft/draw.cc b/src/gpu/soft/draw.cc index 2a7f4436e..3c249f608 100644 --- a/src/gpu/soft/draw.cc +++ b/src/gpu/soft/draw.cc @@ -115,7 +115,7 @@ int iFastFwd = 0; PSXPoint_t ptCursorPoint[8]; uint16_t usCursorActive = 0; -PCSX::GUI *m_gui; +PCSX::GUI* m_gui; bool bVsync_Key = false; //////////////////////////////////////////////////////////////////////// @@ -141,7 +141,7 @@ void DoClearFrontBuffer(void) // CLEAR PRIMARY BUFFER //////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////// -void ShowGunCursor(unsigned char *surf) { +void ShowGunCursor(unsigned char* surf) { uint16_t dx = (uint16_t)PreviousPSXDisplay.Range.x1; uint16_t dy = (uint16_t)PreviousPSXDisplay.DisplayMode.y; int x, y, iPlayer, sx, ex, sy, ey; @@ -183,9 +183,9 @@ void ShowGunCursor(unsigned char *surf) { if (ey > dy) ey = dy; for (x = tx, y = sy; y < ey; y += 2) // -> do dotted y line - *((uint32_t *)((surf) + (y * pitch) + x * 4)) = crCursorColor32[iPlayer]; + *((uint32_t*)((surf) + (y * pitch) + x * 4)) = crCursorColor32[iPlayer]; for (y = ty, x = sx; x < ex; x += 2) // -> do dotted x line - *((uint32_t *)((surf) + (y * pitch) + x * 4)) = crCursorColor32[iPlayer]; + *((uint32_t*)((surf) + (y * pitch) + x * 4)) = crCursorColor32[iPlayer]; } } } @@ -198,7 +198,7 @@ static void checkGL() { } } -static const GLchar *passThroughVS = GL_SHADER_VERSION R"( +static const GLchar* passThroughVS = GL_SHADER_VERSION R"( in vec2 in_Position; in vec2 in_Texcoord; @@ -209,7 +209,7 @@ void main(void) { } )"; -static const GLchar *PS_16 = GL_SHADER_VERSION R"( +static const GLchar* PS_16 = GL_SHADER_VERSION R"( precision highp float; in highp vec2 v_texcoord; @@ -223,7 +223,7 @@ void main(void) { } )"; -static const GLchar *PS_24 = GL_SHADER_VERSION R"( +static const GLchar* PS_24 = GL_SHADER_VERSION R"( precision highp float; in highp vec2 v_texcoord; @@ -237,7 +237,7 @@ void main(void) { } )"; -static GLuint compileShader(const char *VS, const char *PS) { +static GLuint compileShader(const char* VS, const char* PS) { GLuint vertexshader = glCreateShader(GL_VERTEX_SHADER); glShaderSource(vertexshader, 1, &VS, 0); glCompileShader(vertexshader); @@ -246,7 +246,7 @@ static GLuint compileShader(const char *VS, const char *PS) { if (IsCompiled_VS == 0) { GLint maxLength; glGetShaderiv(vertexshader, GL_INFO_LOG_LENGTH, &maxLength); - char *vertexInfoLog = (char *)malloc(maxLength); + char* vertexInfoLog = (char*)malloc(maxLength); glGetShaderInfoLog(vertexshader, maxLength, &maxLength, vertexInfoLog); @@ -264,7 +264,7 @@ static GLuint compileShader(const char *VS, const char *PS) { if (IsCompiled_PS == 0) { GLint maxLength; glGetShaderiv(fragmentshader, GL_INFO_LOG_LENGTH, &maxLength); - char *fragmentInfoLog = (char *)malloc(maxLength); + char* fragmentInfoLog = (char*)malloc(maxLength); glGetShaderInfoLog(fragmentshader, maxLength, &maxLength, fragmentInfoLog); @@ -368,14 +368,14 @@ static void DrawFullscreenQuad(int is24Bit) { glBindBuffer(GL_ARRAY_BUFFER, vbo); checkGL(); glVertexAttribPointer(vertexp, 3, GL_FLOAT, GL_FALSE, sizeof(s_vertexData), - (void *)&((s_vertexData *)NULL)->positions); + (void*)&((s_vertexData*)NULL)->positions); checkGL(); glEnableVertexAttribArray(vertexp); checkGL(); if (texcoordp != -1) { glVertexAttribPointer(texcoordp, 2, GL_FLOAT, GL_FALSE, sizeof(s_vertexData), - (void *)&((s_vertexData *)NULL)->textures); + (void*)&((s_vertexData*)NULL)->textures); glEnableVertexAttribArray(texcoordp); } @@ -452,12 +452,12 @@ uint32_t ulInitDisplay(void) { glGenVertexArrays(1, &vao_handle); checkGL(); shaderprogram16 = compileShader(passThroughVS, PS_16); - vertexp = glGetAttribLocation(shaderprogram16, (const GLchar *)"in_Position"); - texcoordp = glGetAttribLocation(shaderprogram16, (const GLchar *)"in_Texcoord"); + vertexp = glGetAttribLocation(shaderprogram16, (const GLchar*)"in_Position"); + texcoordp = glGetAttribLocation(shaderprogram16, (const GLchar*)"in_Texcoord"); checkGL(); shaderprogram24 = compileShader(passThroughVS, PS_24); - assert(vertexp == glGetAttribLocation(shaderprogram24, (const GLchar *)"in_Position")); - assert(texcoordp == glGetAttribLocation(shaderprogram24, (const GLchar *)"in_Texcoord")); + assert(vertexp == glGetAttribLocation(shaderprogram24, (const GLchar*)"in_Position")); + assert(texcoordp == glGetAttribLocation(shaderprogram24, (const GLchar*)"in_Texcoord")); checkGL(); glGenBuffers(1, &vbo); checkGL(); @@ -472,7 +472,7 @@ void CloseDisplay(void) { //////////////////////////////////////////////////////////////////////// -void CreatePic(unsigned char *pMem) {} +void CreatePic(unsigned char* pMem) {} /////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/gpu/soft/externals.h b/src/gpu/soft/externals.h index 258869040..d293ad6a4 100644 --- a/src/gpu/soft/externals.h +++ b/src/gpu/soft/externals.h @@ -93,7 +93,7 @@ struct VRAMLoad_t { int16_t Height; int16_t RowsRemaining; int16_t ColsRemaining; - uint16_t *ImagePtr; + uint16_t* ImagePtr; }; ///////////////////////////////////////////////////////////////////////////// @@ -149,7 +149,7 @@ namespace PCSX { class GUI; } -extern PCSX::GUI *m_gui; +extern PCSX::GUI* m_gui; extern bool bVsync_Key; extern int iFastFwd; @@ -183,14 +183,14 @@ extern PSXDisplay_t PreviousPSXDisplay; extern bool bSkipNextFrame; extern int32_t lGPUstatusRet; extern int32_t drawingLines; -extern unsigned char *psxVSecure; -extern unsigned char *psxVub; -extern signed char *psxVsb; -extern uint16_t *psxVuw; -extern int16_t *psxVsw; -extern uint32_t *psxVul; -extern int32_t *psxVsl; -extern uint16_t *psxVuw_eom; +extern unsigned char* psxVSecure; +extern unsigned char* psxVub; +extern signed char* psxVsb; +extern uint16_t* psxVuw; +extern int16_t* psxVsw; +extern uint32_t* psxVul; +extern int32_t* psxVsl; +extern uint16_t* psxVuw_eom; extern bool bChangeWinMode; extern int32_t lSelectedSlot; extern uint32_t dwLaceCnt; @@ -224,7 +224,7 @@ extern bool bSSSPSXLimit; // key.c // cfg.c -extern char *pConfigFile; +extern char* pConfigFile; // zn.c extern uint32_t dwGPUVersion; diff --git a/src/gpu/soft/fps.cc b/src/gpu/soft/fps.cc index a96721024..6424f11e2 100644 --- a/src/gpu/soft/fps.cc +++ b/src/gpu/soft/fps.cc @@ -98,8 +98,9 @@ void CheckFrameRate(void) { calcfps(); // -> calc fps display in skipping mode } else // non-skipping mode: { - if (UseFrameLimit) FrameCap(); // -> do it - // if (ulKeybits & KEY_SHOWFPS) calcfps(); // -> and calc fps display + if (UseFrameLimit) + FrameCap(); // -> do it + // if (ulKeybits & KEY_SHOWFPS) calcfps(); // -> and calc fps display } } diff --git a/src/gpu/soft/gpu.cc b/src/gpu/soft/gpu.cc index 0dcdfc9f2..66e5ebe22 100644 --- a/src/gpu/soft/gpu.cc +++ b/src/gpu/soft/gpu.cc @@ -148,22 +148,22 @@ const unsigned char version = 1; // do not touch - library for PSEmu 1.x const unsigned char revision = 1; const unsigned char build = 18; // increase that with each version -static const char *libraryName = "P.E.Op.S. Soft Driver"; +static const char* libraryName = "P.E.Op.S. Soft Driver"; -static const char *PluginAuthor = "Pete Bernert and the P.E.Op.S. team"; +static const char* PluginAuthor = "Pete Bernert and the P.E.Op.S. team"; //////////////////////////////////////////////////////////////////////// // memory image of the PSX vram //////////////////////////////////////////////////////////////////////// -unsigned char *psxVSecure; -unsigned char *psxVub; -signed char *psxVsb; -uint16_t *psxVuw; -uint16_t *psxVuw_eom; -int16_t *psxVsw; -uint32_t *psxVul; -int32_t *psxVsl; +unsigned char* psxVSecure; +unsigned char* psxVub; +signed char* psxVsb; +uint16_t* psxVuw; +uint16_t* psxVuw_eom; +int16_t* psxVsw; +uint32_t* psxVul; +int32_t* psxVsl; //////////////////////////////////////////////////////////////////////// // GPU globals @@ -215,7 +215,7 @@ void GPUdebugSetPC(uint32_t addr) #include time_t tStart; -extern "C" void softGPUdisplayText(char *pText) // some debug func +extern "C" void softGPUdisplayText(char* pText) // some debug func { if (!pText) { szDebugText[0] = 0; @@ -238,16 +238,16 @@ extern "C" void softGPUdisplayFlags(uint32_t dwFlags) // some info func // Snapshot func //////////////////////////////////////////////////////////////////////// -char *pGetConfigInfos(int iCfg) { - char *pB = (char *)malloc(32767); +char* pGetConfigInfos(int iCfg) { + char* pB = (char*)malloc(32767); return pB; } void DoTextSnapShot(int iNum) { - FILE *txtfile; + FILE* txtfile; char szTxt[256]; - char *pB; + char* pB; #ifdef _WIN32 sprintf(szTxt, "SNAP\\PEOPSSOFT%03d.txt", iNum); @@ -269,7 +269,7 @@ void DoTextSnapShot(int iNum) { extern "C" void softGPUmakeSnapshot(void) // snapshot of whole vram { - FILE *bmpfile; + FILE* bmpfile; char filename[256]; unsigned char header[0x36]; int32_t size, height; @@ -349,18 +349,18 @@ int32_t PCSX::SoftGPU::impl::init() // GPU INIT szDebugText[0] = 0; // init debug text buffer - psxVSecure = (unsigned char *)malloc((iGPUHeight * 2) * 1024 + - (1024 * 1024)); // always alloc one extra MB for soft drawing funcs security + psxVSecure = (unsigned char*)malloc((iGPUHeight * 2) * 1024 + + (1024 * 1024)); // always alloc one extra MB for soft drawing funcs security if (!psxVSecure) return -1; //!!! ATTENTION !!! psxVub = psxVSecure + 512 * 1024; // security offset into double sized psx vram! - psxVsb = (signed char *)psxVub; // different ways of accessing PSX VRAM - psxVsw = (int16_t *)psxVub; - psxVsl = (int32_t *)psxVub; - psxVuw = (uint16_t *)psxVub; - psxVul = (uint32_t *)psxVub; + psxVsb = (signed char*)psxVub; // different ways of accessing PSX VRAM + psxVsw = (int16_t*)psxVub; + psxVsl = (int32_t*)psxVub; + psxVuw = (uint16_t*)psxVub; + psxVul = (uint32_t*)psxVub; psxVuw_eom = psxVuw + 1024 * iGPUHeight; // pre-calc of end of vram @@ -405,7 +405,7 @@ int32_t PCSX::SoftGPU::impl::init() // GPU INIT // Here starts all... //////////////////////////////////////////////////////////////////////// -int32_t PCSX::SoftGPU::impl::open(GUI *gui) // GPU OPEN +int32_t PCSX::SoftGPU::impl::open(GUI* gui) // GPU OPEN { m_gui = gui; #if 0 @@ -467,8 +467,9 @@ void updateDisplay(void) // UPDATE DISPLAY if (dwActFixes & 32) // pc fps calculation fix { - if (UseFrameLimit) PCFrameCap(); // -> brake - // if (UseFrameSkip || ulKeybits & KEY_SHOWFPS) PCcalcfps(); + if (UseFrameLimit) + PCFrameCap(); // -> brake + // if (UseFrameSkip || ulKeybits & KEY_SHOWFPS) PCcalcfps(); } // if (ulKeybits & KEY_SHOWFPS) // make fps display buf @@ -528,7 +529,7 @@ void ChangeDispOffsetsX(void) // X CENTER l &= 0xfffffff8; if (l == PreviousPSXDisplay.Range.y1) return; // abusing range.y1 for - PreviousPSXDisplay.Range.y1 = (int16_t)l; // storing last x range and test + PreviousPSXDisplay.Range.y1 = (int16_t)l; // storing last x range and test if (lx >= PreviousPSXDisplay.DisplayMode.x) { PreviousPSXDisplay.Range.x1 = (int16_t)PreviousPSXDisplay.DisplayMode.x; @@ -616,9 +617,9 @@ void updateDisplayIfChanged(void) // UPDATE DISPLAY IF CHANGED PSXDisplay.DisplayMode.y = PSXDisplay.DisplayModeNew.y; PSXDisplay.DisplayMode.x = PSXDisplay.DisplayModeNew.x; - PreviousPSXDisplay.DisplayMode.x = // previous will hold + PreviousPSXDisplay.DisplayMode.x = // previous will hold std::min(640, PSXDisplay.DisplayMode.x); // max 640x512... that's - PreviousPSXDisplay.DisplayMode.y = // the size of my + PreviousPSXDisplay.DisplayMode.y = // the size of my std::min(512, PSXDisplay.DisplayMode.y); // back buffer surface PSXDisplay.Interlaced = PSXDisplay.InterlacedNew; @@ -1009,7 +1010,7 @@ __inline void FinishedVRAMRead(void) { // core read from vram //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::impl::readDataMem(uint32_t *pMem, int iSize) { +void PCSX::SoftGPU::impl::readDataMem(uint32_t* pMem, int iSize) { int i; if (DataReadMode != DR_VRAMTRANSFER) return; @@ -1106,7 +1107,7 @@ const unsigned char primTableCX[256] = { 3, 3, 3, 3, 4, 4, 4, 4, // 68 2, 2, 2, 2, 3, 3, 3, 3, // 3=SPRITE1??? - // 70 + // 70 2, 2, 2, 2, 3, 3, 3, 3, // 78 2, 2, 2, 2, 3, 3, 3, 3, @@ -1143,7 +1144,7 @@ const unsigned char primTableCX[256] = { // f8 0, 0, 0, 0, 0, 0, 0, 0}; -void PCSX::SoftGPU::impl::writeDataMem(uint32_t *pMem, int iSize) { +void PCSX::SoftGPU::impl::writeDataMem(uint32_t* pMem, int iSize) { unsigned char command; uint32_t gdata = 0; int i = 0; @@ -1235,7 +1236,7 @@ void PCSX::SoftGPU::impl::writeDataMem(uint32_t *pMem, int iSize) { if (gpuDataP == gpuDataC) { gpuDataC = gpuDataP = 0; - m_softPrim.callFunc(gpuCommand, (unsigned char *)gpuDataM); + m_softPrim.callFunc(gpuCommand, (unsigned char*)gpuDataM); if (dwEmuFixes & 0x0001 || dwActFixes & 0x0400) // hack for emulating "gpu busy" in some games iFakePrimBusy = 4; @@ -1312,9 +1313,9 @@ __inline bool CheckForEndlessLoop(uint32_t laddr) { return false; } -int32_t PCSX::SoftGPU::impl::dmaChain(uint32_t *baseAddrL, uint32_t addr) { +int32_t PCSX::SoftGPU::impl::dmaChain(uint32_t* baseAddrL, uint32_t addr) { uint32_t dmaMem; - unsigned char *baseAddrB; + unsigned char* baseAddrB; int16_t count; unsigned int DMACommandCounter = 0; @@ -1322,7 +1323,7 @@ int32_t PCSX::SoftGPU::impl::dmaChain(uint32_t *baseAddrL, uint32_t addr) { lUsedAddr[0] = lUsedAddr[1] = lUsedAddr[2] = 0xffffff; - baseAddrB = (unsigned char *)baseAddrL; + baseAddrB = (unsigned char*)baseAddrL; do { if (iGPUHeight == 512) addr &= 0x1FFFFC; @@ -1348,21 +1349,21 @@ int32_t PCSX::SoftGPU::impl::dmaChain(uint32_t *baseAddrL, uint32_t addr) { //////////////////////////////////////////////////////////////////////// typedef struct GPUFREEZETAG { - uint32_t ulFreezeVersion; // should be always 1 for now (set by main emu) - uint32_t ulStatus; // current gpu status - uint32_t ulControl[256]; // latest control register values + uint32_t ulFreezeVersion; // should be always 1 for now (set by main emu) + uint32_t ulStatus; // current gpu status + uint32_t ulControl[256]; // latest control register values unsigned char psxVRam[1024 * 1024 * 2]; // current VRam image (full 2 MB for ZN) } GPUFreeze_t; //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::impl::save(SaveStates::GPU &gpu) { +void PCSX::SoftGPU::impl::save(SaveStates::GPU& gpu) { gpu.get().value = lGPUstatusRet; gpu.get().copyFrom(reinterpret_cast(ulStatusControl)); gpu.get().copyFrom(psxVub); } -void PCSX::SoftGPU::impl::load(const SaveStates::GPU &gpu) { +void PCSX::SoftGPU::impl::load(const SaveStates::GPU& gpu) { lGPUstatusRet = gpu.get().value; gpu.get().copyTo(reinterpret_cast(ulStatusControl)); gpu.get().copyTo(psxVub); @@ -1481,7 +1482,7 @@ unsigned char cFont[10][120] = { //////////////////////////////////////////////////////////////////////// -void PaintPicDot(unsigned char *p, unsigned char c) { +void PaintPicDot(unsigned char* p, unsigned char c) { if (c == 0) { *p++ = 0x00; *p++ = 0x00; @@ -1512,7 +1513,7 @@ void PaintPicDot(unsigned char *p, unsigned char c) { // so you have to use the frontbuffer to get a fully // rendered picture -extern "C" void softGPUgetScreenPic(unsigned char *pMem) {} +extern "C" void softGPUgetScreenPic(unsigned char* pMem) {} //////////////////////////////////////////////////////////////////////// // func will be called with 128x96x3 BGR data. @@ -1522,7 +1523,7 @@ extern "C" void softGPUgetScreenPic(unsigned char *pMem) {} // release your picture data and stop displaying // the screen pic -extern "C" void softGPUshowScreenPic(unsigned char *pMem) { +extern "C" void softGPUshowScreenPic(unsigned char* pMem) { DestroyPic(); // destroy old pic data if (pMem == 0) return; // done CreatePic(pMem); // create new pic... don't free pMem or something like that... just read from it diff --git a/src/gpu/soft/interface.h b/src/gpu/soft/interface.h index 3c6790ded..685524d10 100644 --- a/src/gpu/soft/interface.h +++ b/src/gpu/soft/interface.h @@ -32,19 +32,19 @@ namespace SoftGPU { class impl : public GPU { virtual int32_t init() final; virtual int32_t shutdown() final; - virtual int32_t open(GUI *) final; + virtual int32_t open(GUI*) final; virtual int32_t close() final; virtual uint32_t readData() final { uint32_t l; readDataMem(&l, 1); return lGPUdataRet; } - virtual void readDataMem(uint32_t *pMem, int iSize) final; + virtual void readDataMem(uint32_t* pMem, int iSize) final; virtual uint32_t readStatus() final; virtual void writeData(uint32_t gdata) final { writeDataMem(&gdata, 1); } - virtual void writeDataMem(uint32_t *pMem, int iSize) final; + virtual void writeDataMem(uint32_t* pMem, int iSize) final; virtual void writeStatus(uint32_t gdata) final; - virtual int32_t dmaChain(uint32_t *baseAddrL, uint32_t addr) final; + virtual int32_t dmaChain(uint32_t* baseAddrL, uint32_t addr) final; virtual void updateLace() final; virtual bool configure() final { if (m_showCfg) { @@ -54,8 +54,8 @@ class impl : public GPU { } } - virtual void save(SaveStates::GPU &gpu) final; - virtual void load(const SaveStates::GPU &gpu) final; + virtual void save(SaveStates::GPU& gpu) final; + virtual void load(const SaveStates::GPU& gpu) final; SoftPrim m_softPrim; diff --git a/src/gpu/soft/prim.cc b/src/gpu/soft/prim.cc index dd94881be..f6135dd45 100644 --- a/src/gpu/soft/prim.cc +++ b/src/gpu/soft/prim.cc @@ -100,14 +100,14 @@ int iUseFixes; // ?? bool bDoVSyncUpdate = false; -bool PCSX::SoftGPU::SoftPrim::configure(bool *show) { +bool PCSX::SoftGPU::SoftPrim::configure(bool* show) { bool changed = false; ImGui::SetNextWindowPos(ImVec2(60, 60), ImGuiCond_FirstUseEver); ImGui::SetNextWindowSize(ImVec2(300, 200), ImGuiCond_FirstUseEver); if (!ImGui::Begin("Soft GPU configuration", show)) { ImGui::End(); } - static const char *ditherValues[] = {"No dithering (fastest)", "Game dependend dithering (slow)", + static const char* ditherValues[] = {"No dithering (fastest)", "Game dependend dithering (slow)", "Always dither g-shaded polygons (slowest)"}; changed |= ImGui::Combo("Dithering", &iUseDither, ditherValues, 3); changed |= ImGui::Checkbox("UseFrameLimit", &UseFrameLimit); @@ -374,8 +374,8 @@ static constexpr inline bool CheckCoordL(int16_t slx0, int16_t sly0, int16_t slx // mask stuff... used in silent hill //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::cmdSTP(unsigned char *baseAddr) { - uint32_t gdata = ((uint32_t *)baseAddr)[0]; +void PCSX::SoftGPU::SoftPrim::cmdSTP(unsigned char* baseAddr) { + uint32_t gdata = ((uint32_t*)baseAddr)[0]; lGPUstatusRet &= ~0x1800; // Clear the necessary bits lGPUstatusRet |= ((gdata & 0x03) << 11); // Set the necessary bits @@ -395,8 +395,8 @@ void PCSX::SoftGPU::SoftPrim::cmdSTP(unsigned char *baseAddr) { // cmd: Set texture page infos //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::cmdTexturePage(unsigned char *baseAddr) { - uint32_t gdata = ((uint32_t *)baseAddr)[0]; +void PCSX::SoftGPU::SoftPrim::cmdTexturePage(unsigned char* baseAddr) { + uint32_t gdata = ((uint32_t*)baseAddr)[0]; UpdateGlobalTP((uint16_t)gdata); GlobalTextREST = (gdata & 0x00ffffff) >> 9; @@ -406,8 +406,8 @@ void PCSX::SoftGPU::SoftPrim::cmdTexturePage(unsigned char *baseAddr) { // cmd: turn on/off texture window //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::cmdTextureWindow(unsigned char *baseAddr) { - uint32_t gdata = ((uint32_t *)baseAddr)[0]; +void PCSX::SoftGPU::SoftPrim::cmdTextureWindow(unsigned char* baseAddr) { + uint32_t gdata = ((uint32_t*)baseAddr)[0]; uint32_t YAlign, XAlign; @@ -465,8 +465,8 @@ void PCSX::SoftGPU::SoftPrim::cmdTextureWindow(unsigned char *baseAddr) { // cmd: start of drawing area... primitives will be clipped inside //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::cmdDrawAreaStart(unsigned char *baseAddr) { - uint32_t gdata = ((uint32_t *)baseAddr)[0]; +void PCSX::SoftGPU::SoftPrim::cmdDrawAreaStart(unsigned char* baseAddr) { + uint32_t gdata = ((uint32_t*)baseAddr)[0]; drawX = gdata & 0x3ff; // for soft drawing @@ -485,8 +485,8 @@ void PCSX::SoftGPU::SoftPrim::cmdDrawAreaStart(unsigned char *baseAddr) { // cmd: end of drawing area... primitives will be clipped inside //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::cmdDrawAreaEnd(unsigned char *baseAddr) { - uint32_t gdata = ((uint32_t *)baseAddr)[0]; +void PCSX::SoftGPU::SoftPrim::cmdDrawAreaEnd(unsigned char* baseAddr) { + uint32_t gdata = ((uint32_t*)baseAddr)[0]; drawW = gdata & 0x3ff; // for soft drawing @@ -505,8 +505,8 @@ void PCSX::SoftGPU::SoftPrim::cmdDrawAreaEnd(unsigned char *baseAddr) { // cmd: draw offset... will be added to prim coords //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::cmdDrawOffset(unsigned char *baseAddr) { - uint32_t gdata = ((uint32_t *)baseAddr)[0]; +void PCSX::SoftGPU::SoftPrim::cmdDrawOffset(unsigned char* baseAddr) { + uint32_t gdata = ((uint32_t*)baseAddr)[0]; PSXDisplay.DrawOffset.x = (int16_t)(gdata & 0x7ff); @@ -526,8 +526,8 @@ void PCSX::SoftGPU::SoftPrim::cmdDrawOffset(unsigned char *baseAddr) { // cmd: load image to vram //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primLoadImage(unsigned char *baseAddr) { - uint16_t *sgpuData = ((uint16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primLoadImage(unsigned char* baseAddr) { + uint16_t* sgpuData = ((uint16_t*)baseAddr); VRAMWrite.x = sgpuData[2] & 0x3ff; VRAMWrite.y = sgpuData[3] & iGPUHeightMask; @@ -545,8 +545,8 @@ void PCSX::SoftGPU::SoftPrim::primLoadImage(unsigned char *baseAddr) { // cmd: vram -> psx mem //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primStoreImage(unsigned char *baseAddr) { - uint16_t *sgpuData = ((uint16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primStoreImage(unsigned char* baseAddr) { + uint16_t* sgpuData = ((uint16_t*)baseAddr); VRAMRead.x = sgpuData[2] & 0x03ff; VRAMRead.y = sgpuData[3] & iGPUHeightMask; @@ -566,9 +566,9 @@ void PCSX::SoftGPU::SoftPrim::primStoreImage(unsigned char *baseAddr) { // cmd: blkfill - NO primitive! Doesn't care about draw areas... //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primBlkFill(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primBlkFill(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); int16_t sX = sgpuData[2]; int16_t sY = sgpuData[3]; @@ -594,8 +594,8 @@ void PCSX::SoftGPU::SoftPrim::primBlkFill(unsigned char *baseAddr) { // cmd: move image vram -> vram //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primMoveImage(unsigned char *baseAddr) { - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primMoveImage(unsigned char* baseAddr) { + int16_t* sgpuData = ((int16_t*)baseAddr); int16_t imageY0, imageX0, imageY1, imageX1, imageSX, imageSY, i, j; @@ -658,8 +658,8 @@ void PCSX::SoftGPU::SoftPrim::primMoveImage(unsigned char *baseAddr) { uint16_t LineOffset; int dx = imageSX >> 1; - SRCPtr = (uint32_t *)(psxVuw + (1024 * imageY0) + imageX0); - DSTPtr = (uint32_t *)(psxVuw + (1024 * imageY1) + imageX1); + SRCPtr = (uint32_t*)(psxVuw + (1024 * imageY0) + imageX0); + DSTPtr = (uint32_t*)(psxVuw + (1024 * imageY1) + imageX1); LineOffset = 512 - dx; @@ -695,9 +695,9 @@ void PCSX::SoftGPU::SoftPrim::primMoveImage(unsigned char *baseAddr) { //#define SMALLDEBUG //#include -void PCSX::SoftGPU::SoftPrim::primTileS(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primTileS(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); int16_t sW = sgpuData[4] & 0x3ff; int16_t sH = sgpuData[5] & iGPUHeightMask; // mmm... limit tiles to 0x1ff or height? @@ -724,9 +724,9 @@ void PCSX::SoftGPU::SoftPrim::primTileS(unsigned char *baseAddr) { // cmd: draw 1 dot Tile (point) //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primTile1(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primTile1(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); int16_t sH = 1; int16_t sW = 1; @@ -753,9 +753,9 @@ void PCSX::SoftGPU::SoftPrim::primTile1(unsigned char *baseAddr) { // cmd: draw 8 dot Tile (small rect) //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primTile8(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primTile8(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); int16_t sH = 8; int16_t sW = 8; @@ -782,9 +782,9 @@ void PCSX::SoftGPU::SoftPrim::primTile8(unsigned char *baseAddr) { // cmd: draw 16 dot Tile (medium rect) //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primTile16(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primTile16(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); int16_t sH = 16; int16_t sW = 16; @@ -811,9 +811,9 @@ void PCSX::SoftGPU::SoftPrim::primTile16(unsigned char *baseAddr) { // cmd: small sprite (textured rect) //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primSprt8(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primSprt8(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -836,9 +836,9 @@ void PCSX::SoftGPU::SoftPrim::primSprt8(unsigned char *baseAddr) { // cmd: medium sprite (textured rect) //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primSprt16(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primSprt16(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -862,9 +862,9 @@ void PCSX::SoftGPU::SoftPrim::primSprt16(unsigned char *baseAddr) { //////////////////////////////////////////////////////////////////////// // func used on texture coord wrap -void PCSX::SoftGPU::SoftPrim::primSprtSRest(unsigned char *baseAddr, uint16_t type) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primSprtSRest(unsigned char* baseAddr, uint16_t type) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); uint16_t sTypeRest = 0; int16_t s; @@ -949,9 +949,9 @@ void PCSX::SoftGPU::SoftPrim::primSprtSRest(unsigned char *baseAddr, uint16_t ty //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primSprtS(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primSprtS(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); int16_t sW, sH; lx0 = sgpuData[2]; @@ -998,9 +998,9 @@ void PCSX::SoftGPU::SoftPrim::primSprtS(unsigned char *baseAddr) { // cmd: flat shaded Poly4 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primPolyF4(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primPolyF4(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -1028,9 +1028,9 @@ void PCSX::SoftGPU::SoftPrim::primPolyF4(unsigned char *baseAddr) { // cmd: smooth shaded Poly4 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primPolyG4(unsigned char *baseAddr) { - uint32_t *gpuData = (uint32_t *)baseAddr; - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primPolyG4(unsigned char* baseAddr) { + uint32_t* gpuData = (uint32_t*)baseAddr; + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -1058,9 +1058,9 @@ void PCSX::SoftGPU::SoftPrim::primPolyG4(unsigned char *baseAddr) { // cmd: flat shaded Texture3 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primPolyFT3(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primPolyFT3(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -1089,9 +1089,9 @@ void PCSX::SoftGPU::SoftPrim::primPolyFT3(unsigned char *baseAddr) { // cmd: flat shaded Texture4 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primPolyFT4(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primPolyFT4(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -1123,9 +1123,9 @@ void PCSX::SoftGPU::SoftPrim::primPolyFT4(unsigned char *baseAddr) { // cmd: smooth shaded Texture3 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primPolyGT3(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primPolyGT3(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -1160,9 +1160,9 @@ void PCSX::SoftGPU::SoftPrim::primPolyGT3(unsigned char *baseAddr) { // cmd: smooth shaded Poly3 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primPolyG3(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primPolyG3(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -1188,9 +1188,9 @@ void PCSX::SoftGPU::SoftPrim::primPolyG3(unsigned char *baseAddr) { // cmd: smooth shaded Texture4 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primPolyGT4(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primPolyGT4(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -1228,9 +1228,9 @@ void PCSX::SoftGPU::SoftPrim::primPolyGT4(unsigned char *baseAddr) { // cmd: smooth shaded Poly3 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primPolyF3(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primPolyF3(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -1256,8 +1256,8 @@ void PCSX::SoftGPU::SoftPrim::primPolyF3(unsigned char *baseAddr) { // cmd: skipping shaded polylines //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primLineGSkip(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primLineGSkip(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); int iMax = 255; int i = 2; @@ -1277,8 +1277,8 @@ void PCSX::SoftGPU::SoftPrim::primLineGSkip(unsigned char *baseAddr) { // cmd: shaded polylines //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primLineGEx(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primLineGEx(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); int iMax = 255; uint32_t lc0, lc1; int16_t slx0, slx1, sly0, sly1; @@ -1337,9 +1337,9 @@ void PCSX::SoftGPU::SoftPrim::primLineGEx(unsigned char *baseAddr) { // cmd: shaded polyline2 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primLineG2(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primLineG2(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -1367,8 +1367,8 @@ void PCSX::SoftGPU::SoftPrim::primLineG2(unsigned char *baseAddr) { // cmd: skipping flat polylines //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primLineFSkip(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primLineFSkip(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); int i = 2, iMax = 255; ly1 = (int16_t)((gpuData[1] >> 16) & 0xffff); @@ -1386,8 +1386,8 @@ void PCSX::SoftGPU::SoftPrim::primLineFSkip(unsigned char *baseAddr) { // cmd: drawing flat polylines //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primLineFEx(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primLineFEx(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); int iMax; int16_t slx0, slx1, sly0, sly1; int i = 2; @@ -1435,9 +1435,9 @@ void PCSX::SoftGPU::SoftPrim::primLineFEx(unsigned char *baseAddr) { // cmd: drawing flat polyline2 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primLineF2(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); - int16_t *sgpuData = ((int16_t *)baseAddr); +void PCSX::SoftGPU::SoftPrim::primLineF2(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); + int16_t* sgpuData = ((int16_t*)baseAddr); lx0 = sgpuData[2]; ly0 = sgpuData[3]; @@ -1466,7 +1466,7 @@ void PCSX::SoftGPU::SoftPrim::primLineF2(unsigned char *baseAddr) { // cmd: well, easiest command... not implemented //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftPrim::primNI(unsigned char *baseAddr) {} +void PCSX::SoftGPU::SoftPrim::primNI(unsigned char* baseAddr) {} //////////////////////////////////////////////////////////////////////// // cmd func ptr table diff --git a/src/gpu/soft/prim.h b/src/gpu/soft/prim.h index 30e4810ab..972b9cc92 100644 --- a/src/gpu/soft/prim.h +++ b/src/gpu/soft/prim.h @@ -30,7 +30,7 @@ namespace SoftGPU { class SoftPrim : public SoftRenderer { public: - inline void callFunc(uint8_t cmd, unsigned char *baseAddr) { + inline void callFunc(uint8_t cmd, unsigned char* baseAddr) { if (!bSkipNextFrame) { (*this.*(funcs[cmd]))(baseAddr); } else { @@ -38,7 +38,7 @@ class SoftPrim : public SoftRenderer { } } - bool configure(bool *); + bool configure(bool*); inline void reset() { GlobalTextAddrX = 0; @@ -58,41 +58,41 @@ class SoftPrim : public SoftRenderer { int iUseDither = 0; int32_t GlobalTextREST; - typedef void (SoftPrim::*func_t)(unsigned char *); + typedef void (SoftPrim::*func_t)(unsigned char*); typedef const func_t cfunc_t; - void cmdSTP(unsigned char *baseAddr); - void cmdTexturePage(unsigned char *baseAddr); - void cmdTextureWindow(unsigned char *baseAddr); - void cmdDrawAreaStart(unsigned char *baseAddr); - void cmdDrawAreaEnd(unsigned char *baseAddr); - void cmdDrawOffset(unsigned char *baseAddr); - void primLoadImage(unsigned char *baseAddr); - void primStoreImage(unsigned char *baseAddr); - void primBlkFill(unsigned char *baseAddr); - void primMoveImage(unsigned char *baseAddr); - void primTileS(unsigned char *baseAddr); - void primTile1(unsigned char *baseAddr); - void primTile8(unsigned char *baseAddr); - void primTile16(unsigned char *baseAddr); - void primSprt8(unsigned char *baseAddr); - void primSprt16(unsigned char *baseAddr); - void primSprtSRest(unsigned char *baseAddr, uint16_t type); - void primSprtS(unsigned char *baseAddr); - void primPolyF4(unsigned char *baseAddr); - void primPolyG4(unsigned char *baseAddr); - void primPolyFT3(unsigned char *baseAddr); - void primPolyFT4(unsigned char *baseAddr); - void primPolyGT3(unsigned char *baseAddr); - void primPolyG3(unsigned char *baseAddr); - void primPolyGT4(unsigned char *baseAddr); - void primPolyF3(unsigned char *baseAddr); - void primLineGSkip(unsigned char *baseAddr); - void primLineGEx(unsigned char *baseAddr); - void primLineG2(unsigned char *baseAddr); - void primLineFSkip(unsigned char *baseAddr); - void primLineFEx(unsigned char *baseAddr); - void primLineF2(unsigned char *baseAddr); - void primNI(unsigned char *baseAddr); + void cmdSTP(unsigned char* baseAddr); + void cmdTexturePage(unsigned char* baseAddr); + void cmdTextureWindow(unsigned char* baseAddr); + void cmdDrawAreaStart(unsigned char* baseAddr); + void cmdDrawAreaEnd(unsigned char* baseAddr); + void cmdDrawOffset(unsigned char* baseAddr); + void primLoadImage(unsigned char* baseAddr); + void primStoreImage(unsigned char* baseAddr); + void primBlkFill(unsigned char* baseAddr); + void primMoveImage(unsigned char* baseAddr); + void primTileS(unsigned char* baseAddr); + void primTile1(unsigned char* baseAddr); + void primTile8(unsigned char* baseAddr); + void primTile16(unsigned char* baseAddr); + void primSprt8(unsigned char* baseAddr); + void primSprt16(unsigned char* baseAddr); + void primSprtSRest(unsigned char* baseAddr, uint16_t type); + void primSprtS(unsigned char* baseAddr); + void primPolyF4(unsigned char* baseAddr); + void primPolyG4(unsigned char* baseAddr); + void primPolyFT3(unsigned char* baseAddr); + void primPolyFT4(unsigned char* baseAddr); + void primPolyGT3(unsigned char* baseAddr); + void primPolyG3(unsigned char* baseAddr); + void primPolyGT4(unsigned char* baseAddr); + void primPolyF3(unsigned char* baseAddr); + void primLineGSkip(unsigned char* baseAddr); + void primLineGEx(unsigned char* baseAddr); + void primLineG2(unsigned char* baseAddr); + void primLineFSkip(unsigned char* baseAddr); + void primLineFEx(unsigned char* baseAddr); + void primLineF2(unsigned char* baseAddr); + void primNI(unsigned char* baseAddr); static const func_t funcs[256]; static const func_t skip[256]; diff --git a/src/gpu/soft/soft.cc b/src/gpu/soft/soft.cc index ee0d939fe..0ff46ca93 100644 --- a/src/gpu/soft/soft.cc +++ b/src/gpu/soft/soft.cc @@ -242,7 +242,7 @@ void PCSX::SoftGPU::SoftRenderer::offsetPSX4(void) { static const unsigned char dithertable[16] = {7, 0, 6, 1, 2, 5, 3, 4, 1, 6, 0, 7, 4, 3, 5, 2}; -void Dither16(uint16_t *pdest, uint32_t r, uint32_t g, uint32_t b, uint16_t sM) { +void Dither16(uint16_t* pdest, uint32_t r, uint32_t g, uint32_t b, uint16_t sM) { unsigned char coeff; unsigned char rlow, glow, blow; int x, y; @@ -272,7 +272,7 @@ void Dither16(uint16_t *pdest, uint32_t r, uint32_t g, uint32_t b, uint16_t sM) ///////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetShadeTransCol_Dither(uint16_t *pdest, int32_t m1, int32_t m2, int32_t m3) { +inline void PCSX::SoftGPU::SoftRenderer::GetShadeTransCol_Dither(uint16_t* pdest, int32_t m1, int32_t m2, int32_t m3) { int32_t r, g, b; if (bCheckMask && *pdest & 0x8000) return; @@ -323,7 +323,7 @@ inline void PCSX::SoftGPU::SoftRenderer::GetShadeTransCol_Dither(uint16_t *pdest //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetShadeTransCol(uint16_t *pdest, uint16_t color) { +inline void PCSX::SoftGPU::SoftRenderer::GetShadeTransCol(uint16_t* pdest, uint16_t color) { if (bCheckMask && *pdest & 0x8000) return; if (DrawSemiTrans) { @@ -371,7 +371,7 @@ inline void PCSX::SoftGPU::SoftRenderer::GetShadeTransCol(uint16_t *pdest, uint1 //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetShadeTransCol32(uint32_t *pdest, uint32_t color) { +inline void PCSX::SoftGPU::SoftRenderer::GetShadeTransCol32(uint32_t* pdest, uint32_t color) { if (DrawSemiTrans) { int32_t r, g, b; @@ -454,7 +454,7 @@ inline void PCSX::SoftGPU::SoftRenderer::GetShadeTransCol32(uint32_t *pdest, uin //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG(uint16_t *pdest, uint16_t color) { +inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG(uint16_t* pdest, uint16_t color) { int32_t r, g, b; uint16_t l; @@ -515,7 +515,7 @@ inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG(uint16_t *pdest, ui //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG_S(uint16_t *pdest, uint16_t color) { +inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG_S(uint16_t* pdest, uint16_t color) { int32_t r, g, b; uint16_t l; @@ -536,7 +536,7 @@ inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG_S(uint16_t *pdest, //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG_SPR(uint16_t *pdest, uint16_t color) { +inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG_SPR(uint16_t* pdest, uint16_t color) { int32_t r, g, b; uint16_t l; @@ -597,7 +597,7 @@ inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG_SPR(uint16_t *pdest //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG32(uint32_t *pdest, uint32_t color) { +inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG32(uint32_t* pdest, uint32_t color) { int32_t r, g, b, l; if (color == 0) return; @@ -697,7 +697,7 @@ inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG32(uint32_t *pdest, //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG32_S(uint32_t *pdest, uint32_t color) { +inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG32_S(uint32_t* pdest, uint32_t color) { int32_t r, g, b; if (color == 0) return; @@ -727,7 +727,7 @@ inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG32_S(uint32_t *pdest //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG32_SPR(uint32_t *pdest, uint32_t color) { +inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG32_SPR(uint32_t* pdest, uint32_t color) { int32_t r, g, b; if (color == 0) return; @@ -825,8 +825,8 @@ inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColG32_SPR(uint32_t *pde //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX_Dither(uint16_t *pdest, uint16_t color, - int32_t m1, int32_t m2, int32_t m3) { +inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX_Dither(uint16_t* pdest, uint16_t color, int32_t m1, + int32_t m2, int32_t m3) { int32_t r, g, b; if (color == 0) return; @@ -883,8 +883,8 @@ inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX_Dither(uint16_t *p //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX(uint16_t *pdest, uint16_t color, int16_t m1, - int16_t m2, int16_t m3) { +inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX(uint16_t* pdest, uint16_t color, int16_t m1, int16_t m2, + int16_t m3) { int32_t r, g, b; uint16_t l; @@ -944,8 +944,8 @@ inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX(uint16_t *pdest, u //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX_S(uint16_t *pdest, uint16_t color, int16_t m1, - int16_t m2, int16_t m3) { +inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX_S(uint16_t* pdest, uint16_t color, int16_t m1, int16_t m2, + int16_t m3) { int32_t r, g, b; if (color == 0) return; @@ -963,7 +963,7 @@ inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX_S(uint16_t *pdest, //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX32_S(uint32_t *pdest, uint32_t color, int16_t m1, +inline void PCSX::SoftGPU::SoftRenderer::GetTextureTransColGX32_S(uint32_t* pdest, uint32_t color, int16_t m1, int16_t m2, int16_t m3) { int32_t r, g, b; @@ -1047,7 +1047,7 @@ void PCSX::SoftGPU::SoftRenderer::FillSoftwareAreaTrans(int16_t x0, int16_t y0, if (dx & 1) // slow fill { - uint16_t *DSTPtr; + uint16_t* DSTPtr; uint16_t LineOffset; DSTPtr = psxVuw + (1024 * y0) + x0; LineOffset = 1024 - dx; @@ -1057,11 +1057,11 @@ void PCSX::SoftGPU::SoftRenderer::FillSoftwareAreaTrans(int16_t x0, int16_t y0, } } else // fast fill { - uint32_t *DSTPtr; + uint32_t* DSTPtr; uint16_t LineOffset; uint32_t lcol = lSetMask | (((uint32_t)(col)) << 16) | col; dx >>= 1; - DSTPtr = (uint32_t *)(psxVuw + (1024 * y0) + x0); + DSTPtr = (uint32_t*)(psxVuw + (1024 * y0) + x0); LineOffset = 512 - dx; if (!bCheckMask && !DrawSemiTrans) { @@ -1081,7 +1081,7 @@ void PCSX::SoftGPU::SoftRenderer::FillSoftwareAreaTrans(int16_t x0, int16_t y0, //////////////////////////////////////////////////////////////////////// void PCSX::SoftGPU::SoftRenderer::FillSoftwareArea(int16_t x0, int16_t y0, int16_t x1, // FILL AREA (BLK FILL) - int16_t y1, uint16_t col) // no draw area check here! + int16_t y1, uint16_t col) // no draw area check here! { int16_t j, i, dx, dy; @@ -1097,7 +1097,7 @@ void PCSX::SoftGPU::SoftRenderer::FillSoftwareArea(int16_t x0, int16_t y0, int16 dx = x1 - x0; dy = y1 - y0; if (dx & 1) { - uint16_t *DSTPtr; + uint16_t* DSTPtr; uint16_t LineOffset; DSTPtr = psxVuw + (1024 * y0) + x0; @@ -1108,12 +1108,12 @@ void PCSX::SoftGPU::SoftRenderer::FillSoftwareArea(int16_t x0, int16_t y0, int16 DSTPtr += LineOffset; } } else { - uint32_t *DSTPtr; + uint32_t* DSTPtr; uint16_t LineOffset; uint32_t lcol = (((int32_t)col) << 16) | col; dx >>= 1; - DSTPtr = (uint32_t *)(psxVuw + (1024 * y0) + x0); + DSTPtr = (uint32_t*)(psxVuw + (1024 * y0) + x0); LineOffset = 512 - dx; for (i = 0; i < dy; i++) { @@ -1159,8 +1159,8 @@ static constexpr inline int shl10idiv(int x, int y) { //////////////////////////////////////////////////////////////////////// static inline int RightSection_F(void) { - soft_vertex *v1 = right_array[right_section]; - soft_vertex *v2 = right_array[right_section - 1]; + soft_vertex* v1 = right_array[right_section]; + soft_vertex* v2 = right_array[right_section - 1]; int height = v2->y - v1->y; if (height == 0) return 0; @@ -1174,8 +1174,8 @@ static inline int RightSection_F(void) { //////////////////////////////////////////////////////////////////////// static inline int LeftSection_F(void) { - soft_vertex *v1 = left_array[left_section]; - soft_vertex *v2 = left_array[left_section - 1]; + soft_vertex* v1 = left_array[left_section]; + soft_vertex* v2 = left_array[left_section - 1]; int height = v2->y - v1->y; if (height == 0) return 0; @@ -1215,7 +1215,8 @@ static inline bool NextRow_F(void) { //////////////////////////////////////////////////////////////////////// -inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_F(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3) { +inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_F(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3) { soft_vertex *v1, *v2, *v3; int height, int32_test; @@ -1230,17 +1231,17 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_F(int16_t x1, int16_t y1, v3->y = y3; if (v1->y > v2->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v2; v2 = v; } if (v1->y > v3->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v3; v3 = v; } if (v2->y > v3->y) { - soft_vertex *v = v2; + soft_vertex* v = v2; v2 = v3; v3 = v; } @@ -1294,8 +1295,8 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_F(int16_t x1, int16_t y1, //////////////////////////////////////////////////////////////////////// static inline int RightSection_G(void) { - soft_vertex *v1 = right_array[right_section]; - soft_vertex *v2 = right_array[right_section - 1]; + soft_vertex* v1 = right_array[right_section]; + soft_vertex* v2 = right_array[right_section - 1]; int height = v2->y - v1->y; if (height == 0) return 0; @@ -1309,8 +1310,8 @@ static inline int RightSection_G(void) { //////////////////////////////////////////////////////////////////////// static inline int LeftSection_G(void) { - soft_vertex *v1 = left_array[left_section]; - soft_vertex *v2 = left_array[left_section - 1]; + soft_vertex* v1 = left_array[left_section]; + soft_vertex* v2 = left_array[left_section - 1]; int height = v2->y - v1->y; if (height == 0) return 0; @@ -1360,8 +1361,8 @@ static inline bool NextRow_G(void) { //////////////////////////////////////////////////////////////////////// -inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_G(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int32_t rgb1, int32_t rgb2, int32_t rgb3) { +inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_G(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int32_t rgb1, int32_t rgb2, int32_t rgb3) { soft_vertex *v1, *v2, *v3; int height, int32_test, temp; @@ -1385,17 +1386,17 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_G(int16_t x1, int16_t y1, v3->B = (rgb3 << 16) & 0x00ff0000; if (v1->y > v2->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v2; v2 = v; } if (v1->y > v3->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v3; v3 = v; } if (v2->y > v3->y) { - soft_vertex *v = v2; + soft_vertex* v = v2; v2 = v3; v3 = v; } @@ -1456,8 +1457,8 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_G(int16_t x1, int16_t y1, //////////////////////////////////////////////////////////////////////// static inline int RightSection_FT(void) { - soft_vertex *v1 = right_array[right_section]; - soft_vertex *v2 = right_array[right_section - 1]; + soft_vertex* v1 = right_array[right_section]; + soft_vertex* v2 = right_array[right_section - 1]; int height = v2->y - v1->y; if (height == 0) return 0; @@ -1471,8 +1472,8 @@ static inline int RightSection_FT(void) { //////////////////////////////////////////////////////////////////////// static inline int LeftSection_FT(void) { - soft_vertex *v1 = left_array[left_section]; - soft_vertex *v2 = left_array[left_section - 1]; + soft_vertex* v1 = left_array[left_section]; + soft_vertex* v2 = left_array[left_section - 1]; int height = v2->y - v1->y; if (height == 0) return 0; @@ -1519,9 +1520,9 @@ static inline bool NextRow_FT(void) { //////////////////////////////////////////////////////////////////////// -inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_FT(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3) { +inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_FT(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, + int16_t ty2, int16_t tx3, int16_t ty3) { soft_vertex *v1, *v2, *v3; int height, int32_test, temp; @@ -1542,17 +1543,17 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_FT(int16_t x1, int16_t y1 v3->v = ty3 << 16; if (v1->y > v2->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v2; v2 = v; } if (v1->y > v3->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v3; v3 = v; } if (v2->y > v3->y) { - soft_vertex *v = v2; + soft_vertex* v = v2; v2 = v3; v3 = v; } @@ -1629,8 +1630,8 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_FT(int16_t x1, int16_t y1 //////////////////////////////////////////////////////////////////////// static inline int RightSection_GT(void) { - soft_vertex *v1 = right_array[right_section]; - soft_vertex *v2 = right_array[right_section - 1]; + soft_vertex* v1 = right_array[right_section]; + soft_vertex* v2 = right_array[right_section - 1]; int height = v2->y - v1->y; if (height == 0) return 0; @@ -1644,8 +1645,8 @@ static inline int RightSection_GT(void) { //////////////////////////////////////////////////////////////////////// static inline int LeftSection_GT(void) { - soft_vertex *v1 = left_array[left_section]; - soft_vertex *v2 = left_array[left_section - 1]; + soft_vertex* v1 = left_array[left_section]; + soft_vertex* v2 = left_array[left_section - 1]; int height = v2->y - v1->y; if (height == 0) return 0; @@ -1702,9 +1703,10 @@ static inline bool NextRow_GT(void) { //////////////////////////////////////////////////////////////////////// -inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_GT(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int32_t rgb1, int32_t rgb2, int32_t rgb3) { +inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_GT(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, + int16_t ty2, int16_t tx3, int16_t ty3, int32_t rgb1, + int32_t rgb2, int32_t rgb3) { soft_vertex *v1, *v2, *v3; int height, int32_test, temp; @@ -1736,17 +1738,17 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_GT(int16_t x1, int16_t y1 v3->B = (rgb3 << 16) & 0x00ff0000; if (v1->y > v2->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v2; v2 = v; } if (v1->y > v3->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v3; v3 = v; } if (v2->y > v3->y) { - soft_vertex *v = v2; + soft_vertex* v = v2; v2 = v3; v3 = v; } @@ -1827,8 +1829,8 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_GT(int16_t x1, int16_t y1 //////////////////////////////////////////////////////////////////////// static inline int RightSection_F4(void) { - soft_vertex *v1 = right_array[right_section]; - soft_vertex *v2 = right_array[right_section - 1]; + soft_vertex* v1 = right_array[right_section]; + soft_vertex* v2 = right_array[right_section - 1]; int height = v2->y - v1->y; right_section_height = height; @@ -1844,8 +1846,8 @@ static inline int RightSection_F4(void) { //////////////////////////////////////////////////////////////////////// static inline int LeftSection_F4(void) { - soft_vertex *v1 = left_array[left_section]; - soft_vertex *v2 = left_array[left_section - 1]; + soft_vertex* v1 = left_array[left_section]; + soft_vertex* v2 = left_array[left_section - 1]; int height = v2->y - v1->y; left_section_height = height; @@ -1883,8 +1885,8 @@ static inline bool NextRow_F4(void) { //////////////////////////////////////////////////////////////////////// -inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_F4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4) { +inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_F4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4) { soft_vertex *v1, *v2, *v3, *v4; int height, width, int32_test1, int32_test2; @@ -1902,32 +1904,32 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_F4(int16_t x1, int16_t y1 v4->y = y4; if (v1->y > v2->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v2; v2 = v; } if (v1->y > v3->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v3; v3 = v; } if (v1->y > v4->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v4; v4 = v; } if (v2->y > v3->y) { - soft_vertex *v = v2; + soft_vertex* v = v2; v2 = v3; v3 = v; } if (v2->y > v4->y) { - soft_vertex *v = v2; + soft_vertex* v = v2; v2 = v4; v4 = v; } if (v3->y > v4->y) { - soft_vertex *v = v3; + soft_vertex* v = v3; v3 = v4; v4 = v; } @@ -2042,8 +2044,8 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_F4(int16_t x1, int16_t y1 //////////////////////////////////////////////////////////////////////// static inline int RightSection_FT4(void) { - soft_vertex *v1 = right_array[right_section]; - soft_vertex *v2 = right_array[right_section - 1]; + soft_vertex* v1 = right_array[right_section]; + soft_vertex* v2 = right_array[right_section - 1]; int height = v2->y - v1->y; right_section_height = height; @@ -2063,8 +2065,8 @@ static inline int RightSection_FT4(void) { //////////////////////////////////////////////////////////////////////// static inline int LeftSection_FT4(void) { - soft_vertex *v1 = left_array[left_section]; - soft_vertex *v2 = left_array[left_section - 1]; + soft_vertex* v1 = left_array[left_section]; + soft_vertex* v2 = left_array[left_section - 1]; int height = v2->y - v1->y; left_section_height = height; @@ -2110,9 +2112,10 @@ static inline bool NextRow_FT4(void) { //////////////////////////////////////////////////////////////////////// -inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_FT4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4) { +inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_FT4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4) { soft_vertex *v1, *v2, *v3, *v4; int height, width, int32_test1, int32_test2; @@ -2141,32 +2144,32 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_FT4(int16_t x1, int16_t y v4->v = ty4 << 16; if (v1->y > v2->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v2; v2 = v; } if (v1->y > v3->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v3; v3 = v; } if (v1->y > v4->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v4; v4 = v; } if (v2->y > v3->y) { - soft_vertex *v = v2; + soft_vertex* v = v2; v2 = v3; v3 = v; } if (v2->y > v4->y) { - soft_vertex *v = v2; + soft_vertex* v = v2; v2 = v4; v4 = v; } if (v3->y > v4->y) { - soft_vertex *v = v3; + soft_vertex* v = v3; v3 = v4; v4 = v; } @@ -2281,8 +2284,8 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_FT4(int16_t x1, int16_t y //////////////////////////////////////////////////////////////////////// static inline int RightSection_GT4(void) { - soft_vertex *v1 = right_array[right_section]; - soft_vertex *v2 = right_array[right_section - 1]; + soft_vertex* v1 = right_array[right_section]; + soft_vertex* v2 = right_array[right_section - 1]; int height = v2->y - v1->y; right_section_height = height; @@ -2309,8 +2312,8 @@ static inline int RightSection_GT4(void) { //////////////////////////////////////////////////////////////////////// static inline int LeftSection_GT4(void) { - soft_vertex *v1 = left_array[left_section]; - soft_vertex *v2 = left_array[left_section - 1]; + soft_vertex* v1 = left_array[left_section]; + soft_vertex* v2 = left_array[left_section - 1]; int height = v2->y - v1->y; left_section_height = height; @@ -2369,10 +2372,11 @@ static inline bool NextRow_GT4(void) { //////////////////////////////////////////////////////////////////////// -inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_GT4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, - int32_t rgb1, int32_t rgb2, int32_t rgb3, int32_t rgb4) { +inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_GT4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int32_t rgb1, int32_t rgb2, + int32_t rgb3, int32_t rgb4) { soft_vertex *v1, *v2, *v3, *v4; int height, width, int32_test1, int32_test2; @@ -2413,32 +2417,32 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_GT4(int16_t x1, int16_t y v4->B = (rgb4 << 16) & 0x00ff0000; if (v1->y > v2->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v2; v2 = v; } if (v1->y > v3->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v3; v3 = v; } if (v1->y > v4->y) { - soft_vertex *v = v1; + soft_vertex* v = v1; v1 = v4; v4 = v; } if (v2->y > v3->y) { - soft_vertex *v = v2; + soft_vertex* v = v2; v2 = v3; v3 = v; } if (v2->y > v4->y) { - soft_vertex *v = v2; + soft_vertex* v = v2; v2 = v4; v4 = v; } if (v3->y > v4->y) { - soft_vertex *v = v3; + soft_vertex* v = v3; v3 = v4; v4 = v; } @@ -2561,8 +2565,8 @@ inline bool PCSX::SoftGPU::SoftRenderer::SetupSections_GT4(int16_t x1, int16_t y // POLY 3/4 FLAT SHADED //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::drawPoly3Fi(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int32_t rgb) { +inline void PCSX::SoftGPU::SoftRenderer::drawPoly3Fi(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int32_t rgb) { int i, j, xmin, xmax, ymin, ymax; uint16_t color; uint32_t lcolor; @@ -2595,7 +2599,7 @@ inline void PCSX::SoftGPU::SoftRenderer::drawPoly3Fi(int16_t x1, int16_t y1, int if (drawW < xmax) xmax = drawW; for (j = xmin; j < xmax; j += 2) { - *((uint32_t *)&psxVuw[(i << 10) + j]) = lcolor; + *((uint32_t*)&psxVuw[(i << 10) + j]) = lcolor; } if (j == xmax) psxVuw[(i << 10) + j] = color; @@ -2613,7 +2617,7 @@ inline void PCSX::SoftGPU::SoftRenderer::drawPoly3Fi(int16_t x1, int16_t y1, int if (drawW < xmax) xmax = drawW; for (j = xmin; j < xmax; j += 2) { - GetShadeTransCol32((uint32_t *)&psxVuw[(i << 10) + j], lcolor); + GetShadeTransCol32((uint32_t*)&psxVuw[(i << 10) + j], lcolor); } if (j == xmax) GetShadeTransCol(&psxVuw[(i << 10) + j], color); @@ -2669,7 +2673,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4F(int32_t rgb) { if (drawW < xmax) xmax = drawW; for (j = xmin; j < xmax; j += 2) { - *((uint32_t *)&psxVuw[(i << 10) + j]) = lcolor; + *((uint32_t*)&psxVuw[(i << 10) + j]) = lcolor; } if (j == xmax) psxVuw[(i << 10) + j] = color; @@ -2687,7 +2691,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4F(int32_t rgb) { if (drawW < xmax) xmax = drawW; for (j = xmin; j < xmax; j += 2) { - GetShadeTransCol32((uint32_t *)&psxVuw[(i << 10) + j], lcolor); + GetShadeTransCol32((uint32_t*)&psxVuw[(i << 10) + j], lcolor); } if (j == xmax) GetShadeTransCol(&psxVuw[(i << 10) + j], color); @@ -2699,9 +2703,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4F(int32_t rgb) { // POLY 3/4 F-SHADED TEX PAL 4 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, - int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, + int16_t ty3, int16_t clX, int16_t clY) { int i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; int32_t posX, posY, YAdjust, XAdjust; @@ -2758,7 +2762,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4(int16_t x1, int16_t y1, int16_t tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; @@ -2804,7 +2808,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4(int16_t x1, int16_t y1, int16_t tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; @@ -2825,9 +2829,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4(int16_t x1, int16_t y1, int16_t //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, - int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, + int16_t tx3, int16_t ty3, int16_t clX, int16_t clY) { int i, j, xmin, xmax, ymin, ymax, n_xi, n_yi, TXV; int32_t difX, difY, difX2, difY2; int32_t posX, posY, YAdjust, XAdjust; @@ -2893,7 +2897,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_IL(int16_t x1, int16_t y1, int16 tC2 = (psxVuw[(n_yi << 10) + YAdjust + n_xi] >> ((XAdjust & 0x03) << 2)) & 0x0f; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; @@ -2953,7 +2957,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_IL(int16_t x1, int16_t y1, int16 tC2 = (psxVuw[(n_yi << 10) + YAdjust + n_xi] >> ((XAdjust & 0x03) << 2)) & 0x0f; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; @@ -2979,9 +2983,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_IL(int16_t x1, int16_t y1, int16 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, - int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, + int16_t tx3, int16_t ty3, int16_t clX, int16_t clY) { int i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; int32_t posX, posY, YAdjust, XAdjust; @@ -3035,13 +3039,15 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_TW(int16_t x1, int16_t y1, int16 for (j = xmin; j < xmax; j += 2) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; XAdjust = ((posX + difX) >> 16) % TWin.Position.x1; - tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; @@ -3049,7 +3055,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_TW(int16_t x1, int16_t y1, int16 } if (j == xmax) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; GetTextureTransColG_S(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } @@ -3081,13 +3088,15 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_TW(int16_t x1, int16_t y1, int16 for (j = xmin; j < xmax; j += 2) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = + psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; XAdjust = ((posX + difX) >> 16) % TWin.Position.x1; - tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; @@ -3095,7 +3104,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_TW(int16_t x1, int16_t y1, int16 } if (j == xmax) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = + psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; GetTextureTransColG(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } @@ -3110,9 +3120,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx4_TW(int16_t x1, int16_t y1, int16 #ifdef POLYQUAD3 -void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, - int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY) { drawPoly3TEx4(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4, clX, clY); drawPoly3TEx4(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4, clX, clY); } @@ -3121,9 +3132,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TRI(int16_t x1, int16_t y1, int1 // more exact: -void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, + int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, + int16_t clX, int16_t clY) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; @@ -3183,7 +3195,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4(int16_t x1, int16_t y1, int16_t tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -3234,7 +3246,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4(int16_t x1, int16_t y1, int16_t tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -3252,9 +3264,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4(int16_t x1, int16_t y1, int16_t //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax, n_xi, n_yi, TXV; int32_t difX, difY, difX2, difY2; @@ -3323,7 +3336,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_IL(int16_t x1, int16_t y1, int16 tC2 = (psxVuw[(n_yi << 10) + YAdjust + n_xi] >> ((XAdjust & 0x03) << 2)) & 0x0f; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -3388,7 +3401,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_IL(int16_t x1, int16_t y1, int16 tC2 = (psxVuw[(n_yi << 10) + YAdjust + n_xi] >> ((XAdjust & 0x03) << 2)) & 0x0f; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -3410,9 +3423,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_IL(int16_t x1, int16_t y1, int16 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; @@ -3467,20 +3481,23 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TW(int16_t x1, int16_t y1, int16 for (j = xmin; j < xmax; j += 2) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; XAdjust = ((posX + difX) >> 16) % TWin.Position.x1; - tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; } if (j == xmax) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; GetTextureTransColG_S(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } @@ -3518,20 +3535,23 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TW(int16_t x1, int16_t y1, int16 for (j = xmin; j < xmax; j += 2) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = + psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; XAdjust = ((posX + difX) >> 16) % TWin.Position.x1; - tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; } if (j == xmax) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = + psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; GetTextureTransColG(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } @@ -3542,9 +3562,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TW(int16_t x1, int16_t y1, int16 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, - int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; @@ -3599,20 +3620,23 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TW_S(int16_t x1, int16_t y1, int for (j = xmin; j < xmax; j += 2) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; XAdjust = ((posX + difX) >> 16) % TWin.Position.x1; - tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; } if (j == xmax) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; GetTextureTransColG_S(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } @@ -3650,20 +3674,23 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TW_S(int16_t x1, int16_t y1, int for (j = xmin; j < xmax; j += 2) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = + psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; XAdjust = ((posX + difX) >> 16) % TWin.Position.x1; - tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; - GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32_SPR((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; } if (j == xmax) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = + psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; GetTextureTransColG_SPR(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } @@ -3675,9 +3702,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx4_TW_S(int16_t x1, int16_t y1, int // POLY 3 F-SHADED TEX PAL 8 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, - int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, + int16_t ty3, int16_t clX, int16_t clY) { int i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; int32_t posX, posY, YAdjust, clutP; @@ -3727,8 +3754,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8(int16_t x1, int16_t y1, int16_t for (j = xmin; j < xmax; j += 2) { tC1 = psxVub[static_cast(((posY >> 5) & 0xFFFFF800) + YAdjust + (posX >> 16))]; - tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + ((posX + difX) >> 16))]; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + + ((posX + difX) >> 16))]; + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -3766,8 +3794,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8(int16_t x1, int16_t y1, int16_t for (j = xmin; j < xmax; j += 2) { tC1 = psxVub[static_cast(((posY >> 5) & 0xFFFFF800) + YAdjust + (posX >> 16))]; - tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + ((posX + difX) >> 16))]; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + tC2 = + psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + ((posX + difX) >> 16))]; + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -3786,9 +3815,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8(int16_t x1, int16_t y1, int16_t //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, - int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, + int16_t tx3, int16_t ty3, int16_t clX, int16_t clY) { int i, j, xmin, xmax, ymin, ymax, n_xi, n_yi, TXV, TXU; int32_t difX, difY, difX2, difY2; int32_t posX, posY, YAdjust, clutP; @@ -3851,7 +3880,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8_IL(int16_t x1, int16_t y1, int16 tC2 = (psxVuw[(n_yi << 10) + YAdjust + n_xi] >> ((TXU & 0x01) << 3)) & 0xff; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -3908,7 +3937,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8_IL(int16_t x1, int16_t y1, int16 tC2 = (psxVuw[(n_yi << 10) + YAdjust + n_xi] >> ((TXU & 0x01) << 3)) & 0xff; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -3933,9 +3962,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8_IL(int16_t x1, int16_t y1, int16 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, - int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, + int16_t tx3, int16_t ty3, int16_t clX, int16_t clY) { int i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; int32_t posX, posY, YAdjust, clutP; @@ -3987,19 +4016,19 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8_TW(int16_t x1, int16_t y1, int16 } for (j = xmin; j < xmax; j += 2) { - tC1 = - psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - (((posX + difX) >> 16) % TWin.Position.x1))]; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + (((posX + difX) >> 16) % TWin.Position.x1))]; + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; } if (j == xmax) { - tC1 = - psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; GetTextureTransColG_S(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } } @@ -4029,17 +4058,19 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8_TW(int16_t x1, int16_t y1, int16 } for (j = xmin; j < xmax; j += 2) { - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - (((posX + difX) >> 16) % TWin.Position.x1))]; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + (((posX + difX) >> 16) % TWin.Position.x1))]; + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; } if (j == xmax) { - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; GetTextureTransColG(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } } @@ -4053,9 +4084,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TEx8_TW(int16_t x1, int16_t y1, int16 #ifdef POLYQUAD3 -void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, - int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY) { drawPoly3TEx8(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4, clX, clY); drawPoly3TEx8(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4, clX, clY); @@ -4065,9 +4097,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TRI(int16_t x1, int16_t y1, int1 // more exact: -void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, + int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, + int16_t clX, int16_t clY) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; @@ -4121,8 +4154,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8(int16_t x1, int16_t y1, int16_t for (j = xmin; j < xmax; j += 2) { tC1 = psxVub[static_cast(((posY >> 5) & 0xFFFFF800) + YAdjust + (posX >> 16))]; - tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + ((posX + difX) >> 16))]; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + + ((posX + difX) >> 16))]; + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -4165,8 +4199,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8(int16_t x1, int16_t y1, int16_t for (j = xmin; j < xmax; j += 2) { tC1 = psxVub[static_cast(((posY >> 5) & 0xFFFFF800) + YAdjust + (posX >> 16))]; - tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + ((posX + difX) >> 16))]; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + tC2 = + psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + ((posX + difX) >> 16))]; + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -4182,9 +4217,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8(int16_t x1, int16_t y1, int16_t //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax, n_xi, n_yi, TXV, TXU; int32_t difX, difY, difX2, difY2; @@ -4251,7 +4287,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_IL(int16_t x1, int16_t y1, int16 tC2 = (psxVuw[(n_yi << 10) + YAdjust + n_xi] >> ((TXU & 0x01) << 3)) & 0xff; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -4313,7 +4349,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_IL(int16_t x1, int16_t y1, int16 tC2 = (psxVuw[(n_yi << 10) + YAdjust + n_xi] >> ((TXU & 0x01) << 3)) & 0xff; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; @@ -4333,9 +4369,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_IL(int16_t x1, int16_t y1, int16 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; @@ -4389,18 +4426,18 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TW(int16_t x1, int16_t y1, int16 if (drawW < xmax) xmax = drawW; for (j = xmin; j < xmax; j += 2) { - tC1 = - psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - (((posX + difX) >> 16) % TWin.Position.x1))]; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + (((posX + difX) >> 16) % TWin.Position.x1))]; + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; } if (j == xmax) { tC1 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - ((posX >> 16) % TWin.Position.x1))]; + ((posX >> 16) % TWin.Position.x1))]; GetTextureTransColG_S(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } } @@ -4436,17 +4473,18 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TW(int16_t x1, int16_t y1, int16 if (drawW < xmax) xmax = drawW; for (j = xmin; j < xmax; j += 2) { - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - (((posX + difX) >> 16) % TWin.Position.x1))]; - GetTextureTransColG32((uint32_t *)&psxVuw[(i << 10) + j], + (((posX + difX) >> 16) % TWin.Position.x1))]; + GetTextureTransColG32((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; } if (j == xmax) { tC1 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - ((posX >> 16) % TWin.Position.x1))]; + ((posX >> 16) % TWin.Position.x1))]; GetTextureTransColG(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } } @@ -4456,9 +4494,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TW(int16_t x1, int16_t y1, int16 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, - int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; @@ -4512,18 +4551,18 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TW_S(int16_t x1, int16_t y1, int if (drawW < xmax) xmax = drawW; for (j = xmin; j < xmax; j += 2) { - tC1 = - psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - (((posX + difX) >> 16) % TWin.Position.x1))]; - GetTextureTransColG32_S((uint32_t *)&psxVuw[(i << 10) + j], + (((posX + difX) >> 16) % TWin.Position.x1))]; + GetTextureTransColG32_S((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; } if (j == xmax) { tC1 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - ((posX >> 16) % TWin.Position.x1))]; + ((posX >> 16) % TWin.Position.x1))]; GetTextureTransColG_S(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } } @@ -4559,17 +4598,18 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TW_S(int16_t x1, int16_t y1, int if (drawW < xmax) xmax = drawW; for (j = xmin; j < xmax; j += 2) { - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - (((posX + difX) >> 16) % TWin.Position.x1))]; - GetTextureTransColG32_SPR((uint32_t *)&psxVuw[(i << 10) + j], + (((posX + difX) >> 16) % TWin.Position.x1))]; + GetTextureTransColG32_SPR((uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16); posX += difX2; posY += difY2; } if (j == xmax) { tC1 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - ((posX >> 16) % TWin.Position.x1))]; + ((posX >> 16) % TWin.Position.x1))]; GetTextureTransColG_SPR(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1]); } } @@ -4581,8 +4621,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TEx8_TW_S(int16_t x1, int16_t y1, int // POLY 3 F-SHADED TEX 15 BIT //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, + int16_t ty3) { int i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; int32_t posX, posY; @@ -4627,9 +4668,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TD(int16_t x1, int16_t y1, int16_t x2 for (j = xmin; j < xmax; j += 2) { GetTextureTransColG32_S( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t)psxVuw[((((posY + difY) >> 16) + GlobalTextAddrY) << 10) + ((posX + difX) >> 16) + - GlobalTextAddrX]) + GlobalTextAddrX]) << 16) | psxVuw[(((posY >> 16) + GlobalTextAddrY) << 10) + ((posX) >> 16) + GlobalTextAddrX]); @@ -4668,9 +4709,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TD(int16_t x1, int16_t y1, int16_t x2 for (j = xmin; j < xmax; j += 2) { GetTextureTransColG32( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t)psxVuw[((((posY + difY) >> 16) + GlobalTextAddrY) << 10) + ((posX + difX) >> 16) + - GlobalTextAddrX]) + GlobalTextAddrX]) << 16) | psxVuw[(((posY >> 16) + GlobalTextAddrY) << 10) + ((posX) >> 16) + GlobalTextAddrX]); @@ -4689,8 +4730,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TD(int16_t x1, int16_t y1, int16_t x2 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, + int16_t ty3) { int i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; int32_t posX, posY; @@ -4735,7 +4777,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TD_TW(int16_t x1, int16_t y1, int16_t for (j = xmin; j < xmax; j += 2) { GetTextureTransColG32_S( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t) psxVuw[(((((posY + difY) >> 16) % TWin.Position.y1) + GlobalTextAddrY + TWin.Position.y0) << 10) + @@ -4780,10 +4822,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TD_TW(int16_t x1, int16_t y1, int16_t for (j = xmin; j < xmax; j += 2) { GetTextureTransColG32( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t)psxVuw[(((((posY + difY) >> 16) % TWin.Position.y1) + GlobalTextAddrY + TWin.Position.y0) - << 10) + - (((posX + difX) >> 16) % TWin.Position.x1) + GlobalTextAddrX + TWin.Position.x0]) + << 10) + + (((posX + difX) >> 16) % TWin.Position.x1) + GlobalTextAddrX + TWin.Position.x0]) << 16) | psxVuw[((((posY >> 16) % TWin.Position.y1) + GlobalTextAddrY + TWin.Position.y0) << 10) + (((posX) >> 16) % TWin.Position.x1) + GlobalTextAddrX + TWin.Position.x0]); @@ -4807,9 +4849,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TD_TW(int16_t x1, int16_t y1, int16_t #ifdef POLYQUAD3 -void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4) { drawPoly3TD(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4); drawPoly3TD(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4); } @@ -4818,9 +4861,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TRI(int16_t x1, int16_t y1, int16_ // more exact: -void PCSX::SoftGPU::SoftRenderer::drawPoly4TD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, + int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; @@ -4869,9 +4912,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TD(int16_t x1, int16_t y1, int16_t x2 for (j = xmin; j < xmax; j += 2) { GetTextureTransColG32_S( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t)psxVuw[((((posY + difY) >> 16) + GlobalTextAddrY) << 10) + ((posX + difX) >> 16) + - GlobalTextAddrX]) + GlobalTextAddrX]) << 16) | psxVuw[(((posY >> 16) + GlobalTextAddrY) << 10) + ((posX) >> 16) + GlobalTextAddrX]); @@ -4916,9 +4959,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TD(int16_t x1, int16_t y1, int16_t x2 for (j = xmin; j < xmax; j += 2) { GetTextureTransColG32( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t)psxVuw[((((posY + difY) >> 16) + GlobalTextAddrY) << 10) + ((posX + difX) >> 16) + - GlobalTextAddrX]) + GlobalTextAddrX]) << 16) | psxVuw[(((posY >> 16) + GlobalTextAddrY) << 10) + ((posX) >> 16) + GlobalTextAddrX]); @@ -4935,9 +4978,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TD(int16_t x1, int16_t y1, int16_t x2 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, + int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; @@ -4986,7 +5029,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TW(int16_t x1, int16_t y1, int16_t for (j = xmin; j < xmax; j += 2) { GetTextureTransColG32_S( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t) psxVuw[(((((posY + difY) >> 16) % TWin.Position.y1) + GlobalTextAddrY + TWin.Position.y0) << 10) + @@ -5037,10 +5080,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TW(int16_t x1, int16_t y1, int16_t for (j = xmin; j < xmax; j += 2) { GetTextureTransColG32( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t)psxVuw[(((((posY + difY) >> 16) % TWin.Position.y1) + GlobalTextAddrY + TWin.Position.y0) - << 10) + - (((posX + difX) >> 16) % TWin.Position.x1) + GlobalTextAddrX + TWin.Position.x0]) + << 10) + + (((posX + difX) >> 16) % TWin.Position.x1) + GlobalTextAddrX + TWin.Position.x0]) << 16) | psxVuw[((((posY >> 16) % TWin.Position.y1) + GlobalTextAddrY + TWin.Position.y0) << 10) + ((posX >> 16) % TWin.Position.x1) + GlobalTextAddrX + TWin.Position.x0]); @@ -5060,9 +5103,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TW(int16_t x1, int16_t y1, int16_t //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t difX, difY, difX2, difY2; @@ -5111,7 +5155,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TW_S(int16_t x1, int16_t y1, int16 for (j = xmin; j < xmax; j += 2) { GetTextureTransColG32_S( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t) psxVuw[(((((posY + difY) >> 16) % TWin.Position.y1) + GlobalTextAddrY + TWin.Position.y0) << 10) + @@ -5162,10 +5206,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TW_S(int16_t x1, int16_t y1, int16 for (j = xmin; j < xmax; j += 2) { GetTextureTransColG32_SPR( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t)psxVuw[(((((posY + difY) >> 16) % TWin.Position.y1) + GlobalTextAddrY + TWin.Position.y0) - << 10) + - (((posX + difX) >> 16) % TWin.Position.x1) + GlobalTextAddrX + TWin.Position.x0]) + << 10) + + (((posX + difX) >> 16) % TWin.Position.x1) + GlobalTextAddrX + TWin.Position.x0]) << 16) | psxVuw[((((posY >> 16) % TWin.Position.y1) + GlobalTextAddrY + TWin.Position.y0) << 10) + ((posX >> 16) % TWin.Position.x1) + GlobalTextAddrX + TWin.Position.x0]); @@ -5187,8 +5231,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TD_TW_S(int16_t x1, int16_t y1, int16 // POLY 3/4 G-SHADED //////////////////////////////////////////////////////////////////////// -inline void PCSX::SoftGPU::SoftRenderer::drawPoly3Gi(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int32_t rgb1, int32_t rgb2, int32_t rgb3) { +inline void PCSX::SoftGPU::SoftRenderer::drawPoly3Gi(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int32_t rgb1, int32_t rgb2, int32_t rgb3) { int i, j, xmin, xmax, ymin, ymax; int32_t cR1, cG1, cB1; int32_t difR, difB, difG, difR2, difB2, difG2; @@ -5236,7 +5280,7 @@ inline void PCSX::SoftGPU::SoftRenderer::drawPoly3Gi(int16_t x1, int16_t y1, int } for (j = xmin; j < xmax; j += 2) { - *((uint32_t *)&psxVuw[(i << 10) + j]) = + *((uint32_t*)&psxVuw[(i << 10) + j]) = ((((cR1 + difR) << 7) & 0x7c000000) | (((cG1 + difG) << 2) & 0x03e00000) | (((cB1 + difB) >> 3) & 0x001f0000) | (((cR1) >> 9) & 0x7c00) | (((cG1) >> 14) & 0x03e0) | (((cB1) >> 19) & 0x001f)) | @@ -5335,9 +5379,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4G(int32_t rgb1, int32_t rgb2, int32_t // POLY 3/4 G-SHADED TEX PAL4 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, - int16_t clY, int32_t col1, int32_t col2, int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, + int16_t ty3, int16_t clX, int16_t clY, int32_t col1, int32_t col2, + int32_t col3) { int i, j, xmin, xmax, ymin, ymax; int32_t cR1, cG1, cB1; int32_t difR, difB, difG, difR2, difB2, difG2; @@ -5409,7 +5454,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4(int16_t x1, int16_t y1, int16_t tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, + (uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, (cB1 >> 16) | ((cB1 + difB) & 0xff0000), (cG1 >> 16) | ((cG1 + difG) & 0xff0000), (cR1 >> 16) | ((cR1 + difR) & 0xff0000)); posX += difX2; @@ -5482,9 +5527,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4(int16_t x1, int16_t y1, int16_t //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, - int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, + int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, int32_t col1, + int32_t col2, int32_t col3) { int i, j, xmin, xmax, ymin, ymax, n_xi, n_yi, TXV; int32_t cR1, cG1, cB1; int32_t difR, difB, difG, difR2, difB2, difG2; @@ -5565,7 +5611,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4_IL(int16_t x1, int16_t y1, int1 tC2 = (psxVuw[(n_yi << 10) + YAdjust + n_xi] >> ((XAdjust & 0x03) << 2)) & 0x0f; GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, + (uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, (cB1 >> 16) | ((cB1 + difB) & 0xff0000), (cG1 >> 16) | ((cG1 + difG) & 0xff0000), (cR1 >> 16) | ((cR1 + difR) & 0xff0000)); posX += difX2; @@ -5648,9 +5694,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4_IL(int16_t x1, int16_t y1, int1 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, - int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, + int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, int32_t col1, + int32_t col2, int32_t col3) { int i, j, xmin, xmax, ymin, ymax; int32_t cR1, cG1, cB1; int32_t difR, difB, difG, difR2, difB2, difG2; @@ -5716,13 +5763,15 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4_TW(int16_t x1, int16_t y1, int1 for (j = xmin; j < xmax; j += 2) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; XAdjust = ((posX + difX) >> 16) % TWin.Position.x1; - tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, + (uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, (cB1 >> 16) | ((cB1 + difB) & 0xff0000), (cG1 >> 16) | ((cG1 + difG) & 0xff0000), (cR1 >> 16) | ((cR1 + difR) & 0xff0000)); posX += difX2; @@ -5733,7 +5782,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4_TW(int16_t x1, int16_t y1, int1 } if (j == xmax) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; GetTextureTransColGX_S(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1], (cB1 >> 16), (cG1 >> 16), (cR1 >> 16)); @@ -5772,7 +5822,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4_TW(int16_t x1, int16_t y1, int1 for (j = xmin; j <= xmax; j++) { XAdjust = (posX >> 16) % TWin.Position.x1; - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; + tC1 = + psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + (XAdjust >> 1))]; tC1 = (tC1 >> ((XAdjust & 1) << 2)) & 0xf; if (iDither) GetTextureTransColGX_Dither(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1], (cB1 >> 16), (cG1 >> 16), @@ -5800,20 +5851,22 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx4_TW(int16_t x1, int16_t y1, int1 // correct that way, so small texture distortions can // happen... -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4_TRI_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, - int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY, int32_t col1, int32_t col2, int32_t col3, int32_t col4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4_TRI_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY, int32_t col1, + int32_t col2, int32_t col3, int32_t col4) { drawPoly3TGEx4_IL(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4, clX, clY, col2, col4, col3); drawPoly3TGEx4_IL(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4, clX, clY, col1, col2, col3); } #ifdef POLYQUAD3GT -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, - int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, - int32_t col1, int32_t col2, int32_t col3, int32_t col4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, + int32_t col3, int32_t col4) { drawPoly3TGEx4(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4, clX, clY, col2, col4, col3); drawPoly3TGEx4(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4, clX, clY, col1, col2, col3); } @@ -5822,10 +5875,11 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4_TRI(int16_t x1, int16_t y1, int //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, int32_t col1, - int32_t col2, int32_t col4, int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, + int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, + int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col4, + int32_t col3) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t cR1, cG1, cB1; @@ -5903,7 +5957,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4(int16_t x1, int16_t y1, int16_t tC2 = (tC2 >> ((XAdjust & 1) << 2)) & 0xf; GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, + (uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, (cB1 >> 16) | ((cB1 + difB) & 0xff0000), (cG1 >> 16) | ((cG1 + difG) & 0xff0000), (cR1 >> 16) | ((cR1 + difR) & 0xff0000)); posX += difX2; @@ -5988,10 +6042,11 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4(int16_t x1, int16_t y1, int16_t //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, - int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, - int32_t col1, int32_t col2, int32_t col3, int32_t col4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, + int32_t col3, int32_t col4) { drawPoly3TGEx4_TW(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4, clX, clY, col2, col4, col3); drawPoly3TGEx4_TW(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4, clX, clY, col1, col2, col3); @@ -6001,9 +6056,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx4_TW(int16_t x1, int16_t y1, int1 // POLY 3/4 G-SHADED TEX PAL8 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, - int16_t clY, int32_t col1, int32_t col2, int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, + int16_t ty3, int16_t clX, int16_t clY, int32_t col1, int32_t col2, + int32_t col3) { int i, j, xmin, xmax, ymin, ymax; int32_t cR1, cG1, cB1; int32_t difR, difB, difG, difR2, difB2, difG2; @@ -6067,9 +6123,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8(int16_t x1, int16_t y1, int16_t for (j = xmin; j < xmax; j += 2) { tC1 = psxVub[static_cast(((posY >> 5) & 0xFFFFF800) + YAdjust + ((posX >> 16)))]; - tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + (((posX + difX) >> 16)))]; + tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + + (((posX + difX) >> 16)))]; GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, + (uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, (cB1 >> 16) | ((cB1 + difB) & 0xff0000), (cG1 >> 16) | ((cG1 + difG) & 0xff0000), (cR1 >> 16) | ((cR1 + difR) & 0xff0000)); posX += difX2; @@ -6138,9 +6195,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8(int16_t x1, int16_t y1, int16_t //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, - int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, + int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, int32_t col1, + int32_t col2, int32_t col3) { int i, j, xmin, xmax, ymin, ymax, n_xi, n_yi, TXV, TXU; int32_t cR1, cG1, cB1; int32_t difR, difB, difG, difR2, difB2, difG2; @@ -6218,7 +6276,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8_IL(int16_t x1, int16_t y1, int1 tC2 = (psxVuw[(n_yi << 10) + YAdjust + n_xi] >> ((TXU & 0x01) << 3)) & 0xff; GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, + (uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, (cB1 >> 16) | ((cB1 + difB) & 0xff0000), (cG1 >> 16) | ((cG1 + difG) & 0xff0000), (cR1 >> 16) | ((cR1 + difR) & 0xff0000)); posX += difX2; @@ -6299,9 +6357,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8_IL(int16_t x1, int16_t y1, int1 //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, - int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, + int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, int32_t col1, + int32_t col2, int32_t col3) { int i, j, xmin, xmax, ymin, ymax; int32_t cR1, cG1, cB1; int32_t difR, difB, difG, difR2, difB2, difG2; @@ -6365,13 +6424,13 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8_TW(int16_t x1, int16_t y1, int1 } for (j = xmin; j < xmax; j += 2) { - tC1 = - psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; tC2 = psxVub[static_cast(((((posY + difY) >> 16) % TWin.Position.y1) << 11) + YAdjust + - (((posX + difX) >> 16) % TWin.Position.x1))]; + (((posX + difX) >> 16) % TWin.Position.x1))]; GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, + (uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, (cB1 >> 16) | ((cB1 + difB) & 0xff0000), (cG1 >> 16) | ((cG1 + difG) & 0xff0000), (cR1 >> 16) | ((cR1 + difR) & 0xff0000)); posX += difX2; @@ -6381,8 +6440,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8_TW(int16_t x1, int16_t y1, int1 cB1 += difB2; } if (j == xmax) { - tC1 = - psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; GetTextureTransColGX_S(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1], (cB1 >> 16), (cG1 >> 16), (cR1 >> 16)); } @@ -6419,7 +6478,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8_TW(int16_t x1, int16_t y1, int1 } for (j = xmin; j <= xmax; j++) { - tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + ((posX >> 16) % TWin.Position.x1))]; + tC1 = psxVub[static_cast((((posY >> 16) % TWin.Position.y1) << 11) + YAdjust + + ((posX >> 16) % TWin.Position.x1))]; if (iDither) GetTextureTransColGX_Dither(&psxVuw[(i << 10) + j], psxVuw[clutP + tC1], (cB1 >> 16), (cG1 >> 16), (cR1 >> 16)); @@ -6443,30 +6503,33 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGEx8_TW(int16_t x1, int16_t y1, int1 // note: two g-shaded tris: small texture distortions can happen -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8_TRI_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, - int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY, int32_t col1, int32_t col2, int32_t col3, int32_t col4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8_TRI_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY, int32_t col1, + int32_t col2, int32_t col3, int32_t col4) { drawPoly3TGEx8_IL(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4, clX, clY, col2, col4, col3); drawPoly3TGEx8_IL(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4, clX, clY, col1, col2, col3); } #ifdef POLYQUAD3GT -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, - int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, - int32_t col1, int32_t col2, int32_t col3, int32_t col4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, + int32_t col3, int32_t col4) { drawPoly3TGEx8(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4, clX, clY, col2, col4, col3); drawPoly3TGEx8(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4, clX, clY, col1, col2, col3); } #endif -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, int32_t col1, - int32_t col2, int32_t col4, int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, + int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, + int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col4, + int32_t col3) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t cR1, cG1, cB1; @@ -6537,10 +6600,11 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8(int16_t x1, int16_t y1, int16_t for (j = xmin; j < xmax; j += 2) { tC1 = psxVub[static_cast(((posY >> 5) & 0xFFFFF800) + YAdjust + (posX >> 16))]; - tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + ((posX + difX) >> 16))]; + tC2 = psxVub[static_cast((((posY + difY) >> 5) & 0xFFFFF800) + YAdjust + + ((posX + difX) >> 16))]; GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, + (uint32_t*)&psxVuw[(i << 10) + j], psxVuw[clutP + tC1] | ((int32_t)psxVuw[clutP + tC2]) << 16, (cB1 >> 16) | ((cB1 + difB) & 0xff0000), (cG1 >> 16) | ((cG1 + difG) & 0xff0000), (cR1 >> 16) | ((cR1 + difR) & 0xff0000)); posX += difX2; @@ -6620,10 +6684,11 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8(int16_t x1, int16_t y1, int16_t //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, - int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, - int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, - int32_t col1, int32_t col2, int32_t col3, int32_t col4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, + int32_t col3, int32_t col4) { drawPoly3TGEx8_TW(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4, clX, clY, col2, col4, col3); drawPoly3TGEx8_TW(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4, clX, clY, col1, col2, col3); } @@ -6632,9 +6697,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TGEx8_TW(int16_t x1, int16_t y1, int1 // POLY 3 G-SHADED TEX 15 BIT //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TGD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int32_t col1, - int32_t col2, int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TGD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, + int16_t ty3, int32_t col1, int32_t col2, int32_t col3) { int i, j, xmin, xmax, ymin, ymax; int32_t cR1, cG1, cB1; int32_t difR, difB, difG, difR2, difB2, difG2; @@ -6693,9 +6758,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGD(int16_t x1, int16_t y1, int16_t x for (j = xmin; j < xmax; j += 2) { GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t)psxVuw[((((posY + difY) >> 16) + GlobalTextAddrY) << 10) + ((posX + difX) >> 16) + - GlobalTextAddrX]) + GlobalTextAddrX]) << 16) | psxVuw[(((posY >> 16) + GlobalTextAddrY) << 10) + ((posX) >> 16) + GlobalTextAddrX], (cB1 >> 16) | ((cB1 + difB) & 0xff0000), (cG1 >> 16) | ((cG1 + difG) & 0xff0000), @@ -6769,9 +6834,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGD(int16_t x1, int16_t y1, int16_t x //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3TGD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int32_t col1, - int32_t col2, int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly3TGD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, + int16_t tx3, int16_t ty3, int32_t col1, int32_t col2, int32_t col3) { int i, j, xmin, xmax, ymin, ymax; int32_t cR1, cG1, cB1; int32_t difR, difB, difG, difR2, difB2, difG2; @@ -6830,7 +6895,7 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGD_TW(int16_t x1, int16_t y1, int16_ for (j = xmin; j < xmax; j += 2) { GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t) psxVuw[(((((posY + difY) >> 16) % TWin.Position.y1) + GlobalTextAddrY + TWin.Position.y0) << 10) + @@ -6916,9 +6981,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3TGD_TW(int16_t x1, int16_t y1, int16_ #ifdef POLYQUAD3GT -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGD_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int32_t col1, int32_t col2, int32_t col3, +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGD_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int32_t col1, int32_t col2, int32_t col3, int32_t col4) { drawPoly3TGD(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4, col2, col4, col3); drawPoly3TGD(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4, col1, col2, col3); @@ -6926,10 +6992,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TGD_TRI(int16_t x1, int16_t y1, int16 #endif -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int32_t col1, int32_t col2, int32_t col4, - int32_t col3) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, + int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, + int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, + int32_t col1, int32_t col2, int32_t col4, int32_t col3) { int32_t num; int32_t i, j, xmin, xmax, ymin, ymax; int32_t cR1, cG1, cB1; @@ -6995,9 +7061,9 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TGD(int16_t x1, int16_t y1, int16_t x for (j = xmin; j < xmax; j += 2) { GetTextureTransColGX32_S( - (uint32_t *)&psxVuw[(i << 10) + j], + (uint32_t*)&psxVuw[(i << 10) + j], (((int32_t)psxVuw[((((posY + difY) >> 16) + GlobalTextAddrY) << 10) + ((posX + difX) >> 16) + - GlobalTextAddrX]) + GlobalTextAddrX]) << 16) | psxVuw[(((posY >> 16) + GlobalTextAddrY) << 10) + ((posX) >> 16) + GlobalTextAddrX], (cB1 >> 16) | ((cB1 + difB) & 0xff0000), (cG1 >> 16) | ((cG1 + difG) & 0xff0000), @@ -7082,10 +7148,10 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4TGD(int16_t x1, int16_t y1, int16_t x //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4TGD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, - int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, - int16_t ty3, int16_t tx4, int16_t ty4, int32_t col1, int32_t col2, int32_t col3, - int32_t col4) { +void PCSX::SoftGPU::SoftRenderer::drawPoly4TGD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, + int16_t y3, int16_t x4, int16_t y4, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int32_t col1, int32_t col2, int32_t col3, int32_t col4) { drawPoly3TGD_TW(x2, y2, x3, y3, x4, y4, tx2, ty2, tx3, ty3, tx4, ty4, col2, col4, col3); drawPoly3TGD_TW(x1, y1, x2, y2, x4, y4, tx1, ty1, tx2, ty2, tx4, ty4, col1, col2, col3); } @@ -7134,8 +7200,8 @@ inline bool PCSX::SoftGPU::SoftRenderer::IsNoRect() { //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3FT(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); +void PCSX::SoftGPU::SoftRenderer::drawPoly3FT(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); if (GlobalTextIL && GlobalTextTP < 2) { if (GlobalTextTP == 0) @@ -7199,8 +7265,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3FT(unsigned char *baseAddr) { //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4FT(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); +void PCSX::SoftGPU::SoftRenderer::drawPoly4FT(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); if (GlobalTextIL && GlobalTextTP < 2) { if (GlobalTextTP == 0) @@ -7301,8 +7367,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4FT(unsigned char *baseAddr) { //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly3GT(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); +void PCSX::SoftGPU::SoftRenderer::drawPoly3GT(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); if (GlobalTextIL && GlobalTextTP < 2) { if (GlobalTextTP == 0) @@ -7366,8 +7432,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly3GT(unsigned char *baseAddr) { //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::drawPoly4GT(unsigned char *baseAddr) { - uint32_t *gpuData = ((uint32_t *)baseAddr); +void PCSX::SoftGPU::SoftRenderer::drawPoly4GT(unsigned char* baseAddr) { + uint32_t* gpuData = ((uint32_t*)baseAddr); if (GlobalTextIL && GlobalTextTP < 2) { if (GlobalTextTP == 0) @@ -7480,8 +7546,8 @@ void PCSX::SoftGPU::SoftRenderer::drawPoly4GT(unsigned char *baseAddr) { // SPRITE FUNCS //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSpriteTWin(unsigned char *baseAddr, int32_t w, int32_t h) { - uint32_t *gpuData = (uint32_t *)baseAddr; +void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSpriteTWin(unsigned char* baseAddr, int32_t w, int32_t h) { + uint32_t* gpuData = (uint32_t*)baseAddr; int16_t sx0, sy0, sx1, sy1, sx2, sy2, sx3, sy3; int16_t tx0, ty0, tx1, ty1, tx2, ty2, tx3, ty3; @@ -7515,11 +7581,11 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSpriteTWin(unsigned char *baseAddr //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSpriteMirror(unsigned char *baseAddr, int32_t w, int32_t h) { +void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSpriteMirror(unsigned char* baseAddr, int32_t w, int32_t h) { int32_t sprtY, sprtX, sprtW, sprtH, lXDir, lYDir; int32_t clutY0, clutX0, clutP, textX0, textY0, sprtYa, sprCY, sprCX, sprA; int16_t tC; - uint32_t *gpuData = (uint32_t *)baseAddr; + uint32_t* gpuData = (uint32_t*)baseAddr; sprtY = ly0; sprtX = lx0; sprtH = h; @@ -7595,9 +7661,9 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSpriteMirror(unsigned char *baseAd clutP >>= 1; for (sprCY = 0; sprCY < sprtH; sprCY++) for (sprCX = 0; sprCX < sprtW; sprCX++) { - tC = - psxVub[static_cast(((textY0 + (sprCY * lYDir)) << 11) + (GlobalTextAddrX << 1) + textX0 + (sprCX * lXDir))] & - 0xff; + tC = psxVub[static_cast(((textY0 + (sprCY * lYDir)) << 11) + (GlobalTextAddrX << 1) + + textX0 + (sprCX * lXDir))] & + 0xff; GetTextureTransColG_SPR(&psxVuw[((sprtY + sprCY) << 10) + sprtX + sprCX], psxVuw[clutP + tC]); } return; @@ -7616,9 +7682,10 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSpriteMirror(unsigned char *baseAd //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite_IL(unsigned char *baseAddr, int16_t w, int16_t h, int32_t tx, int32_t ty) { +void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite_IL(unsigned char* baseAddr, int16_t w, int16_t h, int32_t tx, + int32_t ty) { int32_t sprtY, sprtX, sprtW, sprtH, tdx, tdy; - uint32_t *gpuData = (uint32_t *)baseAddr; + uint32_t* gpuData = (uint32_t*)baseAddr; sprtY = ly0; sprtX = lx0; @@ -7650,12 +7717,13 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite_IL(unsigned char *baseAddr, //////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite(unsigned char *baseAddr, int16_t w, int16_t h, int32_t tx, int32_t ty) { +void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite(unsigned char* baseAddr, int16_t w, int16_t h, int32_t tx, + int32_t ty) { int32_t sprtY, sprtX, sprtW, sprtH; int32_t clutY0, clutX0, clutP, textX0, textY0, sprtYa, sprCY, sprCX, sprA; int16_t tC, tC2; - uint32_t *gpuData = (uint32_t *)baseAddr; - unsigned char *pV; + uint32_t* gpuData = (uint32_t*)baseAddr; + unsigned char* pV; bool bWT, bWS; if (GlobalTextIL && GlobalTextTP < 2) { @@ -7744,7 +7812,7 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite(unsigned char *baseAddr, in tC = *pV++; GetTextureTransColG32_S( - (uint32_t *)&psxVuw[sprA], + (uint32_t*)&psxVuw[sprA], (((int32_t)psxVuw[clutP + ((tC >> 4) & 0xf)]) << 16) | psxVuw[clutP + (tC & 0x0f)]); } @@ -7771,7 +7839,7 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite(unsigned char *baseAddr, in tC = *pV++; GetTextureTransColG32_SPR( - (uint32_t *)&psxVuw[sprA], + (uint32_t*)&psxVuw[sprA], (((int32_t)psxVuw[clutP + ((tC >> 4) & 0xf)]) << 16) | psxVuw[clutP + (tC & 0x0f)]); } @@ -7796,7 +7864,7 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite(unsigned char *baseAddr, in for (sprCX = 0; sprCX < sprtW; sprCX += 2, sprA += 2) { tC = *pV++; tC2 = *pV++; - GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA], + GetTextureTransColG32_S((uint32_t*)&psxVuw[sprA], (((int32_t)psxVuw[clutP + tC2]) << 16) | psxVuw[clutP + tC]); } if (sprCX == sprtW) GetTextureTransColG_S(&psxVuw[sprA], psxVuw[clutP + (*pV)]); @@ -7812,7 +7880,7 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite(unsigned char *baseAddr, in for (sprCX = 0; sprCX < sprtW; sprCX += 2, sprA += 2) { tC = *pV++; tC2 = *pV++; - GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA], + GetTextureTransColG32_SPR((uint32_t*)&psxVuw[sprA], (((int32_t)psxVuw[clutP + tC2]) << 16) | psxVuw[clutP + tC]); } if (sprCX == sprtW) GetTextureTransColG_SPR(&psxVuw[sprA], psxVuw[clutP + (*pV)]); @@ -7831,7 +7899,7 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite(unsigned char *baseAddr, in sprA = ((sprtY + sprCY) << 10) + sprtX; for (sprCX = 0; sprCX < sprtW; sprCX += 2, sprA += 2) { - GetTextureTransColG32_S((uint32_t *)&psxVuw[sprA], + GetTextureTransColG32_S((uint32_t*)&psxVuw[sprA], (((int32_t)psxVuw[(sprCY << 10) + textX0 + sprCX + 1]) << 16) | psxVuw[(sprCY << 10) + textX0 + sprCX]); } @@ -7846,7 +7914,7 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite(unsigned char *baseAddr, in sprA = ((sprtY + sprCY) << 10) + sprtX; for (sprCX = 0; sprCX < sprtW; sprCX += 2, sprA += 2) { - GetTextureTransColG32_SPR((uint32_t *)&psxVuw[sprA], + GetTextureTransColG32_SPR((uint32_t*)&psxVuw[sprA], (((int32_t)psxVuw[(sprCY << 10) + textX0 + sprCX + 1]) << 16) | psxVuw[(sprCY << 10) + textX0 + sprCX]); } @@ -7868,8 +7936,7 @@ void PCSX::SoftGPU::SoftRenderer::DrawSoftwareSprite(unsigned char *baseAddr, in /////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::Line_E_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, - uint32_t rgb1) { +void PCSX::SoftGPU::SoftRenderer::Line_E_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1) { int dx, dy, incrE, incrSE, d; uint32_t r0, g0, b0, r1, g1, b1; int32_t dr, dg, db; @@ -7922,8 +7989,7 @@ void PCSX::SoftGPU::SoftRenderer::Line_E_SE_Shade(int x0, int y0, int x1, int y1 /////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::Line_S_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, - uint32_t rgb1) { +void PCSX::SoftGPU::SoftRenderer::Line_S_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1) { int dx, dy, incrS, incrSE, d; uint32_t r0, g0, b0, r1, g1, b1; int32_t dr, dg, db; @@ -7976,8 +8042,7 @@ void PCSX::SoftGPU::SoftRenderer::Line_S_SE_Shade(int x0, int y0, int x1, int y1 /////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::Line_N_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, - uint32_t rgb1) { +void PCSX::SoftGPU::SoftRenderer::Line_N_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1) { int dx, dy, incrN, incrNE, d; uint32_t r0, g0, b0, r1, g1, b1; int32_t dr, dg, db; @@ -8030,8 +8095,7 @@ void PCSX::SoftGPU::SoftRenderer::Line_N_NE_Shade(int x0, int y0, int x1, int y1 /////////////////////////////////////////////////////////////////////// -void PCSX::SoftGPU::SoftRenderer::Line_E_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, - uint32_t rgb1) { +void PCSX::SoftGPU::SoftRenderer::Line_E_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1) { int dx, dy, incrE, incrNE, d; uint32_t r0, g0, b0, r1, g1, b1; int32_t dr, dg, db; diff --git a/src/gpu/soft/soft.h b/src/gpu/soft/soft.h index a6659a723..442c0ad0d 100644 --- a/src/gpu/soft/soft.h +++ b/src/gpu/soft/soft.h @@ -65,13 +65,13 @@ class SoftRenderer { void drawPoly4G(int32_t rgb1, int32_t rgb2, int32_t rgb3, int32_t rgb4); void drawPoly3F(int32_t rgb); void drawPoly4F(int32_t rgb); - void drawPoly4FT(unsigned char *baseAddr); - void drawPoly4GT(unsigned char *baseAddr); - void drawPoly3FT(unsigned char *baseAddr); - void drawPoly3GT(unsigned char *baseAddr); - void DrawSoftwareSprite(unsigned char *baseAddr, int16_t w, int16_t h, int32_t tx, int32_t ty); - void DrawSoftwareSpriteTWin(unsigned char *baseAddr, int32_t w, int32_t h); - void DrawSoftwareSpriteMirror(unsigned char *baseAddr, int32_t w, int32_t h); + void drawPoly4FT(unsigned char* baseAddr); + void drawPoly4GT(unsigned char* baseAddr); + void drawPoly3FT(unsigned char* baseAddr); + void drawPoly3GT(unsigned char* baseAddr); + void DrawSoftwareSprite(unsigned char* baseAddr, int16_t w, int16_t h, int32_t tx, int32_t ty); + void DrawSoftwareSpriteTWin(unsigned char* baseAddr, int32_t w, int32_t h); + void DrawSoftwareSpriteMirror(unsigned char* baseAddr, int32_t w, int32_t h); void DrawSoftwareLineShade(int32_t rgb0, int32_t rgb1); void DrawSoftwareLineFlat(int32_t rgb); @@ -81,137 +81,159 @@ class SoftRenderer { bool IsNoRect(); bool SetupSections_F(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3); - bool SetupSections_G(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int32_t rgb1, int32_t rgb2, int32_t rgb3); - bool SetupSections_FT(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3); - bool SetupSections_GT(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int32_t rgb1, int32_t rgb2, int32_t rgb3); - bool SetupSections_F4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4); - bool SetupSections_FT4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4); - bool SetupSections_GT4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int32_t rgb1, - int32_t rgb2, int32_t rgb3, int32_t rgb4); - - void GetShadeTransCol_Dither(uint16_t *pdest, int32_t m1, int32_t m2, int32_t m3); - void GetShadeTransCol(uint16_t *pdest, uint16_t color); - void GetShadeTransCol32(uint32_t *pdest, uint32_t color); - void GetTextureTransColG(uint16_t *pdest, uint16_t color); - void GetTextureTransColG_S(uint16_t *pdest, uint16_t color); - void GetTextureTransColG_SPR(uint16_t *pdest, uint16_t color); - void GetTextureTransColG32(uint32_t *pdest, uint32_t color); - void GetTextureTransColG32_S(uint32_t *pdest, uint32_t color); - void GetTextureTransColG32_SPR(uint32_t *pdest, uint32_t color); - void GetTextureTransColGX_Dither(uint16_t *pdest, uint16_t color, int32_t m1, int32_t m2, int32_t m3); - void GetTextureTransColGX(uint16_t *pdest, uint16_t color, int16_t m1, int16_t m2, int16_t m3); - void GetTextureTransColGX_S(uint16_t *pdest, uint16_t color, int16_t m1, int16_t m2, int16_t m3); - void GetTextureTransColGX32_S(uint32_t *pdest, uint32_t color, int16_t m1, int16_t m2, int16_t m3); - void DrawSoftwareSprite_IL(unsigned char *baseAddr, int16_t w, int16_t h, int32_t tx, int32_t ty); + bool SetupSections_G(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int32_t rgb1, + int32_t rgb2, int32_t rgb3); + bool SetupSections_FT(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3); + bool SetupSections_GT(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int32_t rgb1, int32_t rgb2, + int32_t rgb3); + bool SetupSections_F4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4); + bool SetupSections_FT4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4); + bool SetupSections_GT4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int32_t rgb1, int32_t rgb2, int32_t rgb3, int32_t rgb4); + + void GetShadeTransCol_Dither(uint16_t* pdest, int32_t m1, int32_t m2, int32_t m3); + void GetShadeTransCol(uint16_t* pdest, uint16_t color); + void GetShadeTransCol32(uint32_t* pdest, uint32_t color); + void GetTextureTransColG(uint16_t* pdest, uint16_t color); + void GetTextureTransColG_S(uint16_t* pdest, uint16_t color); + void GetTextureTransColG_SPR(uint16_t* pdest, uint16_t color); + void GetTextureTransColG32(uint32_t* pdest, uint32_t color); + void GetTextureTransColG32_S(uint32_t* pdest, uint32_t color); + void GetTextureTransColG32_SPR(uint32_t* pdest, uint32_t color); + void GetTextureTransColGX_Dither(uint16_t* pdest, uint16_t color, int32_t m1, int32_t m2, int32_t m3); + void GetTextureTransColGX(uint16_t* pdest, uint16_t color, int16_t m1, int16_t m2, int16_t m3); + void GetTextureTransColGX_S(uint16_t* pdest, uint16_t color, int16_t m1, int16_t m2, int16_t m3); + void GetTextureTransColGX32_S(uint32_t* pdest, uint32_t color, int16_t m1, int16_t m2, int16_t m3); + void DrawSoftwareSprite_IL(unsigned char* baseAddr, int16_t w, int16_t h, int32_t tx, int32_t ty); void drawPoly3Fi(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int32_t rgb); - void drawPoly3TD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3); - void drawPoly3TEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); - void drawPoly3TEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); - void drawPoly3TEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); - void drawPoly4TEx4_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY); - void drawPoly4TEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY); - void drawPoly4TEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY); - void drawPoly4TEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY); - void drawPoly4TEx4_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY); - void drawPoly3TEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); - void drawPoly3TEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); - void drawPoly3TEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); - void drawPoly4TEx8_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY); - void drawPoly4TEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY); - void drawPoly4TEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY); - void drawPoly4TEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY); - void drawPoly4TEx8_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY); - void drawPoly3TD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3); - void drawPoly4TD_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4); - void drawPoly4TD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4); - void drawPoly4TD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4); - void drawPoly4TD_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4); - void drawPoly3Gi(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int32_t rgb1, int32_t rgb2, int32_t rgb3); - void drawPoly3TGEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3); - void drawPoly3TGEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3); - void drawPoly3TGEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3); - void drawPoly4TGEx4_TRI_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, - int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3, int32_t col4); - void drawPoly4TGEx4_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY, int32_t col1, int32_t col2, int32_t col3, int32_t col4); - void drawPoly4TGEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY, int32_t col1, int32_t col2, int32_t col4, int32_t col3); - void drawPoly4TGEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY, int32_t col1, int32_t col2, int32_t col3, int32_t col4); - void drawPoly3TGEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3); - void drawPoly3TGEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3); - void drawPoly3TGEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3); - void drawPoly4TGEx8_TRI_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, - int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, - int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3, int32_t col4); - void drawPoly4TGEx8_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY, int32_t col1, int32_t col2, int32_t col3, int32_t col4); - void drawPoly4TGEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY, int32_t col1, int32_t col2, int32_t col4, int32_t col3); - void drawPoly4TGEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int16_t clX, - int16_t clY, int32_t col1, int32_t col2, int32_t col3, int32_t col4); - void drawPoly3TGD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int32_t col1, int32_t col2, int32_t col3); - void drawPoly3TGD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, int16_t tx2, - int16_t ty2, int16_t tx3, int16_t ty3, int32_t col1, int32_t col2, int32_t col3); - void drawPoly4TGD_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int32_t col1, - int32_t col2, int32_t col3, int32_t col4); - void drawPoly4TGD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int32_t col1, int32_t col2, - int32_t col4, int32_t col3); - void drawPoly4TGD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, int16_t tx1, - int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, int16_t ty4, int32_t col1, - int32_t col2, int32_t col3, int32_t col4); + void drawPoly3TD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3); + void drawPoly3TEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); + void drawPoly3TEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); + void drawPoly3TEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); + void drawPoly4TEx4_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY); + void drawPoly4TEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY); + void drawPoly4TEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY); + void drawPoly4TEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY); + void drawPoly4TEx4_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY); + void drawPoly3TEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); + void drawPoly3TEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); + void drawPoly3TEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY); + void drawPoly4TEx8_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY); + void drawPoly4TEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY); + void drawPoly4TEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY); + void drawPoly4TEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY); + void drawPoly4TEx8_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY); + void drawPoly3TD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3); + void drawPoly4TD_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4); + void drawPoly4TD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4); + void drawPoly4TD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4); + void drawPoly4TD_TW_S(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4); + void drawPoly3Gi(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int32_t rgb1, int32_t rgb2, + int32_t rgb3); + void drawPoly3TGEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, + int32_t col1, int32_t col2, int32_t col3); + void drawPoly3TGEx4_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, + int32_t col1, int32_t col2, int32_t col3); + void drawPoly3TGEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, + int32_t col1, int32_t col2, int32_t col3); + void drawPoly4TGEx4_TRI_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, + int32_t col3, int32_t col4); + void drawPoly4TGEx4_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, + int32_t col3, int32_t col4); + void drawPoly4TGEx4(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col4, int32_t col3); + void drawPoly4TGEx4_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3, + int32_t col4); + void drawPoly3TGEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, + int32_t col1, int32_t col2, int32_t col3); + void drawPoly3TGEx8_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, + int32_t col1, int32_t col2, int32_t col3); + void drawPoly3TGEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t clX, int16_t clY, + int32_t col1, int32_t col2, int32_t col3); + void drawPoly4TGEx8_TRI_IL(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, + int32_t col3, int32_t col4); + void drawPoly4TGEx8_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, + int32_t col3, int32_t col4); + void drawPoly4TGEx8(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col4, int32_t col3); + void drawPoly4TGEx8_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int16_t clX, int16_t clY, int32_t col1, int32_t col2, int32_t col3, + int32_t col4); + void drawPoly3TGD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, int16_t ty1, + int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int32_t col1, int32_t col2, int32_t col3); + void drawPoly3TGD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t tx1, + int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int32_t col1, int32_t col2, + int32_t col3); + void drawPoly4TGD_TRI(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, + int16_t y4, int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, + int16_t tx4, int16_t ty4, int32_t col1, int32_t col2, int32_t col3, int32_t col4); + void drawPoly4TGD(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int32_t col1, int32_t col2, int32_t col4, int32_t col3); + void drawPoly4TGD_TW(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4, + int16_t tx1, int16_t ty1, int16_t tx2, int16_t ty2, int16_t tx3, int16_t ty3, int16_t tx4, + int16_t ty4, int32_t col1, int32_t col2, int32_t col3, int32_t col4); void Line_E_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1); void Line_S_SE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1); void Line_N_NE_Shade(int x0, int y0, int x1, int y1, uint32_t rgb0, uint32_t rgb1); diff --git a/src/gpu/soft/zn.cc b/src/gpu/soft/zn.cc index 438520104..33b74b4b8 100644 --- a/src/gpu/soft/zn.cc +++ b/src/gpu/soft/zn.cc @@ -78,9 +78,9 @@ int iTileCheat = 0; typedef struct GPUOTAG { uint32_t Version; // Version of structure - currently 1 - int32_t hWnd; // Window handle + int32_t hWnd; // Window handle uint32_t ScreenRotation; // 0 = 0CW, 1 = 90CW, 2 = 180CW, 3 = 270CW = 90CCW uint32_t GPUVersion; // 0 = a, 1 = b, 2 = c - const char* GameName; // NULL terminated string - const char* CfgFile; // NULL terminated string + const char* GameName; // NULL terminated string + const char* CfgFile; // NULL terminated string } GPUConfiguration_t; diff --git a/src/gui/gui.h b/src/gui/gui.h index 8c4436b52..046bd8ef0 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -50,7 +50,7 @@ namespace PCSX { class GUI final { public: - GUI(const flags::args &args) : m_args(args) {} + GUI(const flags::args& args) : m_args(args) {} void init(); void close(); void update(); @@ -58,14 +58,14 @@ class GUI final { void bindVRAMTexture(); void setViewport(); void setFullscreen(bool); - void addLog(const char *fmt, ...) { + void addLog(const char* fmt, ...) { va_list args; va_start(args, fmt); addLog(fmt, args); va_end(args); } - void addLog(const char *fmt, va_list args) { m_log.addLog(fmt, args); } - void addNotification(const char *fmt, va_list args) { + void addLog(const char* fmt, va_list args) { m_log.addLog(fmt, args); } + void addNotification(const char* fmt, va_list args) { // TODO // SDL_TriggerBreakpoint(); } @@ -86,7 +86,7 @@ class GUI final { void interruptsScaler(); public: - static void normalizeDimensions(ImVec2 &vec, float ratio) { + static void normalizeDimensions(ImVec2& vec, float ratio) { float r = vec.y / vec.x; if (r > ratio) { vec.y = vec.x * ratio; @@ -96,11 +96,11 @@ class GUI final { } private: - GLFWwindow *m_window = nullptr; - int &m_glfwPosX = settings.get().value; - int &m_glfwPosY = settings.get().value; - int &m_glfwSizeX = settings.get().value; - int &m_glfwSizeY = settings.get().value; + GLFWwindow* m_window = nullptr; + int& m_glfwPosX = settings.get().value; + int& m_glfwPosY = settings.get().value; + int& m_glfwSizeX = settings.get().value; + int& m_glfwSizeY = settings.get().value; unsigned int m_VRAMTexture = 0; unsigned int m_offscreenFrameBuffer = 0; @@ -112,7 +112,7 @@ class GUI final { ImVec2 m_renderSize = ImVec2(1, 1); float m_renderRatio = 3.0f / 4.0f; - bool &m_fullscreen = {settings.get().value}; + bool& m_fullscreen = {settings.get().value}; // GUI typedef Setting Fullscreen; @@ -127,8 +127,8 @@ class GUI final { Settings settings; - bool &m_fullscreenRender = {settings.get().value}; - bool &m_showMenu = {settings.get().value}; + bool& m_fullscreenRender = {settings.get().value}; + bool& m_showMenu = {settings.get().value}; bool m_showDemo = false; bool m_showAbout = false; bool m_showInterruptsScaler = false; @@ -139,10 +139,10 @@ class GUI final { editor.OptUpperCaseHex = false; } MemoryEditor editor; - std::function title; - bool &show = editor.Open; + std::function title; + bool& show = editor.Open; void MenuItem() { ImGui::MenuItem(title(), nullptr, &show); } - void draw(void *mem, size_t size, uint32_t baseAddr = 0) { editor.DrawWindow(title(), mem, size, baseAddr); } + void draw(void* mem, size_t size, uint32_t baseAddr = 0) { editor.DrawWindow(title(), mem, size, baseAddr); } }; std::string m_stringHolder; MemoryEditorWrapper m_mainMemEditors[8]; @@ -162,10 +162,10 @@ class GUI final { std::vector m_overlayLoadSizes; bool m_showCfg = false; - bool &m_showBiosCounters = {settings.get().value}; + bool& m_showBiosCounters = {settings.get().value}; bool m_skipBiosUnknowns = true; - const flags::args &m_args; + const flags::args& m_args; bool m_scheduleSoftReset = false; bool m_scheduleHardReset = false; diff --git a/src/gui/widgets/assembly.cc b/src/gui/widgets/assembly.cc index 750f07979..1071f2e16 100644 --- a/src/gui/widgets/assembly.cc +++ b/src/gui/widgets/assembly.cc @@ -587,8 +587,7 @@ void PCSX::Widgets::Assembly::draw(psxRegisters* registers, Memory* memory, cons }; if (clipper.DisplayStart != 0) { uint32_t addr = clipper.DisplayStart * 4 - 4; - process( - addr, [](uint32_t, const char*, uint32_t) {}, &dummy); + process(addr, [](uint32_t, const char*, uint32_t) {}, &dummy); } for (int x = clipper.DisplayStart; x < clipper.DisplayEnd; x++) { uint32_t addr = x * 4; @@ -882,7 +881,7 @@ void PCSX::Widgets::Assembly::draw(psxRegisters* registers, Memory* memory, cons for (auto fileName : filesToOpen) { std::ifstream file; // oh the irony - file.open(reinterpret_cast(fileName.c_str())); + file.open(reinterpret_cast(fileName.c_str())); if (!file) continue; while (!file.eof()) { std::string addressString; diff --git a/src/gui/widgets/breakpoints.cc b/src/gui/widgets/breakpoints.cc index 78f719d37..919375339 100644 --- a/src/gui/widgets/breakpoints.cc +++ b/src/gui/widgets/breakpoints.cc @@ -113,7 +113,8 @@ void PCSX::Widgets::Breakpoints::draw(const char* title) { if (it->second.enabled()) { ImGui::Text(" %8.8x - %-20s", it->first, PCSX::Debug::s_breakpoint_type_names[it->second.type()]()); } else { - ImGui::TextDisabled(" %8.8x - %-20s", it->first, PCSX::Debug::s_breakpoint_type_names[it->second.type()]()); + ImGui::TextDisabled(" %8.8x - %-20s", it->first, + PCSX::Debug::s_breakpoint_type_names[it->second.type()]()); } ImGui::SameLine(); std::string buttonLabel = _("Remove##"); diff --git a/src/gui/widgets/filedialog.cc b/src/gui/widgets/filedialog.cc index f1af6df05..ec6e6410d 100644 --- a/src/gui/widgets/filedialog.cc +++ b/src/gui/widgets/filedialog.cc @@ -43,27 +43,23 @@ #include "core/system.h" #include "gui/widgets/filedialog.h" -struct InputTextCallback_UserData -{ - PCSX::u8string* Str; - ImGuiInputTextCallback ChainCallback; - void* ChainCallbackUserData; +struct InputTextCallback_UserData { + PCSX::u8string* Str; + ImGuiInputTextCallback ChainCallback; + void* ChainCallbackUserData; }; -static int InputTextCallback(ImGuiInputTextCallbackData* data) -{ +static int InputTextCallback(ImGuiInputTextCallbackData* data) { InputTextCallback_UserData* user_data = (InputTextCallback_UserData*)data->UserData; - if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) - { + if (data->EventFlag == ImGuiInputTextFlags_CallbackResize) { // Resize string callback - // If for some reason we refuse the new length (BufTextLen) and/or capacity (BufSize) we need to set them back to what we want. + // If for some reason we refuse the new length (BufTextLen) and/or capacity (BufSize) we need to set them back + // to what we want. PCSX::u8string* str = user_data->Str; - IM_ASSERT(data->Buf == reinterpret_cast(str->c_str())); + IM_ASSERT(data->Buf == reinterpret_cast(str->c_str())); str->resize(data->BufTextLen); data->Buf = (char*)str->c_str(); - } - else if (user_data->ChainCallback) - { + } else if (user_data->ChainCallback) { // Forward to user callback, if any data->UserData = user_data->ChainCallbackUserData; return user_data->ChainCallback(data); @@ -71,8 +67,8 @@ static int InputTextCallback(ImGuiInputTextCallbackData* data) return 0; } -static bool InputText(const char* label, PCSX::u8string* str, ImGuiInputTextFlags flags = 0, ImGuiInputTextCallback callback = NULL, void* user_data = NULL) -{ +static bool InputText(const char* label, PCSX::u8string* str, ImGuiInputTextFlags flags = 0, + ImGuiInputTextCallback callback = NULL, void* user_data = NULL) { IM_ASSERT((flags & ImGuiInputTextFlags_CallbackResize) == 0); flags |= ImGuiInputTextFlags_CallbackResize; @@ -80,7 +76,8 @@ static bool InputText(const char* label, PCSX::u8string* str, ImGuiInputTextFlag cb_user_data.Str = str; cb_user_data.ChainCallback = callback; cb_user_data.ChainCallbackUserData = user_data; - return ImGui::InputText(label, const_cast(reinterpret_cast(str->c_str())), str->capacity() + 1, flags, InputTextCallback, &cb_user_data); + return ImGui::InputText(label, const_cast(reinterpret_cast(str->c_str())), str->capacity() + 1, + flags, InputTextCallback, &cb_user_data); } #ifdef _WIN32 @@ -195,7 +192,8 @@ bool PCSX::Widgets::FileDialog::draw() { goUp = true; } for (auto& p : m_directories) { - if (ImGui::Selectable(reinterpret_cast(p.c_str()), false, 0, ImVec2(ImGui::GetWindowContentRegionWidth(), 0))) { + if (ImGui::Selectable(reinterpret_cast(p.c_str()), false, 0, + ImVec2(ImGui::GetWindowContentRegionWidth(), 0))) { goDown = p; } } @@ -296,7 +294,8 @@ bool PCSX::Widgets::FileDialog::draw() { for (auto& p : m_files) { PCSX::u8string label = MAKEU8(u8"##") + p.filename; - if (ImGui::Selectable(reinterpret_cast(label.c_str()), p.selected, ImGuiSelectableFlags_SpanAllColumns)) { + if (ImGui::Selectable(reinterpret_cast(label.c_str()), p.selected, + ImGuiSelectableFlags_SpanAllColumns)) { for (auto& f : m_files) f.selected = false; p.selected = true; if (m_flags & NewFile) { @@ -326,7 +325,8 @@ bool PCSX::Widgets::FileDialog::draw() { selectedStr = m_newFile; gotSelected = !m_newFile.empty(); } else { - selectedStr = (m_currentPath / std::filesystem::path(selected ? selected->filename : MAKEU8(u8"..."))).u8string(); + selectedStr = + (m_currentPath / std::filesystem::path(selected ? selected->filename : MAKEU8(u8"..."))).u8string(); ImGui::Text(reinterpret_cast(selectedStr.c_str())); } if (!gotSelected) { diff --git a/src/gui/widgets/filedialog.h b/src/gui/widgets/filedialog.h index a94c2a060..90697d517 100644 --- a/src/gui/widgets/filedialog.h +++ b/src/gui/widgets/filedialog.h @@ -30,7 +30,9 @@ namespace Widgets { class FileDialog { public: enum Flags { NewFile = 1 }; - FileDialog(std::function title, uint64_t flags = 0) : m_title(title), m_flags(flags) { setToCurrentPath(); } + FileDialog(std::function title, uint64_t flags = 0) : m_title(title), m_flags(flags) { + setToCurrentPath(); + } void setToCurrentPath() { m_currentPath = std::filesystem::current_path(); nukeCache(); diff --git a/src/gui/widgets/log.cc b/src/gui/widgets/log.cc index 9b7526a87..f68f2f20a 100644 --- a/src/gui/widgets/log.cc +++ b/src/gui/widgets/log.cc @@ -17,8 +17,8 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * ***************************************************************************/ -#include "core/system.h" #include "gui/widgets/log.h" +#include "core/system.h" void PCSX::Widgets::Log::clear() { m_buffer.clear(); diff --git a/src/gui/widgets/log.h b/src/gui/widgets/log.h index e6a4effc1..dc73a1019 100644 --- a/src/gui/widgets/log.h +++ b/src/gui/widgets/log.h @@ -39,7 +39,7 @@ class Log { void addLog(const char* fmt, va_list args); void draw(const char* title); - bool & m_show; + bool& m_show; private: ImGuiTextBuffer m_buffer; diff --git a/src/gui/widgets/vram-viewer.cc b/src/gui/widgets/vram-viewer.cc index f7c42341e..3b4cfde5d 100644 --- a/src/gui/widgets/vram-viewer.cc +++ b/src/gui/widgets/vram-viewer.cc @@ -36,7 +36,7 @@ #define GL_SHADER_VERSION "#version 300 es\n" -static const GLchar *s_defaultVertexShader = GL_SHADER_VERSION R"( +static const GLchar* s_defaultVertexShader = GL_SHADER_VERSION R"( precision highp float; in vec2 i_position; in vec2 i_texUV; @@ -49,7 +49,7 @@ void main() { } )"; -static const GLchar *s_defaultPixelShader = GL_SHADER_VERSION R"( +static const GLchar* s_defaultPixelShader = GL_SHADER_VERSION R"( precision highp float; uniform sampler2D u_vramTexture; uniform vec2 u_origin; @@ -198,7 +198,7 @@ void main() { } )"; -void PCSX::Widgets::VRAMViewer::compileShader(const char *VS, const char *PS) { +void PCSX::Widgets::VRAMViewer::compileShader(const char* VS, const char* PS) { GLint status = 0; GLuint vertexShader = glCreateShader(GL_VERTEX_SHADER); @@ -209,7 +209,7 @@ void PCSX::Widgets::VRAMViewer::compileShader(const char *VS, const char *PS) { if (status == 0) { GLint maxLength; glGetShaderiv(vertexShader, GL_INFO_LOG_LENGTH, &maxLength); - char *log = (char *)malloc(maxLength); + char* log = (char*)malloc(maxLength); glGetShaderInfoLog(vertexShader, maxLength, &maxLength, log); m_errorMessage = std::string(_("Vertex Shader compilation error:\n")) + log; @@ -228,7 +228,7 @@ void PCSX::Widgets::VRAMViewer::compileShader(const char *VS, const char *PS) { if (status == 0) { GLint maxLength; glGetShaderiv(pixelShader, GL_INFO_LOG_LENGTH, &maxLength); - char *log = (char *)malloc(maxLength); + char* log = (char*)malloc(maxLength); glGetShaderInfoLog(pixelShader, maxLength, &maxLength, log); @@ -251,7 +251,7 @@ void PCSX::Widgets::VRAMViewer::compileShader(const char *VS, const char *PS) { if (status == 0) { GLint maxLength; glGetProgramiv(shaderProgram, GL_INFO_LOG_LENGTH, &maxLength); - char *log = (char *)malloc(maxLength); + char* log = (char*)malloc(maxLength); glGetProgramInfoLog(shaderProgram, maxLength, &maxLength, log); @@ -326,7 +326,7 @@ void PCSX::Widgets::VRAMViewer::drawVRAM(unsigned int textureID) { auto mousePos = ImGui::GetIO().MousePos - basePos; m_mousePos = mousePos - m_origin; - ImDrawList *drawList = ImGui::GetWindowDrawList(); + ImDrawList* drawList = ImGui::GetWindowDrawList(); drawList->AddCallback(imguiCBtrampoline, this); // TexCoord - (TexturePoint - ResolutionPoint) / dimensions @@ -349,7 +349,7 @@ void PCSX::Widgets::VRAMViewer::drawVRAM(unsigned int textureID) { drawList->AddCallback(ImDrawCallback_ResetRenderState, nullptr); - const auto &io = ImGui::GetIO(); + const auto& io = ImGui::GetIO(); ImVec2 texSpan = texBR - texTL; m_mouseUV = texTL + texSpan * (m_mousePos + basePos) / m_resolution; @@ -385,7 +385,7 @@ void PCSX::Widgets::VRAMViewer::drawVRAM(unsigned int textureID) { void PCSX::Widgets::VRAMViewer::drawEditor() { auto contents = ImGui::GetContentRegionAvail(); - ImGuiStyle &style = ImGui::GetStyle(); + ImGuiStyle& style = ImGui::GetStyle(); const float heightSeparator = style.ItemSpacing.y; float footerHeight = heightSeparator * 2 + 5 * ImGui::GetTextLineHeightWithSpacing(); float width = contents.x / 2 - style.ItemInnerSpacing.x; @@ -401,7 +401,7 @@ void PCSX::Widgets::VRAMViewer::drawEditor() { } } -void PCSX::Widgets::VRAMViewer::imguiCB(const ImDrawList *parentList, const ImDrawCmd *cmd) { +void PCSX::Widgets::VRAMViewer::imguiCB(const ImDrawList* parentList, const ImDrawCmd* cmd) { GLint imguiProgramID; glGetIntegerv(GL_CURRENT_PROGRAM, &imguiProgramID); @@ -439,9 +439,9 @@ void PCSX::Widgets::VRAMViewer::imguiCB(const ImDrawList *parentList, const ImDr glEnableVertexAttribArray(m_attribLocationVtxPos); glEnableVertexAttribArray(m_attribLocationVtxUV); glVertexAttribPointer(m_attribLocationVtxPos, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), - (GLvoid *)IM_OFFSETOF(ImDrawVert, pos)); + (GLvoid*)IM_OFFSETOF(ImDrawVert, pos)); glVertexAttribPointer(m_attribLocationVtxUV, 2, GL_FLOAT, GL_FALSE, sizeof(ImDrawVert), - (GLvoid *)IM_OFFSETOF(ImDrawVert, uv)); + (GLvoid*)IM_OFFSETOF(ImDrawVert, uv)); glBindTexture(GL_TEXTURE_2D, m_textureID); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); diff --git a/src/gui/widgets/vram-viewer.h b/src/gui/widgets/vram-viewer.h index e277465aa..eaccce961 100644 --- a/src/gui/widgets/vram-viewer.h +++ b/src/gui/widgets/vram-viewer.h @@ -32,7 +32,7 @@ class VRAMViewer { public: void init(); void setTitle(std::function title) { m_title = title; } - void setClutDestination(VRAMViewer *destination) { + void setClutDestination(VRAMViewer* destination) { m_clutDestination = destination; destination->m_hasClut = true; } @@ -45,13 +45,13 @@ class VRAMViewer { private: static inline const float RATIOS[] = {0.75f, 0.5f, 0.25f, 0.125f, 0.0625f, 0.03125f}; void drawVRAM(unsigned int textureID); - void compileShader(const char *VS, const char *PS); + void compileShader(const char* VS, const char* PS); void modeChanged(); - static void imguiCBtrampoline(const ImDrawList *parentList, const ImDrawCmd *cmd) { - VRAMViewer *that = reinterpret_cast(cmd->UserCallbackData); + static void imguiCBtrampoline(const ImDrawList* parentList, const ImDrawCmd* cmd) { + VRAMViewer* that = reinterpret_cast(cmd->UserCallbackData); that->imguiCB(parentList, cmd); } - void imguiCB(const ImDrawList *parentList, const ImDrawCmd *cmd); + void imguiCB(const ImDrawList* parentList, const ImDrawCmd* cmd); unsigned int m_shaderProgram = 0; int m_attribLocationTex; @@ -100,6 +100,7 @@ class VRAMViewer { bool m_greyscale = false; bool m_selectingClut = false; int m_24shift = 0; + public: bool m_show = false; @@ -109,7 +110,7 @@ class VRAMViewer { bool m_hasClut = false; ImVec2 m_clut; - VRAMViewer *m_clutDestination = nullptr; + VRAMViewer* m_clutDestination = nullptr; bool m_firstShown = false; }; diff --git a/src/main/main.cc b/src/main/main.cc index b1c944ede..ef3e2009f 100644 --- a/src/main/main.cc +++ b/src/main/main.cc @@ -20,9 +20,9 @@ #include #include +#include #include #include -#include #include "core/cdrom.h" #include "core/gpu.h" @@ -33,10 +33,10 @@ #include "gui/gui.h" #include "spu/interface.h" -static PCSX::GUI *s_gui; +static PCSX::GUI* s_gui; class SystemImpl : public PCSX::System { - virtual void printf(const char *fmt, ...) final { + virtual void printf(const char* fmt, ...) final { // print message to debugging console va_list a; va_start(a, fmt); @@ -56,7 +56,7 @@ class SystemImpl : public PCSX::System { va_end(a); } - virtual void biosPrintf(const char *fmt, ...) final { + virtual void biosPrintf(const char* fmt, ...) final { // print message to debugging console va_list a; va_start(a, fmt); @@ -76,7 +76,7 @@ class SystemImpl : public PCSX::System { va_end(a); } - virtual void vbiosPrintf(const char *fmt, va_list a) final { + virtual void vbiosPrintf(const char* fmt, va_list a) final { if (m_logfile) { va_list c; va_copy(c, a); @@ -92,7 +92,7 @@ class SystemImpl : public PCSX::System { s_gui->addLog(fmt, a); } - virtual void message(const char *fmt, ...) final { + virtual void message(const char* fmt, ...) final { // display message to user as a pop-up va_list a; va_start(a, fmt); @@ -113,7 +113,7 @@ class SystemImpl : public PCSX::System { va_end(a); } - virtual void log(const char *facility, const char *fmt, va_list a) final { + virtual void log(const char* facility, const char* fmt, va_list a) final { if (m_logfile) { va_list c; va_copy(c, a); @@ -152,21 +152,23 @@ class SystemImpl : public PCSX::System { // emulator is requesting a shutdown of the emulation } - FILE *m_logfile = nullptr; + FILE* m_logfile = nullptr; public: ~SystemImpl() { if (m_logfile) fclose(m_logfile); } - void useLogfile(const PCSX::u8string &filename) { m_logfile = fopen(reinterpret_cast(filename.c_str()), "w"); } + void useLogfile(const PCSX::u8string& filename) { + m_logfile = fopen(reinterpret_cast(filename.c_str()), "w"); + } bool m_enableStdout = false; }; using json = nlohmann::json; -int main(int argc, char **argv) { +int main(int argc, char** argv) { const flags::args args(argc, argv); if (args.get("dumpproto")) { @@ -174,7 +176,7 @@ int main(int argc, char **argv) { return 0; } - SystemImpl *system = new SystemImpl; + SystemImpl* system = new SystemImpl; PCSX::g_system = system; std::filesystem::path self = argv[0]; std::filesystem::path binDir = self.parent_path(); @@ -188,7 +190,7 @@ int main(int argc, char **argv) { s_gui = new PCSX::GUI(args); s_gui->init(); system->m_enableStdout = PCSX::g_emulator.settings.get(); - const auto &logfile = PCSX::g_emulator.settings.get().string(); + const auto& logfile = PCSX::g_emulator.settings.get().string(); if (!logfile.empty()) system->useLogfile(logfile); system->activateLocale(PCSX::g_emulator.settings.get()); diff --git a/src/main/settings.h b/src/main/settings.h index 7db1e23d1..2a49f198a 100644 --- a/src/main/settings.h +++ b/src/main/settings.h @@ -49,12 +49,12 @@ class Setting, defaultValue> { public: operator type() const { return value; } - myself &operator=(const type &v) { + myself& operator=(const type& v) { value = v; return *this; } json serialize() const { return value; } - void deserialize(const json &j) { value = j; } + void deserialize(const json& j) { value = j; } void reset() { value = defaultValue; } type value = defaultValue; }; @@ -75,13 +75,13 @@ class SettingString, irqus::typestring> { public: operator type() const { return value; } - myself &operator=(const type &v) { + myself& operator=(const type& v) { value = v; return *this; } - const char *c_str() const { return value.c_str(); } + const char* c_str() const { return value.c_str(); } json serialize() const { return value; } - void deserialize(const json &j) { value = j; } + void deserialize(const json& j) { value = j; } void reset() { value = defaultValue::data(); } type value = defaultValue::data(); }; @@ -102,14 +102,14 @@ class SettingPath, irqus::typestring> { public: operator type() const { return value; } - myself &operator=(const type &v) { + myself& operator=(const type& v) { value = v; return *this; } PCSX::u8string string() const { return value.u8string(); } bool empty() const { return value.u8string().empty(); } json serialize() const { return value.u8string(); } - void deserialize(const json &j) { + void deserialize(const json& j) { std::string str = j; value = std::filesystem::u8path(str); } @@ -135,20 +135,20 @@ class SettingArray, nestedSetting> : public std::vector< typedef irqus::typestring name; json serialize() const { auto ret = json::array(); - for (auto &item : *this) { + for (auto& item : *this) { ret.push_back(item.serialize()); } return ret; } - void deserialize(const json &j) { - for (auto &item : j) { + void deserialize(const json& j) { + for (auto& item : j) { nestedSetting s; s.deserialize(item); this->push_back(s); } } void reset() { - for (auto &item : *this) { + for (auto& item : *this) { item.reset(); } } @@ -160,11 +160,11 @@ class Settings : private std::tuple { public: template - constexpr const setting &get() const { + constexpr const setting& get() const { return std::get(*this); } template - constexpr setting &get() { + constexpr setting& get() { return std::get(*this); } constexpr void reset() { reset<0, settings...>(); } @@ -173,30 +173,30 @@ class Settings : private std::tuple { serialize<0, settings...>(ret); return ret; } - constexpr void deserialize(const json &j) { deserialize<0, settings...>(j); } + constexpr void deserialize(const json& j) { deserialize<0, settings...>(j); } private: template constexpr void reset() {} template constexpr void reset() { - settingType &setting = std::get(*this); + settingType& setting = std::get(*this); setting.reset(); reset(); } template - constexpr void serialize(json &j) const {} + constexpr void serialize(json& j) const {} template - constexpr void serialize(json &j) const { - const settingType &setting = std::get(*this); + constexpr void serialize(json& j) const { + const settingType& setting = std::get(*this); j[settingType::name::data()] = setting.serialize(); serialize(j); } template - constexpr void deserialize(const json &j, bool doReset = true) {} + constexpr void deserialize(const json& j, bool doReset = true) {} template - constexpr void deserialize(const json &j, bool doReset = true) { - settingType &setting = std::get(*this); + constexpr void deserialize(const json& j, bool doReset = true) { + settingType& setting = std::get(*this); try { if (j.find(settingType::name::data()) != j.end()) { setting.deserialize(j[settingType::name::data()]); diff --git a/src/mips/.projects/tester.code-workspace b/src/mips/.projects/tester.code-workspace new file mode 100644 index 000000000..fc81e4f98 --- /dev/null +++ b/src/mips/.projects/tester.code-workspace @@ -0,0 +1,13 @@ +{ + "folders": [ + { + "path": "/data/code/PS/PS1/pcsx-redux/src/mips/tester/src" + }, + { + "path": "/data/code/PS/PS1/pcsx-redux/src/mips/tester/crt0" + }, + { + "path": "/data/code/PS/PS1/pcsx-redux/src/mips/tester/include" + } + ] +} \ No newline at end of file diff --git a/src/mips/common.mk b/src/mips/common.mk index b15707109..e7f85b44f 100644 --- a/src/mips/common.mk +++ b/src/mips/common.mk @@ -1,6 +1,14 @@ PREFIX = mipsel-linux-gnu CC = $(PREFIX)-gcc +AR = $(PREFIX)-ar + +## If "TLOAD_ADDR" was specified in the Makefile, pass it to the linker. +ifneq ($(strip $(TLOAD_ADDR)),) +LDFLAGS += -Wl,--defsym,TLOAD_ADDR=$(TLOAD_ADDR) +endif + +TARGETBASE = $(basename $(TARGET)) ARCHFLAGS = -march=mips1 -mabi=32 -EL -fno-pic -mno-shared -mno-abicalls -mfp32 ARCHFLAGS += -fno-stack-protector -nostdlib -ffreestanding @@ -9,24 +17,37 @@ CPPFLAGS += -fno-builtin CPPFLAGS += $(ARCHFLAGS) CPPFLAGS += -I.. -LDFLAGS = -Wl,-Map=$(TARGET).map -nostdlib -T$(LDSCRIPT) -static -Wl,--gc-sections -LDFLAGS += $(ARCHFLAGS) +LDFLAGS += -Wl,-Map=$(TARGETBASE).map -nostdlib -T$(LDSCRIPT) -static -Wl,--gc-sections +LDFLAGS += $(ARCHFLAGS) -L../ps1sdk LDFLAGS += -g -Os CPPFLAGS += -g -Os OBJS += $(addsuffix .o, $(basename $(SRCS))) -all: $(TARGET).bin +all: $(TARGET) + +../ps1sdk/libps1sdk.a: + $(MAKE) -C ../ps1sdk all clean: - rm -f $(OBJS) $(TARGET).elf $(TARGET).map $(TARGET).bin + rm -f $(OBJS) $(TARGETBASE).psx $(TARGETBASE).elf $(TARGETBASE).map $(TARGETBASE).bin $(TARGET) + +$(TARGETBASE).bin: $(TARGETBASE).elf + $(PREFIX)-objcopy -O binary $< $@ -$(TARGET).bin: $(TARGET).elf +$(TARGETBASE).psx: $(TARGETBASE).elf $(PREFIX)-objcopy -O binary $< $@ -$(TARGET).elf: $(OBJS) - $(CC) $(LDFLAGS) -g -o $(TARGET).elf $(OBJS) +$(TARGETBASE).a: $(OBJS) + $(AR) cru $@ $(OBJS) + +$(TARGETBASE).elf: $(OBJS) $(LIBS) + $(CC) $(LDFLAGS) -g -o $(TARGETBASE).elf $(OBJS) $(LIBS) + +%.o: %.S + $(CC) $(CPPFLAGS) -I.. -g -c -o $@ $< %.o: %.s $(CC) $(ARCHFLAGS) -I.. -g -c -o $@ $< + diff --git a/src/mips/common/hardware/hwregs.h b/src/mips/common/hardware/hwregs.h index cacdd1bf8..4079d62f6 100644 --- a/src/mips/common/hardware/hwregs.h +++ b/src/mips/common/hardware/hwregs.h @@ -21,12 +21,12 @@ #include "common/compiler/stdint.h" -#define HW_U8(x) (*(volatile uint8_t *)(x)) -#define HW_U16(x) (*(volatile uint16_t *)(x)) -#define HW_U32(x) (*(volatile uint32_t *)(x)) -#define HW_S8(x) (*(volatile int8_t *)(x)) -#define HW_S16(x) (*(volatile int16_t *)(x)) -#define HW_S32(x) (*(volatile int32_t *)(x)) +#define HW_U8(x) (*(volatile uint8_t*)(x)) +#define HW_U16(x) (*(volatile uint16_t*)(x)) +#define HW_U32(x) (*(volatile uint32_t*)(x)) +#define HW_S8(x) (*(volatile int8_t*)(x)) +#define HW_S16(x) (*(volatile int16_t*)(x)) +#define HW_S32(x) (*(volatile int32_t*)(x)) #define SPU_MVOL_L HW_U16(0x1f801d80) #define SPU_MVOL_R HW_U16(0x1f801d82) diff --git a/src/mips/common/include/mipsregs.h b/src/mips/common/include/mipsregs.h new file mode 100644 index 000000000..87a89b3a0 --- /dev/null +++ b/src/mips/common/include/mipsregs.h @@ -0,0 +1,162 @@ +#ifndef _MIPSREGS_H +#define _MIPSREGS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* general registers */ + +#define r0 $0 +#define r1 $1 +#define r2 $2 +#define r3 $3 +#define r4 $4 +#define r5 $5 +#define r6 $6 +#define r7 $7 +#define r8 $8 +#define r9 $9 +#define r10 $10 +#define r11 $11 +#define r12 $12 +#define r13 $13 +#define r14 $14 +#define r15 $15 +#define r16 $16 +#define r17 $17 +#define r18 $18 +#define r19 $19 +#define r20 $20 +#define r21 $21 +#define r22 $22 +#define r23 $23 +#define r24 $24 +#define r25 $25 +#define r26 $26 +#define r27 $27 +#define r28 $28 +#define r29 $29 +#define r30 $30 +#define r31 $31 + +#define zero $0 +//#define at $1 +#define v0 $2 +#define v1 $3 +#define a0 $4 +#define a1 $5 +#define a2 $6 +#define a3 $7 +#define t0 $8 +#define t1 $9 +#define t2 $10 +#define t3 $11 +#define t4 $12 +#define t5 $13 +#define t6 $14 +#define t7 $15 +#define s0 $16 +#define s1 $17 +#define s2 $18 +#define s3 $19 +#define s4 $20 +#define s5 $21 +#define s6 $22 +#define s7 $23 +#define t8 $24 +#define t9 $25 +#define k0 $26 +#define k1 $27 +#define gp $28 +#define sp $29 +#define s8 $30 +#define fp $30 +#define ra $31 + +/* COP0 Registers */ + +/* BreakPoint Control */ +#define C0_BPC $3 +/* BreakPoint on Data Access */ +#define C0_BDA $5 +/* BreakPoint on Data Access */ +#define C0_DCIC $7 +#define C0_BADVADDR $8 +#define C0_BDAM $9 +#define C0_BPCM $11 + +/* Status Register */ +#define C0_STATUS $12 + +/* Cause Register */ +#define C0_CAUSE $13 + +/* Error PC Register */ +#define C0_EPC $14 + +/* Processor ID */ +#define C0_PRID $15 + +// Interrupt Enable(current) +#define SR_IEC (1 << 0) +// Kernel/User mode(current) +#define SR_KUC (1 << 1) +// Interrupt Enable(previous) +#define SR_IEP (1 << 2) +// Kernel/User mode(previous) +#define SR_KUP (1 << 3) +// Interrupt Enable(old) +#define SR_IEO (1 << 4) +// Kernel/User mode(old) +#define SR_KUO (1 << 5) + +/* Interrupt Mask 0 */ +#define SR_IMO (1 << 8) +/* Interrupt Mask 1 */ +#define SR_IM1 (1 << 9) +/* Interrupt Mask 2 */ +#define SR_IM2 (1 << 10) +/* Interrupt Mask 3 */ +#define SR_IM3 (1 << 11) +/* Interrupt Mask 4 */ +#define SR_IM4 (1 << 12) +/* Interrupt Mask 5 */ +#define SR_IM5 (1 << 13) +/* Interrupt Mask 6 */ +#define SR_IM6 (1 << 14) +/* Interrupt Mask 7 */ +#define SR_IM7 (1 << 15) + +/* Isolate Cache */ +#define SR_ISC (1 << 16) +/* Swap Caches */ +#define SR_SWC (1 << 17) +/* Parity Zero */ +#define SR_PZ (1 << 18) +/* Cache Miss */ +#define SR_CM (1 << 19) +/* Parity Error */ +#define SR_PE (1 << 20) +/* TLB Shutdown */ +#define SR_TS (1 << 21) +/* Boot-time Exception Vector */ +#define SR_BEV (1 << 22) + +/* Reverse Endian enable */ +#define SR_RE (1 << 25) + +/* Coprocessor 0 Usable */ +#define SR_CU0 (1 << 28) +/* Coprocessor 1 Usable */ +#define SR_CU1 (1 << 29) +/* Coprocessor 2 Usable */ +#define SR_CU2 (1 << 30) +/* Coprocessor 3 Usable */ +#define SR_CU3 (1 << 31) + +#ifdef __cplusplus +} +#endif + +#endif /* _MIPSREGS_H */ diff --git a/src/mips/common/util/djbhash.h b/src/mips/common/util/djbhash.h index eb096d383..1c30fc411 100644 --- a/src/mips/common/util/djbhash.h +++ b/src/mips/common/util/djbhash.h @@ -25,6 +25,4 @@ static inline uint32_t djbProcess(uint32_t hash, const char str[], unsigned n) { return n ? djbProcess(((hash << 5) + hash) ^ str[0], str + 1, n - 1) : hash; } -static inline uint32_t djbHash(const char * str, unsigned n) { - return djbProcess(5381, str, n); -} +static inline uint32_t djbHash(const char* str, unsigned n) { return djbProcess(5381, str, n); } diff --git a/src/mips/hello/Makefile b/src/mips/hello/Makefile new file mode 100644 index 000000000..d761d9595 --- /dev/null +++ b/src/mips/hello/Makefile @@ -0,0 +1,14 @@ +TARGET = hello.psx +TLOAD_ADDR = 0x80010000 +SRCS = \ + ../common/hardware/cop0.s \ + crt0/crt0.S \ + src/main.c + +LIBS = ../ps1sdk/libps1sdk.a + +LDSCRIPT = ../psx-exe.ld +CPPFLAGS := -I../ps1sdk/include -Isrc -Iinclude +LDFLAGS := -L../ps1sdk -lps1sdk + +include ../common.mk diff --git a/src/mips/hello/crt0/crt0.S b/src/mips/hello/crt0/crt0.S new file mode 100644 index 000000000..e1d246126 --- /dev/null +++ b/src/mips/hello/crt0/crt0.S @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include + +.set push +.set noreorder +.set noat + + .section .start, "ax", @progbits + .align 2 + .global main + .global _start + .type _start, @function +_start: + la t0, __bss_start + la t1, __bss_end + addiu t1, t1, 3 + srl t1, t1, 2 + sll t1, t1, 2 + beq t0, t1, _zero_bss_done + nop + +_zero_bss: + sw zero, 0(t0) + addiu t0, t0, 4 + bne t0, t1, _zero_bss + nop + +_zero_bss_done: +/* la gp, _gp*/ + li a0, 0 + j main + li a1, 0 + +/* +.end _start +.data + +.bss +*/ + .extern __bss_start + .extern __bss_end + .extern _gp +/* int _main(int argc, const char **argv, const char **envp) */ + .extern main + +.set pop diff --git a/src/mips/hello/src/main.c b/src/mips/hello/src/main.c new file mode 100644 index 000000000..c29d04c50 --- /dev/null +++ b/src/mips/hello/src/main.c @@ -0,0 +1,22 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include "common/hardware/cop0.h" + +int main() { return 0; } diff --git a/src/mips/notes.txt b/src/mips/notes.txt new file mode 100644 index 000000000..f733e3b95 --- /dev/null +++ b/src/mips/notes.txt @@ -0,0 +1 @@ +git fetch --all / git checkout -b local-branch-name upstream/master / do some commits / git push --set-upstream origin local-branch-name diff --git a/src/mips/openbios/Makefile b/src/mips/openbios/Makefile index 916bd4940..74852da6a 100644 --- a/src/mips/openbios/Makefile +++ b/src/mips/openbios/Makefile @@ -1,4 +1,4 @@ -TARGET = openbios +TARGET = openbios.bin SRCS = \ ../common/hardware/cop0.s \ @@ -9,6 +9,8 @@ kernel/handlers.c \ kernel/vectors.s \ main/main.c \ \ +romfs_data.c \ +\ uC-sdk-glue/BoardConsole.c \ uC-sdk-glue/BoardInit.c \ uC-sdk-glue/init.c \ @@ -44,3 +46,14 @@ CPPFLAGS += -I../../../third_party/uC-sdk/os/include CPPFLAGS += -IuC-sdk-glue include ../common.mk + +romfs_data.c: ../pshittyload/pshittyload.bin ../../../third_party/uC-sdk/tools/romfs/mkromfs + mkdir -p romfs + cp ../pshittyload/pshittyload.bin romfs + ../../../third_party/uC-sdk/tools/romfs/mkromfs -d romfs -c romfs romfs_data.c + +../../../third_party/uC-sdk/tools/romfs/mkromfs: + CPU_FAMILY=mips ROOTDIR=../.. $(MAKE) -C ../../../third_party/uC-sdk/tools/romfs mkromfs + +../pshittyload/pshittyload.bin: + $(MAKE) -C ../pshittyload diff --git a/src/mips/openbios/kernel/handlers.c b/src/mips/openbios/kernel/handlers.c index 60d74d69e..9964503d0 100644 --- a/src/mips/openbios/kernel/handlers.c +++ b/src/mips/openbios/kernel/handlers.c @@ -17,10 +17,25 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * ***************************************************************************/ +#include +#include + #include "osdebug.h" -#include "common/compiler/stdint.h" #include "openbios/kernel/handlers.h" +#include "common/compiler/stdint.h" + +static int printf_impl(const char * fmt, ...) { + int r; + va_list ap; + va_start(ap, fmt); + r = vprintf(fmt, ap); + va_end(ap); + + return r; +} + +void flushCache(); void unimplemented(); void breakVector(); @@ -29,108 +44,108 @@ void A0Vector(); void B0Vector(); void C0Vector(); -__attribute__((section(".a0table"))) void * A0table[0xc0] = { - unimplemented, unimplemented, unimplemented, unimplemented, // 00 - unimplemented, unimplemented, unimplemented, unimplemented, // 04 - unimplemented, unimplemented, unimplemented, unimplemented, // 08 - unimplemented, unimplemented, unimplemented, unimplemented, // 0c - unimplemented, unimplemented, unimplemented, unimplemented, // 10 - unimplemented, unimplemented, unimplemented, unimplemented, // 14 - unimplemented, unimplemented, unimplemented, unimplemented, // 18 - unimplemented, unimplemented, unimplemented, unimplemented, // 1c - unimplemented, unimplemented, unimplemented, unimplemented, // 20 - unimplemented, unimplemented, unimplemented, unimplemented, // 24 - unimplemented, unimplemented, unimplemented, unimplemented, // 28 - unimplemented, unimplemented, unimplemented, unimplemented, // 2c - unimplemented, unimplemented, unimplemented, unimplemented, // 30 - unimplemented, unimplemented, unimplemented, unimplemented, // 34 - unimplemented, unimplemented, unimplemented, unimplemented, // 38 - unimplemented, unimplemented, unimplemented, unimplemented, // 3c - unimplemented, unimplemented, unimplemented, unimplemented, // 40 - unimplemented, unimplemented, unimplemented, unimplemented, // 44 - unimplemented, unimplemented, unimplemented, unimplemented, // 48 - unimplemented, unimplemented, unimplemented, unimplemented, // 4c - unimplemented, unimplemented, unimplemented, unimplemented, // 50 - unimplemented, unimplemented, unimplemented, unimplemented, // 54 - unimplemented, unimplemented, unimplemented, unimplemented, // 58 - unimplemented, unimplemented, unimplemented, unimplemented, // 5c - unimplemented, unimplemented, unimplemented, unimplemented, // 60 - unimplemented, unimplemented, unimplemented, unimplemented, // 64 - unimplemented, unimplemented, unimplemented, unimplemented, // 68 - unimplemented, unimplemented, unimplemented, unimplemented, // 6c - unimplemented, unimplemented, unimplemented, unimplemented, // 70 - unimplemented, unimplemented, unimplemented, unimplemented, // 74 - unimplemented, unimplemented, unimplemented, unimplemented, // 78 - unimplemented, unimplemented, unimplemented, unimplemented, // 7c - unimplemented, unimplemented, unimplemented, unimplemented, // 80 - unimplemented, unimplemented, unimplemented, unimplemented, // 84 - unimplemented, unimplemented, unimplemented, unimplemented, // 88 - unimplemented, unimplemented, unimplemented, unimplemented, // 8c - unimplemented, unimplemented, unimplemented, unimplemented, // 90 - unimplemented, unimplemented, unimplemented, unimplemented, // 94 - unimplemented, unimplemented, unimplemented, unimplemented, // 98 - unimplemented, unimplemented, unimplemented, unimplemented, // 9c - unimplemented, unimplemented, unimplemented, unimplemented, // a0 - unimplemented, unimplemented, unimplemented, unimplemented, // a4 - unimplemented, unimplemented, unimplemented, unimplemented, // a8 - unimplemented, unimplemented, unimplemented, unimplemented, // ac - unimplemented, unimplemented, unimplemented, unimplemented, // b0 - unimplemented, unimplemented, unimplemented, unimplemented, // b4 - unimplemented, unimplemented, unimplemented, unimplemented, // b8 - unimplemented, unimplemented, unimplemented, unimplemented, // bc +__attribute__((section(".a0table"))) void* A0table[0xc0] = { + unimplemented, unimplemented, unimplemented, unimplemented, // 00 + unimplemented, unimplemented, unimplemented, unimplemented, // 04 + unimplemented, unimplemented, unimplemented, unimplemented, // 08 + unimplemented, unimplemented, unimplemented, unimplemented, // 0c + unimplemented, unimplemented, unimplemented, unimplemented, // 10 + unimplemented, unimplemented, unimplemented, unimplemented, // 14 + unimplemented, unimplemented, unimplemented, unimplemented, // 18 + unimplemented, unimplemented, unimplemented, unimplemented, // 1c + unimplemented, unimplemented, unimplemented, unimplemented, // 20 + unimplemented, unimplemented, unimplemented, unimplemented, // 24 + unimplemented, unimplemented, unimplemented, unimplemented, // 28 + unimplemented, unimplemented, unimplemented, unimplemented, // 2c + unimplemented, unimplemented, unimplemented, unimplemented, // 30 + unimplemented, unimplemented, unimplemented, unimplemented, // 34 + unimplemented, unimplemented, unimplemented, unimplemented, // 38 + unimplemented, unimplemented, unimplemented, printf_impl , // 3c + unimplemented, unimplemented, unimplemented, unimplemented, // 40 + flushCache, unimplemented, unimplemented, unimplemented, // 44 + unimplemented, unimplemented, unimplemented, unimplemented, // 48 + unimplemented, unimplemented, unimplemented, unimplemented, // 4c + unimplemented, unimplemented, unimplemented, unimplemented, // 50 + unimplemented, unimplemented, unimplemented, unimplemented, // 54 + unimplemented, unimplemented, unimplemented, unimplemented, // 58 + unimplemented, unimplemented, unimplemented, unimplemented, // 5c + unimplemented, unimplemented, unimplemented, unimplemented, // 60 + unimplemented, unimplemented, unimplemented, unimplemented, // 64 + unimplemented, unimplemented, unimplemented, unimplemented, // 68 + unimplemented, unimplemented, unimplemented, unimplemented, // 6c + unimplemented, unimplemented, unimplemented, unimplemented, // 70 + unimplemented, unimplemented, unimplemented, unimplemented, // 74 + unimplemented, unimplemented, unimplemented, unimplemented, // 78 + unimplemented, unimplemented, unimplemented, unimplemented, // 7c + unimplemented, unimplemented, unimplemented, unimplemented, // 80 + unimplemented, unimplemented, unimplemented, unimplemented, // 84 + unimplemented, unimplemented, unimplemented, unimplemented, // 88 + unimplemented, unimplemented, unimplemented, unimplemented, // 8c + unimplemented, unimplemented, unimplemented, unimplemented, // 90 + unimplemented, unimplemented, unimplemented, unimplemented, // 94 + unimplemented, unimplemented, unimplemented, unimplemented, // 98 + unimplemented, unimplemented, unimplemented, unimplemented, // 9c + unimplemented, unimplemented, unimplemented, unimplemented, // a0 + unimplemented, unimplemented, unimplemented, unimplemented, // a4 + unimplemented, unimplemented, unimplemented, unimplemented, // a8 + unimplemented, unimplemented, unimplemented, unimplemented, // ac + unimplemented, unimplemented, unimplemented, unimplemented, // b0 + unimplemented, unimplemented, unimplemented, unimplemented, // b4 + unimplemented, unimplemented, unimplemented, unimplemented, // b8 + unimplemented, unimplemented, unimplemented, unimplemented, // bc }; -void *B0table[0x60] = { - unimplemented, unimplemented, unimplemented, unimplemented, // 00 - unimplemented, unimplemented, unimplemented, unimplemented, // 04 - unimplemented, unimplemented, unimplemented, unimplemented, // 08 - unimplemented, unimplemented, unimplemented, unimplemented, // 0c - unimplemented, unimplemented, unimplemented, unimplemented, // 10 - unimplemented, unimplemented, unimplemented, unimplemented, // 14 - unimplemented, unimplemented, unimplemented, unimplemented, // 18 - unimplemented, unimplemented, unimplemented, unimplemented, // 1c - unimplemented, unimplemented, unimplemented, unimplemented, // 20 - unimplemented, unimplemented, unimplemented, unimplemented, // 24 - unimplemented, unimplemented, unimplemented, unimplemented, // 28 - unimplemented, unimplemented, unimplemented, unimplemented, // 2c - unimplemented, unimplemented, unimplemented, unimplemented, // 30 - unimplemented, unimplemented, unimplemented, unimplemented, // 34 - unimplemented, unimplemented, unimplemented, unimplemented, // 38 - unimplemented, unimplemented, unimplemented, unimplemented, // 3c - unimplemented, unimplemented, unimplemented, unimplemented, // 40 - unimplemented, unimplemented, unimplemented, unimplemented, // 44 - unimplemented, unimplemented, unimplemented, unimplemented, // 48 - unimplemented, unimplemented, unimplemented, unimplemented, // 4c - unimplemented, unimplemented, unimplemented, unimplemented, // 50 - unimplemented, unimplemented, unimplemented, unimplemented, // 54 - unimplemented, unimplemented, unimplemented, unimplemented, // 58 - unimplemented, unimplemented, unimplemented, unimplemented, // 5c +void* B0table[0x60] = { + unimplemented, unimplemented, unimplemented, unimplemented, // 00 + unimplemented, unimplemented, unimplemented, unimplemented, // 04 + unimplemented, unimplemented, unimplemented, unimplemented, // 08 + unimplemented, unimplemented, unimplemented, unimplemented, // 0c + unimplemented, unimplemented, unimplemented, unimplemented, // 10 + unimplemented, unimplemented, unimplemented, unimplemented, // 14 + unimplemented, unimplemented, unimplemented, unimplemented, // 18 + unimplemented, unimplemented, unimplemented, unimplemented, // 1c + unimplemented, unimplemented, unimplemented, unimplemented, // 20 + unimplemented, unimplemented, unimplemented, unimplemented, // 24 + unimplemented, unimplemented, unimplemented, unimplemented, // 28 + unimplemented, unimplemented, unimplemented, unimplemented, // 2c + unimplemented, unimplemented, unimplemented, unimplemented, // 30 + unimplemented, unimplemented, unimplemented, unimplemented, // 34 + unimplemented, unimplemented, unimplemented, unimplemented, // 38 + unimplemented, unimplemented, unimplemented, unimplemented, // 3c + unimplemented, unimplemented, unimplemented, unimplemented, // 40 + unimplemented, unimplemented, unimplemented, unimplemented, // 44 + unimplemented, unimplemented, unimplemented, unimplemented, // 48 + unimplemented, unimplemented, unimplemented, unimplemented, // 4c + unimplemented, unimplemented, unimplemented, unimplemented, // 50 + unimplemented, unimplemented, unimplemented, unimplemented, // 54 + unimplemented, unimplemented, unimplemented, unimplemented, // 58 + unimplemented, unimplemented, unimplemented, unimplemented, // 5c }; -void * C0table[0x20] = { - unimplemented, unimplemented, unimplemented, unimplemented, // 00 - unimplemented, unimplemented, unimplemented, unimplemented, // 04 - unimplemented, unimplemented, unimplemented, unimplemented, // 08 - unimplemented, unimplemented, unimplemented, unimplemented, // 0c - unimplemented, unimplemented, unimplemented, unimplemented, // 10 - unimplemented, unimplemented, unimplemented, unimplemented, // 14 - unimplemented, unimplemented, unimplemented, unimplemented, // 18 - unimplemented, unimplemented, unimplemented, unimplemented, // 1c +void* C0table[0x20] = { + unimplemented, unimplemented, unimplemented, unimplemented, // 00 + unimplemented, unimplemented, unimplemented, unimplemented, // 04 + unimplemented, unimplemented, unimplemented, unimplemented, // 08 + unimplemented, unimplemented, unimplemented, unimplemented, // 0c + unimplemented, unimplemented, unimplemented, unimplemented, // 10 + unimplemented, unimplemented, unimplemented, unimplemented, // 14 + unimplemented, unimplemented, unimplemented, unimplemented, // 18 + unimplemented, unimplemented, unimplemented, unimplemented, // 1c }; -static void installHandler(const void * src, void * dst) { - ((uint32_t *) dst)[0] = ((uint32_t *) src)[0]; - ((uint32_t *) dst)[1] = ((uint32_t *) src)[1]; - ((uint32_t *) dst)[2] = ((uint32_t *) src)[2]; - ((uint32_t *) dst)[3] = ((uint32_t *) src)[3]; +static void installHandler(const void* src, void* dst) { + ((uint32_t*)dst)[0] = ((uint32_t*)src)[0]; + ((uint32_t*)dst)[1] = ((uint32_t*)src)[1]; + ((uint32_t*)dst)[2] = ((uint32_t*)src)[2]; + ((uint32_t*)dst)[3] = ((uint32_t*)src)[3]; } void installKernelHandlers() { - installHandler(breakVector, (uint32_t *) 0x40); - installHandler(interruptVector, (uint32_t *) 0x80); - installHandler(A0Vector, (uint32_t *) 0xa0); - installHandler(B0Vector, (uint32_t *) 0xb0); - installHandler(C0Vector, (uint32_t *) 0xc0); + installHandler(breakVector, (uint32_t*)0x40); + installHandler(interruptVector, (uint32_t*)0x80); + installHandler(A0Vector, (uint32_t*)0xa0); + installHandler(B0Vector, (uint32_t*)0xb0); + installHandler(C0Vector, (uint32_t*)0xc0); } typedef struct { @@ -162,10 +177,10 @@ static void printInterruptData(InterruptData* data) { osDbgPrintf("hi = %p - lo = %p\r\n", data->GPR.r[32], data->GPR.r[33]); } -void breakHandler(InterruptData* data) { -} +void breakHandler(InterruptData* data) {} void interruptHandler(InterruptData* data) { osDbgPrintf("***Exception***\r\n"); printInterruptData(data); + while(1); } diff --git a/src/mips/openbios/kernel/vectors.s b/src/mips/openbios/kernel/vectors.s index 39ae36385..2fcd2cb8a 100644 --- a/src/mips/openbios/kernel/vectors.s +++ b/src/mips/openbios/kernel/vectors.s @@ -192,7 +192,7 @@ C0Vector: A0Handler: la $t0, A0table - sll $t2, $t1, 1 + sll $t2, $t1, 2 add $t2, $t0 lw $t2, 0($t2) li $t0, 0xa0 @@ -205,7 +205,7 @@ A0Handler: B0Handler: la $t0, B0table - sll $t2, $t1, 1 + sll $t2, $t1, 2 add $t2, $t0 lw $t2, 0($t2) li $t0, 0xb0 @@ -218,7 +218,7 @@ B0Handler: C0Handler: la $t0, C0table - sll $t2, $t1, 1 + sll $t2, $t1, 2 add $t2, $t0 lw $t2, 0($t2) li $t0, 0xc0 diff --git a/src/mips/openbios/main/main.c b/src/mips/openbios/main/main.c index 09c4f92d1..814aefbb4 100644 --- a/src/mips/openbios/main/main.c +++ b/src/mips/openbios/main/main.c @@ -18,8 +18,9 @@ ***************************************************************************/ #include -#include #include +#include +#include #include "common/hardware/cop0.h" #include "common/hardware/sio1.h" @@ -27,17 +28,24 @@ #include "common/util/djbhash.h" #include "openbios/kernel/handlers.h" +extern const char romfs[]; + static void start(const char* systemPath, const char* exePath); int main() { - *((uint32_t*) 0x60) = 0x02; - *((uint32_t*) 0x64) = 0x00; - *((uint32_t*) 0x68) = 0xff; + *((uint32_t*)0x60) = 0x02; + *((uint32_t*)0x64) = 0x00; + *((uint32_t*)0x68) = 0xff; muteSpu(); sio1_init(); + sio1_putc('H'); + sio1_putc('i'); + sio1_putc('\r'); + sio1_putc('\n'); register_devfs(); register_stdio_devices(); + register_romfs("romfs", (uint8_t *) romfs); printf("OpenBIOS starting.\r\n"); @@ -56,10 +64,25 @@ int main() { return 0; } - void start(const char* systemPath, const char* exePath) { writeCOP0Status(readCOP0Status() & 0xfffffbfe); muteSpu(); installKernelHandlers(); + + void(*shell)() = (void(*)()) 0x80030000; + + printf("Trying to load the shell...\r\n"); + int shellFile = open("/romfs/pshittyload.bin", O_RDONLY); + if (shellFile >= 0) { + ssize_t size = read(shellFile, shell, 0x80200000 - 0x80030000); + printf("Shell found, read %i bytes from it.\r\n", size); + close(shellFile); + uint8_t* shellData = (uint8_t*) shell; + printf("Executing the shell.\r\n"); + shell(); + printf("Shell is done running.\r\n"); + } else { + printf("Shell not found.\r\n"); + } } diff --git a/src/mips/ps1sdk/Makefile b/src/mips/ps1sdk/Makefile new file mode 100644 index 000000000..b604f26fc --- /dev/null +++ b/src/mips/ps1sdk/Makefile @@ -0,0 +1,17 @@ +TARGET = libps1sdk.a + +SRCS = \ + src/syscalls.S \ + +#LDSCRIPT = psx-exe.ld + +## If "TLOAD_ADDR" was specified in the Makefile, pass it to the linker. +#~ ifneq ($(strip $(TLOAD_ADDR)),) +#~ LDFLAGS := -Wl,--defsym,TLOAD_ADDR=$(TLOAD_ADDR) +#~ else +LDFLAGS = +#~ endif + +CPPFLAGS += -Iinclude -Isrc + +include ../common.mk diff --git a/src/mips/ps1sdk/include/ario.h b/src/mips/ps1sdk/include/ario.h new file mode 100644 index 000000000..74d54bd9f --- /dev/null +++ b/src/mips/ps1sdk/include/ario.h @@ -0,0 +1,38 @@ +/* + * File: ario.h + * Author: aric + * + * Created on February 10, 2009, 1:13 AM + */ + +#ifndef _ARIO_H +#define _ARIO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define AR12_STATUS ((volatile uint8_t *) 0x1F020010) +#define AR12_SWITCH ((volatile uint8_t *) 0x1F020018) +#define AR12_RXD ((volatile uint8_t *) 0x1F060000) +#define AR12_TXD ((volatile uint8_t *) 0x1F060008) + +// Set when there is data to be read from the comms link. +#define AR12_STAT_RX_RDY (1 << 0) + +/* prototypes */ + +uint8_t AR12_exchange8(uint8_t d); +uint16_t AR12_exchange16(uint16_t d); +uint32_t AR12_exchange32(uint32_t d); + +// the following are basically helpers that call AR12_exchangeX(0) +uint8_t AR12_read8(void); +uint16_t AR12_read16(void); +uint32_t AR12_read32(void); + +#ifdef __cplusplus +} +#endif + +#endif /* _ARIO_H */ diff --git a/src/mips/ps1sdk/include/assert.h b/src/mips/ps1sdk/include/assert.h new file mode 100644 index 000000000..74bb6535a --- /dev/null +++ b/src/mips/ps1sdk/include/assert.h @@ -0,0 +1,33 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# ANSI C "assert.h" for PS1. +# +*/ + +#ifndef _ASSERT_H +#define _ASSERT_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef assert +#undef assert +#endif + +#ifndef NDEBUG +void __assert(const char*, const char*, int); +#define assert(e) ((e) ? (void)0 : __assert(#e, __FILE__, __LINE__)) +#else +#define assert(ignore) ((void)0) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _ASSERT_H */ diff --git a/src/mips/ps1sdk/include/cop0regs.h b/src/mips/ps1sdk/include/cop0regs.h new file mode 100644 index 000000000..c7f9edce8 --- /dev/null +++ b/src/mips/ps1sdk/include/cop0regs.h @@ -0,0 +1,120 @@ +/* COP0 Registers */ + +#ifndef _COP0REGS_H +#define _COP0REGS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* BreakPoint Control */ +#define C0_BPC $3 +/* BreakPoint on Data Access */ +#define C0_BDA $5 +/* BreakPoint on Data Access */ +#define C0_DCIC $7 +/* Bad Virtual Address */ +#define C0_BADVADDR $8 +// Breakpoint Data Access Mask +#define C0_BDAM $9 +// Breakpoint Program Counter Mask +#define C0_BPCM $11 + +/* Status Register */ +#define C0_STATUS $12 + +/* Cause Register */ +#define C0_CAUSE $13 + +/* Error PC Register */ +#define C0_EPC $14 + +/* Processor ID */ +#define C0_PRID $15 + +// Interrupt Enable(current) +#define C0_SR_IEC (1 << 0) +// Kernel/User mode(current) +#define C0_SR_KUC (1 << 1) +// Interrupt Enable(previous) +#define C0_SR_IEP (1 << 2) +// Kernel/User mode(previous) +#define C0_SR_KUP (1 << 3) +// Interrupt Enable(old) +#define C0_SR_IEO (1 << 4) +// Kernel/User mode(old) +#define C0_SR_KUO (1 << 5) + +/* Interrupt Mask 0 */ +#define C0_SR_IMO (1 << 8) +/* Interrupt Mask 1 */ +#define C0_SR_IM1 (1 << 9) +/* Interrupt Mask 2 */ +#define C0_SR_IM2 (1 << 10) +/* Interrupt Mask 3 */ +#define C0_SR_IM3 (1 << 11) +/* Interrupt Mask 4 */ +#define C0_SR_IM4 (1 << 12) +/* Interrupt Mask 5 */ +#define C0_SR_IM5 (1 << 13) +/* Interrupt Mask 6 */ +#define C0_SR_IM6 (1 << 14) +/* Interrupt Mask 7 */ +#define C0_SR_IM7 (1 << 15) + +/* Isolate Cache */ +#define C0_SR_ISC (1 << 16) +/* Swap Caches */ +#define C0_SR_SWC (1 << 17) +/* Parity Zero */ +#define C0_SR_PZ (1 << 18) +/* Cache Miss */ +#define C0_SR_CM (1 << 19) +/* Parity Error */ +#define C0_SR_PE (1 << 20) +/* TLB Shutdown */ +#define C0_SR_TS (1 << 21) +/* Boot-time Exception Vector */ +#define C0_SR_BEV (1 << 22) + +/* Reverse Endian enable */ +#define C0_SR_RE (1 << 25) + +/* Coprocessor 0 Usable */ +#define C0_SR_CU0 (1 << 28) +/* Coprocessor 1 Usable */ +#define C0_SR_CU1 (1 << 29) +/* Coprocessor 2 Usable */ +#define C0_SR_CU2 (1 << 30) +/* Coprocessor 3 Usable */ +#define C0_SR_CU3 (1 << 31) + +// R3000A COP0 DCIC register bits + +/* These are R/W, used to enable/disable various debug/cache things */ +#define C0_DCIC_TR (1 << 31) /* Trap enable */ +#define C0_DCIC_UD (1 << 30) /* User debug enable */ +#define C0_DCIC_KD (1 << 29) /* Kernel debug enable */ +#define C0_DCIC_TE (1 << 28) /* Trace enable */ +#define C0_DCIC_DW (1 << 27) /* Enable data access breakpoints on write */ +#define C0_DCIC_DR (1 << 26) /* Enable data access breakpoints on read */ +#define C0_DCIC_DAE (1 << 25) /* Enable data addresss breakpoints(Is this valid?) */ +#define C0_DCIC_PCE (1 << 24) /* Enable instruction breakpoints */ +#define C0_DCIC_DE (1 << 23) /* Debug Enable */ +#define C0_DCIC_DL (1 << 15) /* Data cache line invalidate */ +#define C0_DCIC_IL (1 << 14) /* Instruction cache line invalidate */ +#define C0_DCIC_D (1 << 13) /* Data cache invalidate enable */ +#define C0_DCIC_I (1 << 12) /* Instr. cache invalidate enable */ +/* The rest of these are R/O, set by the CPU to indicate the type of debug exception that occured */ +#define C0_DCIC_T (1 << 5) /* Trace */ +#define C0_DCIC_W (1 << 4) /* Write reference */ +#define C0_DCIC_R (1 << 3) /* Read reference */ +#define C0_DCIC_DA (1 << 2) /* Data address */ +#define C0_DCIC_PC (1 << 1) /* Program counter */ +#define C0_DCIC_DB (1 << 0) /* Debug */ + +#ifdef __cplusplus +} +#endif + +#endif /* _COP0REGS_H */ diff --git a/src/mips/ps1sdk/include/ctype.h b/src/mips/ps1sdk/include/ctype.h new file mode 100644 index 000000000..ab4b6c2a7 --- /dev/null +++ b/src/mips/ps1sdk/include/ctype.h @@ -0,0 +1,56 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# ANSI C "ctype.h" for PS1. +# +*/ + +#ifndef _PS1_CTYPE_H_ +#define _PS1_CTYPE_H_ + +extern unsigned char __ctype_table[]; + + +enum { + // uppercase alphabetic + CTYPE_UCASE = (1 << 0), + // lowercase alphabetic + CTYPE_LCASE = (1 << 1), + // numeric ('0'-'9') + CTYPE_NUMER = (1 << 2), + // white space + CTYPE_WSPAC = (1 << 3), + // punctuation + CTYPE_PUNCT = (1 << 4), + // control + CTYPE_CNTRL = (1 << 5), + // hexadecimal('0'-'9', 'A'-'F', 'a'-'f') + CTYPE_HEXAD = (1 << 6), + // blank + CTYPE_BLANK = (1 << 7) +}; + +#define __isctype(___ch, ___type) ((__ctype_table[(int)___ch] & (___type)) != 0) + +#define isalnum(___ch) (isalpha(___ch) || isdigit(___ch)) +#define isalpha(___ch) (isupper(___ch) || islower(___ch)) +#define isascii(___ch) (((unsigned char)___ch) <= 127) +#define isblank(___ch) (__isctype(___ch, CTYPE_BLANK)) +#define iscntrl(___ch) (__isctype(___ch, CTYPE_CNTRL)) +#define isdigit(___ch) (__isctype(___ch, CTYPE_NUMER)) +#define isgraph(___ch) (isprint(___ch) && !isspace(___ch)) +#define islower(___ch) (__isctype(___ch, CTYPE_LCASE)) +#define isprint(___ch) \ + (__isctype(___ch, (CTYPE_UCASE | CTYPE_LCASE | CTYPE_NUMER | CTYPE_WSPAC | CTYPE_PUNCT | CTYPE_BLANK))) +#define ispunct(___ch) (__isctype(___ch, CTYPE_PUNCT)) +#define isspace(___ch) (__isctype(___ch, (CTYPE_WSPAC | CTYPE_BLANK))) +#define isupper(___ch) (__isctype(___ch, CTYPE_UCASE)) +#define isxdigit(___ch) (__isctype(___ch, CTYPE_HEXAD)) + +#define _toupper(___ch) (islower(___ch) ? ((___ch)-0x20) : (___ch)) +#define _tolower(___ch) (isupper(___ch) ? ((___ch) + 0x20) : (___ch)) + +#endif // _PS1_CTYPE_H_ diff --git a/src/mips/ps1sdk/include/defs.h b/src/mips/ps1sdk/include/defs.h new file mode 100644 index 000000000..1c1d4c627 --- /dev/null +++ b/src/mips/ps1sdk/include/defs.h @@ -0,0 +1,34 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# PS1 standard definitions. +# +*/ + +#ifndef PS1_DEFS_H +#define PS1_DEFS_H + +#include "types.h" + +#ifndef NULL +#define NULL ((void*)0) +#endif + +#define ALIGN(___x, ___align) (((___x) + ((___align)-1)) & ~((___align)-1)) + +#define PHYSADDR(a) (((uint32_t)(a)) & 0x1FFFFFFF) + +#define KUSEG 0x00000000 +// cached +#define KSEG0 0x80000000 +// uncached +#define KSEG1 0xA0000000 + +#define KUSEGADDR(___a) (PHYSADDR(___a) | KUSEG) +#define KSEG0ADDR(___a) (PHYSADDR(___a) | KSEG0) +#define KSEG1ADDR(___a) (PHYSADDR(___a) | KSEG1) + +#endif /* PS1_DEFS_H */ diff --git a/src/mips/ps1sdk/include/dma.h b/src/mips/ps1sdk/include/dma.h new file mode 100644 index 000000000..eb0fc7ff3 --- /dev/null +++ b/src/mips/ps1sdk/include/dma.h @@ -0,0 +1,28 @@ +/* + * PS1 DMA + */ + +#ifndef _PS1DMA_H +#define _PS1DMA_H + +#ifdef __cplusplus +extern "C" { +#endif + +// DMA channels +enum +{ + DMA_CH_MDEC_IN = (0), + DMA_CH_MDEC_OUT = (1), + DMA_CH_GPU = (2), // list + image data + DMA_CH_CDROM = (3), + DMA_CH_SPU = (4), + DMA_CH_EXP1 = (5), + DMA_CH_GPU_OTC = (6), // (reverse clear the Ordering Table) +}; + +#ifdef __cplusplus +} +#endif + +#endif /* _PS1DMA_H */ diff --git a/src/mips/ps1sdk/include/endian.h b/src/mips/ps1sdk/include/endian.h new file mode 100644 index 000000000..bc831b0e3 --- /dev/null +++ b/src/mips/ps1sdk/include/endian.h @@ -0,0 +1,11 @@ +#ifndef _ENDIAN_H +#define _ENDIAN_H + +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __PDP_ENDIAN 3412 + +/* PlayStation 1 is little-endian */ +#define __BYTE_ORDER __LITTLE_ENDIAN + +#endif // #ifndef _ENDIAN_H diff --git a/src/mips/ps1sdk/include/exec.h b/src/mips/ps1sdk/include/exec.h new file mode 100644 index 000000000..3f535a80e --- /dev/null +++ b/src/mips/ps1sdk/include/exec.h @@ -0,0 +1,64 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# "exec.h" for PS1. +# +*/ + +#ifndef _EXEC_H +#define _EXEC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Executable file types returned by LoadEx() */ +enum { ExecTypeUNK = 0, ExecTypePSX = 1, ExecTypeSCE = 2, ExecTypeECO = 3, ExecTypeCPE = 4 }; + +// sizeof() == 0x3C(60) +typedef struct st_ExecInfo { + uint32_t entry; // 0x00 : Address of program entry-point. + uint32_t init_gp; // 0x04 : SCE only. Initial value the "gp" register is set to. 0 for PS-X EXE. + uint32_t text_addr; // 0x08 : Memory address to which the .text section is loaded. + uint32_t text_size; // 0x0C : Size of the .text section in the file and memory. + uint32_t data_addr; // 0x10 : SCE only. Memory address to which the .data section is loaded. 0 for PS-X EXE. + uint32_t data_size; // 0x14 : SCE only. Size of the .data section in the file and memory. 0 for PS-X EXE. + uint32_t bss_addr; // 0x18 : Memory address of the .bss section. .bss is initialized by Exec(). + uint32_t bss_size; // 0x1C : Size of the .bss section in memory. + uint32_t stack_addr; // 0x20 : Memory address pointing to the bottom(lowest address) of the stack. BIOS replaces + // with "STACK" parameter of "SYSTEM.CNF" file. + uint32_t stack_size; // 0x24 : Size of the stack. Can be 0. + uint32_t saved_sp; // 0x28 : Used by BIOS Exec() function to preserve the "sp" register. + uint32_t saved_fp; // 0x2C : Used by BIOS Exec() function to preserve the "fp" register. + uint32_t saved_gp; // 0x30 : Used by BIOS Exec() function to preserve the "gp" register. + uint32_t saved_ra; // 0x34 : Used by BIOS Exec() function to preserve the "ra" register. + uint32_t saved_s0; // 0x38 : Used by BIOS Exec() function to preserve the "s0" register. +} ExecInfo; + +// sizeof() == 0x88(136) +typedef struct st_EXE_Header { + uint8_t magic[8]; // 0x00-0x07 : "PS-X EXE"(retail) or "SCE EXE"(???) + uint32_t text_off; // 0x08 : SCE only. Offset of the start of the .text section in the file. 0 for PS-X EXE. + uint32_t data_off; // 0x0C : SCE only. Offset of the start of the .text section in the file. 0 for PS-X EXE. + struct st_ExecInfo exec; // 0x10-0x4B + char license[60]; // 0x4C-0x87 + uint8_t __pad[1912]; // 0x88-0x7FF +} EXE_Header; + +int ParseExecHeader(const void* hdr, ExecInfo* exec); +int ReadExecHeader(int fd, ExecInfo* exec); +int LoadEx(const char* fname, ExecInfo* exec); +int LoadExBuffer(const void* fbuf, ExecInfo* exec); +int LoadComms(uint8_t (*get_func)(), ExecInfo *exec); + +void LoadExecEx(const void* f, uint32_t stack_addr, int stack_size); +int ExecEx(ExecInfo* exec, uint32_t stack_addr, uint32_t stack_size); + +#ifdef __cplusplus +} +#endif + +#endif /* _EXEC_H */ diff --git a/src/mips/ps1sdk/include/fileio.h b/src/mips/ps1sdk/include/fileio.h new file mode 100644 index 000000000..5c9a1b766 --- /dev/null +++ b/src/mips/ps1sdk/include/fileio.h @@ -0,0 +1,129 @@ +/* + * File: fileio.h + * Author: aric + * + * Created on February 10, 2009, 1:04 AM + */ + +#ifndef _FILEIO_H +#define _FILEIO_H + +#include "sys/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/* IoBlock flags */ +#define O_RDONLY (0x0001) +#define O_WRONLY (0x0002) +#define O_RDWR (0x0003) +#define O_NBLOCK (0x0004) +#define O_APPEND (0x0100) +#define O_CREAT (0x0200) +#define O_TRUNC (0x0400) +#define O_NOBUF (0x4000) +#define O_NOWAIT (0x8000) + +#define FSCAN 0x1000 + +/* "whence" for seek functions */ +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +/* device types */ +/* for DeviceDriver.type */ +#define DEV_TYPE_CHAR (1 << 0) /* character device */ +#define DEV_TYPE_TTY (1 << 1) /* TTY/console */ +#define DEV_TYPE_BLOCK (1 << 2) /* block device */ +#define DEV_TYPE_RAW (1 << 3) /* raw device that uses fs switch */ +#define DEV_TYPE_FS (1 << 4) + +/* device FIFO flags */ +/* for device_fifo.flags */ +#define DEV_FIFO_RAW (1 << 0) /* don't interpret special chars */ +#define DEV_FIFO_STOPPED (1 << 1) /* stop output */ +#define DEV_FIFO_BREAK (1 << 2) /* cntl-c raise console interrpt */ + +// sizeof() == 0x10C(268) +typedef struct st_device_fifo { + uint32_t flags; // 0x00 - see "device FIFO flags" + char* wr_ptr; // 0x04 - pointer to "write" position in FIFO. + char* rd_ptr; // 0x08 - pointer to "read" position in FIFO. + char buf[256]; // 0x0C - FIFO buffer. +} device_fifo; + +#define M_FIFO_PURGE(__fifo) ((__fifo)->rd_ptr = (__fifo)->wr_ptr = (__fifo)->buf) +#define M_IS_FIFO_EMPTY(__fifo) ((__fifo)->rd_ptr == (__fifo)->wr_ptr) +#define M_IS_FIFO_STOPPED(__fifo) ((__fifo)->flags & DEV_FIFO_STOPPED) +#define stdin (0) +#define stdout (1) + +/* sizeof() == 0x2C(44) */ +typedef struct st_PS1_IoBlock { + int flags; // 0x00 - see IoBlock flags(TODO: fixme?) + int dev_no; // 0x04 - ? + char* buf; // 0x08 - address of the I/O buffer. + uint32_t ccount; // 0x0C - character count + uint32_t cur_pos; // 0x10 - current position in file. + int fstype; // 0x14 - type of file system. + int errno; // 0x18 - last "errno" + struct st_DeviceDriver* dd; // 0x1C - pointer to fsd + uint32_t size; // 0x20 - file size? + uint32_t head; // 0x24 - ? + uint32_t fd; // 0x28 file descriptor +} IoBlock; + +#warning "FIXME: add argument names to prototypes in DeviceDriver struct in fileio.h" +/* sizeof() == 0x50(80) */ +typedef struct st_DeviceDriver { + const char* name; // 0x00 - pointer to unique name identifying device. + uint32_t type; // 0x04 - bitmask. see Device Types. + uint32_t block_size; // 0x08 - size, in bytes, of a block. + const char* desc; // 0x0C - pointer to ASCII-Z description of device. + int (*init)(IoBlock *iob); // 0x10 - pointer to "init" function. Called by AddDevice() + int (*open)(IoBlock *iob, const char *fname, int mode); // 0x14 - pointer to "open" function. + int (*strategy)(IoBlock *iob, int cmd); // 0x18 - pointer to "strategy" function. + int (*close)(IoBlock *iob); // 0x1C - pointer to "close" function. + int (*ioctl)(IoBlock *iob, int cmd, int param); // 0x20 - pointer to "ioctl" function. + int (*read)(IoBlock *iob, void *p, int size); // 0x24 - pointer to "read" function. + int (*write)(IoBlock *iob, const void *p, int size); // 0x28 - pointer to "write" function. + int (*delete)(IoBlock *iob, const char *name); // 0x2C - pointer to "delete" function. + int (*undelete)(IoBlock *iob, const char *name); // 0x30 - pointer to "undelete" function. + int (*firstfile)(); // 0x34 - pointer to "firstfile" function. + int (*nextfile)(); // 0x38 - pointer to "nextfile" function. + int (*format)(); // 0x3C - pointer to "format" function. + int (*chdir)(const char *path); // 0x40 - pointer to "cd" function. + int (*rename)(const char *oldname, const char *newname); // 0x44 - pointer to "rename" function. + int (*deinit)(IoBlock *iob); // 0x48 - pointer to "deinit" function. Called by RemDevice() + int (*lseek)(IoBlock*iob, int pos, int whence); // 0x4C - pointer to "lseek" function. +} DeviceDriver; + +typedef struct st_DirEntry { + char name[20]; // 0x00 - ASCII file name. + uint32_t attr; // 0x14 - file attributes. + uint32_t size; // 0x18 - file size, in bytes. + struct st_DirEntry* next; // 0x1C - pointer to next directory entry structure. + uint32_t head; // 0x20 - ??? + uint8_t system[4]; // 0x24 - ??? unused? +} DirEntry; + +int AddDevice(const DeviceDriver* dd); +int DelDevice(const char* dev_name); + +#warning "FIXME: add argument names to prototypes in fileio.h" +DirEntry* firstfile(const char*, DirEntry*); +DirEntry* nextfile(DirEntry*); + +#ifdef __cplusplus +} +#endif + +#endif /* _FILEIO_H */ diff --git a/src/mips/ps1sdk/include/fileio.h~ b/src/mips/ps1sdk/include/fileio.h~ new file mode 100755 index 000000000..68a17526d --- /dev/null +++ b/src/mips/ps1sdk/include/fileio.h~ @@ -0,0 +1,138 @@ +/* + * File: fileio.h + * Author: aric + * + * Created on February 10, 2009, 1:04 AM + */ + +#ifndef _FILEIO_H +#define _FILEIO_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define O_RDONLY (0x0001) +#define O_WRONLY (0x0002) +#define O_RDWR (0x0003) +#define O_NBLOCK (0x0004) +#define O_APPEND (0x0100) +#define O_CREAT (0x0200) +#define O_TRUNC (0x0400) +#define O_NOBUF (0x4000) +#define O_NOWAIT (0x8000) + +#define FSCAN 0x1000 + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +/* device types */ +#define DEV_TYPE_CHAR (1 << 0) /* character device */ +#define DEV_TYPE_TTY (1 << 1) /* TTY/console */ +#define DEV_TYPE_BLOCK (1 << 2) /* block device */ +#define DEV_TYPE_RAW (1 << 3) /* raw device that uses fs switch */ +#define DEV_TYPE_FS (1 << 4) + +/* device FIFO flags */ +#define DEV_FIFO_RAW (1 << 0) /* don't interpret special chars */ +#define DEV_FIFO_STOPPED (1 << 1) /* stop output */ +#define DEV_FIFO_BREAK (1 << 2) /* cntl-c raise console interrpt */ + +// sizeof() == 0x10C(268) +typedef struct st_device_fifo +{ + uint32_t flags; // 0x00 - see "device FIFO flags" + char *wr_ptr; // 0x04 - pointer to "write" position in FIFO. + char *rd_ptr; // 0x08 - pointer to "read" position in FIFO. + char buf[256]; // 0x0C - FIFO buffer. +} device_fifo; + +#define M_FIFO_FLUSH(__fifo) ((__fifo)->rd_ptr = (__fifo)->wr_ptr = (__fifo)->buf) +#define M_IS_FIFO_EMPTY(__fifo) ((__fifo)->rd_ptr == (__fifo)->wr_ptr) +#define M_IS_FIFO_STOPPED(__fifo) ((__fifo)->flags & DEV_FIFO_STOPPED) + +/* sizeof() == 0x2C(44) */ +typedef struct st_PS1_IoBlock +{ + int flags; // 0x00 + int dev_no; // 0x04 + char *buf; // 0x08 - address of the I/O buffer. + uint32_t ccount; // 0x0C - character count + uint32_t cur_pos; // 0x10 - current position in file. + int fstype; // 0x14 - type of file system. + int errno; // 0x18 - last "errno" + struct st_FileSystemDriver *fsd; // 0x1C - pointer to fsd + uint32_t size; // 0x20 + uint32_t head; // 0x24 + uint32_t fd; // 0x28 file descriptor +} IoBlock; + +/* sizeof() == 0x50(80) */ +typedef struct st_FileSystemDriver +{ + const char *name; // 0x00 - pointer to unique name identifying file system. + uint32_t modes; // 0x04 - + uint32_t block_size; // 0x08 - size, in bytes, of a block. + const char *desc; // 0x0C - pointer to ASCII-Z description of file system. + int (*init)(); // 0x10 - pointer to "init" function. Called by AddDevice() + int (*open)(); // 0x14 - pointer to "open" function. + int (*strategy)(); // 0x18 - pointer to "strategy" function. + int (*close)(); // 0x1C - pointer to "close" function. + int (*ioctl)(); // 0x20 - pointer to "ioctl" function. + int (*read)(); // 0x24 - pointer to "read" function. + int (*write)(); // 0x28 - pointer to "write" function. + int (*delete)(); // 0x2C - pointer to "delete" function. + int (*undelete)(); // 0x30 - pointer to "undelete" function. + int (*firstfile)(); // 0x34 - pointer to "firstfile" function. + int (*nextfile)(); // 0x38 - pointer to "nextfile" function. + int (*format)(); // 0x3C - pointer to "format" function. + int (*chdir)(); // 0x40 - pointer to "cd" function. + int (*rename)(); // 0x44 - pointer to "rename" function. + int (*deinit)(); // 0x48 - pointer to "deinit" function. Called by RemDevice() + int (*call15)(); // 0x4C - pointer to "lseek" function. +} FileSystemDriver; + +typedef struct st_DirEntry +{ + char name[20]; // 0x00 - ASCII file name. + uint32_t attr; // 0x14 - file attributes. + uint32_t size; // 0x18 - file size, in bytes. + struct st_DirEntry *next; // 0x1C - pointer to next directory entry structure. + uint32_t head; // 0x20 - ??? + uint8_t system[4]; // 0x24 - ??? unused? +} DirEntry; + +int AddDevice(const FileSystemDriver *fsd); +int RemDevice(const char *fs_name); + +int open(const char *, uint32_t); +int close(int); +int lseek(int, int, int); +int read(int, void *, int); +int write(int, const void *, int); +int ioctl(int, int, int); +DirEntry *firstfile(const char *, DirEntry *); +DirEntry *nextfile(DirEntry *); + +int erase(const char *); +int undelete(const char *); +int format(const char *); +int rename(const char *, const char *); +int chdir(const char *); + +#ifdef __cplusplus +} +#endif + +#endif /* _FILEIO_H */ + diff --git a/src/mips/ps1sdk/include/flash.h b/src/mips/ps1sdk/include/flash.h new file mode 100644 index 000000000..d0842b567 --- /dev/null +++ b/src/mips/ps1sdk/include/flash.h @@ -0,0 +1,113 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# "FLASH.h" for PS1. +# +*/ + +#ifndef _FLASH_H +#define _FLASH_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct st_FlashMemoryDeviceBlock { + uint32_t n_sects; + uint32_t sz_sects; +} FlashMemoryDeviceBlock; + +typedef int (*FlashMapperFunc)(void* dev, uint32_t offset, uint32_t* p_voff); +typedef int (*FlashChipUnprotectFunc)(uint32_t base_addr, int wait); +typedef int (*FlashChipProtectFunc)(uint32_t base_addr, int wait); +typedef int (*FlashChipEraseFunc)(uint32_t base_addr, int wait); +typedef int (*FlashSectEraseFunc)(uint32_t base_addr, uint32_t sect_addr, int wait); +typedef int (*FlashSectProgFunc)(uint32_t base_addr, uint32_t sect_addr, void* data, int len, int wait); + +typedef struct st_FlashMemoryDevice { + const char* name; // pointer to ASCII-Z string containing the name of the device. + uint16_t man_id; // manufacturer ID. + uint16_t prod_id; // product ID. + uint32_t attr; // attributes. + uint32_t n_total_bytes; // total number of bytes in the device. + + FlashMapperFunc mapper; // pointer to function which handles "mapping" for this chip. + + FlashChipUnprotectFunc chip_unprotect; // pointer to function which "unprotects" this chip for programming. + int chip_unprot_wait; // number of milliseconds to wait after doing a "chip_unlock". + FlashChipProtectFunc chip_protect; // pointer to function which "protects" this chip to disable programming. + int chip_prot_wait; // number of milliseconds to wait after doing a "chip_lock". + + FlashChipEraseFunc chip_erase; // pointer to function which erases this entire chip. + int chip_erase_wait; // number of milliseconds to wait after doing a "chip_erase". + FlashSectEraseFunc sect_erase; // pointer to function which erases a single sector of this chip. + int sect_erase_wait; // number of milliseconds to wait after doing a "sect_erase". + FlashSectProgFunc sect_prog; // pointer to function which programs a single sector of this chip. + int sect_prog_wait; // number of milliseconds to wait after doing a "sect_prog". + + int n_blocks; // number of blocks in the following array. + struct { + uint32_t n_sects; // number of sectors in this block. + uint32_t sect_sz; // size, in bytes, of each sector in this block. + } blocks[]; +} FlashMemoryDevice; + +#define FLASH_MANUF_AMD (0x0001) +#define FLASH_MANUF_ATMEL (0x001F) +#define FLASH_MANUF_SST (0x00BF) +#define FLASH_MANUF_MX (0x00C2) +#define FLASH_MANUF_WINBOND (0x00DA) + +// attributes for flash memory devices + +// supports sector erase +#define FLASH_ATTR_SECT_ERASE (1 << 0) + +// supports chip erase +#define FLASH_ATTR_CHIP_ERASE (1 << 1) + +#define FLASH_ATTR_EEPROM (1 << 2) + +// uniform sector sizes. +#define FLASH_ATTR_UNIFORM (1 << 3) +// "bottom" boot block. +#define FLASH_ATTR_BOTTOM_BOOT (1 << 4) +// "top" boot block. +#define FLASH_ATTR_TOP_BOOT (1 << 5) + +int flash_read_ids(uint32_t base_addr, uint16_t* pman_id, uint16_t* pprod_id); +uint8_t flash_detect_mappers(uint32_t base_addr, uint16_t* p_man_id, uint16_t* p_prod_id); +FlashMemoryDevice* flash_detect_device(uint32_t base_addr); +FlashMemoryDevice* find_device_by_ids(uint16_t man_id, uint16_t prod_id); +int flash_dump_chip(FlashMemoryDevice* dev, uint32_t base_addr, uint32_t off, void* data, int max_bytes); + +void flash_chip_unprotect(FlashMemoryDevice* dev, uint32_t base_addr); +void flash_chip_protect(FlashMemoryDevice* dev, uint32_t base_addr); + +int flash_chip_erase(FlashMemoryDevice* dev, uint32_t base_addr); +int flash_sect_erase(FlashMemoryDevice* dev, uint32_t base_addr, uint32_t sect_addr); +int flash_lookup_sect(FlashMemoryDevice* dev, uint32_t off, uint32_t* p_sect_addr, uint32_t* p_sect_off, + int* p_sect_size); +int flash_sect_prog(FlashMemoryDevice* dev, uint32_t base_addr, uint32_t sect_addr, void* data, int n_bytes); +int flash_blank_check(void* start, int n); +void flash_wait_toggle(uint32_t addr); +void delay_ns(int n); + +static inline void flash_unlock_cycle(uint32_t base_addr, uint8_t cmd) { + // base_addr &= 0xFFFE0000; + + ((vuint8_t*)base_addr)[0x5555] = 0xAA; + ((vuint8_t*)base_addr)[0x2AAA] = 0x55; + ((vuint8_t*)base_addr)[0x5555] = cmd; +} + +#ifdef __cplusplus +} +#endif + +#endif /* _FLASH_H */ diff --git a/src/mips/ps1sdk/include/helpers.h b/src/mips/ps1sdk/include/helpers.h new file mode 100644 index 000000000..b7185f7c5 --- /dev/null +++ b/src/mips/ps1sdk/include/helpers.h @@ -0,0 +1,47 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# Misc. Helpers +# +*/ + +#ifndef _HELPERS_H +#define _HELPERS_H + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +uint32_t C0_get_BPC(void); +uint32_t C0_get_BDA(void); +uint32_t C0_get_DCIC(void); +uint32_t C0_get_BADVADDR(void); +uint32_t C0_get_BDAM(void); +uint32_t C0_get_BPCM(void); +uint32_t C0_get_STATUS(void); +uint32_t C0_get_CAUSE(void); +uint32_t C0_get_EPC(void); +uint32_t C0_get_PRID(void); + +void C0_set_BPC(uint32_t v); +void C0_set_BDA(uint32_t v); +void C0_set_DCIC(uint32_t v); +void C0_set_BADVADDR(uint32_t v); +void C0_set_BDAM(uint32_t v); +void C0_set_BPCM(uint32_t v); +void C0_set_STATUS(uint32_t v); +void C0_set_CAUSE(uint32_t v); +void C0_set_EPC(uint32_t v); +void C0_set_PRID(uint32_t v); + +#ifdef __cplusplus +} +#endif + +#endif /* _HELPERS_H */ diff --git a/src/mips/ps1sdk/include/interrupts.h b/src/mips/ps1sdk/include/interrupts.h new file mode 100644 index 000000000..26a54c8c7 --- /dev/null +++ b/src/mips/ps1sdk/include/interrupts.h @@ -0,0 +1,50 @@ +/* + * PS1 IRQs and such + */ + +#ifndef _PS1INTERRUPTS_H +#define _PS1INTERRUPTS_H + +#ifdef __cplusplus +extern "C" { +#endif + + +/* PS1 IRQs */ + +// V-Blank(external) +#define PS1_IRQ_VB (0) +// GPU(external) +#define PS1_IRQ_GPU (1) +// CD-ROM Controller(external) +#define PS1_IRQ_CD (2) +// DMA Controller(internal) +#define PS1_IRQ_DMAC (3) +// Root-Counter 0(internal) +#define PS1_IRQ_RC0 (4) +// Root-Counter 1(internal) +#define PS1_IRQ_RC1 (5) +// Root-Counter 2(internal) +#define PS1_IRQ_RC2 (6) + +// SIO0, pads/card(internal) +#define PS1_IRQ_SIO0 (7) + +// SIO1, serial port(internal) +#define PS1_IRQ_SIO1 (8) + +// SPU(external) +#define PS1_IRQ_SPU (9) + +// EXP1(external) +// NOTE: IRQ 10 is shared by Expansion 1 and the game pads +// but is likely only used for lightgun stuff. +#define PS1_IRQ_EXP1 (10) +// SIO1(internal) - VERIFY THIS! +//#define PS1_IRQ_SIO1 (11) + +#ifdef __cplusplus +} +#endif + +#endif /* _PS1INTERRUPTS_H */ diff --git a/src/mips/ps1sdk/include/libcd.h b/src/mips/ps1sdk/include/libcd.h new file mode 100644 index 000000000..54c0872b9 --- /dev/null +++ b/src/mips/ps1sdk/include/libcd.h @@ -0,0 +1,322 @@ +/* $PSLibId: Run-time Library Release 4.6$ */ +#ifndef _LIBCD_H_ +#define _LIBCD_H_ +/* + * (C) Copyright 1993/1994 Sony Computer Entertainment ,Tokyo,Japan. + * All Rights Reserved + * + * libcd.h: CD-ROM sub system hendler + * + * CD-ROM Primitive Command list: + * + * Symbol type Contents + * ------------------------------------------------------ + * CdlNop B NOP + * CdlSetloc B Set position + * CdlPlay B CD-DA Play + * CdlForward B Forward + * CdlBackward B Backward + * CdlReadN B Read with retry + * CdlStanby N Standby + * CdlStop N Stop + * CdlPause N Pause + * CdlMute B Mute on + * CdlDemute B Mute off + * CdlSetfilter B Set SubHeader filter + * CdlSetmode B Set mode + * CdlGetlocL B Get logical position + * CdlGetlocP B Get phisycal position + * CdlSeekL N Logical Seek + * CdlSeekP N Phisical Seek + * CdlReadS B Read without retry + * ------------------------------------------------------ + * B: Blocking, N: Non-Blocking operation + * + * + * Symbol arg result + * -------------------------------------------------------------- + * CdlNop - status + * CdlSetloc min,sec,sector status + * CdlPlay - status + * CdlForward - status + * CdlBackward - status + * CdlReadN - status + * CdlStanby - status + * CdlStop - status + * CdlPause - status + * CdlMute - status + * CdlDemute - status + * CdlSetfilter file,chan status + * CdlSetmode mode status + * CdlGetlocL - min,sec,sector,mode,file, chan + * CdlGetlocP - track,index,min,sec,frame, + * amin,asec,aframe + * CdlSeekL - status + * CdlSeekP - status + * CdlReadS - status + * -------------------------------------------------------------- + */ +/* + * CD-ROM Basic System + */ + +/* + * CD-ROM Mode (used int CdlSetmode) + */ + +#define CdlModeStream 0x100 /* Normal Streaming */ +#define CdlModeStream2 0x120 /* SUB HEADER information includes */ +#define CdlModeSpeed 0x80 /* 0: normal speed 1: double speed */ +#define CdlModeRT 0x40 /* 0: ADPCM off 1: ADPCM on */ +#define CdlModeSize1 0x20 /* 0: 2048 byte 1: 2340byte */ +#define CdlModeSize0 0x10 /* 0: - 1: 2328byte */ +#define CdlModeSF 0x08 /* 0: Channel off 1: Channel on */ +#define CdlModeRept 0x04 /* 0: Report off 1: Report on */ +#define CdlModeAP 0x02 /* 0: AutoPause off 1: AutoPause on */ +#define CdlModeDA 0x01 /* 0: CD-DA off 1: CD-DA on */ + +/* + * Status Contents + */ +#define CdlStatPlay 0x80 /* playing CD-DA */ +#define CdlStatSeek 0x40 /* seeking */ +#define CdlStatRead 0x20 /* reading data sectors */ +#define CdlStatShellOpen 0x10 /* once shell open */ +#define CdlStatSeekError 0x04 /* seek error detected */ +#define CdlStatStandby 0x02 /* spindle motor rotating */ +#define CdlStatError 0x01 /* command error detected */ + +/* + * Macros for CdGetDiskType() + */ +#define CdlStatNoDisk 0 +#define CdlOtherFormat 1 +#define CdlCdromFormat 2 + +/* + * CD-ROM Primitive Commands + */ +#define CdlNop 0x01 +#define CdlSetloc 0x02 +#define CdlPlay 0x03 +#define CdlForward 0x04 +#define CdlBackward 0x05 +#define CdlReadN 0x06 +#define CdlStandby 0x07 +#define CdlStop 0x08 +#define CdlPause 0x09 +#define CdlMute 0x0b +#define CdlDemute 0x0c +#define CdlSetfilter 0x0d +#define CdlSetmode 0x0e +#define CdlGetparam 0x0f +#define CdlGetlocL 0x10 +#define CdlGetlocP 0x11 +#define CdlGetTN 0x13 +#define CdlGetTD 0x14 +#define CdlSeekL 0x15 +#define CdlSeekP 0x16 +#define CdlReadS 0x1B + +/* + * Interrupts + */ +#define CdlNoIntr 0x00 /* No interrupt */ +#define CdlDataReady 0x01 /* Data Ready */ +#define CdlComplete 0x02 /* Command Complete */ +#define CdlAcknowledge 0x03 /* Acknowledge (reserved) */ +#define CdlDataEnd 0x04 /* End of Data Detected */ +#define CdlDiskError 0x05 /* Error Detected */ + +/* + * Library Macros + */ +#ifndef btoi +#define btoi(b) ((b) / 16 * 10 + (b) % 16) /* BCD to u_char */ +#endif +#ifndef itob +#define itob(i) ((i) / 10 * 16 + (i) % 10) /* u_char to BCD */ +#endif + +#define CdSeekL(p) CdControl(CdlSeekL, (u_char*)p, 0) +#define CdSeekP(p) CdControl(CdlSeekP, (u_char*)p, 0) +#define CdStandby() CdControl(CdlStandby, 0, 0) +#define CdPause() CdControl(CdlPause, 0, 0) +#define CdStop() CdControl(CdlStop, 0, 0) +#define CdMute() CdControl(CdlMute, 0, 0) +#define CdDeMute() CdControl(CdlDemute, 0, 0) +#define CdForward() CdControl(CdlForward, 0, 0) +#define CdBackward() CdControl(CdlBackward, 0, 0) + +/* + * Position + */ +#define CdlMAXTOC 100 + +/* + * Callback + */ + +typedef void (*CdlCB)(u_char, u_char*); + +/* + * Location + */ +typedef struct { + u_char minute; /* minute (BCD) */ + u_char second; /* second (BCD) */ + u_char sector; /* sector (BCD) */ + u_char track; /* track (void) */ +} CdlLOC; + +/* + * ADPCM Filter + */ +typedef struct { + u_char file; /* file ID (always 1) */ + u_char chan; /* channel ID */ + u_short pad; +} CdlFILTER; + +/* + * Attenuator + */ +typedef struct { + u_char val0; /* volume for CD(L) -> SPU (L) */ + u_char val1; /* volume for CD(L) -> SPU (R) */ + u_char val2; /* volume for CD(R) -> SPU (L) */ + u_char val3; /* volume for CD(R) -> SPU (R) */ +} CdlATV; + +/* + * Low Level File System for CdSearchFile() + */ +#define CdlMAXFILE 64 /* max number of files in a directory */ +#define CdlMAXDIR 128 /* max number of total directories */ +#define CdlMAXLEVEL 8 /* max levels of directories */ + +typedef struct { + CdlLOC pos; /* file location */ + u_long size; /* file size */ + char name[16]; /* file name (body) */ +} CdlFILE; + +/*#define MULTI_INTERRUPT */ +#ifndef MULTI_INTERRUPT +#define pauseMULI() +#define restartMULI() +#endif + +#ifndef _LIBDS_H_ +/* + * Streaming Structures + */ +typedef struct { + u_short id; + u_short type; + u_short secCount; + u_short nSectors; + u_long frameCount; + u_long frameSize; + + u_short width; + u_short height; + u_long dummy1; + u_long dummy2; + CdlLOC loc; +} StHEADER; /* CD-ROM STR structure */ + +#define StFREE 0x0000 +#define StREWIND 0x0001 +#define StCOMPLETE 0x0002 +#define StBUSY 0x0003 +#define StLOCK 0x0004 + +#define EDC 0 +#define SECTOR_SIZE (512) /* Sector Size (word) */ +#define HEADER_SIZE (8) /* Header Size (word) */ + +#define StSTATUS 0x00 +#define StVER 0x00 +#define StTYPE 0x01 +#define StSECTOR_OFFSET 0x02 +#define StSECTOR_SIZE 0x03 +#define StFRAME_NO 0x04 +#define StFRAME_SIZE 0x06 + +#define StMOVIE_WIDTH 0x08 +#define StMOVIE_HEIGHT 0x09 + +/* + * Prototypes for Streaming + */ +#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || defined(c_plusplus) +extern "C" { +#endif +void StSetRing(u_long* ring_addr, u_long ring_size); +void StClearRing(void); +void StUnSetRing(void); +void StSetStream(u_long mode, u_long start_frame, u_long end_frame, void (*func1)(), void (*func2)()); +void StSetEmulate(u_long* addr, u_long mode, u_long start_frame, u_long end_frame, void (*func1)(), void (*func2)()); +u_long StFreeRing(u_long* base); +u_long StGetNext(u_long** addr, u_long** header); +u_long StGetNextS(u_long** addr, u_long** header); +u_short StNextStatus(u_long** addr, u_long** header); +void StRingStatus(short* free_sectors, short* over_sectors); +void StSetMask(u_long mask, u_long start, u_long end); +void StCdInterrupt(void); +int StGetBackloc(CdlLOC* loc); +int StSetChannel(u_long channel); +#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || defined(c_plusplus) +} +#endif +#endif /* ifndef _LIBDS_H_ */ + +/* + * Prototypes + */ +#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || defined(c_plusplus) +extern "C" { +#endif + +void CdFlush(void); +CdlFILE* CdSearchFile(CdlFILE* fp, char* name); +CdlLOC* CdIntToPos(int i, CdlLOC* p); +char* CdComstr(u_char com); +char* CdIntstr(u_char intr); +int CdControl(u_char com, u_char* param, u_char* result); +int CdControlB(u_char com, u_char* param, u_char* result); +int CdControlF(u_char com, u_char* param); +int CdGetSector(void* madr, int size); +int CdGetSector2(void* madr, int size); +int CdDataSync(int mode); +int CdGetToc(CdlLOC* loc); +int CdPlay(int mode, int* track, int offset); +int CdMix(CdlATV* vol); +int CdPosToInt(CdlLOC* p); +int CdRead(int sectors, u_long* buf, int mode); +int CdRead2(long mode); +int CdReadFile(char* file, u_long* addr, int nbyte); +int CdReadSync(int mode, u_char* result); +int CdReady(int mode, u_char* result); +int CdSetDebug(int level); +int CdSync(int mode, u_char* result); +void(*CdDataCallback(void (*func)())); +CdlCB CdReadCallback(CdlCB func); +CdlCB CdReadyCallback(CdlCB func); +CdlCB CdSyncCallback(CdlCB func); +int CdInit(void); +int CdReset(int mode); +int CdStatus(void); +int CdLastCom(void); +CdlLOC* CdLastPos(void); +int CdMode(void); +int CdDiskReady(int mode); +int CdGetDiskType(void); +struct EXEC* CdReadExec(char* file); +void CdReadBreak(void); + +#if defined(_LANGUAGE_C_PLUS_PLUS) || defined(__cplusplus) || defined(c_plusplus) +} +#endif +#endif /* _LIBCD_H_ */ diff --git a/src/mips/ps1sdk/include/memory.h b/src/mips/ps1sdk/include/memory.h new file mode 100644 index 000000000..b36787782 --- /dev/null +++ b/src/mips/ps1sdk/include/memory.h @@ -0,0 +1,16 @@ +#ifndef _MEMORY_H +#define _MEMORY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NULL +#define NULL ((void*)0) +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _MEMORY_H */ diff --git a/src/mips/ps1sdk/include/mipsregs.h b/src/mips/ps1sdk/include/mipsregs.h new file mode 100644 index 000000000..421c6d7f6 --- /dev/null +++ b/src/mips/ps1sdk/include/mipsregs.h @@ -0,0 +1,189 @@ +#ifndef _MIPSREGS_H +#define _MIPSREGS_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* general registers */ + +#define r0 $0 +#define r1 $1 +#define r2 $2 +#define r3 $3 +#define r4 $4 +#define r5 $5 +#define r6 $6 +#define r7 $7 +#define r8 $8 +#define r9 $9 +#define r10 $10 +#define r11 $11 +#define r12 $12 +#define r13 $13 +#define r14 $14 +#define r15 $15 +#define r16 $16 +#define r17 $17 +#define r18 $18 +#define r19 $19 +#define r20 $20 +#define r21 $21 +#define r22 $22 +#define r23 $23 +#define r24 $24 +#define r25 $25 +#define r26 $26 +#define r27 $27 +#define r28 $28 +#define r29 $29 +#define r30 $30 +#define r31 $31 + +#define zero $0 +//#define at $1 +#define v0 $2 +#define v1 $3 +#define a0 $4 +#define a1 $5 +#define a2 $6 +#define a3 $7 +#define t0 $8 +#define t1 $9 +#define t2 $10 +#define t3 $11 +#define t4 $12 +#define t5 $13 +#define t6 $14 +#define t7 $15 +#define s0 $16 +#define s1 $17 +#define s2 $18 +#define s3 $19 +#define s4 $20 +#define s5 $21 +#define s6 $22 +#define s7 $23 +#define t8 $24 +#define t9 $25 +#define k0 $26 +#define k1 $27 +#define gp $28 +#define sp $29 +#define s8 $30 +#define fp $30 +#define ra $31 + +/* COP0 Registers */ + +/* BreakPoint Control */ +#define C0_BPC $3 +/* BreakPoint on Data Access */ +#define C0_BDA $5 +/* BreakPoint on Data Access */ +#define C0_DCIC $7 +/* Bad Virtual Address */ +#define C0_BADVADDR $8 +// Breakpoint Data Access Mask +#define C0_BDAM $9 +// Breakpoint Program Counter Mask +#define C0_BPCM $11 + +/* Status Register */ +#define C0_STATUS $12 + +/* Cause Register */ +#define C0_CAUSE $13 + +/* Error PC Register */ +#define C0_EPC $14 + +/* Processor ID */ +#define C0_PRID $15 + +// Interrupt Enable(current) +#define C0_SR_IEC (1 << 0) +// Kernel/User mode(current) +#define C0_SR_KUC (1 << 1) +// Interrupt Enable(previous) +#define C0_SR_IEP (1 << 2) +// Kernel/User mode(previous) +#define C0_SR_KUP (1 << 3) +// Interrupt Enable(old) +#define C0_SR_IEO (1 << 4) +// Kernel/User mode(old) +#define C0_SR_KUO (1 << 5) + +/* Interrupt Mask 0 */ +#define C0_SR_IMO (1 << 8) +/* Interrupt Mask 1 */ +#define C0_SR_IM1 (1 << 9) +/* Interrupt Mask 2 */ +#define C0_SR_IM2 (1 << 10) +/* Interrupt Mask 3 */ +#define C0_SR_IM3 (1 << 11) +/* Interrupt Mask 4 */ +#define C0_SR_IM4 (1 << 12) +/* Interrupt Mask 5 */ +#define C0_SR_IM5 (1 << 13) +/* Interrupt Mask 6 */ +#define C0_SR_IM6 (1 << 14) +/* Interrupt Mask 7 */ +#define C0_SR_IM7 (1 << 15) + +/* Isolate Cache */ +#define C0_SR_ISC (1 << 16) +/* Swap Caches */ +#define C0_SR_SWC (1 << 17) +/* Parity Zero */ +#define C0_SR_PZ (1 << 18) +/* Cache Miss */ +#define C0_SR_CM (1 << 19) +/* Parity Error */ +#define C0_SR_PE (1 << 20) +/* TLB Shutdown */ +#define C0_SR_TS (1 << 21) +/* Boot-time Exception Vector */ +#define C0_SR_BEV (1 << 22) + +/* Reverse Endian enable */ +#define C0_SR_RE (1 << 25) + +/* Coprocessor 0 Usable */ +#define C0_SR_CU0 (1 << 28) +/* Coprocessor 1 Usable */ +#define C0_SR_CU1 (1 << 29) +/* Coprocessor 2 Usable */ +#define C0_SR_CU2 (1 << 30) +/* Coprocessor 3 Usable */ +#define C0_SR_CU3 (1 << 31) + +// R3000A COP0 DCIC register bits + +/* These are R/W, used to enable/disable various debug/cache things */ +#define C0_DCIC_TR (1 << 31) /* Trap enable */ +#define C0_DCIC_UD (1 << 30) /* User debug enable */ +#define C0_DCIC_KD (1 << 29) /* Kernel debug enable */ +#define C0_DCIC_TE (1 << 28) /* Trace enable */ +#define C0_DCIC_DW (1 << 27) /* Enable data access breakpoints on write */ +#define C0_DCIC_DR (1 << 26) /* Enable data access breakpoints on read */ +#define C0_DCIC_DAE (1 << 25) /* Enable data addresss breakpoints(Is this valid?) */ +#define C0_DCIC_PCE (1 << 24) /* Enable instruction breakpoints */ +#define C0_DCIC_DE (1 << 23) /* Debug Enable */ +#define C0_DCIC_DL (1 << 15) /* Data cache line invalidate */ +#define C0_DCIC_IL (1 << 14) /* Instruction cache line invalidate */ +#define C0_DCIC_D (1 << 13) /* Data cache invalidate enable */ +#define C0_DCIC_I (1 << 12) /* Instr. cache invalidate enable */ +/* The rest of these are R/O, set by the CPU to indicate the type of debug exception that occured */ +#define C0_DCIC_T (1 << 5) /* Trace */ +#define C0_DCIC_W (1 << 4) /* Write reference */ +#define C0_DCIC_R (1 << 3) /* Read reference */ +#define C0_DCIC_DA (1 << 2) /* Data address */ +#define C0_DCIC_PC (1 << 1) /* Program counter */ +#define C0_DCIC_DB (1 << 0) /* Debug */ + +#ifdef __cplusplus +} +#endif + +#endif /* _MIPSREGS_H */ diff --git a/src/mips/ps1sdk/include/packer.h b/src/mips/ps1sdk/include/packer.h new file mode 100644 index 000000000..cc4a2da5e --- /dev/null +++ b/src/mips/ps1sdk/include/packer.h @@ -0,0 +1,24 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# Packers for PS1. +# +*/ + +#ifndef _PACK_H +#define _PACK_H + +#ifdef __cplusplus +extern "C" { +#endif + +void BK_Unpack(void* src, void* dest); + +#ifdef __cplusplus +} +#endif + +#endif /* _PACK_H */ diff --git a/src/mips/ps1sdk/include/ps1cdrom.h b/src/mips/ps1sdk/include/ps1cdrom.h new file mode 100644 index 000000000..e81773c78 --- /dev/null +++ b/src/mips/ps1sdk/include/ps1cdrom.h @@ -0,0 +1,127 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# PS1 CD-ROM definitions. +# +*/ + +#ifndef _PS1_CDROM_H_ +#define _PS1_CDROM_H_ + +// PS1 CD-ROM Commands +enum { + PS1_CdSync = 0x00, + PS1_CdNop = 0x01, + PS1_CdSetloc = 0x02, + PS1_CdPlay = 0x03, + PS1_CdForward = 0x04, + PS1_CdBackward = 0x05, + PS1_CdReadN = 0x06, + PS1_CdStandby = 0x07, + PS1_CdStop = 0x08, + PS1_CdPause = 0x09, + PS1_CdInit = 0x0A, + PS1_CdMute = 0x0B, + PS1_CdDemute = 0x0C, + PS1_CdSetFilter = 0x0D, + PS1_CdSetMode = 0x0E, + PS1_CdGetParam = 0x0F, + PS1_CdGetLocL = 0x10, + PS1_CdGetLocP = 0x11, + PS1_CdCmd12 = 0x12, + PS1_CdGetTN = 0x13, + PS1_CdGetTD = 0x14, + PS1_CdSeekL = 0x15, + PS1_CdSeekP = 0x16, + PS1_CdCmd17 = 0x17, + PS1_CdCmd18 = 0x18, + PS1_CdTest = 0x19, + PS1_CdReadDiscID = 0x1A, + PS1_CdReadS = 0x1B, + PS1_CdReset = 0x1C, + PS1_CdCmd1D = 0x1D, + PS1_CdReadTOC = 0x1E, + PS1_CdCmd1F = 0x1F, +}; + +// macros for reading CD-ROM registers. +#define M_CD_RD_IFSTAT(__res) \ + { __res = *R_PS1_CDROM0; } +#define M_CD_RD_RESULT(__res) \ + { __res = *R_PS1_CDROM1; } +#define M_CD_RD_DATA(__res) \ + { __res = *R_PS1_CDROM2; } +#define M_CD_RD_INTMASK(__res) \ + { \ + *R_PS1_CDROM0 = 0; \ + __res = *R_PS1_CDROM3 & 0x1F; \ + } +#define M_CD_RD_INTSTAT(__res) \ + { \ + *R_PS1_CDROM0 = 1; \ + __res = *R_PS1_CDROM3 & 0x1F; \ + } + +// macros for writing CD-ROM registers. +#define M_CD_WR_CMD(__val) \ + { \ + *R_PS1_CDROM0 = 0; \ + *R_PS1_CDROM1 = (__val); \ + } +#define M_CD_WR_PARAM(__val) \ + { \ + *R_PS1_CDROM0 = 0; \ + *R_PS1_CDROM2 = (__val); \ + } +#define M_CD_WR_CHPCTRL(__val) \ + { \ + *R_PS1_CDROM0 = 0; \ + *R_PS1_CDROM3 = (__val); \ + } +#define M_CD_WR_INTMASK(__val) \ + { \ + *R_PS1_CDROM0 = 1; \ + *R_PS1_CDROM2 = (__val)&0x1F; \ + } +#define M_CD_WR_CLRCTRL(__val) \ + { \ + *R_PS1_CDROM0 = 1; \ + *R_PS1_CDROM3 = (__val); \ + } + +enum { + CdIntrNone = 0, + CdIntrDataRdy = 1, + CdIntrComplete = 2, + CdIntrAcknowledge = 3, + CdIntrDataEnd = 4, + CdIntrDiskError = 5 +}; + +// bits for "status" byte returned by commands. +enum { + CdStatusCmdErr = (1 << 0), // command error + CdStatusStandby = (1 << 1), // spindle motor rotating + CdStatusUnk2 = (1 << 2), // unknown + CdStatusSeekErr = (1 << 3), // seek error + CdStatusOpen = (1 << 4), // drive lid has been opened + CdStatusRead = (1 << 5), // reading data + CdStatusSeek = (1 << 6), // seeking + CdStatusPlay = (1 << 7) // playing CD-DA +}; + +enum { + CD_IFSTAT_RA0 = (1 << 0), + CD_IFSTAT_RA1 = (1 << 1), + CD_IFSTAT_ADPCM_BUSY = (1 << 2), + CD_IFSTAT_PARAM_EMPTY = (1 << 3), + CD_IFSTAT_PARAM_WR_RDY = (1 << 4), + CD_IFSTAT_RESULT_RDY = (1 << 5), + CD_IFSTAT_DATA_REQ = (1 << 6), + CD_IFSTAT_CMD_BUSY = (1 << 7), +}; + +#endif // _PS1_CDROM_H_ diff --git a/src/mips/ps1sdk/include/ps1hwregs.h b/src/mips/ps1sdk/include/ps1hwregs.h new file mode 100644 index 000000000..f5ff79a1f --- /dev/null +++ b/src/mips/ps1sdk/include/ps1hwregs.h @@ -0,0 +1,492 @@ +/* + * PS1 hardware register definitions + */ + +#ifndef _PS1HWREGS_H +#define _PS1HWREGS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define A_PS1_HWREG_BASE 0x1F800000 + +/* 16-bit offsets for the PS1 hardware registers based at 0x1F800000 */ +/* Useful as offsets for assembler. */ + +// DEV0: PIO Expansion Port. +// DEV1: Unknown +// DEV2: BIOS ROM chip(BIOS) +// DEV4: Sound Processing Unit(SPU) +// DEV5: CD-ROM interface(CDROM) +// DEV8: Development hardware in the official dev kit. + +// SBUS device address registers. +#define O_PS1_SBUS_DEV0_ADDR (0x1000) +#define O_PS1_SBUS_DEV8_ADDR (0x1004) + +// SBUS device control registers. +#define O_PS1_SBUS_DEV0_CTRL (0x1008) +#define O_PS1_SBUS_DEV1_CTRL (0x100C) +#define O_PS1_SBUS_DEV2_CTRL (0x1010) +#define O_PS1_SBUS_DEV4_CTRL (0x1014) +#define O_PS1_SBUS_DEV5_CTRL (0x1018) +#define O_PS1_SBUS_DEV8_CTRL (0x101C) + +// SBUS common control register. +#define O_PS1_SBUS_COM_CTRL (0x1020) + +#define O_PS1_SIO0_DATA (0x1040) +#define O_PS1_SIO0_STATUS (0x1044) +#define O_PS1_SIO0_MODE (0x1048) +#define O_PS1_SIO0_CONTROL (0x104A) +#define O_PS1_SIO0_BAUD (0x104E) + +#define O_PS1_SIO1_DATA (0x1050) +#define O_PS1_SIO1_STATUS (0x1054) +#define O_PS1_SIO1_MODE (0x1058) +#define O_PS1_SIO1_CONTROL (0x105A) +#define O_PS1_SIO1_BAUD (0x105E) + +#define O_PS1_RAM_SIZE (0x1060) + +#define O_PS1_I_STAT (0x1070) +#define O_PS1_I_MASK (0x1074) + +#define O_PS1_DMA_CH0_MADR (0x1080) +#define O_PS1_DMA_CH0_BCR (0x1084) +#define O_PS1_DMA_CH0_CHCR (0x1088) + +#define O_PS1_DMA_CH1_MADR (0x1090) +#define O_PS1_DMA_CH1_BCR (0x1094) +#define O_PS1_DMA_CH1_CHCR (0x1098) + +#define O_PS1_DMA_CH2_MADR (0x10A0) +#define O_PS1_DMA_CH2_BCR (0x10A4) +#define O_PS1_DMA_CH2_CHCR (0x10A8) + +#define O_PS1_DMA_CH3_MADR (0x10B0) +#define O_PS1_DMA_CH3_BCR (0x10B4) +#define O_PS1_DMA_CH3_CHCR (0x10B8) + +#define O_PS1_DMA_CH4_MADR (0x10C0) +#define O_PS1_DMA_CH4_BCR (0x10C4) +#define O_PS1_DMA_CH4_CHCR (0x10C8) + +#define O_PS1_DMA_CH5_MADR (0x10D0) +#define O_PS1_DMA_CH5_BCR (0x10D4) +#define O_PS1_DMA_CH5_CHCR (0x10D8) + +#define O_PS1_DMA_CH6_MADR (0x10E0) +#define O_PS1_DMA_CH6_BCR (0x10E4) +#define O_PS1_DMA_CH6_CHCR (0x10E8) + +#define O_PS1_DMA_PCR (0x10F0) +#define O_PS1_DMA_ICR (0x10F4) + +#define O_PS1_T0_COUNT (0x1100) +#define O_PS1_T0_MODE (0x1104) +#define O_PS1_T0_TARGET (0x1108) +#define O_PS1_T1_COUNT (0x1110) +#define O_PS1_T1_MODE (0x1114) +#define O_PS1_T1_TARGET (0x1118) +#define O_PS1_T2_COUNT (0x1120) +#define O_PS1_T2_MODE (0x1124) +#define O_PS1_T2_TARGET (0x1128) + +#define O_PS1_CDROM0 (0x1800) +#define O_PS1_CDROM1 (0x1801) +#define O_PS1_CDROM2 (0x1802) +#define O_PS1_CDROM3 (0x1803) + +#define O_PS1_GPU_REG0 (0x1810) +#define O_PS1_GPU_REG1 (0x1814) + +#define O_PS1_MDEC_REG0 (0x1820) +#define O_PS1_MDEC_REG1 (0x1824) + +#define O_PS1_SPU_MVOL_L (0x1D80) +#define O_PS1_SPU_MVOL_R (0x1D82) + +#define O_PS1_SPU_REVERB_L (0x1D84) +#define O_PS1_SPU_REVERB_R (0x1D86) + +#define O_PS1_SPU_KEY_ON1 (0x1D88) +#define O_PS1_SPU_KEY_ON2 (0x1D8A) + +#define O_PS1_SPU_KEY_OFF1 (0x1D8C) +#define O_PS1_SPU_KEY_OFF2 (0x1D8E) + +#define O_PS1_SPU_KEY_MODEFM1 (0x1D90) +#define O_PS1_SPU_KEY_MODEFM2 (0x1D92) + +#define O_PS1_SPU_KEY_MODENOISE1 (0x1D94) +#define O_PS1_SPU_KEY_MODENOISE2 (0x1D96) + +#define O_PS1_SPU_KEY_MODEREVERB1 (0x1D98) +#define O_PS1_SPU_KEY_MODEREVERB2 (0x1D9A) + +#define O_PS1_SPU_KEY_CHANNELACTIVE1 (0x1D9C) +#define O_PS1_SPU_KEY_CHANNELACTIVE2 (0x1D9E) + +#define O_PS1_SPU_U_E (0x1DA2) + +#define O_PS1_SPU_SB_ADDR (0x1DA6) + +#define O_PS1_SPU_DATA (0x1DA8) + +#define O_PS1_SPU_REG0 (0x1DAA) + +#define O_PS1_SPU_REG1 (0x1DAC) +#define O_PS1_SPU_STATUS (0x1DAE) + +#define O_PS1_SPU_CDMVOL_L (0x1DB0) +#define O_PS1_SPU_CDMVOL_R (0x1DB2) + +#define O_PS1_SPU_EXTVOL_L (0x1DB4) +#define O_PS1_SPU_EXTVOL_R (0x1DB6) + +#define O_PS1_SPU_REVERBCONFIG (0x1DC0) + +#define O_PS1_SPU_FACTORLEFT (0x1DFC) +#define O_PS1_SPU_FACTORRIGHT (0x1DFE) + +#define O_PS1_DBG_R20 (0x2020) +#define O_PS1_DBG_R21 (0x2021) +#define O_PS1_DBG_R22 (0x2022) +#define O_PS1_DBG_R23 (0x2023) +#define O_PS1_DBG_R24 (0x2024) +#define O_PS1_DBG_R25 (0x2025) +#define O_PS1_DBG_R26 (0x2026) +#define O_PS1_DBG_R27 (0x2027) +#define O_PS1_DBG_R28 (0x2028) +#define O_PS1_DBG_R29 (0x2029) +#define O_PS1_DBG_R2A (0x202A) +#define O_PS1_DBG_R2B (0x202B) +#define O_PS1_DBG_R2C (0x202C) +#define O_PS1_DBG_R2D (0x202D) +#define O_PS1_DBG_R2E (0x202E) +#define O_PS1_DBG_R2F (0x202F) +#define O_PS1_DBG_R30 (0x2030) +#define O_PS1_DBG_DIPS (0x2040) +#define O_PS1_DBG_R41 (0x2041) +#define O_PS1_DBG_R42 (0x2042) +#define O_PS1_DBG_R43 (0x2043) + +/* Definitions of PS1 hardware register full physical addresses */ + +#define A_PS1_SBUS_DEV0_ADDR (A_PS1_HWREG_BASE + O_PS1_SBUS_DEV0_ADDR) +#define A_PS1_SBUS_DEV8_ADDR (A_PS1_HWREG_BASE + O_PS1_SBUS_DEV8_ADDR) + +#define A_PS1_SBUS_DEV0_CTRL (A_PS1_HWREG_BASE + O_PS1_SBUS_DEV0_CTRL) +#define A_PS1_SBUS_DEV1_CTRL (A_PS1_HWREG_BASE + O_PS1_SBUS_DEV1_CTRL) +#define A_PS1_SBUS_DEV2_CTRL (A_PS1_HWREG_BASE + O_PS1_SBUS_DEV2_CTRL) +#define A_PS1_SBUS_DEV4_CTRL (A_PS1_HWREG_BASE + O_PS1_SBUS_DEV4_CTRL) +#define A_PS1_SBUS_DEV5_CTRL (A_PS1_HWREG_BASE + O_PS1_SBUS_DEV5_CTRL) +#define A_PS1_SBUS_DEV8_CTRL (A_PS1_HWREG_BASE + O_PS1_SBUS_DEV8_CTRL) + +#define A_PS1_SBUS_COM_CTRL (A_PS1_HWREG_BASE + O_PS1_SBUS_COM_CTRL) + +#define A_PS1_SIO0_DATA (A_PS1_HWREG_BASE + O_PS1_SIO0_DATA) +#define A_PS1_SIO0_STATUS (A_PS1_HWREG_BASE + O_PS1_SIO0_STATUS) +#define A_PS1_SIO0_MODE (A_PS1_HWREG_BASE + O_PS1_SIO0_MODE) +#define A_PS1_SIO0_CONTROL (A_PS1_HWREG_BASE + O_PS1_SIO0_CONTROL) +#define A_PS1_SIO0_BAUD (A_PS1_HWREG_BASE + O_PS1_SIO0_BAUD) + +#define A_PS1_SIO1_DATA (A_PS1_HWREG_BASE + O_PS1_SIO1_DATA) +#define A_PS1_SIO1_STATUS (A_PS1_HWREG_BASE + O_PS1_SIO1_STATUS) +#define A_PS1_SIO1_MODE (A_PS1_HWREG_BASE + O_PS1_SIO1_MODE) +#define A_PS1_SIO1_CONTROL (A_PS1_HWREG_BASE + O_PS1_SIO1_CONTROL) +#define A_PS1_SIO1_BAUD (A_PS1_HWREG_BASE + O_PS1_SIO1_BAUD) + +#define A_PS1_RAM_SIZE (A_PS1_HWREG_BASE + O_PS1_RAM_SIZE) + +#define A_PS1_I_STAT (A_PS1_HWREG_BASE + O_PS1_I_STAT) +#define A_PS1_I_MASK (A_PS1_HWREG_BASE + O_PS1_I_MASK) + +#define A_PS1_DMA_CH0_MADR (A_PS1_HWREG_BASE + O_PS1_DMA_CH0_MADR) +#define A_PS1_DMA_CH0_BCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH0_BCR) +#define A_PS1_DMA_CH0_CHCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH0_CHCR) + +#define A_PS1_DMA_CH1_MADR (A_PS1_HWREG_BASE + O_PS1_DMA_CH1_MADR) +#define A_PS1_DMA_CH1_BCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH1_BCR) +#define A_PS1_DMA_CH1_CHCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH1_CHCR) + +#define A_PS1_DMA_CH2_MADR (A_PS1_HWREG_BASE + O_PS1_DMA_CH2_MADR) + +#define A_PS1_DMA_CH2_BCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH2_BCR) +#define A_PS1_DMA_CH2_CHCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH2_CHCR) +#define A_PS1_DMA_CH3_MADR (A_PS1_HWREG_BASE + O_PS1_DMA_CH3_MADR) +#define A_PS1_DMA_CH3_BCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH3_BCR) +#define A_PS1_DMA_CH3_CHCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH3_CHCR) +#define A_PS1_DMA_CH4_MADR (A_PS1_HWREG_BASE + O_PS1_DMA_CH4_MADR) +#define A_PS1_DMA_CH4_BCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH4_BCR) +#define A_PS1_DMA_CH4_CHCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH4_CHCR) +#define A_PS1_DMA_CH5_MADR (A_PS1_HWREG_BASE + O_PS1_DMA_CH5_MADR) +#define A_PS1_DMA_CH5_BCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH5_BCR) +#define A_PS1_DMA_CH5_CHCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH5_CHCR) +#define A_PS1_DMA_CH6_MADR (A_PS1_HWREG_BASE + O_PS1_DMA_CH6_MADR) +#define A_PS1_DMA_CH6_BCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH6_BCR) +#define A_PS1_DMA_CH6_CHCR (A_PS1_HWREG_BASE + O_PS1_DMA_CH6_CHCR) +#define A_PS1_DMA_PCR (A_PS1_HWREG_BASE + O_PS1_DMA_PCR) +#define A_PS1_DMA_ICR (A_PS1_HWREG_BASE + O_PS1_DMA_ICR) +#define A_PS1_T0_COUNT (A_PS1_HWREG_BASE + O_PS1_T0_COUNT) +#define A_PS1_T0_MODE (A_PS1_HWREG_BASE + O_PS1_T0_MODE) +#define A_PS1_T0_TARGET (A_PS1_HWREG_BASE + O_PS1_T0_TARGET) +#define A_PS1_T1_COUNT (A_PS1_HWREG_BASE + O_PS1_T1_COUNT) +#define A_PS1_T1_MODE (A_PS1_HWREG_BASE + O_PS1_T1_MODE) +#define A_PS1_T1_TARGET (A_PS1_HWREG_BASE + O_PS1_T1_TARGET) +#define A_PS1_T2_COUNT (A_PS1_HWREG_BASE + O_PS1_T2_COUNT) +#define A_PS1_T2_MODE (A_PS1_HWREG_BASE + O_PS1_T2_MODE) +#define A_PS1_T2_TARGET (A_PS1_HWREG_BASE + O_PS1_T2_TARGET) + +#define A_PS1_CDROM0 (A_PS1_HWREG_BASE + O_PS1_CDROM0) +#define A_PS1_CDROM1 (A_PS1_HWREG_BASE + O_PS1_CDROM1) +#define A_PS1_CDROM2 (A_PS1_HWREG_BASE + O_PS1_CDROM2) +#define A_PS1_CDROM3 (A_PS1_HWREG_BASE + O_PS1_CDROM3) + +#define A_PS1_GPU_REG0 (A_PS1_HWREG_BASE + O_PS1_GPU_REG0) +#define A_PS1_GPU_REG1 (A_PS1_HWREG_BASE + O_PS1_GPU_REG1) + +#define A_PS1_MDEC_REG0 (A_PS1_HWREG_BASE + O_PS1_MDEC_REG0) +#define A_PS1_MDEC_REG1 (A_PS1_HWREG_BASE + O_PS1_MDEC_REG1) + +#define A_PS1_SPU_MVOL_L (A_PS1_HWREG_BASE + O_PS1_SPU_MVOL_L) +#define A_PS1_SPU_MVOL_R (A_PS1_HWREG_BASE + O_PS1_SPU_MVOL_R) + +#define A_PS1_SPU_REVERB_L (A_PS1_HWREG_BASE + O_PS1_SPU_REVERB_L) +#define A_PS1_SPU_REVERB_R (A_PS1_HWREG_BASE + O_PS1_SPU_REVERB_R) + +#define A_PS1_SPU_KEY_ON1 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_ON1) +#define A_PS1_SPU_KEY_ON2 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_ON2) + +#define A_PS1_SPU_KEY_OFF1 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_OFF1) +#define A_PS1_SPU_KEY_OFF2 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_OFF2) + +#define A_PS1_SPU_KEY_MODEFM1 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_MODEFM1) +#define A_PS1_SPU_KEY_MODEFM2 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_MODEFM2) + +#define A_PS1_SPU_KEY_MODENOISE1 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_MODENOISE1) +#define A_PS1_SPU_KEY_MODENOISE2 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_MODENOISE2) + +#define A_PS1_SPU_KEY_MODEREVERB1 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_MODEREVERB1) +#define A_PS1_SPU_KEY_MODEREVERB2 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_MODEREVERB2) + +#define A_PS1_SPU_KEY_CHANNELACTIVE1 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_CHANNELACTIVE1) +#define A_PS1_SPU_KEY_CHANNELACTIVE2 (A_PS1_HWREG_BASE + O_PS1_SPU_KEY_CHANNELACTIVE2) + +#define A_PS1_SPU_U_E (A_PS1_HWREG_BASE + O_PS1_SPU_U_E) + +#define A_PS1_SPU_SB_ADDR (A_PS1_HWREG_BASE + O_PS1_SPU_SB_ADDR) + +#define A_PS1_SPU_DATA (A_PS1_HWREG_BASE + O_PS1_SPU_DATA) + +#define A_PS1_SPU_REG0 (A_PS1_HWREG_BASE + O_PS1_SPU_REG0) + +#define A_PS1_SPU_REG1 (A_PS1_HWREG_BASE + O_PS1_SPU_REG1) +#define A_PS1_SPU_STATUS (A_PS1_HWREG_BASE + O_PS1_SPU_STATUS) + +#define A_PS1_SPU_CDMVOL_L (A_PS1_HWREG_BASE + O_PS1_SPU_CDMVOL_L) +#define A_PS1_SPU_CDMVOL_R (A_PS1_HWREG_BASE + O_PS1_SPU_CDMVOL_R) + +#define A_PS1_SPU_EXTVOL_L (A_PS1_HWREG_BASE + O_PS1_SPU_EXTVOL_L) +#define A_PS1_SPU_EXTVOL_R (A_PS1_HWREG_BASE + O_PS1_SPU_EXTVOL_R) + +#define A_PS1_SPU_REVERBCONFIG (A_PS1_HWREG_BASE + O_PS1_SPU_REVERBCONFIG) + +#define A_PS1_SPU_FACTORLEFT (A_PS1_HWREG_BASE + O_PS1_SPU_FACTORLEFT) +#define A_PS1_SPU_FACTORRIGHT (A_PS1_HWREG_BASE + O_PS1_SPU_FACTORRIGHT) + +#define A_PS1_DBG_R20 (A_PS1_HWREG_BASE + O_PS1_DBG_R20) +#define A_PS1_DBG_R21 (A_PS1_HWREG_BASE + O_PS1_DBG_R21) +#define A_PS1_DBG_R22 (A_PS1_HWREG_BASE + O_PS1_DBG_R22) +#define A_PS1_DBG_R23 (A_PS1_HWREG_BASE + O_PS1_DBG_R23) +#define A_PS1_DBG_R24 (A_PS1_HWREG_BASE + O_PS1_DBG_R24) +#define A_PS1_DBG_R25 (A_PS1_HWREG_BASE + O_PS1_DBG_R25) +#define A_PS1_DBG_R26 (A_PS1_HWREG_BASE + O_PS1_DBG_R26) +#define A_PS1_DBG_R27 (A_PS1_HWREG_BASE + O_PS1_DBG_R27) +#define A_PS1_DBG_R28 (A_PS1_HWREG_BASE + O_PS1_DBG_R28) +#define A_PS1_DBG_R29 (A_PS1_HWREG_BASE + O_PS1_DBG_R29) +#define A_PS1_DBG_R2A (A_PS1_HWREG_BASE + O_PS1_DBG_R2A) +#define A_PS1_DBG_R2B (A_PS1_HWREG_BASE + O_PS1_DBG_R2B) +#define A_PS1_DBG_R2C (A_PS1_HWREG_BASE + O_PS1_DBG_R2C) +#define A_PS1_DBG_R2D (A_PS1_HWREG_BASE + O_PS1_DBG_R2D) +#define A_PS1_DBG_R2E (A_PS1_HWREG_BASE + O_PS1_DBG_R2E) +#define A_PS1_DBG_R2F (A_PS1_HWREG_BASE + O_PS1_DBG_R2F) +#define A_PS1_DBG_R30 (A_PS1_HWREG_BASE + O_PS1_DBG_R30) +#define A_PS1_DBG_DIPS (A_PS1_HWREG_BASE + O_PS1_DBG_DIPS) +#define A_PS1_DBG_R41 (A_PS1_HWREG_BASE + O_PS1_DBG_R41) +#define A_PS1_DBG_R42 (A_PS1_HWREG_BASE + O_PS1_DBG_R42) +#define A_PS1_DBG_R43 (A_PS1_HWREG_BASE + O_PS1_DBG_R43) + +/* Definitions of pointers to PS1 hardware registers */ + +#define R_PS1_SBUS_DEV0_ADDR ((vuint32_t*)(A_PS1_SBUS_DEV0_ADDR)) +#define R_PS1_SBUS_DEV8_ADDR ((vuint32_t*)(A_PS1_SBUS_DEV8_ADDR)) + +#define R_PS1_SBUS_DEV0_CTRL ((vuint32_t*)(A_PS1_SBUS_DEV0_CTRL)) +#define R_PS1_SBUS_DEV1_CTRL ((vuint32_t*)(A_PS1_SBUS_DEV1_CTRL)) +#define R_PS1_SBUS_DEV2_CTRL ((vuint32_t*)(A_PS1_SBUS_DEV2_CTRL)) +#define R_PS1_SBUS_DEV4_CTRL ((vuint32_t*)(A_PS1_SBUS_DEV4_CTRL)) +#define R_PS1_SBUS_DEV5_CTRL ((vuint32_t*)(A_PS1_SBUS_DEV5_CTRL)) +#define R_PS1_SBUS_DEV8_CTRL ((vuint32_t*)(A_PS1_SBUS_DEV8_CTRL)) + +#define R_PS1_SBUS_COM_CTRL ((vuint32_t*)(A_PS1_SBUS_COM_CTRL)) + +#define R_PS1_SIO0_DATA ((vuint8_t*)(A_PS1_SIO0_DATA)) +#define R_PS1_SIO0_STAT ((vuint16_t*)(A_PS1_SIO0_STATUS)) +#define R_PS1_SIO0_MODE ((vuint16_t*)(A_PS1_SIO0_MODE)) +#define R_PS1_SIO0_CTRL ((vuint16_t*)(A_PS1_SIO0_CONTROL)) +#define R_PS1_SIO0_BAUD ((vuint16_t*)(A_PS1_SIO0_BAUD)) + +#define R_PS1_SIO1_DATA ((vuint8_t*)(A_PS1_SIO1_DATA)) +#define R_PS1_SIO1_STAT ((vuint16_t*)(A_PS1_SIO1_STATUS)) +#define R_PS1_SIO1_MODE ((vuint16_t*)(A_PS1_SIO1_MODE)) +#define R_PS1_SIO1_CTRL ((vuint16_t*)(A_PS1_SIO1_CONTROL)) +#define R_PS1_SIO1_BAUD ((vuint16_t*)(A_PS1_SIO1_BAUD)) + +#define R_PS1_RAM_SIZE ((vuint32_t*)(A_PS1_RAM_SIZE)) + +#define R_PS1_I_STAT ((vuint32_t*)(A_PS1_I_STAT)) +#define R_PS1_I_MASK ((vuint32_t*)(A_PS1_I_MASK)) + +#define R_PS1_DMA_CH0_MADR ((vuint32_t*)(A_PS1_DMA_CH0_MADR)) +#define R_PS1_DMA_CH0_BCR ((vuint32_t*)(A_PS1_DMA_CH0_BCR)) +#define R_PS1_DMA_CH0_CHCR ((vuint32_t*)(A_PS1_DMA_CH0_CHCR)) + +#define R_PS1_DMA_CH1_MADR ((vuint32_t*)(A_PS1_DMA_CH1_MADR)) +#define R_PS1_DMA_CH1_BCR ((vuint32_t*)(A_PS1_DMA_CH1_BCR)) +#define R_PS1_DMA_CH1_CHCR ((vuint32_t*)(A_PS1_DMA_CH1_CHCR)) + +#define R_PS1_DMA_CH2_MADR ((vuint32_t*)(A_PS1_DMA_CH2_MADR)) + +#define R_PS1_DMA_CH2_BCR ((vuint32_t*)(A_PS1_DMA_CH2_BCR)) +#define R_PS1_DMA_CH2_CHCR ((vuint32_t*)(A_PS1_DMA_CH2_CHCR)) +#define R_PS1_DMA_CH3_MADR ((vuint32_t*)(A_PS1_DMA_CH3_MADR)) +#define R_PS1_DMA_CH3_BCR ((vuint32_t*)(A_PS1_DMA_CH3_BCR)) +#define R_PS1_DMA_CH3_CHCR ((vuint32_t*)(A_PS1_DMA_CH3_CHCR)) +#define R_PS1_DMA_CH4_MADR ((vuint32_t*)(A_PS1_DMA_CH4_MADR)) +#define R_PS1_DMA_CH4_BCR ((vuint32_t*)(A_PS1_DMA_CH4_BCR)) +#define R_PS1_DMA_CH4_CHCR ((vuint32_t*)(A_PS1_DMA_CH4_CHCR)) +#define R_PS1_DMA_CH5_MADR ((vuint32_t*)(A_PS1_DMA_CH5_MADR)) +#define R_PS1_DMA_CH5_BCR ((vuint32_t*)(A_PS1_DMA_CH5_BCR)) +#define R_PS1_DMA_CH5_CHCR ((vuint32_t*)(A_PS1_DMA_CH5_CHCR)) +#define R_PS1_DMA_CH6_MADR ((vuint32_t*)(A_PS1_DMA_CH6_MADR)) +#define R_PS1_DMA_CH6_BCR ((vuint32_t*)(A_PS1_DMA_CH6_BCR)) +#define R_PS1_DMA_CH6_CHCR ((vuint32_t*)(A_PS1_DMA_CH6_CHCR)) +#define R_PS1_DMA_PCR ((vuint32_t*)(A_PS1_DMA_PCR)) +#define R_PS1_DMA_ICR ((vuint32_t*)(A_PS1_DMA_ICR)) + +#define R_PS1_Tx_COUNT(__x) ((vuint16_t*)(A_PS1_T0_COUNT + ((__x)*0x10))) +#define R_PS1_Tx_MODE(__x) ((vuint16_t*)(A_PS1_T0_MODE + ((__x)*0x10))) +#define R_PS1_Tx_TARGET(__x) ((vuint16_t*)(A_PS1_T0_TARGET + ((__x)*0x10))) + +#define R_PS1_T0_COUNT ((vuint16_t*)(A_PS1_T0_COUNT)) +#define R_PS1_T0_MODE ((vuint16_t*)(A_PS1_T0_MODE)) +#define R_PS1_T0_TARGET ((vuint16_t*)(A_PS1_T0_TARGET)) +#define R_PS1_T1_COUNT ((vuint16_t*)(A_PS1_T1_COUNT)) +#define R_PS1_T1_MODE ((vuint16_t*)(A_PS1_T1_MODE)) +#define R_PS1_T1_TARGET ((vuint16_t*)(A_PS1_T1_TARGET)) +#define R_PS1_T2_COUNT ((vuint16_t*)(A_PS1_T2_COUNT)) +#define R_PS1_T2_MODE ((vuint16_t*)(A_PS1_T2_MODE)) +#define R_PS1_T2_TARGET ((vuint16_t*)(A_PS1_T2_TARGET)) + +#define R_PS1_CDROM0 ((vuint8_t*)(A_PS1_CDROM0)) +#define R_PS1_CDROM1 ((vuint8_t*)(A_PS1_CDROM1)) +#define R_PS1_CDROM2 ((vuint8_t*)(A_PS1_CDROM2)) +#define R_PS1_CDROM3 ((vuint8_t*)(A_PS1_CDROM3)) + +#define R_PS1_GPU_REG0 ((vuint32_t*)(A_PS1_GPU_REG0)) +#define R_PS1_GPU_REG1 ((vuint32_t*)(A_PS1_GPU_REG1)) + +#define R_PS1_MDEC_REG0 ((vuint32_t*)(A_PS1_MDEC_REG0)) +#define R_PS1_MDEC_REG1 ((vuint32_t*)(A_PS1_MDEC_REG1)) + +#define R_PS1_SPU_MVOL_L ((vuint16_t*)(A_PS1_SPU_MVOL_L)) +#define R_PS1_SPU_MVOL_R ((vuint16_t*)(A_PS1_SPU_MVOL_R)) + +#define R_PS1_SPU_REVERB_L ((vuint16_t*)(A_PS1_SPU_REVERB_L)) +#define R_PS1_SPU_REVERB_R ((vuint16_t*)(A_PS1_SPU_REVERB_R)) + +#define R_PS1_SPU_KEY_ON1 ((vuint16_t*)(A_PS1_SPU_KEY_ON1)) +#define R_PS1_SPU_KEY_ON2 ((vuint16_t*)(A_PS1_SPU_KEY_ON2)) + +#define R_PS1_SPU_KEY_OFF1 ((vuint16_t*)(A_PS1_SPU_KEY_OFF1)) +#define R_PS1_SPU_KEY_OFF2 ((vuint16_t*)(A_PS1_SPU_KEY_OFF2)) + +#define R_PS1_SPU_KEY_MODEFM1 ((vuint16_t*)(A_PS1_SPU_KEY_MODEFM1)) +#define R_PS1_SPU_KEY_MODEFM2 ((vuint16_t*)(A_PS1_SPU_KEY_MODEFM2)) + +#define R_PS1_SPU_KEY_MODENOISE1 ((vuint16_t*)(A_PS1_SPU_KEY_MODENOISE1)) +#define R_PS1_SPU_KEY_MODENOISE2 ((vuint16_t*)(A_PS1_SPU_KEY_MODENOISE2)) + +#define R_PS1_SPU_KEY_MODEREVERB1 ((vuint16_t*)(A_PS1_SPU_KEY_MODEREVERB1)) +#define R_PS1_SPU_KEY_MODEREVERB2 ((vuint16_t*)(A_PS1_SPU_KEY_MODEREVERB2)) + +#define R_PS1_SPU_KEY_CHANNELACTIVE1 ((vuint16_t*)(A_PS1_SPU_KEY_CHANNELACTIVE1)) +#define R_PS1_SPU_KEY_CHANNELACTIVE2 ((vuint16_t*)(A_PS1_SPU_KEY_CHANNELACTIVE2)) + +#define R_PS1_SPU_U_E ((vuint16_t*)(A_PS1_SPU_U_E)) + +#define R_PS1_SPU_SB_ADDR ((vuint16_t*)(A_PS1_SPU_SB_ADDR)) + +#define R_PS1_SPU_DATA ((vuint16_t*)(A_PS1_SPU_DATA)) + +#define R_PS1_SPU_REG0 ((vuint16_t*)(A_PS1_SPU_REG0)) + +#define R_PS1_SPU_REG1 ((vuint16_t*)(A_PS1_SPU_REG1)) +#define R_PS1_SPU_STATUS ((vuint16_t*)(A_PS1_SPU_STATUS)) + +#define R_PS1_SPU_CDMVOL_L ((vuint16_t*)(A_PS1_SPU_CDMVOL_L)) +#define R_PS1_SPU_CDMVOL_R ((vuint16_t*)(A_PS1_SPU_CDMVOL_R)) + +#define R_PS1_SPU_EXTVOL_L ((vuint16_t*)(A_PS1_SPU_EXTVOL_L)) +#define R_PS1_SPU_EXTVOL_R ((vuint16_t*)(A_PS1_SPU_EXTVOL_R)) + +#define R_PS1_SPU_REVERBCONFIG ((vuint16_t*)(A_PS1_SPU_REVERBCONFIG)) + +#define R_PS1_SPU_FACTORLEFT ((vuint16_t*)(A_PS1_SPU_FACTORLEFT)) +#define R_PS1_SPU_FACTORRIGHT ((vuint16_t*)(A_PS1_SPU_FACTORRIGHT)) + +/* DBG is part of the Expansion 2 hardware and is not present in retail consoles */ +#define R_PS1_DBG_R20 ((vuint8_t*)A_PS1_DBG_R20) +#define R_PS1_DBG_R21 ((vuint8_t*)A_PS1_DBG_R21) +#define R_PS1_DBG_R22 ((vuint8_t*)A_PS1_DBG_R22) +#define R_PS1_DBG_R23 ((vuint8_t*)A_PS1_DBG_R23) +#define R_PS1_DBG_R24 ((vuint8_t*)A_PS1_DBG_R24) +#define R_PS1_DBG_R25 ((vuint8_t*)A_PS1_DBG_R25) +#define R_PS1_DBG_R26 ((vuint8_t*)A_PS1_DBG_R26) +#define R_PS1_DBG_R27 ((vuint8_t*)A_PS1_DBG_R27) +#define R_PS1_DBG_R28 ((vuint8_t*)A_PS1_DBG_R28) +#define R_PS1_DBG_R29 ((vuint8_t*)A_PS1_DBG_R29) +#define R_PS1_DBG_R2A ((vuint8_t*)A_PS1_DBG_R2A) +#define R_PS1_DBG_R2B ((vuint8_t*)A_PS1_DBG_R2B) +#define R_PS1_DBG_R2C ((vuint8_t*)A_PS1_DBG_R2C) +#define R_PS1_DBG_R2D ((vuint8_t*)A_PS1_DBG_R2D) +#define R_PS1_DBG_R2E ((vuint8_t*)A_PS1_DBG_R2E) +#define R_PS1_DBG_R2F ((vuint8_t*)A_PS1_DBG_R2F) +#define R_PS1_DBG_R30 ((vuint8_t*)A_PS1_DBG_R30) +#define R_PS1_DBG_DIPS ((vuint8_t*)A_PS1_DBG_DIPS) +#define R_PS1_DBG_R41 ((vuint8_t*)A_PS1_DBG_R41) +#define R_PS1_DBG_R42 ((vuint8_t*)A_PS1_DBG_R42) +#define R_PS1_DBG_R43 ((vuint8_t*)A_PS1_DBG_R43) + +// Bits for DMA CHCR(Channel Control) Registers +// FIXME: properly define bits 0, 9, 10 and 24 +#define PS1_CHCR_BIT0 (1 << 0) +#define PS1_CHCR_BIT9 (1 << 9) +#define PS1_CHCR_BIT10 (1 << 10) +#define PS1_CHCR_BIT24 (1 << 24) + +// Bits for GPU Status register +// FIXME: properly define bits 28, 29 and 30 +#define PS1_GPU_IDLE (1 << 26) +#define PS1_GPU_BIT28 (1 << 28) +#define PS1_GPU_BIT29 (1 << 29) +#define PS1_GPU_BIT30 (1 << 30) + +#ifdef __cplusplus +} +#endif + +#endif /* _PS1HWREGS_H */ diff --git a/src/mips/ps1sdk/include/ps1sdk.h b/src/mips/ps1sdk/include/ps1sdk.h new file mode 100644 index 000000000..683d07dd2 --- /dev/null +++ b/src/mips/ps1sdk/include/ps1sdk.h @@ -0,0 +1,342 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# Main header for the PlayStation 1 SDK +# +*/ + +#ifndef _LIBPS1_H +#define _LIBPS1_H + +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +enum { EV_DESC_MASK = 0xFF000000 }; + +enum { + EV_DESC_HW = 0xF0000000, + EV_DESC_EV = 0xF1000000, + EV_DESC_RC = 0xF2000000, + EV_DESC_USR = 0xF3000000, + EV_DESC_SW = 0xF4000000, + EV_DESC_TH = 0xFF000000 +}; + +/* Hardware Events */ +enum { + EVD_HW_VBLANK = 0xF0000001, + EVD_HW_GPU = 0xF0000002, + EVD_HW_CDROM = 0xF0000003, + EVD_HW_DMAC = 0xF0000004, + EVD_HW_RTC0 = 0xF0000005, + EVD_HW_RTC1 = 0xF0000006, + EVD_HW_RTC2 = 0xF0000007, + EVD_HW_PAD = 0xF0000008, + EVD_HW_SPU = 0xF0000009, + EVD_HW_PIO = 0xF000000A, + EVD_HW_SIO = 0xF000000B, + EVD_HW_CPU = 0xF0000010, + EVD_HW_CARD = 0xF0000011, + EVD_HW_CARD_0 = 0xF0000012, + EVD_HW_CARD_1 = 0xF0000013 +}; + +/* Software Events */ +enum { + EVD_SW_CARD = 0xF4000001, // memcard + EVD_SW_MATH = 0xF4000002, // math +}; + +// Root Counter Events +enum { + EVD_RC_CNT0 = 0xF2000000, // display pixel + EVD_RC_CNT1 = 0xF2000001, // horizontal sync + EVD_RC_CNT2 = 0xF2000002, // 1/8 system clock + EVD_RC_CNT3 = 0xF2000003 // VBlank +}; + +enum { + EVSP_COUNT_Z = 0x0001, /* counter becomes zero */ + EVSP_INTR = 0x0002, /* interrupted */ + EVSP_IO_ERR = 0x0004, /* end of i/o */ + EVSP_FCLOSE = 0x0008, /* file was closed */ + EVSP_CMD_ACK = 0x0010, /* command acknowledged */ + EVSP_CMD_COMP = 0x0020, /* command completed */ + EVSP_DATA_RDY = 0x0040, /* data ready */ + EVSP_DATA_END = 0x0080, /* data end */ + EVSP_TIMEOUT = 0x0100, /* time out */ + EVSP_UNKNOWN = 0x0200, /* unknown command */ + EVSP_DOM_ERR = 0x0301, /* domain error in libmath */ + EVSP_RANGE_ERR = 0x0302, /* range error in libmath */ + EVSP_IO_END_R = 0x0400, /* end of read buffer */ + EVSP_IO_END_W = 0x0800, /* end of write buffer */ + EVSP_TRAP = 0x1000, /* general interrupt */ + EVSP_NEW_DEV = 0x2000, /* new device */ + EVSP_SYSCALL = 0x4000, /* system call instruction */ + EVSP_ERROR = 0x8000, /* error happened */ + EVSP_PREV_ERR = 0x8001, /* previous write error happened */ +}; + +// Event Modes +enum { + EVENT_MODE_INTR = 0x1000, // interrupt + EVENT_MODE_NOINTR = 0x2000 // no interrupt +}; + +// Event Status +enum { + EVST_UNUSED = 0x0000, // unused event + EVST_WAIT = 0x1000, // waiting + EVST_ACTIVE = 0x2000, // active + EVST_ALREADY = 0x4000 // already occurred +}; + +// Task Modes +enum { + TASK_MODE_RT = 0x1000, // real-time + TASK_MODE_PRI = 0x2000 // priority +}; + +// Task Status +enum { + TASK_STAT_UNUSED = 0x1000, // unused + TASK_STAT_ACTIVE = 0x4000, // active +}; + +/* Table Info */ +// alias "struct ToT" +/* sizeof() == 0x08(8) */ +typedef struct TableInfo_st { + uint32_t *head; + int32_t size; +} TableInfo_t; + +typedef struct st_Queue { + void* head; + void* tail; +} Queue; + +// sizeof() == 0x30(48) +typedef struct st_EntryInt { + uint32_t ret; // 0x00 + uint32_t r_sp; // 0x04 + uint32_t r_fp; // 0x08 + uint32_t r_s0; // 0x0C + uint32_t r_s1; // 0x10 + uint32_t r_s2; // 0x14 + uint32_t r_s3; // 0x18 + uint32_t r_s4; // 0x1C + uint32_t r_s5; // 0x20 + uint32_t r_s6; // 0x24 + uint32_t r_s7; // 0x28 + uint32_t r_gp; // 0x2C +} EntryInt; + +// sizeof() == 0xA0(160) +typedef struct IntrHandlerRegFrame_st +{ + uint32_t r_zero; // 0x00 + uint32_t r_at; // 0x04 + uint32_t r_v0; // 0x08 + uint32_t r_v1; // 0x0C + + uint32_t r_a0; // 0x10 + uint32_t r_a1; // 0x14 + uint32_t r_a2; // 0x18 + uint32_t r_a3; // 0x1C + + uint32_t r_t0; // 0x20 + uint32_t r_t1; // 0x24 + uint32_t r_t2; // 0x28 + uint32_t r_t3; // 0x2C + + uint32_t r_t4; // 0x30 + uint32_t r_t5; // 0x34 + uint32_t r_t6; // 0x38 + uint32_t r_t7; // 0x3C + + uint32_t r_s0; // 0x40 + uint32_t r_s1; // 0x44 + uint32_t r_s2; // 0x48 + uint32_t r_s3; // 0x4C + + uint32_t r_s4; // 0x50 + uint32_t r_s5; // 0x54 + uint32_t r_s6; // 0x58 + uint32_t r_s7; // 0x5C + + uint32_t r_t8; // 0x60 + uint32_t r_t9; // 0x64 + uint32_t r_k0; // 0x68 + uint32_t r_k1; // 0x6C + + uint32_t r_gp; // 0x70 + uint32_t r_sp; // 0x74 + uint32_t r_fp; // 0x78 + uint32_t r_ra; // 0x7C + + uint32_t r_pc; // 0x80 + uint32_t r_hi; // 0x84 + uint32_t r_lo; // 0x88 + uint32_t r_c0_status; // 0x8C + + uint32_t r_c0_cause; // 0x90 + uint32_t r_unk94; // 0x94 + uint32_t r_unk98; // 0x98 + uint32_t r_unk9C; // 0x9C +} IntrHandlerRegFrame; + +/* Task Control Block(TaskCB) */ +/* alias "struct TCB" */ +/* sizeof() == 0xC0(192) */ +typedef struct TaskCB_st { + uint32_t status; // 0x00 + uint32_t mode; // 0x04 + IntrHandlerRegFrame regs; // 0x08-0x9B + uint32_t system[6]; // 0xA8-0xBF +} TaskCB_t; + +// alias "struct TCBH" +typedef struct TCBH_st +{ + TaskCB_t *entry; + int32_t flag; +} TCBH_t; + +/* Event Control Block(EventCB) */ +/* alias "struct EvCB" */ +/* sizeof() == 0x1C(28) */ +typedef struct st_EventCB { + uint32_t desc; // 0x00-0x03 + int32_t status; // 0x04-0x07 + int32_t spec; // 0x08-0x0B + int32_t mode; // 0x0C-0x0F + int32_t (*handler)(); // 0x10-0x13 + int32_t system[2]; // 0x14-0x1B +} EventCB; + +/* Interrupt Control Block(IntrCB) */ +/* sizeof() == 0x10(16) */ +typedef struct st_IntrCB { + struct st_IntrCB* next; // 0x00 - set by SysEnqIntr + uint32_t (*func1)(int); // 0x04 - called if "func0" returns non-zero. Can be NULL. + uint32_t (*func0)(int); // 0x08 - called first. Should return 0 if "func1" should be called. + uint32_t __pad; // 0x0C - unused +} IntrCB; + +// sizeof() == 0x0C(12) +typedef struct st_SystemConf { + int tcb; // 0x00 + int event; // 0x04 + uint32_t stack; // 0x08 +} SystemConf; + +void* malloc(uint32_t size); +void* calloc(uint32_t size); +void free(void* p); + +/* Kernel API calls */ + +extern void* SysMalloc(size_t size); + +extern void SystemError(uint8_t type, uint32_t code); + +// Install and init the ISO9660 device driver. +// Return: ??? +extern int __96_init(void); + +// remove the ISO9660 device driver. +// Return: ??? +extern int __96_remove(void); + +// test if a file is a valid PS-X EXE. +// The ExecInfo structure from the file header +// is loaded into "exec". +// Return: 1 on success, 0 on failure. +extern int LoadTest(const char* filename, ExecInfo* exec); + +// Execute the application described in "exec". +// Return: 1 +extern int Exec(ExecInfo* exec, uint32_t stack_addr, uint32_t stack_size); + +// Load the executable file "filename" into memory. +// The ExecInfo structure from the file header +// is loaded into "exec". +// Return: 1 on success, 0 on failure. +extern int Load(const char* filename, ExecInfo* exec); + +// Load the executable file "filename" into memory and execute it. +// Return: 1 on success, 0 on failure. +int LoadExec(const char* filename, uint32_t stack_addr, uint32_t stack_size); + +// Get the current system configuration information. +void GetConf(int* event_p, int* tcb_p, uint32_t* stack_p); + +// Set the system configuration information. +void SetConf(int event, int tcb, uint32_t stack); + +void KernelRedirect(int tty_mode); +// AddCONSOLEDevice +void AddDummyConsoleDevice(); + +int _cdevscan(void); + +void _exit_A0_58(int status); + +/* Kernel System calls */ +extern void Exception(void); +extern void EnterCriticalSection(void); +extern void ExitCriticalSection(void); + +uint32_t* GetB0Table(void); +uint32_t* GetC0Table(void); + +/* Non-native functions */ + +// initialize the system. Only needed when the BIOS system init +// has been bypassed, for example by hooking the PIO device "startup" +// entry point. +int SystemInit(void); + +// Boot the CD-ROM currently inserted in the drive. +// Skips PS1 logo display and additional disc checks. +// Call with "1" if __96_init() has previously been called. +int FastBootDisc(int rem96); + +// pad/controller +int PAD_init(uint32_t type, void* buf); +int PAD_dr(void); +int InitPAD(void* buf1, int len1, void* buf2, int len2); + +void FlushCache(void); + +void delay_ms(uint32_t n); + +// macros + +#define M_TO_SYS_ID(__addr) (((uint32_t)__addr) >> 2) +#define M_FROM_SYS_ID(__id) (((uint32_t)__id) << 2) + +// suspend/resume interrupts +#define M_SUSPEND_INTR(__state_ptr) \ + { \ + *(__state_ptr) = GetCOP0_STATUS(); \ + SetCOP0_STATUS(*(__state_ptr)&0xFFFFFFFE); \ + *(__state_ptr) &= 1; \ + } +#define M_RESUME_INTR(__state_ptr) \ + { SetCOP0_STATUS((*(__state_ptr)&1) | (GetCOP0_STATUS() & 0xFFFFFFFE)); } + +#ifdef __cplusplus +} +#endif + +#endif /* _LIBPS1_H */ diff --git a/src/mips/ps1sdk/include/pstypes.h b/src/mips/ps1sdk/include/pstypes.h new file mode 100644 index 000000000..18b2c8ec5 --- /dev/null +++ b/src/mips/ps1sdk/include/pstypes.h @@ -0,0 +1,37 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# Type definitions for PS1. +# +*/ + +#ifndef _PSTYPES_H +#define _PSTYPES_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef _PSTYPES_DEFINED +#define _PSTYPES_DEFINED + +typedef unsigned char uint8_t; +typedef unsigned short uint16_t; +typedef unsigned int uint32_t; + +typedef volatile unsigned char vuint8_t; +typedef volatile unsigned short vuint16_t; +typedef volatile unsigned int vuint32_t; + +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _PSTYPES_H */ diff --git a/src/mips/ps1sdk/include/serialio.h b/src/mips/ps1sdk/include/serialio.h new file mode 100644 index 000000000..c2a62f172 --- /dev/null +++ b/src/mips/ps1sdk/include/serialio.h @@ -0,0 +1,173 @@ +/* + * File: serialio.h + * Author: asmblur + * + * Created on February 10, 2009, 1:13 AM + * Reversed on September 2, 2019 + */ + +#ifndef _SERIALIO_H +#define _SERIALIO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Definitions: + * + * DTE(Data Terminal Equiptment): a PC/PS/etc(Not a modem) + * DCE(Data Communications Equiptment): a modem + * + * RTS-CTS flow control: + * RTS/RTR: Request To Send/Ready To Receive, assert to indicate readiness to receive data + * CTS: Clear To Send, input from RTR of other. + * + * DTR: Data Terminal Ready, assert to indicate readiness to communicate + * DSR: Data Set Ready, input from DTR of other + * + * + * + * + */ + +// bits for STATUS +// SIO Interrupt Pending +#define SIO_STAT_IRQ 0x0200 +#define SIO_STAT_CTS 0x0100 +#define SIO_STAT_DSR 0x0080 +#define SIO_STAT_SYNC_DET 0x0040 +#define SIO_STAT_FRAME_ERR 0x0020 +#define SIO_STAT_RX_OVRN_ERR 0x0010 +#define SIO_STAT_PARITY_ERR 0x0008 +#define SIO_STAT_TX_EMPTY 0x0004 +#define SIO_STAT_RX_RDY 0x0002 +#define SIO_STAT_TX_RDY 0x0001 +#define SIO_STAT_MASK (0x03FF) + +// bits for CONTROL + +// enable DSR interrupts. +#define SIO_CTRL_DSRI_EN 0x1000 +// enable RXD interrupts. +#define SIO_CTRL_RXI_EN 0x0800 +// enable TXD interrupts. +#define SIO_CTRL_TXI_EN 0x0400 +#define SIO_CTRL_BUF8 0x0300 +#define SIO_CTRL_BUF4 0x0200 +#define SIO_CTRL_BUF2 0x0100 +#define SIO_CTRL_BUF1 0x0000 +// why is there nothing for bit 7? CTRL_BUFx is bits 9-10 +#define SIO_CTRL_RESET_INT 0x0040 +// enable RTS driver(inverted) +#define SIO_CTRL_RTS_EN 0x0020 +#define SIO_CTRL_RTR_EN 0x0020 +#define SIO_CTRL_RESET_ERR 0x0010 +#define SIO_CTRL_BRK 0x0008 +// enable RXD +#define SIO_CTRL_RX_EN 0x0004 +// enable DTR driver(inverted) +#define SIO_CTRL_DTR_EN 0x0002 +// enable TXD +#define SIO_CTRL_TX_EN 0x0001 +#define SIO_CTRL_MASK (0x1FFF) + +/* + * SIO1 + * Pins go from left to right + * + * NOTE: All pins except for RXD, TXD, GND and 3V3 are inverted. + * + * Pin Name Dir Notes + * ----- ----- --- ---------- + * 1 RXD I Receive Data + * 2 3V3 3.3V output + * 3 DSR I Data Set Ready + * 4 TXD O Transmit Data + * 5 CTS O Clear To Send + * 6 DTR I Data Terminal Ready + * 7 GND Ground + * 8 RTS O Request To Send + */ + +// Bits for MODE + +// MODE: Stop Bits +// bits 6-7 +#define SIO_MODE_SB_1 0x0040 +#define SIO_MODE_SB_1_5 0x0080 +#define SIO_MODE_SB_2 0x00C0 + +// MODE: Parity +// bits 4-5 +#define SIO_MODE_P_NONE 0x0000 +#define SIO_MODE_P_ODD 0x0010 +#define SIO_MODE_P_EVEN 0x0030 + +// MODE: Character Length(Bits Per Character) +// bits 2-3 +#define SIO_MODE_CHLEN_5 0x0000 +#define SIO_MODE_CHLEN_6 0x0004 +#define SIO_MODE_CHLEN_7 0x0008 +#define SIO_MODE_CHLEN_8 0x000C + +// MODE: Baud Rate multiplier(??) +// NOTE: supposedly these 2 bits should always be "10"(2).. +// bits 0-1 +#define SIO_MODE_BR_1 0x0001 +#define SIO_MODE_BR_16 0x0002 +#define SIO_MODE_BR_64 0x0003 + +#define SIO_MODE_MASK 0x00FF + +/* prototypes */ + +int sio_peek8(uint32_t timeout); +uint32_t sio_peek32(uint32_t timeout); +uint16_t sio_peek16(uint32_t timeout); + +int sio_poke8(uint8_t data, uint32_t timeout); +int sio_poke16(uint16_t data, uint32_t timeout); +int sio_poke32(uint32_t data, uint32_t timeout); + +void sio_reset(void); +void sio_clear_error(void); +void sio_reset_driver(void); +void init_sio(uint32_t baud); + +uint8_t sio_get_byte(void); +void sio_put_byte(uint8_t d); + +//~ void sio_init(int port_no, int baud); + +//~ int sio_reset(int port_no); +//~ int sio_reset_fifos(int port_no); + +//~ int sio_set_baud(int port_no, int baud); + +//~ int sio_get_byte(int port_no); +//~ int sio_put_byte(int port_no, uint8_t data, uint32_t timeout); + +//~ uint8_t sio_peek_data(int port_no); +//~ void sio_poke_data(int port_no, uint8_t data); + +//~ uint16_t sio_peek_status(int port_no); +//~ void sio_poke_status(int port_no, uint16_t status); + +//~ uint16_t sio_peek_mode(int port_no); +//~ void sio_poke_mode(int port_no, uint16_t mode); + +//~ uint16_t sio_peek_ctrl(int port_no); +//~ void sio_poke_ctrl(int port_no, uint16_t ctrl); + +//~ uint16_t sio_peek_baud(int port_no); +//~ void sio_poke_baud(int port_no, uint16_t baud); + +// TTY stuff(uses SIO1) +int sio_putchar(char ch); + +#ifdef __cplusplus +} +#endif + +#endif /* _SERIALIO_H */ diff --git a/src/mips/ps1sdk/include/setjmp.h b/src/mips/ps1sdk/include/setjmp.h new file mode 100644 index 000000000..6129ca291 --- /dev/null +++ b/src/mips/ps1sdk/include/setjmp.h @@ -0,0 +1,40 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# ANSI C "setjmp.h" for PS1. +# +*/ + +#ifndef _SETJMP_H +#define _SETJMP_H + +#ifdef __cplusplus +extern "C" { +#endif + +typedef struct st_jmp_buf { + void* r_ra; // 0x00 + void* r_sp; // 0x04 + void* r_fp; // 0x08 + void* r_s0; // 0x0C + void* r_s1; // 0x10 + void* r_s2; // 0x14 + void* r_s3; // 0x18 + void* r_s4; // 0x1C + void* r_s5; // 0x20 + void* r_s6; // 0x24 + void* r_s7; // 0x28 + void* r_gp; // 0x2C +} jmp_buf; + +int setjmp(jmp_buf env); +void longjmp(jmp_buf env, int val); + +#ifdef __cplusplus +} +#endif + +#endif /* _SETJMP_H */ diff --git a/src/mips/ps1sdk/include/stdarg.h b/src/mips/ps1sdk/include/stdarg.h new file mode 100644 index 000000000..b37e174c8 --- /dev/null +++ b/src/mips/ps1sdk/include/stdarg.h @@ -0,0 +1,33 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# ANSI C "stdarg.h" for PS1. +# +*/ + +#ifndef _STDARG_H +#define _STDARG_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define __va_rounded_size(T) (((sizeof(T) + sizeof(int) - 1) / sizeof(int)) * sizeof(int)) + +#define va_arg(ap, T) \ + (ap = (va_list)((char*)(ap) + __va_rounded_size(T)), *((T*)(void*)((char*)(ap)-__va_rounded_size(T)))) + +#define va_start(ap, last_arg) (ap = ((char*)&(last_arg) + __va_rounded_size(last_arg))) + +#define va_end(ap) ___ap = (char*)NULL + +typedef void* va_list; + +#ifdef __cplusplus +} +#endif + +#endif /* _STDARG_H */ diff --git a/src/mips/ps1sdk/include/stddef.h b/src/mips/ps1sdk/include/stddef.h new file mode 100644 index 000000000..69c860eb3 --- /dev/null +++ b/src/mips/ps1sdk/include/stddef.h @@ -0,0 +1,32 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# ANSI C "stddef.h" for PS1. +# +*/ + +#ifndef _STDDEF_H +#define _STDDEF_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NULL +#define NULL ((void*)0) +#endif + +#define offsetof(type, member) __builtin_offsetof(type, member) + +typedef int ptrdiff_t; +typedef unsigned long wchar_t; +typedef unsigned int size_t; + +#ifdef __cplusplus +} +#endif + +#endif /* _STDDEF_H */ diff --git a/src/mips/ps1sdk/include/stdio.h b/src/mips/ps1sdk/include/stdio.h new file mode 100644 index 000000000..b17d9f5da --- /dev/null +++ b/src/mips/ps1sdk/include/stdio.h @@ -0,0 +1,62 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# ANSI C "stdio.h" for PS1. +# +*/ + +#ifndef _STDIO_H +#define _STDIO_H + +#include +#include "stddef.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define BUFSIZ 1024 +#define EOF (-1) + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +int open(const char*, uint32_t); +int close(int); +int lseek(int, int, int); +int read(int, void*, int); +int write(int, const void*, int); +int ioctl(int, int, int); + +int remove(const char* path); +int undelete(const char* path); +int format(const char* path); +int rename(const char* oldname, const char* newname); + +int printf(const char* fmt, ...); +int sprintf(char* buffer, const char* fmt, ...); + +char getc(int); +char getchar(void); +char* gets(char*); +void putc(char, int); +void putchar(char); +void puts(const char*); + +#ifdef __cplusplus +} +#endif + +#endif /* _STDIO_H */ diff --git a/src/mips/ps1sdk/include/string.h b/src/mips/ps1sdk/include/string.h new file mode 100644 index 000000000..63af05876 --- /dev/null +++ b/src/mips/ps1sdk/include/string.h @@ -0,0 +1,47 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# ANSI C "string.h" for PS1. +# +*/ + +#ifndef _STRING_H +#define _STRING_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +void* memcpy(void* dest, const void* src, size_t n); +void* memmove(void* dest, const void* src, size_t n); +void* memchr(const void* s, char c, size_t n); +int memcmp(const void* s1, const void* s2, size_t n); +void* memset(void*, int, size_t); +char* strcat(char* dest, const char* src); +char* strncat(char*, const char*, size_t); +char* strchr(const char*, int); +char* strrchr(const char*, int); +int strcmp(const char*, const char*); +int strncmp(const char*, const char*, size_t); +int strcoll(const char*, const char*); +char* strcpy(char* toHere, const char* fromHere); +char* strncpy(char* toHere, const char* fromHere, size_t); +char* strerror(int); +size_t strlen(const char*); +size_t strspn(const char* s, const char* accept); +size_t strcspn(const char* s, const char* reject); +char* strpbrk(const char* s, const char* accept); +char* strstr(const char* haystack, const char* needle); +char* strtok(char*, const char*); +size_t strxfrm(char* dest, const char* src, size_t n); + +#ifdef __cplusplus +} +#endif + +#endif /* _STRING_H */ diff --git a/src/mips/ps1sdk/include/strings.h b/src/mips/ps1sdk/include/strings.h new file mode 100644 index 000000000..4fece9be1 --- /dev/null +++ b/src/mips/ps1sdk/include/strings.h @@ -0,0 +1,33 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# ANSI C "strings.h" for PS1. +# +*/ + +#ifndef _STRINGS_H +#define _STRINGS_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +int bcmp(const void*, const void*, size_t); +void bcopy(const void*, void*, size_t); +void bzero(void*, size_t); +int ffs(int); +char* index(const char*, int); +char* rindex(const char*, int); +int strcasecmp(const char*, const char*); +int strncasecmp(const char*, const char*, size_t); + +#ifdef __cplusplus +} +#endif + +#endif /* _STRINGS_H */ diff --git a/src/mips/ps1sdk/include/sys/errno.h b/src/mips/ps1sdk/include/sys/errno.h new file mode 100644 index 000000000..489c2d590 --- /dev/null +++ b/src/mips/ps1sdk/include/sys/errno.h @@ -0,0 +1,109 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# ANSI C "errno.h" for PS1. +# +*/ + +#ifndef _ERRNO_H +#define _ERRNO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* PS1 only */ +#define ENOTBLK 15 /* Block device required */ +#define EFORMAT 31 /* Bad file format */ + +/* ANSI C */ +#define E2BIG 7 /* Argument list too long. */ +#define EACCES 13 /* Permission denied. */ +#define EAGAIN 11 /* Resource unavailable, try again. */ +#define EALREADY 37 /* Connection already in progress. */ +#define EBADF 9 /* Bad file descriptor. */ +#define EBUSY 16 /* Device or resource busy. */ +#define ECHILD 10 /* No child processes. */ +#define EDOM 33 /* Mathematics argument out of domain of function. */ +#define EEXIST 17 /* File exists. */ +#define EFAULT 14 /* Bad address. */ +#define EFBIG 27 /* File too large. */ +#define EINPROGRESS 36 /* Operation in progress. */ +#define EINTR 4 /* Interrupted function. */ +#define EINVAL 22 /* Invalid argument. */ +#define EIO 5 /* I/O error. */ +#define EISDIR 21 /* Is a directory. */ +#define EMFILE 24 /* File descriptor value too large. */ +#define ENFILE 23 /* Too many files open in system. */ +#define ENODEV 19 /* No such device. */ +#define ENOENT 2 /* No such file or directory. */ +#define ENOEXEC 8 /* Executable file format error. */ +#define ENOMEM 12 /* Not enough space. */ +#define ENOSPC 28 /* No space left on device. */ +#define ENOTDIR 20 /* Not a directory. */ +#define ENOTTY 25 /* Inappropriate I/O control operation. */ +#define ENXIO 6 /* No such device or address. */ +#define EPERM 1 /* Operation not permitted. */ +#define EPIPE 32 /* Broken pipe. */ +#define ERANGE 34 /* Result too large. */ +#define EROFS 30 /* Read-only file system. */ +#define ESPIPE 29 /* Invalid seek. */ +#define ESRCH 3 /* No such process. */ +#define ETXTBSY 26 /* Text file busy. */ +#define EWOULDBLOCK 35 /* Operation would block. */ +#define EXDEV 18 /* Cross-device link. */ + +#if 0 +#define EPERM 1 /* Operation not permitted */ +#define ENOENT 2 /* No such file or directory */ +#define ESRCH 3 /* No such process */ +#define EINTR 4 /* Interrupted system call */ +#define EIO 5 /* Input/output error */ +#define ENXIO 6 /* Device not configured */ +#define E2BIG 7 /* Argument list too long */ +#define ENOEXEC 8 /* Exec format error */ +#define EBADF 9 /* Bad file descriptor */ +#define ECHILD 10 /* No child processes */ +#define EAGAIN 11 /* No more processes */ +#define ENOMEM 12 /* Cannot allocate memory */ +#define EACCES 13 /* Permission denied */ +#define EFAULT 14 /* Bad address */ +#define ENOTBLK 15 /* Block device required */ +#define EBUSY 16 /* Device busy */ +#define EEXIST 17 /* File exists */ +#define EXDEV 18 /* Cross-device link */ +#define ENODEV 19 /* Operation not supported by device */ +#define ENOTDIR 20 /* Not a directory */ +#define EISDIR 21 /* Is a directory */ +#define EINVAL 22 /* Invalid argument */ +#define ENFILE 23 /* Too many open files in system */ +#define EMFILE 24 /* Too many open files */ +#define ENOTTY 25 /* Inappropriate ioctl for device */ +#define ETXTBSY 26 /* Text file busy */ +#define EFBIG 27 /* File too large */ +#define ENOSPC 28 /* No space left on device */ +#define ESPIPE 29 /* Illegal seek */ +#define EROFS 30 /* Read-only file system */ +#define EMLINK 31 /* Too many links */ +#define EPIPE 32 /* Broken pipe */ + +/* math software */ +#define EDOM 33 /* Numerical argument out of domain */ +#define ERANGE 34 /* Result too large */ + +/* non-blocking and interrupt i/o */ +#define EWOULDBLOCK 35 /* Operation would block */ +#define EINPROGRESS 36 /* Operation now in progress */ +#define EALREADY 37 /* Operation already in progress */ +#endif + +extern int errno; /* global error number */ + +#ifdef __cplusplus +} +#endif + +#endif /* _ERRNO_H */ diff --git a/src/mips/ps1sdk/include/sys/fcntl.h b/src/mips/ps1sdk/include/sys/fcntl.h new file mode 100644 index 000000000..740e4003d --- /dev/null +++ b/src/mips/ps1sdk/include/sys/fcntl.h @@ -0,0 +1,93 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# "fcntl.h" for PS1. +# +*/ + +#ifndef _FCNTL_H +#define _FCNTL_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Values for cmd used by fcntl(): */ + +#if 0 +UNSUPPORTED +#define F_DUPFD 0x0000 /* Duplicate file descriptor. */ +#define F_GETFD 0x0000 /* Get file descriptor flags. */ +#define F_SETFD 0x0000 /* Set file descriptor flags. */ +#define F_GETFL 0x0000 /* Get file status flags and file access modes. */ +#define F_SETFL 0x0000 /* Set file status flags. */ +#define F_GETLK 0x0000 /* Get record locking information. */ +#define F_SETLK 0x0000 /* Set record locking information. */ +#define F_SETLKW 0x0000 /* Set record locking information; wait if blocked. */ +#endif + +/* File creation flags for open(): */ +#if 0 +UNSUPPORTED +#define O_EXCL 0x0000 /* Exclusive use flag. */ +#endif +#if 0 +UNSUPPORTED +#define O_NOCTTY 0x0000 /* Do not assign controlling terminal. */ +#endif +#define O_CREAT 0x0200 /* Create file if it does not exist. */ +#define O_TRUNC 0x0400 /* Truncate flag. */ + +/* File status flags used for open() and fcntl(): */ +#define O_APPEND 0x0100 /* Set append mode. */ +#define O_NONBLOCK 0x0004 /* Non-blocking mode. */ +#define O_SYNC 0x0000 /* Write according to synchronized I/O file integrity completion. */ + +/* PS1-specific file status flags used for open() and fcntl(): */ +#define O_SCAN 0x1000 /* Scan type */ +#define O_RCOM 0x2000 /* Remote command entry */ +#define O_NBUF 0x4000 /* No ring buffer and console interrupt */ +#define O_NOWAIT 0x8000 /* Asynchronous I/O mode */ + +/* File access modes used for open() and fcntl() */ +#define O_RDONLY 0x0001 /* Open for reading only. */ +#define O_WRONLY 0x0002 /* Open for writing only. */ +#define O_RDWR (O_RDONLY | O_WRONLY) /* Open for reading and writing. */ + +/* Mask for use with file access modes */ +#define O_ACCMODE (O_RDONLY | O_WRONLY) + +/* File descriptor flags used for fcntl(): */ +#if 0 +UNSUPPORTED +#define FD_CLOEXEC 0x0000 /* Close the file descriptor upon execution of an exec family function. */ +#endif + +/* Values for l_type used for record locking with fcntl() */ +#if 0 +UNSUPPORTED +#define F_UNLCK 0x0000 /* Unlock. */ +#define F_RDLCK 0x0010 /* Shared or read lock. */ +#define F_WRLCK 0x0020 /* Exclusive or write lock. */ +#endif + +#ifndef SEEK_SET +#define SEEK_SET 0 +#endif + +#ifndef SEEK_CUR +#define SEEK_CUR 1 +#endif + +#ifndef SEEK_END +#define SEEK_END 2 +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _FCNTL_H */ diff --git a/src/mips/ps1sdk/include/sys/types.h b/src/mips/ps1sdk/include/sys/types.h new file mode 100644 index 000000000..4256fff2e --- /dev/null +++ b/src/mips/ps1sdk/include/sys/types.h @@ -0,0 +1,87 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# Type definitions for PS1. +# +*/ +#ifndef _TYPES_H_ +#define _TYPES_H_ + +#ifndef _UCHAR_T +#define _UCHAR_T +typedef unsigned char u_char; +#endif // !_UCHAR_T +#ifndef _USHORT_T +#define _USHORT_T +typedef unsigned short u_short; +#endif // !_USHORT_T +#ifndef _UINT_T +#define _UINT_T +typedef unsigned int u_int; +#endif // !_UINT_T +#ifndef _ULONG_T +#define _ULONG_T +typedef unsigned long u_long; +#endif // !_ULONG_T + +#ifndef _DEV_T +#define _DEV_T +typedef short dev_t; /* device number */ +#endif // !_DEV_T + +#ifndef _OFF_T +#define _OFF_T +typedef long off_t; /* file offset (should be a quad) */ +#endif // !_OFF_T + +#ifndef _UID_T +#define _UID_T +typedef u_short uid_t; /* user id */ +#endif // !_UID_T + +#ifndef _gid_T +#define _gid_T +typedef u_short gid_t; /* group id */ +#endif // !_GID_T + +#ifndef _OFF_T +#define _OFF_T +typedef long off_t; /* file offset (should be a quad) */ +#endif // !_OFF_T + +#ifndef _PID_T +#define _PID_T +typedef short pid_t; /* process id */ +#endif // !_PID_T + +#ifndef _MODE_T +#define _MODE_T +typedef u_short mode_t; /* permissions */ +#endif // !_MODE_T + +#ifndef _SIZE_T +#define _SIZE_T +typedef unsigned int size_t; +#endif // !_SIZE_T + +#ifdef _TIME_T +#define _TIME_T +typedef long time_t; +#endif // !_TIME_T + +#ifndef NBBY +#define NBBY 8 /* number of bits in a byte */ +#endif // !NBBY + +#define major(x) ((int)(((u_int)(x) >> 8)&0xff)) /* major number */ +#define minor(x) ((int)((x)&0xff)) /* minor number */ +#define makedev(x,y) ((dev_t)(((x)<<8) | (y))) /* create dev_t */ + +#ifdef __cplusplus +} +#endif + +#endif /* _TYPES_H */ diff --git a/src/mips/ps1sdk/include/tty.h b/src/mips/ps1sdk/include/tty.h new file mode 100644 index 000000000..bd3889df4 --- /dev/null +++ b/src/mips/ps1sdk/include/tty.h @@ -0,0 +1,32 @@ +/* + * File: tty.h + * Author: asmblur + * + */ + +#ifndef _TTY_H +#define _TTY_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* prototypes */ + +int init_tty(void); + +// NOTE: you probably don't want to use the rest of these. Instead, you should use the kernel putchar and such. +int DelTTY(void); +int tty_unhook_putchar(void); +int tty_hook_putchar(void); +int tty_putchar(char ch); +void tty_print32(uint32_t d); +void tty_print16(uint16_t d); +void tty_print8(uint8_t d); +void tty_puts(const char *s); + +#ifdef __cplusplus +} +#endif + +#endif /* _TTY_H */ diff --git a/src/mips/ps1sdk/include/unistd.h b/src/mips/ps1sdk/include/unistd.h new file mode 100644 index 000000000..48824fb80 --- /dev/null +++ b/src/mips/ps1sdk/include/unistd.h @@ -0,0 +1,30 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# "unistd.h" for PS1. +# +*/ + +#ifndef _FILEIO_H +#define _FILEIO_H + +#include "types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#ifndef NULL +#define NULL ((void*)0) +#endif + +int chdir(const char* path); + +#ifdef __cplusplus +} +#endif + +#endif /* _FILEIO_H */ diff --git a/src/mips/ps1sdk/include/xmodem.h b/src/mips/ps1sdk/include/xmodem.h new file mode 100644 index 000000000..93a8527bf --- /dev/null +++ b/src/mips/ps1sdk/include/xmodem.h @@ -0,0 +1,34 @@ +#ifndef _XMODEM_H +#define _XMODEM_H + +#include "sys/types.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define MAX_XM_SEND_RETRY 10 + +#define XM_SOH 1 + +#define XM_STX 2 +// end of transfer +#define XM_EOT 4 +// acknowledge +#define XM_ACK 6 +// negative acknowledge +#define XM_NAK 21 +// cancel +#define XM_CAN 24 + +typedef int (*PeekFunc)(uint8_t* ch, int timeout); +typedef int (*PokeFunc)(uint8_t ch, int timeout); + +int xmodem_recv(PeekFunc peek, PokeFunc poke, int use_crc16, void* dest, int max, int timeout); +int xmodem_send(PeekFunc peek, PokeFunc poke, int use_1k, void* src, int len, int timeout); + +#ifdef __cplusplus +} +#endif + +#endif /* _XMODEM_H */ diff --git a/src/mips/ps1sdk/src/ar12comms.c b/src/mips/ps1sdk/src/ar12comms.c new file mode 100644 index 000000000..2f71afc68 --- /dev/null +++ b/src/mips/ps1sdk/src/ar12comms.c @@ -0,0 +1,108 @@ +/* + * + * PS1 Action Replay/GameShark v1 and v2 communications library. + * + */ +#include + +uint8_t AR12_exchange8(uint8_t d) +{ + uint8_t rv; + while((*AR12_STATUS & 0x01) == 0); + rv = *AR12_RXD; + *AR12_TXD = d; + return rv; +} + +uint16_t AR12_exchange16(uint16_t d) +{ + uint16_t rv; + rv = ((AR12_exchange8((d >> 8) & 0xFF) << 8) | + (AR12_exchange8(d & 0xFF) << 0)); + return rv; +} + +uint32_t AR12_exchange32(uint32_t d) +{ + uint32_t rv; + rv = ((AR12_exchange16((d >> 16) & 0xFFFF) << 16) | + (AR12_exchange16(d & 0xFFFF) << 0)); + return rv; +} + +uint8_t AR12_read8(void) +{ + uint8_t rv; + while((*AR12_STATUS & 0x01) == 0); + rv = *AR12_RXD; + *AR12_TXD = rv; + return rv; +} + +uint16_t AR12_read16(void) +{ + uint16_t rv; + rv = ((AR12_read8() << 8) | + (AR12_read8() << 0)); + return rv; +} + +uint32_t AR12_read32(void) +{ + uint32_t rv; + rv = ((AR12_read16() << 16) | + (AR12_read16() << 0)); + return rv; +} + +void processComms(void) +{ + int i; + uint8_t cmd; + + if(*AR12_RXD != 'W') return; + + while(AR12_exchange8('R') != 'W'); + while(AR12_exchange8('W') != 'B'); + cmd = AR12_read8(); + switch(cmd) + { + case 'U': // Upload + case 'X': // eXecute + { + addr = AR12_read32(); + len = AR12_read32(); + for(i = 0; i < len; i++) + { + d = AR12_read8(); + ((uint8_t *) (addr))[i] = d; + csum += d; + } + + if(AR12_read16() != (csum & 0xFFFF)) + { + AR12_exchange16(0x4243); // "BC" + break; + } + + old_sr = GetC0_SR(); + SetC0_SR(old_sr & 0xFFFFFFFC); // disable interrupts and put kernel in user mode? + + AR12_exchange16(0x4F4B); // "OK" + if(cmd == 'X') + { + (*((void(**)()) addr))(); + AR12_exchange16(0x4F4B); // "BF" + } + + SetC0_SR(old_sr); + + break; + } + default: + { + AR12_exchange16(0x4258); // "BX" + break; + } + } +} diff --git a/src/mips/ps1sdk/src/bkunpack.s b/src/mips/ps1sdk/src/bkunpack.s new file mode 100644 index 000000000..9b6fcaf7d --- /dev/null +++ b/src/mips/ps1sdk/src/bkunpack.s @@ -0,0 +1,167 @@ +; ByteKiller decrunch code for PSX by Silpheed of Hitmen + +; BK_Decrunch +; a0 - src +; a1 - dest + + +BK_Decrunch move t9, ra + move t0, a0 + lw t2, (a0) + move t1, a1 + lw t3, 4(a0) + addu t2,t2,t1 + addu t0,t0,t3 + subiu t0,t0,4 + lw t3, (t0) + +BK_mainloop jal BK_getnextbit + nop + + beq zero,v0,BK_part2 + nop + + jal BK_readbits + li a0, 2 + + slti t4, v0, 2 + beq zero,t4,BK_skip1 + nop + + addiu a0,v0,9 + jal BK_dodupl + addiu a1,v0,2 + + b BK_endloop + nop + +BK_skip1 subiu t4,v0,3 + bne zero,t4,BK_skip2 + nop + + li a0, 8 + jal BK_dojmp + li a1, 8 + + b BK_endloop + nop + +BK_skip2 jal BK_readbits + li a0, 8 + + move a1,v0 + jal BK_dodupl + li a0, 12 + + b BK_endloop + nop +BK_part2 + jal BK_getnextbit + nop + + beq zero,v0,BK_skip3 + nop + + li a0, 8 + jal BK_dodupl + li a1, 1 + + b BK_endloop + nop + +BK_skip3 li a0, 3 + jal BK_dojmp + move a1, zero + +BK_endloop bne t2,t1,BK_mainloop + nop + + jr ra + move ra, t9 + + +BK_getnextbit andi v0,t3,1 + srl t3,t3,1 + bne zero,t3,BK_gnbend + nop + + subiu t0,t0,4 + lw t3, (t0) + nop + andi v0,t3,1 + srl t3,t3,1 + lui t5, $8000 + or t3,t3,t5 + +BK_gnbend jr ra + nop + + +BK_readbits move v1, zero + move t8,ra +BK_rbloop beq zero,a0,BK_rbend + nop + + subiu a0,a0,1 + + jal BK_getnextbit + sll v1,v1,1 + or v1,v1,v0 + + b BK_rbloop + nop + +BK_rbend move v0,v1 + jr ra + move ra,t8 + + +BK_dojmp move t7, ra + jal BK_readbits + nop + + addu t4,v0,a1 + addiu t4,t4,1 + +BK_djloop beq zero,t4,BK_djend + nop + + subiu t4,t4,1 + + li a0, 8 + jal BK_readbits + subiu t2,t2,1 + + sb v0, (t2) + nop + + b BK_djloop + nop + +BK_djend jr ra + move ra, t7 + + +BK_dodupl move t7, ra + jal BK_readbits + addiu a1,a1,1 + +BK_ddloop beq zero,a1,BK_ddend + nop + + subiu a1,a1,1 + + subiu t2,t2,1 + addu t4,t2,v0 + lb t4, (t4) + nop + sb t4, (t2) + nop + + b BK_ddloop + nop + +BK_ddend jr ra + move ra, t7 + + diff --git a/src/mips/ps1sdk/src/debug.c b/src/mips/ps1sdk/src/debug.c new file mode 100644 index 000000000..a0a14c621 --- /dev/null +++ b/src/mips/ps1sdk/src/debug.c @@ -0,0 +1,52 @@ +#define C0_BPC $3 +#define C0_BDA $5 +#define C0_DCIC $7 +#define C0_BADVADDR $8 +#define C0_BDAM $9 +#define C0_BPCM $11 +#define C0_STATUS $12 +#define C0_CAUSE $13 +#define C0_EPC $14 +#define C0_PRID $15 + +// set a breakpoint on data access +// addr: The address to trigger on. +// addr_mask: The mask used when comparing addresses. +// ctrl - bitmask of access types to trigger on. +// C0_DCIC_DR: Data Read +// C0_DCIC_DW: Data Write +void dbg_set_bpda(uint32_t addr, uint32_t addr_mask, uint32_t ctrl) +{ + register uint32_t cur_DCIC; + + cur_dcic = C0_get_DCIC(); // get the current value of DCIC + C0_set_DCIC(0); // set DCIC to 0 temporarily to ensure all breakpoints are disabled. + + C0_set_BDA(addr & addr_mask); // set BDA with the address on which to set the breakpoint. + C0_set_BDAM(addr_mask); // set BDAM with the address mask used to determine which bits to compare in the address. + + cur_DCIC &= ~(C0_DCIC_DR | C0_DCIC_DW); // clear the Data Read and Data Write bits. + + cur_DCIC |= (C0_DCIC_TR | C0_DCIC_DAE | C0_DCIC_DE); // set the "Trap", "Data Access" and "Debug" enable bits. + cur_DCIC |= ctrl & (C0_DCIC_DR | C0_DCIC_DW); + C0_set_DCIC(cur_DCIC); +} + +// set a breakpoint on program counter +// addr: The address to trigger on. +// addr_mask: The mask used when comparing addresses. +void dbg_set_bppc(uint32_t addr, uint32_t addr_mask) +{ + register uint32_t cur_DCIC; + + cur_dcic = C0_get_DCIC(); // get the current value of DCIC + C0_set_DCIC(0); // set DCIC to 0 temporarily to ensure all breakpoints are disabled. + + C0_set_BPC(addr & addr_mask); // set BDA with the address on which to set the breakpoint. + C0_set_BPCM(addr_mask); // set BDAM with the address mask used to determine which bits to compare in the address. + + cur_DCIC |= (C0_DCIC_TR | C0_DCIC_PCE | C0_DCIC_DE); // set the "Trap", "Program Counter" and "Debug" enable bits. + cur_DCIC |= C0_DCIC_DR; + C0_set_DCIC(cur_DCIC); +} + diff --git a/src/mips/ps1sdk/src/helpers.c b/src/mips/ps1sdk/src/helpers.c new file mode 100644 index 000000000..ee741ccc0 --- /dev/null +++ b/src/mips/ps1sdk/src/helpers.c @@ -0,0 +1,25 @@ +#include +#include + +/* accessors for getting and setting COP0 registers */ +uint32_t C0_get_BPC(void) { register uint32_t rv; __asm__ __volatile__("mfc0 %0, $3" : "=&r" (rv)); return rv; } +uint32_t C0_get_BDA(void) { register uint32_t rv; __asm__ __volatile__("mfc0 %0, $5" : "=&r" (rv)); return rv; } +uint32_t C0_get_DCIC(void) { register uint32_t rv; __asm__ __volatile__("mfc0 %0, $7" : "=&r" (rv)); return rv; } +uint32_t C0_get_BADVADDR(void) { register uint32_t rv; __asm__ __volatile__("mfc0 %0, $8" : "=&r" (rv)); return rv; } +uint32_t C0_get_BDAM(void) { register uint32_t rv; __asm__ __volatile__("mfc0 %0, $9" : "=&r" (rv)); return rv; } +uint32_t C0_get_BPCM(void) { register uint32_t rv; __asm__ __volatile__("mfc0 %0, $11" : "=&r" (rv)); return rv; } +uint32_t C0_get_STATUS(void) { register uint32_t rv; __asm__ __volatile__("mfc0 %0, $12" : "=&r" (rv)); return rv; } +uint32_t C0_get_CAUSE(void) { register uint32_t rv; __asm__ __volatile__("mfc0 %0, $13" : "=&r" (rv)); return rv; } +uint32_t C0_get_EPC(void) { register uint32_t rv; __asm__ __volatile__("mfc0 %0, $14" : "=&r" (rv)); return rv; } +uint32_t C0_get_PRID(void) { register uint32_t rv; __asm__ __volatile__("mfc0 %0, $15" : "=&r" (rv)); return rv; } + +void C0_set_BPC(uint32_t v) { __asm__ __volatile__("mtc0 %0, $3" : : "r" (v)); } +void C0_set_BDA(uint32_t v) { __asm__ __volatile__("mtc0 %0, $5" : : "r" (v)); } +void C0_set_DCIC(uint32_t v) { __asm__ __volatile__("mtc0 %0, $7" : : "r" (v)); } +void C0_set_BADVADDR(uint32_t v) { __asm__ __volatile__("mtc0 %0, $8" : : "r" (v)); } +void C0_set_BDAM(uint32_t v) { __asm__ __volatile__("mtc0 %0, $9" : : "r" (v)); } +void C0_set_BPCM(uint32_t v) { __asm__ __volatile__("mtc0 %0, $11" : : "r" (v)); } +void C0_set_STATUS(uint32_t v) { __asm__ __volatile__("mtc0 %0, $12" : : "r" (v)); } +void C0_set_CAUSE(uint32_t v) { __asm__ __volatile__("mtc0 %0, $13" : : "r" (v)); } +void C0_set_EPC(uint32_t v) { __asm__ __volatile__("mtc0 %0, $14" : : "r" (v)); } +void C0_set_PRID(uint32_t v) { __asm__ __volatile__("mtc0 %0, $15" : : "r" (v)); } diff --git a/src/mips/ps1sdk/src/syscalls.S b/src/mips/ps1sdk/src/syscalls.S new file mode 100644 index 000000000..17cf34570 --- /dev/null +++ b/src/mips/ps1sdk/src/syscalls.S @@ -0,0 +1,327 @@ +.set push +.set noreorder +.set noat + +#include + +.text + +.macro M_KCALL, label, tablenum, callnum +.global \label +.type \label, @function +.ent \label +\label: + li t1, \tablenum + jr t1 + li t0, \callnum +.end \label +.endm + +.macro M_SYSCALL, label, callNum +.global \label +.type \label, @function +.ent \label +\label: + li a0, \callNum + syscall 0 + jr ra + nop +.end \label +.endm + +.macro M_BREAK, label, code +.global \label +.type \label, @function +.ent \label +\label: + break \code + jr ra + nop +.end \label +.endm + +/* this will only be accurate if interrupts are disabled */ +.global delay_ms +.type delay_ms, @function +.ent delay_ms +delay_ms: + li t0, 1665 +_delay_ms_l2: + bnez t0, _delay_ms_l2 + addiu t0, -1 + bnez a0, delay_ms + addiu a0, -1 + jr ra + nop +.end delay_ms + +M_KCALL open, 0xA0, 0x0000 +M_KCALL lseek, 0xA0, 0x0001 +M_KCALL read, 0xA0, 0x0002 +M_KCALL write, 0xA0, 0x0003 +M_KCALL close, 0xA0, 0x0004 +M_KCALL ioctl, 0xA0, 0x0005 +M_KCALL exit, 0xA0, 0x0006 +M_KCALL sys_b0_39, 0xA0, 0x0007 +M_KCALL getc, 0xA0, 0x0008 +M_KCALL putc, 0xA0, 0x0009 +M_KCALL todigit, 0xA0, 0x000a +M_KCALL atof, 0xA0, 0x000b +M_KCALL strtoul, 0xA0, 0x000c +M_KCALL strtol, 0xA0, 0x000d +M_KCALL abs, 0xA0, 0x000e +M_KCALL fabs, 0xA0, 0x000f +M_KCALL atoi, 0xA0, 0x0010 +M_KCALL atol, 0xA0, 0x0011 +M_KCALL atob, 0xA0, 0x0012 +M_KCALL setjmp, 0xA0, 0x0013 +M_KCALL longjmp, 0xA0, 0x0014 +M_KCALL strcat, 0xA0, 0x0015 +M_KCALL strncat, 0xA0, 0x0016 +M_KCALL strcmp, 0xA0, 0x0017 +M_KCALL strncmp, 0xA0, 0x0018 +M_KCALL strcpy, 0xA0, 0x0019 +M_KCALL strncpy, 0xA0, 0x001a +M_KCALL strlen, 0xA0, 0x001b +M_KCALL index, 0xA0, 0x001c +M_KCALL rindex, 0xA0, 0x001d +M_KCALL strchr, 0xA0, 0x001e +M_KCALL strrchr, 0xA0, 0x001f +M_KCALL strpbrk, 0xA0, 0x0020 +M_KCALL strspn, 0xA0, 0x0021 +M_KCALL strcspn, 0xA0, 0x0022 +M_KCALL strtok, 0xA0, 0x0023 +M_KCALL strstr, 0xA0, 0x0024 +M_KCALL toupper, 0xA0, 0x0025 +M_KCALL tolower, 0xA0, 0x0026 +M_KCALL bcopy, 0xA0, 0x0027 +M_KCALL bzero, 0xA0, 0x0028 +M_KCALL bcmp, 0xA0, 0x0029 +M_KCALL memcpy, 0xA0, 0x002a +M_KCALL memset, 0xA0, 0x002b +M_KCALL memmove, 0xA0, 0x002c +M_KCALL memcmp, 0xA0, 0x002d +M_KCALL memchr, 0xA0, 0x002e +M_KCALL rand, 0xA0, 0x002f +M_KCALL srand, 0xA0, 0x0030 +M_KCALL qsort, 0xA0, 0x0031 +M_KCALL strtod, 0xA0, 0x0032 +M_KCALL malloc, 0xA0, 0x0033 +M_KCALL free, 0xA0, 0x0034 +M_KCALL lsearch, 0xA0, 0x0035 +M_KCALL bsearch, 0xA0, 0x0036 +M_KCALL calloc, 0xA0, 0x0037 +M_KCALL realloc, 0xA0, 0x0038 +M_KCALL InitHeap, 0xA0, 0x0039 +M_KCALL _exit_A0_58, 0xA0, 0x003a +M_KCALL getchar, 0xA0, 0x003b +M_KCALL putchar, 0xA0, 0x003c +M_KCALL gets, 0xA0, 0x003d +M_KCALL puts, 0xA0, 0x003e +M_KCALL printf, 0xA0, 0x003f +M_KCALL LoadTest, 0xA0, 0x0041 +M_KCALL Load, 0xA0, 0x0042 +M_KCALL Exec, 0xA0, 0x0043 +M_KCALL FlushCache, 0xA0, 0x0044 +M_KCALL InstallInterruptDispatch, 0xA0, 0x0045 +M_KCALL GPU_dw, 0xA0, 0x0046 +M_KCALL GPU_mem2vram, 0xA0, 0x0047 +M_KCALL SetGPUStatus, 0xA0, 0x0048 +M_KCALL GPU_cw, 0xA0, 0x0049 +M_KCALL GPU_cwb, 0xA0, 0x004a +M_KCALL GPU_SendPackets, 0xA0, 0x004B +M_KCALL GPU_abort, 0xA0, 0x004C +M_KCALL GetGPUStatus, 0xA0, 0x004d +M_KCALL GPU_sync, 0xA0, 0x004e +M_KCALL LoadExec, 0xA0, 0x0051 +M_KCALL GetSysSp, 0xA0, 0x0052 +M_KCALL _96_init, 0xA0, 0x0054 +M_KCALL _bu_init, 0xA0, 0x0055 +M_KCALL _96_remove, 0xA0, 0x0056 +M_KCALL dev_tty_init, 0xA0, 0x005b +M_KCALL dev_tty_open, 0xA0, 0x005c +M_KCALL dev_tty_strategy, 0xA0, 0x005D +M_KCALL dev_tty_ioctl, 0xA0, 0x005e +M_KCALL dev_cd_open, 0xA0, 0x005f +M_KCALL dev_cd_read, 0xA0, 0x0060 +M_KCALL dev_cd_close, 0xA0, 0x0061 +M_KCALL dev_cd_firstfile, 0xA0, 0x0062 +M_KCALL dev_cd_nextfile, 0xA0, 0x0063 +M_KCALL dev_cd_chdir, 0xA0, 0x0064 +M_KCALL dev_card_open, 0xA0, 0x0065 +M_KCALL dev_card_read, 0xA0, 0x0066 +M_KCALL dev_card_write, 0xA0, 0x0067 +M_KCALL dev_card_close, 0xA0, 0x0068 +M_KCALL dev_card_firstfile, 0xA0, 0x0069 +M_KCALL dev_card_nextfile, 0xA0, 0x006a +M_KCALL dev_card_erase, 0xA0, 0x006b +M_KCALL dev_card_undelete, 0xA0, 0x006c +M_KCALL dev_card_format, 0xA0, 0x006d +M_KCALL dev_card_rename, 0xA0, 0x006e +M_KCALL dev_card_call111, 0xA0, 0x006F +/* M_KCALL _bu_init, 0xA0, 0x0070 + M_KCALL _96_init, 0xA0, 0x0071 + M_KCALL _96_remove, 0xA0, 0x0072 +*/ +M_KCALL _96_CdSeekL, 0xA0, 0x0078 +M_KCALL _96_CdGetStatus, 0xA0, 0x007c +M_KCALL _96_CdRead, 0xA0, 0x007e +M_KCALL _96_SetMode, 0xA0, 0x0081 +M_KCALL _96_CdStop, 0xA0, 0x0085 +M_KCALL _kcallA0_144, 0xA0, 0x0090 +M_KCALL _kcallA0_145, 0xA0, 0x0091 +M_KCALL _kcallA0_146, 0xA0, 0x0092 +M_KCALL _kcallA0_147, 0xA0, 0x0093 +M_KCALL _kcallA0_148, 0xA0, 0x0094 +M_KCALL _kcallA0_149, 0xA0, 0x0095 +M_KCALL AddCDROMDevice, 0xA0, 0x0096 +M_KCALL AddMemCardDevice, 0xA0, 0x0097 +M_KCALL AddDEBUGCONDevice, 0xA0, 0x0098 +// aka add_nullcon_driver and AddConsoleDevice +M_KCALL AddDummyConsoleDevice, 0xA0, 0x0099 +M_KCALL SetConf, 0xA0, 0x009c +M_KCALL GetConf, 0xA0, 0x009d +M_KCALL _kcallA0_158, 0xA0, 0x009E +M_KCALL SetMem, 0xA0, 0x009f +M_KCALL _boot, 0xA0, 0x00A0 +M_KCALL SystemError, 0xA0, 0x00a1 +M_KCALL EnqCdIntr, 0xA0, 0x00a2 +M_KCALL DeqCdIntr, 0xA0, 0x00a3 +M_KCALL _96_call_A0_164, 0xA0, 0x00A4 +M_KCALL ReadSector, 0xA0, 0x00a5 +M_KCALL IsCdOpen, 0xA0, 0x00a6 +M_KCALL bufs_cb_0, 0xA0, 0x00a7 +M_KCALL bufs_cb_1, 0xA0, 0x00a8 +M_KCALL bufs_cb_2, 0xA0, 0x00a9 +M_KCALL bufs_cb_3, 0xA0, 0x00aa +M_KCALL _card_info, 0xA0, 0x00ab +M_KCALL _card_load, 0xA0, 0x00ac +M_KCALL _card_auto, 0xA0, 0x00ad +M_KCALL bufs_cb_4, 0xA0, 0x00ae +M_KCALL _card_call175, 0xA0, 0x00AF +M_KCALL do_longjmp, 0xA0, 0x00b2 +M_KCALL GetKernelInfo, 0xA0, 0x00b4 +M_KCALL _SysMalloc, 0xB0, 0x0000 +M_KCALL SysFree, 0xB0, 1 +M_KCALL SetRCnt, 0xB0, 2 +M_KCALL GetRCnt, 0xB0, 3 +M_KCALL StartRCnt, 0xB0, 4 +M_KCALL StopRCnt, 0xB0, 5 +M_KCALL ResetRCnt, 0xB0, 6 +M_KCALL DeliverEvent, 0xB0, 0x0007 +M_KCALL OpenEvent, 0xB0, 0x0008 +M_KCALL CloseEvent, 0xB0, 0x0009 +M_KCALL WaitEvent, 0xB0, 0x000a +M_KCALL TestEvent, 0xB0, 0x000b +M_KCALL EnableEvent, 0xB0, 0x000c +M_KCALL DisableEvent, 0xB0, 0x000d +M_KCALL OpenTh, 0xB0, 0x000e +M_KCALL CloseTh, 0xB0, 0x000f +M_KCALL ChangeTh, 0xB0, 0x0010 +M_KCALL InitPAD, 0xB0, 0x0012 +M_KCALL StartPAD, 0xB0, 0x0013 +M_KCALL StopPAD, 0xB0, 0x0014 +M_KCALL PAD_init, 0xB0, 0x0015 +M_KCALL PAD_dr, 0xB0, 0x0016 +M_KCALL ReturnFromException, 0xB0, 0x0017 +M_KCALL ResetEntryInt, 0xB0, 0x0018 +M_KCALL HookEntryInt, 0xB0, 0x0019 +M_KCALL UnDeliverEvent, 0xB0, 0x0020 +M_KCALL _open, 0xB0, 0x0032 +M_KCALL _lseek, 0xB0, 0x0033 +M_KCALL _read, 0xB0, 0x0034 +M_KCALL _write, 0xB0, 0x0035 +M_KCALL _close, 0xB0, 0x0036 +M_KCALL _ioctl, 0xB0, 0x0037 +M_KCALL _exit, 0xB0, 0x0038 +M_KCALL _is_a_tty, 0xB0, 0x0039 +M_KCALL _getc, 0xB0, 0x003A +M_KCALL _putc, 0xB0, 0x003B +M_KCALL _getchar, 0xB0, 0x003C +M_KCALL _putchar, 0xB0, 0x003D +M_KCALL _gets, 0xB0, 0x003E +M_KCALL _puts, 0xB0, 0x003F +M_KCALL _chdir, 0xB0, 0x0040 +M_KCALL _format, 0xB0, 0x0041 +M_KCALL firstfile, 0xB0, 0x0042 +M_KCALL nextfile, 0xB0, 0x0043 +M_KCALL rename, 0xB0, 0x0044 +/* alias delete */ +M_KCALL remove, 0xB0, 0x0045 +M_KCALL undelete, 0xB0, 0x0046 +/* Alias AddDrv */ +M_KCALL AddDevice, 0xB0, 0x0047 +/* Alias DelDrv */ +M_KCALL DelDevice, 0xB0, 0x0048 +M_KCALL PrintInstalledDevices, 0xB0, 0x0049 +M_KCALL InitCARD, 0xB0, 0x004a +M_KCALL StartCARD, 0xB0, 0x004b +M_KCALL StopCARD, 0xB0, 0x004c +M_KCALL _card_callB0_77, 0xB0, 0x004D +M_KCALL _card_write, 0xB0, 0x004e +M_KCALL _card_read, 0xB0, 0x004f +M_KCALL _new_card, 0xB0, 0x0050 +M_KCALL Krom2RawAdd, 0xB0, 0x0051 +M_KCALL _kcallB0_83, 0xB0, 0x0053 +M_KCALL _get_errno, 0xB0, 0x0054 +M_KCALL _get_error, 0xB0, 0x0055 +M_KCALL GetC0Table, 0xB0, 0x0056 +M_KCALL GetB0Table, 0xB0, 0x0057 +M_KCALL _card_chan, 0xB0, 0x0058 +M_KCALL iocall_B0_89, 0xB0, 0x0059 +M_KCALL ChangeClearPad, 0xB0, 0x005b +M_KCALL _card_status, 0xB0, 0x005c +M_KCALL _card_wait, 0xB0, 0x005d +M_KCALL InitRCnt, 0xC0, 0x0000 +M_KCALL InitException, 0xC0, 0x0001 +M_KCALL SysEnqIntRP, 0xC0, 0x0002 +M_KCALL SysDeqIntRP, 0xC0, 0x0003 +M_KCALL get_free_event_slot, 0xC0, 0x0004 +M_KCALL get_free_TCB_slot, 0xC0, 0x0005 +M_KCALL ExceptionHandler, 0xC0, 0x0006 +M_KCALL InstallExceptionHandlers, 0xC0, 0x0007 +M_KCALL SysInitMemory, 0xC0, 0x0008 +M_KCALL SysInitKMem, 0xC0, 0x0009 +M_KCALL ChangeClearRCnt, 0xC0, 0x000a +/*M_KCALL SystemError, 0xC0, 0x000b*/ +M_KCALL InitDefInt, 0xC0, 0x000c +M_KCALL SetIrqClearEn, 0xC0, 0xD +M_KCALL InstallDevices, 0xC0, 0x0012 +M_KCALL FlushStdInOut, 0xC0, 0x0013 +M_KCALL GetWord8644, 0xC0, 0x0014 +M_KCALL _cdevinput, 0xC0, 0x0015 +M_KCALL _cdevscan, 0xC0, 0x0016 +M_KCALL _circgetc, 0xC0, 0x0017 +M_KCALL _circputc, 0xC0, 0x0018 +M_KCALL ioabort, 0xC0, 0x0019 +M_KCALL SetWord8644, 0xC0, 0x001A +M_KCALL KernelRedirect, 0xC0, 0x001B +M_KCALL PatchAOTable, 0xC0, 0x001C + +M_SYSCALL Exception, 0 +M_SYSCALL EnterCriticalSection, 1 +M_SYSCALL ExitCriticalSection, 2 + +M_BREAK PCInit, 0x0101 + +.global GetCOP0_STATUS +.type GetCOP0_STATUS, @function +.ent GetCOP0_STATUS +GetCOP0_STATUS: + mfc0 v0, C0_STATUS + nop + jr ra + nop +.end GetCOP0_STATUS + +.global SetCOP0_STATUS +.type SetCOP0_STATUS, @function +.ent SetCOP0_STATUS +SetCOP0_STATUS: + mtc0 a0, C0_STATUS + nop + jr ra + nop +.end SetCOP0_STATUS + +.set pop diff --git a/src/mips/ps1sdk/src/syscalls.json b/src/mips/ps1sdk/src/syscalls.json new file mode 100644 index 000000000..7c30e673c --- /dev/null +++ b/src/mips/ps1sdk/src/syscalls.json @@ -0,0 +1,253 @@ +{ + "kcalls": + { + "0xA0": + { + "0x0000": { "label": "open" }, + "0x0001": { "label": "lseek" }, + "0x0002": { "label": "read" }, + "0x0003": { "label": "write" }, + "0x0004": { "label": "close" }, + "0x0005": { "label": "ioctl" }, + "0x0006": { "label": "exit" }, + "0x0007": { "label": "sys_b0_39" }, + "0x0008": { "label": "getc" }, + "0x0009": { "label": "putc" }, + "0x000A": { "label": "todigit" }, + "0x000B": { "label": "atof" }, + "0x000C": { "label": "strtoul" }, + "0x000D": { "label": "strtol" }, + "0x000E": { "label": "abs" }, + "0x000F": { "label": "fabs" }, + "0x0010": { "label": "atoi" }, + "0x0011": { "label": "atol" }, + "0x0012": { "label": "atob" }, + "0x0013": { "label": "setjmp" }, + "0x0014": { "label": "longjmp" }, + "0x0015": { "label": "strcat" }, + "0x0016": { "label": "strncat" }, + "0x0017": { "label": "strcmp" }, + "0x0018": { "label": "strncmp" }, + "0x0019": { "label": "strcpy" }, + "0x001A": { "label": "strncpy" }, + "0x001B": { "label": "strlen" }, + "0x001C": { "label": "index" }, + "0x001D": { "label": "rindex" }, + "0x001E": { "label": "strchr" }, + "0x001F": { "label": "strrchr" }, + "0x0020": { "label": "strpbrk" }, + "0x0021": { "label": "strspn" }, + "0x0022": { "label": "strcspn" }, + "0x0023": { "label": "strtok" }, + "0x0024": { "label": "strstr" }, + "0x0025": { "label": "toupper" }, + "0x0026": { "label": "tolower" }, + "0x0027": { "label": "bcopy" }, + "0x0028": { "label": "bzero" }, + "0x0029": { "label": "bcmp" }, + "0x002A": { "label": "memcpy" }, + "0x002B": { "label": "memset" }, + "0x002C": { "label": "memmove" }, + "0x002D": { "label": "memcmp" }, + "0x002E": { "label": "memchr" }, + "0x002F": { "label": "rand" }, + "0x0030": { "label": "srand" }, + "0x0031": { "label": "qsort" }, + "0x0032": { "label": "strtod" }, + "0x0033": { "label": "malloc" }, + "0x0034": { "label": "free" }, + "0x0035": { "label": "lsearch" }, + "0x0036": { "label": "bsearch" }, + "0x0037": { "label": "calloc" }, + "0x0038": { "label": "realloc" }, + "0x0039": { "label": "InitHeap" }, + "0x003A": { "label": "_exit_A0_58" }, + "0x003B": { "label": "getchar" }, + "0x003C": { "label": "putchar" }, + "0x003D": { "label": "gets" }, + "0x003E": { "label": "puts" }, + "0x003F": { "label": "printf" }, + "0x0041": { "label": "LoadTest" }, + "0x0042": { "label": "Load" }, + "0x0043": { "label": "Exec" }, + "0x0044": { "label": "FlushCache" }, + "0x0045": { "label": "InstallInterruptDispatch" }, + "0x0046": { "label": "GPU_dw" }, + "0x0047": { "label": "GPU_mem2vram" }, + "0x0048": { "label": "SetGPUStatus" }, + "0x0049": { "label": "GPU_cw" }, + "0x004A": { "label": "GPU_cwb" }, + "0x004B": { "label": "GPU_SendPackets" }, + "0x004C": { "label": "GPU_abort" }, + "0x004D": { "label": "GetGPUStatus" }, + "0x004E": { "label": "GPU_sync" }, + "0x0051": { "label": "LoadExec" }, + "0x0052": { "label": "GetSysSp" }, + "0x0054": { "label": "_96_init" }, + "0x0055": { "label": "_bu_init" }, + "0x0056": { "label": "_96_remove" }, + "0x005B": { "label": "dev_tty_init" }, + "0x005C": { "label": "dev_tty_open" }, + "0x005D": { "label": "dev_tty_strategy" }, + "0x005E": { "label": "dev_tty_ioctl" }, + "0x005F": { "label": "dev_cd_open" }, + "0x0060": { "label": "dev_cd_read" }, + "0x0061": { "label": "dev_cd_close" }, + "0x0062": { "label": "dev_cd_firstfile" }, + "0x0063": { "label": "dev_cd_nextfile" }, + "0x0064": { "label": "dev_cd_chdir" }, + "0x0065": { "label": "dev_card_open" }, + "0x0066": { "label": "dev_card_read" }, + "0x0067": { "label": "dev_card_write" }, + "0x0068": { "label": "dev_card_close" }, + "0x0069": { "label": "dev_card_firstfile" }, + "0x006A": { "label": "dev_card_nextfile" }, + "0x006B": { "label": "dev_card_erase" }, + "0x006C": { "label": "dev_card_undelete" }, + "0x006D": { "label": "dev_card_format" }, + "0x006E": { "label": "dev_card_rename" }, + "0x006F": { "label": "dev_card_call111" }, + "0x0078": { "label": "_96_CdSeekL" }, + "0x007C": { "label": "_96_CdGetStatus" }, + "0x007E": { "label": "_96_CdRead" }, + "0x0081": { "label": "_96_SetMode" }, + "0x0085": { "label": "_96_CdStop" }, + "0x0090": { "label": "_kcallA0_144" }, + "0x0091": { "label": "_kcallA0_145" }, + "0x0092": { "label": "_kcallA0_146" }, + "0x0093": { "label": "_kcallA0_147" }, + "0x0094": { "label": "_kcallA0_148" }, + "0x0095": { "label": "_kcallA0_149" }, + "0x0096": { "label": "AddCDROMDevice" }, + "0x0097": { "label": "AddMemCardDevice" }, + "0x0098": { "label": "AddDEBUGCONDevice" }, + "0x0099": { "label": "AddDummyConsoleDevice" }, + "0x009C": { "label": "SetConf" }, + "0x009D": { "label": "GetConf" }, + "0x009E": { "label": "_kcallA0_158" }, + "0x009F": { "label": "SetMem" }, + "0x00A0": { "label": "_boot" }, + "0x00A1": { "label": "SystemError" }, + "0x00A2": { "label": "EnqCdIntr" }, + "0x00A3": { "label": "DeqCdIntr" }, + "0x00A4": { "label": "_96_call_A0_164" }, + "0x00A5": { "label": "ReadSector" }, + "0x00A6": { "label": "IsCdOpen" }, + "0x00A7": { "label": "bufs_cb_0" }, + "0x00A8": { "label": "bufs_cb_1" }, + "0x00A9": { "label": "bufs_cb_2" }, + "0x00AA": { "label": "bufs_cb_3" }, + "0x00AB": { "label": "_card_info" }, + "0x00AC": { "label": "_card_load" }, + "0x00AD": { "label": "_card_auto" }, + "0x00AE": { "label": "bufs_cb_4" }, + "0x00AF": { "label": "_card_call175" }, + "0x00B2": { "label": "do_longjmp" }, + "0x00B4": { "label": "GetKernelInfo" } + }, + "0xB0": + { + "0x0000": { "label": "_SysMalloc" }, + "0x0001": { "label": "SysFree" }, + "0x0002": { "label": "SetRCnt" }, + "0x0003": { "label": "GetRCnt" }, + "0x0004": { "label": "StartRCnt" }, + "0x0005": { "label": "StopRCnt" }, + "0x0006": { "label": "ResetRCnt" }, + "0x0007": { "label": "DeliverEvent" }, + "0x0008": { "label": "OpenEvent" }, + "0x0009": { "label": "CloseEvent" }, + "0x000A": { "label": "WaitEvent" }, + "0x000B": { "label": "TestEvent" }, + "0x000C": { "label": "EnableEvent" }, + "0x000D": { "label": "DisableEvent" }, + "0x000E": { "label": "OpenTh" }, + "0x000F": { "label": "CloseTh" }, + "0x0010": { "label": "ChangeTh" }, + "0x0012": { "label": "InitPAD" }, + "0x0013": { "label": "StartPAD" }, + "0x0014": { "label": "StopPAD" }, + "0x0015": { "label": "PAD_init" }, + "0x0016": { "label": "PAD_dr" }, + "0x0017": { "label": "ReturnFromException" }, + "0x0018": { "label": "ResetEntryInt" }, + "0x0019": { "label": "HookEntryInt" }, + "0x0020": { "label": "UnDeliverEvent" }, + "0x0032": { "label": "_open" }, + "0x0033": { "label": "_lseek" }, + "0x0034": { "label": "_read" }, + "0x0035": { "label": "_write" }, + "0x0036": { "label": "_close" }, + "0x0037": { "label": "_ioctl" }, + "0x0038": { "label": "_exit" }, + "0x0039": { "label": "_is_a_tty" }, + "0x003A": { "label": "_getc" }, + "0x003B": { "label": "_putc" }, + "0x003C": { "label": "_getchar" }, + "0x003D": { "label": "_putchar" }, + "0x003E": { "label": "_gets" }, + "0x003F": { "label": "_puts" }, + "0x0040": { "label": "_chdir" }, + "0x0041": { "label": "_format" }, + "0x0042": { "label": "firstfile" }, + "0x0043": { "label": "nextfile" }, + "0x0044": { "label": "rename" }, + "0x0045": { "label": "remove" }, + "0x0046": { "label": "undelete" }, + "0x0047": { "label": "AddDevice" }, + "0x0048": { "label": "DelDevice" }, + "0x0049": { "label": "PrintInstalledDevices" }, + "0x004A": { "label": "InitCARD" }, + "0x004B": { "label": "StartCARD" }, + "0x004C": { "label": "StopCARD" }, + "0x004D": { "label": "_card_callB0_77" }, + "0x004E": { "label": "_card_write" }, + "0x004F": { "label": "_card_read" }, + "0x0050": { "label": "_new_card" }, + "0x0051": { "label": "Krom2RawAdd" }, + "0x0053": { "label": "_kcallB0_83" }, + "0x0054": { "label": "_get_errno" }, + "0x0055": { "label": "_get_error" }, + "0x0056": { "label": "GetC0Table" }, + "0x0057": { "label": "GetB0Table" }, + "0x0058": { "label": "_card_chan" }, + "0x0059": { "label": "iocall_B0_89" }, + "0x005B": { "label": "ChangeClearPad" }, + "0x005C": { "label": "_card_status" }, + "0x005D": { "label": "_card_wait" } + }, + "0xC0": + { + "0x0000": { "label": "InitRCnt" }, + "0x0001": { "label": "InitException" }, + "0x0002": { "label": "SysEnqIntRP" }, + "0x0003": { "label": "SysDeqIntRP" }, + "0x0004": { "label": "get_free_event_slot" }, + "0x0005": { "label": "get_free_TCB_slot" }, + "0x0006": { "label": "ExceptionHandler" }, + "0x0007": { "label": "InstallExceptionHandlers" }, + "0x0008": { "label": "SysInitMemory" }, + "0x0009": { "label": "SysInitKMem" }, + "0x000A": { "label": "ChangeClearRCnt" }, + "0x000C": { "label": "InitDefInt" }, + "0x000D": { "label": "SetIrqClearEn" }, + "0x0012": { "label": "InstallDevices" }, + "0x0013": { "label": "FlushStdInOut" }, + "0x0014": { "label": "GetWord8644" }, + "0x0015": { "label": "_cdevinput" }, + "0x0016": { "label": "_cdevscan" }, + "0x0017": { "label": "_circgetc" }, + "0x0018": { "label": "_circputc" }, + "0x0019": { "label": "ioabort" }, + "0x001A": { "label": "SetWord8644" }, + "0x001B": { "label": "KernelRedirect" }, + "0x001C": { "label": "PatchAOTable" }, + }, + "syscalls": + { + "0": { "label": "Exception" }, + "1": { "label": "ExitCriticalSection" }, + "2": { "label": "EnterCriticalSection" }, + } +} + diff --git a/src/mips/ps1sdk/src/sysinit.c b/src/mips/ps1sdk/src/sysinit.c new file mode 100644 index 000000000..b1f046799 --- /dev/null +++ b/src/mips/ps1sdk/src/sysinit.c @@ -0,0 +1,36 @@ +typedef struct ROMCallTable_st +{ + void (*SysInitKMem)(void); + void (*CopyKCallA0Table)(void); + void (*InstallInterruptDispatch)(void); + int (*alloc_something)(int count); + int (*SetEventConfig)(uint32_t evcb); + int (*SetTCBConfig)(uint32_t tcb); + void (*_96_init)(void); + int (*ValidatePIOShell)(void); + void (*ParseSetupFile)(void *raw_cnf, SystemConf *cfg, char *bootFileName); + void (*KernelSetup)(void); + // NOTE: This points to the STUB for the Exec kcall. NOT the "Exec" function itself. + int (*stub_Exec)(ExecInfo* exec, uint32_t stack_addr, uint32_t stack_size); + SystemConf *config; + void (*init_some_events)(void); +} ROMCallTable; + +void SystemInit(int rem96) +{ + +} +.text:00000028 lhu date_code, 0xBFC00102 +.text:00000030 li $v1, 8 +.text:00000034 andi date_code, 0xFFFF +.text:00000038 move x, $zero +.text:0000003C +.text:0000003C _l1: # CODE XREF: SystemInit+54↓j +.text:0000003C sll $a1, x, 1 # a1 = i * 2 +.text:00000040 sll x, 3 # x *= 8 +.text:00000044 srl $a0, date_code, 28 +.text:00000048 addu x, $a1, x +.text:0000004C addiu $v1, -1 +.text:00000050 addu x, $a0, x +.text:00000054 bnez $v1, _l1 +.text:00000058 sll date_code, 4 diff --git a/src/mips/ps1sdk/src/vblank_handler.c b/src/mips/ps1sdk/src/vblank_handler.c new file mode 100644 index 000000000..d3036ef7b --- /dev/null +++ b/src/mips/ps1sdk/src/vblank_handler.c @@ -0,0 +1,59 @@ +/* + * VBlank interrupt handler example. Adds a vblank interrupt handler and prints + * the count of vblanks that occur to the console. + * + * This is basically a port of VBLANK.ASM which has the following copyright: + * "copyright 1999 by Doomed/Padua." + * + * Doomed deserves all the credit and more. + * + */ +#include + +static uint32_t Vblank_handler(void); + +static volatile uint32_t vblank_count = 0; +static IntrCB vblank_icb = { 0, NULL, &Vblank_handler }; + +static uint32_t Vblank_handler(void) +{ + if(!(*R_PS1_I_MASK & IRQ_VBLANK)) return 0; + if(!(*R_PS1_I_STAT & IRQ_VBLANK)) return 0; + +/* +;## If you are using other Vblank stuff as well (cards/pads etc..) you should +;## not acknowledge the vblank, as this handler gets called first.. (que 0, +;## the vsync handler used by the pads etc is in que 2). So define USING_PADS +;## in that case. (Also make sure you init those before this handler.) +*/ + +#ifdef USING_PADS + *R_PS1_I_STAT ^= IRQ_VBLANK; // clear VBLANK IRQ pending +#endif + + vblank_count++; + + return 0; +} + +int main(void) +{ + uint32_t prev_count = 0; + printf("\r\nVertical blank example. 1999\x2C doomed/padua\r\n"); + + EnterCriticalSection(); // suspend interrupts + SysEnqIntrp(0, &Vblank_handler); // add our handler to queue 0(highest priority) + *R_PS1_I_MASK |= IRQ_VBLANK; // enable the VBLANK IRQ + ExitCriticalSection(); // resume interrupts + + while(1) + { + // wait for vblank_count to change + while(vblank_count == prev_count); + // keep track of vblank count + prev_count = vblank_count; + printf("VBlank Count: %8x/%d", prev_count, prev_count); + } + + return 0; +} diff --git a/src/mips/pshittyload/Makefile b/src/mips/pshittyload/Makefile new file mode 100644 index 000000000..cee2a6f0a --- /dev/null +++ b/src/mips/pshittyload/Makefile @@ -0,0 +1,18 @@ +TARGET = pshittyload.bin +TLOAD_ADDR = 0x80030000 +SRCS = \ + crt0/crt0.S \ + src/main.c \ + src/pshittysio.c \ + src/exec.S \ + src/flash.c \ + src/syscalls.S + +LIBS = + +LDSCRIPT = ../shell/shell.ld +CPPFLAGS := -Isrc -Iinclude -I../ps1sdk/include +LDFLAGS := + +include ../common.mk + diff --git a/src/mips/pshittyload/crt0/crt0.S b/src/mips/pshittyload/crt0/crt0.S new file mode 100644 index 000000000..6ec5f9a0e --- /dev/null +++ b/src/mips/pshittyload/crt0/crt0.S @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include + +.set push +.set noreorder +.set noat + + .section .start, "ax", @progbits + .align 2 + .global main + .global _start + .type _start, @function +.ent _start +_start: + li a0, 0 + j main + li a1, 0 +.end _start +.set pop diff --git a/src/mips/pshittyload/include/exec.h b/src/mips/pshittyload/include/exec.h new file mode 100644 index 000000000..f81bfaf9e --- /dev/null +++ b/src/mips/pshittyload/include/exec.h @@ -0,0 +1,57 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# "exec.h" for PS1. +# +*/ + +#ifndef _EXEC_H +#define _EXEC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Executable file types returned by LoadEx() */ +enum { ExecTypeUNK = 0, ExecTypePSX = 1, ExecTypeSCE = 2, ExecTypeECO = 3, ExecTypeCPE = 4 }; + +// sizeof() == 0x3C(60) +typedef struct st_ExecInfo { + uint32_t entry; // 0x00 : Address of program entry-point. + uint32_t init_gp; // 0x04 : SCE only. Initial value the "gp" register is set to. 0 for PS-X EXE. + uint32_t text_addr; // 0x08 : Memory address to which the .text section is loaded. + uint32_t text_size; // 0x0C : Size of the .text section in the file and memory. + uint32_t data_addr; // 0x10 : SCE only. Memory address to which the .data section is loaded. 0 for PS-X EXE. + uint32_t data_size; // 0x14 : SCE only. Size of the .data section in the file and memory. 0 for PS-X EXE. + uint32_t bss_addr; // 0x18 : Memory address of the .bss section. .bss is initialized by Exec(). + uint32_t bss_size; // 0x1C : Size of the .bss section in memory. + uint32_t stack_addr; // 0x20 : Memory address pointing to the bottom(lowest address) of the stack. BIOS replaces + // with "STACK" parameter of "SYSTEM.CNF" file. + uint32_t stack_size; // 0x24 : Size of the stack. Can be 0. + uint32_t saved_sp; // 0x28 : Used by BIOS Exec() function to preserve the "sp" register. + uint32_t saved_fp; // 0x2C : Used by BIOS Exec() function to preserve the "fp" register. + uint32_t saved_gp; // 0x30 : Used by BIOS Exec() function to preserve the "gp" register. + uint32_t saved_ra; // 0x34 : Used by BIOS Exec() function to preserve the "ra" register. + uint32_t saved_s0; // 0x38 : Used by BIOS Exec() function to preserve the "s0" register. +} ExecInfo; + +// sizeof() == 0x88(136) +typedef struct st_EXE_Header { + uint8_t magic[8]; // 0x00-0x07 : "PS-X EXE"(retail) or "SCE EXE"(???) + uint32_t text_off; // 0x08 : SCE only. Offset of the start of the .text section in the file. 0 for PS-X EXE. + uint32_t data_off; // 0x0C : SCE only. Offset of the start of the .text section in the file. 0 for PS-X EXE. + struct st_ExecInfo exec; // 0x10-0x4B + char license[60]; // 0x4C-0x87 + uint8_t __pad[1912]; // 0x88-0x7FF +} EXE_Header; + +int Exec2(ExecInfo* exec, uint32_t arg0, uint32_t arg1); + +#ifdef __cplusplus +} +#endif + +#endif /* _EXEC_H */ diff --git a/src/mips/pshittyload/include/flash.h b/src/mips/pshittyload/include/flash.h new file mode 100644 index 000000000..9e3e6dba3 --- /dev/null +++ b/src/mips/pshittyload/include/flash.h @@ -0,0 +1,39 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# "flash.h" - header of the flash memory library for PS1. +# +*/ + +#ifndef _FLASH_H +#define _FLASH_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* macros */ +// test if bit 6 of any byte in the array toggles on consecutive reads +// which indicates that a Program or Erase operation is in progress. +#define isBitToggling(__base) (((((volatile uint8_t *) __base)[0] ^ ((volatile uint8_t *) __base)[0]) & (1 << 6)) != 0) + +/* prototypes */ +void Flash_Reset(void *base); +void Flash_Autoselect(void *base); +void Flash_SectorErase(void *base, uint32_t offset); +void Flash_ChipErase(void *base);; +void Flash_Program(void *base, uint32_t offs, void *src, uint32_t size); +void FlashUnlockCycle(void *base, uint8_t cmd); +void Flash_ProgramFast(void *base, uint32_t offs, void *src, uint32_t size); +uint32_t flash_detect(void *base, uint16_t *p_mid, uint16_t *p_did); + +#ifdef __cplusplus +} +#endif + +#endif /* _FLASH_H */ diff --git a/src/mips/pshittyload/include/ftfifo.h b/src/mips/pshittyload/include/ftfifo.h new file mode 100644 index 000000000..f87d02512 --- /dev/null +++ b/src/mips/pshittyload/include/ftfifo.h @@ -0,0 +1,41 @@ +#ifndef _FTFIFO_H +#define _FTFIFO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define FTFIFO_DATA ((volatile uint8_t *)0x1F000000) +#define FTFIFO_STAT ((volatile uint8_t *)0x1F000001) +#define FTFIFO_STAT_RXRDY (1 << 0) +#define FTFIFO_STAT_TXRDY (1 << 1) + +#define FTFIFO_RX_Ready() ((*FTFIFO_STAT & (FTFIFO_STAT_RXRDY)) == (FTFIFO_STAT_RXRDY)) +#define FTFIFO_TX_Ready() ((*FTFIFO_STAT & (FTFIFO_STAT_TXRDY)) == (FTFIFO_STAT_TXRDY)) +#define FTFIFO_Ready() ((*FTFIFO_STAT & (FTFIFO_STAT_RXRDY | FTFIFO_STAT_TXRDY)) == (FTFIFO_STAT_RXRDY | FTFIFO_STAT_TXRDY)) + +static inline uint8_t FT_get(void) +{ + while(!FTFIFO_RX_Ready()); + return *FTFIFO_DATA; +} + +static inline void FT_put(uint8_t d) +{ + while(!FTFIFO_TX_Ready()); + *FTFIFO_DATA = d; +} + +uint8_t FT_peek8(uint32_t timeout, int *presult); +uint16_t FT_peek16(uint32_t timeout, int *presult); +uint32_t FT_peek32(uint32_t timeout, int *presult); + +int FT_poke8(uint8_t d, uint32_t timeout); +int FT_poke16(uint16_t d, uint32_t timeout); +int FT_poke32(uint32_t d, uint32_t timeout); + +#ifdef __cplusplus +} +#endif + +#endif /* _FTFIFO_H */ diff --git a/src/mips/pshittyload/include/pshitty.h b/src/mips/pshittyload/include/pshitty.h new file mode 100644 index 000000000..951882867 --- /dev/null +++ b/src/mips/pshittyload/include/pshitty.h @@ -0,0 +1,21 @@ +#ifndef _PSHITTY_H +#define _PSHITTY_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "common/compiler/stdint.h" +#include "exec.h" +#include "serialio.h" + +extern void FlushCache(void); +extern int printf(const char * fmt, ...); +void shortWait(uint32_t n); +void longWait(uint32_t n); + +#ifdef __cplusplus +} +#endif + +#endif /* _PSHITTY_H */ diff --git a/src/mips/pshittyload/include/serialio.h b/src/mips/pshittyload/include/serialio.h new file mode 100644 index 000000000..834ea48c7 --- /dev/null +++ b/src/mips/pshittyload/include/serialio.h @@ -0,0 +1,145 @@ +/* + * File: serialio.h + * Author: asmblur + * + * Created on February 10, 2009, 1:13 AM + * Reversed on September 2, 2019 + */ + +#ifndef _SERIALIO_H +#define _SERIALIO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Definitions: + * + * DTE(Data Terminal Equiptment): a PC/PS/etc(Not a modem) + * DCE(Data Communications Equiptment): a modem + * + * RTS-CTS flow control: + * RTS/RTR: Request To Send/Ready To Receive, assert to indicate readiness to receive data + * CTS: Clear To Send, input from RTR of other. + * + * DTR: Data Terminal Ready, assert to indicate readiness to communicate + * DSR: Data Set Ready, input from DTR of other + * + * + * + * + */ + +// bits for STATUS +// SIO Interrupt Pending +#define SIO_STAT_IRQ 0x0200 +#define SIO_STAT_CTS 0x0100 +#define SIO_STAT_DSR 0x0080 +#define SIO_STAT_SYNC_DET 0x0040 +#define SIO_STAT_FRAME_ERR 0x0020 +#define SIO_STAT_RX_OVRN_ERR 0x0010 +#define SIO_STAT_PARITY_ERR 0x0008 +#define SIO_STAT_TX_EMPTY 0x0004 +#define SIO_STAT_RX_RDY 0x0002 +#define SIO_STAT_TX_RDY 0x0001 +#define SIO_STAT_MASK (0x03FF) + +// bits for CONTROL + +// enable DSR interrupts. +#define SIO_CTRL_DSRI_EN 0x1000 +// enable RXD interrupts. +#define SIO_CTRL_RXI_EN 0x0800 +// enable TXD interrupts. +#define SIO_CTRL_TXI_EN 0x0400 +#define SIO_CTRL_BUF8 0x0300 +#define SIO_CTRL_BUF4 0x0200 +#define SIO_CTRL_BUF2 0x0100 +#define SIO_CTRL_BUF1 0x0000 +// why is there nothing for bit 7? CTRL_BUFx is bits 9-10 +#define SIO_CTRL_RESET_INT 0x0040 +// enable RTS driver(inverted) +#define SIO_CTRL_RTS_EN 0x0020 +#define SIO_CTRL_RTR_EN 0x0020 +#define SIO_CTRL_RESET_ERR 0x0010 +#define SIO_CTRL_BRK 0x0008 +// enable RXD +#define SIO_CTRL_RX_EN 0x0004 +// enable DTR driver(inverted) +#define SIO_CTRL_DTR_EN 0x0002 +// enable TXD +#define SIO_CTRL_TX_EN 0x0001 +#define SIO_CTRL_MASK (0x1FFF) + +/* + * SIO1 + * Pins go from left to right + * + * NOTE: All pins except for RXD, TXD, GND and 3V3 are inverted. + * + * Pin Name Dir Notes + * ----- ----- --- ---------- + * 1 RXD I Receive Data + * 2 3V3 3.3V output + * 3 DSR I Data Set Ready + * 4 TXD O Transmit Data + * 5 CTS O Clear To Send + * 6 DTR I Data Terminal Ready + * 7 GND Ground + * 8 RTS O Request To Send + */ + +// Bits for MODE + +// MODE: Stop Bits +// bits 6-7 +#define SIO_MODE_SB_1 0x0040 +#define SIO_MODE_SB_1_5 0x0080 +#define SIO_MODE_SB_2 0x00C0 + +// MODE: Parity +// bits 4-5 +#define SIO_MODE_P_NONE 0x0000 +#define SIO_MODE_P_ODD 0x0010 +#define SIO_MODE_P_EVEN 0x0030 + +// MODE: Character Length(Bits Per Character) +// bits 2-3 +#define SIO_MODE_CHLEN_5 0x0000 +#define SIO_MODE_CHLEN_6 0x0004 +#define SIO_MODE_CHLEN_7 0x0008 +#define SIO_MODE_CHLEN_8 0x000C + +// MODE: Baud Rate multiplier(??) +// NOTE: supposedly these 2 bits should always be "10"(2).. +// bits 0-1 +#define SIO_MODE_BR_1 0x0001 +#define SIO_MODE_BR_16 0x0002 +#define SIO_MODE_BR_64 0x0003 + +#define SIO_MODE_MASK 0x00FF + +#define R_PS1_SIO1_DATA ((volatile uint8_t *) 0x1F801050) +#define R_PS1_SIO1_STAT ((volatile uint16_t *) 0x1F801054) +#define R_PS1_SIO1_MODE ((volatile uint16_t *) 0x1F801058) +#define R_PS1_SIO1_CTRL ((volatile uint16_t *) 0x1F80105A) +#define R_PS1_SIO1_BAUD ((volatile uint16_t *) 0x1F80105E) + +/* prototypes */ +void psio_init(void); +void sio_reset(void); + +uint8_t psio_get(void); +uint16_t psio_get16(void); +uint32_t psio_get32(void); + +void psio_put(uint8_t d); +void psio_put16(uint16_t d); +void psio_put32(uint32_t d); + +#ifdef __cplusplus +} +#endif + +#endif /* _SERIALIO_H */ diff --git a/src/mips/pshittyload/src/arcomms.S b/src/mips/pshittyload/src/arcomms.S new file mode 100644 index 000000000..f5aaa0fab --- /dev/null +++ b/src/mips/pshittyload/src/arcomms.S @@ -0,0 +1,100 @@ +.set push +.set noreorder +.set noat +/* + #define XP_STAT ((volatile uint8_t *) 0x1F060000) + #define XP_CTRL ((volatile uint8_t *) 0x1F060001) + #define XP_STAT ((volatile uint8_t *) 0x1F060002) + + +uint8_t AR12_exch8(uint8_t d) +{ + uint8_t rv; + + // 0x1F020010 + while((*AR12_STAT & 1) == 0); + // 0x1F060000 + rv = *AR12_DATA; + *AR12_DATA = d; + return rv; +} + +uint8_t XP_read8(void) +{ + uint8_t d; + while((*XP_STAT & 1) == 0); + + d = *XP_CTRL; + *XP_CTRL = 0x08; + + while((*XP_STAT & 1) != 0); + *XP_CTRL = 0; + return d; +} + +uint8_t COMMS_read8(void) +{ + if(!isXP) + { + return AR12_Exchange8(0); + } +} +*/ +#include + +.text + +.global shortWait +.type shortWait, @function +.ent shortWait +shortWait: +_shortWait_l1: + bnez a0, _shortWait_l1 + addiu a0, a0, -1 + jr ra + nop +.end shortWait + + +void shortWait(uint32_t n); +void longWait(uint32_t n); + + +.global longWait +.type longWait, @function +.ent longWait +longWait: +_longWait_l1: + li t0, 1665 +_longWait_l2: + bnez t0, _longWait_l2 + addiu t0, -1 + bnez a0, _longWait_l1 + addiu a0, -1 + jr ra + nop +.end longWait + + +/* this will only be accurate if interrupts are disabled */ +.global delay_ms +.type delay_ms, @function +.ent delay_ms +delay_ms: + li t0, 1665 +_delay_ms_l2: + bnez t0, _delay_ms_l2 + addiu t0, -1 + bnez a0, delay_ms + addiu a0, -1 + jr ra + nop +.end delay_ms + +M_KCALL printf, 0xA0, 0x003F +M_KCALL FlushCache, 0xA0, 0x0044 + +M_SYSCALL EnterCriticalSection, 1 +M_SYSCALL ExitCriticalSection, 2 + +.set pop diff --git a/src/mips/pshittyload/src/delay.S b/src/mips/pshittyload/src/delay.S new file mode 100644 index 000000000..7df659ba1 --- /dev/null +++ b/src/mips/pshittyload/src/delay.S @@ -0,0 +1,37 @@ +.set push +.set noreorder +.set noat + +#include + +.text + +.global shortWait +.type shortWait, @function +.ent shortWait +shortWait: +_shortWait_l1: + bnez a0, _shortWait_l1 + addiu a0, a0, -1 + jr ra + nop +.end shortWait + +/* this will only be accurate if interrupts are disabled */ + +/* aka "longWait()" */ +.global delay_ms +.type delay_ms, @function +.ent delay_ms +delay_ms: + li t0, 1665 +_delay_ms_l2: + bnez t0, _delay_ms_l2 + addiu t0, -1 + bnez a0, delay_ms + addiu a0, -1 + jr ra + nop +.end delay_ms + +.set pop diff --git a/src/mips/pshittyload/src/exec.S b/src/mips/pshittyload/src/exec.S new file mode 100644 index 000000000..061e518f7 --- /dev/null +++ b/src/mips/pshittyload/src/exec.S @@ -0,0 +1,78 @@ +.set push +.set noreorder +.set noat + +#include + +.text + +// sizeof() == 0x3C(60) +#define ExecInfo_entry 0x00 // Address of program entry-point. +#define ExecInfo_init_gp 0x04 // SCE only. Initial value the "gp" register is set to. 0 for PS-X EXE. +#define ExecInfo_text_addr 0x08 // Memory address to which the .text section is loaded. +#define ExecInfo_text_size 0x0C // Size of the .text section in the file and memory. +#define ExecInfo_data_addr 0x10 // SCE only. Memory address to which the .data section is loaded. 0 for PS-X EXE. +#define ExecInfo_data_size 0x14 // SCE only. Size of the .data section in the file and memory. 0 for PS-X EXE. +#define ExecInfo_bss_addr 0x18 // Memory address of the .bss section. .bss is initialized by Exec(). +#define ExecInfo_bss_size 0x1C // Size of the .bss section in memory. +#define ExecInfo_stack_addr 0x20 // Memory address pointing to the bottom(lowest address) of the stack. BIOS replaces + // with "STACK" parameter of "SYSTEM.CNF" file. +#define ExecInfo_stack_size 0x24 // Size of the stack. Can be 0. +#define ExecInfo_saved_sp 0x28 // Used by BIOS Exec() function to preserve the "sp" register. +#define ExecInfo_saved_fp 0x2C // Used by BIOS Exec() function to preserve the "fp" register. +#define ExecInfo_saved_gp 0x30 // Used by BIOS Exec() function to preserve the "gp" register. +#define ExecInfo_saved_ra 0x34 // Used by BIOS Exec() function to preserve the "ra" register. +#define ExecInfo_saved_s0 0x38 // Used by BIOS Exec() function to preserve the "s0" register. + +.global Exec2 +.type Exec2, @function +.ent Exec2 +Exec2: + sw s0, ExecInfo_saved_s0(a0) + or s0, zero, a0 + sw ra, ExecInfo_saved_ra(s0) + sw sp, ExecInfo_saved_sp(s0) + sw fp, ExecInfo_saved_fp(s0) + lw t0, ExecInfo_bss_size(s0) + sw gp, ExecInfo_saved_gp(s0) + + beqz t0, _no_bss + + lw t1, ExecInfo_bss_addr(s0) + nop +_bss_clear_loop: + addiu t0, t0, -4 + sw zero, 0(t1) + bgtz t0, _bss_clear_loop + addiu t1, t1, 4 + +_no_bss: + lw t0, ExecInfo_stack_addr(s0) + nop + beqz t0, _no_stack + nop + + lw t1, ExecInfo_stack_size(s0) + nop + add t0, t1 + move sp, t0 /* sp = ExecInfo.stack_addr + ExecInfo.stack_size; */ + move fp, sp /* fp = sp */ + + +_no_stack: + lw t3, ExecInfo_entry(s0) + lw gp, ExecInfo_init_gp(s0) + + move a0, a1 + jalr t3 + move a1, a2 + + lw ra, ExecInfo_saved_ra(s0) + lw sp, ExecInfo_saved_sp(s0) + lw fp, ExecInfo_saved_fp(s0) + lw gp, ExecInfo_saved_gp(s0) + lw s0, ExecInfo_saved_s0(s0) + jr ra + li v0, 1 +.end Exec2 +.set pop diff --git a/src/mips/pshittyload/src/flash.c b/src/mips/pshittyload/src/flash.c new file mode 100644 index 000000000..e3a380dde --- /dev/null +++ b/src/mips/pshittyload/src/flash.c @@ -0,0 +1,146 @@ +#include "flash.h" + + +// TODO: time these to see how long the wait really is. +__attribute__((noinline)) void shortWait(int n) +{ + int i = 6499; + while((i -= 25) >= 0); +} + +// TODO: time these to see how long the wait really is. +__attribute__((noinline)) void longWait(void) +{ + int i = 0; + for(i = 0; i < 350; i += 14) + { + shortWait(); shortWait(); shortWait(); shortWait(); + shortWait(); shortWait(); shortWait(); shortWait(); + shortWait(); shortWait(); shortWait(); shortWait(); + shortWait(); shortWait(); + } +} + +// performs a 3-byte "unlock cycle" +#define M_FlashUnlockCycle(__base, __cmd) \ +{ \ + ((volatile uint8_t *) __base)[0xAAA] = 0xAA; \ + ((volatile uint8_t *) __base)[0x555] = 0x55; \ + ((volatile uint8_t *) __base)[0xAAA] = (__cmd); \ +} + +void FlashUnlockCycle(void *base, uint8_t cmd) { M_FlashUnlockCycle(base, cmd); } + +// reset the device state +void Flash_Reset(void *base) { ((volatile uint8_t *) base)[0x555] = 0xF0; } + +// enters "Autoselect" mode which allows access to chip information +// by reading from addresses 0+ +// Muse be exited with a Reset(see Flash_Reset) +void Flash_Autoselect(void *base) { M_FlashUnlockCycle(base, 0x90); } + +void Flash_ChipErase(void *base) +{ + M_FlashUnlockCycle(base, 0x80); // Unlock Cycle 1 + M_FlashUnlockCycle(base, 0x10); // Unlock Cycle 2 + + // wait for operation to complete. + while(isBitToggling(base)); +} + +// erases a sector +void Flash_SectorErase(void *base, uint32_t offset) +{ + M_FlashUnlockCycle(base, 0x80); // Unlock Cycle 1 + + ((volatile uint8_t *) base)[0xAAA] = 0xAA; // Unlock Cycle 2 + ((volatile uint8_t *) base)[0x555] = 0x55; + ((volatile uint8_t *) base)[offset] = 0x30; + + // wait for operation to complete. + while(isBitToggling(base + offset)); +} + +// programs "size" number of data from "src" to flash starting at (base + offs) +// NOTE: Flash_ProgramFast() is a better option. +void Flash_Program(void *base, uint32_t offs, void *src, uint32_t size) +{ + int i; + + volatile uint8_t *b = (volatile uint8_t *) base; + volatile uint8_t *d = (volatile uint8_t *) base + offs; + volatile uint8_t *s = (volatile uint8_t *) src; + + for(i = 0; i < size; i++) + { + M_FlashUnlockCycle(b, 0xA0); // Unlock Cycle 1(3 cycles) + d[i] = s[i]; + // I don't *think* you have to wait for bit toggling to cease here... + } + + // wait for operation to complete. + while(isBitToggling(base)); +} + +// programs "size" number of data from "src" to flash starting at (base + offs). +// NOTE: uses the "Unlock Bypass" mode along with the "Unlock Bypass Program" +// command instead of the normal "Program" command. This reduces programming by +// about half the cycles. +void Flash_ProgramFast(void *base, uint32_t offs, void *src, uint32_t size) +{ + int i; + + volatile uint8_t *b = (volatile uint8_t *) base; + volatile uint8_t *d = (volatile uint8_t *) base + offs; + volatile uint8_t *s = (volatile uint8_t *) src; + + M_FlashUnlockCycle(base, 0x20); // "Unlock Bypass" + + for(i = 0; i < size; i++) + { + b[0xAAA] = 0xA0; // Unlock Bypass Program + d[i] = s[i]; // program 1 byte + // I don't *think* you have to wait for bit toggling to cease here... + } + + b[0] = 0x90; // Unlock Bypass Reset(2 cycles) + b[0] = 0x00; + + // wait for operation to complete. + while(isBitToggling(base)); +} + +// try to detect flash memory device at "base". +// args: +// base: base address pointer of device. +// p_mid: pointer where a uint16_t containing the manufacturer ID can be written. +// Can be NULL. +// p_did: pointer where a uint16_t containing the device ID can be written. +// Can be NULL. +// returns: +// lower 16: manufacturer ID +// upper 16: device ID +// +// NOTE: No attempt is made to validate these IDs! They may be completely bogus if there's no device or it doesn't support +// this method of reading the IDs. +// +uint32_t flash_detect(void *base, uint16_t *p_mid, uint16_t *p_did) +{ + uint16_t man_id, dev_id; + uint8_t *p = (uint8_t *) base; + + Flash_Autoselect(base); // enter Autoselect mode + longWait(); + + man_id = p[0x000]; // byte 0 is the manufacturer ID + dev_id = p[0x001]; // byte 1 is the device ID + // CFI stuff next but we don't need it + + longWait(); + + Flash_Reset(base); // reset the device to exit Autoselect mode + + if(p_mid) *p_mid = man_id; + if(p_did) *p_did = dev_id; + return (man_id | (dev_id << 16)); +} diff --git a/src/mips/pshittyload/src/ftfifo.c b/src/mips/pshittyload/src/ftfifo.c new file mode 100644 index 000000000..290be9710 --- /dev/null +++ b/src/mips/pshittyload/src/ftfifo.c @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include "pshitty.h" + +#define FTFA_BASE_ADDR (0x1F600000) +#define FTFB_BASE_ADDR (0x1F600002) + +#define FTF_BASE_ADDRS(__fn) ((((__fn) & 1) == 0) ? FTFA_BASE_ADDR : FTFB_BASE_ADDR) + +#define FTFA_REGS (((volatile uint8_t *) FTFA_BASE_ADDR) +#define FTFB_REGS (((volatile uint8_t *) FTFB_BASE_ADDR) + +#define FTFx_REGS(__fn) (((volatile uint8_t *) FTF_BASE_ADDRS(__fn))) + +enum { FTFA = 0, FTFB = 1 }; + +void ftfifo_init(int fn) +{ + // TODO: synch with the PC to ensure buffers are clear of garbage from previous transfers or whatever. + +} + +// get 1 byte from FT FIFO +uint8_t ftfifo_get(int fn) +{ + // wait for the RX FIFO to had data + while((FTFA_REGS[1] & FTF_STAT_RX_RDY) == 0); + // read a byte from the RX FIFO + return FTFA_REGS[0]; +} + +// send 1 byte to FT FIFO +void ftfifo_put(int fn, uint8_t d) +{ + // wait for the TX FIFO to be ready to accept data + while((FTFA_REGS[1] & FTF_STAT_TX_RDY) == 0); + // write a byte to the TX FIFO + FTFA_REGS[0] = d; +} + +uint16_t ftfifo_get16(void) { return (ftfifo_get() | (ftfifo_get() << 8)); } +uint32_t ftfifo_get32(void) { return (ftfifo_get16() | (ftfifo_get16() << 16)); } + +void ftfifo_put16(uint16_t d) { ftfifo_put(d & 0xFF); ftfifo_put(d >> 8); } +void ftfifo_put32(uint32_t d) { ftfifo_put16(d & 0xFFFF); ftfifo_put16(d >> 16); } diff --git a/src/mips/pshittyload/src/main.c b/src/mips/pshittyload/src/main.c new file mode 100644 index 000000000..a85806c24 --- /dev/null +++ b/src/mips/pshittyload/src/main.c @@ -0,0 +1,79 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include "pshitty.h" + +#define _KBuffer ((void *) 0xA000B070) +#define _KExecInfo ((void *) 0xA000B870) + +int psLoad(ExecInfo *exec) +{ + int i; + EXE_Header *hdr = (EXE_Header *) _KBuffer; + + // load the 2048-byte header of the EXE into "header" and the "text" of the into + // the "text_addr" specified by the header. + printf("psLoad() reading 2048 bytes first.\r\n"); + for(i = 0; i < 2048; i++) { + uint8_t b = psio_get(); + ((uint8_t *) hdr)[i] = b; + } + + for(i = 0; i < sizeof(ExecInfo); i++) { + ((uint8_t *) exec)[i] = ((uint8_t *) &hdr->exec)[i]; + } + + printf("psLoad() reading %i bytes\r\n", hdr->exec.text_size); + for(i = 0; i < hdr->exec.text_size; i++) { + uint8_t b = psio_get(); + ((uint8_t *) hdr->exec.text_addr)[i] = b; + } + + printf("\r\nDone, calling flushCache()\r\n"); + FlushCache(); + return 1; +} + +void main(void) +{ + int rv = 1; + uint8_t d; + ExecInfo *info = (ExecInfo *) _KExecInfo; + + printf("pshittyload starting...\r\n"); + while(rv != 0) + { + psio_init(); // (re-) initialize SIO1 + + // loop until we get 'P', 'L' + // when we get a 'P' and another character, we send a response char: + // '+': if we got an 'L' + // '-': if we got something else + do + { + do { d = psio_get(); } while (d != 'P'); + psio_put((d = psio_get()) == 'L' ? '+' : '-' ); + } while(d != 'L'); + printf("Got PL signature, calling psLoad(%p)\r\n", info); + + psLoad(info); + printf("psLoad(%p) done, calling Exec2(%p)\r\n", info, info); + rv = Exec2(info, 0, 0); + } +} diff --git a/src/mips/pshittyload/src/pshittysio.c b/src/mips/pshittyload/src/pshittysio.c new file mode 100644 index 000000000..a14410f76 --- /dev/null +++ b/src/mips/pshittyload/src/pshittysio.c @@ -0,0 +1,119 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include "pshitty.h" + +// un-comment this to use some error recovery stuff. +//#define ENHANCED_ERROR + +// un-comment this to use RTS/CTS flow control +//#define USE_RTSCTS + +#ifdef USE_RTSCTS +#define RTR_ON() { *R_PS1_SIO1_CTRL |= SIO_CTRL_RTR_EN;} } +#define RTR_OFF() { *R_PS1_SIO1_CTRL &= ~(SIO_CTRL_RTR_EN); } +#else +#define RTR_ON(){} +#define RTR_OFF(){} +#endif + +#define SIO1_BAUD_DIV (2073600) +#define BAUD_RATE (57600) + +#define SIO1_RX_Ready() (((*R_PS1_SIO1_STAT) & SIO_STAT_RX_RDY) != 0) + +#define SIO1_TX_Ready() (((*R_PS1_SIO1_STAT) & (SIO_STAT_TX_EMPTY | SIO_STAT_TX_RDY)) == (SIO_STAT_TX_EMPTY | SIO_STAT_TX_RDY)) + +// true if RX Overrun, Frame Error or Parity Error occured +// otherwise false +#define SIO1_Err() (((*R_PS1_SIO1_STAT) & (SIO_STAT_RX_OVRN_ERR | SIO_STAT_FRAME_ERR | SIO_STAT_PARITY_ERR)) != 0) + +// these are the default values for the corresponding registers +static const uint16_t + // init with TX and RX enabled. + def_ctrl = (SIO_CTRL_RX_EN | SIO_CTRL_TX_EN), + /* 8bit, no-parity, 1 stop-bit */ + def_mode = (SIO_MODE_CHLEN_8 | SIO_MODE_P_NONE | SIO_MODE_SB_1 | SIO_MODE_BR_16), + def_baud = (2073600/BAUD_RATE); + +static inline void psio_setup(uint32_t ctrl, uint32_t mode, uint32_t baud) +{ + *R_PS1_SIO1_CTRL = ctrl; + *R_PS1_SIO1_MODE = mode; + *R_PS1_SIO1_BAUD = baud; +} + +// sets the SIO1 registers to their default values +void psio_init(void) { psio_setup(def_ctrl, def_mode, def_baud); } + +// get 1 byte from SIO1 RX FIFO +uint8_t psio_get(void) +{ + RTR_ON(); + while(!SIO1_RX_Ready()); + uint8_t d = *R_PS1_SIO1_DATA; + RTR_OFF(); + return d; +} + +void sio_reset(void) { *R_PS1_SIO1_CTRL = SIO_CTRL_RESET_INT | SIO_CTRL_RESET_ERR; } + +// this needs more investigation. +void sio_reset_driver(void) { psio_setup(SIO_CTRL_RESET_INT, 0x0000, 0x0000); } + +// I think this is wrong and should be the same as sio_reset(). +//void sio_clear_error(void) { *R_PS1_SIO1_CTRL = (SIO_CTRL_RESET_ERR); } + +void psio_put(uint8_t d) +{ +#ifdef ENHANCED_ERROR + volatile uint8_t x; + + if (SIO1_Err()) { + + // I guess this is to preserve the data that's currently in the TX FIFO? + x = *R_PS1_SIO1_DATA; + + while (SIO1_Err()) { + // reset the interrupt and error + sio_reset(); + + delay_ms(5); + + // restore the TX FIFO? + *R_PS1_SIO1_DATA = x; + + // restore mode and ctrl + *R_PS1_SIO1_MODE = (def_mode); + *R_PS1_SIO1_CTRL = (def_ctrl); + } + } +#endif + while(!SIO1_TX_Ready()); +// while (((*R_PS1_SIO1_STAT) & (SIO_STAT_TX_EMPTY | SIO_STAT_TX_RDY)) != (SIO_STAT_TX_EMPTY | SIO_STAT_TX_RDY)); + + // push the byte into the TX FIFO + *R_PS1_SIO1_DATA = d; +} + +uint16_t psio_get16(void) { return (psio_get() | (psio_get() << 8)); } +uint32_t psio_get32(void) { return (psio_get16() | (psio_get16() << 16)); } + +void psio_put16(uint16_t d) { psio_put(d & 0xFF); psio_put(d >> 8); } +void psio_put32(uint32_t d) { psio_put16(d & 0xFFFF); psio_put16(d >> 16); } diff --git a/src/mips/pshittyload/src/syscalls.S b/src/mips/pshittyload/src/syscalls.S new file mode 100644 index 000000000..81cc97736 --- /dev/null +++ b/src/mips/pshittyload/src/syscalls.S @@ -0,0 +1,53 @@ +.set push +.set noreorder +.set noat + +#include + +.text + +.macro M_KCALL, label, tablenum, callnum +.global \label +.type \label, @function +.ent \label +\label: + li t2, \tablenum + jr t2 + li t1, \callnum +.end \label +.endm + +.macro M_SYSCALL, label, callNum +.global \label +.type \label, @function +.ent \label +\label: + li a0, \callNum + syscall + jr ra + nop +.end \label +.endm + +/* this will only be accurate if interrupts are disabled */ +.global delay_ms +.type delay_ms, @function +.ent delay_ms +delay_ms: + li t0, 1665 +_delay_ms_l2: + bnez t0, _delay_ms_l2 + addiu t0, -1 + bnez a0, delay_ms + addiu a0, -1 + jr ra + nop +.end delay_ms + +M_KCALL printf, 0xA0, 0x003F +M_KCALL FlushCache, 0xA0, 0x0044 + +M_SYSCALL EnterCriticalSection, 1 +M_SYSCALL ExitCriticalSection, 2 + +.set pop diff --git a/src/mips/psx-exe.ld b/src/mips/psx-exe.ld new file mode 100644 index 000000000..78923d777 --- /dev/null +++ b/src/mips/psx-exe.ld @@ -0,0 +1,167 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +OUTPUT_FORMAT("elf32-tradlittlemips") +/*OUTPUT_ARCH("mips:3000")*/ +OUTPUT_FORMAT("binary") + +EXTERN(_start) +ENTRY(_start) + +TLOAD_ADDR = DEFINED(_TLOAD_ADDR) ? TLOAD_ADDR : 0x80010000; + +MEMORY { + loader : ORIGIN = 0x8000f800, LENGTH = 2048 + ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 + dcache : ORIGIN = 0x1f800000, LENGTH = 0x400 +} + +__ram_top = ORIGIN(ram) + LENGTH(ram); +__sp = __ram_top - 0x100; + +__dcache = ORIGIN(dcache); +__dcache_top = ORIGIN(dcache) + LENGTH(dcache); + +__bss_len = (__bss_end - __bss_start); +__ftext_len = (__ftext_end - __ftext_start); +__fdata_len = (__fdata_end - __fdata_start); + +SECTIONS { + .PSX_EXE_Header : { + /* + 0x0000 - 0x0007 : "PS-X EXE" + */ + BYTE(80); BYTE(83); BYTE(45); BYTE(88); BYTE(32); BYTE(69); BYTE(88); BYTE(69); + + /* 0x0008 - 0x000F : skip text_off and data_off since they're not supported by the PS1 BIOS */ + LONG(0); LONG(0); + + /* 0x0010 - 0x0013 : entry point */ + LONG(ABSOLUTE(_start)); + + /* 0x0014 - 0x0017 : initial value of $gp */ + LONG(0); + + /* 0x0018 - 0x001B : Memory address to load "text" section to. */ + /* + NOTE: The "text" section is actually all of the "load" + sections of the file including .text, .rodata, .data. + etc. + */ + LONG(TLOAD_ADDR); + + /* 0x001C - 0x001F : size, in bytes, of the "text" section. */ + LONG(__ftext_len + __fdata_len); + + /* 0x0020 - 0x002F : + Skip "data_addr", "data_size", "bss_addr" and "bss_size". + None of these are supported by retail PS1 BIOS. + */ + LONG(0); LONG(0); + LONG(0); LONG(0); + + /* 0x0030 - 0x0033 : Initial stack address. */ + LONG(DEFINED(_sp) ? ABSOLUTE(_sp) : 0x801FFF00); + + /* 0x0034 - 0x0037 : Initial stack size, set it to 0. */ + LONG(0); + + /* Skip the remaining fields as they're not supported by the BIOS */ + . = . + 1992; + /* + . = ADDR(.text); + */ + } > loader + + __ftext_start = ABSOLUTE(.); + .text TLOAD_ADDR : { + *(.start) + *(.init) + KEEP (*(SORT_NONE(.fini))) + *(.text.unlikely .text.*_unlikely .text.unlikely.*) + *(.text.exit .text.exit.*) + *(.text.startup .text.startup.*) + *(.text.hot .text.hot.*) + *(.text .stub .text.* .gnu.linkonce.t.*) + . = ALIGN(16); + } > ram + + .fini : { + . = ALIGN(16); + } > ram + + . = ALIGN(16); + __text_end = .; + __ftext_end = ABSOLUTE(.); + + __fdata_start = ABSOLUTE(.); + + .rodata : { + *(.rodata .rodata.* .rdata .rdata.* .gnu.linkonce.r.*) + } > ram + + .rodata1 : { + *(.rodata1) + } > ram + + __data_start = .; + .data : { + *(.a0table) + *(.data .data.* .gnu.linkonce.d.*) + *(.data1) + *(.got.plt) + *(.got) + } > ram + + . = ALIGN(4); + __data_end = .; + __fdata_end = .; + __bss_start = .; + .sbss : { + *(.dynsbss) + *(.sbss .sbss.* .gnu.linkonce.sb.*) + *(.scommon) + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + } > ram + + . = ALIGN(4); + __bss_end = .; + + __end = .; + + /* pad file to be a multiple of 2048 bytes. Needed for loading from CD-ROM. */ + /* .__pad : { BYTE(0); . = ALIGN(2048); }*/ + . = ADDR(.text) - 0x800; + + + /DISCARD/ : { *(.MIPS.abiflags) } + + /* Everything is statically linked, so discard PLTs. */ + /DISCARD/ : { *(.rel.iplt) *(.rela.iplt) *(.rel.plt) *(.rela.plt) *(.plt) *(.iplt) } + + /* We don't make use of debugging information, so drop that, too. */ + /DISCARD/ : { *(.debug) *(.debug_srcinfo) *(.debug_sfnames) *(.debug_aranges) *(.debug_pubnames) *(.debug_info .gnu.linkonce.wi.*) *(.debug_abbrev) *(.debug_line .debug_line.* .debug_line_end ) *(.debug_frame) *(.debug_str) *(.debug_loc) *(.debug_macinfo) *(.debug_weaknames) *(.debug_funcnames) *(.debug_typenames) *(.debug_varnames) *(.debug_pubtypes) *(.debug_ranges) *(.debug_macro) *(.mdebug.abi32) *(.mdebug.abiN32) *(.mdebug.abi64) *(.mdebug.abiO64) *(.mdebug.eabi32) *(.mdebug.eabi64) } + + /* Discard things that the standard link script drops, too. */ + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } + + /DISCARD/ : { *(.note.gnu.build-id) } +} diff --git a/src/mips/serial/Makefile b/src/mips/serial/Makefile new file mode 100644 index 000000000..a0d96ee6c --- /dev/null +++ b/src/mips/serial/Makefile @@ -0,0 +1,14 @@ +TARGET = serial.psx +TLOAD_ADDR = 0x80010000 +SRCS = \ + ../common/hardware/cop0.s \ + crt0/crt0.S \ + src/main.c + +LIBS = ../ps1sdk/libps1sdk.a + +LDSCRIPT = ../psx-exe.ld +CPPFLAGS := -I../ps1sdk/include -Isrc -Iinclude +LDFLAGS := -L../ps1sdk -lps1sdk + +include ../common.mk diff --git a/src/mips/serial/crt0/crt0.S b/src/mips/serial/crt0/crt0.S new file mode 100644 index 000000000..e1d246126 --- /dev/null +++ b/src/mips/serial/crt0/crt0.S @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include + +.set push +.set noreorder +.set noat + + .section .start, "ax", @progbits + .align 2 + .global main + .global _start + .type _start, @function +_start: + la t0, __bss_start + la t1, __bss_end + addiu t1, t1, 3 + srl t1, t1, 2 + sll t1, t1, 2 + beq t0, t1, _zero_bss_done + nop + +_zero_bss: + sw zero, 0(t0) + addiu t0, t0, 4 + bne t0, t1, _zero_bss + nop + +_zero_bss_done: +/* la gp, _gp*/ + li a0, 0 + j main + li a1, 0 + +/* +.end _start +.data + +.bss +*/ + .extern __bss_start + .extern __bss_end + .extern _gp +/* int _main(int argc, const char **argv, const char **envp) */ + .extern main + +.set pop diff --git a/src/mips/serial/src/console.c b/src/mips/serial/src/console.c new file mode 100644 index 000000000..6e96eab2d --- /dev/null +++ b/src/mips/serial/src/console.c @@ -0,0 +1,150 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either verttyn 2 of the License, or * + * (at your option) any later verttyn. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include "common/hardware/cop0.h" +#include "ps1sdk.h" +#include "ps1hwregs.h" +#include "serialio.h" +#include "tty.h" + +#include "fileio.h" + +static void *_old_putchar = NULL; +static void *_old__putchar = NULL; +static char __last_tty_ch = 0; + +static void sio_reset(void) { *R_PS1_SIO1_CTRL = SIO_CTRL_RESET_INT | SIO_CTRL_RESET_ERR; } + +static int force_dos_line_endings = 1; + +int tty_putchar(char ch) +{ + if(ch == 0x0A) + { + if(force_dos_line_endings) + if(__last_tty_ch != 0x0D) tty_put_byte(0x0D); + } + + tty_put_byte(ch); + __last_tty_ch = ch; + return 0; +} + +void tty_puts(const char *s) +{ + while(*s != '\0') tty_putchar(*(s++)); +} + +void tty_print8(uint8_t d) +{ + const char hex_chars[] = "0123456789ABCDEF"; + tty_putchar(hex_chars[(d >> 4) & 0x0F]); + tty_putchar(hex_chars[d & 0x0F]); +} + +void tty_print16(uint16_t d) +{ + tty_print8((d >> 8) & 0xFF); + tty_print8((d >> 0) & 0xFF); +} + +void tty_print32(uint32_t d) +{ + tty_print8((d >> 24) & 0xFF); + tty_print8((d >> 16) & 0xFF); + tty_print8((d >> 8) & 0xFF); + tty_print8((d >> 0) & 0xFF); +} + +int tty_hook_putchar(void) +{ + uint32_t *table = GetB0Table(); + + _old_putchar = (void *) ((uint32_t *) 0x200)[60]; + ((uint32_t *) 0x200)[60] = (uint32_t) &tty_putchar; // hook 0xA0 call 60(putchar) + + _old__putchar = (void *) table[61]; + table[61] = (uint32_t) &tty_putchar; // hook 0xB0 call 61(_putchar) + + FlushCache(); + return 0; +} + +int tty_unhook_putchar(void) +{ + uint32_t *table = GetB0Table(); + + if(_old_putchar != NULL) + ((uint32_t *) 0x200)[60] = (uint32_t) _old_putchar; // restore 0xA0 call 60(putchar) + if(_old__putchar != NULL) + ((uint32_t *) table)[61] = (uint32_t) _old__putchar; // restore 0xB0 call 61(_putchar) +} + +//~ int tty_init_tty(int baud) +//~ { + //~ tty_init(1, baud); + //~ tty_hook_putchar(); +//~ } + +int DelTTY(void) { + close(stdin); + close(stdout); + DelDevice("tty"); + + sio_reset(); + + AddDummyConsoleDevice(); + + if (open("tty00:", O_RDONLY) != stdin) return 1; + if (open("tty00:", O_WRONLY) != stdout) return 1; + + return 0; +} + +// sizeof() == 0x50(80) +static DeviceDriver tty_dd = +{ + name: "tty", // 0x00 - unique device name + type: DEV_TYPE_CHAR | DEV_TYPE_TTY, // 0x04 - TTY character device. + block_size: 1, // 0x08 - 1 byte per block + desc: "TTY Console", // 0x0C - description of device + init: _tty_init, // 0x10 - pointer to "init" function. Called by AddDevice() + open: _tty_open, // 0x14 - pointer to "open" function. + strategy: _tty_strategy, // 0x18 - pointer to "strategy" function. + close: _tty_close, // 0x1C - pointer to "close" function. + ioctl: _tty_ioctl, // 0x20 - pointer to "ioctl" function. + read: _tty_read, // 0x24 - pointer to "read" function. + write: _tty_write, // 0x28 - pointer to "write" function. + delete: _tty_delete, // 0x2C - pointer to "delete" function. + undelete: _tty_undelete, // 0x30 - pointer to "undelete" function. + firstfile: _tty_firstfile, // 0x34 - pointer to "firstfile" function. + nextfile: _tty_nextfile, // 0x38 - pointer to "nextfile" function. + format: _tty_format, // 0x3C - pointer to "format" function. + chdir: _tty_chdir, // 0x40 - pointer to "cd" function. + rename: _tty_rename, // 0x44 - pointer to "rename" function. + deinit: _tty_deinit, // 0x48 - pointer to "deinit" function. Called by RemDevice() + lseek: _tty_lseek, // 0x4C - pointer to "lseek" function. +}; + +int init_tty(void) +{ + DelTTY(); + + return 0; +} diff --git a/src/mips/serial/src/main.c b/src/mips/serial/src/main.c new file mode 100644 index 000000000..e87edd586 --- /dev/null +++ b/src/mips/serial/src/main.c @@ -0,0 +1,245 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include "common/hardware/cop0.h" +#include "ps1sdk.h" +#include "ps1hwregs.h" +#include "serialio.h" + +#include "fileio.h" + +static void *_old_putchar = NULL; +static void *_old__putchar = NULL; +static char __last_sio_ch = 0; + +typedef struct { + uint32_t inited, mode, ctrl, baud; +} port_config_t; + +static port_config_t sio_config = {0, 0, 0, 0}; + +void sio_reset(void) { *R_PS1_SIO1_CTRL = SIO_CTRL_RESET_INT | SIO_CTRL_RESET_ERR; } + +void sio_put_byte(uint8_t d) { + while ((*R_PS1_SIO1_STAT & (SIO_STAT_TX_EMPTY | SIO_STAT_TX_RDY)) != (SIO_STAT_TX_EMPTY | SIO_STAT_TX_RDY)) + ; + *R_PS1_SIO1_DATA = d; + + if (*R_PS1_SIO1_STAT & (SIO_STAT_RX_OVRN_ERR | SIO_STAT_FRAME_ERR | SIO_STAT_PARITY_ERR)) { + // RX Overrun, Frame Error or Parity Error occured + + // I guess this is to preserve the data that's currently in the TX FIFO? + d = *R_PS1_SIO1_DATA; + + while (*R_PS1_SIO1_STAT & (SIO_STAT_RX_OVRN_ERR | SIO_STAT_FRAME_ERR | SIO_STAT_PARITY_ERR)) { + // reset the interrupt and error + sio_reset(); + + delay_ms(5); + + // restore the TX FIFO? + *R_PS1_SIO1_DATA = d; + + // restore mode and ctrl + *R_PS1_SIO1_MODE = (sio_config.mode); + *R_PS1_SIO1_CTRL = (sio_config.ctrl); + } + } + +} + +int sio_get_byte(uint32_t timeout) +{ + int ret = -1; + + // this may not be necessary. Some UARTs won't transfer if yout don't though. + + // RTR(Ready To Receive akia "RTS"/Request to Send): on + *R_PS1_SIO1_CTRL |= SIO_CTRL_RTR_EN; + + // wait for data in the RX FIFO + if (timeout == 0) { + while (!(*R_PS1_SIO1_STAT & SIO_STAT_RX_RDY)) + { + if (*R_PS1_SIO1_STAT & (SIO_STAT_RX_OVRN_ERR | SIO_STAT_FRAME_ERR | SIO_STAT_PARITY_ERR)) { + // RX Overrun, Frame Error or Parity Error occured + + // I guess this is to preserve the data that's currently in the TX FIFO? + uint8_t d = *R_PS1_SIO1_DATA; + + while (*R_PS1_SIO1_STAT & (SIO_STAT_RX_OVRN_ERR | SIO_STAT_FRAME_ERR | SIO_STAT_PARITY_ERR)) { + // reset the interrupt and error + sio_reset(); + + delay_ms(5); + + // restore the TX FIFO? + *R_PS1_SIO1_DATA = d; + + // restore mode and ctrl + *R_PS1_SIO1_MODE = (sio_config.mode); + *R_PS1_SIO1_CTRL = (sio_config.ctrl | SIO_CTRL_RTR_EN); + } + } + } + ; + } else { + uint32_t tries = 0; + while (!(*R_PS1_SIO1_STAT & SIO_STAT_RX_RDY)) { + if (++tries >= timeout) goto _done; + } + } + + // pop a byte from the RX FIFO + ret = *R_PS1_SIO1_DATA; + +_done: + // RTR/RTS: off + *R_PS1_SIO1_CTRL &= ~(SIO_CTRL_RTR_EN); + + return ret; +} + +static int force_dos_line_endings = 1; + +int sio_putchar(char ch) +{ + if(ch == 0x0A) + { + if(force_dos_line_endings) + if(__last_sio_ch != 0x0D) sio_put_byte(0x0D); + } + + sio_put_byte(ch); + __last_sio_ch = ch; + return 0; +} + +void sio_puts(const char *s) +{ + while(*s != '\0') sio_putchar(*(s++)); +} + +void sio_print8(uint8_t d) +{ + const char hex_chars[] = "0123456789ABCDEF"; + sio_putchar(hex_chars[(d >> 4) & 0x0F]); + sio_putchar(hex_chars[d & 0x0F]); +} + +void sio_print16(uint16_t d) +{ + sio_print8((d >> 8) & 0xFF); + sio_print8((d >> 0) & 0xFF); +} + +void sio_print32(uint32_t d) +{ + sio_print8((d >> 24) & 0xFF); + sio_print8((d >> 16) & 0xFF); + sio_print8((d >> 8) & 0xFF); + sio_print8((d >> 0) & 0xFF); +} + +int sio_hook_putchar(void) +{ + uint32_t *table = GetB0Table(); + + _old_putchar = (void *) ((uint32_t *) 0x200)[60]; + ((uint32_t *) 0x200)[60] = (uint32_t) &sio_putchar; // hook 0xA0 call 60(putchar) + + _old__putchar = (void *) table[61]; + table[61] = (uint32_t) &sio_putchar; // hook 0xB0 call 61(_putchar) + + FlushCache(); + return 0; +} + +int sio_unhook_putchar(void) +{ + uint32_t *table = GetB0Table(); + + if(_old_putchar != NULL) + ((uint32_t *) 0x200)[60] = (uint32_t) _old_putchar; // restore 0xA0 call 60(putchar) + if(_old__putchar != NULL) + ((uint32_t *) table)[61] = (uint32_t) _old__putchar; // restore 0xB0 call 61(_putchar) +} + +//~ int sio_init_tty(int baud) +//~ { + //~ sio_init(1, baud); + //~ sio_hook_putchar(); +//~ } + +void init_sio(uint32_t baud) +{ + /* initialize SIO1 with RX and TX FIFOs enabled */ + *R_PS1_SIO1_CTRL = (SIO_CTRL_RX_EN | SIO_CTRL_TX_EN); + /* 8bit, no-parity, 1 stop-bit */ + *R_PS1_SIO1_MODE = (SIO_MODE_CHLEN_8 | SIO_MODE_P_NONE | SIO_MODE_SB_1 | SIO_MODE_BR_16); + *R_PS1_SIO1_BAUD = (2073600/baud); +} + +int DelSIO(void) { + close(stdin); + close(stdout); + DelDevice("tty"); + + sio_reset(); + + AddDummyConsoleDevice(); + + if (open("tty00:", O_RDONLY) != stdin) return 1; + if (open("tty00:", O_WRONLY) != stdout) return 1; + + return 0; +} + +int main(void) +{ + DelSIO(); + init_sio(115200); + + + // b0rked. Used to work, wtf did I fuck up? +// sio_hook_putchar(); + + sio_puts("Hello, pixel. Would you like to play a game?\n"); + sio_puts("No, this isn't a saw reference. Fuck them!\n"); + sio_puts("I'mma do it! Hold my beer!\n"); + + +// printf("I'mma do it!\n"); + + uint32_t d = *(uint32_t *) 0x1F801008; + d = (((d >> 16) + 4) << 16) | (d & 0xFFFF); + *(uint32_t *) 0x1F801008 = d; + +// printf("Done did it.\n"); + for(int addr = 0x1F000000; addr < 0x1F800000; addr += 0x00020000) + { + sio_print32(addr); + sio_puts(": 0x"); + sio_print32(*(uint32_t *) addr); +// sio_puts((const char *) (addr + 4)); + sio_puts("\n"); + } + + return 0; +} diff --git a/src/mips/serial/src/serialio.c b/src/mips/serial/src/serialio.c new file mode 100644 index 000000000..e87edd586 --- /dev/null +++ b/src/mips/serial/src/serialio.c @@ -0,0 +1,245 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include "common/hardware/cop0.h" +#include "ps1sdk.h" +#include "ps1hwregs.h" +#include "serialio.h" + +#include "fileio.h" + +static void *_old_putchar = NULL; +static void *_old__putchar = NULL; +static char __last_sio_ch = 0; + +typedef struct { + uint32_t inited, mode, ctrl, baud; +} port_config_t; + +static port_config_t sio_config = {0, 0, 0, 0}; + +void sio_reset(void) { *R_PS1_SIO1_CTRL = SIO_CTRL_RESET_INT | SIO_CTRL_RESET_ERR; } + +void sio_put_byte(uint8_t d) { + while ((*R_PS1_SIO1_STAT & (SIO_STAT_TX_EMPTY | SIO_STAT_TX_RDY)) != (SIO_STAT_TX_EMPTY | SIO_STAT_TX_RDY)) + ; + *R_PS1_SIO1_DATA = d; + + if (*R_PS1_SIO1_STAT & (SIO_STAT_RX_OVRN_ERR | SIO_STAT_FRAME_ERR | SIO_STAT_PARITY_ERR)) { + // RX Overrun, Frame Error or Parity Error occured + + // I guess this is to preserve the data that's currently in the TX FIFO? + d = *R_PS1_SIO1_DATA; + + while (*R_PS1_SIO1_STAT & (SIO_STAT_RX_OVRN_ERR | SIO_STAT_FRAME_ERR | SIO_STAT_PARITY_ERR)) { + // reset the interrupt and error + sio_reset(); + + delay_ms(5); + + // restore the TX FIFO? + *R_PS1_SIO1_DATA = d; + + // restore mode and ctrl + *R_PS1_SIO1_MODE = (sio_config.mode); + *R_PS1_SIO1_CTRL = (sio_config.ctrl); + } + } + +} + +int sio_get_byte(uint32_t timeout) +{ + int ret = -1; + + // this may not be necessary. Some UARTs won't transfer if yout don't though. + + // RTR(Ready To Receive akia "RTS"/Request to Send): on + *R_PS1_SIO1_CTRL |= SIO_CTRL_RTR_EN; + + // wait for data in the RX FIFO + if (timeout == 0) { + while (!(*R_PS1_SIO1_STAT & SIO_STAT_RX_RDY)) + { + if (*R_PS1_SIO1_STAT & (SIO_STAT_RX_OVRN_ERR | SIO_STAT_FRAME_ERR | SIO_STAT_PARITY_ERR)) { + // RX Overrun, Frame Error or Parity Error occured + + // I guess this is to preserve the data that's currently in the TX FIFO? + uint8_t d = *R_PS1_SIO1_DATA; + + while (*R_PS1_SIO1_STAT & (SIO_STAT_RX_OVRN_ERR | SIO_STAT_FRAME_ERR | SIO_STAT_PARITY_ERR)) { + // reset the interrupt and error + sio_reset(); + + delay_ms(5); + + // restore the TX FIFO? + *R_PS1_SIO1_DATA = d; + + // restore mode and ctrl + *R_PS1_SIO1_MODE = (sio_config.mode); + *R_PS1_SIO1_CTRL = (sio_config.ctrl | SIO_CTRL_RTR_EN); + } + } + } + ; + } else { + uint32_t tries = 0; + while (!(*R_PS1_SIO1_STAT & SIO_STAT_RX_RDY)) { + if (++tries >= timeout) goto _done; + } + } + + // pop a byte from the RX FIFO + ret = *R_PS1_SIO1_DATA; + +_done: + // RTR/RTS: off + *R_PS1_SIO1_CTRL &= ~(SIO_CTRL_RTR_EN); + + return ret; +} + +static int force_dos_line_endings = 1; + +int sio_putchar(char ch) +{ + if(ch == 0x0A) + { + if(force_dos_line_endings) + if(__last_sio_ch != 0x0D) sio_put_byte(0x0D); + } + + sio_put_byte(ch); + __last_sio_ch = ch; + return 0; +} + +void sio_puts(const char *s) +{ + while(*s != '\0') sio_putchar(*(s++)); +} + +void sio_print8(uint8_t d) +{ + const char hex_chars[] = "0123456789ABCDEF"; + sio_putchar(hex_chars[(d >> 4) & 0x0F]); + sio_putchar(hex_chars[d & 0x0F]); +} + +void sio_print16(uint16_t d) +{ + sio_print8((d >> 8) & 0xFF); + sio_print8((d >> 0) & 0xFF); +} + +void sio_print32(uint32_t d) +{ + sio_print8((d >> 24) & 0xFF); + sio_print8((d >> 16) & 0xFF); + sio_print8((d >> 8) & 0xFF); + sio_print8((d >> 0) & 0xFF); +} + +int sio_hook_putchar(void) +{ + uint32_t *table = GetB0Table(); + + _old_putchar = (void *) ((uint32_t *) 0x200)[60]; + ((uint32_t *) 0x200)[60] = (uint32_t) &sio_putchar; // hook 0xA0 call 60(putchar) + + _old__putchar = (void *) table[61]; + table[61] = (uint32_t) &sio_putchar; // hook 0xB0 call 61(_putchar) + + FlushCache(); + return 0; +} + +int sio_unhook_putchar(void) +{ + uint32_t *table = GetB0Table(); + + if(_old_putchar != NULL) + ((uint32_t *) 0x200)[60] = (uint32_t) _old_putchar; // restore 0xA0 call 60(putchar) + if(_old__putchar != NULL) + ((uint32_t *) table)[61] = (uint32_t) _old__putchar; // restore 0xB0 call 61(_putchar) +} + +//~ int sio_init_tty(int baud) +//~ { + //~ sio_init(1, baud); + //~ sio_hook_putchar(); +//~ } + +void init_sio(uint32_t baud) +{ + /* initialize SIO1 with RX and TX FIFOs enabled */ + *R_PS1_SIO1_CTRL = (SIO_CTRL_RX_EN | SIO_CTRL_TX_EN); + /* 8bit, no-parity, 1 stop-bit */ + *R_PS1_SIO1_MODE = (SIO_MODE_CHLEN_8 | SIO_MODE_P_NONE | SIO_MODE_SB_1 | SIO_MODE_BR_16); + *R_PS1_SIO1_BAUD = (2073600/baud); +} + +int DelSIO(void) { + close(stdin); + close(stdout); + DelDevice("tty"); + + sio_reset(); + + AddDummyConsoleDevice(); + + if (open("tty00:", O_RDONLY) != stdin) return 1; + if (open("tty00:", O_WRONLY) != stdout) return 1; + + return 0; +} + +int main(void) +{ + DelSIO(); + init_sio(115200); + + + // b0rked. Used to work, wtf did I fuck up? +// sio_hook_putchar(); + + sio_puts("Hello, pixel. Would you like to play a game?\n"); + sio_puts("No, this isn't a saw reference. Fuck them!\n"); + sio_puts("I'mma do it! Hold my beer!\n"); + + +// printf("I'mma do it!\n"); + + uint32_t d = *(uint32_t *) 0x1F801008; + d = (((d >> 16) + 4) << 16) | (d & 0xFFFF); + *(uint32_t *) 0x1F801008 = d; + +// printf("Done did it.\n"); + for(int addr = 0x1F000000; addr < 0x1F800000; addr += 0x00020000) + { + sio_print32(addr); + sio_puts(": 0x"); + sio_print32(*(uint32_t *) addr); +// sio_puts((const char *) (addr + 4)); + sio_puts("\n"); + } + + return 0; +} diff --git a/src/mips/serial/src/tty.c b/src/mips/serial/src/tty.c new file mode 100644 index 000000000..567064d4a --- /dev/null +++ b/src/mips/serial/src/tty.c @@ -0,0 +1,125 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either verttyn 2 of the License, or * + * (at your option) any later verttyn. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include "common/hardware/cop0.h" +#include "ps1sdk.h" +#include "ps1hwregs.h" +#include "serialio.h" +#include "tty.h" + +#include "fileio.h" + +static void *_old_putchar = NULL; +static void *_old__putchar = NULL; +static char __last_tty_ch = 0; + +static void sio_reset(void) { *R_PS1_SIO1_CTRL = SIO_CTRL_RESET_INT | SIO_CTRL_RESET_ERR; } + +static int force_dos_line_endings = 1; + +int tty_putchar(char ch) +{ + if(ch == 0x0A) + { + if(force_dos_line_endings) + if(__last_tty_ch != 0x0D) tty_put_byte(0x0D); + } + + tty_put_byte(ch); + __last_tty_ch = ch; + return 0; +} + +void tty_puts(const char *s) +{ + while(*s != '\0') tty_putchar(*(s++)); +} + +void tty_print8(uint8_t d) +{ + const char hex_chars[] = "0123456789ABCDEF"; + tty_putchar(hex_chars[(d >> 4) & 0x0F]); + tty_putchar(hex_chars[d & 0x0F]); +} + +void tty_print16(uint16_t d) +{ + tty_print8((d >> 8) & 0xFF); + tty_print8((d >> 0) & 0xFF); +} + +void tty_print32(uint32_t d) +{ + tty_print8((d >> 24) & 0xFF); + tty_print8((d >> 16) & 0xFF); + tty_print8((d >> 8) & 0xFF); + tty_print8((d >> 0) & 0xFF); +} + +int tty_hook_putchar(void) +{ + uint32_t *table = GetB0Table(); + + _old_putchar = (void *) ((uint32_t *) 0x200)[60]; + ((uint32_t *) 0x200)[60] = (uint32_t) &tty_putchar; // hook 0xA0 call 60(putchar) + + _old__putchar = (void *) table[61]; + table[61] = (uint32_t) &tty_putchar; // hook 0xB0 call 61(_putchar) + + FlushCache(); + return 0; +} + +int tty_unhook_putchar(void) +{ + uint32_t *table = GetB0Table(); + + if(_old_putchar != NULL) + ((uint32_t *) 0x200)[60] = (uint32_t) _old_putchar; // restore 0xA0 call 60(putchar) + if(_old__putchar != NULL) + ((uint32_t *) table)[61] = (uint32_t) _old__putchar; // restore 0xB0 call 61(_putchar) +} + +//~ int tty_init_tty(int baud) +//~ { + //~ tty_init(1, baud); + //~ tty_hook_putchar(); +//~ } + +int DelTTY(void) { + close(stdin); + close(stdout); + DelDevice("tty"); + + sio_reset(); + + AddDummyConsoleDevice(); + + if (open("tty00:", O_RDONLY) != stdin) return 1; + if (open("tty00:", O_WRONLY) != stdout) return 1; + + return 0; +} + +int init_tty(void) +{ + DelTTY(); + + return 0; +} diff --git a/src/mips/shell/Makefile b/src/mips/shell/Makefile index e5de4fbcc..f408d6914 100644 --- a/src/mips/shell/Makefile +++ b/src/mips/shell/Makefile @@ -1,4 +1,5 @@ -TARGET = shell +TARGET = shell.bin +LOAD_ADDR = 0x80030000 SRCS = \ ../common/hardware/cop0.s \ diff --git a/src/mips/shell/main/main.c b/src/mips/shell/main/main.c index a7e3c2b61..c29d04c50 100644 --- a/src/mips/shell/main/main.c +++ b/src/mips/shell/main/main.c @@ -19,6 +19,4 @@ #include "common/hardware/cop0.h" -int main() { - return 0; -} +int main() { return 0; } diff --git a/src/mips/shell/shell.ld b/src/mips/shell/shell.ld index 1fd397508..c28e5a3cf 100644 --- a/src/mips/shell/shell.ld +++ b/src/mips/shell/shell.ld @@ -24,7 +24,7 @@ EXTERN(_start) ENTRY(_start) MEMORY { - ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 + ram (rwx) : ORIGIN = 0x80030000, LENGTH = 2M - 0x30000 dcache : ORIGIN = 0x1f800000, LENGTH = 0x400 } diff --git a/src/mips/tester/Makefile b/src/mips/tester/Makefile new file mode 100644 index 000000000..8aafa5875 --- /dev/null +++ b/src/mips/tester/Makefile @@ -0,0 +1,15 @@ +TARGET = tester.psx +TLOAD_ADDR = 0x80100000 +SRCS = \ + crt0/crt0.S \ + src/main.c \ + src/flash.c \ + src/syscalls.S + +LIBS = + +LDSCRIPT = ./psx-exe.ld +CPPFLAGS := -Isrc -Iinclude -I../ps1sdk/include +LDFLAGS := + +include ../common.mk diff --git a/src/mips/tester/crt0/crt0-dummy.S b/src/mips/tester/crt0/crt0-dummy.S new file mode 100644 index 000000000..6ec5f9a0e --- /dev/null +++ b/src/mips/tester/crt0/crt0-dummy.S @@ -0,0 +1,37 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include + +.set push +.set noreorder +.set noat + + .section .start, "ax", @progbits + .align 2 + .global main + .global _start + .type _start, @function +.ent _start +_start: + li a0, 0 + j main + li a1, 0 +.end _start +.set pop diff --git a/src/mips/tester/crt0/crt0-x.S b/src/mips/tester/crt0/crt0-x.S new file mode 100644 index 000000000..e1d246126 --- /dev/null +++ b/src/mips/tester/crt0/crt0-x.S @@ -0,0 +1,64 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include + +.set push +.set noreorder +.set noat + + .section .start, "ax", @progbits + .align 2 + .global main + .global _start + .type _start, @function +_start: + la t0, __bss_start + la t1, __bss_end + addiu t1, t1, 3 + srl t1, t1, 2 + sll t1, t1, 2 + beq t0, t1, _zero_bss_done + nop + +_zero_bss: + sw zero, 0(t0) + addiu t0, t0, 4 + bne t0, t1, _zero_bss + nop + +_zero_bss_done: +/* la gp, _gp*/ + li a0, 0 + j main + li a1, 0 + +/* +.end _start +.data + +.bss +*/ + .extern __bss_start + .extern __bss_end + .extern _gp +/* int _main(int argc, const char **argv, const char **envp) */ + .extern main + +.set pop diff --git a/src/mips/tester/crt0/crt0.S b/src/mips/tester/crt0/crt0.S new file mode 100644 index 000000000..dd3241b33 --- /dev/null +++ b/src/mips/tester/crt0/crt0.S @@ -0,0 +1,56 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include + +.set push +.set noreorder +.set noat + + .section .start, "ax", @progbits + .align 2 + .global main + .global _start + .type _start, @function +_start: + la t0, __bss_start + la t1, __bss_end + addiu t1, t1, 3 + srl t1, t1, 2 + sll t1, t1, 2 + beq t0, t1, _zero_bss_done + nop + +_zero_bss: + sw zero, 0(t0) + addiu t0, t0, 4 + bne t0, t1, _zero_bss + nop + +_zero_bss_done: + li a0, 0 + j main + li a1, 0 + + .extern __bss_start + .extern __bss_end + .extern _gp + .extern main + +.set pop diff --git a/src/mips/tester/include/exec.h b/src/mips/tester/include/exec.h new file mode 100644 index 000000000..f81bfaf9e --- /dev/null +++ b/src/mips/tester/include/exec.h @@ -0,0 +1,57 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# "exec.h" for PS1. +# +*/ + +#ifndef _EXEC_H +#define _EXEC_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* Executable file types returned by LoadEx() */ +enum { ExecTypeUNK = 0, ExecTypePSX = 1, ExecTypeSCE = 2, ExecTypeECO = 3, ExecTypeCPE = 4 }; + +// sizeof() == 0x3C(60) +typedef struct st_ExecInfo { + uint32_t entry; // 0x00 : Address of program entry-point. + uint32_t init_gp; // 0x04 : SCE only. Initial value the "gp" register is set to. 0 for PS-X EXE. + uint32_t text_addr; // 0x08 : Memory address to which the .text section is loaded. + uint32_t text_size; // 0x0C : Size of the .text section in the file and memory. + uint32_t data_addr; // 0x10 : SCE only. Memory address to which the .data section is loaded. 0 for PS-X EXE. + uint32_t data_size; // 0x14 : SCE only. Size of the .data section in the file and memory. 0 for PS-X EXE. + uint32_t bss_addr; // 0x18 : Memory address of the .bss section. .bss is initialized by Exec(). + uint32_t bss_size; // 0x1C : Size of the .bss section in memory. + uint32_t stack_addr; // 0x20 : Memory address pointing to the bottom(lowest address) of the stack. BIOS replaces + // with "STACK" parameter of "SYSTEM.CNF" file. + uint32_t stack_size; // 0x24 : Size of the stack. Can be 0. + uint32_t saved_sp; // 0x28 : Used by BIOS Exec() function to preserve the "sp" register. + uint32_t saved_fp; // 0x2C : Used by BIOS Exec() function to preserve the "fp" register. + uint32_t saved_gp; // 0x30 : Used by BIOS Exec() function to preserve the "gp" register. + uint32_t saved_ra; // 0x34 : Used by BIOS Exec() function to preserve the "ra" register. + uint32_t saved_s0; // 0x38 : Used by BIOS Exec() function to preserve the "s0" register. +} ExecInfo; + +// sizeof() == 0x88(136) +typedef struct st_EXE_Header { + uint8_t magic[8]; // 0x00-0x07 : "PS-X EXE"(retail) or "SCE EXE"(???) + uint32_t text_off; // 0x08 : SCE only. Offset of the start of the .text section in the file. 0 for PS-X EXE. + uint32_t data_off; // 0x0C : SCE only. Offset of the start of the .text section in the file. 0 for PS-X EXE. + struct st_ExecInfo exec; // 0x10-0x4B + char license[60]; // 0x4C-0x87 + uint8_t __pad[1912]; // 0x88-0x7FF +} EXE_Header; + +int Exec2(ExecInfo* exec, uint32_t arg0, uint32_t arg1); + +#ifdef __cplusplus +} +#endif + +#endif /* _EXEC_H */ diff --git a/src/mips/tester/include/flash.h b/src/mips/tester/include/flash.h new file mode 100644 index 000000000..9e3e6dba3 --- /dev/null +++ b/src/mips/tester/include/flash.h @@ -0,0 +1,39 @@ +/* +# _____ ___ __ ___ ____ +# ____| | | | | |____| +# | ___| ___| ___| ____| | \ +#----------------------------------------------------------------------- +# +# "flash.h" - header of the flash memory library for PS1. +# +*/ + +#ifndef _FLASH_H +#define _FLASH_H + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/* macros */ +// test if bit 6 of any byte in the array toggles on consecutive reads +// which indicates that a Program or Erase operation is in progress. +#define isBitToggling(__base) (((((volatile uint8_t *) __base)[0] ^ ((volatile uint8_t *) __base)[0]) & (1 << 6)) != 0) + +/* prototypes */ +void Flash_Reset(void *base); +void Flash_Autoselect(void *base); +void Flash_SectorErase(void *base, uint32_t offset); +void Flash_ChipErase(void *base);; +void Flash_Program(void *base, uint32_t offs, void *src, uint32_t size); +void FlashUnlockCycle(void *base, uint8_t cmd); +void Flash_ProgramFast(void *base, uint32_t offs, void *src, uint32_t size); +uint32_t flash_detect(void *base, uint16_t *p_mid, uint16_t *p_did); + +#ifdef __cplusplus +} +#endif + +#endif /* _FLASH_H */ diff --git a/src/mips/tester/include/ftfifo.h b/src/mips/tester/include/ftfifo.h new file mode 100644 index 000000000..f87d02512 --- /dev/null +++ b/src/mips/tester/include/ftfifo.h @@ -0,0 +1,41 @@ +#ifndef _FTFIFO_H +#define _FTFIFO_H + +#ifdef __cplusplus +extern "C" { +#endif + +#define FTFIFO_DATA ((volatile uint8_t *)0x1F000000) +#define FTFIFO_STAT ((volatile uint8_t *)0x1F000001) +#define FTFIFO_STAT_RXRDY (1 << 0) +#define FTFIFO_STAT_TXRDY (1 << 1) + +#define FTFIFO_RX_Ready() ((*FTFIFO_STAT & (FTFIFO_STAT_RXRDY)) == (FTFIFO_STAT_RXRDY)) +#define FTFIFO_TX_Ready() ((*FTFIFO_STAT & (FTFIFO_STAT_TXRDY)) == (FTFIFO_STAT_TXRDY)) +#define FTFIFO_Ready() ((*FTFIFO_STAT & (FTFIFO_STAT_RXRDY | FTFIFO_STAT_TXRDY)) == (FTFIFO_STAT_RXRDY | FTFIFO_STAT_TXRDY)) + +static inline uint8_t FT_get(void) +{ + while(!FTFIFO_RX_Ready()); + return *FTFIFO_DATA; +} + +static inline void FT_put(uint8_t d) +{ + while(!FTFIFO_TX_Ready()); + *FTFIFO_DATA = d; +} + +uint8_t FT_peek8(uint32_t timeout, int *presult); +uint16_t FT_peek16(uint32_t timeout, int *presult); +uint32_t FT_peek32(uint32_t timeout, int *presult); + +int FT_poke8(uint8_t d, uint32_t timeout); +int FT_poke16(uint16_t d, uint32_t timeout); +int FT_poke32(uint32_t d, uint32_t timeout); + +#ifdef __cplusplus +} +#endif + +#endif /* _FTFIFO_H */ diff --git a/src/mips/tester/include/serialio.h b/src/mips/tester/include/serialio.h new file mode 100644 index 000000000..834ea48c7 --- /dev/null +++ b/src/mips/tester/include/serialio.h @@ -0,0 +1,145 @@ +/* + * File: serialio.h + * Author: asmblur + * + * Created on February 10, 2009, 1:13 AM + * Reversed on September 2, 2019 + */ + +#ifndef _SERIALIO_H +#define _SERIALIO_H + +#ifdef __cplusplus +extern "C" { +#endif + +/* + * Definitions: + * + * DTE(Data Terminal Equiptment): a PC/PS/etc(Not a modem) + * DCE(Data Communications Equiptment): a modem + * + * RTS-CTS flow control: + * RTS/RTR: Request To Send/Ready To Receive, assert to indicate readiness to receive data + * CTS: Clear To Send, input from RTR of other. + * + * DTR: Data Terminal Ready, assert to indicate readiness to communicate + * DSR: Data Set Ready, input from DTR of other + * + * + * + * + */ + +// bits for STATUS +// SIO Interrupt Pending +#define SIO_STAT_IRQ 0x0200 +#define SIO_STAT_CTS 0x0100 +#define SIO_STAT_DSR 0x0080 +#define SIO_STAT_SYNC_DET 0x0040 +#define SIO_STAT_FRAME_ERR 0x0020 +#define SIO_STAT_RX_OVRN_ERR 0x0010 +#define SIO_STAT_PARITY_ERR 0x0008 +#define SIO_STAT_TX_EMPTY 0x0004 +#define SIO_STAT_RX_RDY 0x0002 +#define SIO_STAT_TX_RDY 0x0001 +#define SIO_STAT_MASK (0x03FF) + +// bits for CONTROL + +// enable DSR interrupts. +#define SIO_CTRL_DSRI_EN 0x1000 +// enable RXD interrupts. +#define SIO_CTRL_RXI_EN 0x0800 +// enable TXD interrupts. +#define SIO_CTRL_TXI_EN 0x0400 +#define SIO_CTRL_BUF8 0x0300 +#define SIO_CTRL_BUF4 0x0200 +#define SIO_CTRL_BUF2 0x0100 +#define SIO_CTRL_BUF1 0x0000 +// why is there nothing for bit 7? CTRL_BUFx is bits 9-10 +#define SIO_CTRL_RESET_INT 0x0040 +// enable RTS driver(inverted) +#define SIO_CTRL_RTS_EN 0x0020 +#define SIO_CTRL_RTR_EN 0x0020 +#define SIO_CTRL_RESET_ERR 0x0010 +#define SIO_CTRL_BRK 0x0008 +// enable RXD +#define SIO_CTRL_RX_EN 0x0004 +// enable DTR driver(inverted) +#define SIO_CTRL_DTR_EN 0x0002 +// enable TXD +#define SIO_CTRL_TX_EN 0x0001 +#define SIO_CTRL_MASK (0x1FFF) + +/* + * SIO1 + * Pins go from left to right + * + * NOTE: All pins except for RXD, TXD, GND and 3V3 are inverted. + * + * Pin Name Dir Notes + * ----- ----- --- ---------- + * 1 RXD I Receive Data + * 2 3V3 3.3V output + * 3 DSR I Data Set Ready + * 4 TXD O Transmit Data + * 5 CTS O Clear To Send + * 6 DTR I Data Terminal Ready + * 7 GND Ground + * 8 RTS O Request To Send + */ + +// Bits for MODE + +// MODE: Stop Bits +// bits 6-7 +#define SIO_MODE_SB_1 0x0040 +#define SIO_MODE_SB_1_5 0x0080 +#define SIO_MODE_SB_2 0x00C0 + +// MODE: Parity +// bits 4-5 +#define SIO_MODE_P_NONE 0x0000 +#define SIO_MODE_P_ODD 0x0010 +#define SIO_MODE_P_EVEN 0x0030 + +// MODE: Character Length(Bits Per Character) +// bits 2-3 +#define SIO_MODE_CHLEN_5 0x0000 +#define SIO_MODE_CHLEN_6 0x0004 +#define SIO_MODE_CHLEN_7 0x0008 +#define SIO_MODE_CHLEN_8 0x000C + +// MODE: Baud Rate multiplier(??) +// NOTE: supposedly these 2 bits should always be "10"(2).. +// bits 0-1 +#define SIO_MODE_BR_1 0x0001 +#define SIO_MODE_BR_16 0x0002 +#define SIO_MODE_BR_64 0x0003 + +#define SIO_MODE_MASK 0x00FF + +#define R_PS1_SIO1_DATA ((volatile uint8_t *) 0x1F801050) +#define R_PS1_SIO1_STAT ((volatile uint16_t *) 0x1F801054) +#define R_PS1_SIO1_MODE ((volatile uint16_t *) 0x1F801058) +#define R_PS1_SIO1_CTRL ((volatile uint16_t *) 0x1F80105A) +#define R_PS1_SIO1_BAUD ((volatile uint16_t *) 0x1F80105E) + +/* prototypes */ +void psio_init(void); +void sio_reset(void); + +uint8_t psio_get(void); +uint16_t psio_get16(void); +uint32_t psio_get32(void); + +void psio_put(uint8_t d); +void psio_put16(uint16_t d); +void psio_put32(uint32_t d); + +#ifdef __cplusplus +} +#endif + +#endif /* _SERIALIO_H */ diff --git a/src/mips/tester/include/tester.h b/src/mips/tester/include/tester.h new file mode 100644 index 000000000..b5992f7f4 --- /dev/null +++ b/src/mips/tester/include/tester.h @@ -0,0 +1,21 @@ +#ifndef _TESTER_H +#define _TESTER_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include "common/compiler/stdint.h" +#include "exec.h" +#include "serialio.h" + +extern void FlushCache(void); +extern int printf(const char * fmt, ...); +// void shortWait(uint32_t n); +// void longWait(uint32_t n); + +#ifdef __cplusplus +} +#endif + +#endif /* _TESTER_H */ diff --git a/src/mips/tester/psx-exe.ld b/src/mips/tester/psx-exe.ld new file mode 100644 index 000000000..48780cec2 --- /dev/null +++ b/src/mips/tester/psx-exe.ld @@ -0,0 +1,163 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +OUTPUT_FORMAT("elf32-tradlittlemips") +OUTPUT_FORMAT("binary") + +EXTERN(_start) +ENTRY(_start) + +TLOAD_ADDR = DEFINED(_TLOAD_ADDR) ? TLOAD_ADDR : 0x80010000; + +MEMORY { + loader : ORIGIN = 0x8000f800, LENGTH = 2048 + ram (rwx) : ORIGIN = 0x80010000, LENGTH = 2M - 0x10000 + dcache : ORIGIN = 0x1f800000, LENGTH = 0x400 +} + +__ram_top = ORIGIN(ram) + LENGTH(ram); +__sp = __ram_top - 0x100; + +__dcache = ORIGIN(dcache); +__dcache_top = ORIGIN(dcache) + LENGTH(dcache); + +__bss_len = (__bss_end - __bss_start); +__ftext_len = (__ftext_end - __ftext_start); +__fdata_len = (__fdata_end - __fdata_start); + +SECTIONS { + .PSX_EXE_Header : { + /* + 0x0000 - 0x0007 : "PS-X EXE" + */ + BYTE(80); BYTE(83); BYTE(45); BYTE(88); BYTE(32); BYTE(69); BYTE(88); BYTE(69); + + /* 0x0008 - 0x000F : skip text_off and data_off since they're not supported by the PS1 BIOS */ + LONG(0); LONG(0); + + /* 0x0010 - 0x0013 : entry point */ + LONG(ABSOLUTE(_start)); + + /* 0x0014 - 0x0017 : initial value of $gp */ + LONG(0); + + /* 0x0018 - 0x001B : Memory address to load "text" section to. */ + /* + NOTE: The "text" section is actually all of the "load" + sections of the file including .text, .rodata, .data. + etc. + */ + LONG(TLOAD_ADDR); + + /* 0x001C - 0x001F : size, in bytes, of the "text" section. */ + LONG(__ftext_len + __fdata_len); + + /* 0x0020 - 0x002F : + Skip "data_addr", "data_size", "bss_addr" and "bss_size". + None of these are supported by retail PS1 BIOS. + */ + LONG(0); LONG(0); + LONG(0); LONG(0); + + /* 0x0030 - 0x0033 : Initial stack address. */ + LONG(DEFINED(_sp) ? ABSOLUTE(_sp) : 0x801FFF00); + + /* 0x0034 - 0x0037 : Initial stack size, set it to 0. */ + LONG(0); + + /* Skip the remaining fields as they're not supported by the BIOS */ + . = . + 1992; + } > loader + + __ftext_start = ABSOLUTE(.); + .text TLOAD_ADDR : { + *(.start) + *(.init) + KEEP (*(SORT_NONE(.fini))) + *(.text.unlikely .text.*_unlikely .text.unlikely.*) + *(.text.exit .text.exit.*) + *(.text.startup .text.startup.*) + *(.text.hot .text.hot.*) + *(.text .stub .text.* .gnu.linkonce.t.*) + . = ALIGN(16); + } > ram + + .fini : { + . = ALIGN(16); + } > ram + + . = ALIGN(16); + __text_end = .; + __ftext_end = ABSOLUTE(.); + + __fdata_start = ABSOLUTE(.); + + .rodata : { + *(.rodata .rodata.* .rdata .rdata.* .gnu.linkonce.r.*) + } > ram + + .rodata1 : { + *(.rodata1) + } > ram + + __data_start = .; + .data : { + *(.a0table) + *(.data .data.* .gnu.linkonce.d.*) + *(.data1) + *(.got.plt) + *(.got) + } > ram + + . = ALIGN(4); + __data_end = .; + __fdata_end = .; + __bss_start = .; + .sbss : { + *(.dynsbss) + *(.sbss .sbss.* .gnu.linkonce.sb.*) + *(.scommon) + *(.dynbss) + *(.bss .bss.* .gnu.linkonce.b.*) + *(COMMON) + } > ram + + . = ALIGN(4); + __bss_end = .; + + __end = .; + + /* pad file to be a multiple of 2048 bytes. Needed for loading from CD-ROM. */ + /* .__pad : { BYTE(0); . = ALIGN(2048); }*/ + . = ADDR(.text) - 0x800; + + + /DISCARD/ : { *(.MIPS.abiflags) } + + /* Everything is statically linked, so discard PLTs. */ + /DISCARD/ : { *(.rel.iplt) *(.rela.iplt) *(.rel.plt) *(.rela.plt) *(.plt) *(.iplt) } + + /* We don't make use of debugging information, so drop that, too. */ + /DISCARD/ : { *(.debug) *(.debug_srcinfo) *(.debug_sfnames) *(.debug_aranges) *(.debug_pubnames) *(.debug_info .gnu.linkonce.wi.*) *(.debug_abbrev) *(.debug_line .debug_line.* .debug_line_end ) *(.debug_frame) *(.debug_str) *(.debug_loc) *(.debug_macinfo) *(.debug_weaknames) *(.debug_funcnames) *(.debug_typenames) *(.debug_varnames) *(.debug_pubtypes) *(.debug_ranges) *(.debug_macro) *(.mdebug.abi32) *(.mdebug.abiN32) *(.mdebug.abi64) *(.mdebug.abiO64) *(.mdebug.eabi32) *(.mdebug.eabi64) } + + /* Discard things that the standard link script drops, too. */ + /DISCARD/ : { *(.note.GNU-stack) *(.gnu_debuglink) *(.gnu.lto_*) } + + /DISCARD/ : { *(.note.gnu.build-id) } +} diff --git a/src/mips/tester/src/delay.S b/src/mips/tester/src/delay.S new file mode 100644 index 000000000..7df659ba1 --- /dev/null +++ b/src/mips/tester/src/delay.S @@ -0,0 +1,37 @@ +.set push +.set noreorder +.set noat + +#include + +.text + +.global shortWait +.type shortWait, @function +.ent shortWait +shortWait: +_shortWait_l1: + bnez a0, _shortWait_l1 + addiu a0, a0, -1 + jr ra + nop +.end shortWait + +/* this will only be accurate if interrupts are disabled */ + +/* aka "longWait()" */ +.global delay_ms +.type delay_ms, @function +.ent delay_ms +delay_ms: + li t0, 1665 +_delay_ms_l2: + bnez t0, _delay_ms_l2 + addiu t0, -1 + bnez a0, delay_ms + addiu a0, -1 + jr ra + nop +.end delay_ms + +.set pop diff --git a/src/mips/tester/src/flash.c b/src/mips/tester/src/flash.c new file mode 100644 index 000000000..f24bfc020 --- /dev/null +++ b/src/mips/tester/src/flash.c @@ -0,0 +1,122 @@ +#include "flash.h" + +// performs a 3-byte "unlock cycle" +#define M_FlashUnlockCycle(__base, __cmd) \ +{ \ + ((volatile uint8_t *) __base)[0xAAA] = ((uint8_t) 0xAA); \ + ((volatile uint8_t *) __base)[0x555] = ((uint8_t) 0x55); \ + ((volatile uint8_t *) __base)[0xAAA] = ((uint8_t) (__cmd)); \ +} + +void FlashUnlockCycle(void *base, uint8_t cmd) { M_FlashUnlockCycle(base, cmd); } + +// reset the device state +void Flash_Reset(void *base) { ((volatile uint8_t *) base)[0x555] = 0xF0; } + +// enters "Autoselect" mode which allows access to chip information +// by reading from addresses 0+ +// Muse be exited with a Reset(see Flash_Reset) +void Flash_Autoselect(void *base) { M_FlashUnlockCycle(base, 0x90); } + +void Flash_ChipErase(void *base) +{ + M_FlashUnlockCycle(base, 0x80); // Unlock Cycle 1 + M_FlashUnlockCycle(base, 0x10); // Unlock Cycle 2 + + // wait for operation to complete. + while(isBitToggling(base)); +} + +// erases a sector +void Flash_SectorErase(void *base, uint32_t offset) +{ + M_FlashUnlockCycle(base, 0x80); // Unlock Cycle 1 + + ((volatile uint8_t *) base)[0xAAA] = (uint8_t) 0xAA; // Unlock Cycle 2 + ((volatile uint8_t *) base)[0x555] = (uint8_t) 0x55; + ((volatile uint8_t *) base)[offset] = (uint8_t) 0x30; + + // wait for operation to complete. + while(isBitToggling(base + offset)); +} + +// programs "size" number of data from "src" to flash starting at (base + offs) +// NOTE: Flash_ProgramFast() is a better option. +void Flash_Program(void *base, uint32_t offs, void *src, uint32_t size) +{ + int i; + + volatile uint8_t *b = (volatile uint8_t *) base; + volatile uint8_t *d = (volatile uint8_t *) base + offs; + volatile uint8_t *s = (volatile uint8_t *) src; + + for(i = 0; i < size; i++) + { + M_FlashUnlockCycle(b, 0xA0); // Unlock Cycle 1(3 cycles) + d[i] = s[i]; + // I don't *think* you have to wait for bit toggling to cease here... + } + + // wait for operation to complete. + while(isBitToggling(base)); +} + +// programs "size" number of data from "src" to flash starting at (base + offs). +// NOTE: uses the "Unlock Bypass" mode along with the "Unlock Bypass Program" +// command instead of the normal "Program" command. This reduces programming by +// about half the cycles. +void Flash_ProgramFast(void *base, uint32_t offs, void *src, uint32_t size) +{ + int i; + + volatile uint8_t *b = (volatile uint8_t *) base; + volatile uint8_t *d = (volatile uint8_t *) base + offs; + volatile uint8_t *s = (volatile uint8_t *) src; + + M_FlashUnlockCycle(base, 0x20); // "Unlock Bypass" + + for(i = 0; i < size; i++) + { + b[0xAAA] = 0xA0; // Unlock Bypass Program + d[i] = s[i]; // program 1 byte + // I don't *think* you have to wait for bit toggling to cease here... + } + + b[0] = 0x90; // Unlock Bypass Reset(2 cycles) + b[0] = 0x00; + + // wait for operation to complete. + while(isBitToggling(base)); +} + +// try to detect flash memory device at "base". +// args: +// base: base address pointer of device. +// p_mid: pointer where a uint16_t containing the manufacturer ID can be written. +// Can be NULL. +// p_did: pointer where a uint16_t containing the device ID can be written. +// Can be NULL. +// returns: +// lower 16: manufacturer ID +// upper 16: device ID +// +// NOTE: No attempt is made to validate these IDs! They may be completely bogus if there's no device or it doesn't support +// this method of reading the IDs. +// +uint32_t flash_detect(void *base, uint16_t *p_mid, uint16_t *p_did) +{ + uint16_t man_id, dev_id; + volatile uint8_t *p = (volatile uint8_t *) base; + + Flash_Autoselect(base); // enter Autoselect mode + + man_id = p[0x000]; // byte 0 is the manufacturer ID + dev_id = p[0x001]; // byte 1 is the device ID + // CFI stuff next but we don't need it + + Flash_Reset(base); // reset the device to exit Autoselect mode + + if(p_mid) *p_mid = man_id; + if(p_did) *p_did = dev_id; + return (man_id | (dev_id << 16)); +} diff --git a/src/mips/tester/src/main.c b/src/mips/tester/src/main.c new file mode 100644 index 000000000..d6d1c24d8 --- /dev/null +++ b/src/mips/tester/src/main.c @@ -0,0 +1,266 @@ +/*************************************************************************** + * Copyright (C) 2019 PCSX-Redux authors * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. * + ***************************************************************************/ + +#include "tester.h" +#include "flash.h" + +struct rc4_key { + unsigned char state[256]; + unsigned x, y; +}; + +/* expand a key (makes a rc4_key) */ +void prepare_key(unsigned char *keydata, unsigned len, struct rc4_key *key) +{ + unsigned index1, index2, counter; + unsigned char *state; + + state = key->state; + + for (counter = 0; counter < 256; counter++) + state[counter] = counter; + + key->x = key->y = index1 = index2 = 0; + + for (counter = 0; counter < 256; counter++) { + index2 = (keydata[index1] + state[counter] + index2) & 255; + + /* swap */ + state[counter] ^= state[index2]; + state[index2] ^= state[counter]; + state[counter] ^= state[index2]; + + index1 = (index1 + 1) % len; + } +} + +/* reversible encryption, will encode a buffer updating the key */ +uint8_t rc4(struct rc4_key *key) +{ + unsigned x, y, xorIndex, counter; + unsigned char *state; + uint8_t ret; + + /* get local copies */ + x = key->x; y = key->y; + state = key->state; + + x = (x + 1) & 255; + y = (state[x] + y) & 255; + + /* swap */ + state[x] ^= state[y]; + state[y] ^= state[x]; + state[x] ^= state[y]; + + xorIndex = (state[y] + state[x]) & 255; + + ret = state[xorIndex]; + + key->x = x; key->y = y; + + return ret; +} + +#define SIZE (2 * 1024 * 1024) + +void main(void) +{ + volatile uint8_t * base; + + printf("\r\n\r\nSetting EXT1 to 8MB...\r\n\r\n"); + *((volatile uint32_t *) 0x1f801008) = (23 << 16) | 0x243f; + + base = (volatile uint8_t *) 0x1f400000; + printf("\r\n\r\nDone... writing to sram now...\r\n\r\n"); + + struct rc4_key key; + + prepare_key("Sram Test Vector", 16, &key); + for (int i = 0; i < SIZE; i++) { + base[i] = rc4(&key); + } + + printf("\r\n\r\nDone... reading sram now...\r\n\r\n"); + + prepare_key("Sram Test Vector", 16, &key); + int good = 1; + int count = 0; + uintptr_t block = 0; + for (int i = 0; i < SIZE; i++) { + uint8_t c = rc4(&key); + uint8_t r = base[i]; + if (c != r) { + good = 0; + count++; + if (count < 16) { + printf("Byte at %08x is mismatching: %02x instead of %02x\r\n", i, r, c); + } else if (count == 16) { + printf("Too many mismatches...\r\n\r\n"); + } + } + } + + if (good) { + printf("\r\n\r\nSRAM good\r\n\r\n"); + } else { + printf("\r\n\r\nSRAM not good: %i bytes are mismatching\r\n\r\n", count); + } + + printf("\r\n\r\nDone... reading flash1 now...\r\n\r\n"); + base = (volatile uint8_t *) 0x1f000000; + +{ + base[0xAAA] = 0xAA; + base[0x555] = 0x55; + base[0xAAA] = 0x90; + uint8_t mid1 = base[0x00]; + uint8_t did1 = base[0x02]; + uint8_t mid2 = base[0x00]; + uint8_t did2 = base[0x02]; + uint8_t mid3 = base[0x00]; + uint8_t did3 = base[0x02]; + uint8_t mid4 = base[0x00]; + uint8_t did4 = base[0x02]; + + base[0xAAA] = 0xF0; + printf("\r\n\r\nflash tester\r\nMID: 0x%04X\r\nDID: 0x%04X\r\n", mid1, did1); + printf("\r\n\r\nflash tester\r\nMID: 0x%04X\r\nDID: 0x%04X\r\n", mid2, did2); + printf("\r\n\r\nflash tester\r\nMID: 0x%04X\r\nDID: 0x%04X\r\n", mid3, did3); + printf("\r\n\r\nflash tester\r\nMID: 0x%04X\r\nDID: 0x%04X\r\n", mid4, did4); + printf("\r\n\r\n[0] = %02x, [2] = %02x\r\n\r\n", base[0], base[2]); + + volatile uint8_t * rc4data = (volatile uint8_t *) 0x1f400000; + + printf("Erasing flash1...\r\n\r\n"); + Flash_ChipErase(base); + + printf("Programming flash1...\r\n\r\n"); + Flash_Program(base, 0, rc4data, 2 * 1024 * 1024); + + printf("Done... Reading back...\r\n\r\n"); + + uint32_t i = 0; + good = 1; + count = 0; + for (i = 0; i < 2 * 1024 * 1024; i++) { + uint8_t c = rc4data[i]; + uint8_t r = base[i]; + if (c != r) { + good = 0; + count++; + if (count < 16) { + printf("Byte at %08x is mismatching: %02x instead of %02x\r\n", i, r, c); + } else if (count == 16) { + printf("Too many mismatches...\r\n\r\n"); + } + } + } + + if (good) { + printf("\r\n\r\nFlash1 looks good\r\n\r\n"); + } else { + printf("\r\n\r\nFlash1 not good: %i bytes are mismatching\r\n\r\n", count); + } +} + + printf("\r\n\r\nDone... reading flash2 now...\r\n\r\n"); + base = (volatile uint8_t *) 0x1f200000; + +{ + volatile uint8_t * bios = (volatile uint8_t *) 0xbfc00000; + base[0xAAA] = 0xAA; + base[0x555] = 0x55; + base[0xAAA] = 0x90; + uint8_t mid1 = base[0x00]; + uint8_t did1 = base[0x02]; + uint8_t mid2 = base[0x00]; + uint8_t did2 = base[0x02]; + uint8_t mid3 = base[0x00]; + uint8_t did3 = base[0x02]; + uint8_t mid4 = base[0x00]; + uint8_t did4 = base[0x02]; + + base[0xAAA] = 0xF0; + printf("\r\n\r\nflash tester\r\nMID: 0x%04X\r\nDID: 0x%04X\r\n", mid1, did1); + printf("\r\n\r\nflash tester\r\nMID: 0x%04X\r\nDID: 0x%04X\r\n", mid2, did2); + printf("\r\n\r\nflash tester\r\nMID: 0x%04X\r\nDID: 0x%04X\r\n", mid3, did3); + printf("\r\n\r\nflash tester\r\nMID: 0x%04X\r\nDID: 0x%04X\r\n", mid4, did4); + printf("\r\n\r\n[0] = %02x, [2] = %02x\r\n\r\n", base[0], base[2]); + + uint32_t i = 0; + good = 1; + count = 0; + for (i = 0; i < 512 * 1024; i++) { + uint8_t c = bios[i]; + uint8_t r = base[i]; + if (c != r) { + good = 0; + count++; + if (count < 16) { + printf("Byte at %08x is mismatching: %02x instead of %02x\r\n", i, r, c); + } else if (count == 16) { + printf("Too many mismatches...\r\n\r\n"); + } + } + } + + if (good) { + printf("\r\n\r\nFlash2 looks good\r\n\r\n"); + } else { + printf("\r\n\r\nFlash2 not good: %i bytes are mismatching\r\n\r\n", count); + } +} + + base = (volatile uint8_t *) 0x1f600004; + + base[1] = 0x01; + printf("\r\n\r\n[0] = %02x\r\n\r\n", base[0]); + + base[1] = 0x06; + base[0] = 0x55; + printf("\r\n\r\n[0] = %02x\r\n\r\n", base[0]); + + base[1] = 0x06; + base[0] = 0xaa; + printf("\r\n\r\n[0] = %02x\r\n\r\n", base[0]); + + base = (volatile uint8_t *) 0x1f600007; + printf("\r\n\r\nbits = %02x\r\n\r\n", base[0]); + base[0] = 0xff; + printf("\r\n\r\nbits = %02x\r\n\r\n", base[0]); + base[0] = 0x00; + printf("\r\n\r\nbits = %02x\r\n\r\n", base[0]); + base[0] = 0x55; + printf("\r\n\r\nbits = %02x\r\n\r\n", base[0]); + base[0] = 0xaa; + printf("\r\n\r\nbits = %02x\r\n\r\n", base[0]); + + base = (volatile uint8_t *) 0x1f600006; + + int p = -1; + while (1) { + uint8_t b = base[0]; + base[0] = b; + if (p != b) { + printf("New switches values: %02x\r\n\r\n", b); + p = b; + } + } +} diff --git a/src/mips/tester/src/syscalls.S b/src/mips/tester/src/syscalls.S new file mode 100644 index 000000000..d675f5fc5 --- /dev/null +++ b/src/mips/tester/src/syscalls.S @@ -0,0 +1,53 @@ +.set push +.set noreorder +.set noat + +#include + +.text + +.macro M_KCALL, label, tablenum, callnum +.global \label +.type \label, @function +.ent \label +\label: + li t2, \tablenum + jr t2 + li t1, \callnum +.end \label +.endm + +.macro M_SYSCALL, label, callNum +.global \label +.type \label, @function +.ent \label +\label: + li a0, \callNum + syscall + jr ra + nop +.end \label +.endm + +/* this will only be accurate if interrupts are disabled */ +.global delay_ms +.type delay_ms, @function +.ent delay_ms +delay_ms: + li t0, 1665 +_delay_ms_l2: + bnez t0, _delay_ms_l2 + addiu t0, -1 + bnez a0, delay_ms + addiu a0, -1 + jr ra + nop +.end delay_ms + +M_KCALL printf, 0xA0, 0x003F +//M_KCALL FlushCache, 0xA0, 0x0044 + +//M_SYSCALL EnterCriticalSection, 1 +//M_SYSCALL ExitCriticalSection, 2 + +.set pop diff --git a/src/spu/adsr.cc b/src/spu/adsr.cc index 5822711a0..70198fa8e 100644 --- a/src/spu/adsr.cc +++ b/src/spu/adsr.cc @@ -71,7 +71,7 @@ PCSX::SPU::ADSR::Table::Table() // INIT ADSR //////////////////////////////////////////////////////////////////////// -void PCSX::SPU::ADSR::start(SPUCHAN *pChannel) // MIX ADSR +void PCSX::SPU::ADSR::start(SPUCHAN* pChannel) // MIX ADSR { pChannel->ADSRX.get().value = 1; // and init some adsr vars pChannel->ADSRX.get().value = 0; @@ -80,7 +80,7 @@ void PCSX::SPU::ADSR::start(SPUCHAN *pChannel) // MIX ADSR //////////////////////////////////////////////////////////////////////// -int PCSX::SPU::ADSR::mix(SPUCHAN *ch) { +int PCSX::SPU::ADSR::mix(SPUCHAN* ch) { uint32_t disp; int32_t EnvelopeVol = ch->ADSRX.get().value; diff --git a/src/spu/adsr.h b/src/spu/adsr.h index 861c88f3e..75a9e16d7 100644 --- a/src/spu/adsr.h +++ b/src/spu/adsr.h @@ -40,10 +40,12 @@ class ADSR { private: static inline const uint32_t m_tableDisp[] = { - -0x18 + 0 + 32, -0x18 + 4 + 32, -0x18 + 6 + 32, -0x18 + 8 + 32, // release/decay + -0x18 + 0 + 32, -0x18 + 4 + 32, -0x18 + 6 + 32, + -0x18 + 8 + 32, // release/decay -0x18 + 9 + 32, -0x18 + 10 + 32, -0x18 + 11 + 32, -0x18 + 12 + 32, - -0x1B + 0 + 32, -0x1B + 4 + 32, -0x1B + 6 + 32, -0x1B + 8 + 32, // sustain + -0x1B + 0 + 32, -0x1B + 4 + 32, -0x1B + 6 + 32, + -0x1B + 8 + 32, // sustain -0x1B + 9 + 32, -0x1B + 10 + 32, -0x1B + 11 + 32, -0x1B + 12 + 32, }; diff --git a/src/spu/cfg.cc b/src/spu/cfg.cc index ff2e44b8c..163a3a1e1 100644 --- a/src/spu/cfg.cc +++ b/src/spu/cfg.cc @@ -22,7 +22,7 @@ #include "core/system.h" #include "spu/interface.h" -static void ShowHelpMarker(const char *desc) { +static void ShowHelpMarker(const char* desc) { ImGui::SameLine(); ImGui::TextDisabled("(?)"); if (ImGui::IsItemHovered()) { @@ -48,7 +48,7 @@ bool PCSX::SPU::impl::configure() { ShowHelpMarker(_(R"(Uncheck this to mute the streaming channel from the main CPU to the SPU. This includes XA audio and audio tracks.)")); - const char *volumeValues[] = {_("Low"), _("Medium"), _("Loud"), _("Loudest")}; + const char* volumeValues[] = {_("Low"), _("Medium"), _("Loud"), _("Loudest")}; changed |= ImGui::Combo(_("Volume"), &settings.get().value, volumeValues, IM_ARRAYSIZE(volumeValues)); changed |= ImGui::Checkbox(_("Change streaming pitch"), &settings.get().value); ShowHelpMarker(_(R"(Attempts to make the CPU-to-SPU audio stream @@ -57,10 +57,10 @@ in sync, by changing its pitch. Consumes more CPU.)")); ShowHelpMarker(_(R"(Suspends the SPU processing during an IRQ, waiting for the main CPU to acknowledge it. Fixes issues with some games, but slows SPU processing.)")); - const char *reverbValues[] = {_("None - fastest"), _("Simple - only handles the most common effects"), + const char* reverbValues[] = {_("None - fastest"), _("Simple - only handles the most common effects"), _("Accurate - best quality, but slower")}; changed |= ImGui::Combo(_("Reverb"), &settings.get().value, reverbValues, IM_ARRAYSIZE(reverbValues)); - const char *interpolationValues[] = {_("None - fastest"), _("Simple interpolation"), + const char* interpolationValues[] = {_("None - fastest"), _("Simple interpolation"), _("Gaussian interpolation - good quality"), _("Cubic interpolation - better treble")}; changed |= ImGui::Combo(_("Interpolation"), &settings.get().value, interpolationValues, diff --git a/src/spu/freeze.cc b/src/spu/freeze.cc index 6b6ce83ac..4ca7dd827 100644 --- a/src/spu/freeze.cc +++ b/src/spu/freeze.cc @@ -59,35 +59,35 @@ typedef struct { // SPUFREEZE: called by main emu on savestate load/save //////////////////////////////////////////////////////////////////////// -void PCSX::SPU::impl::save(SaveStates::SPU &spu) { +void PCSX::SPU::impl::save(SaveStates::SPU& spu) { RemoveThread(); - spu.get().copyFrom(reinterpret_cast(spuMem)); - spu.get().copyFrom(reinterpret_cast(regArea)); - auto &xa = spu.get(); + spu.get().copyFrom(reinterpret_cast(spuMem)); + spu.get().copyFrom(reinterpret_cast(regArea)); + auto& xa = spu.get(); if (xapGlobal) { xa.get().value = xapGlobal->freq; xa.get().value = xapGlobal->nbits; xa.get().value = xapGlobal->nsamples; xa.get().value = xapGlobal->stereo; - auto &left = xa.get(); + auto& left = xa.get(); left.get().value = xapGlobal->left.y0; left.get().value = xapGlobal->left.y1; - auto &right = xa.get(); + auto& right = xa.get(); right.get().value = xapGlobal->right.y0; right.get().value = xapGlobal->right.y1; - xa.get().copyFrom(reinterpret_cast(xapGlobal->pcm)); + xa.get().copyFrom(reinterpret_cast(xapGlobal->pcm)); } spu.get().value = spuIrq; if (pSpuIrq) spu.get().value = uintptr_t(pSpuIrq - spuMemC); for (unsigned i = 0; i < MAXCHAN; i++) { - auto &channel = spu.get().value[i]; - auto &data = channel.get(); + auto& channel = spu.get().value[i]; + auto& data = channel.get(); data = s_chan[i].data; channel.get() = s_chan[i].ADSR; channel.get() = s_chan[i].ADSRX; - auto storePtr = [=](uint8_t *ptr, Protobuf::Int32 &val) { val.value = ptr ? ptr - spuMemC : -1; }; + auto storePtr = [=](uint8_t* ptr, Protobuf::Int32& val) { val.value = ptr ? ptr - spuMemC : -1; }; storePtr(s_chan[i].pStart, data.get()); storePtr(s_chan[i].pCurr, data.get()); storePtr(s_chan[i].pLoop, data.get()); @@ -100,11 +100,11 @@ void PCSX::SPU::impl::save(SaveStates::SPU &spu) { SetupThread(); } -void PCSX::SPU::impl::load(const SaveStates::SPU &spu) { +void PCSX::SPU::impl::load(const SaveStates::SPU& spu) { RemoveThread(); // we stop processing while doing the save! - spu.get().copyTo(reinterpret_cast(spuMem)); - spu.get().copyTo(reinterpret_cast(regArea)); + spu.get().copyTo(reinterpret_cast(spuMem)); + spu.get().copyTo(reinterpret_cast(regArea)); #if 0 // ugh, the xa_decode pointer is grabbed... this seems a mess. We'll need to fix this up later. @@ -115,16 +115,16 @@ void PCSX::SPU::impl::load(const SaveStates::SPU &spu) { xapGlobal = 0; spuIrq = spu.get().value; - const auto &pSpuIrqIn = spu.get().value; + const auto& pSpuIrqIn = spu.get().value; pSpuIrq = pSpuIrqIn ? pSpuIrqIn + spuMemC : nullptr; for (unsigned i = 0; i < MAXCHAN; i++) { - const auto &channel = spu.get().value[i]; - const auto &data = channel.get(); + const auto& channel = spu.get().value[i]; + const auto& data = channel.get(); s_chan[i].data = data; s_chan[i].ADSR = channel.get(); s_chan[i].ADSRX = channel.get(); - auto restorePtr = [=](uint8_t *&ptr, const Protobuf::Int32 &val) { + auto restorePtr = [=](uint8_t*& ptr, const Protobuf::Int32& val) { ptr = val.value == -1 ? nullptr : val.value + spuMemC; }; restorePtr(s_chan[i].pStart, data.get()); diff --git a/src/spu/interface.h b/src/spu/interface.h index 04e77382f..cf6575221 100644 --- a/src/spu/interface.h +++ b/src/spu/interface.h @@ -25,8 +25,8 @@ #include "json.hpp" #include "core/decode_xa.h" -#include "core/sstate.h" #include "core/spu.h" +#include "core/sstate.h" #include "main/settings.h" #include "spu/adsr.h" #include "spu/sdlsound.h" @@ -48,15 +48,15 @@ class impl : public SPUInterface { // void playSample(uint8_t); void writeRegister(uint32_t, uint16_t) final; uint16_t readRegister(uint32_t) final; - void writeDMAMem(uint16_t *, int) final; - void readDMAMem(uint16_t *, int) final; - virtual void playADPCMchannel(xa_decode_t *) final; + void writeDMAMem(uint16_t*, int) final; + void readDMAMem(uint16_t*, int) final; + virtual void playADPCMchannel(xa_decode_t*) final; - void save(SaveStates::SPU &) final; - void load(const SaveStates::SPU &) final; + void save(SaveStates::SPU&) final; + void load(const SaveStates::SPU&) final; void async(uint32_t) final; - void playCDDAchannel(int16_t *, int) final; + void playCDDAchannel(int16_t*, int) final; void registerCDDAVolume(void (*CDDAVcallback)(uint16_t, uint16_t)); // num of channels @@ -65,7 +65,7 @@ class impl : public SPUInterface { void debug() final; bool configure() final; json getCfg() final { return settings.serialize(); } - void setCfg(const json &j) final { + void setCfg(const json& j) final { if (j.count("SPU") && j["SPU"].is_object()) { settings.deserialize(j["SPU"]); } else { @@ -85,8 +85,8 @@ class impl : public SPUInterface { // spu void MainThread(); - static int MainThreadTrampoline(void *arg) { - impl *that = static_cast(arg); + static int MainThreadTrampoline(void* arg) { + impl* that = static_cast(arg); that->MainThread(); return 0; } @@ -94,12 +94,12 @@ class impl : public SPUInterface { void RemoveStreams(); void SetupThread(); void RemoveThread(); - void StartSound(SPUCHAN *pChannel); - void VoiceChangeFrequency(SPUCHAN *pChannel); - void FModChangeFrequency(SPUCHAN *pChannel, int ns); - int iGetNoiseVal(SPUCHAN *pChannel); - void StoreInterpolationVal(SPUCHAN *pChannel, int fa); - int iGetInterpolationVal(SPUCHAN *pChannel); + void StartSound(SPUCHAN* pChannel); + void VoiceChangeFrequency(SPUCHAN* pChannel); + void FModChangeFrequency(SPUCHAN* pChannel, int ns); + int iGetNoiseVal(SPUCHAN* pChannel); + void StoreInterpolationVal(SPUCHAN* pChannel, int fa); + int iGetInterpolationVal(SPUCHAN* pChannel); // registers void SoundOn(int start, int end, uint16_t val); @@ -117,23 +117,23 @@ class impl : public SPUInterface { void s_buffer1(int iOff, int iVal); // set_buffer (+1 sample) content helper: takes care about wraps and clipping void InitREVERB(); void SetREVERB(uint16_t val); - void StartREVERB(SPUCHAN *pChannel); - void StoreREVERB(SPUCHAN *pChannel, int ns); + void StartREVERB(SPUCHAN* pChannel); + void StoreREVERB(SPUCHAN* pChannel, int ns); int MixREVERBLeft(int ns); int MixREVERBRight(); // xa - void FeedXA(xa_decode_t *xap); + void FeedXA(xa_decode_t* xap); int bSPUIsOpen; // psx buffer / addresses uint16_t regArea[10000]; uint16_t spuMem[256 * 1024]; - uint8_t *spuMemC; - uint8_t *pSpuIrq = 0; - uint8_t *pSpuBuffer; - uint8_t *pMixIrq = 0; + uint8_t* spuMemC; + uint8_t* pSpuIrq = 0; + uint8_t* pSpuBuffer; + uint8_t* pMixIrq = 0; // user settings typedef Setting Streaming; @@ -162,7 +162,7 @@ class impl : public SPUInterface { int bThreadEnded = 0; int bSpuInit = 0; - SDL_Thread *hMainThread; + SDL_Thread* hMainThread; uint32_t dwNewChannel = 0; // flags for faster testing, if new channel starts void (*cddavCallback)(uint16_t, uint16_t) = 0; @@ -174,7 +174,7 @@ class impl : public SPUInterface { int SSumL[NSSIZE]; int iFMod[NSSIZE]; int iCycle = 0; - int16_t *pS; + int16_t* pS; int lastch = -1; // last channel processed on spu irq in timer mode int lastns = 0; // last ns pos @@ -183,15 +183,15 @@ class impl : public SPUInterface { // REVERB info and timing vars... - int *sRVBPlay = 0; - int *sRVBEnd = 0; - int *sRVBStart = 0; + int* sRVBPlay = 0; + int* sRVBEnd = 0; + int* sRVBStart = 0; int iReverbOff = -1; // some delay factor for reverb int iReverbRepeat = 0; int iReverbNum = 1; // XA - xa_decode_t *xapGlobal = 0; + xa_decode_t* xapGlobal = 0; int iLeftXAVol = 32767; int iRightXAVol = 32767; @@ -199,10 +199,10 @@ class impl : public SPUInterface { int gauss_ptr = 0; int gauss_window[8] = {0, 0, 0, 0, 0, 0, 0, 0}; - int &gvall0() { return gauss_window[gauss_ptr]; } - int &gvall(int pos) { return gauss_window[(gauss_ptr + pos) & 3]; } - int &gvalr0() { return gauss_window[4 + gauss_ptr]; } - int &gvalr(int pos) { return gauss_window[4 + ((gauss_ptr + pos) & 3)]; } + int& gvall0() { return gauss_window[gauss_ptr]; } + int& gvall(int pos) { return gauss_window[(gauss_ptr + pos) & 3]; } + int& gvalr0() { return gauss_window[4 + gauss_ptr]; } + int& gvalr(int pos) { return gauss_window[4 + ((gauss_ptr + pos) & 3)]; } ADSR m_adsr; SDLsound m_sound = {settings.get().value}; diff --git a/src/spu/registers.cc b/src/spu/registers.cc index 0f95f5a40..c72227f46 100644 --- a/src/spu/registers.cc +++ b/src/spu/registers.cc @@ -555,7 +555,7 @@ void PCSX::SPU::impl::NoiseOn(int start, int end, uint16_t val) // NOISE ON PSX for (ch = start; ch < end; ch++, val >>= 1) // loop channels { - s_chan[ch].data.get().value = !!(val & 1); // -> noise on/off + s_chan[ch].data.get().value = !!(val & 1); // -> noise on/off } } @@ -629,8 +629,8 @@ void PCSX::SPU::impl::SetPitch(int ch, uint16_t val) // SET PITCH s_chan[ch].data.get().value = NP; - NP = (44100L * NP) / 4096L; // calc frequency - if (NP < 1) NP = 1; // some security + NP = (44100L * NP) / 4096L; // calc frequency + if (NP < 1) NP = 1; // some security s_chan[ch].data.get().value = NP; // store frequency } @@ -644,6 +644,6 @@ void PCSX::SPU::impl::ReverbOn(int start, int end, uint16_t val) // REVERB ON P for (ch = start; ch < end; ch++, val >>= 1) // loop channels { - s_chan[ch].data.get().value = !!(val & 1);// -> reverb on/off + s_chan[ch].data.get().value = !!(val & 1); // -> reverb on/off } } diff --git a/src/spu/reverb.cc b/src/spu/reverb.cc index b0bfd6cde..0fa73d118 100644 --- a/src/spu/reverb.cc +++ b/src/spu/reverb.cc @@ -99,7 +99,7 @@ void PCSX::SPU::impl::SetREVERB(unsigned short val) { // START REVERB //////////////////////////////////////////////////////////////////////// -void PCSX::SPU::impl::StartREVERB(SPUCHAN *pChannel) { +void PCSX::SPU::impl::StartREVERB(SPUCHAN* pChannel) { if (pChannel->data.get().value && (spuCtrl & 0x80)) // reverb possible? { if (settings.get() == 2) @@ -129,7 +129,7 @@ void PCSX::SPU::impl::InitREVERB() { // STORE REVERB //////////////////////////////////////////////////////////////////////// -void PCSX::SPU::impl::StoreREVERB(SPUCHAN *pChannel, int ns) { +void PCSX::SPU::impl::StoreREVERB(SPUCHAN* pChannel, int ns) { if (settings.get() == 0) return; else if (settings.get() == 2) // -------------------------------- // Neil's reverb @@ -145,7 +145,7 @@ void PCSX::SPU::impl::StoreREVERB(SPUCHAN *pChannel, int ns) { *(sRVBStart + ns + 1) += iRxr; } else // --------------------------------------------- // Pete's easy fake reverb { - int *pN; + int* pN; int iRn, iRr = 0; // we use the half channel volume (/0x8000) for the first reverb effects, quarter for next and so on @@ -169,7 +169,7 @@ void PCSX::SPU::impl::StoreREVERB(SPUCHAN *pChannel, int ns) { inline int PCSX::SPU::impl::g_buffer(int iOff) // get_buffer content helper: takes care about wraps { - short *p = (short *)spuMem; + short* p = (short*)spuMem; iOff = (iOff * 4) + rvb.CurrAddr; while (iOff > 0x3FFFF) iOff = rvb.StartAddr + (iOff - 0x40000); while (iOff < rvb.StartAddr) iOff = 0x3ffff - (rvb.StartAddr - iOff); @@ -181,7 +181,7 @@ inline int PCSX::SPU::impl::g_buffer(int iOff) // get_buffer content helper: ta inline void PCSX::SPU::impl::s_buffer(int iOff, int iVal) // set_buffer content helper: takes care about wraps and clipping { - short *p = (short *)spuMem; + short* p = (short*)spuMem; iOff = (iOff * 4) + rvb.CurrAddr; while (iOff > 0x3FFFF) iOff = rvb.StartAddr + (iOff - 0x40000); while (iOff < rvb.StartAddr) iOff = 0x3ffff - (rvb.StartAddr - iOff); @@ -195,7 +195,7 @@ inline void PCSX::SPU::impl::s_buffer(int iOff, inline void PCSX::SPU::impl::s_buffer1( int iOff, int iVal) // set_buffer (+1 sample) content helper: takes care about wraps and clipping { - short *p = (short *)spuMem; + short* p = (short*)spuMem; iOff = (iOff * 4) + rvb.CurrAddr + 1; while (iOff > 0x3FFFF) iOff = rvb.StartAddr + (iOff - 0x40000); while (iOff < rvb.StartAddr) iOff = 0x3ffff - (rvb.StartAddr - iOff); diff --git a/src/spu/sdlsound.cc b/src/spu/sdlsound.cc index e0b32bea5..8b6b4d4be 100644 --- a/src/spu/sdlsound.cc +++ b/src/spu/sdlsound.cc @@ -26,7 +26,7 @@ #include "spu/sdlsound.h" void PCSX::SPU::SDLsound::dequeueLocked(uint8_t* stream, size_t len, unsigned streamId) { - auto & str = m_streams[streamId]; + auto& str = m_streams[streamId]; if ((BUFFER_SIZE - str.ptrBegin) < len) { size_t subLen = BUFFER_SIZE - str.ptrBegin; dequeueLocked(stream, subLen, streamId); @@ -135,7 +135,7 @@ unsigned long PCSX::SPU::SDLsound::getBytesBuffered(unsigned streamId) { } void PCSX::SPU::SDLsound::enqueueLocked(const uint8_t* data, size_t len, unsigned streamId) { - auto & str = m_streams[streamId]; + auto& str = m_streams[streamId]; while (true) { size_t available; diff --git a/src/spu/spu.cc b/src/spu/spu.cc index 1f3a291d5..52f588795 100644 --- a/src/spu/spu.cc +++ b/src/spu/spu.cc @@ -151,8 +151,8 @@ // / // -static inline void InterpolateUp(PCSX::SPU::SPUCHAN *pChannel) { - auto &SB = pChannel->data.get().value; +static inline void InterpolateUp(PCSX::SPU::SPUCHAN* pChannel) { + auto& SB = pChannel->data.get().value; if (SB[32].value == 1) // flag == 1? calc step and set flag... and don't change the value in this pass { const int id1 = SB[30].value - SB[29].value; // curr delta to next val @@ -197,8 +197,8 @@ static inline void InterpolateUp(PCSX::SPU::SPUCHAN *pChannel) { // even easier interpolation on downsampling, also no special filter, again just "Pete's common sense" tm // -static inline void InterpolateDown(PCSX::SPU::SPUCHAN *pChannel) { - auto &SB = pChannel->data.get().value; +static inline void InterpolateDown(PCSX::SPU::SPUCHAN* pChannel) { + auto& SB = pChannel->data.get().value; if (pChannel->data.get().value >= 0x20000L) // we would skip at least one val? { SB[29].value += (SB[30].value - SB[29].value) / 2; // add easy weight @@ -210,8 +210,8 @@ static inline void InterpolateDown(PCSX::SPU::SPUCHAN *pChannel) { //////////////////////////////////////////////////////////////////////// // helpers for gauss interpolation -#define gval0 (((int16_t *)(&SB[29].value))[gpos]) -#define gval(x) (((int16_t *)(&SB[29].value))[(gpos + x) & 3]) +#define gval0 (((int16_t*)(&SB[29].value))[gpos]) +#define gval(x) (((int16_t*)(&SB[29].value))[(gpos + x) & 3]) //////////////////////////////////////////////////////////////////////// @@ -219,8 +219,8 @@ static inline void InterpolateDown(PCSX::SPU::SPUCHAN *pChannel) { // START SOUND... called by main thread to setup a new sound on a channel //////////////////////////////////////////////////////////////////////// -inline void PCSX::SPU::impl::StartSound(SPUCHAN *pChannel) { - auto &SB = pChannel->data.get().value; +inline void PCSX::SPU::impl::StartSound(SPUCHAN* pChannel) { + auto& SB = pChannel->data.get().value; m_adsr.start(pChannel); StartREVERB(pChannel); @@ -252,8 +252,8 @@ inline void PCSX::SPU::impl::StartSound(SPUCHAN *pChannel) { // ALL KIND OF HELPERS //////////////////////////////////////////////////////////////////////// -inline void PCSX::SPU::impl::VoiceChangeFrequency(SPUCHAN *pChannel) { - auto &SB = pChannel->data.get().value; +inline void PCSX::SPU::impl::VoiceChangeFrequency(SPUCHAN* pChannel) { + auto& SB = pChannel->data.get().value; pChannel->data.get().value = pChannel->data.get().value; // -> take it and calc steps pChannel->data.get().value = pChannel->data.get().value << 4; @@ -263,8 +263,8 @@ inline void PCSX::SPU::impl::VoiceChangeFrequency(SPUCHAN *pChannel) { //////////////////////////////////////////////////////////////////////// -inline void PCSX::SPU::impl::FModChangeFrequency(SPUCHAN *pChannel, int ns) { - auto &SB = pChannel->data.get().value; +inline void PCSX::SPU::impl::FModChangeFrequency(SPUCHAN* pChannel, int ns) { + auto& SB = pChannel->data.get().value; int NP = pChannel->data.get().value; NP = ((32768L + iFMod[ns]) * NP) / 32768L; @@ -289,8 +289,8 @@ inline void PCSX::SPU::impl::FModChangeFrequency(SPUCHAN *pChannel, int ns) { // surely wrong... and no noise frequency (spuCtrl&0x3f00) will be used... // and sometimes the noise will be used as fmod modulation... pfff -inline int PCSX::SPU::impl::iGetNoiseVal(SPUCHAN *pChannel) { - auto &SB = pChannel->data.get().value; +inline int PCSX::SPU::impl::iGetNoiseVal(SPUCHAN* pChannel) { + auto& SB = pChannel->data.get().value; int fa; if ((dwNoiseVal <<= 1) & 0x80000000L) { @@ -314,8 +314,8 @@ inline int PCSX::SPU::impl::iGetNoiseVal(SPUCHAN *pChannel) { //////////////////////////////////////////////////////////////////////// -inline void PCSX::SPU::impl::StoreInterpolationVal(SPUCHAN *pChannel, int fa) { - auto &SB = pChannel->data.get().value; +inline void PCSX::SPU::impl::StoreInterpolationVal(SPUCHAN* pChannel, int fa) { + auto& SB = pChannel->data.get().value; if (pChannel->data.get().value == 2) // fmod freq channel SB[29].value = fa; else { @@ -348,8 +348,8 @@ inline void PCSX::SPU::impl::StoreInterpolationVal(SPUCHAN *pChannel, int fa) { //////////////////////////////////////////////////////////////////////// -inline int PCSX::SPU::impl::iGetInterpolationVal(SPUCHAN *pChannel) { - auto &SB = pChannel->data.get().value; +inline int PCSX::SPU::impl::iGetInterpolationVal(SPUCHAN* pChannel) { + auto& SB = pChannel->data.get().value; int fa; if (pChannel->data.get().value == 2) return SB[29].value; @@ -425,11 +425,11 @@ inline int PCSX::SPU::impl::iGetInterpolationVal(SPUCHAN *pChannel) { void PCSX::SPU::impl::MainThread() { int s_1, s_2, fa, ns, voldiv = settings.get(); - uint8_t *start; + uint8_t* start; unsigned int nSample; int ch, predict_nr, shift_factor, flags, d, s; int bIRQReturn = 0; - SPUCHAN *pChannel; + SPUCHAN* pChannel; SDL_SetThreadPriority(SDL_THREAD_PRIORITY_HIGH); @@ -505,7 +505,7 @@ void PCSX::SPU::impl::MainThread() { { start = pChannel->pCurr; // set up the current pos - if (start == (uint8_t *)-1) // special "stop" sign + if (start == (uint8_t*)-1) // special "stop" sign { pChannel->data.get().value = false; // -> turn everything off pChannel->ADSRX.get().value = 0; @@ -583,7 +583,7 @@ void PCSX::SPU::impl::MainThread() { pChannel->pLoop == NULL) // PETE: if we don't check exactly for 3, loop hang // ups will happen (DQ4, for example) { // and checking if pLoop is set avoids crashes, yeah - start = (uint8_t *)-1; + start = (uint8_t*)-1; } else { start = pChannel->pLoop; } @@ -750,8 +750,8 @@ void PCSX::SPU::impl::MainThread() { // wanna have around 1/60 sec (16.666 ms) updates if (iCycle++ > 16) { - m_sound.feedStreamData((uint8_t *)pSpuBuffer, ((uint8_t *)pS) - ((uint8_t *)pSpuBuffer)); - pS = (int16_t *)pSpuBuffer; + m_sound.feedStreamData((uint8_t*)pSpuBuffer, ((uint8_t*)pS) - ((uint8_t*)pSpuBuffer)); + pS = (int16_t*)pSpuBuffer; iCycle = 0; } } @@ -782,7 +782,7 @@ void PCSX::SPU::impl::async(uint32_t cycle) { // XA AUDIO //////////////////////////////////////////////////////////////////////// -void PCSX::SPU::impl::playADPCMchannel(xa_decode_t *xap) { +void PCSX::SPU::impl::playADPCMchannel(xa_decode_t* xap) { if (!settings.get()) return; // no XA? bye if (!xap) return; if (!xap->freq) return; // no xa freq ? bye @@ -799,7 +799,7 @@ void PCSX::SPU::impl::playADPCMchannel(xa_decode_t *xap) { //////////////////////////////////////////////////////////////////////// long PCSX::SPU::impl::init(void) { - spuMemC = (uint8_t *)spuMem; // just small setup + spuMemC = (uint8_t*)spuMem; // just small setup wipeChannels(); return 0; } @@ -813,7 +813,7 @@ void PCSX::SPU::impl::wipeChannels() { s_chan[i].pLoop = nullptr; s_chan[i].pStart = nullptr; } - memset((void *)&rvb, 0, sizeof(REVERBInfo)); + memset((void*)&rvb, 0, sizeof(REVERBInfo)); } //////////////////////////////////////////////////////////////////////// @@ -825,7 +825,7 @@ void PCSX::SPU::impl::SetupThread() { memset(SSumL, 0, NSSIZE * sizeof(int)); memset(iFMod, 0, NSSIZE * sizeof(int)); - pS = (int16_t *)pSpuBuffer; // setup soundbuffer pointer + pS = (int16_t*)pSpuBuffer; // setup soundbuffer pointer bEndThread = 0; // init thread vars bThreadEnded = 0; @@ -859,14 +859,14 @@ void PCSX::SPU::impl::RemoveThread() { void PCSX::SPU::impl::SetupStreams() { int i; - pSpuBuffer = (uint8_t *)malloc(32768); // alloc mixing buffer + pSpuBuffer = (uint8_t*)malloc(32768); // alloc mixing buffer if (settings.get() == 1) i = 88200 * 2; else i = NSSIZE * 2; - sRVBStart = (int *)malloc(i * 4); // alloc reverb buffer + sRVBStart = (int*)malloc(i * 4); // alloc reverb buffer memset(sRVBStart, 0, i * 4); sRVBEnd = sRVBStart + i; sRVBPlay = sRVBStart; @@ -912,7 +912,7 @@ bool PCSX::SPU::impl::open() { spuAddr = 0xffffffff; bEndThread = 0; bThreadEnded = 0; - spuMemC = (uint8_t *)spuMem; + spuMemC = (uint8_t*)spuMem; pMixIrq = 0; wipeChannels(); pSpuIrq = 0; @@ -965,7 +965,7 @@ void PCSX::SPU::impl::registerCDDAVolume(void (*CDDAVcallback)(uint16_t, uint16_ //////////////////////////////////////////////////////////////////////// -void PCSX::SPU::impl::playCDDAchannel(int16_t *data, int size) { +void PCSX::SPU::impl::playCDDAchannel(int16_t* data, int size) { m_cdda.freq = 44100; m_cdda.nsamples = size / 4; m_cdda.stereo = 1; diff --git a/src/spu/types.h b/src/spu/types.h index 8d13726eb..b6a953db5 100644 --- a/src/spu/types.h +++ b/src/spu/types.h @@ -133,9 +133,9 @@ typedef Protobuf::Message> 16) & 0xffff; } // FEED XA //////////////////////////////////////////////////////////////////////// -void PCSX::SPU::impl::FeedXA(xa_decode_t *xap) { +void PCSX::SPU::impl::FeedXA(xa_decode_t* xap) { int sinc, spos, i, iSize, iPlace, vl, vr; uint32_t XABuffer[32 * 1024]; - uint32_t *XAFeed = XABuffer; + uint32_t* XAFeed = XABuffer; iPlace = 32 * 1024; @@ -99,7 +99,7 @@ void PCSX::SPU::impl::FeedXA(xa_decode_t *xap) { sinc = (xap->nsamples << 16) / iSize; // calc freq by num / size if (xap->stereo) { - uint32_t *pS = (uint32_t *)xap->pcm; + uint32_t* pS = (uint32_t*)xap->pcm; uint32_t l = 0; if (settings.get()) { @@ -180,7 +180,7 @@ void PCSX::SPU::impl::FeedXA(xa_decode_t *xap) { } } } else { - uint16_t *pS = (uint16_t *)xap->pcm; + uint16_t* pS = (uint16_t*)xap->pcm; uint32_t l; int16_t s = 0; @@ -244,5 +244,5 @@ void PCSX::SPU::impl::FeedXA(xa_decode_t *xap) { } } - m_sound.feedStreamData((uint8_t *)XABuffer, (XAFeed - XABuffer) * sizeof(uint32_t), 1); + m_sound.feedStreamData((uint8_t*)XABuffer, (XAFeed - XABuffer) * sizeof(uint32_t), 1); } diff --git a/tools/code-format/format.sh b/tools/code-format/format.sh index 397931433..132e3c0b8 100755 --- a/tools/code-format/format.sh +++ b/tools/code-format/format.sh @@ -1,6 +1,27 @@ #!/bin/sh +set -e + +if [ $# -gt 0 ]; then + CLANGF_SRC=`realpath -e "$1"` + if [ ! -f "$1" ]; then + echo "$1: no such file or directory" >&2 + exit 1 + fi +fi cd $(dirname $0)/../.. +CLANGF_DEST=src/.clang-format + +rm -f "$CLANGF_DEST" + +if [ -z "$CLANGF_SRC" ]; then + CLANGF_SRC="src/.clang-format-commit" +fi + +cp "$CLANGF_SRC" "$CLANGF_DEST" + +echo "Using \"$CLANGF_SRC\"..." + docker build -t code-format tools/code-format docker run --rm=true -v "$(pwd)":/repository --user "$(id -u):$(id -g)" -t code-format diff --git a/tools/pshittyloader/pshittyloader.py b/tools/pshittyloader/pshittyloader.py new file mode 100755 index 000000000..9b0e56329 --- /dev/null +++ b/tools/pshittyloader/pshittyloader.py @@ -0,0 +1,51 @@ +#!/usr/bin/env python3 + +from array import array +import sys +import serial +import os + +bps=57600 + +args = int(len(sys.argv)) + +sys.stdout.write("\npshittyloader.py\n\n"); + +if args < 2: + sys.stdout.write(" usage : pshittyload.py DEV FILE\n\n") + +else: + devPath = sys.argv[1] + filePath = sys.argv[2] + + filesize = os.path.getsize(filePath) + + inputfile = open(filePath, 'rb') + + sys.stdout.write("Port: {}\n".format(devPath)) + sys.stdout.write("Speed(bps): {}\n".format(bps)) + sys.stdout.write("Executable:\n") + sys.stdout.write(" Name: {}\n".format(filePath)) + sys.stdout.write(" Size(bytes): {}\n".format(filesize)) + + ser = serial.Serial(devPath, bps, serial.EIGHTBITS, serial.PARITY_NONE, serial.STOPBITS_ONE) + sys.stdout.write('\n- Waiting for remote device...\n') + + # send 'P', 'L' and expect '+' in response. + b = b'!' + while b != b'+': + ser.flushInput() + ser.flushOutput() + ser.write(b'P') + ser.write(b'L') + b = ser.read() + if b != b'+': + sys.stdout.write("Bad sync response: {}\n".format(b)) + + sys.stdout.write('- Sending File...\n') + # defines an array which can hold unsigned bytes + data = array('B') + with open(filePath, 'rb') as f: + data.fromfile(f, filesize) + ser.write(data) + sys.stdout.write('\n- Done!\n') diff --git a/tools/psload/Makefile b/tools/psload/Makefile new file mode 100644 index 000000000..29608d7b3 --- /dev/null +++ b/tools/psload/Makefile @@ -0,0 +1,32 @@ +MKDIR=mkdir +CP=cp +RM=rm +RMF=rm -f +CC=gcc +CPP=cpp + +TARGET=psload + +SRCS = \ + src/main.c \ + src/utils.c \ + src/pcsio.c + +LIBS = +# -lusb-1.0 + +CFLAGS=-I/usr/include +CFLAGS+=-Wall -g +CFLAGS+=-Iinclude -Isrc +OBJS= +LDFLAGS= + +OBJS += $(addsuffix .o, $(basename $(SRCS))) + +all: $(TARGET) + +clean: + $(RMF) $(OBJS) $(TARGET) + +$(TARGET): $(OBJS) + $(CC) $(CFLAGS) $(LDFLAGS) -o $(TARGET) $(OBJS) $(LIBS) diff --git a/tools/psload/include/pcserial.h b/tools/psload/include/pcserial.h new file mode 100644 index 000000000..5f7f7f737 --- /dev/null +++ b/tools/psload/include/pcserial.h @@ -0,0 +1,88 @@ +#ifndef _PCSERIAL_H +#define _PCSERIAL_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +typedef enum +{ + CHLEN_5, + CHLEN_6, + CHLEN_7, + CHLEN_8 +} CharLen; + +typedef enum +{ + PARITY_NONE, + PARITY_EVEN, + PARITY_ODD +} Parity; + +typedef enum +{ + STOPBITS_0, + STOPBITS_1, + STOPBITS_1_5, + STOPBITS_2 +} StopBits; + +enum +{ + LINE_ENDS_LF, // use linefeed('\x0A'/'\n'), + LINE_ENDS_CRLF, // use carriage return('\x0D'/'\r'/CR) followed by a linefeed: "\r\n" + LINE_ENDS_AUTO, // use line endings corresponding to the OS this app is running on. + // i.e. CRLF for Windows/DOS-based OS, LF for for others. + LINE_ENDS_DEF // do not alter line endings +}; + +typedef struct SerialConfig_st +{ + int baud; + CharLen chlen; + Parity parity; + StopBits sbits; + int sw_handshake; + int hw_handshake; + int line_ends; + + // private + char *_devPath; + int _line_ends; + int _fd; // fd for the device. + FILE * _in_fp; // fp to use for local "stdin" output + FILE * _out_fp; // fp to use for local "stdout" output + FILE * _err_fp; // fp to use for local "stderr" output + int _prev_ch; + struct termios _old_tio; +} SerialConfig; + +int serial_open(SerialConfig *cfg, const char *path); +int serial_config(SerialConfig *cfg); +int serial_close(SerialConfig *cfg); + +int serial_getb(SerialConfig *cfg, uint8_t *c); +int serial_putb(SerialConfig *cfg, uint8_t c, uint32_t delay); + +int cons_putchar(SerialConfig *cfg, uint8_t ch); + +void print_serial_config(SerialConfig *cfg); + +#ifdef __cplusplus +} +#endif + +#endif // _PCSERIAL_H diff --git a/tools/psload/include/utils.h b/tools/psload/include/utils.h new file mode 100644 index 000000000..c0a1361a8 --- /dev/null +++ b/tools/psload/include/utils.h @@ -0,0 +1,46 @@ +#ifndef _UTILS_H +#define _UTILS_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern uint32_t __verbosity_flags; +extern uint32_t __verbosity_level; + +#define VERBOSITY_FLAG_ERROR (1 << 0) +#define VERBOSITY_FLAG_WARN (1 << 1) +#define VERBOSITY_FLAG_INFO (1 << 2) +#define VERBOSITY_FLAG_DEBUG (1 << 3) + +#define VERBOSITY_SILENT 0 +#define VERBOSITY_ERROR 1 +#define VERBOSITY_WARN 2 +#define VERBOSITY_INFO 3 +#define VERBOSITY_DEBUG 4 +#define VERBOSITY_MAX 10 + +#define MAX_DATA_SIZE (MAXPATHLEN) + +#define eprintf(...) if(((__verbosity_flags & VERBOSITY_FLAG_ERROR) != 0) && (__verbosity_level >= VERBOSITY_ERROR)) { fprintf (stderr, __VA_ARGS__); } +#define wprintf(...) if(((__verbosity_flags & VERBOSITY_FLAG_WARN) != 0) && (__verbosity_level >= VERBOSITY_WARN)) { fprintf (stderr, __VA_ARGS__); } +#define iprintf(...) if(((__verbosity_flags & VERBOSITY_FLAG_INFO) != 0) && (__verbosity_level >= VERBOSITY_INFO)) { fprintf (stdout, __VA_ARGS__); } +#define dprintf(__lvl, ...) if(((__verbosity_flags & VERBOSITY_FLAG_DEBUG) != 0) && (__verbosity_level >= (VERBOSITY_DEBUG + ((__lvl) - 1)))) { fprintf (stdout, __VA_ARGS__); } + +#ifdef __cplusplus +} +#endif + +#endif // _UTILS_H diff --git a/tools/psload/src/main.c b/tools/psload/src/main.c new file mode 100644 index 000000000..afd4ff4d5 --- /dev/null +++ b/tools/psload/src/main.c @@ -0,0 +1,96 @@ +#include +#include +#include +#include +#include + +#include "pcserial.h" +#include "utils.h" + +static SerialConfig cfg = +{ + baud: 57600, + chlen: CHLEN_8, + parity: PARITY_NONE, + sbits: STOPBITS_1, + sw_handshake: 0, + hw_handshake: 0, + line_ends: LINE_ENDS_LF +}; + +static volatile int term = 0; + +void handle_sigint(int sig) +{ + printf("Caught signal %d\n", sig); + term = 1; +} + +void printUsage(const char *arg0) +{ + fprintf(stderr, "usage: %s SERIALPORT CMD ...params...\n",arg0); + fprintf(stderr, "commands:\n"); + fprintf(stderr, "\trun FILE\t- xfer FILE to target and exec\n"); + fprintf(stderr, "\n"); +} + +int main(int argc, char *argv[]) +{ + char *_defDevPath = "/dev/ttyUSB0"; + char *devPath = _defDevPath; + uint8_t ch; + int i; + int rv = 0; + + if(argc < 2) + { + printUsage(argv[0]); + exit(1); + } + + devPath = argv[1]; + i = 2; + + if(__verbosity_level >= VERBOSITY_INFO) + print_serial_config(&cfg); + + signal(SIGINT, handle_sigint); + + if(serial_open(&cfg, devPath) != 0) + { + rv = 1; + goto _end; + } + + if(strcasecmp(argv[i], "run") == 0) + { + eprintf("FIXME!!!! run not supported\n"); + rv = 1; + goto _end; + } + + while(!term) + { + if((rv = serial_getb(&cfg, &ch)) < 0) + { + // should only happen if there was an error + rv = 1; + break; + } + + if(rv != 0) + { + // data was read + cons_putchar(&cfg, ch); + continue; + } + + // note: device may have been disconnected + } + +//~ _finish: + serial_close(&cfg); + +_end: + return rv; +} diff --git a/tools/psload/src/pcsio.c b/tools/psload/src/pcsio.c new file mode 100644 index 000000000..f5344fddd --- /dev/null +++ b/tools/psload/src/pcsio.c @@ -0,0 +1,387 @@ +#include +#include +#include "pcserial.h" +#include "utils.h" + +#define inited(__cfg) (((__cfg)->_devPath) != NULL) + +void millisleep(int ms) +{ + if (ms>0) + { + struct timeval tv; + tv.tv_sec=0; + tv.tv_usec=ms*1000; + select(0, 0, 0, 0, &tv); + } +} + +int serial_open(SerialConfig *cfg, const char *devPath) +{ + cfg->_fd = -1; + cfg->_devPath = NULL; + + cfg->_fd = open(devPath, O_RDWR | O_NDELAY); + if(cfg->_fd < 0) + { + eprintf("failed to open serial port \"%s\"\n", devPath); + return -1; + } + + cfg->_in_fp = stdin; + cfg->_out_fp = stdout; + cfg->_err_fp = stderr; + + // flushing is to be done after opening. This prevents first read and write to be spam'ish. + tcflush(cfg->_fd, TCIOFLUSH); + + int n = fcntl(cfg->_fd, F_GETFL, 0); + fcntl(cfg->_fd, F_SETFL, n & ~O_NDELAY); + + // save the current termios config + if(tcgetattr(cfg->_fd, &cfg->_old_tio)!=0) + { + eprintf("tcgetattr() 2 failed\n"); + close(cfg->_fd); + return -1; + } + + cfg->_prev_ch = -1; + + // NOTE: the string for _devPath is allocated here! It should be free'd with free(cfg->_devPath) + cfg->_devPath = strdup(devPath); + + if(serial_config(cfg) != 0) + { + serial_close(cfg); + return -1; + } + + return 0; +} + +/** This function features some code from minicom 2.0.0, src/sysdep1.c */ +int serial_config(SerialConfig *cfg) +{ + if(!inited(cfg)) return -1; + + struct termios newtio; + + if(tcgetattr(cfg->_fd, &newtio) != 0) + { + eprintf("tcgetattr failed\n"); + return -1; + } + + speed_t _baud=0; + switch (cfg->baud) + { +#ifdef B0 + case 0: _baud=B0; break; +#endif + +#ifdef B50 + case 50: _baud=B50; break; +#endif +#ifdef B75 + case 75: _baud=B75; break; +#endif +#ifdef B110 + case 110: _baud=B110; break; +#endif +#ifdef B134 + case 134: _baud=B134; break; +#endif +#ifdef B150 + case 150: _baud=B150; break; +#endif +#ifdef B200 + case 200: _baud=B200; break; +#endif +#ifdef B300 + case 300: _baud=B300; break; +#endif +#ifdef B600 + case 600: _baud=B600; break; +#endif +#ifdef B1200 + case 1200: _baud=B1200; break; +#endif +#ifdef B1800 + case 1800: _baud=B1800; break; +#endif +#ifdef B2400 + case 2400: _baud=B2400; break; +#endif +#ifdef B4800 + case 4800: _baud=B4800; break; +#endif +#ifdef B7200 + case 7200: _baud=B7200; break; +#endif +#ifdef B9600 + case 9600: _baud=B9600; break; +#endif +#ifdef B14400 + case 14400: _baud=B14400; break; +#endif +#ifdef B19200 + case 19200: _baud=B19200; break; +#endif +#ifdef B28800 + case 28800: _baud=B28800; break; +#endif +#ifdef B38400 + case 38400: _baud=B38400; break; +#endif +#ifdef B57600 + case 57600: _baud=B57600; break; +#endif +#ifdef B76800 + case 76800: _baud=B76800; break; +#endif +#ifdef B115200 + case 115200: _baud=B115200; break; +#endif +#ifdef B128000 + case 128000: _baud=B128000; break; +#endif +#ifdef B230400 + case 230400: _baud=B230400; break; +#endif +#ifdef B460800 + case 460800: _baud=B460800; break; +#endif +#ifdef B576000 + case 576000: _baud=B576000; break; +#endif +#ifdef B921600 + case 921600: _baud=B921600; break; +#endif + default: +// case 256000: +// _baud=B256000; + break; + } + + cfsetospeed(&newtio, (speed_t)_baud); + cfsetispeed(&newtio, (speed_t)_baud); + + newtio.c_cflag &= (~CSIZE); + switch (cfg->chlen) + { + case CHLEN_5: + newtio.c_cflag |= CS5; + break; + case CHLEN_6: + newtio.c_cflag |= CS6; + break; + case CHLEN_7: + newtio.c_cflag |= CS7; + break; + case CHLEN_8: + default: + newtio.c_cflag |= CS8; + break; + } + + newtio.c_cflag |= CLOCAL | CREAD; + + //parity + + newtio.c_cflag &= ~(PARENB | PARODD); + if(cfg->parity != PARITY_NONE) newtio.c_cflag |= PARENB | ((cfg->parity == PARITY_ODD) ? PARODD : 0); + + //hardware handshake +/* if (cfg->hw_handshake) + newtio.c_cflag |= CRTSCTS; + else + newtio.c_cflag &= ~CRTSCTS;*/ + + newtio.c_cflag &= ~CRTSCTS; + + newtio.c_cflag &= ~CSTOPB; + + if(cfg->sbits==STOPBITS_2) + { + newtio.c_cflag |= CSTOPB; + } + +// newtio.c_iflag=IGNPAR | IGNBRK; + newtio.c_iflag=IGNBRK; +// newtio.c_iflag=IGNPAR; + + //software handshake + if (cfg->sw_handshake) + { + newtio.c_iflag |= IXON | IXOFF; + } + else + { + newtio.c_iflag &= ~(IXON|IXOFF|IXANY); + } + + newtio.c_lflag=0; + newtio.c_oflag=0; + + newtio.c_cc[VTIME]=1; + newtio.c_cc[VMIN]=60; + +// tcflush(cfg->_fd, TCIFLUSH); + if(tcsetattr(cfg->_fd, TCSANOW, &newtio)!=0) + { + eprintf("tcsetattr() 1 failed\n"); + return -1; + } + + int mcs=0; + ioctl(cfg->_fd, TIOCMGET, &mcs); + mcs |= TIOCM_RTS; + ioctl(cfg->_fd, TIOCMSET, &mcs); + + if (tcgetattr(cfg->_fd, &newtio)!=0) + { + eprintf("tcgetattr() 4 failed\n"); + return -1; + } + + newtio.c_cflag &= ~CRTSCTS; + if(cfg->hw_handshake) + { + newtio.c_cflag |= CRTSCTS; + } + + if(tcsetattr(cfg->_fd, TCSANOW, &newtio)!=0) + { + eprintf("tcsetattr() 2 failed\n"); + return -1; + } + + cfg->_line_ends = cfg->line_ends; + if(cfg->_line_ends == LINE_ENDS_AUTO) +#ifdef _OS_IS_WINDOWS + cfg->_line_ends = LINE_ENDS_CRLF; +#else + cfg->_line_ends = LINE_ENDS_LF; +#endif + + return 0; +} + +int serial_putb(SerialConfig *cfg, uint8_t c, uint32_t delay) +{ + if(!inited(cfg)) return -1; + + int res = write(cfg->_fd, &c, 1); + if (res<1) + { + eprintf("write returned %d, errno: %d\n", res, errno); + return -1; + } + + if(delay != 0) millisleep(delay); + + return 0; +} + +int serial_getb(SerialConfig *cfg, uint8_t *c) +{ + if(!inited(cfg)) return -1; + + int res = read(cfg->_fd, &c, 1); + if(res < 0) + { + eprintf("read returned %d, errno: %d\n", res, errno); + return -1; + } + + return res; +} + +int serial_close(SerialConfig *cfg) +{ + if(!inited(cfg)) return -1; + + if(cfg->_fd >= 0) + { + tcsetattr(cfg->_fd, TCSANOW, &cfg->_old_tio); + close(cfg->_fd); + cfg->_fd = -1; + } + + if(cfg->_in_fp != NULL) + { + if(cfg->_in_fp != stdin) { fclose(cfg->_in_fp); } + cfg->_in_fp = NULL; + } + + if(cfg->_out_fp!= NULL) + { + if(cfg->_out_fp != stdout) { fclose(cfg->_out_fp); } + cfg->_out_fp = NULL; + } + + if(cfg->_err_fp != NULL) + { + if(cfg->_err_fp != stderr) { fclose(cfg->_err_fp); } + cfg->_err_fp = NULL; + } + + if(cfg->_devPath) + { + free(cfg->_devPath); + cfg->_devPath = NULL; + } + + return 0; +} + +void print_serial_config(SerialConfig *cfg) +{ + if(cfg->_devPath) + printf("dev:\t\t%s\n", cfg->_devPath); + printf("baud:\t\t%d\n", cfg->baud); + printf("chlen:\t\t%d\n", ((cfg->chlen == CHLEN_5) ? 5 : + (((cfg->chlen == CHLEN_5) ? 6 : + ((cfg->chlen == CHLEN_5) ? 7 : 8))))); + printf("parity:\t\t%s\n", ((cfg->parity == PARITY_NONE) ? "None" : + ((cfg->parity == PARITY_EVEN) ? "Even" : "Odd"))); + printf("sbits:\t\t%s\n", ((cfg->sbits == STOPBITS_2) ? "1" : + (((cfg->sbits == STOPBITS_1) ? "1" : + ((cfg->sbits == STOPBITS_1_5) ? "1.5" : + "0"))))); + printf("SW hshake:\t%c\n", cfg->sw_handshake ? 'Y' : 'N'); + printf("HW hshake:\t%c\n", cfg->hw_handshake ? 'Y' : 'N'); +} + +int cons_putchar(SerialConfig *cfg, uint8_t ch) +{ + if(!inited(cfg)) return -1; + + if(cfg->_line_ends != LINE_ENDS_DEF) + { + if(ch == '\x0A') + { + if(cfg->_line_ends == LINE_ENDS_CRLF) + { + if((cfg->_prev_ch == -1) || (cfg->_prev_ch != '\x0D')) + { + fputc('\x0D', cfg->_out_fp); + } + } + } + else if(ch == '\x0D') + { + if(cfg->_line_ends == LINE_ENDS_LF) + { + // if line endings are set to only LF, ignore any CR chars + return 0; + } + } + } + + fputc(ch, cfg->_out_fp); + cfg->_prev_ch = ch; + + return 0; +} diff --git a/tools/psload/src/utils.c b/tools/psload/src/utils.c new file mode 100644 index 000000000..841834831 --- /dev/null +++ b/tools/psload/src/utils.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include + +#include "pcserial.h" +#include "utils.h" + +uint32_t __verbosity_flags = (VERBOSITY_FLAG_WARN | VERBOSITY_FLAG_INFO | VERBOSITY_FLAG_ERROR | VERBOSITY_FLAG_DEBUG); +uint32_t __verbosity_level = VERBOSITY_INFO; +/* +int psl_sync(void) +{ + uint8_t d = '-'; + + do + { + if(psl_putb('P') != 0) return -1; + if(psl_putb('S') != 0) return -2; + if(psl_getb(&d) <= 0) return -3; + } while(d != '+'); +} +*/ diff --git a/vsprojects/pshittyloader/pshittyloader.code-workspace b/vsprojects/pshittyloader/pshittyloader.code-workspace new file mode 100644 index 000000000..738a663a3 --- /dev/null +++ b/vsprojects/pshittyloader/pshittyloader.code-workspace @@ -0,0 +1,7 @@ +{ + "folders": [ + { + "path": "/data/code/PS/PS1/pcsx-redux/src/mips/pshittyload" + } + ] +} \ No newline at end of file