MSXcompiler
version 3.0
MSX compiler from basic to assembly language
by bosh77
Works on Windows
Introduction
Write your code for MSX computer in BASIC and with "F5", the compilator
will create a ".DSK" or ".ROM" file, to your choice, to try on emulator or real MSX!
First you need to set the emulator and its path!
TO START: Select emulator and its path, then load an example
(*.msxproj) from "examples" folder or create your project, press F5 to COMPILE and RUN!
In the same folder you will find the ".DSK", ".ROM" and ".ASM" files!
This compiler is still under development and may contain several bugs.
Also the code created by the compilation could be cumbersome and slower than necessary.
I am working to improve it...
New in This Version
- Color Editor with Syntax Highlighting and multi sheet manager
- Improved IDE with many functions
- Now you can write your program without number lines, but use labels, so you don't need RENUM
- You can compile your project also from command line (see example1.bat and example2.bat)
- Added graphics instructions for MSX2+
- Added some instructions for example BASE, INP, OUT, SOUND and others
- Added settings window
How it's work
The compiler read BASIC code and translate it in ASSEMBLER, then translate it in BINARY code
You can save and see ASM file if you want, select relative option in Settings window
if the binary code resulting from the compilation is greater than 16kb, then you will have to divide your project into more than one file, each with a maximum of 16kb of binary code, up to a maximum of 8 files.
It is possible to make calls between files with the instructions CALLPAGE (as gosub) and JUMPPAGE (as goto)
example: CALLPAGE 1,100 --> make a calling to page 1 at line 100
Look at example folders to see how it's work
You can select TARGET of your compilation (CARTRIDGE or DISK)
Depending on the TARGET (cartridge or disk), a .ROM file of a maximum of 128kb or a .DSK
file containing up to a maximum of 8 files of 16kb each will be created!
- Memory containing the binary code (4000h-7fffh) with memory mapper to change page
- Memory containing the variables (8000h-bfffh)
- Reserved memory (c000h-caffh)
- Additional memory available from cb00h onwards. (Note that the stack pointer is
initialized to d800h)
- Stack (d800h) but you can change it in Settings window
Instructions and syntax
The supported variables are:
- UBYTE (8 bit unsigned, ex: DIM A AS BYTE)
- INT (16 bit, ex: DIM B AS INT )
- FLOAT (32 bit, ex: DIM C AS FLOAT)
- STRING (16-256 byte, ex: DIM D AS STRING)
- ARRAY (ex: DIM E(10) AS INT) make 10 elements, not 11
Every variable must be declared with DIM before use it
Supported instructions:
#lenstrings, #Imports, IncludeFile, CallPage, JumpPage, AsmLine, Goto, Gosub, Return, Dim, Cls,GetChar, GetKey,
Screen, Set page, Setpage, Draw2Block, DrawBlock, DrawNumber, AddNumber, GetAddressLine,
GetDate, GetTime, GetFiles, GetFileName, SetPalette, SetVDP, Color, Color=,Locate,Print,
Pset, Circle, Paint, Line, Copy, Vpoke, Poke, Vpeek, Peek, PutSprite, Put Sprite, DataB,
DataF, DataI, DataS, ReadB, ReadF, ReadI, ReadS, Restore, DrawText, if...then...else,
for...next
(In if...then use { } with boolean operator. ex: If a=1 And {b=2 or c=3} Then ... )
Other functions:
TAN, ATN, COS, SIN, SQR, ABS, INT, RND, ASC, VAL, CHR, STR, HEX
Operators for math operations:
| = or
& = and
~ = xor
% = module
New instructions of this BASIC version
#lenstrings
Set length of string. His value can be 15,31,63,127 or 255.
Example: #lenstrings=31
#Imports
adds a new page to the project, which can be reached with the CALLPAGE or JUMPPAGE instructions
Example: #imports 1,"part2.msxproj"
Now you can use CALLPAGE and JUMPAGE
CallPage
makes a call to the specified page and program line (or label), as a Gosub instruction
Example: CallPage 1,100
JumpPage
makes a jump to the specified page and program line (or label), as a Goto instruction
Example: JumpPage 2,mylabel
AsmLine
Insert an assembly instruction
Example: AsmLine "LD A,10"
GetChar()
Read the Keyboard and return the ascii code corresponding to the key pressed
Example: a=GetChar()
GetKey(KeyCode)
Read the Keyboard and return 0 (key not pressed) or 255 (key pressed)
Example: b=GetKey(KeySpace)
See all key codes here
GetAddressLine
Get the memory address of line or label specified and return it to the specified variable
Example: GetAddressLine id,1000 (now the variable id contains memory address of line 1000)
DrawBlock ram, vram, lines, wram
Copy a block of memory from RAM to VRAM
Example: DrawBlock 0, 0, 10, 32
(See some examples in the Example folders)
Draw2Block ram, vram, lines, wram, wvram, addvram
Copy a block of memory from RAM to VRAM, it is also possible to specify 2 additional parameters
Example: Draw2Block 0, 0, 10, 32, 20, 40
(See some examples in the Example folders)
GetDate
Gets the date of the system
Example: GetDate year, month, day, dayofweek
GetTime
Gets the time of the system
Example: GetTime hours, minutes, seconds
SetPalette
Set the color palette from 32 bytes long index variable
Example:
Dim palette(32) As Byte
SetPalette palette
SetVDP
Sets a VDP register with the specified value
Example: SetVDP 24,10
GetFiles
Reads files from the specified unit and inserts them in a index variable, also returning the number of files found
Example:
Dim filesdata(1232) As Byte
Dim filesnum As Byte
GetFiles 0, filesdata, filesnum
GetFileName
Recover the name of a file from a index variable set before via Getfiles (see Getfiles)
Example: GetFileName numfile, filesdata, filename
List of key codes
Key0, Key1, Key2, Key3, Key4, Key5, Key6, Key7, Key8, Key9, KeyMinus, KeyEqual, KeyBackslash, KeyOpenBracket, KeyCloseBracket, KeyColon, KeyQuote1, KeyQuote2, KeyMinor, KeyMajor, KeySlash,
KeyA, KeyB, KeyC, KeyD, KeyE, KeyF, KeyG, KeyH, KeyI, KeyJ, KeyK, KeyL, KeyM, KeyN, KeyO, KeyP, KeyQ, KeyR, KeyS, KeyT, KeyU, KeyV, KeyW, KeyX, KeyY, KeyZ, KeyShift, KeyCtrl, KeyGraph, KeyCap, KeyCode,
KeyF1, KeyF2, KeyF3, KeyF4, KeyF5, KeyEsc, KeyTab, KeyStop, KeyBs, KeySelect, KeyReturn, KeySpace, KeyHome, KeyIns, KeyDel, KeyLeft, KeyUp, KeyDown, KeyRight
IDE Functions
The IDE contains all the normal functions of a text editor (for example: CTRL + Z = Undo)
In addition there are some commands for different functions:
CTRL + K = Set Main Project
F12 = If pressed on a line number or a label after a GOTO or GOSUB instruction, moves the cursor to the original line number or label
Special thanks to Zeda Thomas for the float32 routines!
Special thanks to Grauw for information about assembly language (http://map.grauw.nl/)