Numbers and misc

;		;comment
*		;comment when in 1st column

a=1234		;base 10
a=$1234		;base 16
a=%11010		;base 2

a=a + &		;line continuation
  b
a$="Howdy"	;strings -- " or ' allowed delimeters
a$=!5"hola"!13	;like chr$(5)+"hola"+chr$(13)
a$=!s"hey"		;!s -- use screen codes instead of petscii
		;!r –  use regular (petscii) codes
		;!n – negate (ora $80) following codes
		;!z – do not null-terminate string
			
Slang is CaSe InSeNsItIvE

Variable types and declarations

byte, ubyte		;1 byte, signed/unsigned
int, uint		;2 bytes, signed/unsigned
float		;5 bytes, MFLPT format

byte blah@$d020	;@-var: locate variable at $d020

int screen(25,40)@$0400      ;Create 2D array, locate at text screen
int blah(3,3)=[ [1 2 3] &
	       [4 5 6] &
	       [7 8 9] ]    ;Create 2D array and pre-initialize values
ubyte str(50)=['..can also use strings to pre-initialize']

blah(2,0) = 1	;Note that array indices start at 0

byte ^test 		;Create 16-bit pointer to a byte
byte ^^test2(20,10) 	;24-bit pointer to byte array
test=$c000		;set point location: lda #$c000  sta zp
^test=10		;set location value: lda #10  sta (zp),y
test2=$123456	;set array base address
test2(3,5)=10	;leading ^ not used with arrays

deftype foo	;Compound variable type declaration
  int .a		;note leading .
  byte .b(10)
  float .x
defend

type foo yak1, yak2	;Create two variables of compound type foo
yak1.a = 10	;...which can then access individual elements
yak.b(3) = -8
yak1.x = 3.1415926

VarBlock @$c000	;Define following variables starting at $c000
  ubyte t1
  int t2
EndVarBlock	;until the EndVarBlock

int b,c
c=#b+3		;Set c to the _address_ of b plus three

Strings

byte str(20)	;Strings are byte arrays, null-terminated
str(1) = 1		;Treat as byte array
str$="Hey!!"!13	;Using the $ sign treats as string

if str$(2:4) = "y!!"	;Can specify substring ranges
  str$(2)="blah"	;|H|e|b|l|a|h|00
Subroutines

note: <- indicates backarrow key; use _ (underscore) on PC/xlang

sub blah()		;Subroutine with no input or output variables
sub blah2(int x, byte r)    ;Subroutine with two input variables
sub blah3(int z)<-byte s,int t  ;Subroutine with one input variable (z)
		            ;and two output variables (s, t)

sub blah4(@ax)	;One input variable, in the .A (lo) and .X (hi)
		;registers. @x @a @xy @yx -> @(lo)(hi)
endsub			;End subroutine (rts)

sub asm chrout@$ffd2(@a)	;Create subroutine interface				;(for calling external routines)
Usage:

blah3(10)		;Call subroutine on its own
a=blah3<-s	;Use subroutine variables in expressions
b=blah3<-t + a + 1
a=blah3(12)<-s	;can also combine operations

Operators
Note: comparison operators can be used with strings

=, +=, -=, *=, /=	;Assignment operator, e.g. a=1, c+=3
++, --		;Increment/decrement, e.g. blah++

bitand, bitor, biteor	;bitwise operators
+		;addition, string concatenation
- * / ^ %		;standard math operators.  Note: int * and /
		;require core library; floats require BASIC
<< >>		;shift operators (note: fixed only, not float)
< <= > >= = !=	;comparison operators.  Returns 0 or 1
and, or, eor	;logical comparison operators.  Returns 0 
		;or nonzero (true).  Note: identical to			;bitand etc. but lowest precedence
Functions

byte, ubyte, int, uint, float	;Type conversion
a = int(x)+c		;Convert x to type int, then add

floating-point functions: (BASIC ROM routines)
abs		;absolute value
atn		;arctangent (note: will rename as atan)
cos		;cosine
exp		;exponential
trunc		;truncate
log		;logarithm
rnd		;random number
sgn		;sign
sqrt		;square root
tan		;tangent

misc functions:
not		;logical not (0->1, nonzero->0)

VIC functions: (may be used in expression)
SpriteColSpr(number) ;Check spr-spr collision.  Returns 0/nonzero

Flow control, loops

Note: may be followed by a ! to execute the block when _false_:

	if!	;ifnot -- if not true then...
	elseif! while! until! case!

May be followed by + to use branch instead of jmp (if+, next+, …)
if (expr)		;standard if-block
  [code]
elsif (expr)
  [code]
else
  [code]
endif

for x=start:end [step y]  ;standard for-loop.  step is optional
  [code]
endfor -or- next	   ;next is alias for endfor

while (expr) / endwhile	;standard while-loop
repeat / until (expr)		;standard repeat-loop
repeat / forever		;infinite repeat loop

testall		;test all of the following cases (inclusive test)
testelse		;test cases like if-elsif-elsif (exclusive test)
  case (expr)	;execute following code if (expr) true
  case (expr)	;multiple case statements may follow
endtest		;end statement

Printing and I/O commands

sprint [string]	;Simple print (String print) -- prints strings.
sprintln		;Like sprint, but adds a CR at the end.
sprint(10,3) "yo!"	;Print to row 10, column 3

print		;Main print command.  Requires core library
print !5"Hey!"!13	;strings…
print "x=" x " and y=",y  ;mix and match, commas optional…
print(10,3) "b=" float(b+10*sin(x))  ;expressions, (row,col) allowed
println			    ;Print, followed by CR

getchar b		;read a char, store in b.  Does not wait for char
waitchar b		;wait for keypress, store in b
waitchar		;wait for keypress

Input b$		;input a string using kernal CHRIN, store in b
InputStr(maxlen) b$	;input using core library, max string length
InputFloat x	;input float using core library
InputInt y		;input 16-bit, signed/unsigned, dec/hex/bin

load "filename",dev,address	;load file to memory
save "filename",dev,start,end	;save memory to file

Misc

MemConfig number	;Set memory configuration (location $01, 0-7)

poke		;similar to BASIC poke
wait address,value	;loop until address = value
wait $d012,255	;wait for $d012=255

waitne, waitge, waitlt	;wait until address !=, >=, or <= value
waitbitsclear	;addr AND value (wait for bits to be clear)
waitbitsset		;wait for specific bits to be set

fillmem(start,end,fill byte)    ;Fill a range of memory with a byte

done / donebrk	;end program (rts/brk)
endsub		;end subroutine (rts)
endirq		;end irq routine (rti)

put 'filename'	;PUT the file into code at current location

saveobj "@0:testcode.o"  ;auto-save object code after compile
autorun		;auto-run program after compile

SetZPTemp address	;Set temporary ZP stack (default=$02)
SetEvalTemp address	;Set temporary results (default=$0110)
SetStrBuf address	;Set location for string buffer (default=$0200)
SlangOut		;Compiler off (asm only)
SlangIn		;Compiler back on

Interrupts

irq name(varlist)	;irq is an alias for sub -- create an IRQ routine
endirq		;...but end it with endirq instead of endsub
jmpkernalirq	;or exit through the normal ROM IRQ

DisableInterrupts	;Disable Interrupts (sei)
SetIRQRoutine(name) ;Set IRQ routine ($0314)
EnableInterrupts	;Enable (cli)

EnableTimerAIRQ	;Enable CIA#1 timer A IRQ (system IRQ)
DisableTimerAIRQ	;Disable
SetTimerA(value)	;set CIA#1 timer A value
AckTimerAIRQ	;Acknowledge timer A IRQ

EnableRasterIRQ	;Enable the VIC raster IRQ
DisableRasterIRQ	;Disable
AckRasterIRQ	;Acknowledge VIC raster irq
SetRaster(value)	;Set raster value for IRQ to occur at

VIC commands

UseSpriteStuff		;Enables below sprite commands

SetSpriteX(#,xpos)		;Set X-position for sprite number #
SetSpriteY(#,ypos)		;Set y-position
SetSpriteColor(#,color)	;Set color
SetSpritePtr(#,block)	;Sets the sprite pointer to block.  Will be
		;updated in future to something more useful
SpriteOn(#)		;Turn sprite number # on
SpriteOff(#)		;Turn it off

SetScrollX(value)		;Set the fine x-scroll value (0-7)
SetCol38 / SetCol40		;Set 38/40 columns
SetCharData(address)		;Set the character dot data address
SetVideoMatrix(address)	;Sets the video (screen) address
SetVICBank(bank)		;Sets the 16k graphics bank to 0-3

Linker

REL - Assemble as RELocatable file.  Placed at top of code.
ENT - Declare label/variable/subroutine as an ENTry point
EXT - Declare label/variable/subroutine as EXTernal

Editor/Jammon (SCPU environment)

Ctrl-h from editor brings up all available commands.
SYS54016 will re-enter editor upon reset, etc.
Please see the jammon docs (they're short!) for ML monitor details.

Memory map

$0801-$A800	Slang core
$A800-$CE00	Compiler commands
$CE00-$CFFF	Used by slang for temporary results
bank 2:		Temp: code assembled to bank 2
bank 3:		Temp: vartab, storage during assembly
bank 8+:		Editor text stored here
hi bank:		Used to store slang environment

Upon exit:
- monitor in bank 0 at config.s address, if exited to monitor
- PPPatch at $CE80-$CFFF or so
- Re-entry code stored to $01d300 (SYS 54016 to restart)
- Editor text moved up in memory as high as it can
- Slang environment, etc. stored in highest available bank, e.g. on a 16M system this will be bank $F5.