12Fermer14
deephLe 27/11/2012 à 11:00
Ça y est j'ai pigé le format des sprites 16 couleurs grin

Enfaite il fallait définir une palette, puis y faire référence dans le sprite (chaque pixel est codé sur 4 bits : 2^4=16) cheeky

img2asm.zip

Code source :
EnableExplicit
If OpenConsole() = 0
  MessageRequester("OpenConsole() error","Unable to open the console.",0)
  End
EndIf
Global NewList color.l()
Define i.l
Global str1$
For i = 1 To 17
  str1$ = str1$ + Chr(205)
Next
ConsoleTitle ("img2asm")
EnableGraphicalConsole(1)
PrintN(Chr(201)+str1$+Chr(187))
PrintN(Chr(186)+" img2asm - deeph "+Chr(186))
PrintN(Chr(200)+str1$+Chr(188))
PrintN("")
If CountProgramParameters() > 0
  Define file.s = ProgramParameter()
  If GetExtensionPart(file) = "jpg" Or GetExtensionPart(file) = "jpeg"
    UseJPEG2000ImageDecoder()
  ElseIf GetExtensionPart(file) = "png"
    UsePNGImageDecoder()
  ElseIf GetExtensionPart(file) = "tif"
    UseTIFFImageDecoder()
  ElseIf GetExtensionPart(file) = "tga"
    UseTGAImageDecoder()
  ElseIf GetExtensionPart(file) <> "bmp"
    PrintN("Error : image format unsupported.")
    End
  EndIf
  If LoadImage(0, file)
    If ImageDepth(0, #PB_Image_OriginalDepth) <> 5
      If CreateFile(0, GetPathPart(ProgramFilename())+ReplaceString(GetFilePart(file), GetExtensionPart(file), "asm"))
        If StartDrawing(ImageOutput(0))
          Define y.l, x.l, i.l = 0, new_color.l = 1
          ; on commence par définir la palette
          For y = 0 To ImageHeight(0)-1
            For x = 0 To ImageWidth(0)-1
              new_color = 1
              ForEach color()
                If Int(Red(Point(x, y))/8)+Int(Green(Point(x, y))/8)<<5+Int(Blue(Point(x, y))/8)<<10 = color()
                  new_color = 0
                  Break
                EndIf
              Next color()
              If new_color
                AddElement(color())
                color() = Int(Red(Point(x, y))/8)+Int(Green(Point(x, y))/8)<<5+Int(Blue(Point(x, y))/8)<<10
              EndIf
            Next x
          Next y
          SortList(color(), #PB_Sort_Ascending)
          WriteStringN(0, ReplaceString(GetFilePart(file), "."+GetExtensionPart(file), "")+"_palette:")
          WriteString(0, Chr(9)+"@dcw ")
          ForEach color()
            If i = 8
              WriteStringN(0, "")
              WriteString(0, Chr(9)+"@dcw ")
              i = 0
            ElseIf i>0
              WriteString(0, ",")
            EndIf
            i+1
            WriteString(0, "0x"+RSet(Hex(color()), 4, "0"))
          Next
          WriteStringN(0, "")
          WriteStringN(0, "")
          i = 0
          ; puis le sprite
          WriteStringN(0, ReplaceString(GetFilePart(file), "."+GetExtensionPart(file), "")+":")
          WriteString(0, Chr(9)+"@dcw 0x")
          For y = 0 To ImageHeight(0)-1
            For x = 0 To ImageWidth(0)-1
              If i = 8
                WriteStringN(0, "")
                WriteString(0, Chr(9)+"@dcw 0x")
                i = 0
              ElseIf i = 4
                WriteString(0, ",0x")
              EndIf
              i+1
              ForEach color()
                If color() = Int(Red(Point(x, y))/8)+Int(Green(Point(x, y))/8)<<5+Int(Blue(Point(x, y))/8)<<10
                  WriteString(0, Hex(ListIndex(color())))
                  Break
                EndIf
              Next color()
            Next x
          Next y
          WriteStringN(0, "")
          StopDrawing()
        EndIf
        PrintN(ReplaceString(GetFilePart(file), GetExtensionPart(file), "asm")+" correctly generated.")
        CloseFile(0)
      Else
        PrintN("Error : unable to create the output file.")
      EndIf
    Else
      PrintN("Error : incorrect image depth (use 16 colors).")
    EndIf
  Else
    PrintN("Error : unable to open the image.")
  EndIf
Else
  PrintN("Error : no input.")
EndIf
End

Donc pour l'instant mon convertisseur ne gère que les images 16 couleurs mais il accepte pas mal de formats (.bmp, .jpg, .jpeg, .png, .tif et .tga). Je compte rajouter le support des images 16-bits ensuite (pour les modes 3 et 5 il me semble).

Par contre lorsque j'essaie de tester l'affichage d'un sprite, le compilateur me sort des erreurs :
.arm
.include "../gba.inc"
.text
.global main

main:
	ldr r0,=OAM
	ldr r1,=128
	ldr r2,=(300<<16)

reset_sprites_loop:
	str r2,[r0]+8!
	subs r1,r1,#1
	bne reset_sprites_loop
	ldr r1,=REG_DISPCNT
	ldr r2,=(MODE_0|BG2_ENABLE|OBJ_ENABLE|OBJ_MAP_1D)
	str r2,[r1]
	ldr r0,=OAM
	ldr r1,=(SQUARE|COLOR_16|10)|((SIZE_32|10)<<16)
	str r1,[r0]+4!
	ldr r1,=0
	str r1,[r0]
	ldr r1,=OBJPAL
	ldr r2,=128
	ldr r3,=sprite_palette

palette_loop:
	ldr r7,[r3]+4!
	str r7,[r1]+4!
	subs r2,r2,#1
	bne palette_loop
	ldr r1,=CHARMEM
	ldr r2,=128
	ldr r3,=sprite

sprite_loop:
	ldr r7,[r3]+4!
	str r7,[r1]+4!
	subs r2,r2,#1
	bne sprite_loop

end:
	b end

.ltorg

.include "../sprite.asm"

(Ah et j'ai dû rajouter quelques trucs à gba.inc, d'ailleurs il y en aura sûrement plus à rajouter plus tard :
@@ SPRITES @@
ROTATION_FLAG	=	0x100
SIZE_DOUBLE	=	0x200
MODE_NORMAL	=	0x0
MODE_TRANSPERANT	=	0x400
MODE_WINDOWED	=	0x800
MOSAIC	=	0x1000
COLOR_16	=	0x0000
COLOR_256	=	0x2000
SQUARE	=	0x0
TALL	=	0x8000
WIDE	=	0x4000
HORIZONTAL_FLIP	=	0x1000
VERTICAL_FLIP	=	0x2000
SIZE_8	=	0x0
SIZE_16	=	0x4000
SIZE_32	=	0x8000
SIZE_64	=	0xC000
OAM	=	0x07000000 
OBJPAL	=	0x5000200
CHARMEM	=	0x6010000
CHARMEM_MODE3	=	0x6012BFD
)

Les erreurs sont :
test.s:12: Error: garbage following instruction -- `str r2, [r0]+8!`
test.s:20: Error: garbage following instruction -- `str r1, [r0]+4!`
test.s:28: Error: garbage following instruction -- `ldr r7, [r3]+4!`etc...