From 53557bd5efeabd4f8e5b9b8c31266ae053790592 Mon Sep 17 00:00:00 2001 From: grinvader <> Date: Tue, 10 May 2005 00:18:29 +0000 Subject: [PATCH] More code cleanup (and trailing spacesremoval). --- zsnes/src/cpu/execute.asm | 37 +++++++---------------------- zsnes/src/zmovie.c | 50 +++++++++++++++++++-------------------- zsnes/src/zstate.c | 48 ++++++++++++++++++++----------------- 3 files changed, 59 insertions(+), 76 deletions(-) diff --git a/zsnes/src/cpu/execute.asm b/zsnes/src/cpu/execute.asm index e6438138..a50f8da4 100644 --- a/zsnes/src/cpu/execute.asm +++ b/zsnes/src/cpu/execute.asm @@ -535,7 +535,14 @@ reexecuteb2: je near .activatereset mov eax,[KeySaveState] test byte[pressed+eax],1 - jnz near savestate + jz .nosavestt + mov byte[pressed+1],0 + mov byte[pressed+eax],2 + pushad + call statesaver + popad + jmp reexecuteb +.nosavestt mov eax,[KeyLoadState] test byte[pressed+eax],1 jz .noloadstt0 @@ -661,34 +668,6 @@ NEWSYM HIRQCycNext, dd 0 NEWSYM HIRQNextExe, db 0 - -;******************************************************* -; Save/Load States -;******************************************************* - -SECTION .data -NEWSYM firstsaveinc, db 0 -NEWSYM txtsavemsg, db 'STATE - SAVED.',0 -NEWSYM txtsavemsgfail, db 'UNABLE TO SAVE.',0 -SECTION .text - -NEWSYM savestate - mov byte[pressed+1],0 - mov eax,[KeySaveState] - mov byte[pressed+eax],2 - pushad - call statesaver - popad - jmp reexecuteb - -SECTION .data -.fname2 db 9,'image.dat',0 - -NEWSYM txtloadmsg, db 'STATE - LOADED.',0 -NEWSYM txtconvmsg, db 'STATE - TOO OLD.',0 -NEWSYM txtnfndmsg, db 'UNABLE TO LOAD STATE -.',0 -SECTION .text - ;******************************************************* ; Int 08h vector ;******************************************************* diff --git a/zsnes/src/zmovie.c b/zsnes/src/zmovie.c index fa346cfd..9721a155 100644 --- a/zsnes/src/zmovie.c +++ b/zsnes/src/zmovie.c @@ -76,7 +76,7 @@ bool zst_compressed_loader(FILE *); print_bin(JoyBOrig, &usedb); printf(" "); \ print_bin(JoyCOrig, &usedc); printf(" "); \ print_bin(JoyDOrig, &usedd); printf(" "); \ - print_bin(JoyEOrig, &usede); printf("\n"); + print_bin(JoyEOrig, &usede); printf("\n"); static unsigned int useda, usedb, usedc, usedd, usede; static void print_bin(unsigned int num, unsigned int *used) @@ -269,7 +269,7 @@ static void zmv_header_write(struct zmv_header *zmv_head, FILE *fp) fwrite2(zmv_head->author_len, fp); fwrite3(zmv_head->zst_size, fp); fwrite2(zmv_head->initial_input, fp); - + switch (zmv_head->zmv_flag.start_method) { case zmv_sm_zst: @@ -538,7 +538,7 @@ static size_t internal_chapter_delete_after(struct internal_chapter_buf *icb, si /* -Bit Encoder and Decoder +Bit Encoder and Decoder */ @@ -560,7 +560,7 @@ size_t bit_encoder(unsigned int data, unsigned int mask, unsigned char *buffer, } skip_bits++; } - + if (!bit_loop) { break; } } @@ -571,7 +571,7 @@ size_t bit_decoder(unsigned int *data, unsigned int mask, unsigned char *buffer, { unsigned char bit_loop; *data = 0; - + for (bit_loop = 31; ; bit_loop--) { if (mask & BIT(bit_loop)) @@ -584,7 +584,7 @@ size_t bit_decoder(unsigned int *data, unsigned int mask, unsigned char *buffer, } if (!bit_loop) { break; } - } + } return(skip_bits); } @@ -664,7 +664,7 @@ static void load_last_joy_state(unsigned char *buffer) skip_bits = bit_decoder(&zmv_vars.last_joy_state.A, 0xFFF00000, buffer, skip_bits); zmv_vars.last_joy_state.A |= (zmv_vars.inputs_enabled & BIT(15)) ? 0x00008000 : 0; } - + if (zmv_vars.inputs_enabled & BIT(0x9)) //Mouse 2 { skip_bits = bit_decoder(&zmv_vars.last_joy_state.B, 0x00C0FFFF, buffer, skip_bits); @@ -684,7 +684,7 @@ static void load_last_joy_state(unsigned char *buffer) zmv_vars.last_joy_state.E = 0; } else - { + { skip_bits = bit_decoder(&zmv_vars.last_joy_state.C, 0xFFF00000, buffer, skip_bits); skip_bits = bit_decoder(&zmv_vars.last_joy_state.D, 0xFFF00000, buffer, skip_bits); skip_bits = bit_decoder(&zmv_vars.last_joy_state.E, 0xFFF00000, buffer, skip_bits); @@ -751,11 +751,11 @@ static size_t internal_chapter_length(size_t offset) fseek(zmv_vars.fp, offset, SEEK_SET); icl = fread3(zmv_vars.fp) & 0x007FFFFF; //The upper 9 bits are not part of the length icl += 3; //Add 3 for the header which says how long it is - + fseek(zmv_vars.fp, current_loc, SEEK_SET); return(icl); } - + /* Create and record ZMV @@ -783,11 +783,11 @@ static void zmv_create(char *filename) (IS_MOUSE_1() ? BIT(0xA) : 0) | (IS_MOUSE_2() ? BIT(0x9) : 0) | (IS_SCOPE() ? BIT(0x8) : 0); - + zmv_header_write(&zmv_vars.header, zmv_vars.fp); zmv_vars.inputs_enabled = zmv_vars.header.initial_input; - + switch (zmv_vars.header.zmv_flag.start_method) { case zmv_sm_zst: @@ -808,7 +808,7 @@ static void zmv_create(char *filename) zst_save(zmv_vars.fp, false, true); zmv_vars.filename = (char *)malloc(filename_len+1); //+1 for null strcpy(zmv_vars.filename, filename); - + debug_input_start; } else @@ -838,7 +838,7 @@ static void zmv_rle_flush() static void zmv_record_command(enum zmv_commands command) { - zmv_rle_flush(); + zmv_rle_flush(); zmv_vars.write_buffer[zmv_vars.write_buffer_loc++] = (command << 1) | BIT(0); @@ -851,7 +851,7 @@ static void zmv_record_command(enum zmv_commands command) prev = cur; \ flag |= BIT(bit); \ skip_bits = bit_encoder(prev, 0xFFF00000, press_buf, skip_bits); \ - } + } static void zmv_record(bool slow, unsigned char combos_used) { @@ -864,7 +864,7 @@ static void zmv_record(bool slow, unsigned char combos_used) zmv_vars.header.key_combos += combos_used; debug_input; - + RECORD_PAD(zmv_vars.last_joy_state.A, JoyAOrig, 7); RECORD_PAD(zmv_vars.last_joy_state.B, JoyBOrig, 6); RECORD_PAD(zmv_vars.last_joy_state.C, JoyCOrig, 5); @@ -893,7 +893,7 @@ static void zmv_record(bool slow, unsigned char combos_used) static bool zmv_insert_chapter() { if ((zmv_vars.header.internal_chapters < 65535) && zmv_vars.header.frames && - (zmv_vars.last_internal_chapter_offset != (ftell(zmv_vars.fp) + + (zmv_vars.last_internal_chapter_offset != (ftell(zmv_vars.fp) + zmv_vars.write_buffer_loc - INT_CHAP_SIZE(zmv_vars.last_internal_chapter_offset)))) { unsigned char flag = BIT(2); @@ -977,7 +977,7 @@ static bool zmv_open(char *filename) MovieStartMethod = (unsigned char)zmv_vars.header.zmv_flag.start_method; zmv_vars.inputs_enabled = zmv_vars.header.initial_input; zmv_open_vars.first_chapter_pos = ftell(zmv_vars.fp); - + if (zmv_vars.header.zsnes_version != (versionNumber & 0xFFFF)) { zst_compressed_loader(zmv_vars.fp); @@ -1030,7 +1030,7 @@ static bool zmv_open(char *filename) strcpy(zmv_vars.filename, filename); debug_input_start; - + return(true); } return(false); @@ -1095,7 +1095,7 @@ static bool zmv_replay() GUIReset = 1; ReturnFromSPCStall = 0; return(true); - } + } if (zmv_replay_command(command)); { return(zmv_replay()); @@ -1119,13 +1119,13 @@ static bool zmv_replay() { unsigned char press_buf[] = { 0, 0, 0, 0, 0, 0, 0, 0 }; size_t skip_bits = 0; - + REPLAY_PAD(zmv_vars.last_joy_state.A, JoyAOrig, 7); REPLAY_PAD(zmv_vars.last_joy_state.B, JoyBOrig, 6); REPLAY_PAD(zmv_vars.last_joy_state.C, JoyCOrig, 5); REPLAY_PAD(zmv_vars.last_joy_state.D, JoyDOrig, 4); REPLAY_PAD(zmv_vars.last_joy_state.E, JoyEOrig, 3); - + debug_input; } } @@ -1658,7 +1658,7 @@ static void raw_video_close() } fclose(raw_vid.fp); - raw_vid.fp = 0; + raw_vid.fp = 0; } } @@ -1695,7 +1695,7 @@ static void raw_video_write_frame() } raw_vid.frame_index++; - + if (raw_vid.frame_index == RAW_BUFFER_FRAMES) { fwrite(raw_vid.frame_buffer, RAW_PIXEL_FRAME_SIZE, RAW_BUFFER_FRAMES, raw_vid.fp); @@ -2053,7 +2053,7 @@ void Replay() if (zmv_frames_replayed()) { Msgptr = "MOVIE FINISHED."; - + if (RawDumpInProgress) { raw_video_close(); diff --git a/zsnes/src/zstate.c b/zsnes/src/zstate.c index a9cd4da1..54e455f3 100755 --- a/zsnes/src/zstate.c +++ b/zsnes/src/zstate.c @@ -235,7 +235,7 @@ void BackupCVFrame() { RewindPosPassed = true; } - + RewindTimer = ActualRewindFrames; } @@ -264,14 +264,14 @@ void RestoreCVFrame() } EMUPause = PauseRewind; } - + copy_state_data(RewindBufferPos, memcpyrinc, csm_load_rewind); //Clear Cache Check memset(vidmemch2, 1, sizeof(vidmemch2)); memset(vidmemch4, 1, sizeof(vidmemch4)); memset(vidmemch8, 1, sizeof(vidmemch8)); - + RewindTimer = ActualRewindFrames; } @@ -416,12 +416,13 @@ void ResetState() ResState(Voice7BufPtr); } -extern unsigned int statefileloc, CurrentHandle, SfxRomBuffer; -extern unsigned int SfxCROM, SfxLastRamAdr, SfxRAMMem; -extern unsigned int MsgCount, MessageOn; -extern unsigned char AutoIncSaveSlot, firstsaveinc, fnamest[512]; -extern unsigned char cbitmode, NoPictureSave, txtsavemsg[14]; -extern unsigned char *Msgptr, txtsavemsgfail[15]; +unsigned char firstsaveinc = 0, txtsavemsg[14] = "STATE - SAVED."; +unsigned char txtsavemsgfail[15] = "UNABLE TO SAVE."; + +extern unsigned int statefileloc, CurrentHandle, SfxRomBuffer, SfxCROM; +extern unsigned int SfxLastRamAdr, SfxRAMMem, MsgCount, MessageOn; +extern unsigned char AutoIncSaveSlot, fnamest[512], cbitmode, NoPictureSave; +extern unsigned char *Msgptr; extern unsigned short PrevPicture[64*56]; static FILE *fhandle; @@ -474,7 +475,7 @@ static bool zst_save_compressed(FILE *fp) } free(buffer); } - + if (!worked) //Compression failed for whatever reason { fwrite3(cur_zst_size | 0x00800000, fp); //Uncompressed ZST will never break 8MB @@ -482,7 +483,7 @@ static bool zst_save_compressed(FILE *fp) return(worked); } - + void zst_save(FILE *fp, bool Thumbnail, bool Compress) { PrepareOffset(); @@ -503,7 +504,7 @@ void zst_save(FILE *fp, bool Thumbnail, bool Compress) if (!Compress || !zst_save_compressed(fp)) //If we don't want compressed or compression failed { fwrite(zst_header_cur, 1, sizeof(zst_header_cur)-1, fp); //-1 for null - + fhandle = fp; //Set global file handle copy_state_data(0, write_save_state_data, csm_save_zst_new); @@ -513,7 +514,7 @@ void zst_save(FILE *fp, bool Thumbnail, bool Compress) fwrite(PrevPicture, 1, 64*56*sizeof(unsigned short), fp); } } - + if (SFXEnable) { SfxRomBuffer += SfxCROM; @@ -592,10 +593,13 @@ void statesaver() stim(); } +unsigned char txtloadmsg[16] = "STATE - LOADED."; +unsigned char txtconvmsg[17] = "STATE - TOO OLD."; +unsigned char txtnfndmsg[24] = "UNABLE TO LOAD STATE -."; + extern unsigned int KeyLoadState, Totalbyteloaded, SfxMemTable[256], SfxCPB; extern unsigned int SfxPBR, SfxROMBR, SfxRAMBR; -extern unsigned char pressed[256+128+64], multchange, txtloadmsg[15]; -extern unsigned char txtconvmsg[16], txtnfndmsg[23], ioportval, SDD1Enable; +extern unsigned char pressed[256+128+64], multchange, ioportval, SDD1Enable; extern unsigned char nexthdma; static void read_save_state_data(unsigned char **dest, void *data, size_t len) @@ -604,11 +608,11 @@ static void read_save_state_data(unsigned char **dest, void *data, size_t len) } static bool zst_load_compressed(FILE *fp, size_t compressed_size) -{ +{ unsigned long data_size = cur_zst_size - (sizeof(zst_header_cur)-1); unsigned char *buffer = 0; bool worked = false; - + if ((buffer = (unsigned char *)malloc(data_size))) { unsigned char *compressed_buffer = 0; @@ -624,7 +628,7 @@ static bool zst_load_compressed(FILE *fp, size_t compressed_size) free(compressed_buffer); } free(buffer); - } + } return(worked); } @@ -662,7 +666,7 @@ bool zst_load(FILE *fp, size_t Compressed) copy_state_data(0, read_save_state_data, (zst_version == 143) ? csm_load_zst_new: csm_load_zst_old ); Totalbyteloaded += load_save_size; } - + if (SFXEnable) { SfxCPB = SfxMemTable[(SfxPBR & 0xFF)]; @@ -708,11 +712,11 @@ bool zst_load(FILE *fp, size_t Compressed) //Wrapper for above bool zst_compressed_loader(FILE *fp) -{ +{ size_t data_size = fread3(fp); return((data_size & 0x00800000) ? zst_load(fp, 0) : zst_load(fp, data_size)); } - + void zst_sram_load(FILE *fp) { fseek(fp, sizeof(zst_header_cur)-1 + PH65816regsize + 199635, SEEK_CUR); @@ -772,7 +776,7 @@ void zst_sram_load_compressed(FILE *fp) free(compressed_buffer); } free(buffer); - } + } } }