Register | Login
Views: 19364387
Main | Memberlist | Active users | ACS | Commons | Calendar | Online users
Ranks | FAQ | Color Chart | Photo album | IRC Chat
11-02-05 12:59 PM
0 user currently in Programming. | 3 guests
Acmlm's Board - I2 Archive - Programming - GBC Tile Format (VB related) | |
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
User Post
HyperLamer
<||bass> and this was the soloution i thought of that was guarinteed to piss off the greatest amount of people

Sesshomaru
Tamaranian

Level: 118

Posts: 178/8210
EXP: 18171887
For next: 211027

Since: 03-15-04
From: Canada, w00t!
LOL FAD

Since last post: 2 hours
Last activity: 2 hours
Posted on 03-27-04 04:28 AM Link | Quote
[edit]
Doh, stupid me. I'd merely mucked up the drawing procedure (each time through the For loop that draws the pixel, I needed to increment the X coord, whereas I only did it once, so I drew all 8 pixels of a row in the same place. It looked like total garbage and didn't crash because of the use of pointers simply reading random crap outta RAM.

So, since it works now, here's the full code:

'Increment a Long value as if unsigned
Function IncLongUnsigned(Value As Long) As Long
If Value < &H7FFFFFFF And Value >= 0 Then
IncLongUnsigned = Value + 1
ElseIf Value > -2147483648# Then
IncLongUnsigned = Value - 1
ElseIf Value = &H7FFFFFFF Then
IncLongUnsigned = -2147483648#
ElseIf Value = -2147483648# Then
IncLongUnsigned = &H7FFFFFFF
End If
End Function

'Params: SrcArrayPtr=Pointer to source byte array (first byte of tile, 16 bytes)
'Required API Declarations: CopyMemory(), SetPixel()
Sub GB2BPPToRGB(SrcArrayPtr As Long, DestDC As Long, Optional XPos As Long, Optional YPos As Long, Optional C1 As Long = &HFFFFFF, Optional C2 As Long = &HAFAFAF, Optional C3 As Long = &H5F5F5F, Optional C4 As Long = 0)
Dim ArrayPtr As Long, Bits(0 To 7) As Byte, C As Integer, Colour(0 To 3) As Long
Dim XP As Byte, YP As Byte 'Draw coords
Dim P1 As Byte, P2 As Byte 'Pixel data
Colour(0) = C1 'Set the colour array
Colour(1) = C2
Colour(2) = C3
Colour(3) = C4
TempByte = 128
For C = 7 To 0 Step -1 'Set the Binary place values
Bits(C) = TempByte
TempByte = TempByte \ 2
Next C
ArrayPtr = SrcArrayPtr

Do
CopyMemory ByVal VarPtr(P1), ByVal ArrayPtr, 1 'Get 2 bytes from the array
ArrayPtr = IncLongUnsigned(ArrayPtr) 'Since we can't pass an array and Variants suck, we pass a pointer
CopyMemory ByVal VarPtr(P2), ByVal ArrayPtr, 1
ArrayPtr = IncLongUnsigned(ArrayPtr)

For C = 7 To 0 Step -1
TempByte = P1 'Get specific bits of each byte
TempByte2 = P2
TempByte = (TempByte And Bits(C)) / (2 ^ C)
TempByte2 = (TempByte2 And Bits(C)) / (2 ^ C)
TempByte3 = (TempByte2 * 2) + TempByte 'TempByte3=Colour #
'Debug.Print TempByte, TempByte2
SetPixel DestDC, XP + XPos, YP + YPos, Colour(TempByte3) 'Draw the pixel
XP = XP + 1 'Inc the x position
Next C
XP = 0
YP = YP + 1 'Inc the y position
Loop Until YP = 8
End Sub


Example use: GB2BPPToRGB VarPtr(TileData(1)), Me.hdc, 8, 12, &hFFFFFF, &h0000FF, &h00FF00, &hFF0000
^ Will draw on the current form starting at X position 8, Y position 12, using the colours white, red, green and blue (Windoze uses BGR). TileData should be an array of 16 bytes. (You don't have to use the first entry of the array, just the first byte of the graphic, it can be VarPtr(TileData(5465642)) for all the code cares. )

The included function IncLongUnsigned is merely for, as the name implies, incrementing a Long as if it were unsigned (since if I just add one to the pointer and it's above 0x7FFFFFFF VB interprets it as negative and I end up subtracting, and of course there's the potential for overflow). Use it however you want.


(edited by HyperHacker on 03-26-04 09:14 PM)
dan

Snap Dragon
Level: 43

Posts: 20/782
EXP: 534516
For next: 30530

Since: 03-15-04

Since last post: 20 hours
Last activity: 14 hours
Posted on 03-27-04 05:01 AM Link | Quote
Is there a tile editor that supports this format? If so, you could reverse engineer the format from that, just to be sure.
Darth Coby

Vire
Dacht je nou echt dat het over was?
Dacht je nou echt dat ik gebroken was? Nee toch?
Nou kijk eens goed op uit je ogen gast.
zonder clic heb je geen kloten tjap... bitch
Level: 55

Posts: 262/1371
EXP: 1240774
For next: 73415

Since: 03-15-04
From: Belgium

Since last post: 2 days
Last activity: 9 hours
Posted on 03-28-04 04:01 AM Link | Quote
w00t! Source code!
*Coby goes to study
Add to favorites | "RSS" Feed | Next newer thread | Next older thread
Acmlm's Board - I2 Archive - Programming - GBC Tile Format (VB related) | |


ABII


AcmlmBoard vl.ol (11-01-05)
© 2000-2005 Acmlm, Emuz, et al



Page rendered in 0.012 seconds.