Blame as10k1/README

Packit 427e91
Packit 427e91
AS10k1 Assembler version A0.99
Packit 427e91
------------------------------
Packit 427e91
Packit 427e91
This is an assembler for the emu10k1 DSP chip present in the creative SB
Packit 427e91
live, PCI 512, and emu APS sound cards. It is used to make audio effects such 
Packit 427e91
as a flanger, chorus or reverb.
Packit 427e91
Packit 427e91
Packit 427e91
Author: Daniel Bertrand <d.bertrand@ieee.ca>
Packit 427e91
Packit 427e91
Packit 427e91
This version of the assembler was modified for the ALSA driver by
Packit 427e91
Jaroslav Kysela <perex@perex.cz>.
Packit 427e91
Packit 427e91
Packit 427e91
Usage: as10k1 <asm file> [bin output file] 
Packit 427e91
------
Packit 427e91
Packit 427e91
Making binary DSP programs:
Packit 427e91
Packit 427e91
example, type:
Packit 427e91
Packit 427e91
./as10k1 chorus.asm
Packit 427e91
Packit 427e91
(it creates chorus.bin)
Packit 427e91
Packit 427e91
--
Packit 427e91
Loading Binary DSP files
Packit 427e91
Packit 427e91
Packit 427e91
<..TODO..>
Packit 427e91
Packit 427e91
Packit 427e91
Description of files included
Packit 427e91
------------------------------
Packit 427e91
Packit 427e91
Chorus.asm	-- chorus effect
Packit 427e91
Flanger.asm	-- flanger effect
Packit 427e91
Delay.asm	-- generates Echos, this is _not_ a reverb
Packit 427e91
eq5.asm		-- A 5 band Equalizer (needs a bit more work)
Packit 427e91
fir.asm		-- A low pass filter (A demo of a fir filter implementation)
Packit 427e91
sine.asm	-- A sinewave generator (can be useful for debuging)
Packit 427e91
vibrato.asm	-- A vibrato effect (or is it a tremolo?)
Packit 427e91
vol_ctrl.asm	-- provides support for the hardware volume control
Packit 427e91
emu_constants.asm -- not an effect, just contains handy constants and macros
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
===============================================================================
Packit 427e91
Packit 427e91
Packit 427e91
Programming Usage:
Packit 427e91
=================
Packit 427e91
Packit 427e91
Assembly Syntax
Packit 427e91
---------------
Packit 427e91
Packit 427e91
Assembly lines generally have four fields seperated by spaces or tabs:
Packit 427e91
Packit 427e91
Packit 427e91
Name_Field   Opcode_field    Operand_Field   Comment_Field
Packit 427e91
----------   ------------    -------------   -------------
Packit 427e91
[symbol]      [mnemonic]      [operands]       [text]
Packit 427e91
Packit 427e91
Packit 427e91
With this assembler, each line can have a maximum of 256 characters and each
Packit 427e91
symbol can be a maximum of 32 characters. Symbols ARE case sensitive, opcodes
Packit 427e91
ARE NOT.
Packit 427e91
Packit 427e91
OPCODES
Packit 427e91
--------
Packit 427e91
Packit 427e91
Packit 427e91
All instructions require 4 operands, they have the format
Packit 427e91
Packit 427e91
	<opcode> R,A,X,Y
Packit 427e91
	
Packit 427e91
(note some documentation out there the call the R operand as Z and the A
Packit 427e91
operand as W).
Packit 427e91
Packit 427e91
Here are 16 opcodes.
Packit 427e91
Packit 427e91
   0x0 (MACS) : R = A + (X * Y >> 31)   ; saturation
Packit 427e91
   0x1 (MACS1) : R = A + (-X * Y >> 31)  ; saturation
Packit 427e91
   0x2 (MACW) : R = A + (X * Y >> 31)   ; wraparound
Packit 427e91
   0x3 (MACW1) : R = A + (-X * Y >> 31)  ; wraparound
Packit 427e91
   0x4 (MACINTS) : R = A + X * Y  ; saturation
Packit 427e91
   0x5 (MACINTW) : R = A + X * Y  ; wraparound (31-bit)
Packit 427e91
   0x6 (ACC3) : R = A + X + Y  ; saturation
Packit 427e91
   0x7 (MACMV) : R = A, acc += X * Y >> 31
Packit 427e91
   0x8 (ANDXOR) : R = (A & X) ^ Y
Packit 427e91
   0x9 (TSTNEG) : R = (A >= Y) ? X : ~X
Packit 427e91
   0xa (LIMIT) : R = (A >= Y) ? X : Y
Packit 427e91
   0xb (LIMIT1): R = (A < Y) ? X : Y
Packit 427e91
   0xc (LOG) : ...
Packit 427e91
   0xd (EXP) : ...
Packit 427e91
   0xe (INTERP) : R = A + (X * (Y - A) >> 31)  ; saturation
Packit 427e91
   0xf (SKIP) : R,CCR,CC_TEST,COUNT  
Packit 427e91
Packit 427e91
Packit 427e91
Special note on the accumulator: 
Packit 427e91
mac* instruction with ACCUM as A operand     => uses Most significant 32 bits.
Packit 427e91
macint* instruction with ACCUM as A operand  => uses Least significant 32 bits.
Packit 427e91
Packit 427e91
Packit 427e91
For more details on the emu10k1 see the dsp.txt file distributed with the
Packit 427e91
linux driver.
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
Operands
Packit 427e91
--------
Packit 427e91
Packit 427e91
Operands can be specified as either a symbol or a value. hex values are
Packit 427e91
prefixed by $, octal by @, and binary by %.
Packit 427e91
Packit 427e91
e.g.:
Packit 427e91
Packit 427e91
123 decimal value
Packit 427e91
$123 hex value
Packit 427e91
@123 octal value
Packit 427e91
%01101 binary value
Packit 427e91
Packit 427e91
The operands for emu10k1 instructions are always addresses of registers, there
Packit 427e91
are no instruction which take immediate values.
Packit 427e91
Packit 427e91
Operands currently support basic arithmetic, It does not support bedmas (or is it bodmas)
Packit 427e91
so don't try to use (). Infact don't put spaces either (for now, until I fix this).
Packit 427e91
Packit 427e91
Summary of assembler directives
Packit 427e91
-------------------------------
Packit 427e91
Packit 427e91
	  NAME "string"			;give a name to the patch
Packit 427e91
Packit 427e91
<symbol>  IO				;defines an Input/output pair	
Packit 427e91
<symbol>  CONTROL <symbol>		;defines a controlable GPR	
Packit 427e91
<symbol>  DYNamic <number of storage spaces>	;defines a temporary GPR
Packit 427e91
<symbol>  STAtic <initial value>		;defines a constant GPR /w initial value
Packit 427e91
<symbol>  EQU <Value equated>		;assembly time constant
Packit 427e91
<symbol>  CONstant <value>		;defines a read-only GPR	
Packit 427e91
Packit 427e91
<symbol>  DELAY  <value>		;defines a Delay line
Packit 427e91
<symbol>  TABLE  <value>		;defines a lookup table
Packit 427e91
Packit 427e91
<symbol>  TREAD  <tram id>,<value>	;defines a tram read 
Packit 427e91
<symbol>  TWRITE <tram id>,<value>	;defines a tram write
Packit 427e91
Packit 427e91
Packit 427e91
	  INCLUDE <"file name">		;includes an external file
Packit 427e91
Packit 427e91
	  FOR <variable>=<start>:<finish> ;Assembly-time 'for' statement
Packit 427e91
	  ENDFOR			;ends a for loop
Packit 427e91
Packit 427e91
Packit 427e91
<symbol>  MACRO	arg1,arg2,arg3....	;used for define a macro
Packit 427e91
	  ENDM				;end a macro definition
Packit 427e91
Packit 427e91
	  END				;ends the code
Packit 427e91
Packit 427e91
Packit 427e91
Detailed description of directives:
Packit 427e91
----------------------------------
Packit 427e91
Packit 427e91
( <> brackets indicate required fields, [] brackets indicate optional fields)
Packit 427e91
Packit 427e91
DYNamic  directive (replaces DS):
Packit 427e91
Packit 427e91
Defines a storage space from the gpr pool on the emu10k1. The
Packit 427e91
assembler maintains a pointer to the gpr registers (starting at $100). The
Packit 427e91
symbol is assigned the value of the address of the gpr pointer. The pointer is
Packit 427e91
increment by the number following the dynamic directive.
Packit 427e91
Packit 427e91
syntax:
Packit 427e91
<symbol> dynamic 
Packit 427e91
Packit 427e91
or
Packit 427e91
Packit 427e91
<symbol> dyn <number of storage spaces>
Packit 427e91
Packit 427e91
--
Packit 427e91
STAtic directive (replaces DC):
Packit 427e91
Packit 427e91
Similar to dynamic, but places an initial value in the memory location.
Packit 427e91
Packit 427e91
The values specified are slightly different from operands for instructions. 
Packit 427e91
The values are 32 bit signed intergers so that a maximum magnitude of 2^31 can
Packit 427e91
be stored. values can be in signed decimal, unsigned octal, binary and hex, 
Packit 427e91
and in fractional decimal (values between -1 to 1) for filter coefficients.
Packit 427e91
Packit 427e91
A fractional decimal is specified using the '#' prefix and can include an 
Packit 427e91
exponent. These values should be used with the fractional "mac" instructions.
Packit 427e91
Packit 427e91
NEW! fractional numbers are now handle automatically, a value between 1 and 
Packit 427e91
-1 will be converted into fractional form. The old # form still works though.
Packit 427e91
(BUG:confusion occurs at 1 and -1 however, should 1 be represented as $1
Packit 427e91
 or $7ffffff?, currently defaults to $1, so #1 still has some importance)
Packit 427e91
Packit 427e91
examples:
Packit 427e91
	.03412
Packit 427e91
	123E-3
Packit 427e91
	#-0.1236
Packit 427e91
Packit 427e91
syntax:
Packit 427e91
Packit 427e91
<symbol> static <initial value>
Packit 427e91
Packit 427e91
or
Packit 427e91
Packit 427e91
<symbol> sta <initial value>
Packit 427e91
Packit 427e91
--
Packit 427e91
CONTROL
Packit 427e91
Packit 427e91
Control registers are similar to DC, but they also include a min and max value. The control register is used
Packit 427e91
by a mixer app to change values in a GPR (a volume control, for example). 
Packit 427e91
Packit 427e91
syntax:
Packit 427e91
Packit 427e91
<symbol> CONTROL <initial value>,<min>,<max>
Packit 427e91
Packit 427e91
--
Packit 427e91
IO
Packit 427e91
Packit 427e91
Defines an input and an output register.
Packit 427e91
Packit 427e91
<symbol> IO
Packit 427e91
Packit 427e91
It defines two register, but they both use the symbol. The assembler handles it automagically
Packit 427e91
depending on whether you're performing a read (X, Y or Z operand) or a write (R operand) to the GPR.
Packit 427e91
Packit 427e91
-
Packit 427e91
If you insist on having two different symbols for read/write (for readability or whatever), use an EQU, 
Packit 427e91
Packit 427e91
i.e.:
Packit 427e91
Packit 427e91
IN   IO
Packit 427e91
OUT  EQU  IN
Packit 427e91
Packit 427e91
-
Packit 427e91
To force a read from the output (for whatever reason) use <symbol>.o (i.e. OUT.o)
Packit 427e91
Packit 427e91
Writing to an input is not allowed.
Packit 427e91
--
Packit 427e91
CONSTANT
Packit 427e91
Packit 427e91
defines a read-only constant GPR
Packit 427e91
Packit 427e91
When the assembler encounters a CONSTANT define, it'll try three things. First 
Packit 427e91
it'll check to see if the defined constant is a hardware constant, if so 
Packit 427e91
substitutes that instead. Next the assembler check to see if another constant 
Packit 427e91
has alrady been declared with the same value, if so it'll substitute it. Else
Packit 427e91
it'll declare a new GPR for holding the value of the constant.  
Packit 427e91
Packit 427e91
syntax:
Packit 427e91
Packit 427e91
<symbol> constant  <value>
Packit 427e91
Packit 427e91
or
Packit 427e91
Packit 427e91
<symbol> con  <value>
Packit 427e91
Packit 427e91
Packit 427e91
--
Packit 427e91
Packit 427e91
DELAY LINES
Packit 427e91
Packit 427e91
Delay lines are defined via three directives:
Packit 427e91
Packit 427e91
--
Packit 427e91
DELAY Directive	
Packit 427e91
Packit 427e91
Define Delay, used for allocating an amount of TRAM for a delay line.
Packit 427e91
Packit 427e91
<symbol>  DELAY  <value>
Packit 427e91
Packit 427e91
The symbol is used to identify this delay line.The value is the amount of TRAM 
Packit 427e91
allocated, it may be specified as a decimal,hex, octal, binary or time value. 
Packit 427e91
Packit 427e91
The time value is prefixed with '&' and represents seconds of time.
Packit 427e91
Packit 427e91
e.g.
Packit 427e91
Packit 427e91
foo DELAY &100e-3  ;;a 100msec delay line
Packit 427e91
bar DELAY 1000	;;a 1000 sample delay line
Packit 427e91
Packit 427e91
--
Packit 427e91
TABLE directive
Packit 427e91
Packit 427e91
Define lookup Table
Packit 427e91
Packit 427e91
same as DELAY but for lookup tables. 
Packit 427e91
Packit 427e91
--
Packit 427e91
TREAD Directive
Packit 427e91
Packit 427e91
Define read: used for defining a TRAM read point
Packit 427e91
Packit 427e91
<symbol1>  TREAD <symbol2>,<value>
Packit 427e91
Packit 427e91
The value represents the read point within the delay line. symbol2 defines 
Packit 427e91
which delay line this read belongs to.
Packit 427e91
Packit 427e91
Symbol1 is a pointer to TRAM data register associated with this TRAM read 
Packit 427e91
operation. The assembler will create <symbol1>.a which points to the TRAM
Packit 427e91
address register.
Packit 427e91
Packit 427e91
example:
Packit 427e91
Packit 427e91
fooread TREAD 100e-3,foo
Packit 427e91
	macs  fooread.a,one,two,three   ; writes a new tram read address 
Packit 427e91
	macs  temp,fooread,one,two	; reads the data from the delay line 
Packit 427e91
Packit 427e91
--
Packit 427e91
WRITE Direcive
Packit 427e91
Packit 427e91
Define write: same as TREAD but used for writing data to a delay line.
Packit 427e91
<symbol1>  TWRITE <symbol2>,<value>
Packit 427e91
Packit 427e91
--
Packit 427e91
EQU directive:
Packit 427e91
Packit 427e91
Equates a symbol to a be constant which is substituted at assembly time:
Packit 427e91
Packit 427e91
syntax:
Packit 427e91
Packit 427e91
<symbol> EQU <Value equated>
Packit 427e91
Packit 427e91
--
Packit 427e91
END directive
Packit 427e91
Packit 427e91
The END directive should be placed at the end of the assembly source file. If
Packit 427e91
the END directive is not found, a warning will be generated. All text located
Packit 427e91
after the END directive is ignored.
Packit 427e91
Packit 427e91
Syntax:
Packit 427e91
Packit 427e91
[symbol]  END
Packit 427e91
Packit 427e91
--
Packit 427e91
INCLUDE Directive
Packit 427e91
Packit 427e91
The include directive is used to include external asm files into the current 
Packit 427e91
asm file.
Packit 427e91
Packit 427e91
Syntax:
Packit 427e91
Packit 427e91
	INCLUDE <"file name">
Packit 427e91
Packit 427e91
The file name Must be enclosed in "" or '' .
Packit 427e91
Packit 427e91
examples:
Packit 427e91
Packit 427e91
	include 'qwerty.asm'
Packit 427e91
	include "foobar.asm"
Packit 427e91
	
Packit 427e91
Packit 427e91
--	
Packit 427e91
Packit 427e91
MACRO directive 
Packit 427e91
Packit 427e91
Used for defining a macro
Packit 427e91
Packit 427e91
Defining Macro:
Packit 427e91
Packit 427e91
<symbol> macro arg1,arg2,arg3....
Packit 427e91
	....
Packit 427e91
	<opcode>  arg4,arg1,arg2...  ;;for example
Packit 427e91
	....	
Packit 427e91
	....
Packit 427e91
	endm
Packit 427e91
Packit 427e91
were the <symbol> used is the nmeumonic representing the macro. 
Packit 427e91
Packit 427e91
arg1,arg2,arg3... can be any symbols (auto-defining and local to a macro)
Packit 427e91
as long as the symbol is not already in use outside the macro (i.e. as 
Packit 427e91
a DC, DS, etc.).
Packit 427e91
Packit 427e91
There's no limit to how many arguments can be used.
Packit 427e91
Packit 427e91
Packit 427e91
Using Macro:
Packit 427e91
Packit 427e91
	<macro nmeumonic> arg1,arg2,arg3....
Packit 427e91
Packit 427e91
where arg1,arg2,arg3,... are values or symbols.
Packit 427e91
Packit 427e91
--
Packit 427e91
Assembly-time For loop
Packit 427e91
Packit 427e91
Packit 427e91
usage:
Packit 427e91
Packit 427e91
	For <symbol>=<start>:<stop>
Packit 427e91
		...
Packit 427e91
		...
Packit 427e91
		macs <symbol>,....
Packit 427e91
		...
Packit 427e91
	endfor
Packit 427e91
	
Packit 427e91
<start> and <stop> must be integers
Packit 427e91
Packit 427e91
Packit 427e91
--
Packit 427e91
Handling Skips
Packit 427e91
Packit 427e91
the as10k1 assembler handles skips in a special way explained best by an example:
Packit 427e91
Packit 427e91
	skip CRR,CRR,CC_test,.foo
Packit 427e91
	...
Packit 427e91
	...
Packit 427e91
	...
Packit 427e91
.foo	...
Packit 427e91
Packit 427e91
the "." tell the assembler that the symbol is for skipping purposes, it will
Packit 427e91
automatically define a GPR when parsing the skip instruction, and when the second
Packit 427e91
.foo is encountered it will insert the number of instructions to skip. (the skip
Packit 427e91
instruction needs a GPR by design, so don't blame me for the half-assness of it). 
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
Features NOT YET Supported
Packit 427e91
==========================
Packit 427e91
Packit 427e91
any ideas?
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91
Packit 427e91