6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri May 03, 2024 10:36 pm

All times are UTC




Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: No love for FORTRAN?
PostPosted: Tue Apr 23, 2024 4:20 pm 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3350
Location: Ontario, Canada
Yeah, the 'C02 is a *very* worthwhile upgrade! :) The extra instructions and new address modes make a real difference! And the pinout changes (compared to NMOS '02) are easily manageable.

As an aside, it's worth noting that the modern C02's made by WDC, though an excellent choice for many applications, are IMO not the best choice for dropping into an existing NMOS project (especially a home-built). You'd be better off with an older 'C02 if you can find one, such as those made in days of yore by Rockwell, CMD and others.

To be clear, many hobbyists have used the WDC chip and had no trouble. But the older devices have much gentler rise and fall times on the outputs, and thus are less prone to noise problems and flaky operation that can result from construction and design shortcomings. Another benefit that helps avoid noise and flakiness issues is the TTL compatibility featured by the inputs on older C02's but not on WDC -- more on that here.

-- Jeff

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Tue Apr 23, 2024 5:09 pm 
Offline

Joined: Mon Apr 22, 2024 6:02 am
Posts: 9
Location: Germany
Thank you for your information.
I already read some articles here, how to pass parameters to a function without a stack.

I want to figure out how people wrote programs on old hardware of the 60s and 70s.
My first programming language was Algol60. It was implemented on stack machines.
I did some assembly on my C64 back then - but I do not remember how I programmed at this time. I was a child at that time - not a professional assembly programmer.

I might try to run an old Fortan compiler on an emulated PET or Apple-II. I want to see what code the compiler generates for the 6502. And I also will check what code the cc65 generates for the NMOS 6502.
If I know what code a Fortran77 compiler generates, I might write a Fortran77 cross compiler for PC (or B, BCPL, PL/M).

Thank you for the hint that the WDC65C02 is not TTL compatible on its inputs.
I also have the Olimex Neo6502 (with the WDC65C02) and I can use that, if I want to use the extended instruction set.
It has an external bus, but sadly the bus (and the 65C02) run on 3.3V - not 5V. Now I understand that the 74LVC245 on this board does not reach the 5V CMOS levels when supplied with 3.3V which is needed for the rp2040.

For the programming of the Elektor Junior together with my friend: he will probably stick to his old NMOS 6502.
(If you don't know the Junior - it is a KIM-1 clone)


Last edited by Hermes on Tue Apr 23, 2024 6:53 pm, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Tue Apr 23, 2024 6:34 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10793
Location: England
Welcome, Hermes. I think in some ways the usual programming approach for 6502 is like FORTRAN's common block - the programmer will arrange allocations and deal in global addresses, and probably re-use some addresses for multiple purposes.


Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Tue Apr 23, 2024 6:57 pm 
Offline

Joined: Mon Apr 22, 2024 6:02 am
Posts: 9
Location: Germany
BigEd wrote:
Welcome, Hermes. I think in some ways the usual programming approach for 6502 is like FORTRAN's common block - the programmer will arrange allocations and deal in global addresses, and probably re-use some addresses for multiple purposes.


And that is the reason that I am interested in Fortran.
The compiler would do some work for me that I had to do if I would use hand coded assembly.
I am looking for a replacement of assembly with as few overhead and performance loss as possible.

I also took a look at the source code of CP/M-65 by David Given. He uses a special assembler that can generate functions and nested loops and IF statements. I have never seen such an assembler before. He wrote some macros to implement that. Those macros look different from what I have seen before.
I try to understand those macros: https://github.com/davidgiven/cpm65/blo ... de/zif.inc
The assembler is called MADS and implemented in FreePascal. That is all I know about it.
It might be this one: https://github.com/tebe6502/Mad-Assembler/tree/master
It looks very interesting to me.


Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Tue Apr 23, 2024 9:11 pm 
Offline

Joined: Mon Apr 22, 2024 6:02 am
Posts: 9
Location: Germany
I figured out, that MADS can define procedures with ".PROC" . They are reentrant (which I do not need) and use a software stack (which I want to avoid). MADS can also generate loops and ifs.

David Given defines his own macros in MADS for functions and loops.
To me it looks like a strategy that a Fortran compiler might use. I have to analyze that in more detail.


Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Tue Apr 23, 2024 9:25 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8430
Location: Southern California
Hermes wrote:
BigEd wrote:
Welcome, Hermes.  I think in some ways the usual programming approach for 6502 is like FORTRAN's common block - the programmer will arrange allocations and deal in global addresses, and probably re-use some addresses for multiple purposes.

And that is the reason that I am interested in Fortran.
The compiler would do some work for me that I had to do if I would use hand-coded assembly.
I am looking for a replacement of assembly with as few overhead and performance loss as possible.

These these things are discussed in the previously mentioned 6502 stacks treatise; and sections 14 and 15 of the are on local variables and environments, and recursion.

Quote:
I also took a look at the source code of CP/M-65 by David Given. He uses a special assembler that can generate functions and nested loops and IF statements. I have never seen such an assembler before. He wrote some macros to implement that. Those macros look different from what I have seen before.

See the article on program flow control structure macros at http://wilsonminesco.com/StructureMacros/ .  There are a couple of extended usage examples in the last 40% of the page on simple multitasking methods, and in the end of the SPI bit-banging code page where there's an example of transmitting and receiving at the same time in the different SPI modes.  There's more explanation of how it works in section 17 of the 6502 stacks treatise, and near the end of that page, there's a CASE (called "switch case" in C) structure example where you can mouse over each of the lines and a box will pop up telling what the line does and what's on the assembler's stack at that point.  These things can of course be used also in writing a 6502 FORTRAN compiler or interpreter.  Hopefully they'll be somewhat easier to understand than the dizzying, huge tree of directories and files in the github links you mentioned.

Quote:
and use a software stack (which I want to avoid).

Having a 6502 ZP software stack works amazingly well, and solves various problems that otherwise arise if you try to mix data and addresses on the hardware stack.  This is described, with the reasons, in the 6502 stacks treatise.

_________________
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: No love for FORTRAN?
PostPosted: Tue Apr 23, 2024 9:47 pm 
Offline

Joined: Mon Apr 22, 2024 6:02 am
Posts: 9
Location: Germany
Hermes wrote:
Small programs I write in 6502 assembly but I am unhappy that I can not easily save X or Y on the stack and can not access any function parameter on the stack with stack relative addressing.


Maybe I should not use X and Y for loops counters and A for passing parameters (except in functions that do not call other functions or in the innermost loop which does not call any function). And I should not pass parameters on the stack. I also must not have local variables on the stack.
Sounds like ancient Fortran to me :D


Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Tue Apr 23, 2024 10:01 pm 
Offline

Joined: Mon Apr 22, 2024 6:02 am
Posts: 9
Location: Germany
Thank you very much Garth Wilson for your link about structured macros.
I think, this is exactly what I was searching for.
This is amazing!

I never could find a good tutorial about advanced macro techniques.


Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Tue Apr 23, 2024 10:31 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1927
Location: Sacramento, CA, USA
Hermes wrote:
I never could find a good tutorial about advanced macro techniques.

Garth makes them appear useful and easy, but (for better of worse) my brain doesn't process macros nearly as well as plain assembly language, so I only use what limited knowledge I have of them to traverse the code of others, never for my own projects. I have found "includes" to be mentally cumbersome too, but I do my best to respect the preferences of others. Ctrl+Z, Ctrl+X, Ctrl+C, and Ctrl+V get a lot of well-deserved use on my keyboard.

_________________
Got a kilobyte lying fallow in your 65xx's memory map? Sprinkle some VTL02C on it and see how it grows on you!

Mike B. (about me) (learning how to github)


Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Wed Apr 24, 2024 12:02 am 
Offline

Joined: Mon Apr 22, 2024 6:02 am
Posts: 9
Location: Germany
I am used to structured programming in higher languages, and I never had a teacher who showed me assembly on a professional level.
I do not like C and I always joke about C, that it is just a better macro assembler. And maybe this is kind of true.

Today I learned how to do loops and branches (even nested ones) in macro assembly without using labels.
I still have to learn how to have arithmetic expressions in assembly that look like in a higher language (not RPN or FORTH).
And I have some clue how to pass parameters without a stack and maybe how to have local variables without stack. I need to learn more about that.

I always wondered how the first Fortran compiler could be implemented without Fortran (or any other higher language).
Now I have some understanding how it could be done with macro assembly. (It does not mean that it actually was done like this)

I will practice some 6502 assembly programming (with macros) to gain more skill.

I am still curious how efficient the 6502 code is that a good Fortran compiler can produce.
I assume, there was a fight in the 1960s between the traditional assembly programmers and the modern Fortran/Algol programmers. I did not program during that time period.

For me the 6502 is the most simple microprocessor. (not looking at the 1802 or any older ones)
I want to figure out what I can do with that.


Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Wed Apr 24, 2024 12:05 am 
Offline

Joined: Mon Apr 22, 2024 6:02 am
Posts: 9
Location: Germany
I apologize that I "stole" this thread and it turned into macro assembly. But I am still open for Fortran 6502.


Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Wed Apr 24, 2024 6:19 am 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8172
Location: Midwestern USA
Hermes wrote:
I am used to structured programming in higher languages, and I never had a teacher who showed me assembly on a professional level.

When I started out, almost all mainframe programs were written in assembly language, FORTRAN or COBOL.  The first machine I programmed only accepted raw machine code.  Needless to say, debugging a program was an interesting experience.

Assembly language on the IBM S360 monster continued to be used to some extent in applications into the mid-1980s, mostly because the development costs had already been amortized and little was to be gained from rewriting it in high level code.  The Union Pacific Railroad continued to run assembly language programs on their mainframes until around 1987.

Although assembly language is about as unstructured as one can get, assembly language programmers from the mainframe era were expected to write top-down code, which meant a lot of analysis and flow-charting was carried out before jumping on the card punch machine (or a video terminal, if one was available—those didn’t start to proliferate until the mid-1970s and were kind of gawd-awful at first).  Even before the term “structured programming” existed, it was being practiced due to the size of many projects.

Professionally-written assembly language has almost become a lost art.  I only knew two others of my generation of code jockeys who knew assembly language well enough to write a major application with it.  Today’s programmers have gotten spoiled by gigahertz MPUs and high-level languages and more often than not, don’t know much about what is going on behind the curtains.  I suspect assembly language is not even being taught in most college CompSci courses anymore.

Quote:
I do not like C and I always joke about C, that it is just a better macro assembler. And maybe this is kind of true.

C is an abstraction of PDP-11 assembly language, mostly an exercise in trying to describe machine code using English words.  Of the two authors of the original K&R C manual, only one of them knew the PDP-11 assembly language, and it wasn’t the ‘K’ in “K&R”.  :D

I'm no fan of C and admit to being a middling C programmer.  Also, I really fail to see the allure of C running on a 6502 system—the output of the compiler is a bulky and slow binary, since MPU capabilities that work well with C’s model are not present in the 6502/65C02.  Nor can I envision a reason to try to run FORTRAN on a 6502.

Quote:
Today I learned how to do loops and branches (even nested ones) in macro assembly without using labels.

Some minor pedantry: there is no such a thing as “macro assembly.”  Assembly language is assembly language: mnemonics, operands, etc.  You don’t need macros to write an assembly language program.  A macro facility allows you to reduce typing tedium by assigning names to frequently-used sequences of instructions.  Well-designed macros can also reduce the introduction of bugs into your code.  If one is really artful with macros, it is possible to create a sort of high-level language in some ways, like the structured macros advocated by Garth.  I don’t take it that far, but do use macros a lot (see attached example).  However, when it comes time to write the smallest and tightest code, e.g., a device driver, the macro processor stays in the closet.  I need to be able to see every instruction so I can identify anything that may increase cycle count without adding useful function.

Attachment:
File comment: Display Date, Time, Uptime (full of macros)
date.asm [15.26 KiB]
Downloaded 3 times

You should first learn how to write effective and clean code without using macros so you can fully understand what you are doing.  You don’t want macros to become a crutch.

Quote:
I still have to learn how to have arithmetic expressions in assembly that look like in a higher language (not RPN or FORTH).

Well, good luck on that.  There is no concept of algebraic precedence in assembly language.  If anything, it’s more like RPN, in that you copy your operands to defined workspace and then carry out the operation.  For example, if you are adding two numbers, it would conceptually be like N1 N2 +, where N1 and N2 are the numbers to be added.

Quote:
I always wondered how the first Fortran compiler could be implemented without Fortran (or any other higher language).

The language concepts had to be defined and then a compiler written to implement them.  In principle, it wasn’t complicated.  In actuality, given the capabilities of the computers of the times, the journey from concept to reality involved tons of flowcharts, tons of assembly language and countless manhours of debugging and testing.  About three years elapsed from when FORTRAN was formally defined until a working compiler was made available.

Quote:
I will practice some 6502 assembly programming (with macros) to gain more skill.

I suggest you practice the assembly LANGUAGE part first.  You aren’t going to become skilled in the art if you bury your work in macros.

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


Top
 Profile  
Reply with quote  
 Post subject: Re: No love for FORTRAN?
PostPosted: Wed Apr 24, 2024 8:00 am 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1401
Location: Scotland
Hermes wrote:
If I know what code a Fortran77 compiler generates, I might write a Fortran77 cross compiler for PC (or B, BCPL, PL/M).


Do you mean write a FORTRAN compiler in .. BCPL ... etc. ?

If so, I'm interested.

However there is only one BCPL implementation that runs on the 6502 that I'm aware of and that's the one for the BBC Micro. It uses 16-bit integers but there is a separate numbers package with 48 bit floating point and a number of fixed point (and fast integer) routines. I used it extensively in the 80s... Which a number of years later (about 40) led me to implement BCPL on my '816 board.

BCPL can also run under Linux and maybe under MS Windows, but I've no idea about the latter.

A "classic" FORTRAN (77) compiler ought to be relatively easy to write to generate 6502 code - there is always the question of who wants to write it and why. The hard part is the optimiser - vectorising array operations which the good compilers can do on systems which support such a thing.

-Gordon

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


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 43 posts ]  Go to page Previous  1, 2, 3

All times are UTC


Who is online

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