Skip to content

Commit

Permalink
xdftools: fixed bitmap dump
Browse files Browse the repository at this point in the history
  • Loading branch information
cnvogelg committed Dec 2, 2023
1 parent 6c74b02 commit 0bd6eb5
Show file tree
Hide file tree
Showing 26 changed files with 83 additions and 36 deletions.
1 change: 0 additions & 1 deletion amitools/binfmt/elf/ELFDumper.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ def dump_sections(self, show_relocs=False, show_debug=False):
print("ELF Sections")
print("id name size rela syms type flags")
for sect in self.elf.sections:

# determine number of relocations
rela = sect.get_rela()
num_rela = len(rela)
Expand Down
26 changes: 13 additions & 13 deletions amitools/fs/ADFSBitmap.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,47 +315,47 @@ def print_free(self, brief=False):
res = self.blkdev.reserved
for i in range(self.blkdev.num_blocks):
if i >= res and self.get_bit(i):
bm[i] = "F"
bm[i] = ord("F")
self.print_draw_bitmap(bm, brief)

def print_used(self, brief=False):
bm = self.create_draw_bitmap()
res = self.blkdev.reserved
for i in range(self.blkdev.num_blocks):
if i >= res and not self.get_bit(i):
bm[i] = "#"
bm[i] = ord("#")
self.print_draw_bitmap(bm, brief)

def draw_on_bitmap(self, bm):
# show reserved blocks
res = self.blkdev.reserved
bm[0:res] = "x" * res
bm[0:res] = b"x" * res
# root block
bm[self.root_blk.blk_num] = "R"
bm[self.root_blk.blk_num] = ord("R")
# bitmap blocks
for bm_blk in self.bitmap_blks:
bm[bm_blk.blk_num] = "b"
bm[bm_blk.blk_num] = ord("b")
# bitmap ext blocks
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):
line = ""
line = bytearray()
blk = 0
blk_cyl = self.blkdev.sectors * self.blkdev.heads
found = False
for i in range(self.blkdev.num_blocks):
c = bm[i]
if ord(c) == 0:
c = "."
if c == 0:
c = ord(".")
else:
found = True
line += c
line.append(c)
if i % self.blkdev.sectors == self.blkdev.sectors - 1:
line += " "
line.append(ord(" "))
if i % blk_cyl == blk_cyl - 1:
if not brief or found:
print("%8d: %s" % (blk, line))
print("%8d: %s" % (blk, line.decode("utf-8")))
blk += blk_cyl
line = ""
line = bytearray()
found = False
4 changes: 2 additions & 2 deletions amitools/fs/ADFSDir.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@ def get_path(self, pc, allow_file=True, allow_dir=True):

def draw_on_bitmap(self, bm, show_all=False, first=True):
blk_num = self.block.blk_num
bm[blk_num] = "D"
bm[blk_num] = ord("D")
if show_all or first:
self.ensure_entries()
for e in self.entries:
e.draw_on_bitmap(bm, show_all, False)
if self.dcache_blks != None:
for dcb in self.dcache_blks:
bm[dcb.blk_num] = "C"
bm[dcb.blk_num] = ord("C")

def get_block_nums(self):
self.ensure_entries()
Expand Down
6 changes: 3 additions & 3 deletions amitools/fs/ADFSFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -275,11 +275,11 @@ def write(self):
left -= bs

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:
bm[b] = "E"
bm[b] = ord("E")
for b in self.data_blk_nums:
bm[b] = "d"
bm[b] = ord("d")

def get_block_nums(self):
result = [self.block.blk_num]
Expand Down
2 changes: 1 addition & 1 deletion amitools/fs/ADFSVolDir.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def __repr__(self):

def draw_on_bitmap(self, bm, show_all=False, first=True):
blk_num = self.block.blk_num
bm[blk_num] = "V"
bm[blk_num] = ord("V")
if show_all or first:
self.ensure_entries()
for e in self.entries:
Expand Down
1 change: 0 additions & 1 deletion amitools/fs/Imager.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@


class Imager:

META_MODE_NONE = 0
META_MODE_DB = 1
META_MODE_FSUAE = 2
Expand Down
1 change: 0 additions & 1 deletion amitools/fs/blkdev/ADFBlockDevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@


class ADFBlockDevice(BlockDevice):

# number of total sectors for DD/HD disks
DD_SECS = 80 * 2 * 11
HD_SECS = 80 * 2 * 22
Expand Down
3 changes: 3 additions & 0 deletions amitools/fs/block/Block.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ def is_file_data_block(self):
def is_comment_block(self):
return self.type == Block.T_COMMENT

def is_dir_cache_block(self):
return self.type == Block.T_DIR_CACHE

def read(self):
if self.data == None:
self._read_data()
Expand Down
33 changes: 33 additions & 0 deletions amitools/fs/block/BlockFactory.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 1 addition & 1 deletion amitools/fs/block/UserDirBlock.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class UserDirBlock(EntryBlock):
def __init__(self, blkdev, blk_num, is_longname):
def __init__(self, blkdev, blk_num, is_longname=False):
EntryBlock.__init__(
self,
blkdev,
Expand Down
1 change: 0 additions & 1 deletion amitools/rom/rompatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ def apply_patch(self, access, args):


class RomPatcher:

# list of all available patch classes
patches = [OneMegRomPatch(), FourMegRomPatch(), BootConRomPatch()]

Expand Down
1 change: 1 addition & 0 deletions amitools/tools/rdbtool.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import amitools.util.ByteSize as ByteSize
import amitools.util.VerTag as VerTag


# ----- commands -----
class Command:
def __init__(self, args, opts, edit=False):
Expand Down
22 changes: 21 additions & 1 deletion amitools/tools/xdftool.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from amitools.fs.Repacker import Repacker
from amitools.fs.block.BootBlock import BootBlock
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.HexDump import *
import amitools.util.KeyValue as KeyValue
Expand Down Expand Up @@ -567,7 +569,7 @@ def handle_vol(self, vol):
n = len(self.opts)
if n == 0:
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
cmd = self.opts[0]
Expand Down Expand Up @@ -600,6 +602,24 @@ def handle_vol(self, vol):
block_no = int(self.opts[1])
data = vol.blkdev.read_block(block_no)
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 -----
Expand Down
1 change: 0 additions & 1 deletion amitools/vamos/astructs/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@


class AccessStruct(object):

_size_to_width = [None, 0, 1, None, 2]

def __init__(self, mem, struct_def, struct_addr):
Expand Down
2 changes: 0 additions & 2 deletions amitools/vamos/astructs/astruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ def get_all_struct_names(self):


class FieldDef(FieldDefBase):

_base_offset = 0
_parent_def = None

Expand Down Expand Up @@ -322,7 +321,6 @@ def _create_field_type(self, field_def):


class AmigaStruct(TypeBase):

# overwrite in derived class!
_format = None
# top-level alias names for subfields
Expand Down
1 change: 0 additions & 1 deletion amitools/vamos/astructs/astructdef.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ def _setup_fields(self, cls, format, type_name):

# run through fields
for field_type, field_name in format:

# replace self pointers
if field_type is APTR_SELF:
field_type = APTR(cls)
Expand Down
1 change: 0 additions & 1 deletion amitools/vamos/lib/dos/MatchFirstNext.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@


class MatchFirstNext:

DODIR = 4
DIDDIR = 8

Expand Down
1 change: 0 additions & 1 deletion amitools/vamos/lib/lexec/SemaphoreManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@


class SemaphoreManager:

NT_SIGNALSEM = 15

def __init__(self, alloc, mem):
Expand Down
1 change: 0 additions & 1 deletion amitools/vamos/libcore/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ def dump(self, name, write=print):


class LibProfiler(Profiler):

name = "libs"

def __init__(self, names=None, add_calls=False, add_all=False):
Expand Down
1 change: 0 additions & 1 deletion amitools/vamos/libnative/initstruct.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@ def init_struct(self, init_table_ptr, memory_ptr, size):


class InitStructBuilder(object):

SIZE_LONG = 0
SIZE_WORD = 1
SIZE_BYTE = 2
Expand Down
1 change: 0 additions & 1 deletion amitools/vamos/libnative/libfuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@


class LibFuncs(object):

LVO_Open = 1
LVO_Close = 2
LVO_Expunge = 3
Expand Down
1 change: 1 addition & 0 deletions amitools/vamos/libstructs/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
ULONG,
)


# TagItem
@AmigaStructDef
class TagItemStruct(AmigaStruct):
Expand Down
2 changes: 1 addition & 1 deletion amitools/vamos/libtypes/library.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def alloc(cls, alloc, tag=None, pos_size=0, neg_size=0, fd=None, **kwargs):
tag=tag,
pos_size=pos_size,
neg_size=neg_size,
**kwargs
**kwargs,
)


Expand Down
1 change: 0 additions & 1 deletion amitools/vamos/libtypes/resident.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

@AmigaClassDef
class Resident(ResidentStruct):

RTC_MATCHWORD = 0x4AFC

@classmethod
Expand Down
1 change: 1 addition & 0 deletions test/tools/romtool.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import pytest


# tag a parameter for full testing
def tag_full(value):
return pytest.param(value, marks=pytest.mark.full)
Expand Down
2 changes: 2 additions & 0 deletions test/unit/libnative_initres.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def libnative_initres_init_test(buildlibnix):
sp = init_addr - 4
# load lib
seglist, addr, size, end = load_lib(alloc, buildlibnix)

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

# setup init func
def init_func(op, pc):
assert cpu.r_reg(REG_A0) == seglist.get_baddr()
Expand Down

0 comments on commit 0bd6eb5

Please sign in to comment.