### Install Test Dependencies and Run Tests Source: https://context7.com/fubukimaru/asmsx/llms.txt Install Behave BDD framework and dos2unix for testing. Use 'make test' to build and run all passing tests, or 'behave test' for manual execution. ```shell # Install test dependencies pip install behave sudo apt install dos2unix # Build and run all passing tests make test # Run tests manually (skip WIP) behave test --tags=-wip # Run every test including WIP behave test ``` -------------------------------- ### Set Prompt Message Example Source: https://github.com/fubukimaru/asmsx/blob/master/ref/RedBook-Konamiman.txt An example demonstrating how to set a prompt message for BASIC using WRTCLK and REDCLK via an interslot call. It writes string data to back-up RAM. ```assembly ;************************************************ ; ; List 5.10 set prompt message ; ;************************************************ ; WRTCLK: EQU 01F9H EXTROM: EQU 015FH ORG 0B000H ;----- program start ----- ;Note: Set prompt message for BASIC. START: LD C,00110000B ;address data LD A,2 ;ID := prompt mode CALL WRTRAM ;write to back-up RAM LD B,6 ;loop counter LD HL,STRING ;prompt data L01: LD A,(HL) ;read string data AND 0FH ;A := hi 4 bit INC C ;increment address CALL WRTRAM ;write data to back-up RAM LD A,(HL) RRCA RRCA RRCA RRCA AND 0FH INC C ;increment address CALL WRTRAM ;write low 4 bits INC HL DJNZ L01 RET ;----- write data to back-up RAM ----- WRTRAM: PUSH HL PUSH BC LD IX,WRTCLK CALL EXTROM ;use interslot call POP BC POP HL RET ;----- string data ----- STRING: DB 'Ready?' END ``` -------------------------------- ### Install Testing Dependencies Source: https://github.com/fubukimaru/asmsx/blob/master/doc/testing.md Installs the behave testing framework and dos2unix utility. It's recommended to use a virtual environment. ```sh pip install behave sudo apt install dos2unix ``` -------------------------------- ### Start Music Playback (Assembly) Source: https://github.com/fubukimaru/asmsx/blob/master/ref/RedBook-Konamiman.txt Initiates music playback from a queue of MML data. Checks if music is already playing before starting. ```assembly STRTMS EQU 0099H ``` -------------------------------- ### Program Line Structure Example Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt Illustrates the structure of a typical program line in ROM BASIC, including the link, line number, and statement tokens. The link stores the starting address of the next line. ```Assembly +-------------------------------------------+ | 09H 80H | 0AH 00H | 91H | 20H | 1AH | 00H | +-------------------------------------------+ ``` -------------------------------- ### Joystick and Trigger Access Example (Assembly) Source: https://github.com/fubukimaru/asmsx/blob/master/ref/RedBook-Konamiman.txt Example assembly code demonstrating how to read joystick and trigger status and display it on the screen. ```APIDOC ================================================================= List 5.7 Joystick and trigger access ================================================================= ;************************************************ ; ; List 5.7 Joystick and trigger access ; ;************************************************ ; CHPUT EQU 00A2H BREAKX EQU 00B7H GTSTCK EQU 00D5H GTTRIG EQU 00D8H ORG 0D00H ;----- program start ----- Note: display joystick status STICK: LD A,1 ;choose joystick 1 CALL GTSTCK ;read joystick status LD (WK1),A LD A,1 ;choose joystick 1 CALL GTTRIG ;read trigger status OR A JR Z,STCK1 LD HL,WDON ;trigger ON JR STCK2 STCK1: LD HL,WDOFF ;trigger OFF STCK2: CALL PUTSTR LD A,(WK1) OR A JR Z,BRKCH0 ;do not use joystick LD C,0 STCK3: DEC A JR NZ,STCK4 INC C JR STCK3 STCK4: SLA C ;C := C*16 SLA C SLA C SLA C LD B,0 ;Accounting Strings data address LD HL,WDSTK ADD HL,BC CALL PUTSTR BRKCH0: LD A,0DH ;put carriage return CALL CHPUT ;code := 0DH BRKCHK: CALL BREAKX ;break check RET C JR STICK ;----- put strings to screen ----- PUTSTR: LD A,(HL) CP '$' RET Z INC HL CALL CHPUT JR PUTSTR ;----- string area ----- WDON: DB 'Trigger ON: $' WDOFF: DB 'Trigger OFF: $' WDSTK: DB 'UP only ',0DH,0AH,'$' DB 'Up and Right ',0DH,0AH,'$' DB 'Right only ',0DH,0AH,'$' DB 'Right & Down ',0DH,0AH,'$' DB 'Down only ',0DH,0AH,'$' DB 'Down and Left',0DH,0AH,'$' DB 'Left only ',0DH,0AH,'$' DB 'Left and Up ',0DH,0AH,'$' WK1: DW 0 END ``` -------------------------------- ### MSX-DOS INLIN and PINLIN Example Source: https://github.com/fubukimaru/asmsx/blob/master/ref/RedBook-Konamiman.txt Demonstrates the usage of INLIN and PINLIN routines for string input, displaying prompts and the entered strings. ```Assembly ;************************************************ ; ; List 5.6 INLIN and PINLIN ; ;************************************************ CHPUT EQU 00A2H INLIN EQU 00B1H PINLIN EQU 00AEH KILBUF EQU 0156H BUF EQU F55EH ORG 0B000H ; ----- program start ----- LD HL,PRMPT1 CALL PUTMSG ;put prompt message CALL INLIN ;use INLIN routine LD HL,BUF CALL PUTMSG LD HL,PRMPT2 CALL PUTMSG ;put prompt message CALL PINLIN ;use PINLIN routine LD HL,BUF CALL PUTMSG RET ; ----- put a string ----- PUTMSG: LD A,(HL) CP '$' RET Z CALL CHPUT INC HL JR PUTMSG ; ----- string data ----- PRMPT1: DB 0DH,0AH,'INLIN:$' PRMPT2: DB 0DH,0AH,'PINLIN:$' END ``` -------------------------------- ### Basic Assembly Syntax Example Source: https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md Demonstrates the fundamental line format for asMSX assembly code, including optional labels, directives or opcodes, and comments. ```assembly loop: ld a,[0ffffh] ; reads the master record points: db 20,30,40,50 ; points table org 08000h ; code offset on page 2 nop ``` -------------------------------- ### Minimal ROM Example Source: https://context7.com/fubukimaru/asmsx/llms.txt A self-contained 8 KB ROM that prints 'HELLO, MSX!' to the screen. Demonstrates .bios, .page, .start, .rom directives, BIOS calls, and page 3 variables. ```assembly ; hello.asm — minimal MSX ROM ; Assemble: asmsx hello.asm → hello.rom ; Load in emulator as a standard 8 KB ROM cartridge .bios ; enable BIOS label set .page 2 ; ROM lives at $8000 .start MAIN ; execution entry point .rom ; emit 16-byte ROM header ; ------------------------------------------------------- MAIN: ; One-time initialisation xor a ld [CLIKSW], a ; silence keyboard click (BIOSVARS) call ERAFNK ; hide function-key display ; Set up Screen 1 (32-column text mode) call INIT32 ; Print "HELLO, MSX!" at top-left ld hl, MSG @@LOOP: ld a, [hl] or a ret z ; stop at null terminator call CHPUT ; BIOS: output character inc hl jr @@LOOP ; ------------------------------------------------------- MSG: db "HELLO, MSX!", 0 ; ------------------------------------------------------- ; Variables in page 3 (RAM area $C000–$FFFF) .page 3 CLIKSW .equ $F3DB ; or use .biosvars for all system vars ; .printtext output → hello.txt: .printtext "hello.asm assembled OK" .print (MSG - $8000 + 16) ; code size in bytes (after 16-byte header) .printtext "bytes" ``` -------------------------------- ### Trigonometric Function Example Source: https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md Shows how to use the SIN function with PI for converting degrees to radians. ```python sin(pi*45.0/180.0) ``` -------------------------------- ### MSX BIOS Routine Calls Example Source: https://context7.com/fubukimaru/asmsx/llms.txt Demonstrates calling various MSX BIOS routines for sound initialization, character output, joystick input, VDP register writing, VRAM filling, and reading system variables. ```assembly .page 2 .rom .start MAIN MAIN: ; Initialise PSG sound chip call GICINI ; BIOS: init PSG ; Print a character ld a, 'H' call CHPUT ; BIOS: output char to screen ; Read joystick port 1 (returns direction 0-8) ld a, 1 call GTSTCK ; BIOS: get stick direction → A ; Read button state ld a, 1 call GTTRIG ; BIOS: get trigger state → A (0=released) ; Write to VDP register 1 ld bc, $E201 ; B=value, C=register call WRTVDP ; Fill VRAM region with a value ld hl, $1800 ; VRAM destination address ld bc, 768 ; byte count xor a ; fill value = 0 call FILVRM ; Read system variable JIFFY (frame counter) ld hl, JIFFY ld a, [hl] ; Change foreground colour ld hl, FORCLR ld [hl], 15 ; white ret ``` -------------------------------- ### Set Execution Entry Point Source: https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md Indicates the starting execution address for ROM, MegaROM, and BIN files if it's not at the beginning. Use before any .ROM-like directive. ```assembly .START X ``` -------------------------------- ### BASIC USR Function Example with String Corruption Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt This example demonstrates a common pitfall when returning strings from USR functions. It shows how temporary string storage can be corrupted if not handled carefully, leading to unexpected results. ```basic 10 POKE &H9000,&HC9 20 DEFUSR=&H9000 30 A$=STRING$(12,"!") 40 PRINT A$ 50 B$=STRING$(9,"X") 60 PRINT A$ ``` -------------------------------- ### STRTMS (Start Music) Source: https://github.com/fubukimaru/asmsx/blob/master/ref/RedBook-Konamiman.txt Initiates music playback. It checks if music is already playing as a background task and starts playing the music from the queue if it's not already active. ```APIDOC ## STRTMS (0099H/MAIN) ### Description Examines whether the music is played as the background task, and plays the music which is set in the queue, if the music has not yet been played. ### Method CALL ### Parameters #### Input - **(QUEUE)** - MML which is translated into the intermediate language ### Function Starts music playback if not already running. ``` -------------------------------- ### Local Label Definition Example Source: https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md Shows how to define and use local labels (prefixed with '@@' or '.') within different functions for improved code readability and reusability. ```assembly Function1: ... @@loop: ... Function2: ... @@loop: ... ``` ```assembly Function1: ... .loop: ... Function2: ... .loop: ... ``` -------------------------------- ### Build asMSX on GNU/Linux Source: https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md Installs necessary dependencies and builds asMSX from source on Ubuntu-based systems using make. ```bash sudo apt install -y make gcc flex bison git build-essential \ libbison-dev libfl-dev libpthread-stubs0-dev ``` -------------------------------- ### Arithmetic Expression Example Source: https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md Demonstrates a complex arithmetic expression using standard operators and parentheses for precedence. ```python ((2*8)/(1+3))<<2 ``` -------------------------------- ### Generate MSX-BASIC Header Source: https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md Generates a header for a loadable binary MSX-BASIC file. Use .ORG to specify the start address and .START for the execution entry point if different. ```assembly .BASIC ``` -------------------------------- ### Conditional Assembly Example Source: https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md Demonstrates nested IF-ELSE-ENDIF blocks for platform-specific code assembly. Conditions are evaluated based on C/C++ rules; non-zero is true. ```assembly IF (computer==MSX) call MSX1_Init ELSE IF (computer==MSX2) call MSX2_Init ELSE IF (computer==MSX2plus) call MSX2plus_Init ELSE call TurboR_Init ENDIF ENDIF ENDIF ``` -------------------------------- ### Multicolour Mode Coordinate to Address Conversion (BASIC) Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt Example BASIC code demonstrating the conversion of X,Y coordinates to a screen address in Multicolour Mode. It adjusts the coordinates by dividing by four, then calculates the address and bit mask. ```basic 10 INPUT"X,Y Coordinates";X,Y 20 X=X\4:Y-Y\4 30 A=(Y\8)*256+(Y AND 7)+(X*4 AND &HF8) 40 PRINT"ADDR=";HEX$(BASE(17)+A);"H "; ``` -------------------------------- ### BASIC USR Function String Handling with Variable Assignment Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt This example illustrates the correct method for handling string returns from USR functions by pre-allocating string space and assigning the parameter to a variable beforehand. This prevents temporary storage corruption. ```basic 10 A$=STRING$(12,"!") 20 A$=USR(A$) ``` -------------------------------- ### Assembly Instruction with Multiple Entry Points Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt Demonstrates a common trick in the interpreter where an instruction can be entered at different points to achieve different functionalities. This specific example shows 'LD A,0D1H' acting as 'POP DE' when entered at the 'Normal' label. ```assembly 3E D1 Normal: LD A,0D1H ``` -------------------------------- ### Pull Docker Image for asMSX Source: https://github.com/fubukimaru/asmsx/blob/master/README.md Use this command to pull the latest Docker image for asMSX from GitHub Packages. This is a convenient way to get started without local compilation. ```sh docker pull ghcr.io/fubukimaru/asmsx ``` -------------------------------- ### Gherkin Test Structure Example Source: https://github.com/fubukimaru/asmsx/blob/master/doc/testing.md An example of the basic Gherkin syntax used to define test scenarios in the behave framework. ```gherkin Given we have this status When we do this Then we should have this ``` -------------------------------- ### Assemble ROM Image (8 KB) Source: https://context7.com/fubukimaru/asmsx/llms.txt Assembles code at $8000, sets execution entry point, and writes a ROM header. Output file is game.rom. ```assembly ; ============================================================ ; 1. ROM image (8 KB, page 2) ; ============================================================ .page 2 ; assemble at $8000 .start INIT ; execution entry (must come BEFORE .ROM) .rom ; write ROM header; output: game.rom ``` -------------------------------- ### INIFNK - Initialize Function Key Strings Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt Initializes the ten function key strings to their default power-up values by copying data from ROM to the Workspace Area. ```APIDOC ## INIFNK ### Description Standard routine to initialize the ten function key strings to their power-up values. The data is copied from ROM to the FNKSTR buffer in the Workspace Area. ### Entry None ### Exit None ### Modifies BC, DE, HL ### Data Location Power-up strings are located starting at address 13A9H in ROM. ``` -------------------------------- ### Demonstrate Garbage Collection in BASIC Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt This program demonstrates garbage collection by repeatedly assigning strings to an array. Observe the program's speed decrease as it pauses to eliminate dead strings. ```BASIC 10 CLEAR 1000 20 DIM A$(200) 30 FOR N=0 TO 200 40 A$(N)=STRING$(4,"A") 50 PRINT"."; 60 NEXT N 70 GOTO 30 ``` -------------------------------- ### Interpreter Warm Start Control Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt Determines if the interrupt handler will execute a warm start to the Interpreter upon detecting CODE, GRAPH, CTRL, and SHIFT keys pressed together. 00H disables, NZ enables. ```assembly FBB0H ENSTOP: DEFB 00H ``` -------------------------------- ### CHKRAM Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt Standard routine to perform memory initialization at power-up. Tests for RAM in pages 2 and 3 across all slots. ```APIDOC ## CHKRAM ### Description Standard routine to perform memory initialization at power-up. It non-destructively tests for RAM in pages 2 and 3 in all sixteen possible slots then sets the Primary and Secondary Slot registers to switch in the largest area found. The entire Workspace Area (F380H to FFC9H) is zeroed and EXPTBL and SLTTBL filled in to map any expansion interfaces in existence Interrupt Mode 1 is set and control transfers to the remainder of the power-up initialization routine (7C76H). ### Modifies AF, BC, DE, HL, SP ``` -------------------------------- ### LPTSTT - Get Printer Status Source: https://github.com/fubukimaru/asmsx/blob/master/ref/RedBook-Konamiman.txt Examines the current status of the printer. The result is returned in the A register and Z flag. ```APIDOC ## LPTSTT (00A8H/MAIN) ### Description Examines the current printer status. ### Method BIOS Routine ### Parameters Input: None ### Output - **A register**: Printer status - **Z flag**: Printer status ### Function Returns the printer status. The printer can be used when A register is 255 and Z flag is 0. The printer cannot be used when A register is 0 and Z flag is 1. ``` -------------------------------- ### Basic asMSX Invocation Source: https://context7.com/fubukimaru/asmsx/llms.txt Assemble a source file from the command line. The `.asm` extension is assumed if not provided. Output files are generated alongside the source file. ```sh # Assemble file.asm → file.rom / file.sym / file.txt asmsx file.asm ``` ```sh # Enable Zilog standard syntax (parentheses for indirection) asmsx -z file.asm ``` ```sh # Silent mode – suppress all messages asmsx -s file.asm ``` ```sh # Verbose/debug mode asmsx -vv file.asm ``` ```sh # Write all output to a custom prefix or directory asmsx -o build/output file.asm # → build/output.rom, build/output.sym … asmsx -o build/ # → build/file.rom, build/file.sym … ``` -------------------------------- ### Include Files and Binary Data Source: https://context7.com/fubukimaru/asmsx/llms.txt Use .INCLUDE to insert other assembly files and .INCBIN to embed raw binary data. .INCBIN supports skipping and sizing to include specific file ranges. ```assembly ; Include a shared library .include "inc/pt3-rom.asm" .include "inc/pletter05b-unpackVram-asmsx.asm" ``` ```assembly ; Include a binary graphics file verbatim TILESET: .incbin "data/tileset.bin" ``` ```assembly ; Include a sub-range: skip the 16-byte header, take 2048 bytes FONT_DATA: .incbin "data/font.bin" SKIP 16 SIZE 2048 ``` ```assembly ; Include binary conditionally IFDEF DEBUG_BUILD .incbin "debug_overlay.bin" ENDIF ``` -------------------------------- ### Assemble BASIC-loadable Binary Source: https://context7.com/fubukimaru/asmsx/llms.txt Sets the origin to $C000 and assembles a binary file suitable for loading with BASIC's BLOAD command. Sets the execution entry point. ```assembly ; ============================================================ ; 3. BASIC-loadable binary (.bin) ; ============================================================ .org $C000 .basic ; output: game.bin (BLOAD"GAME.BIN",R) .start MAIN ``` -------------------------------- ### GTPDL - Read Paddle Value Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt Reads the value of a paddle attached to a joystick connector. It involves issuing a start pulse and counting read operations. ```APIDOC ## GTPDL ### Description Standard routine to read the value of any paddle attached to a joystick connector. A start pulse is issued to the specified joystick connector via PSG Register 15. A count is then kept of how many times PSG Register 14 has to be read until the relevant input times out. ### Entry A=Paddle ID (1 to 12) ### Exit A=Paddle value (0 to 255) ### Modifies AF, BC, DE, EI ### Details Paddle IDs for joystick connector 1: 1, 3, 5, 7, 9, 11 Paddle IDs for joystick connector 2: 2, 4, 6, 8, 10, 12 Each unit increment represents approximately 12 μs. ``` -------------------------------- ### INIMLT Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt Standard routine to initialize the VDP to Multicolour Mode. This involves disabling the screen, setting SCRMOD, copying parameters, clearing the screen and sprites, setting VDP mode, and enabling the screen. ```APIDOC ## INIMLT ### Description Standard routine to initialize the VDP to Multicolour Mode. The screen is temporarily disabled via the DISSCR standard routine and SCRMOD set to 03H. The parameters required by the GRPPRT standard routine are set up by copying MLTPAT to PATBAS and MLTATR to ATRBAS. The character code driver pattern is then copied into the VDP Name Table, the screen cleared (07B9H) and all sprites cleared (06BBH). Finally the VDP mode and base addresses are set via the SETMLT standard routine and the screen is enabled. ### Address 061FH ### Entry None ### Exit None ### Modifies AF, BC, DE, HL, EI ``` -------------------------------- ### Building asMSX from Source Source: https://context7.com/fubukimaru/asmsx/llms.txt Compile asMSX using Make. Dependencies include GCC, Flex, Bison, and the standard C library with math support. The Makefile supports Linux, cross-compiled Windows executables, macOS, and ARM. ```sh # Install dependencies (Ubuntu / Debian) sudo apt install -y make gcc flex bison git build-essential \ libbison-dev libfl-dev libpthread-stubs0-dev ``` ```sh # Build native Linux binary make ``` ```sh # Cross-compile for Windows (32-bit) make asmsx32.exe # requires i686-w64-mingw32-gcc ``` ```sh # Cross-compile for Windows (64-bit) make asmsx64.exe # requires x86_64-w64-mingw32-gcc ``` ```sh # Cross-compile for macOS make asmsx.osx # requires o64-clang ``` ```sh # Cross-compile for ARM (e.g. Raspberry Pi) make asmsx.arm # requires arm-linux-gnueabi-gcc ``` ```sh # Debug build with extra Bison/Flex output make debug ``` ```sh # Install to /usr/local/bin sudo make install ``` ```sh # Install debug binary sudo make install-debug ``` ```sh # Build release ZIPs for all targets make release ``` ```sh # Run automated tests (requires behave) make test ``` -------------------------------- ### Find and Set Slot/Subslot for ROMs Source: https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md For ROMs and MegaROMs starting on page 1 (4000h), this automatically finds and sets the slot and subslot on page 2 (8000h). ```assembly .SEARCH ``` -------------------------------- ### MSX Extension ROM Workspace Buffer Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt Defines a buffer for local workspace for each of the sixty-four possible extension ROMs. Each ROM gets two bytes of workspace. ```assembly FD09H SLTWRK: DEFS 128 ``` -------------------------------- ### STMOTR BIOS Routine (Assembly) Source: https://github.com/fubukimaru/asmsx/blob/master/ref/RedBook-Konamiman.txt Sets the status of the tape motor. Input A specifies the action: 0 for stop, 1 for start, 255 for reverse current status. ```assembly STMOTR EQU 00F3H ``` -------------------------------- ### INIGRP Source: https://github.com/fubukimaru/asmsx/blob/master/ref/aredbook.txt Standard routine to initialize the VDP to Graphics Mode. This involves disabling the screen, setting SCRMOD, copying parameters, clearing the screen and sprites, setting VDP mode, and enabling the screen. ```APIDOC ## INIGRP ### Description Standard routine to initialize the VDP to Graphics Mode. The screen is temporarily disabled via the DISSCR standard routine and SCRMOD set to 02H. The parameters required by the GRPPRT standard routine are set up by copying GRPPAT to PATBAS and GRPATR to ATRBAS. The character code driver pattern is then copied into the VDP Name Table, the screen cleared (07A1H) and all sprites cleared (06BBH). Finally the VDP mode and base addresses are set via the SETGRP standard routine and the screen is enabled. ### Address 05D2H ### Entry None ### Exit None ### Modifies AF, BC, DE, HL, EI ``` -------------------------------- ### Generate MegaROM Header Source: https://github.com/fubukimaru/asmsx/blob/master/doc/asmsx.md Generates a header for specified MegaROM mappers. Sets the start address to sub-page 0, eliminating the need for ORG, PAGE, or SUBPAGE directives. ```assembly .MegaROM [mapper] ```