<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>
Date   : Tue, 26 Jul 1994 09:23:18 WET DST
From   : Bonfield James <jkb@...>
Subject: Re: Erk! I've got stuck again!

Stephen Quan writes:

>Chris Rae writes:
>
>> No sooner than I've started, I've come across an STA &FE30.
>
>Doesn't some hardware attach itself to these locations?

FE30 is a 4 bit latch used to determine the sideways RAM bank in use.

>I remember there were a few bytes up there that you set which gave
>you direct access to the user port and perhaps a few other things.

There's heaps! The user port ones are &FE60-&6F; this is a VIA (6522). The
system VIA is at &FE40. I suggest obtaining a copy of the new advanced user
guide which covers _most_ requirements reasonably.

>If you are doing it in C, you could do.
>
>      if ((signed short) address >= 0)
>        *address = newbyte;

In this example, all addresses >= 0x8000 are unwritable. However in real life
this isn't true. 0x8000-0xbfff are sideways rom/ram. This may or may not be
writable, depending on the machine configuration and the contents of the
latch. Also, as you mention, there's fred, jim and sheila to worry about. An
STA to, say &FE30, needs to trigger the correct piece of emulator to page in a
new ROM.

In my emulator I use:

#define STA(mode, len, time, func) \
{ \
    write##func(mode(), A); \
    inc_PC(len); \
    inc_time(time); \
}

This macro is used in a variety of 'case's in the switch - eg:

 case 0x85: /* STA aa */
    STA(zp, 2, 3, bq);
    break;

Here, the macro is expanded to:

writebq(zp(), A); inc_PC(2); inc_time(3);

writebq is a quick (ie no memory checks, which is appropriate for a zero page
write) memory write, as defined below:

#define writebq(addr, val) (mem[(addr)] = (val))

zp is yet another macro to handle the correct memory access for the zero page
adressing mode. The relevant bits are:

#ifdef ASSUME
#    define arg_byte readbq(PC+1)
#else
#    define arg_byte readb(PC+1)
#endif
#define zp()    (arg_byte)

So the entire "STA &xx" instruction will be expanded to something like (with
excess brackets removed):

mem[readbq(PC+1)] = A;
PC += 2;

Feel free to grab the code to (an out of date - sorry) version of the emulator
by ftp to al.mrc-lmb.cam.ac.uk, directory pub/jkb/beeb.

       James
<< Previous Message Main Index Next Message >>
<< Previous Message in Thread This Month Next Message in Thread >>