6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 5:46 am

All times are UTC




Post new topic Reply to topic  [ 298 posts ]  Go to page Previous  1 ... 8, 9, 10, 11, 12, 13, 14 ... 20  Next
Author Message
PostPosted: Wed Mar 11, 2020 6:23 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8507
Location: Midwestern USA
Proxy wrote:
not sure how i would do "clock stretching" with my current PCB, since the Clock sadly doesn't connect to one of the GAL's outputs.

Blue wire, my friend. Use enough of it and you can turn a VIC-20 into a DEC VAX. :D

I don't recall seeing a complete schematic for your unit, but I suspect the clock stretching thing wouldn't be all that difficult to set up. As I earlier said, I'm working on something for my POC V1.2 unit to test someone else's clock stretching theory.

Quote:
anyways, after fixing that i ran right into the next problem, when the CPU writes data into the FT240X i only receive 0xFF on the Terminal. checking with my logic probe the WE on the FT240X gets set to low while PH2 is High. and clearly it is writing something, otherwise it wouldn't send anything.

WR on the FT240X is an active high signal. :shock: Says so in the data sheet.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 11, 2020 6:31 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1488
Location: Scotland
Proxy wrote:
so i got the FT240X to work... basically i just turned the WR output from the GAL from Active-Low to Active-High and it works now.

except now i seem to have a logic error in my program and i cannot fiquire out why.

just to be sure i understand this correctly (i come from the Z80, so the 6502 is quite strange with some things for me)
the Overflow (V) flag i supposed to be set when some arithmetic instruction... well overflows.
so like adding 0x01 to the Accumulator when it contains 0xFF.
and when it doesn't overflow it gets cleared, right


Not quite like that.

For now, I'd suggest forgetting and ignoring the overflow flag. It's not quite what you think.

What you want to think about is the carry flag.

Add 1 to $FF and you get $00 with the carry set. (the 9th bit).

Then you can branch carry set or clear (BCS, BCC) without needing an explicit test.

And note about the explicit test - if you load A with 0 (or it, or any register or memory becomes zero) then the Z flag will be automatically set. That's the key thing to clever 6502 code - the condition flags are automatic based on the last result - Zero or Carry are the 2 you'll use most. So simply:

Code:
loop:
    LDA $1234,X
    BEQ done
    .. print A
    INX
    BRA loop
done:


Go back to the V (overflow) flag when you really want to do 2s compliment arithmetic.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 11, 2020 6:48 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8507
Location: Midwestern USA
Proxy wrote:
just to be sure i understand this correctly (i come from the Z80, so the 6502 is quite strange with some things for me)
the Overflow (V) flag i supposed to be set when some arithmetic instruction... well overflows.

Specifically, overflow occurs when signed arithmetic results in a "carry" from bit 6 to bit 7. In signed arithmetic, integers range from $00 to $7F in the positive direction, and $FF to $80 in the negative direction. Here's some contrived code to illustrate the principle:

Code:
         clv                   ;clear overflow
         clc                   ;clear carry
         lda #$7f              ;decimal 127
         adc #$01              ;decimal 1
         bvs signovr           ;branch if sign overflow <—— this branch will be taken
;
         bvc signok            ;branch if sign not overflowed
;
         bcs carry             ;etc...

Quote:
then i don't get why this code doesn't work, all i'm doing is using X as an index to a String, but once i increment X at the end (from 0 to 1) the V flag gets set for some reason. i know that because right afterwards is a conditional relative jump that i supposed to jump back to the start of the loop when the overflow is not set. and when it is set it completely restarts the function (ie all registers back to 0 and SP back to 0xFF)

I grabbed a snippet from my Arduino Logic Analyzer and split it into the sperate instructions with some comments.

Instructions are labeled with ">>>>" infront of them

Code:
This part just loads 0xFF into the SP.

>>>>LDX 0xFF
A: 0xE001;  D: 0xA2; RD;  HIGH
A: 0xE002;  D: 0xFF; RD;  HIGH

Two things:

  1. Hexadecimal values in standards-based 6502 assembly language are notated as $nn or $nnnn. 0xNN is C notation. Even x86 assembly language doesn't use that—it uses NNh to indicate hex.
  2. Immediate register loads are indicated to the assembler with # preceding the value to be loaded. Hence your first instruction would be written as LDX #$FF.

Quote:
Code:
>>>>TXS
A: 0xE003;  D: 0x9A; RD;  HIGH...
Compare A to 0x00 to see if the String is over

>>>>CMP 0x00
A: 0xE00B;  D: 0xC9; RD;  HIGH
A: 0xE00C;  D: 0x00; RD;  HIGH

Loading .A with $00 automatically sets Z, so the CMP #$00 is unnecessary.

Quote:
Code:
Increment X (the pointer into the String)

>>>>INX
A: 0xE01D;  D: 0xE8; RD;  HIGH

Check if X overflowed (overflew?), if it didn't go back to the "Main Loop"

>>>>BVC 0xE8 (0xE008)
A: 0xE01E;  D: 0x50; RD;  HIGH
A: 0xE01E;  D: 0x50; RD;  HIGH
A: 0xE01F;  D: 0xE8; RD;  HIGH

Incrementing or decrementing a register has no effect on the V flag. The only arithmetic instructions that affect it are ADC and SBC.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 11, 2020 7:11 pm 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
BigDumbDinosaur wrote:
Specifically, overflow occurs when signed arithmetic results in a "carry" from bit 6 to bit 7. In signed arithmetic, integers range from $00 to $7F in the positive direction, and $FF to $80 in the negative direction. Here's some contrived code to illustrate the principle:

Code:
         clv                   ;clear overflow
         clc                   ;clear carry
         lda #$7f              ;decimal 127
         adc #$01              ;decimal 1
         bvs signovr           ;branch if sign overflow <—— this branch will be taken
;
         bvc signok            ;branch if sign not overflowed
;
         bcs carry             ;etc...


oh so i used the wrong flag... well damn, i'm used to carry and overflow being interchangeable.

BigDumbDinosaur wrote:
Two things:

  1. Hexadecimal values in standards-based 6502 assembly language are notated as $nn or $nnnn. 0xNN is C notation. Even x86 assembly language doesn't use that—it uses NNh to indicate hex.
  2. Immediate register loads are indicated to the assembler with # preceding the value to be loaded. Hence your first instruction would be written as LDX #$FF.


yea sorry, i'm used to that because that's what my assembler uses. (it's a good assembler (constants, global and local labels, #include so you can split your program into multiple files, etc), i can post more details if anyone is interested)
so i'm also gonna keep using that because i like how clean it is.
"0x" for Hexadecimal, "0b" for Binary, and nothing for Decimal.
it's just so nice without the use of special characters that would require me to press SHIFT+something.

BigDumbDinosaur wrote:
Incrementing or decrementing a register has no effect on the V flag. The only arithmetic instructions that affect it are ADC and SBC.

ok good.

the program now works after changing the V flag to the C flag.
finally i got some code working. and it runs perfectly at 1MHz and even seems to work at 10MHz without a RDY Circuit! which is good news
and my poor terminal program can barely keep up with all the "Hello World!"s filling it.


I'm very thankful for the help i got here with my project. even if a lot of issues were caused by my own stupidity, but hey mistakes happen. and this will definitely not be the last project i'll post about on here. :)
now it's time to get a bit more into the programming, gonna do the basic functions first. stuff like reading a string from the FT240X, writing a string to it, etc.
that usually gets me used to a CPU/Syntax as i already know exactly how those functions are supposed to work. luckly it isn't my first time using assembly.


Top
 Profile  
Reply with quote  
PostPosted: Wed Mar 11, 2020 10:02 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8507
Location: Midwestern USA
Proxy wrote:
now it's time to get a bit more into the programming, gonna do the basic functions first. stuff like reading a string from the FT240X, writing a string to it, etc. that usually gets me used to a CPU/Syntax as i already know exactly how those functions are supposed to work. luckly it isn't my first time using assembly.

There are several books that can help you with learning the 6502 assembly language, foremost of which is Programming the 65816, Including the 6502, 65C02, and 65802 by David Eyes and Ron Lichty. That will help you get familiar with the 6502 "idiom." For example, since the 6502 family automatically sets and clears status register flags according to the most recent load, arithmetic or logical operation, succinct code can be written that exploits that feature, especially in loops, in which counting backward is common.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2020 5:05 am 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
BigDumbDinosaur wrote:
Proxy wrote:
now it's time to get a bit more into the programming, gonna do the basic functions first. stuff like reading a string from the FT240X, writing a string to it, etc. that usually gets me used to a CPU/Syntax as i already know exactly how those functions are supposed to work. luckly it isn't my first time using assembly.

There are several books that can help you with learning the 6502 assembly language, foremost of which is Programming the 65816, Including the 6502, 65C02, and 65802 by David Eyes and Ron Lichty. That will help you get familiar with the 6502 "idiom." For example, since the 6502 family automatically sets and clears status register flags according to the most recent load, arithmetic or logical operation, succinct code can be written that exploits that feature, especially in loops, in which counting backward is common.


yea the flags are really the only confusing part about the CPU (plus some other oddities). especially since non-arithmetic instructions can change them as well.
I've actually designed a custom CPU based on the 65C02, but i only looked at the instructions and basic functions, stuff like interrupts, and flags i did completely from scratch... so i never learned how those work in the original hardware.

luckly the NESdev.com provides a complete PDF of the book so i don't need to buy anything.

anyways i'll still want to do a second revision of the board to make some things better.
like having a power switch so i don't have to unplug the board to turn it off.
having a seperate Reset for the USB chip and the rest of the system. (so that resetting the system doesn't reset the USB connection, which otherwise gets annoying as it has to reconnect to the PC)
maybe replacing the GALs with a CPLD to save some space
I need to think about what else could be done. but those are some ideas i had.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2020 5:10 am 
Offline
User avatar

Joined: Sat Dec 01, 2018 1:53 pm
Posts: 730
Location: Tokyo, Japan
Regarding the flags: handling them well is, in my experience, core to how good your assembly code will be. I find obelisk's 6502 instruction set reference quite useful since it gives the details of exactly what flags are modified by each instruction, helping me to choose carefully what instructions I'm using based on what they set or don't set. But for quicker reference, I've also created a table of flags listing all the instructions that affect each one.

Proxy wrote:
so i'm also gonna keep using that because i like how clean it is.
"0x" for Hexadecimal, "0b" for Binary, and nothing for Decimal.
it's just so nice without the use of special characters that would require me to press SHIFT+something.

Well, certainly bikeshedding here, but I find using one character rather than two to be more clean. Either way, it's two keystrokes, one in the number row and one in the bottom row, so there doesn't seem to be any difference there.

_________________
Curt J. Sampson - github.com/0cjs


Last edited by cjs on Thu Mar 12, 2020 11:41 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2020 8:49 am 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
INC, INX, INY, DEC, DEX, DEY only affect the Z and N flags. This can be frustrating if you want to be clever with your loop termination conditions, but once you know the idioms it can actually be useful, since it allows you to preserve the Carry flag between iterations of a loop. In general, N and Z are affected by any instruction which changes A, X, Y or performs an operation directly on memory.

The only instructions which affect the V flag are: ADC, SBC, PLP, RTI, CLV - and the /SO signal input (there's no SEV instruction). It's the least-used flag on the 6502, only really useful for error handling during signed arithmetic, and when was the last time you saw a program which did that? (The C language doesn't make it easy.) Hence the secondary use as an external hardware input; /SO is normally tied high, hence unused.

Carry is used not only by ADC and SBC, but also by CMP and the shift and rotate instructions. It is preserved by loads, increments, decrements, and bitwise logical operations (other than shifts and rotates). Some routines also use it as an error flag on exit, as it's easy to set and test explicitly.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2020 8:57 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1488
Location: Scotland
cjs wrote:
Regarding the flags: handling them well is, in my experience, core to how good your assembly code will be. I find obelisk's 6502 instruction set reference quite useful since it gives the details of exactly what flags are modified by each instruction, helping me to choose carefully what instructions I'm using based on what they set or don't set. But for quicker reference, I've also created a [url=https://github.com/0cjs/sedoc/tree/master/ee/6502#program-status-register-p-flags}table of flags[/url] listing all the instructions that affect each one.

Proxy wrote:
so i'm also gonna keep using that because i like how clean it is.
"0x" for Hexadecimal, "0b" for Binary, and nothing for Decimal.
it's just so nice without the use of special characters that would require me to press SHIFT+something.

Well, certainly bikeshedding here, but I find using one character rather than two to be more clean. Either way, it's two keystrokes, one in the number row and one in the bottom row, so there doesn't seem to be any difference there.


Adaptability and flexibility is the key in my book, and, really, life's too short to point out (or worry about) minutia like 0x vs. $ vs nnH vs & vs. #x and whatever else might exist in the systems and languages we use.

For those not aware, while $ may well be the convention in the MOS world, but &num is the convention in Acorn/BBC Micro world.

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2020 9:18 am 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Agreed! Of course you have to use the conventions which your assembler uses, but we shouldn't find it any barrier that one person illustrates with &FA and another with $FA.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2020 3:26 pm 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
ok because noone asked i'm still gonan talk about the assembler i use, just because i feel like it deserves some praise. :D

I never really found a good 6502/65C02 assembler. the 6502.org's tool page isn't really that great for finding one, especially since it doesn't seem very updated (some sites on there don't exist anymore for example).

basically all assemblers listed are either mainly for some specific platform, cost money/require a key, run on very old Operating systems (ie DOS), or are bound to some specific emulator (which can be useful in cases)

so i opted for an Assembler i already knew... because i used for custom CPUs.
CustomASM
It supports global and local labels, bit slicing, constants, and probably more i can't think of right now. it has a full feature list on the Github.
it's a Universal Assembler, which means you need to define the instruction set and names of instructions yourself.
and that is exactly what i did for the 6502 and 65C02.

though technically i did 2 seperate CPU files for both the 6502 and 65C02.
CS (Classic Syntax), which is something like this:
Code:
LOOP:
   LDA STRING,X
   BEQ EXIT
   STA OUT
   INX
BCC LOOP
EXIT:
STP

ZS (Z80 Syntax), which is something like this: (and probably easier to remember than 3 letter acronyms, atleast for me)
Code:
LOOP:
   LD A, (STRING, X)
   JR Z EXIT
   LD (OUT), A
   INC X
JR NC LOOP
EXIT:
HALT


another great thing about it is that it doesn't come with some predefined IDE, you can use whatever Text Editor you want.
though i would REALLY recommend Notepad++, it's such an overall amazing text editor.
it even supports custom highlight, which is perfect for an Assembler.
example:

No Custom Highlighting:
Attachment:
notepad++_2020-03-12_16-22-59.png
notepad++_2020-03-12_16-22-59.png [ 54.45 KiB | Viewed 814 times ]

Custom Highlighting (made it myself to fit my dark background):
Attachment:
2020-03-12_16-23-08.png
2020-03-12_16-23-08.png [ 55.7 KiB | Viewed 814 times ]


overall CustomASM nice to use and probably a much better option than a lot of the existing ones, atleast for starters i think.
you literally just drag your ASM files onto the EXE and it assembles them, or you use the command line if you want some debugging info.


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2020 3:36 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1488
Location: Scotland
Proxy wrote:
ok because noone asked i'm still gonan talk about the assembler i use, just because i feel like it deserves some praise. :D

I never really found a good 6502/65C02 assembler. the 6502.org's tool page isn't really that great for finding one, especially since it doesn't seem very updated (some sites on there don't exist anymore for example).

basically all assemblers listed are either mainly for some specific platform, cost money/require a key, run on very old Operating systems (ie DOS), or are bound to some specific emulator (which can be useful in cases)

so i opted for an Assembler i already knew... because i used for custom CPUs.
CustomASM
It supports global and local labels, bit slicing, constants, and probably more i can't think of right now. it has a full feature list on the Github.
it's a Universal Assembler, which means you need to define the instruction set and names of instructions yourself.
and that is exactly what i did for the 6502 and 65C02.


Interesting. That's one I've not seen before - at least I don't think I've seen it - possibly because in the past I've looked specifically for 6502/65816 specific assemblers and taking the path of least resistance went for something that "just worked" ...

My ever lasting to-do list includes writing an assembler for my Ruby 816 platform - one that runs natively on it... But until then I'm using ca65 from the cc65 suite as it ticks all those boxes (free, and I use Linux and a text editor and Makefiles although I think there are ports to MS Win, etc.)

Cheers,

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Thu Mar 12, 2020 9:00 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8544
Location: Southern California
I had not heard of CustomASM either. If you find dead links on the non-forum part of this site, let us know so we can fix them. Sometimes they just need to be corrected; and other times, depending on the type of page, it might be appropriate to change the link to point to an archived page on archive.org. There's a lot preserved there. Even after Ed and others pointed it out, it took me a while to start thinking rather automatically to look there when a page or site goes down.

I also have a list of 65xx assemblers on my own site's link page at http://wilsonminesco.com/links.html#assem . I try to keep it up to date; but with probably one or two thousand links on my site, it's easy to miss when one goes down or needs fixing; so let me know if you find a dead link there too. I'm constantly updating my site, and my last edit on that page was today, and the last previous was two days ago.

I'm using C32 (linked there), under DOS, but it runs under Windows too. It's not free (it's $99), but it's an excellent macro assembler that works for dozens of processors, and they give you the information to extend it for a processor of your own design if you wish. I have written program-structure macros for it to give it HLL-like structures, and written it up at http://wilsonminesco.com/StructureMacros/, and there are more-extended examples in the last 40% of my page on simple methods for multitasking without a multitasking OS, at http://wilsonminesco.com/multitask/index.html#cycexec . This has really improved my productivity in, and enjoyment of, assembly language, and reduced bugs and improved maintainability. Our own Andrew Jacobs (forum name BitWise) has written an assembler he calls As65 which has similar program-structure capability built in and looks excellent, and our own Anton Treuenfels also has his HXA 6502 assembler where he has adopted my structures. (Disclaimer: I don't have any experience with either of these.)

I think most assemblers allow you to use the text editor of your choice. The big cheese in professional programmers' text editors today seems to be UltraEdit. I think MultiEdit is right up there too. (I use the latter.) They allow you to do all the things you'd expect from a professional programmers' text editor.

_________________
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  
PostPosted: Sun Mar 15, 2020 2:13 pm 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
Alright, i think i'm done with version 2 of my Board.

Attachment:
kicad_2020-03-15_14-56-42.png
kicad_2020-03-15_14-56-42.png [ 236.34 KiB | Viewed 749 times ]


what i did:

* Fixes the Reset button and removed the connection to the USB Chip. there is not really a reason to ever reset the FT240X and it's annoying that resetting the System also resets it. (it's annoying because that disconnects it from the PC for a short time)
* changed the placement of the USB connector and the size of the PCB, now it's slightly smaller than before.
* Added a power switch, just a standard 3 pin Slide switch. It's connected in such a way that disabling the power connects all Vcc connections to GND. (with the obvious exception of the USB Port and the USB Chip). it's to prevent the power pins of all ICs and such from being floating while not switched on. not sure if needed.

This is how i hooked up the power switch. I don't know if the switch can technically be on both positions (i doubt it) so i don't know if i should add a resistor between it and GND.
Attachment:
Untitl46ed.png
Untitl46ed.png [ 579.44 KiB | Viewed 749 times ]


Other than that i don't think i changed much. i tried to keep as much of the original design as i could because i know it works.

lastly, i found out Kicad has a Raytracing feature for the 3D viewer... took a minute to caluclate but doesn't look that bad. even got reflections on the board.
Attachment:
kicad_2020-03-15_15-02-16.jpg
kicad_2020-03-15_15-02-16.jpg [ 841.8 KiB | Viewed 749 times ]

This has nothing to do with the design, i just found it interesting.

let me know if there are any other changes i should probably do before ordering the boards.


Top
 Profile  
Reply with quote  
PostPosted: Sun Mar 15, 2020 2:30 pm 
Offline

Joined: Mon May 21, 2018 8:09 pm
Posts: 1462
You should be very careful about separating the power planes of the USB interface and the rest of the board. If the USB chip drives a high logic level into any logic whose power is not only removed but grounded, you can expect that signal to short through the protection diodes of whatever logic is connected to it. Does the USB chip interpret its selection signals as active-low?


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 298 posts ]  Go to page Previous  1 ... 8, 9, 10, 11, 12, 13, 14 ... 20  Next

All times are UTC


Who is online

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