Skip to content

Commit

Permalink
fixed pink tiles issue
Browse files Browse the repository at this point in the history
  • Loading branch information
nstbayless committed May 16, 2023
1 parent 68b21df commit e96d921
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,7 @@ Supported roms: us/eu, jp, kgb4ceu
python3.8 is requied to run the script.

(Optional): z80-asm is required to assemble the resulting data.

## License

cc-by-nc-sa v3.0
16 changes: 10 additions & 6 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,8 @@ def __init__(self, j, nes):
self.cached_vram_descriptor = None

def getVramBGTile(self, tileidx):
if tileidx > 0x80:
return self.tileset[tileidx]
return self.tileset[0x100 + tileidx]

def loadVramTile(self, destaddr, srcaddr, srcbank):
Expand Down Expand Up @@ -558,23 +560,25 @@ def paintEvent(self, event):
painter.setCompositionMode(QPainter.CompositionMode_SourceOver)

class SelectorPanel(QScrollArea):
def __init__(self, parent, type=ChunkSelectorWidget, scale=2, w=4, h=0x40):
def __init__(self, parent, type=ChunkSelectorWidget, scale=2, w=4, h=0x40, **kwargs):
super().__init__()
self.idxremap = kwargs.get("idxremap", lambda x: x)
self.app = parent
self.scale = scale
self.w = w
self.h = h
self.type = type
self.margin = 4
self.spacing = 3
self.widgets = []
self.widgets = dict()
grid_layout = QGridLayout()
grid_layout.setSpacing(self.spacing)
grid_layout.setContentsMargins(self.margin, self.margin, self.margin, self.margin)
for j in range(self.h):
for i in range(self.w):
self.widgets.append(type(i + j * self.w, self.app, self.scale))
grid_layout.addWidget(self.widgets[-1], j, i)
id = self.idxremap(i + j * self.w)
self.widgets[id] = type(id, self.app, self.scale)
grid_layout.addWidget(self.widgets[id], j, i)

scroll_area_widget = QWidget()
scroll_area_widget.setLayout(grid_layout)
Expand Down Expand Up @@ -1277,7 +1281,7 @@ def defineChunksTab(self, tab):
hlay.addWidget(QWidget())

# tile selector
self.tileSelectors.append(SelectorPanel(self, TileSelectorWidget, 4, 0x4, 0x20))
self.tileSelectors.append(SelectorPanel(self, TileSelectorWidget, 4, 0x4, 0x24, idxremap=lambda x: x if x < 0x80 else x+0x70))
hlay.addWidget(self.tileSelectors[-1])

# depth=0: level only
Expand Down Expand Up @@ -1679,7 +1683,7 @@ def setLevel(self, level):
qcb.blockSignals(False)

for selector in self.chunkSelectors + self.tileSelectors:
for widget in selector.widgets:
for id, widget in selector.widgets.items():
widget.update()

self.chunkEdit.update()
Expand Down
8 changes: 8 additions & 0 deletions model.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ def loadRom(path):
jsl = JSONDict()
jl.sublevels.append(jsl)
loadSublevelScreens(j, i, sublevel)
loadSublevelTimer(j, i, sublevel);
loadSublevelScreenTable(j, i, sublevel)
loadSublevelScreenEntities(j, i, sublevel)
loadSublevelInitRoutine(j, i, sublevel)
Expand Down Expand Up @@ -582,6 +583,13 @@ def getScreenEnterable(j, level, sublevel, x, y):
def getEnterabilityLayout(j, level, sublevel):
return [[getScreenEnterable(j, level, sublevel, x, y) for y in range(16)] for x in range(16)]

def loadSublevelTimer(j, level, sublevel):
jl = j.levels[level]
jsl = jl.sublevels[sublevel]
levelTimerPointer = rom.readword(rom.BANK3, rom.LEVEL_TIMER_TABLE + level*2) # fetch timer table of the level
levelTimerPointerData = rom.readbyte(rom.BANK3, levelTimerPointer + sublevel) # fetch sublevel timer value
jsl.timer = levelTimerPointerData

# ------------------------------------------------------

class SaveContext:
Expand Down
4 changes: 4 additions & 0 deletions rom.py
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,8 @@ def readrom(_data):
global ENTGFXLOAD_BANK
ENTGFXLOAD_BANK = 0
ENTGFXLOAD = 0x0e4c
global SUB0_TILE_PATCH
SUB0_TILE_PATCH = 0x2b28

global LEVEL_START_2855
global LEVEL_START_28DB
Expand Down Expand Up @@ -440,6 +442,8 @@ def readrom(_data):
global LOAD_SPRITES_ROUTINES
SPRITE_PATCH_TABLE = 0x7059 # TODO: localized
LOAD_SPRITES_ROUTINES = 0x6fef # TODO: localized
global LEVEL_TIMER_TABLE
LEVEL_TIMER_TABLE = 0x77f0 # TODO: localized

# bank6
global BANK6
Expand Down

0 comments on commit e96d921

Please sign in to comment.