| 1 |
3 |
sinclairrf |
# Copyright 2014, Sinclair R.F., Inc.
|
| 2 |
|
|
|
| 3 |
|
|
def push16(ad):
|
| 4 |
|
|
"""
|
| 5 |
|
|
User-defined macro to push a 16 bit value onto the data stack so that the LSB
|
| 6 |
|
|
is deepest in the data stack and the MSB is at the top of the data stack.\n
|
| 7 |
|
|
Usage:
|
| 8 |
|
|
.push16(v)
|
| 9 |
|
|
where
|
| 10 |
|
|
v is a 16-bit value, a constant, or an evaluated expression\n
|
| 11 |
|
|
The effect is to push v%0x100 and int(v/2**8)%0x100 onto the data stack.\n
|
| 12 |
|
|
( - u_LSB u u u_MSB )
|
| 13 |
|
|
"""
|
| 14 |
|
|
|
| 15 |
|
|
# Add the macro to the list of recognized macros.
|
| 16 |
|
|
ad.AddMacro('.push16', 2, [ ['','singlevalue','symbol'] ]);
|
| 17 |
|
|
|
| 18 |
|
|
# Define the macro functionality.
|
| 19 |
|
|
def emitFunction(ad,fp,argument):
|
| 20 |
|
|
argument = argument[0];
|
| 21 |
|
|
if argument['type'] == 'value':
|
| 22 |
|
|
v = argument['value'];
|
| 23 |
|
|
elif argument['type'] == 'symbol':
|
| 24 |
|
|
name = argument['value'];
|
| 25 |
|
|
if not ad.IsSymbol(name):
|
| 26 |
|
|
raise asmDef.AsmException('Symbol "%s" not recognized at %s' % (argument['value'],argument['loc'],));
|
| 27 |
|
|
ix = ad.symbols['list'].index(name);
|
| 28 |
|
|
v = ad.symbols['body'][ix];
|
| 29 |
|
|
if len(v) != 1:
|
| 30 |
|
|
raise asmDef.AsmException('Argument can only be one value at %s' % argument['loc']);
|
| 31 |
|
|
v = v[0];
|
| 32 |
|
|
else:
|
| 33 |
|
|
raise asmDef.AsmException('Argument "%s" of type "%s" not recognized at %s' % (argument['value'],argument['type'],argument['loc'],));
|
| 34 |
|
|
if type(v) != int:
|
| 35 |
|
|
raise Exception('Program Bug -- value should be an "int"');
|
| 36 |
|
|
ad.EmitPush(fp,v%0x100,''); v >>= 8;
|
| 37 |
|
|
printValue = argument['value'] if type(argument['value']) == str else '0x%08X' % argument['value'];
|
| 38 |
|
|
ad.EmitPush(fp,v%0x100,'.push16(%s)' % printValue);
|
| 39 |
|
|
ad.EmitFunction['.push16'] = emitFunction;
|