elixirnova
Posts: 81/177 |
sure thing plus i now have somewhat an idea how to do it but a bit of a delima here it is: hrm its a bit big but ah well Public Sub CreateMetaTable(ByVal sFile As String, ByVal lOffset As Long, ByVal lNoTiles As Long) ' Temporary buffer for the 4BPP tiles Dim bTiles() As Byte, i As Long, cBitMask As Byte, ixMT As Integer, ixTile As Integer, mVal As Byte
' Indexed pixels (speed! speed!) Dim ix_1 As Long, ix_2 As Long, ix_3 As Long, ix_4 As Long
' Verify file If Dir$(sFile) = "" Then MsgBox("File not found [" & sFile & "]", vbCritical + vbOKOnly, "cls4BPP Class") Exit Sub End If
' Allocate memory for tiles If lNoTiles > 0 Then ReDim MetaTable((lNoTiles * 64) - 1) ReDim bTiles((lNoTiles * 32) - 1) Else MsgBox("Can't rip 0 tiles.", vbCritical + vbOKOnly, "cls4BPP Class") Exit Sub End If
' Get tiles FileOpen(FileNumber, sFile, OpenMode.Binary, OpenAccess.Read) FileGet(FileNumber, bTiles, lOffset + 1) FileClose(FileNumber)
' Create Meta Table For i = 0 To (lNoTiles - 1) For ixTile = 0 To 7 ' Reset bitmask cBitMask = 128 ix_1 = (i * 32) + (ixTile * 2) : ix_2 = (i * 32) + (ixTile * 2) + 1 ix_3 = (i * 32) + (ixTile * 2) + 16 : ix_4 = (i * 32) + (ixTile * 2) + 17
' Coded in "loopless" form to gain some speed. MetaTable(i * 64 + ixTile * 8 + 0) = ((bTiles(ix_1) And cBitMask) / cBitMask) Or (((bTiles(ix_2) And cBitMask) / cBitMask) * 2) Or (((bTiles(ix_3) And cBitMask) / cBitMask) * 4) Or (((bTiles(ix_4) And cBitMask) / cBitMask) * 8) : cBitMask = RShift(cBitMask, 1) MetaTable(i * 64 + ixTile * 8 + 1) = ((bTiles(ix_1) And cBitMask) / cBitMask) Or (((bTiles(ix_2) And cBitMask) / cBitMask) * 2) Or (((bTiles(ix_3) And cBitMask) / cBitMask) * 4) Or (((bTiles(ix_4) And cBitMask) / cBitMask) * 8) : cBitMask = RShift(cBitMask, 1) MetaTable(i * 64 + ixTile * 8 + 2) = ((bTiles(ix_1) And cBitMask) / cBitMask) Or (((bTiles(ix_2) And cBitMask) / cBitMask) * 2) Or (((bTiles(ix_3) And cBitMask) / cBitMask) * 4) Or (((bTiles(ix_4) And cBitMask) / cBitMask) * 8) : cBitMask = RShift(cBitMask, 1) MetaTable(i * 64 + ixTile * 8 + 3) = ((bTiles(ix_1) And cBitMask) / cBitMask) Or (((bTiles(ix_2) And cBitMask) / cBitMask) * 2) Or (((bTiles(ix_3) And cBitMask) / cBitMask) * 4) Or (((bTiles(ix_4) And cBitMask) / cBitMask) * 8) : cBitMask = RShift(cBitMask, 1) MetaTable(i * 64 + ixTile * 8 + 4) = ((bTiles(ix_1) And cBitMask) / cBitMask) Or (((bTiles(ix_2) And cBitMask) / cBitMask) * 2) Or (((bTiles(ix_3) And cBitMask) / cBitMask) * 4) Or (((bTiles(ix_4) And cBitMask) / cBitMask) * 8) : cBitMask = RShift(cBitMask, 1) MetaTable(i * 64 + ixTile * 8 + 5) = ((bTiles(ix_1) And cBitMask) / cBitMask) Or (((bTiles(ix_2) And cBitMask) / cBitMask) * 2) Or (((bTiles(ix_3) And cBitMask) / cBitMask) * 4) Or (((bTiles(ix_4) And cBitMask) / cBitMask) * 8) : cBitMask = RShift(cBitMask, 1) MetaTable(i * 64 + ixTile * 8 + 6) = ((bTiles(ix_1) And cBitMask) / cBitMask) Or (((bTiles(ix_2) And cBitMask) / cBitMask) * 2) Or (((bTiles(ix_3) And cBitMask) / cBitMask) * 4) Or (((bTiles(ix_4) And cBitMask) / cBitMask) * 8) : cBitMask = RShift(cBitMask, 1) MetaTable(i * 64 + ixTile * 8 + 7) = ((bTiles(ix_1) And cBitMask) / cBitMask) Or (((bTiles(ix_2) And cBitMask) / cBitMask) * 2) Or (((bTiles(ix_3) And cBitMask) / cBitMask) * 4) Or (((bTiles(ix_4) And cBitMask) / cBitMask) * 8) : cBitMask = RShift(cBitMask, 1) Next ixTile Next i
' Wipe out bTiles Erase bTiles End Sub
Private Function LShift(ByVal pnValue As Long, ByVal pnShift As Long) LShift = CByte((pnValue * (2 ^ pnShift)) And 255) End Function
Private Function RShift(ByVal pnValue As Long, ByVal pnShift As Long) RShift = CByte((pnValue \ (2 ^ pnShift)) And 255) End Function ------------------------------------------------------ what all that does is takes two bytes and splits them up into a 4bpp pixels so metatable(0) would be a palette color 0-15 (16color palette) lets say metatable(0) = 1 and metatable(1) = 11 so now in binary i have 0000 0001 and 0000 1011 so now somehow ive got to convert each of these bytes in metatable back into this format saying a=metatable(0) b=metatable(1) c=metatable(2) d=metatable(3) ------------------ w=metatable(4) x=metatable(5) y=metatable(6) z=metatable(7) ------------------- so now lets make another graphic the binary equivalent a) xxxx nxxx b) xxxx nxxx.......... <' and take the n bit from each of the letters a-d and rearrange them into a byte like this 'byte1 = aN bN cN dN 0000' and that being a binary value of the byte... ah and then somehow ive got to take wxyz in the previous example using the method 1 and placing their n bits like so 'byte2 =0000 wN xN yN zN' and then do (hexbyte1 being the first of the 2 bytes that make up one tile in an snes rom) hexbyte1 = byte1 + byte2 'which is now aN bN cN dN wN xN yN zN ---and then do the same with 8-15 and arrange them to = hexbyte2 and then simply save hexbyte1 , hexbyte2 to the rom... in that order... hrm though im gonna play around with it some more tomorrow SM gave me this algorythm that supposedly takes abcd's n value and puts it into the order aN bN cN dN 0000 here it is: byte1 = (a And &H80 + (b And &H80) / 2 + (c And &H80) / 4 + (d And &H80) / 8) i know thats alota stuff but maybe someone will be able to use it for somthing else. Anyhow i think i might be able to get it now. I'll post what I come up with tomorrow durring keyboarding. Maybe i'll come up with somthing that works .
Chickenlump
Posts: 390/722 |
I wouldn't mind having a look, if you don't mind posting it that is.
I've played around with it a couple of times, I wouldn't mind learning a bit more. |
elixirnova
Posts: 80/177 |
hello... again... i got tfg's graphics routine working but i dont get how to undo it to save it back to the rom O_o... so i have the metatable thats been edited so just wondering if anyone knows how i could convert the metatable back to its state it would be in the rom if ya want the code say so and ill post it... |
|