xdftools: fixed bitmap dump

This commit is contained in:
Christian Vogelgsang 2023-12-02 14:56:50 +01:00
parent 6c74b0235d
commit 0bd6eb5dba
26 changed files with 83 additions and 36 deletions

View File

@ -32,7 +32,6 @@ class ELFDumper:
print("ELF Sections") print("ELF Sections")
print("id name size rela syms type flags") print("id name size rela syms type flags")
for sect in self.elf.sections: for sect in self.elf.sections:
# determine number of relocations # determine number of relocations
rela = sect.get_rela() rela = sect.get_rela()
num_rela = len(rela) num_rela = len(rela)

View File

@ -315,7 +315,7 @@ class ADFSBitmap:
res = self.blkdev.reserved res = self.blkdev.reserved
for i in range(self.blkdev.num_blocks): for i in range(self.blkdev.num_blocks):
if i >= res and self.get_bit(i): if i >= res and self.get_bit(i):
bm[i] = "F" bm[i] = ord("F")
self.print_draw_bitmap(bm, brief) self.print_draw_bitmap(bm, brief)
def print_used(self, brief=False): def print_used(self, brief=False):
@ -323,39 +323,39 @@ class ADFSBitmap:
res = self.blkdev.reserved res = self.blkdev.reserved
for i in range(self.blkdev.num_blocks): for i in range(self.blkdev.num_blocks):
if i >= res and not self.get_bit(i): if i >= res and not self.get_bit(i):
bm[i] = "#" bm[i] = ord("#")
self.print_draw_bitmap(bm, brief) self.print_draw_bitmap(bm, brief)
def draw_on_bitmap(self, bm): def draw_on_bitmap(self, bm):
# show reserved blocks # show reserved blocks
res = self.blkdev.reserved res = self.blkdev.reserved
bm[0:res] = "x" * res bm[0:res] = b"x" * res
# root block # root block
bm[self.root_blk.blk_num] = "R" bm[self.root_blk.blk_num] = ord("R")
# bitmap blocks # bitmap blocks
for bm_blk in self.bitmap_blks: for bm_blk in self.bitmap_blks:
bm[bm_blk.blk_num] = "b" bm[bm_blk.blk_num] = ord("b")
# bitmap ext blocks # bitmap ext blocks
for ext_blk in self.ext_blks: for ext_blk in self.ext_blks:
bm[ext_blk.blk_num] = "B" bm[ext_blk.blk_num] = ord("B")
def print_draw_bitmap(self, bm, brief=False): def print_draw_bitmap(self, bm, brief=False):
line = "" line = bytearray()
blk = 0 blk = 0
blk_cyl = self.blkdev.sectors * self.blkdev.heads blk_cyl = self.blkdev.sectors * self.blkdev.heads
found = False found = False
for i in range(self.blkdev.num_blocks): for i in range(self.blkdev.num_blocks):
c = bm[i] c = bm[i]
if ord(c) == 0: if c == 0:
c = "." c = ord(".")
else: else:
found = True found = True
line += c line.append(c)
if i % self.blkdev.sectors == self.blkdev.sectors - 1: if i % self.blkdev.sectors == self.blkdev.sectors - 1:
line += " " line.append(ord(" "))
if i % blk_cyl == blk_cyl - 1: if i % blk_cyl == blk_cyl - 1:
if not brief or found: if not brief or found:
print("%8d: %s" % (blk, line)) print("%8d: %s" % (blk, line.decode("utf-8")))
blk += blk_cyl blk += blk_cyl
line = "" line = bytearray()
found = False found = False

View File

@ -374,14 +374,14 @@ class ADFSDir(ADFSNode):
def draw_on_bitmap(self, bm, show_all=False, first=True): def draw_on_bitmap(self, bm, show_all=False, first=True):
blk_num = self.block.blk_num blk_num = self.block.blk_num
bm[blk_num] = "D" bm[blk_num] = ord("D")
if show_all or first: if show_all or first:
self.ensure_entries() self.ensure_entries()
for e in self.entries: for e in self.entries:
e.draw_on_bitmap(bm, show_all, False) e.draw_on_bitmap(bm, show_all, False)
if self.dcache_blks != None: if self.dcache_blks != None:
for dcb in self.dcache_blks: for dcb in self.dcache_blks:
bm[dcb.blk_num] = "C" bm[dcb.blk_num] = ord("C")
def get_block_nums(self): def get_block_nums(self):
self.ensure_entries() self.ensure_entries()

View File

@ -275,11 +275,11 @@ class ADFSFile(ADFSNode):
left -= bs left -= bs
def draw_on_bitmap(self, bm, show_all=False, first=False): def draw_on_bitmap(self, bm, show_all=False, first=False):
bm[self.block.blk_num] = "H" bm[self.block.blk_num] = ord("H")
for b in self.ext_blk_nums: for b in self.ext_blk_nums:
bm[b] = "E" bm[b] = ord("E")
for b in self.data_blk_nums: for b in self.data_blk_nums:
bm[b] = "d" bm[b] = ord("d")
def get_block_nums(self): def get_block_nums(self):
result = [self.block.blk_num] result = [self.block.blk_num]

View File

@ -18,7 +18,7 @@ class ADFSVolDir(ADFSDir):
def draw_on_bitmap(self, bm, show_all=False, first=True): def draw_on_bitmap(self, bm, show_all=False, first=True):
blk_num = self.block.blk_num blk_num = self.block.blk_num
bm[blk_num] = "V" bm[blk_num] = ord("V")
if show_all or first: if show_all or first:
self.ensure_entries() self.ensure_entries()
for e in self.entries: for e in self.entries:

View File

@ -17,7 +17,6 @@ from .MetaInfoFSUAE import MetaInfoFSUAE
class Imager: class Imager:
META_MODE_NONE = 0 META_MODE_NONE = 0
META_MODE_DB = 1 META_MODE_DB = 1
META_MODE_FSUAE = 2 META_MODE_FSUAE = 2

View File

@ -2,7 +2,6 @@ from .BlockDevice import BlockDevice
class ADFBlockDevice(BlockDevice): class ADFBlockDevice(BlockDevice):
# number of total sectors for DD/HD disks # number of total sectors for DD/HD disks
DD_SECS = 80 * 2 * 11 DD_SECS = 80 * 2 * 11
HD_SECS = 80 * 2 * 22 HD_SECS = 80 * 2 * 22

View File

@ -62,6 +62,9 @@ class Block:
def is_comment_block(self): def is_comment_block(self):
return self.type == Block.T_COMMENT return self.type == Block.T_COMMENT
def is_dir_cache_block(self):
return self.type == Block.T_DIR_CACHE
def read(self): def read(self):
if self.data == None: if self.data == None:
self._read_data() self._read_data()

View File

@ -0,0 +1,33 @@
from .Block import Block
from .RootBlock import RootBlock
from .UserDirBlock import UserDirBlock
from .FileHeaderBlock import FileHeaderBlock
from .FileListBlock import FileListBlock
from .FileDataBlock import FileDataBlock
from .CommentBlock import CommentBlock
from .DirCacheBlock import DirCacheBlock
class BlockFactory:
@classmethod
def create_block(cls, blkdev, blk_num, type, sub_type):
if type == Block.T_SHORT:
if sub_type == Block.ST_ROOT:
return RootBlock(blkdev, blk_num)
elif sub_type == Block.ST_USERDIR:
return UserDirBlock(blkdev, blk_num)
elif sub_type == Block.ST_FILE:
return FileHeaderBlock(blkdev, blk_num)
elif type == Block.T_LIST:
if sub_type == Block.ST_FILE:
return FileListBlock(blkdev, blk_num)
elif type == Block.T_DATA:
return FileDataBlock(blkdev, blk_num)
elif type == Block.T_COMMENT:
return CommentBlock(blkdev, blk_num)
elif type == Block.T_DIR_CACHE:
return DirCacheBlock(blkdev, blk_num)
@classmethod
def create_specific_block(cls, block):
return cls.create_block(block.blkdev, block.blk_num, block.type, block.sub_type)

View File

@ -6,7 +6,7 @@ from ..FSString import FSString
class UserDirBlock(EntryBlock): class UserDirBlock(EntryBlock):
def __init__(self, blkdev, blk_num, is_longname): def __init__(self, blkdev, blk_num, is_longname=False):
EntryBlock.__init__( EntryBlock.__init__(
self, self,
blkdev, blkdev,

View File

@ -137,7 +137,6 @@ class BootConRomPatch(RomPatch):
class RomPatcher: class RomPatcher:
# list of all available patch classes # list of all available patch classes
patches = [OneMegRomPatch(), FourMegRomPatch(), BootConRomPatch()] patches = [OneMegRomPatch(), FourMegRomPatch(), BootConRomPatch()]

View File

@ -24,6 +24,7 @@ import amitools.util.KeyValue as KeyValue
import amitools.util.ByteSize as ByteSize import amitools.util.ByteSize as ByteSize
import amitools.util.VerTag as VerTag import amitools.util.VerTag as VerTag
# ----- commands ----- # ----- commands -----
class Command: class Command:
def __init__(self, args, opts, edit=False): def __init__(self, args, opts, edit=False):

View File

@ -14,6 +14,8 @@ from amitools.fs.Imager import Imager
from amitools.fs.Repacker import Repacker from amitools.fs.Repacker import Repacker
from amitools.fs.block.BootBlock import BootBlock from amitools.fs.block.BootBlock import BootBlock
from amitools.fs.block.RootBlock import RootBlock from amitools.fs.block.RootBlock import RootBlock
from amitools.fs.block.Block import Block
from amitools.fs.block.BlockFactory import BlockFactory
from amitools.util.CommandQueue import CommandQueue from amitools.util.CommandQueue import CommandQueue
from amitools.util.HexDump import * from amitools.util.HexDump import *
import amitools.util.KeyValue as KeyValue import amitools.util.KeyValue as KeyValue
@ -567,7 +569,7 @@ class BlockCmd(Command):
n = len(self.opts) n = len(self.opts)
if n == 0: if n == 0:
print( print(
"Usage: block ( boot | root | node <ami_file> [data] | dump <block_no> )" "Usage: block ( boot | root | node <ami_file> [data] | dump <block_no> | decode <block_no> )"
) )
return 1 return 1
cmd = self.opts[0] cmd = self.opts[0]
@ -600,6 +602,24 @@ class BlockCmd(Command):
block_no = int(self.opts[1]) block_no = int(self.opts[1])
data = vol.blkdev.read_block(block_no) data = vol.blkdev.read_block(block_no)
print_hex(data) print_hex(data)
elif cmd == "decode":
if n == 1:
print("No block number given!")
return 1
else:
block_no = int(self.opts[1])
# read block
blk = Block(vol.blkdev, block_no)
blk.read()
if blk.valid:
dec_blk = BlockFactory.create_specific_block(blk)
if dec_blk:
dec_blk.read()
dec_blk.dump()
else:
blk.dump("Unknown")
else:
print("Error reading block!")
# ----- Bitmap Tools ----- # ----- Bitmap Tools -----

View File

@ -3,7 +3,6 @@ from .pointer import BCPLPointerType
class AccessStruct(object): class AccessStruct(object):
_size_to_width = [None, 0, 1, None, 2] _size_to_width = [None, 0, 1, None, 2]
def __init__(self, mem, struct_def, struct_addr): def __init__(self, mem, struct_def, struct_addr):

View File

@ -46,7 +46,6 @@ FieldDefBase = collections.namedtuple(
class FieldDef(FieldDefBase): class FieldDef(FieldDefBase):
_base_offset = 0 _base_offset = 0
_parent_def = None _parent_def = None
@ -322,7 +321,6 @@ class AmigaStructFields:
class AmigaStruct(TypeBase): class AmigaStruct(TypeBase):
# overwrite in derived class! # overwrite in derived class!
_format = None _format = None
# top-level alias names for subfields # top-level alias names for subfields

View File

@ -39,7 +39,6 @@ class AmigaStructDecorator(object):
# run through fields # run through fields
for field_type, field_name in format: for field_type, field_name in format:
# replace self pointers # replace self pointers
if field_type is APTR_SELF: if field_type is APTR_SELF:
field_type = APTR(cls) field_type = APTR(cls)

View File

@ -10,7 +10,6 @@ from .Error import *
class MatchFirstNext: class MatchFirstNext:
DODIR = 4 DODIR = 4
DIDDIR = 8 DIDDIR = 8

View File

@ -4,7 +4,6 @@ from amitools.vamos.error import *
class SemaphoreManager: class SemaphoreManager:
NT_SIGNALSEM = 15 NT_SIGNALSEM = 15
def __init__(self, alloc, mem): def __init__(self, alloc, mem):

View File

@ -241,7 +241,6 @@ class LibProfileData(object):
class LibProfiler(Profiler): class LibProfiler(Profiler):
name = "libs" name = "libs"
def __init__(self, names=None, add_calls=False, add_all=False): def __init__(self, names=None, add_calls=False, add_all=False):

View File

@ -82,7 +82,6 @@ class InitStruct(object):
class InitStructBuilder(object): class InitStructBuilder(object):
SIZE_LONG = 0 SIZE_LONG = 0
SIZE_WORD = 1 SIZE_WORD = 1
SIZE_BYTE = 2 SIZE_BYTE = 2

View File

@ -6,7 +6,6 @@ from amitools.vamos.machine.opcodes import op_jmp
class LibFuncs(object): class LibFuncs(object):
LVO_Open = 1 LVO_Open = 1
LVO_Close = 2 LVO_Close = 2
LVO_Expunge = 3 LVO_Expunge = 3

View File

@ -5,6 +5,7 @@ from amitools.vamos.astructs import (
ULONG, ULONG,
) )
# TagItem # TagItem
@AmigaStructDef @AmigaStructDef
class TagItemStruct(AmigaStruct): class TagItemStruct(AmigaStruct):

View File

@ -40,7 +40,7 @@ class LibBase:
tag=tag, tag=tag,
pos_size=pos_size, pos_size=pos_size,
neg_size=neg_size, neg_size=neg_size,
**kwargs **kwargs,
) )

View File

@ -10,7 +10,6 @@ from amitools.vamos.astructs import AmigaClassDef
@AmigaClassDef @AmigaClassDef
class Resident(ResidentStruct): class Resident(ResidentStruct):
RTC_MATCHWORD = 0x4AFC RTC_MATCHWORD = 0x4AFC
@classmethod @classmethod

View File

@ -1,5 +1,6 @@
import pytest import pytest
# tag a parameter for full testing # tag a parameter for full testing
def tag_full(value): def tag_full(value):
return pytest.param(value, marks=pytest.mark.full) return pytest.param(value, marks=pytest.mark.full)

View File

@ -29,6 +29,7 @@ def libnative_initres_init_test(buildlibnix):
sp = init_addr - 4 sp = init_addr - 4
# load lib # load lib
seglist, addr, size, end = load_lib(alloc, buildlibnix) seglist, addr, size, end = load_lib(alloc, buildlibnix)
# setup init func # setup init func
def init_func(op, pc): def init_func(op, pc):
assert cpu.r_reg(REG_A0) == seglist.get_baddr() assert cpu.r_reg(REG_A0) == seglist.get_baddr()
@ -63,6 +64,7 @@ def libnative_initres_autoinit_test(buildlibnix):
sp = init_addr - 4 sp = init_addr - 4
# load lib # load lib
seglist, addr, size, end = load_lib(alloc, buildlibnix) seglist, addr, size, end = load_lib(alloc, buildlibnix)
# setup init func # setup init func
def init_func(op, pc): def init_func(op, pc):
assert cpu.r_reg(REG_A0) == seglist.get_baddr() assert cpu.r_reg(REG_A0) == seglist.get_baddr()