6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Mon Jul 08, 2024 2:31 pm

All times are UTC




Post new topic Reply to topic  [ 17 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Thu Dec 26, 2013 5:48 pm 
Offline

Joined: Wed Dec 25, 2013 10:06 am
Posts: 13
Hello,

I tried to search and pretty sure this is common question, but does anyone have simple set of files I need to create a custom target into cc65? What I really want is a template where I can change memory settings and write screen/keyboard functions to able to create a "Hello world" executable. I found one instruction how to create custom target, but it was way too limited.


thanks,

Axel.


Top
 Profile  
Reply with quote  
PostPosted: Thu Dec 26, 2013 6:17 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1705
Location: Sacramento, CA
Try this thread. I wrote some simple targets for the Kowalski Simulator that should be a good start for building your own.

viewtopic.php?f=2&t=2196

Daryl

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 27, 2013 6:35 pm 
Offline

Joined: Wed Dec 25, 2013 10:06 am
Posts: 13
Hi. Nice work.
I tried to build a lib template, but it turned out to be unsuccessful. I was able to compile executable binary code, but cprintf or printf never reaches putc subroutine and I was unable to continue modifying screen routines.
I also tried to use Atmos and Nes libraries as a template but I faced the same issue. It seems that adding stdio or conio to c-software results not executable code in the end. At least according to simulator. Simple "1+2" code compiles fine and results working binary - at least in simulator.

For sure cc65 is very good compiler but it is also quite complex and there are too many parameters to understand before all of the bits and bytes are in the right position - I can see.

Is there any other (simpler) options to compile 6502 software?

Thanks for your reply,

Axel.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 27, 2013 7:16 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8464
Location: Southern California
6502sbc wrote:
Is there any other (simpler) options to compile 6502 software?

What is your goal? If it is to gain the structure of a higher-level language and get rid of the spaghetti which is typical of assembly language, you can use program-structure macros in assembly and get more clarity, better control, fewer bugs, with (in most cases) no penalties in memory taken or in performance. I have an article on them, with source code for the C32 assembler, at http://wilsonminesco.com/StructureMacros/index.html. Others here have written assemblers with the structure capabilities built in. The As65 assembler (written by BitWise on this forum) has structure capabilities without the user adding macros. His even automatically chooses branch versus jump instructions to get the code compact in most cases but still able to make the jump when the distances exceed 127 bytes. Anton Treuenfels added structures to his HXA 6502 assembler. The source code I provide on my website has the following:
Code:
  IF_EQ       (using Z flag)           BEGIN
  IF_ZERO     (using Z flag)           
  IF_NEQ      (using Z flag)           WHILE_EQ       (using Z flag)
  IF_NOT_ZERO (using Z flag)           WHILE_NEQ      (using Z flag)
  IF_PLUS     (using N flag)           WHILE_ZERO     (using Z flag)
  IF_MINUS    (using N flag)           WHILE_NOT_ZERO (using Z flag)
  IF_NEG      (using N flag)           WHILE_PLUS     (using N flag)
  IF_C_SET    (using C flag)           WHILE_MINUS    (using N flag)
  IF_C_CLR    (using C flag)           WHILE_NEG      (using N flag)
  IF_GE       (using C flag)           WHILE_C_CLR    (using C flag)
  IF_LT       (using C flag)           WHILE_C_SET    (using C flag)
  IF_V_SET    (using V flag)           WHILE_GE       (using C flag)
  IF_V_CLR    (using V flag)           WHILE_LT       (using C flag)
  IF_FLAG_VAR     (added May 2013)     WHILE_V_CLR    (using V flag)
  IF_BIT          (added May 2013)     WHILE_V_SET    (using V flag)
  IF_MEM_BYTE_NEG (added May 2013)     WHILE_BIT      (added May 2013)
  IF_MEM_BYTE_POS (added May 2013)     
                                       REPEAT
  ELSE_                                AGAIN
  END_IF                               
                                       
                                       UNTIL_EQ       (using Z flag)
  CASE      (using A, X, or Y)         UNTIL_ZERO     (using Z flag)
  CASE_OF   (using A, X, or Y)         UNTIL_NEQ      (using Z flag)
  END_OF                               UNTIL_NOT_ZERO (using Z flag)
  END_CASE                             UNTIL_PLUS     (using N flag)
                                       UNTIL_MINUS    (using N flag)
                                       UNTIL_NEG      (using N flag)
  FOR       (16-bit.  Overwrites A)    UNTIL_C_CLR    (using C flag)
  NEXT      (16-bit.  Overwrites A)    UNTIL_C_SET    (using C flag)
                                       UNTIL_GE       (using C flag)
  FOR_X     (added May 2013)           UNTIL_LT       (using C flag)
  NEXT_X    (added May 2013)           UNTIL_V_CLR    (using V flag)
  FOR_Y     (added May 2013)           UNTIL_V_SET    (using V flag)
  NEXT_Y    (added May 2013)           UNTIL_BIT      (added May 2013)


plus a group of accessory macros I find useful:

  RTS_IF_EQ          RTS if Z flag is set
  RTS_IF_NEQ         RTS if Z flag is clear
  RTS_IF_PLUS        RTS if N flag is clear
  RTS_IF_MINUS       RTS if N flag is set
  RTS_IF_FLAG_VAR    RTS on a flag variable's condition.  The variable name and target condition are given in the parameter list.
  RTS_IF_BIT         RTS if the specified bit of the specified byte in memory meets the target condition.  These are given in the parameter list.
  RTS_IF_MEM_LOC     RTS if the value in the specified memory location is positive | negative | zero | non-zero, again per the parameter list.

I have not done a major 6502 project yet using the structure macros, but I have completed one commercial project using them on PIC16 and am well on my way to completing another one (the latter using two separate PIC16's), and the structures have made things vastly easier and more clear, without the memory and performance penalties of higher-level languages. It's still assembly and you still have full control, but does the same thing you would do by hand but keeps you from having to look at the ungly internal details over and over.

_________________
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: Fri Dec 27, 2013 8:38 pm 
Offline

Joined: Wed Dec 25, 2013 10:06 am
Posts: 13
I searched the reason why my adapted putc-function never executed and noticed that cc65 compiles this source somehow wrong:
#include <stdio.h>
unsigned int i,j;
static const char Text [] = "Hello world!";
void main(void)
{
while (1){
j = 15;
i = 1 + j;
j = i + 2;
printf ("%s", Text);
}
}

Somewhere (actually 1621 steps from the start) there is a hard jump to start of data segment which is obviously out of executable code (eh!?).. Opcode 0 results booting loop which I could notice earlier running it in actual hw. CC65 (like "all" of the high level languages) also generates hugh amount of code. This example is almost 4k.

I have no experience of structured assembler but it sound like a possible approach. Writing in pure assembler has some issues and I'm not seeking them in this project as a challenge. A bit higher language would be better choice and C was first in mind. One of the reasons to use C is string operations.

Thanks,

Axel.


Top
 Profile  
Reply with quote  
PostPosted: Fri Dec 27, 2013 9:18 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8464
Location: Southern California
6502sbc wrote:
One of the reasons to use C is string operations.

BDD posted his 65816 assembly string-manipulation library at http://sbc.bcstechnology.net/files/code ... ibrary.zip. I don't know of a ready-made assembly-language set for 6502, but one will be included in my source code in my primer and treatise on 6502 stacks (plural, not just the page-1 hardware stack) which I hope to finish in 2014 and post on my website. [Edit: It's up, at http://wilsonminesco.com/stacks/ .]

_________________
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: Sat Dec 28, 2013 2:03 am 
Offline

Joined: Tue Jul 24, 2012 2:27 am
Posts: 672
If you just want "a bit higher [level] language" that doesn't clash with the 6502 as badly as C does, give Forth a whirl. There's a separate subforum for it.

The error you describe might still somehow be a missing module that didn't trip an error, with the JMP to where it thought one of the underlying printf support calls could be. So while that situation would still be a bug, it doesn't necessarily yet indicate that the code generator is buggy.

I use ca65 and ld65 a lot, but sorry I can't help you further with the C & stdlib end of things.

_________________
WFDis Interactive 6502 Disassembler
AcheronVM: A Reconfigurable 16-bit Virtual CPU for the 6502 Microprocessor


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 28, 2013 6:57 am 
Offline

Joined: Wed Dec 25, 2013 10:06 am
Posts: 13
GARTHWILSON: Thanks for the information. String library would be useful.

White Flame: It is true and I had a strong doubt about mem settings in modified cfg-file. However if I only comment printf-line, compiled program executes just fine. Adding printf adds few subroutine calls before main function and one of them jumps to data segment. That would be odd to find a bug like that - there must be an explanation I could not find within time period I can spend for it right now.


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 28, 2013 10:25 am 
Offline

Joined: Sun Apr 10, 2011 8:29 am
Posts: 597
Location: Norway/Japan
6502sbc wrote:
CC65 (like "all" of the high level languages) also generates hugh amount of code. This example is almost 4k.

That's almost certainly because of the single 'printf'. printf (and friends sprintf¸ fprintf etc.) drags in a lot of code on any platform. Some small-memory platforms (microcontrollers etc) try to avoid that by providing a limited-functionality library which mimics just the basic printf features, e.g. if you only need to print "hello world\n" then you'll need almost nothing of what standard printf provides (and includes whether you use it or not). In fact the standard 'hell world' example is one of the worst for testing compilers.. almost nothing in the executable is your own code.

-Tor


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 28, 2013 5:23 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1705
Location: Sacramento, CA
6502sbc wrote:
Hi. Nice work.
I tried to build a lib template, but it turned out to be unsuccessful. I was able to compile executable binary code, but cprintf or printf never reaches putc subroutine and I was unable to continue modifying screen routines.
I also tried to use Atmos and Nes libraries as a template but I faced the same issue. It seems that adding stdio or conio to c-software results not executable code in the end. At least according to simulator. Simple "1+2" code compiles fine and results working binary - at least in simulator.

For sure cc65 is very good compiler but it is also quite complex and there are too many parameters to understand before all of the bits and bytes are in the right position - I can see.

Is there any other (simpler) options to compile 6502 software?

Thanks for your reply,

Axel.


Hi Axel,

Sorry for the delay in responding. If you care to provide some details about your target system, I can try to help tailor a cc65 target for you. I will need to know the memory map, how your console is configured, and whether you want your C executables to be in ROM or RAM.

I also want to be sure you got the right files that I originally linked to. This is the package I created.
http://sbc.rictor.org/support/CC65forSim.zip

I want to confirm that is the file you downloaded and that you followed the "installation instructions.txt" file.

thanks!

Daryl

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


Top
 Profile  
Reply with quote  
PostPosted: Sat Dec 28, 2013 9:08 pm 
Offline

Joined: Wed Dec 25, 2013 10:06 am
Posts: 13
8BIT: great and kind offer! However I've but this idea on hold for a while. I'll take a look at your Sim version to determine whether it could suit my needs. To be honest, I thought I could build my own library within reasonable time but I couldn't.

Tor: You pointed out what was proved in my testing earlier and also answered to my original question what are my possibilities to use cc65.

thanks,

Axel.


Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 29, 2013 4:26 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 9:02 pm
Posts: 1705
Location: Sacramento, CA
No problem. The complexity of your library is directly proportional to your IO system. For simple console operations, the SIM version will require very little changes. My SBC-3 supported color graphics, Disk IO, a real time clock, and Ethernet. The target code for that took about a month to complete.

If you venture back to CC65, let me know if I can help.

Daryl

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


Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 29, 2013 5:48 am 
Offline

Joined: Wed Dec 25, 2013 10:06 am
Posts: 13
Hello. Exactly. Thats why I tried to search/build a very simple and lite template using only minimal and necessary source code. All the code lines for color etc. are something I don't need - and are increasing unwanted payload as a "cold" code in the result program. And it was pretty easy to put cfg crt0 and some other source files together and have simple library which generates proper starting points and necessary startup routines. After adding necessary library sources to get stdio/conio capability luck ended. I think that the library I built is not consistent even it passes compiling and linking. But... like I wrote: the result is too big. I was hoping that I could have lets say 1-2kKB hello world -program. Even that is rather big when debugging is required for some reason.

Thanks,

Axel.


Top
 Profile  
Reply with quote  
PostPosted: Sun Dec 29, 2013 2:02 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10838
Location: England
Try using putc or puts instead of printf...


Top
 Profile  
Reply with quote  
PostPosted: Mon Dec 30, 2013 11:49 am 
Offline

Joined: Wed Dec 25, 2013 10:06 am
Posts: 13
This started to bother me too much to leave it unresolved. I recreated customized library with necessary modifications and compiled Hello world works now fine (including real hw). BidEd wrote a good point and using cputs the code above is 319B. Perfect.
For the record: these files are needed for this example:
ar65 a mos6502.lib lib\crt0.o lib\cputc.o lib\incax1.o lib\incax2.o lib\revers.o lib\incsp2.o lib\zeropage.o lib\cputs.o lib\popa.o lib\gotoxy.o lib\pusha.o

All the library files intact (except crt0)

Conclusion: it is possible to make such a small customized library and keep most of the files intact (=remain cc65 functionality to compile actual working results).

8bit: do you know what zerobss, copydata and initlib do exactly (used in crt0)? I've commented them out without noticeable problem. Left argument stack initialization active tho...


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

All times are UTC


Who is online

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