"Hello, World!" with cc65

Chat about anything CX16 related that doesn't fit elsewhere
geek504
Posts: 95
Joined: Wed Aug 26, 2020 4:52 pm

"Hello, World!" with cc65

Post by geek504 »



20 minutes ago, desertfish said:




What do you prefer instead?



Doesn't exist yet... since I don't expect the compiler to be compliant to C-standards, I am thinking about writing my own (yet another) BASIC compiler akin to BASIC Boss but with more improvements. The only difference is that this one will be custom-made for the X16 and its improvements. I'll borrow many ideas from Woz's Integer BASIC, add HTAB/VTAB (or LOCATE) et al. With a BASIC compiler I won't need to bother the X16 devs for C64 BASIC improvements.

User avatar
desertfish
Posts: 1096
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

"Hello, World!" with cc65

Post by desertfish »


Sounds similar to what I am doing with Prog8 ?

geek504
Posts: 95
Joined: Wed Aug 26, 2020 4:52 pm

"Hello, World!" with cc65

Post by geek504 »



50 minutes ago, desertfish said:




Sounds similar to what I am doing with Prog8 ?



Yea, it occurred to me too! Honestly I have never heard of Prog8 and actually I thought it was invented by you! Couldn't find much on Google... anyways I know BASIC quite well and the grammar is already done for C64 BASIC V2. I am also old-school UNIX programmer so I am much more comfortable with Flex/Bison (lex/yacc) and C. I also don't feel like patching up cc65.

We can definitely exchange ideas!

User avatar
desertfish
Posts: 1096
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

"Hello, World!" with cc65

Post by desertfish »


Prog8 *is* created by me, I'm working on the compiler while trying to create some interesting programs with it at the same time.

geek504
Posts: 95
Joined: Wed Aug 26, 2020 4:52 pm

"Hello, World!" with cc65

Post by geek504 »



7 hours ago, desertfish said:




Prog8 *is* created by me, I'm working on the compiler while trying to create some interesting programs with it at the same time.



That explains the lack of information on the Net! I had first assumed that you created this language which led me to decide to write a compiler based on a true and tested BASIC dialect. I wouldn't need to re-invent anything, just code away the implementations. Analyzing Prog8 I can see how it is a blend of many different ideas so implementing it wouldn't present much problems... but still involve some thinking!

Feel free to add simple Prog8 source along with the generated assembly code in your Prog8 thread... I love analyzing compiled code and see how efficient or how to improve efficiency!

User avatar
kliepatsch
Posts: 247
Joined: Thu Oct 08, 2020 9:54 pm

"Hello, World!" with cc65

Post by kliepatsch »


This may be a dumb question. In the assembler tutorial, the code starts at address $80D, which is in the BASIC memory that starts at $800, according to the documentation. Why does the program start at that address? To prevent clashes with the LOAD "HELLOASM.PRG" , which may still be in the BASIC memory?



And also, how does the BASIC interpreter know, when typing RUN, where to jump?

Thanks BTW for the great content to help beginners with setting up everything for Development on the X16!

User avatar
desertfish
Posts: 1096
Joined: Tue Aug 25, 2020 8:27 pm
Location: Netherlands

"Hello, World!" with cc65

Post by desertfish »


I think both of your questions are answered at the same time:

The assembly code starts at $080d  (2061 decimal) so that it leaves enough room to put a tiny one liner basic program before it, starting at the usual $0801.

The basic program is just   10  SYS 2061     -- so when you type RUN , the first thing basic does is doing the SYS into the assembly routine starting at 2061 that then takes over

 

SlithyMatt
Posts: 913
Joined: Tue Apr 28, 2020 2:45 am

"Hello, World!" with cc65

Post by SlithyMatt »


Sounds like you have it figured out. The SYS call needs to be loaded with the rest of the program. You could always load it anywhere and do the SYS call yourself, but just typing LOAD and RUN is a lot easier! ?

User avatar
kliepatsch
Posts: 247
Joined: Thu Oct 08, 2020 9:54 pm

"Hello, World!" with cc65

Post by kliepatsch »


Thank you very much. I did the listing and got indeed


Quote




800 SYS2061



just like you mentioned. To me, the 2061 still seems like a magic number. Where does it come from?

With a hex editor, I see that the .PRG file is loaded at $801 and that this BASIC program is actually included in the binary file. Therefore it must stem from the assembler.

I assume that there should be a possibility to define what's at the start of the file. But I couldn't find it anywhere in the config files for the X16 (I mean cc65 config files).

Is this (i.e. the "SYS2061" at the start) the default behaviour if cc65 compiles for the X16?

User avatar
kliepatsch
Posts: 247
Joined: Thu Oct 08, 2020 9:54 pm

"Hello, World!" with cc65

Post by kliepatsch »


I did a little more research and it seems to be common practice to put the SYS2061 command in front of machine code programs. Not only on the X16 but even on the C64.

Well, I think I can accept that it is like this for now, as I don't have a good reason to not make use of this convenient auto-starter ?

Thanks @desertfish and @SlithyMatt again for the explanations.

Post Reply