Date : Wed, 27 Jul 1994 11:06:33 EST
From : Stephen Quan <quan@...>
Subject: JB's macros!
In another thread, JB writes :
> In my emulator I use:
>
> #define STA(mode, len, time, func) \
> { \
> write##func(mode(), A); \
> inc_PC(len); \
> inc_time(time); \
> }
And I was just wondering, (actually I had thought of this before),
with C, you could use imbedded assebly. Keep the macro as it is
above, but you could have
#ifdef _386_
#define inc_PC(len) \
_asm add si,len
#endif
#ifdef _SPARC_
#define inc_PC(len) \
_asm add %o1,len,%o1
#endif
Then some of the problems such as 256-branch I have raised in other
threads could be implemented as follows :
/* 386 definitions */
#define Jmp(label) _asm jmp @label
#define Label(label) _asm @label:
#define Equw(label) _asm @label
#define Fetch_Instruction _asm mov al,[es:si] \
_asm inc si
#define Execute_Instruction _asm mov ah,00h \
_asm add ax,ax \
_asm mov di,ax \
_asm jmp word ptr acorn6502[di]
main()
{
Jmp(start_emulator)
Label(acorn6502)
Equw(opcode_0x00)
Equw(opcode_0x01)
Equw(opcode_0x02)
Label(start_emulator)
Label(main_loop)
Fetch_Instruction
Execute_Instruction
Label(opcode_x00)
/* ... */
Jmp(main_loop)
Label(opcode_x01)
/* ... */
Jmp(main_loop)
/* ... */
}
Unfortunately, my Borland C++ compiler mangles the labels so that when
I tried this idea it failed miserably. All macros work except for
the one with Equw(), but I am sure this idea will work on UNIX and
perhaps other platforms, so it is possible to write portable assembly
code. The only requirement is that you have to write the macros for
every platform you port to.
--
Stephen Quan (quan@... ), SysAdmin, Analyst/Programmer.
Centre for Spatial Information Studies, University of Tasmania, Hobart.
GPO BOX 252C, Australia, 7001. Local Tel: (002) 202898 Fax: (002) 240282
International Callers use +6102 instead of (002).