OT: Altair32: C arrays and pointers

From: Richard A. Cini, Jr. <rcini_at_optonline.net>
Date: Sat May 19 19:26:56 2001

Hello, all:

        Futher errors have been found in the Altair32 8080 processor emulator code
by some eagle-eyed users. So, I'm trying to fix them, but my lack of depth
in C programming has become evident. So, I'd like to enlist some help again.

        Here's the code (cut and paste; written by Claus Giloi):

uchar regs[8] ; // A, F, B, C, D, E, H, L - actual storage order!
                        // 0 1 2 3 4 5 6 7

// pointer array for sss, ddd addressing
uchar * b_regs[8]=
{&regs[2],&regs[3],&regs[4],&regs[5],&regs[6],&regs[7],&dummy,&regs[0]} ;
// B C D E H L trap! ACC

// pointer array for rp addressing
ushort * w_regs[4] =
{ (ushort *)&regs[2], (ushort *)&regs[4], (ushort *)&regs[6], &SP } ;
// B D H SP


        As you 8080 users know, several instructions operate on register pairs
instead of individual registers. The instruction that began this odyssey was
INX H. The INX B/D/H instructions increment the BC, DE, HL pairs. INX SP
works. B/D/H don't. While the individual register halves reflect the proper
values, the word registers are reversed. I guess it's because when accessing
a word value in an array, the CRT code swaps the high-order and low-order
bytes.

        So, I used the following code, which produces the desired result but is
what I can only assume to be the sledgehammer way of doing what I want (lots
of snipping):

                                                        // u is the opcode and
                switch ((u&RP_MASK)>>4){ // RP_MASK isolates register pairs
                        case 2: //HL
                                tmpH = *pH ; // pointer to H storage
                                tmpL = tmpL2 = *pL ;
                                tmpL++;
                                if (((tmpL & 0xff) == 0) && (tmpL2 == 0xff)) tmpH++ ;
                                *pH = tmpH ; // save regs
                                *pL = tmpL ;
                                break ;
                        // other cases omitted.
                }

        What I do is manually manipulate the byte registers (watching for rollover)
to get the desired result, totally skipping the w_regs array. Bogus I admit,
but it works.

        I can only imagine that there is a better way to do this. So, I'm asking
for help finding the better way.

        Thanks again.

Rich

Rich Cini
Collector of classic computers
Build Master for the Altair32 Emulation Project
Web site: http://highgate.comm.sfu.ca/~rcini/classiccmp/
/************************************************************/
Received on Sat May 19 2001 - 19:26:56 BST

This archive was generated by hypermail 2.3.0 : Fri Oct 10 2014 - 23:34:09 BST