CosmoVM!

Lien Github

Assembleur et Emulateur pour un ordinateur imaginaire!
C'est vaguement inspiré du classique 8086 mais se veut plus droit au but avec peu de symbole et plus de texte. On donne l'impression de coder de l'assembleur mais dans un contexte simplifié et plus agréable. L'assembleur supporte avec aisance la compilation de plusieurs fichiers assembleurs avec prise en charge de la relocalisation et résolution de symboles externes. Depuis on peut accéder a une mémoire de 65535 octets, le clavier, une horloge très faible résolution, un écran RGB565 160x120, un disque permanent par addressage linéaire (sorte de LBA).
Compatible avec Linux et Windows, l'implémentation est en C++ avec un grand usage de ses conteneurs standard ainsi que SDL3, il est à compiler avec XMake (une alternative simple assez peu connue par rapport au systèmes conventionnels). Ce programme n'est certainement pas des plus réalistes (d'un point de vue électronique) mais il se veut être un environnement pour coder de l'assembleur très simple et explicite.

Galerie:

Spécifications:

    
    /**
     * 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
     *
     * WCYL, Wait cycle does nothing
     * 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
     * DEC, Decrement inplace register
     * DIV DIVi, Divide, quotient in IZ, remainder in JZ
     * IN, [!] first operand(REG) is destination, second operand(IMM) is port number
     * INC, Increment inplace register
     * --------------------
     * Following instructions jump to code offset + first operand(IMM)
     * JE, Jump if equal flag set
     * JER, Jump if error flag set
     * JG, Jump if greater flag set
     * JGE, Jump if greater flag set or equal flag set
     * JL, Jump if lesser flag set
     * JLE, Jump if lesser flag set or equal flag set
     * JMP, Jump unconditionally
     * JNE, Jump if equal flag cleared
     * JNER, Jump if error flag cleared
     * JNXP, Jump if exception flag cleared
     * JXP, Jump if exception flag set
     * LOP, Loop JZ times
     * LOPE, Loop if equal
     * LOPNE, Loop if not equal
     * --------------------
     * --------------------
     * 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
    */
    /**
     * 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
    */
    
    
Exemple de code:
    
    jmp start

    ; Data
    locate prompt
        str /Press enter to boot.../
        u8 0

    locate stack_base
        u16 0xB000

    ; Code
    locate start
        ; Setup stack
        loadi sb, stack_base

        ; Set text mode
        call clear_text_mode
        movi az, 0
        out az, 0x44

        ; Print message
        movi az, prompt                       ; Move pointer to string
        movi bz, 0                            ; 0 offset

        call print

        call wait_enter_pressed

        ; Load sectors 1 and 2
        movi az, 1
        movi bz, 0x200
        call sector_load

        movi az, 2
        movi bz, 0x400
        call sector_load

        ; Go stage 2
        pushi 0x0200                        ; Set MO to 0x200
        pushi 0x0000                        ; Set XA to 0x0
        ret
    
    
Version 3daf2b8 2025-11-30 11:43:13 +0100.