Fixed tile address calculation and tileset numbering.

This commit is contained in:
Martin Haye 2015-01-27 08:36:05 -08:00
parent dc194d44f7
commit b9a4caba1f
3 changed files with 43 additions and 32 deletions

View File

@ -450,8 +450,7 @@ class PackPartitions
(0..<TILES_PER_ROW).each { colNum -> (0..<TILES_PER_ROW).each { colNum ->
def x = hOff + colNum def x = hOff + colNum
def tile = (row && x < width) ? row[x] : null def tile = (row && x < width) ? row[x] : null
def id = tile?.@id buf.put((byte)(tile ? tileMap[tile.@id] : 0))
buf.put((byte)(id ? tileMap[tile?.@id] : 0))
} }
} }
} }
@ -660,18 +659,21 @@ class PackPartitions
def setName = "tileSet${setNum}" def setName = "tileSet${setNum}"
def tileMap = [null:0] def tileMap = [null:0]
def buf = ByteBuffer.allocate(50000) def buf = ByteBuffer.allocate(50000)
// Start with the empty tile
(0..31).each { buf.put((byte)0) }
// Then add each non-null tile to the set
rows.each { row -> rows.each { row ->
row.each { tile -> row.each { tile ->
if (tile) { def id = tile?.@id
def id = tile.@id if (tile && !tileMap.containsKey(id)) {
if (!tileMap.containsKey(id)) { def num = tileMap.size()
def num = tileMap.size() + 1 assert num < 32 : "Temporary, need to fix: Only 32 kinds of tiles are allowed on any given map."
assert num < 32 : "Temporary, need to fix: Only 32 kinds of tiles are allowed on any given map." tileMap[id] = num
tileMap[id] = num tiles[id].flip() // crazy stuff to append one buffer to another
tiles[id].flip() // crazy stuff to append one buffer to another buf.put(tiles[id])
buf.put(tiles[id]) tiles[id].compact() // more of crazy stuff above
tiles[id].compact() // more of crazy stuff above
}
} }
} }
} }

View File

@ -872,6 +872,7 @@ def move2D(ox, oy)
*relX = ox + *relX *relX = ox + *relX
*relY = oy + *relY *relY = oy + *relY
checkCrossing() checkCrossing()
renderFrame()
end end
def moveNorth() def moveNorth()

View File

@ -12,7 +12,7 @@
!source "../include/mem.i" !source "../include/mem.i"
!source "../include/plasma.i" !source "../include/plasma.i"
DEBUG = 1 ; 1=some logging, 2=lots of logging DEBUG = 0 ; 1=some logging, 2=lots of logging
HEADER_LENGTH=6 HEADER_LENGTH=6
SECTION_WIDTH=22 SECTION_WIDTH=22
@ -44,10 +44,10 @@ NW_MAP_LOC=$52
NE_MAP_LOC=$54 NE_MAP_LOC=$54
SW_MAP_LOC=$56 SW_MAP_LOC=$56
SE_MAP_LOC=$58 SE_MAP_LOC=$58
NW_TILESET_LOC=$70 NW_TILESET_LOC=$90
NE_TILESET_LOC=$72 NE_TILESET_LOC=$92
SW_TILESET_LOC=$74 SW_TILESET_LOC=$94
SE_TILESET_LOC=$76 SE_TILESET_LOC=$96
; Map section IDs (255 = not loaded) ; Map section IDs (255 = not loaded)
NOT_LOADED=$FF NOT_LOADED=$FF
NW_MAP_ID=$5A NW_MAP_ID=$5A
@ -214,9 +214,9 @@ FREE_ALL_TILES
LOAD_ALL_TILES LOAD_ALL_TILES
+loadTileset NW_MAP_LOC, NW_TILESET_LOC +loadTileset NW_MAP_LOC, NW_TILESET_LOC
+loadTileset NE_MAP_LOC, NW_TILESET_LOC +loadTileset NE_MAP_LOC, NE_TILESET_LOC
+loadTileset SW_MAP_LOC, NW_TILESET_LOC +loadTileset SW_MAP_LOC, SW_TILESET_LOC
+loadTileset SE_MAP_LOC, NW_TILESET_LOC +loadTileset SE_MAP_LOC, SE_TILESET_LOC
RTS RTS
!macro loadAllTiles { !macro loadAllTiles {
JSR LOAD_ALL_TILES JSR LOAD_ALL_TILES
@ -234,11 +234,11 @@ CROSS
BMI .20 BMI .20
JSR CROSS_SOUTH JSR CROSS_SOUTH
.20 LDA REL_X .20 LDA REL_X
CMP #VIEWPORT_HORZ_PAD-1 CMP #VIEWPORT_HORIZ_PAD-1
BPL .30 BPL .30
JSR CROSS_WEST JSR CROSS_WEST
.30 LDA REL_X .30 LDA REL_X
CMP #VIEWPORT_HORZ_PAD+SECTION_WIDTH CMP #VIEWPORT_HORIZ_PAD+SECTION_WIDTH
BMI .40 BMI .40
JSR CROSS_EAST JSR CROSS_EAST
.40 RTS .40 RTS
@ -431,7 +431,13 @@ DRAW
LDA DRAW_WIDTH LDA DRAW_WIDTH
STA DRAW_X_START STA DRAW_X_START
+drawMapSection SE_MAP_LOC, SE_TILESET_LOC, SECTION_WIDTH, SECTION_HEIGHT +drawMapSection SE_MAP_LOC, SE_TILESET_LOC, SECTION_WIDTH, SECTION_HEIGHT
!if DEBUG { +prStr : !text "Draw complete.",0 } !if DEBUG {
+prStr : !text "Draw complete, REL_X=",0
+prByte REL_X
+prStr : !text "REL_Y=",0
+prByte REL_Y
+crout
}
RTS RTS
MainDraw MainDraw
@ -547,22 +553,24 @@ ROW_OFFSET = 3
; Get tile ; Get tile
TXA TXA
TAY TAY
LDA #0
STA TILE_SOURCE+1
LDA (ROW_LOCATION), Y LDA (ROW_LOCATION), Y
; Calculate location of tile data == tile_base + ((tile & 31) * 16) ; Calculate location of tile data == tile_base + ((tile & 31) * 32)
AND #31 AND #31
ASL ASL
ASL ASL
ASL ASL
ASL ASL
ROL TILE_SOURCE+1
ASL
ROL TILE_SOURCE+1
CLC
ADC TILE_BASE
STA TILE_SOURCE STA TILE_SOURCE
LDA TILE_BASE + 1 LDA TILE_SOURCE+1
ADC #$00 ADC TILE_BASE + 1
STA TILE_SOURCE+1 STA TILE_SOURCE+1
LDA TILE_BASE
ADC TILE_SOURCE
STA TILE_SOURCE
BCC .doneCalculatingTileLocation
INC TILE_SOURCE+1
.doneCalculatingTileLocation .doneCalculatingTileLocation
; Is there a NPC there? ; Is there a NPC there?
; No, use map tile ; No, use map tile
@ -647,7 +655,7 @@ INIT
+ +loadAllTiles + +loadAllTiles
+finishLoad +finishLoad
; set up the X and Y coordinates ; set up the X and Y coordinates
LDX #VIEWPORT_HORIZ_PAD LDX #VIEWPORT_HORIZ_PAD+1
LDY #VIEWPORT_VERT_PAD LDY #VIEWPORT_VERT_PAD
JSR SET_XY JSR SET_XY
RTS RTS