def writeSong(self, index, song): '''Writes a song to the ROM, if there is already a song at the given index, this song will be overwritten.''' rom = self.rom voicegroup = song.voicegroup tracks = song.getTracks() print("> Writing song %d" %index) #Step 1, check wheter there is a song to overwrite self.assertSong(index) #Step 2, free space: song header and all song tracks self.truncSong(index) print(" > Space freed") #Step 3, find space # TODO For now this tool stores an entire song at one location # this could be separated in a later state of this software development. headerlength = 2+2+4 #short trackscount + short unknown + pointer voicegroup trackslength = 0 for track in tracks: headerlength += 4 #pointer to track trackslength += len(track) #one byte for each track instruction newchunksize = headerlength+trackslength newpointer = rom.findSpace(0x6b5640, newchunksize) print (" > Storing at pointer %X"%newpointer) #Step 4, write song and tracks #4.1 Prepare all tracks and their pointers romtracks = {} tp = newpointer + headerlength for track in tracks: track = self.fixTrackPointer(tp, track) romtracks[tp] = BBlock.fromBytes(track) tp += len(track) #TODO: Add trailing 000 00 or 0 (so song end is aligned at a group of 4 bytes) #4.2 Generate the header header = BBlock() header.addByte(len(tracks)) # Number of tracks header.addByte(song.numblks) header.addByte(song.priority) header.addByte(song.reverb) header.addPointer(voicegroup) # Used voicegroup for track for trackpointer in romtracks: header.addPointer(trackpointer) #4.3 Write header + tracks to rom rom.write(newpointer, header) rom.writeBlocks(romtracks) #Step 5, update table # -- todo: set newpointer in table as pointer to track index self.updateSongTable(index, newpointer)
def writeSong(self, index, song): '''Writes a song to the ROM, if there is already a song at the given index, this song will be overwritten.''' rom = self.rom voicegroup = song.voicegroup tracks = song.getTracks() print("> Writing song %d" % index) #Step 1, check wheter there is a song to overwrite self.assertSong(index) #Step 2, free space: song header and all song tracks self.truncSong(index) print(" > Space freed") #Step 3, find space # TODO For now this tool stores an entire song at one location # this could be separated in a later state of this software development. headerlength = 2 + 2 + 4 #short trackscount + short unknown + pointer voicegroup trackslength = 0 for track in tracks: headerlength += 4 #pointer to track trackslength += len(track) #one byte for each track instruction newchunksize = headerlength + trackslength newpointer = rom.findSpace(0x6b5640, newchunksize) print(" > Storing at pointer %X" % newpointer) #Step 4, write song and tracks #4.1 Prepare all tracks and their pointers romtracks = {} tp = newpointer + headerlength for track in tracks: track = self.fixTrackPointer(tp, track) romtracks[tp] = BBlock.fromBytes(track) tp += len(track) #TODO: Add trailing 000 00 or 0 (so song end is aligned at a group of 4 bytes) #4.2 Generate the header header = BBlock() header.addByte(len(tracks)) # Number of tracks header.addByte(song.numblks) header.addByte(song.priority) header.addByte(song.reverb) header.addPointer(voicegroup) # Used voicegroup for track for trackpointer in romtracks: header.addPointer(trackpointer) #4.3 Write header + tracks to rom rom.write(newpointer, header) rom.writeBlocks(romtracks) #Step 5, update table # -- todo: set newpointer in table as pointer to track index self.updateSongTable(index, newpointer)
def updateSongTable(self, trackid, pointer): '''Rewrites a value in the songtable, so it plays the song at the given pointer.''' p = self.tablepointer + 8*trackid data = BBlock() data.addPointer(pointer) data.addInt(0x00) self.rom.write(p, data)
def updateSongTable(self, trackid, pointer): '''Rewrites a value in the songtable, so it plays the song at the given pointer.''' p = self.tablepointer + 8 * trackid data = BBlock() data.addPointer(pointer) data.addInt(0x00) self.rom.write(p, data)