gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

OffTopic > Suggestion for 8TED to support XY-MINI format

#158224 - zzo38computer - Sat Jun 07, 2008 8:01 pm

Suggestion for 8TED to support XY-MINI format. 1-bit (PC) mode is compatible with XY-MINI monochrome tile mode. The other modes don't work yet in 8TED. The other suggestion is to add some of the features of the DOS TILEMAKR that I made for editing monochrome XY-MINI tiles (the source-code is below). Some of these features are: AND/OR/XOR of tiles with the clipboard, and some functions for dealing with a whole row, flip/mirror/negative tiles, and a few others.

Code:
DECLARE FUNCTION MirrorTile$ (t$)
DECLARE FUNCTION FlipTile$ (t$)
DECLARE FUNCTION SaveTile$ (BYVAL x!, BYVAL y!, BYVAL B%, BYVAL f%)
DECLARE SUB DrawTile (BYVAL x!, BYVAL y!, t$, BYVAL B%, BYVAL f%)
TYPE TileData
 s AS STRING * 8
END TYPE
DIM tiles(0 TO 255) AS TileData, clip AS TileData, edittile AS TileData

FILES
INPUT filename$
SCREEN 1
OPEN filename$ FOR BINARY AS #1
FOR i% = 0 TO 255
 GET #1, , tiles(i%)
NEXT i%
CLOSE

TileSelection:
CLS
LOCATE 1, 2: PRINT "0123456789ABCDEF"
LOCATE 18, 2: PRINT "0123456789ABCDEF"
FOR i% = 0 TO 15
 LOCATE 2 + i%, 1: PRINT HEX$(i%);
 LOCATE 2 + i%, 18: PRINT HEX$(i%);
 FOR j% = 0 TO 15
  DrawTile j% * 8 + 8, i% * 8 + 8, tiles(i% * 16 + j%).s, 0, 1
 NEXT j%
NEXT i%
sel% = 0
DO
 a$ = INKEY$
 IF LEN(a$) = 1 THEN a$ = LCASE$(a$)
 DrawTile (sel% MOD 16) * 8 + 8, (sel% \ 16) * 8 + 8, tiles(sel%).s, 0, 1
 SELECT CASE a$
  CASE "q", CHR$(27)
   OPEN filename$ FOR BINARY AS #1
   FOR i% = 0 TO 255
    PUT #1, , tiles(i%)
   NEXT i%
   CLOSE
   END
  CASE CHR$(3): END
  CASE "s"
   OPEN filename$ FOR BINARY AS #1
   FOR i% = 0 TO 255
    PUT #1, , tiles(i%)
   NEXT i%
   CLOSE
  CASE CHR$(0) + CHR$(72): sel% = (sel% + 240) MOD 256
  CASE CHR$(0) + CHR$(75): sel% = (sel% + 255) MOD 256
  CASE CHR$(0) + CHR$(77): sel% = (sel% + 1) MOD 256
  CASE CHR$(0) + CHR$(80): sel% = (sel% + 16) MOD 256
  CASE "c": clip = tiles(sel%)
  CASE "v": tiles(sel%) = clip
  CASE "n"
   FOR i% = 1 TO 8
    MID$(tiles(sel%).s, i%, 1) = CHR$(255 - ASC(MID$(tiles(sel%).s, i%, 1)))
   NEXT i%
  CASE CHR$(0) + CHR$(83): tiles(sel%).s = STRING$(8, 0)
  CASE "k"
   LOCATE 1, 1: PRINT INPUT$(1);
   tiles(sel%).s = SaveTile$(0, 0, 0, 3)
   LOCATE 1, 1: PRINT " ";
  CASE CHR$(1)
   FOR i% = 0 TO 255
    LOCATE 1, 1: PRINT CHR$(i%);
    tiles(i%).s = SaveTile$(0, 0, 0, 3)
   NEXT i%
   GOTO TileSelection
  CASE "`": GOTO TileSelection
  CASE "e", CHR$(13): GOSUB TileEditor
  CASE "f": tiles(sel%).s = FlipTile$(tiles(sel%).s)
  CASE "m": tiles(sel%).s = MirrorTile$(tiles(sel%).s)
  CASE "x"
   FOR i% = 1 TO 8
    k% = ASC(MID$(tiles(sel%).s, i%, 1))
    k% = k% XOR ASC(MID$(clip.s, i%, 1))
    MID$(tiles(sel%).s, i%, 1) = CHR$(k%)
   NEXT i%
  CASE "o"
   FOR i% = 1 TO 8
    k% = ASC(MID$(tiles(sel%).s, i%, 1))
    k% = k% OR ASC(MID$(clip.s, i%, 1))
    MID$(tiles(sel%).s, i%, 1) = CHR$(k%)
   NEXT i%
  CASE "a"
   FOR i% = 1 TO 8
    k% = ASC(MID$(tiles(sel%).s, i%, 1))
    k% = k% AND ASC(MID$(clip.s, i%, 1))
    MID$(tiles(sel%).s, i%, 1) = CHR$(k%)
   NEXT i%
  CASE "w": GOTO KeyInTiles
  CASE "r"
   sel% = sel% AND &HF0
   k% = VAL("&H" + INPUT$(1))
   FOR i% = 0 TO 15
    tiles(sel% + i%).s = tiles(k% * 16 + i%).s
   NEXT i%
   GOTO TileSelection
 END SELECT
 DrawTile (sel% MOD 16) * 8 + 8, (sel% \ 16) * 8 + 8, tiles(sel%).s, 2, 3
LOOP

TileEditor:
edittile = tiles(sel%)
ei% = 0: ej% = 0
RedrawTileEditor:
FOR i% = 0 TO 7
 FOR j% = 0 TO 7
  k% = ASC(MID$(edittile.s, i% + 1, 1)) AND (2 ^ j%)
  IF k% > 0 THEN
   LINE (200 + 8 * (7 - j%), 15 + 8 * i%)-STEP(6, 6), 2, BF
  ELSE
   LINE (200 + 8 * (7 - j%), 15 + 8 * i%)-STEP(6, 6), 0, BF
  END IF
  LINE (200 + 8 * (7 - j%), 15 + 8 * i%)-STEP(6, 6), 3, B
 NEXT j%
NEXT i%
DrawTile (sel% MOD 16) * 8 + 8, (sel% \ 16) * 8 + 8, edittile.s, 2, 3
DO
 k% = ASC(MID$(edittile.s, ei% + 1, 1)) AND (2 ^ ej%)
 IF k% > 0 THEN
  LINE (200 + 8 * (7 - ej%), 15 + 8 * ei%)-STEP(6, 6), 2, BF
 ELSE
  LINE (200 + 8 * (7 - ej%), 15 + 8 * ei%)-STEP(6, 6), 0, BF
 END IF
 LINE (200 + 8 * (7 - ej%), 15 + 8 * ei%)-STEP(6, 6), 3, B
 a$ = INKEY$
 IF LEN(a$) = 1 THEN a$ = LCASE$(a$)
 SELECT CASE a$
  CASE CHR$(27), CHR$(13): EXIT DO
  CASE CHR$(0) + CHR$(72): ei% = (ei% + 7) MOD 8
  CASE CHR$(0) + CHR$(75): ej% = (ej% + 1) MOD 8
  CASE CHR$(0) + CHR$(77): ej% = (ej% + 7) MOD 8
  CASE CHR$(0) + CHR$(80): ei% = (ei% + 1) MOD 8
  CASE " "
   k% = ASC(MID$(edittile.s, ei% + 1, 1))
   MID$(edittile.s, ei% + 1, 1) = CHR$(k% XOR (2 ^ ej%))
  CASE "n"
   FOR i% = 1 TO 8
    MID$(edittile.s, i%, 1) = CHR$(255 - ASC(MID$(edittile.s, i%, 1)))
   NEXT i%
   GOTO RedrawTileEditor
  CASE CHR$(0) + CHR$(141)
   edittile.s = MID$(edittile.s, 2) + edittile.s: GOTO RedrawTileEditor
  CASE CHR$(0) + CHR$(115)
   FOR i% = 1 TO 8
    k% = ASC(MID$(edittile.s, i%, 1))
    MID$(edittile.s, i%, 1) = CHR$(((2 * k%) AND 255) + k% \ 128)
   NEXT i%
   GOTO RedrawTileEditor
  CASE CHR$(0) + CHR$(116)
   FOR i% = 1 TO 8
    k% = ASC(MID$(edittile.s, i%, 1))
    MID$(edittile.s, i%, 1) = CHR$(k% \ 2 + (k% AND 1) * 128)
   NEXT i%
   GOTO RedrawTileEditor
  CASE CHR$(0) + CHR$(145)
   edittile.s = MID$(edittile.s, 8) + edittile.s: GOTO RedrawTileEditor
  CASE "f": edittile.s = FlipTile$(edittile.s): GOTO RedrawTileEditor
  CASE "m": edittile.s = MirrorTile$(edittile.s): GOTO RedrawTileEditor
  CASE ELSE
   'IF LEN(a$) = 2 THEN LOCATE 21: PRINT ASC(RIGHT$(a$, 1));
 END SELECT
 k% = ASC(MID$(edittile.s, ei% + 1, 1)) AND (2 ^ ej%)
 IF k% > 0 THEN
  LINE (200 + 8 * (7 - ej%), 15 + 8 * ei%)-STEP(6, 6), 2, BF
 ELSE
  LINE (200 + 8 * (7 - ej%), 15 + 8 * ei%)-STEP(6, 6), 0, BF
 END IF
 LINE (200 + 8 * (7 - ej%), 15 + 8 * ei%)-STEP(6, 6), 1, B
 IF a$ <> "" THEN DrawTile (sel% MOD 16) * 8 + 8, (sel% \ 16) * 8 + 8, edittile.s, 2, 3
LOOP
LINE (200, 15)-STEP(8 * 8, 8 * 8), 0, BF
tiles(sel%) = edittile
RETURN

KeyInTiles:
DO
 a$ = INPUT$(1)
 LOCATE (sel% \ 16) + 2, (sel% MOD 16) + 2: PRINT a$;
 IF ASC(a$) > 31 THEN
  tiles(sel%).s = SaveTile$((sel% MOD 16) * 8 + 8, (sel% \ 16) * 8 + 8, 0, 3)
 ELSE
  EXIT DO
 END IF
 sel% = (sel% + 1) MOD 256
LOOP
GOTO TileSelection

SUB DrawTile (BYVAL x!, BYVAL y!, t$, BYVAL B%, BYVAL f%)
 FOR i% = 0 TO 7
  FOR j% = 0 TO 7
   k% = ASC(MID$(t$, i% + 1, 1)) AND (2 ^ j%)
   IF k% > 0 THEN k% = f% ELSE k% = B%
   PSET (x! + 7 - j%, y! + i%), k%
  NEXT j%
 NEXT i%
END SUB

FUNCTION FlipTile$ (t$)
a$ = ""
FOR i% = 8 TO 1 STEP -1
 a$ = a$ + MID$(t$, i%, 1)
NEXT i%
FlipTile$ = a$
END FUNCTION

FUNCTION MirrorTile$ (t$)
a$ = ""
FOR i% = 1 TO 8
 k1% = ASC(MID$(t$, i%, 1)): k% = 0
 FOR j% = 0 TO 7
  k% = k% + (k1% AND (2 ^ j%)) * (2 ^ (7 - j%)) / (2 ^ j%)
 NEXT j%
 a$ = a$ + CHR$(k%)
NEXT i%
MirrorTile$ = a$
END FUNCTION

FUNCTION SaveTile$ (BYVAL x!, BYVAL y!, BYVAL B%, BYVAL f%)
 t$ = STRING$(8, 0)
 FOR i% = 0 TO 7
  FOR j% = 0 TO 7
   'k% = ASC(MID$(t$, i% + 1, 1)) AND (2 ^ j%)
   'IF k% > 0 THEN k% = f% ELSE k% = b%
   'PSET (x! + 7 - j%, y! + i%), k%
   k% = POINT(x! + 7 - j%, y! + i%)
   IF k% = f% THEN MID$(t$, i% + 1, 1) = CHR$(ASC(MID$(t$, i% + 1, 1)) + (2 ^ j%))
  NEXT j%
 NEXT i%
 SaveTile$ = t$
END FUNCTION

_________________
Important: Please send messages about FWNITRO to the public forum, not privately to me.

#158238 - tepples - Sun Jun 08, 2008 2:20 am

zzo38computer wrote:
Suggestion for 8TED to support XY-MINI format. 1-bit (PC) mode is compatible with XY-MINI monochrome tile mode. The other modes don't work yet in 8TED.

That would break several assumptions in 8TED, such as the assumption that each tile is one contiguous block of data. If a platforms store bitplanes separately, how would 8TED know the distance in bytes between bitplanes of a single tile? But you can edit tiles in Game Boy (2-bit, row interleaved), NES (2-bit, tile interleaved), or SMS (4-bit, row interleaved) format and then deinterleave them either at build time or at runtime.

Quote:
The other suggestion is to add some of the features of the DOS TILEMAKR that I made for editing monochrome XY-MINI tiles (the source-code is below). Some of these features are: AND/OR/XOR of tiles with the clipboard, and some functions for dealing with a whole row, flip/mirror/negative tiles, and a few others.

Mirror and flip are in. Press H, V, or R while a tile is loaded into the editor. In the build on my hard drive, I have been experimenting with a tool that exchanges the left-click and right-click colors in a given tile, which might match your "negative". AND and OR sound interesting, and I might figure out how to turn them into some sort of "overlay tool".
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.