ts-c-compiler
ts-c-compiler copied to clipboard
⚙️ Multipass C Compiler, Assembler and X86 emulator written in TypeScript
ts-c-compiler
Heroku APP: https://i8086.herokuapp.com/
16 bit ANSI C99 x86 compiler, assembler and virtual machine written entirely in TypeScript. It is designed to help with prototyping small bootsector (or bigger) real mode games 🎮 and apps 💻.
JavaScript 16bit x86 assembler bundled in emulator is designed to be fully binarny compatible with 16bit NASM compiler.

Running
yarn run develop
ASM syntax
It's pretty similar to NASM syntax (including preprocessor), examples:
https://github.com/Mati365/i8086.js/tree/master/packages/x86-assembler/tests/asm
Testing
yarn run test
Status
- [ ] C compiler
- [ ] Frontend
- [x] Syntax parser
- [x] Typechecker
- [x] IR code generator
- [ ] Backend
- [ ] IR optimizer
- [ ] X86-16 Code generator
- [ ] Frontend
- [x] ASM Compiler
- [x] NASM syntax instruction compiler matcher with expression eval
mov ax, byte [ds:label+bx+12+(1/3)]
- [x] Instruction prefix support
rep movsw
- [x] Compiler bits/org config
[bits 16]
,[org 0x7C00]
- [x] Labels support
jmp_label:
- [x] Data define support
db
,dw
,dd
,dq
,dt
- [x]
EQU
,times
support - [x] Floating point numbers support
- [x] Preprocessor
- [x] Basic lang keywords support:
%if
,%ifn
,%ifdef
,%ifndef
,%else
,%elif
,%elifndef
,%elifdef
,%elifn
,%define
,%undef
- [x] Macros support:
%macro
,%define
,%imacro
- [x] Predefined macros like
__TIMES__
- [x] Inline expressions calls
%[__TIMES__]
- [x] Basic lang keywords support:
- [x] Output logger
- [x] Basic logger binary blob serializer helpers
- [x] Diassembler binary view
- [x] Branch arrows (for
jmp
,call
,jz
etc.)
- [x] NASM syntax instruction compiler matcher with expression eval
- [ ] CPU Emulator
- [x] Magic breakpoint support
xchg bx, bx
- [x] Interrupts handlers support
- [x] Basic Intel ~80186 instructions set
- [x] ALU instructions support
- [x] FPU Support
- [x] Assembler
- [x] Emulator
- [ ] Basic PIT/PIC support
- [x] PIT
- [ ] PIC
- [ ] IDE
- [ ] PS2
- [ ] Graphics mode
- [x] Basic canvas graphics driver
- [x] Text Mode
- [x] Graphics VGA
- [x] VGA IO ports bindings
- [ ] BIOS
- [x] Basic bios interrupt handlers
- [x] Magic breakpoint support
- [ ] App frontend
- [ ] Basic front CSS UI
- [ ] Debugger
Screens
Docs
https://cs.lmu.edu/~ray/notes/ir/
https://www.youtube.com/watch?v=yTXCPGAD3SQ
https://bellard.org/otcc/otccn.c
https://gist.github.com/nikAizuddin/0e307cac142792dcdeba
http://www.plantation-productions.com/Webster/www.artofasm.com/Windows/HTML/RealArithmetica3.html
https://gist.github.com/mikesmullin/6259449
http://teaching.idallen.com/dat2343/10f/notes/040_overflow.txt
http://ece425web.groups.et.byu.net/stable/labs/8086Assembly.html
http://dsearls.org/courses/C391OrgSys/IntelAL/8086_instruction_set.html
https://pdos.csail.mit.edu/6.828/2008/readings/i386/s17_02.htm
https://xem.github.io/minix86/manual/intel-x86-and-64-manual-vol1/o_7281d5ea06a5b67a-194.html
https://johnloomis.org/ece314/notes/fpu/fpu.pdf
https://www.felixcloutier.com/x86/index.html
https://c9x.me/x86/html/file_module_x86_id_87.html
http://www.osdever.net/FreeVGA/vga/graphreg.htm#06
http://www.osdever.net/FreeVGA/vga/vgamem.htm
http://www.osdever.net/FreeVGA/home.htm
License
The MIT License (MIT) Copyright (c) 2021 Mateusz Bagiński
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.