Re: [Tuxnes-devel] more help w/ asm
Brought to you by:
tmmm
|
From: Jim U. <ji...@3e...> - 2001-04-12 20:05:27
|
At 10:28am on 2001 April 12, Rigel did write:
> heads up here. I don't understand the implementation in table.x86. So
> on all these listed instructions I set carry flag if there was a carrry
> (and clear it otherwise)?
Yes. What trouble are you having with the implementation?
When carry is set, ebp is -1. When carry is clear, ebp is 0.
For instructions which may carry, the sequence is:
addl -1, %ebp # set i386 carry if %ebp was set
<instruction which may carry> # set i386 carry according to 6502 instruction
sbbl %ebp, %ebp # set %ebp to -1 on carry, else clear
Like I said, check out SEC, CLC and ROR - Accumulator, these are the
simplest examples.
> Yes I am trying to port the sucker to mips. Wouldn't it be best though,
> to write the linkage (x86.S) in C?
There are a few things x86.S does:
1) acts as a call gate between asm and C -- e.g. most of the memory mappers.
This needs to stay in assembly by definition.
2) Brings the global CLOCK, CPF, CTNI, etc. variables back in sync with the
in-register versions -- e.g. in the INPUT:, OUTPUT:, NMI: routines, and in
a couple mappers (mmc1, mmc3, aorom to be specific).
3) Distinguishes between IRQ and NMI in routine NMI:. Then it sets up the
6502 for interrupt (push return address, php, setup flags).
4) Handles self-modifying code. Also must stay in assembly.
You can rewrite 2) and 3) in high-level code.
** SPOILERS AHEAD ;) **
For example, the OUTPUT: routine looks like this in C:
void output_shim(int addr, int val)
{
int cesi = ESI;
cesi = cesi - CTNI + CLOCK;
CTNI = ESI;
if (cesi - CPF >= 0) { cesi -= CPF; }
CLOCK = cesi;
output(addr,val);
ESI = CTNI;
}
NMI: has extra logic to handle 3)--specifically, the distinguishing between
IRQ and NMI. Interpreter cores should implement the 6502 interrupt setup
themselves, so this can be ignored.
This is required for a C-based core. However, there's no reason to rewrite
these in C if you're using an assembly language core, since the linkage
needs to stay anyway.
--
"But if food is so good for you, how come the body
keeps trying to get rid of it?" -- breatharian.com
ji...@3e... / 0x43340710 / 517B C658 D2CB 260D 3E1F 5ED1 6DB3 FBB9 4334 0710
|