6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Nov 22, 2024 10:18 pm

All times are UTC




Post new topic Reply to topic  [ 609 posts ]  Go to page Previous  1 ... 22, 23, 24, 25, 26, 27, 28 ... 41  Next
Author Message
PostPosted: Tue Mar 26, 2013 5:20 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
I know it may look strange, but thanks for checking it out... :)

I use the C accumulator strictly to hold the background color. So that is STCiy (translate: STC ($xxxx),y. i.e. STore C accumulator indirect indexed y)
and I use the B accumulator strictly for the pixel color. My comments are very lacking I see now.

EDIT: Also whenever I use a macro, there's a '-' in the comment section. I use that to help myself remember what the code should really look like, in spite of the macro.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 27, 2013 7:21 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Today I had some other things to do but I was able to finish typing in Daryl's Bresenham Circle program and try it out. First thing I did was comment out anything that had to do with the 6502's MSBs for all the variables, since we're dealing with 16-bit bytes. I'll paste the code. Uh, I just now realized now I could have copied/pasted his code into the assembler. :oops:
Code:
CIRCLE            LDA RA            ;BRESENHAM CIRCLE COURTESY OF DARYL RICTOR @ HTTP://SBC.RICTOR.ORG/
                  BNE _C1
                  LDA XC
                  STA XP
                  ;LDA XC+1
                  ;STA XP+1
                  LDA YC
                  STA YP
                  ;LDA YC+1
                  ;STA YP+1
                  JMP PLTPXL

; INT Y = RADIUS                 
_C1               LDA RA        ;8 BIT RADIUS, CAN BE EXPANDED TO 16 BIT
                  STA Y1
                  LDDi $0000    ;-LDD #$0000 ACCUMULATOR IS USED FOR 65C02 STZ, AND IS ALWAYS ZERO IN THIS SUBROUTINE
                  ;STA Y1+1
                 
; INT X = 0
                  STDzp X1      ;-STD X1
                  ;STDzp X1+1    ;-STD X1+1
                 
; INT F = 1 - RADIUS     IF USING 16-BIT RADIUS, THIS SECTION
                  SEC   ;WILL NEED MODIFICATION
                  LDA #$01
                  SBC RA
                  STA FF
                  ;STDzp FF+1      ;-STD FF+1
                  ;BCS _C2
                  ;DEC FF+1
                 
; int ddF_X = 1;
_C2               LDA #$01
                  STA FX
                  ;STDzp FX+1      ;-STD FX+1
                 
; INT ddF_Y = -2 * RADIUS        IF USING 16-BIT RADIUS, THIS CODE SECTION
                  ;STDzp FY+1    ;WILL NEED MODIFICATION ALSO
                  LDA RA
                  ASL
                  STA FY
                  ;ROL FY+1
                  LDA FY
                  EOR #$FFFF      ;WAS EOR #$00FF
                  STA FY
                  ;LDA FY+1
                  ;EOR #$FF
                  ;STA FY+1
                  INC FY
                  BNE _C3
                  ;INC FY+1
               
; TGI_SETPIXEL(XC, YC+Y)
_C3               LDA XC
                  STA XP
                  ;LDA XC+1
                  ;STA XP+1
                  CLC
                  LDA YC
                  ADC Y1
                  STA YP
                  ;LDA YC+1
                  ;ADC Y1+1
                  ;STA YP+1
                  JSR PLTPXL
           
; TGI_SETPIXEL(XC, YC-Y)
                  SEC
                  LDA YC
                  SBC Y1
                  STA YP
                  ;LDA YC+1
                  ;SBC Y1+1
                  ;STA YP+1
                  JSR PLTPXL
                 
; TGI_SETPIXEL(XC+Y, YC)
                  CLC
                  LDA XC
                  ADC Y1
                  STA XP
                  ;LDA XC+1
                  ;ADC Y1+1
                  ;STA XP+1
                  LDA YC
                  STA YP
                  ;LDA YC+1
                  ;STA YP+1
                  JSR PLTPXL
                 
; TGI_SETPIXEL(XC-Y,YC)
                  SEC
                  LDA XC
                  SBC Y1
                  STA XP
                  ;LDA XC+1
                  ;SBC Y1+1
                  ;STA XP+1
                  JSR PLTPXL
                 
_CLOOP
; WHILE (X<Y) CALCULATE NEXT PLOT STEP
                  SEC
                  LDA X1
                  SBC Y1
                  ;LDA X1+1
                  ;SBC Y1+1
                  BCC _C4       ;X<Y
                  RTS
                 
_C4               ;LDA FF+1
                  ;BMI _C6
                 
                  ;LDA Y1
                  ;BNE _C5
                  ;DEC Y1+1
_C5               DEC Y1
                  CLC
                  LDA FY
                  ADC #$02
                  STA FY
                  ;TAX
                  ;LDA FY+1
                  ;ADC #$00
                  ;STA FY+1
                  ;TAY
                  CLC
                  ;TXA
                  ADC FF
                  STA FF
                  ;TYA
                  ;ADC FF+1
                  ;STA FF+1
                 
_C6               INC X1
                  ;BNE _C7
                  ;INC X1+1
_C7               CLC
                  LDA FX
                  ADC #$02
                  STA FX
                  ;TAX
                  ;LDA FX+1
                  ;ADC #$00
                  ;STA FX+1
                  ;TAY
                  CLC
                  ;TXA
                  ADC FF
                  STA FF
                  ;TYA
                  ;ADC FF+1
                  ;STA FF+1     ;COMPUTATIONS DONE - NOW PLOT 8 OCTANTS
                 
; TGI_SETPIXEL(XC+X, YC+Y)
                  CLC
                  LDA XC
                  ADC X1
                  STA XP
                  PHA
                  ;LDA XC+1
                  ;ADC X1+1
                  ;STA XP+1
                  ;PHA
                  CLC
                  LDA YC
                  ADC Y1
                  STA YP
                  ;LDA YC+1
                  ;ADC Y1+1
                  ;STA YP+1
                  JSR PLTPXL
                 
; TGI_SETPIXEL(XC-X, YC+Y)
                  SEC
                  LDA XC
                  SBC X1
                  STA XP
                  ;LDA XC+1
                  ;SBC X1+1
                  ;STA XP+1
                  JSR PLTPXL
                 
; TGI_SETPIXEL(XC-X, YC-Y)
                  SEC
                  LDA YC
                  SBC Y1
                  STA YP
                  ;LDA YC+1
                  ;SBC Y1+1
                  ;STA YP+1
                  JSR PLTPXL
                 
; TGI_SETPIXEL(XC+X, YC-Y)
                  ;PLA
                  ;STA XP+1
                  PLA
                  STA XP
                  JSR PLTPXL
                 
; TGI_SETPIXEL(XC+Y, YC+X)
                  CLC
                  LDA XC
                  ADC Y1
                  STA XP
                  PHA
                  ;LDA XC+1
                  ;ADC Y1+1
                  ;STA XP+1
                  ;PHA
                  CLC
                  LDA YC
                  ADC X1
                  STA YP
                  ;LDA YC+1
                  ;ADC X1+1
                  ;STA YP+1
                  JSR PLTPXL
                 
; TGI_SETPIXEL(XC-Y,YC+X)
                  SEC
                  LDA XC
                  SBC Y1
                  STA XP
                  ;LDA XC+1
                  ;SBC Y1+1
                  ;STA XP+1
                  JSR PLTPXL
                 
; TGI_SETPIXEL(XC-Y, YC-X)
                  SEC
                  LDA YC
                  SBC X1
                  STA YP
                  ;LDA YC+1
                  ;SBC X1+1
                  ;STA YP+1
                  JSR PLTPXL
                 
; TGI_SETPIXEL(XC+X,YC-Y)
                  ;PLA
                  ;STA XP+1
                  PLA
                  STA XP
                  JSR PLTPXL
                  JMP _CLOOP
                 
PLTPXL            LDA XP
                  STA SCRLO
                  LDA YP
                  STA SCRHI
                  LDY #0
                  STBiy (SCRLO),Y      ;-STB(SCRLO),Y. B ACCUMULATOR IS ALWAYS PIXEL COLOR
                  RTS


Mild success. The radius is set to 10, and the XC and YC are (100,100).


Attachments:
P1000969.JPG
P1000969.JPG [ 234.94 KiB | Viewed 1363 times ]

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502
Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 28, 2013 1:55 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
Looks like you got to the start of the loop (0,90,180,270 deg points got plotted correctly). It's a start!

Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 29, 2013 1:56 am 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
8BIT wrote:
Looks like you got to the start of the loop (0,90,180,270 deg points got plotted correctly). It's a start!

Daryl

I had nothing at first. Then 1 pixel, then 2. Then 4, which is when I posted...
I'm running through your code now using ISim, and skipping all the real world stuff like clear screen and character plotting for the timer.
Hopefully I can do this one step at a time and post. It's a dual step here where I have to understand what's going on in your program, then convert to 65O16. I guess I can consider ISim my real world emulator. I will make more progress soon. :D

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 29, 2013 2:18 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
I took a quick look but will need more time to study the changes. I think there is some decision making code here that needs to be addressed. Will work on it over the weekend.

Code:
_C4               ;LDA FF+1
                  ;BMI _C6
                 
                  ;LDA Y1
                  ;BNE _C5
                  ;DEC Y1+1


Daryl

_________________
Please visit my website -> https://sbc.rictor.org/


Top
 Profile  
Reply with quote  
PostPosted: Fri Mar 29, 2013 10:32 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Thanks for taking some of your time out to do that, I appreciate it!

The few minutes I have after a long day at work don't seem to be very fruitful. Chances are progress won't be made on my end til tue or wed.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 30, 2013 9:19 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1748
Location: Sacramento, CA
ok, I think this will work. I removed the commented-out lines for clarify. Let me know how this works.

Daryl


Attachments:
circ16.asm [4.52 KiB]
Downloaded 76 times

_________________
Please visit my website -> https://sbc.rictor.org/
Top
 Profile  
Reply with quote  
PostPosted: Sat Mar 30, 2013 11:19 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Ah, I see you've totally redone _C4. Was just checking. Trying now...

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 31, 2013 12:01 am 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
No change in the graphics, however, the timer now reads at 0.00000304 which is .1uS faster. Not sure if this makes sense. Too much going on in the next few days... ^^^ Check PM.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 31, 2013 2:53 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Forgot I had Easter Sunday off, heh.

With a clear mind and using ISim, I was able to track down where it is exiting:
Code:
_CLOOP
; WHILE (X<Y) CALCULATE NEXT PLOT STEP
                  SEC
                  LDA X1
                  SBC Y1
                  BCC _C4       ;X<Y
                  RTS

The carry is set with X1=0, and Y1=RA=10, so it is not branching.

EDIT: Looks like another problem with the .b core. Changing the BCC to a BCS plots the circle, then continues off into infinity. The SBC is not resetting the Carry flag. I'll check this out next.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 31, 2013 4:50 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Looking again at the ALU the case where A-B. Considering if A=$0000 and B was $FFFF, then value of temp_BI was just be $0000 and temp would be $0000 or $0001 depending on the CarryIn. I think temp_BI needs to be expanded to 17-bits, that would result in a value of $10000. Then modify the CarryOut to toggle the CarryIn if (temp_BI[16]) is set.
Code:
always @* begin
    case( op[3:2] )
        2'b00 : temp_BI = BI; // A+B
        2'b01 : temp_BI = ~BI; // A-B
        2'b10 : temp_BI = logical; // A+A
        2'b11 : temp_BI = 0; // A+0
    endcase
end

//always @(logical or temp_BI or adder_CI)
always @*
    temp = logical + temp_BI + adder_CI;
..........
// calculate the flags

always @(posedge clk)
    if( RDY ) begin
        ......
        ......
        ......
        CO <= (shiftrotate ? tempshifted[dw] : temp[dw]);
        ......
    end


I've expanded the temp_BI register and it looks good. Working on the Carry.

Sound logical?

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 31, 2013 5:24 pm 
Offline
User avatar

Joined: Tue Nov 16, 2010 8:00 am
Posts: 2353
Location: Gouda, The Netherlands
In the 8 bit core, the temp_BI signal is only 8 bits, but I don't think there's a problem with the carry. Not sure what the problem is.


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 31, 2013 5:41 pm 
Offline
User avatar

Joined: Mon Apr 23, 2012 12:28 am
Posts: 760
Location: Huntsville, AL
I generally capture the output carry for an adder in a vector that's one bit wider than the operands. I don't think that you need to increase the size of the input data, but simply expand the size of your output by one bit. The extra bit will be the carry out of the summer. The following code snippet is an example;

Code:
module Add(
    input   [15:0] A,    // Adder Input A
    input   [15:0] B,    // Adder Input B
    input   Ci,         // Adder Carry In
   
    output  [15:0] Sum,  // Adder Sum <= A + B + Ci
    output  Co          // Carry Out
);

assign {Co, Sum} = A + B + Ci;

endmodule

It results in the synthesis of a 16-bit adder with a carry input and a carry output. The carry output will be assigned to Co.
Quote:
========================================================================
Advanced HDL Synthesis Report

Macro Statistics
# Adders/Subtractors : 1
16-bit adder carry in/out : 1

========================================================================

_________________
Michael A.


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 31, 2013 5:49 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
Thank you both! I was going to ask Arlet the following, but I think I've found my problem, in the middle of posting, in the opcode decoding for the adc_sbc flag.


In your core, when it executes any opcode that sets the OP_SUB flag for the ALU.v to do a subtraction, in which the ALU would have to change the C flag going back into the cpu, I don't see how that CO signal works it way back into the cpu.v for the OP_SUB opcodes.
Code:
/*
 * Update C flag when doing ADC/SBC, shift/rotate, compare
 */
always @(posedge clk )
    if( shift && state == WRITE )
   C <= CO;
    else if( state == RTI2 )
       C <= DIMUX[0];
    else if( ~write_back && state == DECODE ) begin
   if( adc_sbc | shift | compare )
       C <= CO;
   else if( plp )
       C <= ADD[0];
   else begin
       if( sec ) C <= 1;
       if( clc ) C <= 0;
   end
    end
The adc_sbc is for the addition opcodes

EDIT: In comparing the 2 cores, I think I just saw my error. One I think I've had from the very beginning of tinkering with Verilog and your core. I had misunderstood your adc_sbc flag to be set for only the ADC opcodes, which I always thought was strange. Which now I see it is strange, because it's wrong. :lol:

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 31, 2013 6:49 pm 
Offline

Joined: Mon Mar 02, 2009 7:27 pm
Posts: 3258
Location: NC, USA
It works!
I had to loose the random number generator so the project would fit, luckily the timer still fit after 15 runs of smartexplorer!

I timed a circle with radius 150 @.6mS. Very nice looking circle.

_________________
65Org16:https://github.com/ElEctric-EyE/verilog-6502


Last edited by ElEctric_EyE on Sun Mar 31, 2013 7:11 pm, edited 2 times in total.

Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 609 posts ]  Go to page Previous  1 ... 22, 23, 24, 25, 26, 27, 28 ... 41  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 13 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: