def writefile(data, filename=None, prompt=False, append=False): """Opens a file, writes data to it, and returns the filename""" if append: f = io.openfile(zcode.screen.currentWindow, 'a', filename, prompt) else: f = io.openfile(zcode.screen.currentWindow, 'w', filename, prompt) f.write(data) filename = f.name f.close() return filename
def readFile(length, filename=None, prompt=False, seek=0): f = io.openfile(zcode.screen.currentWindow, 'r', filename, prompt) if f == None: return False f.seek(seek) if length == -1: data = f.read() else: data = f.read(length) f.close() return data
def save(): f = io.openfile(zcode.screen.currentWindow, 'w') sd = quetzal.qdata() sd.release = zcode.header.release() sd.serial = zcode.header.serial() sd.checksum = zcode.header.getchecksum() sd.PC = PC sd.memory = zcode.memory.data[:zcode.header.statmembase()] sd.omemory = zcode.memory.originaldata[:zcode.header.statmembase()] sd.callstack = copy.deepcopy(callstack) sd.currentframe = copy.deepcopy(currentframe) return quetzal.save(f, sd)
def restore(filename=None, prompt=1): global PC, callstack, currentframe, interruptstack zcode.sounds.stopall() bis = interruptstack[:] interruptstack = [ ] # clear the interrupt stack, or it may do weird things after the game is restored f = io.openfile(zcode.screen.currentWindow, 'r') sd = quetzal.qdata() sd.release = zcode.header.release() sd.serial = zcode.header.serial() sd.checksum = zcode.header.getchecksum() sd.omemory = zcode.memory.originaldata[:zcode.header.statmembase()] sd = quetzal.restore(f.read(), sd) if sd == False: interruptstack = bis[:] # if the restore failed, put the interrupt stack back how it was return 0 zcode.memory.setarray(0, sd.memory) PC = sd.PC callstack = copy.deepcopy(sd.callstack) currentframe = copy.deepcopy(sd.currentframe) return 1
def output(self, data): data = data.replace('\r', '\n') if zcode.screen.currentWindow.testattribute(4): file = io.openfile(zcode.screen.currentWindow, 'a', self.filename) writefile(data.encode('utf-8'), filename=self.filename, prompt=False, append=True)
def output(self, data): file = io.openfile(zcode.screen.currentWindow, 'a', self.filename) writefile(data.encode('utf-8'), filename=self.filename, prompt=False, append=True)