all repos — mgba @ fade9941370ae801487c8ab39822f41fdd6a6f75

mGBA Game Boy Advance Emulator

Clean up logic with an EOF tag
Jeffrey Pfau jeffrey@endrift.com
Tue, 29 Jul 2014 23:13:16 -0700
commit

fade9941370ae801487c8ab39822f41fdd6a6f75

parent

68454549690cb0d4bb60d2fd200b275b5f602571

2 files changed, 15 insertions(+), 15 deletions(-)

jump to
M src/gba/gba-rr.csrc/gba/gba-rr.c

@@ -3,6 +3,8 @@

#include "gba.h" #include "util/vfs.h" +#define BINEXT ".log" + static enum GBARRTag _readTag(struct GBARRContext* rr, struct VFile* vf); static bool _seekTag(struct GBARRContext* rr, struct VFile* vf, enum GBARRTag tag); static bool _emitTag(struct GBARRContext* rr, struct VFile* vf, uint8_t tag);

@@ -49,7 +51,7 @@ }

rr->movieStream = 0; rr->streamId = streamId; char buffer[14]; - snprintf(buffer, sizeof(buffer), "%u.log", streamId); + snprintf(buffer, sizeof(buffer), "%u" BINEXT, streamId); if (GBARRIsRecording(rr)) { rr->movieStream = rr->streamDir->openFile(rr->streamDir, buffer, O_TRUNC | O_CREAT | O_WRONLY); } else if (GBARRIsPlaying(rr)) {

@@ -240,14 +242,16 @@ case TAG_LAG:

case TAG_BEGIN: case TAG_END: case TAG_INVALID: + case TAG_EOF: break; } uint8_t tagBuffer; if (vf->read(vf, &tagBuffer, 1) != 1) { - tagBuffer = TAG_END; + rr->peekedTag = TAG_EOF; + } else { + rr->peekedTag = tagBuffer; } - rr->peekedTag = tagBuffer; return tag; }

@@ -255,19 +259,13 @@ bool _seekTag(struct GBARRContext* rr, struct VFile* vf, enum GBARRTag tag) {

enum GBARRTag readTag; while ((readTag = _readTag(rr, vf)) != tag) { if (readTag == TAG_END) { - if (rr->peekedTag == TAG_NEXT_TIME) { - while (_readTag(rr, vf) != TAG_END) { - if (!rr->nextTime) { - return false; - } - } - if (!rr->nextTime || !GBARRLoadStream(rr, rr->nextTime)) { - return false; - } - vf = rr->movieStream; - } else { + while (_readTag(rr, vf) != TAG_EOF); + if (!rr->nextTime || !GBARRLoadStream(rr, rr->nextTime)) { return false; } + vf = rr->movieStream; + } else if (readTag == TAG_EOF) { + return false; } } return true;
M src/gba/gba-rr.hsrc/gba/gba-rr.h

@@ -29,7 +29,9 @@ TAG_INIT_TYPE = 0x23,

// User metadata tags TAG_AUTHOR = 0x30, - TAG_COMMENT = 0x31 + TAG_COMMENT = 0x31, + + TAG_EOF = INT_MAX }; struct GBARRContext {