How djh0ffman/knightmareamiga works
Project Type and Purpose
• This is an Amiga port of the classic Konami MSX game “Knightmare.” The project is written largely in assembly language, with a strong emphasis on low-level hardware access (as indicated by the “include/hardware” and “include/exec” directories) and game logic implementation using ASM.
• The codebase is organized around assets (graphics, audio, level data, mods), game engine logic (handling enemy behaviors, boss fights, player input/control, etc.), memory management (chip and fast memory), and utility routines. The port targets Amiga hardware, with a build script for Windows (build.bat) to facilitate compilation.
Analyzing the File Structure
• Top-level directories such as:
• assets – Contains binary data, sprite graphics, palettes, audio, level maps, and mod outputs.
• constants – Holds configuration files and definitions for game values, structures, and variables.
• data – Provides initialization data and animation information, such as enemy parameters, level pointers, and text data.
• – Divided into subdirectories (exec, graphics, hardware) indicating reliance on the Amiga OS libraries and hardware interfaces.
• logic – Contains multiple ASM files organized by game elements (e.g., enemy, boss, player, map, collision, sound), clearly partitioning the game engine’s behavior.
• memory – Deals with memory data and memory management routines (chip and fast RAM).
• utils – Offers helper routines for tasks like binary conversion, data compression/expansion (e.g., shrinkler, unpack), and possibly debugging.
• The build.bat file shows that the project uses a custom/build script to assemble and link under a Windows environment for Amiga port development.
Key Components
a. Assets Module:
• Represented by the entire assets folder (graphics, audio, level data, mods). This module holds all external resources the game engine needs.
b. Game Engine / Logic Module:
• Contains the “logic” folder, subdivided into:
• General game logic (controls, collision, gamestatus, mainmenu).
• Specific subsystems for enemies (sub-folders like enemy, boss) and player interactions.
• Other critical routines (map, palette management, text, score handling).
c. Data and Constants Module:
• Includes the “data” and “constants” folders to feed game initialization values, animation frames, enemy waves, configuration definitions, etc.
d. Memory Management Module:
• The “memory” folder that handles allocation and usage of different memory areas (chip vs. fast memory), vital for Amiga systems.
e. Hardware & OS Interface Module:
• The “include” folder breaks down into low-level Amiga-specific libraries and definitions (exec, graphics, hardware). This module is responsible for interfacing with Amiga OS and hardware registers through system calls, graphics routines, and interrupt handling.
f. Utility & Build Tools Module:
• Contains the “utils” folder (helper routines for tasks such as unpacking and data conversion) plus the build script (build.bat) which ties the assembly source files together and drives the compilation for Amiga targets.
Relationships and Interactions
• Assets are loaded into memory (chip/fast) by routines within the memory management module. They are then rendered via calls in the graphics/hardware interface.
• The game engine (logic) uses data from both the constants and data modules to dictate game behavior, enemy AI, controls, collision detection, and more.
• Hardware/OS interface components (from include/) underlie almost every aspect of the game, providing essential low-level functions (display, interrupts, memory allocation, I/O) that the logic and rendering layers depend on.
• Utility routines assist with data transformation and may also be used during the build process (e.g., shrinking/unpacking assets) to optimize the final binary.
Architectural Patterns and Design Principles
• Separation of Concerns: The project clearly splits asset handling, game logic, data/constants, memory management, and hardware interfacing into distinct modules.
• Layered Architecture: At the bottom, low-level Amiga OS and hardware interaction (include) form the foundation, above which game logic and data processing layers operate, culminating in the final game experience.
• Modularity: Directory segmentation (especially within the “logic” folder, which is further divided for bosses, enemies, etc.) helps in isolating and reusing code, making the integration of different game elements clearer.