uc65, a Mid-Level Language Compiler READY FOR USE!

Discuss technical or other issues relating to programming the Nintendo Entertainment System, Famicom, or compatible systems.

Moderator: Moderators

User avatar
infiniteneslives
Posts: 2100
Joined: Mon Apr 04, 2011 11:49 am
Location: WhereverIparkIt, USA
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by infiniteneslives » Tue Dec 03, 2013 1:23 pm

Yeah I'll hold of on the bash stuff. My main goal was to help someone take the step from compiling roms as done by nerdy nights (asm6?) To using uc65. I think using .bat files as provided in shiru's example is the simplest minimalist approach.

That said I'd love to see support for uc65 in NESICIDE. I'll give NESICIDE another try and give you the user freindly feedback you're asking for. To be honest, this 'getting things started' step is where I gave up on NESICIDE when I initially gave it a try. I don't remember the details of what my issue was as it was well over a year ago now. I only remember being new and confused not being able to find that 'go button' to build a program so I was quickly frustrated and tried elsewhere.
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers

User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by cpow » Tue Dec 03, 2013 1:57 pm

qbradq wrote:That'd be awesome cpow! :) But yea, if you have an existing makefile for cc65, you can define another rule that builds .s files from .uc files and that's that. There's even a make-style dependency generation flag for uc65.
Ok I'm almost there...but I seem to have hit a snag.
Image
That error is coming from the main.s that is generated by uc65.jar. Here's what I did:
1. Created a new NROM "Hello World" template project.
2. Gutted it [I really should create a "completely empty" template project].
3. Copied the following files into the project folder:
lib/nes/nrom/memory.cfg -> ./
lib/nes/nrom/crt0.s -> ./src/
lib/nes/nes.uc -> ./src/
examples/nes/simple/main.uc -> ./src/
4. Set the project's linker-config file to the memory.cfg file.
5. Added custom build rules to support building a .s from a .uc file.
6. Tried to build...

You can see the uc65.jar being used in the output window.

I verified I get the same error when trying to do ./build.sh nes simple in your examples folder [after fixing the path to CC65 for my setup]:

Code: Select all

$ ./build.sh nes simple
ld65.exe: Error: Missing memory area assignment for segment `ROM31'
Seems like the JAR file is expecting something similar to what is set up in the MMC3 example? That's the only place I see ROM31 segment defined.

User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by cpow » Tue Dec 03, 2013 3:06 pm

I switched to trying to build the life example.

What's this about?

Code: Select all

java -jar C:/Users/Christopher/Projects/NES/nesicide/deps/cc65-master/bin/uc65.jar -i src -o obj/nes/main.s src/main.uc
src\nes.uc:18 Error - Expected a number or constant reference
src\nes.uc:19 Error - Expected a number or constant reference
Also, when I try ./build.sh nes life in Cygwin:

Code: Select all

$ ./build.sh nes life
Error - Unable to determine parent directory of source file
Compilation failed
Also, if you could make the warning/error message format match CC65's, the snap-to-line functionality already in NESICIDE would work without me having to special case the output parser for uc65. :D

An example of the CC65 message format:

Code: Select all

$ cc65 main.uc
main.uc(1): Warning: Implicit `int' is an obsolete feature
main.uc(1): Error: `;' expected
main.uc(1): Error: Identifier expected
main.uc(1): Warning: Implicit `int' is an obsolete feature

User avatar
qbradq
Posts: 951
Joined: Wed Oct 15, 2008 11:50 am

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by qbradq » Wed Dec 04, 2013 3:41 am

Can you please confirm which release you are using? 0.5-rc3 (attached to the first post) is the most recent release and has these issues corrected.

As for build.sh, I'm not sure it's going to work well under msys / cygwin. Again, this is why I'm not wanting to roll my own build system :)

Also, can you try the attached jar and see if the message output works with your snap-to-line feature?
Attachments
patchbuild.zip
(57.24 KiB) Downloaded 131 times

User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by cpow » Wed Dec 04, 2013 5:34 am

qbradq wrote:Can you please confirm which release you are using? 0.5-rc3 (attached to the first post) is the most recent release and has these issues corrected.

As for build.sh, I'm not sure it's going to work well under msys / cygwin. Again, this is why I'm not wanting to roll my own build system :)

Also, can you try the attached jar and see if the message output works with your snap-to-line feature?
I downloaded 0.5-rc3, yes. Your patch works but I've got a little bit of work to do to get the error annunciation markers in the margins working for .uc files.

User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by cpow » Wed Dec 04, 2013 8:08 am

cpow wrote:
qbradq wrote:Can you please confirm which release you are using? 0.5-rc3 (attached to the first post) is the most recent release and has these issues corrected.

As for build.sh, I'm not sure it's going to work well under msys / cygwin. Again, this is why I'm not wanting to roll my own build system :)

Also, can you try the attached jar and see if the message output works with your snap-to-line feature?
I downloaded 0.5-rc3, yes. Your patch works but I've got a little bit of work to do to get the error annunciation markers in the margins working for .uc files.
Couple other small things:
  • Output error/warning messages to stderr instead of stdio. That way NESICIDE will colorize the error messages red in contrast to the non-error messages in the build output.
    It seems uc65.jar might be returning a "success" process exit code which causes make to continue on even when there's indicated Error messages in the last invocation?
EDIT: The error/warning thing seems to be a 3-character 'fix': System.out <> System.err - but I don't have your latest code since you sent me just the JAR with the error string format patched. So I will wait for your update.

I might take a look at your code and offer a patch but I am rusty with Java. I bought a book on it in '96, spent a weekend holed up in a UMich computer lab programming a peg solitaire puzzle game, and promptly forgot about the experience. :D

User avatar
infiniteneslives
Posts: 2100
Joined: Mon Apr 04, 2011 11:49 am
Location: WhereverIparkIt, USA
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by infiniteneslives » Wed Dec 04, 2013 11:20 pm

Line 31 of main.uc in examples\nes\simple:

Code: Select all

; Put all of this into the high page of ROM and system RAM
rom 31
ram 1
Pretty sure that's not supposed to be rom 31 as I'm getting a compilation error about segment ROM31 not defined...

I changed it to rom 0, but my .nes file still isn't getting built properly as the reset vector is missing/mis-placed.

Ahh nvm, think I figured it out, this simple example is supposed to be mmc3... With setting that to rom 0, and using the nrom config files I was able to compile and looks like it's booting as everything goes black now vice grey screen. There isn't any chr data included and I'm not sure if there was meant to be anyways... Try something else?

I'd like to just get something up and running on NROM. Looks like life is NROM and has chr data provided, so let's give that a try!

Well I was able to compile and create a .nes file, but I had to comment out lines 18 & 19 in nes.uc:

Code: Select all

; NES System Library
rom librom
ram libram
Because I was getting this error:

Code: Select all

C:\Users\Paul\Dropbox\nesdev\uc65-release-0.5-rc3>java -jar uc65.jar lib\nes\nes.uc
lib\nes\nes.uc:18 Error - Expected a number or constant reference
lib\nes\nes.uc:19 Error - Expected a number or constant reference
Compilation failed
Commenting those out allowed me to get a successful build. And I'm getting something as it's booting with a bunch of zeros on the screen. Not sure if whatever I'm missing without those librom/ram lines is causing an issue or if I'm building something improperly.

Here's my hodgepodge .bat file that allowed me to compile things in their locations as downloaded. Only issue was I needed to make a second copy of nes.uc and put it in the src directory so it could be included in the other .uc files.

Code: Select all

java -jar uc65.jar lib\nes\nes.uc
java -jar uc65.jar examples\nes\life\src\blinktext.uc
java -jar uc65.jar examples\nes\life\src\data.uc
java -jar uc65.jar examples\nes\life\src\title.uc
java -jar uc65.jar examples\nes\life\src\main.uc
path=path;cc65\
set CC65_HOME=.
ca65 lib\nes\nrom\crt0.s
ca65 lib\nes\nes.s
ca65 examples\nes\life\src\blinktext.s
ca65 examples\nes\life\src\data.s
ca65 examples\nes\life\src\title.s
ca65 examples\nes\life\src\main.s
ld65 -o life.nes lib\nes\nrom\crt0.o lib\nes\nes.o examples\nes\life\src\blinktext.o examples\nes\life\src\data.o examples\nes\life\src\title.o examples\nes\life\src\main.o -C lib\nes\nrom\memory.cfg 
pause
life.nes
Any suggestions on how to fix me up so I can make a successful build of life? After that I'll post my 'getting started' doc to help newbies out and get started on my own project! :)
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers

User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by cpow » Thu Dec 05, 2013 5:39 am

I also get what I think infininteneslives is describing once i comment out the

Code: Select all

rom librom
ram libram
in nes.uc.
Image
But it looks like something isn't quite formatted right in the generated debug info file [error in output pane]. I'll take a look. But I too am wondering what we should expect from the "life" example?

User avatar
qbradq
Posts: 951
Joined: Wed Oct 15, 2008 11:50 am

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by qbradq » Thu Dec 05, 2013 7:35 am

Wow folks, I'm floored by the amount of interest! Thank you so much! I wish I weren't so swamped with work at the moment and could whip all this up into shape. Hopefully this weekend I'll be able to make another release that reduces all the confusion.

The "simple" example uses MMC3 with character RAM. I'll change this to use NROM so it's a lot more simple :)

The "life" example is not anywhere near complete. Honestly I'd never compiled the thing. A screen of zeros is actually what should happen with the code that's present now. I am going to move work-in-progress examples into their own branch in the repo and only merge them into the main trunk when they are complete so as to avoid this confusion. Sorry folks.

The librom and libram bits were part of the build management conventions I was tinkering with before I had to disengage due to the Thanksgiving holiday prep. The thought was the standard libraries would use constants librom and libram to determine what rom and ram banks to use, and then when evoking the compiler you would use the -c argument (twice) to define both. That way you can control at build-time where these things are placed.

Finally, that was a bone-head miss to send the errors to stdout :) I'll get that fixed as soon as I can.

Also, as for the debug info, I have no idea what's going on there. This stuff isn't documented anywhere and honestly I've never tested it.

User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by cpow » Thu Dec 05, 2013 8:35 am

I'm still looking into the debug info issue, but...
I removed the offending line and :beer: :beer: :
Image
Not only is source following working, I can set breakpoints. :beer: :beer:
Almost to that "go button", eh? :mrgreen:

User avatar
qbradq
Posts: 951
Joined: Wed Oct 15, 2008 11:50 am

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by qbradq » Thu Dec 05, 2013 9:06 am

That's awesome! Can you paste in the offending line so I can track it down?

User avatar
cpow
NESICIDE developer
Posts: 1097
Joined: Mon Oct 13, 2008 7:55 pm
Location: Minneapolis, MN
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by cpow » Thu Dec 05, 2013 9:23 am

qbradq wrote:That's awesome! Can you paste in the offending line so I can track it down?
Line 2187 in the debug info is:

Code: Select all

type	id=4,val="90"
But I'm not sure how to figure out what source module that comes from.
For reference, the debug info parser doesn't complain about these lines:

Code: Select all

type	id=0,val="800420"
type	id=1,val="800120"
type	id=2,val="800220"
type	id=3,val="800321"
type	id=5,val="800C20"
type	id=6,val="800320"
type	id=7,val="800820"
Just to be clear, it is the debug info parser provided in the CC65 source that is complaining. This is not a compilation issue.

User avatar
infiniteneslives
Posts: 2100
Joined: Mon Apr 04, 2011 11:49 am
Location: WhereverIparkIt, USA
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by infiniteneslives » Thu Dec 05, 2013 11:26 pm

qbradq wrote:The "life" example is not anywhere near complete. Honestly I'd never compiled the thing. A screen of zeros is actually what should happen with the code that's present now. I am going to move work-in-progress examples into their own branch in the repo and only merge them into the main trunk when they are complete so as to avoid this confusion. Sorry folks.
No worries, I'm glad that I'm getting what I should be, I'm not too concerned about getting life to work if it's not yet complete. I'm thinking about working on converting some of shiru's simple examples or at least a hello world to start.
The librom and libram bits were part of the build management conventions I was tinkering with before I had to disengage due to the Thanksgiving holiday prep. The thought was the standard libraries would use constants librom and libram to determine what rom and ram banks to use, and then when evoking the compiler you would use the -c argument (twice) to define both. That way you can control at build-time where these things are placed.
I like that idea! :)

I re-read over the documentation today and took some notes for my own learning purposes. Pretty refreshing that I was able to read the entirety of the language's definition in an hour or so. I'm pretty excited to get going with this, especially not that it's ready for use! It really feels like uc65 has the simple elegance of only giving you what's needed to overcome the inefficiencies of assembly. All the extra fat that's not needed just simply isn't there. The fact that it's not highly abstracted away from the hardware is great and really opens the door for mapper use. I also love the easy integration of inline assembly. Time to jump in and see if it's everything I'm cracking it up to be! :)
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers

User avatar
infiniteneslives
Posts: 2100
Joined: Mon Apr 04, 2011 11:49 am
Location: WhereverIparkIt, USA
Contact:

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by infiniteneslives » Sat Dec 07, 2013 5:12 pm

Sorry, double post, have things to share, and questions to ask.

I finished a hello world demo in uc65! :D

Here's my Getting Started with uc65 for Dummies guide. There is a .zip download to go along with it for the hello world build. Feel free to do whatever you'd like with it. It's more than welcome to be included in the first post or project page for others to find more easily.

I had some confusion about something on the doc:
Loop Statement

The loop statement executes a block of statements indefinitely, or until a conditional expression evaluates as true. The block of statements will execute at least once as the optional conditional expression is evaluated at the end of the loop.

Code: Select all

loop
  [statement block]
end loop [when (conditional expression)]
So it loops until the conditional expression evaluates to true? Or till it's false? If it's the former, I guess i makes more sense now that I read it at "*END* loop when (cond expr)". I originally thought of the "end" as syntactical only, I was reading it without the end, just "loop when (cond expr)" which doesn't make sense.

I have should probably answer my own question here by looking at my compiled assembly files. But I'll ask here anyways. I'm a little curious about RAM management. I understand the 'ram' segment identifier can be used to define where ram will be allocated. Does this apply to ALL allocated ram for the code that follows? (with the obvious exception of zero/fast variables). How are passed in variables handled specifically? Is the stack used for transfer, and then the sub routine allocates ram in it's defined segment? Or is it that the stack isn't used, but the copy which the sub routine receives is allocated it's segment? Or is it still in the calling routines' segment? If one wanted to allocate specific locations of variables/arrays would the best way to do this be define a new segment? If one wanted OAM ram to be in it's typical location is the type of thing I'm thinking here. Additionally down the road I'd like to swap ram and "pseudo-ROM" in $6000-7FFF so with bankswitching RAM around I'd like to ensure my attack is inline with the abilities and methods of uc65 variable allocation.

Couple typos:

Code: Select all

test\subroutines.uc:41 Warning - Possible loss of percision
documentation under address dereferencing:

Code: Select all

address prt
ptr = $0200
All in all, it was pretty fun to play around with and get my hands dirty with the language. Kudos on the great work thus far qbradq! There were a couple times where I knew exactly what I wanted in assembly, and wasn't sure how to get the language to give it to me. So having the ease of inserting assembly without trouble is pretty awesome and allows you to stay close to the hardware.

I'll be working on building my nes.uc library file and share it here from time to time for anyone who's interested. Ping me if you'd like my latest version, not sure how it'll compare to qbradq's but no need to duplicate efforts further.
If you're gonna play the Game Boy, you gotta learn to play it right. -Kenny Rogers

User avatar
qbradq
Posts: 951
Joined: Wed Oct 15, 2008 11:50 am

Re: uc65, a Mid-Level Language Compiler READY FOR USE!

Post by qbradq » Sun Dec 08, 2013 6:54 pm

I am super excited about this INL! I have the flu right now, but when I'm better I'll fix the typos and put up the links.

Also, there is no end clause for loop. That was dropped from the language spec but apparently forgot to take it out of the docs.

Subroutine parameters are copy-on-call. If you want them in zero-page, use the fast modifier for the subroutine. If you want the subroutine's variables in zero page, use the fast modifier on the variables. uc65 only uses the stack to store register values during interrupt handlers.

rom and ram apply to everything that emits code or variables following those statements until the next such statement.

Again when I am feeling better I will try to make the documentation more clear.

Post Reply