Skip to content

Repository files navigation

CosmoVM

Assembler + emulator for an imaginary computer
Example assembly code in /example/boot.asm

Gallery

asm.avif text_mode.avif gfx_mode.avif

Specifications

/**
 * Cosmo 16-bit CPU
 * General purpose registers:
 * AZ, BZ, CZ, DZ, EZ, FZ, GZ, HZ
 *
 * Special registers:
 * MO: Memory Offset
 * XA: eXecution Address
 * SB: Stack base
 * SP: Stack ptr
 *
 * Flags from LSB to MSB
 * ERROR
 * EXCEPTION
 * EQUAL
 * GREATER
 * LESSER
 * RESET
 * SHUTDOWN
*/
/**
 * Instruction set:
 * i-variants: takes a immediate or a label name
 * b-variants: byte-wide as opposed to word-wide by default
 *
 * ADD ADDi, Add, result in first operand
 * AND ANDi, Logical AND, result in first operand
 * CALL, Store MO, XA in stack, jumps to code offset + first operand(IMM)
 * CLER, Clear error flag
 * CLXP, Clear exception flag
 * CMP CMPi, Sets condition flags accordingly
 * DIV DIVi, Divide, quotient in GZ, remainder in HZ
 * IN, [!] first operand(REG) is destination, second operand(IMM) is port number
 * --------------------
 * Following instructions jump to code offset + first operand(IMM)
 * JE, Jump if equal flag set
 * JNE, Jump if equal flag cleared
 * JER, Jump if error flag set
 * JXP, Jump if exception flag set
 * JG, Jump if greater flag set
 * JGE, Jump if greater flag set or equal flag set
 * JMP, Jump unconditionally
 * LOP, Loop HZ times
 * --------------------
 * --------------------
 * Following instructions copy the second operand to the first operand
 * Move word
 * MOV, register <- register
 * MOVi, register <- immediate
 * LOAD, register <- memory at register
 * LOADi, register <- memory at immediate
 * STOR, memory at register <- register
 * STORi, memory at register <- immediate
 * COPY, memory at register <- memory at register
 * COPYi, memory at register <- memory at immediate
 *
 * Move byte
 * LOADb, register <- memory at register
 * LOADbi, register <- memory at immediate
 * STORb, memory at register <- register
 * STORbi, memory at register <- immediate
 * COPYb, memory at register <- memory at register
 * COPYbi, memory at register <- memory at immediate
 * --------------------
 * MUL MULi, Multiply, result in first operand
 * NEG, Negate inplace
 * NOT, Logical NOT inplace
 * OR ORi, Logical OR, result in first operand
 * OUT, [!] first operand(REG) is data, second operand(IMM) is port number
 * POP, Get value from stack to first operand(REG)
 * POPF, Get flags from stack
 * PUSH, PUSHi, Send first operand
 * PUSHF, Send flags to stack
 * RET, Get ZZ, YZ from stack
 * SHL, SHLi, Shift Left first operand(REG) is target, second operand(REG) is n-places
 * SHR, SHRi, Shift Right first operand(REG) is target, second operand(REG) is n-places
 * STER, Set error flag
 * STXP, Set exception flag
 * STRS, Set reset flag
 * STSD, Set shutdown flag
 * SUB SUBi, Substract, result in first operand
 * WCYL, Wait cycle, do nothing
 * XOR XORi, Logical XOR, result in first operand
*/
/**
 * Memory addresses
 * 0x0000 BOOT
 * 0xB4FF VIDEO
*/

Port numbers

/**
 * CosmoClock
 * 0x31: Get year
 * 0x32: Get month
 * 0x33: Get day
 * 0x34: Get hour
 * 0x35: Get minutes
 * 0x36: Get seconds
 *
 * CosmoScreen
 * 0x44: Set video mode, 0: Text, 1: Graphics
 *
 * CosmoKeyboard
 * 0x51: Set key selector, SDL Scancodes
 * 0x52: Get selected key state, 0: Up, 1: Pressed
 * 0x53: Get pressed key, SDL Scancodes
 *
 * CosmoDisk
 * 0x61: Set mode, 0: Read, 1: Write
 * 0x62: Select sector
 * 0x63: Load buffer/ Write buffer
 * 0x64: Get character/Put character
 * 0x65: Get sector count
 * 0x66: At the end of buffer
*/

License

Copyright (C) 2026 JeSuisSur

Unless otherwise stated, original code authored by the project contributors is licensed under the GNU Affero General Public License, version 3 or any later version (AGPL-3.0-or-later).

This repository also contains third-party software, data, generated files, and other materials that are subject to their respective copyrights and license terms. Such materials are not relicensed under the AGPL by inclusion in this repository.

The applicable license and attribution information for third-party materials is retained with those materials where provided and/or documented in the corresponding directories and files.

About

Assembler + Emulator for an imaginary computer

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages