6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Thu Nov 21, 2024 9:01 pm

All times are UTC




Post new topic Reply to topic  [ 213 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8 ... 15  Next
Author Message
 Post subject: Re: Breaking 6502 apart
PostPosted: Fri Jul 20, 2012 5:40 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
I decided to release sources of ALU and LOGIC :

http://ogamespec.com/6502/ALU.psd
http://ogamespec.com/6502/LOGIC.psd

Remember, this is still W.I.P.

_________________
6502 addict


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Mon Jul 23, 2012 2:20 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
Todays speccy: complete ALU transistor schematics

Enjoy! :D


Attachments:
ALU_trans.png
ALU_trans.png [ 970.5 KiB | Viewed 2105 times ]

_________________
6502 addict


Last edited by org on Fri Jul 27, 2012 8:28 am, edited 4 times in total.
Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Wed Jul 25, 2012 6:31 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8543
Location: Southern California
GARTHWILSON wrote:
Dieter has updates coming too.

Mike just got them posted, at http://6502.org/users/dieter/index.htm . Thanks Mike!

_________________
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Thu Jul 26, 2012 10:10 am 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
Todays speccy: ALU logic (missing BCD correction).

Code:
// A/B INPUT

if ( NDB_ADD ) BI = ~DB;
if ( DB_ADD ) BI = DB;
if ( ADL_ADD ) BI = ADL;

if ( SB_ADD ) AI = SB;
if ( 0_ADD ) AI = 0;

// LOGIC (based on NAND/NOR)

NOR = ~(AI | BI);
NAND = ~(AI & BI);

if ( ORS ) ADD = NOR;
if ( ANDS ) ADD = NAND;
if ( SRS ) ADD = NAND >> 1;        // next bit feed previous result

if ( EORS ) {
    nEOR[0,2,4,6] = ~ (~NOR & NAND)
    EOR[1,3,5,7] = ~ (~NAND | NOR)
    ADD[0,2,4,6] = nEOR[0,2,4,6]
    ADD[1,3,5,7] = ~EOR[1,3,5,7]
}

// ARITHMETIC
// BCD correction run-flow : DAA -> ALU -> ADD -> DSA -> SB -> AC.

// DECIMAL ADDER ADJUST (detect decimal carry and halfcarry)
// ...

// input carry driver I_ADDC comes in inverted form

// carry chain
carry_out = I_ADDC;

// bits 0,2,4,6
carry_in = carry_out;
carry_out = ~(NAND[0,2,3,6] & carry_in) & ~NOR[0,2,4,6];
SUM[0,2,4,6] = ~(nEOR[0,2,4,6] & ~carry_in) & (nEOR[0,2,4,6] | ~carry_in);

// bits 1,3,5,7
carry_in = carry_out;
carry_out = ~(~NOR[1,3,5,7] & carry_in) & NAND[1,3,5,7];
SUM[1,3,5,7] = ~(EOR[1,3,5,7] & ~carry_in) & (EOR[1,3,5,7] | ~carry_in);

// trans-level implementation of summator see in ALU_sum.png

// overflow test
carry6_out = carry_in;
if ( PHI2 ) AVR_Latch = ~(NOR7 & carry6_out) & (NAND7 | carry6_out);
AVR = AVR_Latch;

if ( SUMS) ADD = SUM;

// High-level implementation :
// s = AI + BI + ~I_ADDC;
// SUM = ~ ( s & 0xFF );
// carry_out = s >> 8;

// ADDER HOLD (register holds data in inverted logic)

if ( ADD_ADL ) ADL = ~ADD;
if ( ADD_SB06 ) SB = (SB & 0x80) | (~ADD & 0x7F);
if ( ADD_SB7 ) SB = (SB & 0x7F) | (~ADD & 0x80);

// DECIMAL SBUS ADJUST (affects SBus lines)
// ...

// ACCUMULATOR

if ( SB_DB ) DB = SB;
if ( SB_AC ) AC = SB;
if ( AC_SB ) SB = AC;
if ( AC_DB ) DB = AC;

if ( 0_ADH0 ) ADH &= ~0x01;
if ( 0_ADH17 ) ADH &= 0x01;


DSA is actually "DECIMAL SBUS ADJUST", not "DECIMAL SUBTRACT ADJUST".
DSA is applied before loading accumulator (AC), after BCD correction.

EDIT: important condition:
Code:
if ( PHI2 )
{
    NDB_ADD = DB_ADD = ADL_ADD = 0_ADD = 0;
    SB_AC = AC_SB = AC_DB = 0;
    ADH = 0;
}


Attachments:
ALU_sum.png
ALU_sum.png [ 24.52 KiB | Viewed 2106 times ]
ALU_overflow.png
ALU_overflow.png [ 8.44 KiB | Viewed 2143 times ]

_________________
6502 addict


Last edited by org on Fri Jul 27, 2012 8:53 am, edited 10 times in total.
Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Fri Jul 27, 2012 6:41 am 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
Previous post need some corrections... I'm writing test program ATM, errors will be fixed later.

EDIT: fixed ALU SUM errors and wrote test program:

Code:
#include <stdio.h>

int nand (int a, int b, int bit )
{
    int bit_a = (a >> bit) & 1;
    int bit_b = (b >> bit) & 1;
    return (~ (bit_a & bit_b)) & 1;
}

int nor (int a, int b, int bit )
{
    int bit_a = (a >> bit) & 1;
    int bit_b = (b >> bit) & 1;
    return (~ (bit_a | bit_b)) & 1;
}

int noteor (int a, int b, int bit )
{
    return ~ (~nor(a,b,bit) & nand(a,b,bit));
}

int eor (int a, int b, int bit )
{
    return ~ (~nand(a,b,bit) | nor(a,b,bit));
}

int alusum ( int a, int b, int carry_in, int *carry, int numbits )
{
    int bit;
    int carry_out = ~carry_in;
    int sum = 0, s;

    for (bit=0; bit<numbits; bit++)
    {
        if ( bit & 1 ) {
            carry_in = carry_out & 1;
            carry_out = ~(~nor(a,b,bit) & carry_in) & nand(a,b,bit);
            s = ~(eor(a,b,bit) & ~carry_in) & (eor(a,b,bit) | ~carry_in);
        }
        else {
            carry_in = carry_out & 1;
            carry_out = ~(nand(a,b,bit) & carry_in) & ~nor(a,b,bit);
            s = ~(noteor(a,b,bit) & ~carry_in) & (noteor(a,b,bit) | ~carry_in);
        }
        //printf ( "%i: %i %i %i %i %i\n", bit, (a >> bit) & 1, (b >> bit) & 1, s & 1, carry_in & 1, carry_out & 1);
        sum |= (s & 1) << bit;
    }

    *carry = ~carry_out & 1;
    return ~sum & ((1 << numbits) - 1);
}

void logic_test ( int a, int b )
{
    int bit;
    for (bit=0; bit<8; bit++)
    {
        printf ( "NAND=%i ", nand(a, b, bit) );
        printf ( "NOR=%i ", nor(a, b, bit) );
        printf ( "EOR=%i \n", eor(a, b, bit) );
        printf ( "!EOR=%i \n", noteor(a, b, bit) );
    }
}

main ()
{
    int a, b, sum, carry;

    //logic_test ( 0x35, 0x53 );

    printf ( "6502 ALU test.\n" );
    printf ( " A  B  S C\n" );

    for ( a=0; a<256; a++ )
    {
        for (b=0; b<256; b++)
        {
            sum = alusum ( a, b, 0, &carry, 8 );
            printf ( "%02X %02X %02X %01X\n", a, b, sum, carry );
        }
    }

}


Now everything is correct.

Code:
6502 ALU test.
 A  B  S C
03 F9 FC 0
03 FA FD 0
03 FB FE 0
03 FC FF 0
03 FD 00 1
03 FE 01 1
03 FF 02 1
04 00 04 0
04 01 05 0


BCD correction is next.

_________________
6502 addict


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Fri Jul 27, 2012 12:25 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
DAA

I disentangled decimal carry lookahead logic, driven by DAA:

Code:
carry0_out = ~(NAND0 & I_ADDC) & ~NOR0;
A = ~( ~(~NAND1 & carry0_out) | NOR2 );
B = ~(EOR3 | ~NAND2);
C = ~(EOR1 | ~NAND1) & ~carry0_out & (~NAND2 | NOR2);
DecimalHalfCarry = A & (B | C) & ~DAA;
(Decimal Half Carry is low when DAA driver is high)

A = ~ (~(~NAND5 & carry4_out) | EOR6);
B = ~(~NAND6 | EOR7);
C = ~(~NAND5 | XOR5) & ~(carry4_out | ~EOR6);
DecimalCarry = A & (B | C) & ~DAA;
(DecimalCarry is low when DAA driver is high)

Human-readable explanation:

Decimal HalfCarry is set, when AI and BI are in following combinations:
| AI | BI |
|----|----|
| X3 | X7 |
| X7 | X3 |
| XF | XB |
| XB | XF |

Decimal Carry is set, when AI and BI are in following combinations:
| AI | BI |
|----|----|
| 2X | 3X |
| 3X | 2X |
| 3X | 3X |
| AX | BX |
| BX | AX |
| BX | BX |

X - mean any number 0-F.


Can someone explain why it use such combinations ? :)

ALU Carry out route

Code:
// Carry out.
if (PHI2 ) DAA_Latch = ~DAA
CarryOut = ~(DecimalCarry | ~carry7_out)
DSA_CarryOut = ~(CarryOut | ~DAA_Latch)
ACR = ~CarryOut;    // to random logic


ALU Carry out is combination of bit7 carry out and high-nibble DecimalCarry.
ALU carry out later outputs to ACR line and also feeds by DSA (controlled by DAA latch).

Decimal half carry has affect only on bit3 of carry-out chain :
Code:
// bits 1,3,5,7
carry_in = carry_out;
carry_out = ~(~NOR[1,3,5,7] & carry_in) & NAND[1,3,5,7];
if (bit == 3 && DecimalHalfCarry) carry_out = 0;
SUM[1,3,5,7] = ~(EOR[1,3,5,7] & ~carry_in) & (EOR[1,3,5,7] | ~carry_in);

_________________
6502 addict


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Mon Aug 06, 2012 7:55 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
For the equations, you could check the patent which is linked from this post
viewtopic.php?p=8859#p8859

You might find some of the info on the visual6502 wiki useful too
http://visual6502.org/wiki/index.php?ti ... ecimalMode

Cheers
Ed


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Tue Aug 07, 2012 8:15 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
Cool stuff :) You saved some time to me again :D
Is this patent still valid ? Can I use it in software simulation ? :)

_________________
6502 addict


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Tue Aug 07, 2012 8:22 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
It's a 1976 grant date, so it must be expired now - 20 years is the term.


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Wed Aug 22, 2012 9:27 am 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
A bit cleaned ALU.

I'm ready to write its C simulator. Stay tuned ;)


Attachments:
ALU_trans.png
ALU_trans.png [ 963.14 KiB | Viewed 1953 times ]

_________________
6502 addict
Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Thu Aug 23, 2012 12:38 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
I started my project on Google Code :

http://code.google.com/p/breaks/source/ ... ks6502/SRC

_________________
6502 addict


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Thu Aug 23, 2012 12:44 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
Excellent, thanks for sharing: starred and RSS-subscribed.
(As ever, it would be great if you'd paste in a BSD or GPL license)
Cheers
Ed


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Thu Aug 23, 2012 1:07 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
This is "Other license". This mean its absolutely free to use, without any exceptions.

_________________
6502 addict


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Thu Aug 23, 2012 1:29 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10985
Location: England
That's great: in that case CC0 would be ideal - it only takes a sentence. (You have copyright as soon as you create it, and you can't really lose it - you need to license your work somehow if you want grant access to others, even if your intent is to impose no restrictions)
Cheers
Ed
http://creativecommons.org/choose/zero/
http://paulmillr.com/posts/simple-descr ... -licenses/

"To the extent possible under law, the person who associated CC0 with this work has waived all copyright and related or neighboring rights to this work."


Top
 Profile  
Reply with quote  
 Post subject: Re: Breaking 6502 apart
PostPosted: Thu Aug 23, 2012 2:00 pm 
Offline
User avatar

Joined: Fri Jun 22, 2012 7:39 am
Posts: 201
I really dont care )

_________________
6502 addict


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 213 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6, 7, 8 ... 15  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron