Adding NES support to XC=BASIC

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

Moderator: Moderators

Post Reply
neils
Posts: 4
Joined: Fri Jan 03, 2020 11:03 am

Adding NES support to XC=BASIC

Post by neils » Fri Jan 03, 2020 11:24 am

Dear NES devs

XC=BASIC is an optimizing BASIC cross compiler which is currently targeted to the Commodore-64. As the next big step, the compiler will support multiple platforms that are built around the MOS 6502. Contributors are already working on the VIC-20, C16/Plus4 and C128 extensions. Many users have requested to extend it to support the NES and I really like the idea, but to tell the truth all I know about the NES is what I've read on the NesDev Wiki.

The compiler itself can produce quite fast machine code, even scrolling games are doable in XC=BASIC, at least on C64. See this small video of a game under development: https://twitter.com/news_xc/status/1204866546440589318

The reason why I think it's possible to extend it to NES is that most of the language core is platform-independent and any extra code or platform-specific instructions can be added.

Anyone of you guys think you could manage such a "sub-project", making the XC=BASIC for NES? The job would mostly be to plan and write the NES-specific runtime library in assembly language (in DASM more closely). I would give all my support, even if it requires to hack into the language core, but again ... I'm completely unfamiliar with NES.

More information on XC=BASIC here: https://xc-basic.net/doku.php and if you're interested in the source, check out the GitHub page here: https://github.com/neilsf/XC-BASIC

If you think it's a stupid idea, don't hesitate to tell me :D :beer:

Thanks

lidnariq
Posts: 9384
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: Adding NES support to XC=BASIC

Post by lidnariq » Fri Jan 03, 2020 11:46 am

The biggest problem with the NES, relative to the C64 and other CBM computers, is that you have to queue up screen updates until the PPU is ready for them (signaled with an NMI).

But it looks like XC=BASIC is low-enough level that the only thing a NES port would need is an implementation of this queue and an abstraction for putting things into said queue.

nitrofurano
Posts: 10
Joined: Sun Mar 21, 2010 3:07 pm

Re: Adding NES support to XC=BASIC

Post by nitrofurano » Fri Jan 03, 2020 12:44 pm

here is my very humble attempt: i'm using Geany as IDE because it allows to run a makefile just pressing shift+f9, the makefile calls a bash script: it calls XC=BASIC for compiling the basic code, uses some bash commands for patching the compiled file into a NES rom, and run it in an emulator (mame/mess, in this case)

this development method is very similar to what i have done since the last half decade using Boriel's ZX-Basic Compiler ( http://nitrofurano.altervista.org/retro ... ndex2.html - http://nitrofurano.altervista.org/retrocoding/arcade/ - http://nitrofurano.altervista.org/retro ... ndex2.html - https://gitlab.com/nitrofurano/borielzx ... amples/z80 - https://bitbucket.org/nitrofurano/borie ... mples/z80/ ), so i wanted to do the same for 6502-based hardware (and XC=BASIC shown to be quite similar to Boriel's ZX-Basic Compiler, in the 6502 side), and NES is one of them (NES is actually special for me because nostalgic memories from the 80's! ;) )

see that i'm very noob on NES development, C64 development and XC=BASIC, since i were mostly around z80 and 68000 machines - i really wished to be more skilled to take the most of XC=BASIC and making it an effective basic-language cross-compiler for NES

(and yes, i also tried Bob Rost's NBasic, and not misregretting, i'm seeing that XC=BASIC, even as it is now, is way better featured for NES development than NBasic)
Attachments
nes_1e_origin.zip
(15.05 KiB) Downloaded 50 times

neils
Posts: 4
Joined: Fri Jan 03, 2020 11:03 am

Re: Adding NES support to XC=BASIC

Post by neils » Fri Jan 03, 2020 1:39 pm

lidnariq wrote:
Fri Jan 03, 2020 11:46 am
But it looks like XC=BASIC is low-enough level that the only thing a NES port would need is an implementation of this queue and an abstraction for putting things into said queue.
Yeah, I think that all the things that are implemented in the core language (arithmetics and program structures) should be the same for all platforms. I/O is drastically different however. But as each platform can have its own I/O library and each platform can implement its own commands and functions through extensions, the screen update should be doable for NES. But let me have a deeper look into this before saying 100% sure.

neils
Posts: 4
Joined: Fri Jan 03, 2020 11:03 am

Re: Adding NES support to XC=BASIC

Post by neils » Fri Jan 03, 2020 1:43 pm

nitrofurano wrote:
Fri Jan 03, 2020 12:44 pm
here is my very humble attempt: i'm using Geany as IDE because it allows to run a makefile just pressing shift+f9, the makefile calls a bash script: it calls XC=BASIC for compiling the basic code, uses some bash commands for patching the compiled file into a NES rom, and run it in an emulator (mame/mess, in this case)
I've checked your example, thanks! And I think this is a good example of what I mean: you've implemented the startup routine with inline assembly. The same thing could go to the runtime library and run on startup - without having to write inline assembly.

nitrofurano
Posts: 10
Joined: Sun Mar 21, 2010 3:07 pm

Re: Adding NES support to XC=BASIC

Post by nitrofurano » Sat Jan 04, 2020 3:23 am

i'm now trying to convert Jon Moody's tutorial to XC=BASIC, i'm getting an "uninitialized segment" error, very probably caused from a mistaking assembly "hand conversion" from nesasm to dasm (it seems something easy to be fixed from more experimented people here? thanks in advance!)

since this example moves a sprite from the controller, and seems simple enough, my focus would be, later, trying to replace the assembly code from there with basic, and being able then to have it with minimal enough inline assembly, and then being able to tell that XC=BASIC actually and finally indeed compiles basic to NES
Attachments
nes_2a_fromjonmoodystutorial.zip
(34.21 KiB) Downloaded 54 times

neils
Posts: 4
Joined: Fri Jan 03, 2020 11:03 am

Re: Adding NES support to XC=BASIC

Post by neils » Sat Jan 04, 2020 7:39 am

nitrofurano wrote:
Sat Jan 04, 2020 3:23 am
i'm now trying to convert Jon Moody's tutorial to XC=BASIC, i'm getting an "uninitialized segment" error, very probably caused from a mistaking assembly "hand conversion" from nesasm to dasm (it seems something easy to be fixed from more experimented people here? thanks in advance!)

since this example moves a sprite from the controller, and seems simple enough, my focus would be, later, trying to replace the assembly code from there with basic, and being able then to have it with minimal enough inline assembly, and then being able to tell that XC=BASIC actually and finally indeed compiles basic to NES
Uninitialized segment is not the error here. It's just a note that XC=BASIC variables go to an uninitialized segment. Here's your error:

shipTile2X 0000 ???? (R )
shipTile2Y 0000 ???? (R )
shipTile3X 0000 ???? (R )
shipTile3Y 0000 ???? (R )
shipTile1X 0000 ???? (R )
shipTile1Y 0000 ???? (R )
shipTile6X 0000 ???? (R )
shipTile6Y 0000 ???? (R )
shipTile4X 0000 ???? (R )
shipTile4Y 0000 ???? (R )
shipTile5X 0000 ???? (R )
shipTile5Y 0000 ???? (R )
pointerBackgroundLowByte 0000 ???? (R )
pointerBackgroundHighByte 0000 ???? (R )

These symbols are missing from the assembly file. I'm not sure this is valid in DASM:
shipTile1Y=$0300

Maybe Try:
shipTile1Y EQU $0300

nitrofurano
Posts: 10
Joined: Sun Mar 21, 2010 3:07 pm

Re: Adding NES support to XC=BASIC

Post by nitrofurano » Sat Jan 04, 2020 10:05 am

thanks... tried, but i can't notice any change... :S - perhaps it's something else?
Attachments
nes_2b_fromjonmoodystutorial.zip
(34.21 KiB) Downloaded 49 times

nitrofurano
Posts: 10
Joined: Sun Mar 21, 2010 3:07 pm

Re: Adding NES support to XC=BASIC

Post by nitrofurano » Sat Jan 04, 2020 10:23 am

i think i found the bug, i was writing those 3 vector addresses bytes between $FFFA and $FFFF in a reversed order - now a sprite moves on the screen, but it looks different than from the nesasm version (available compiled in the documentation folder), i have no idea what i'm doing wrong there...
Attachments
nes_2c_fromjonmoodystutorial.zip
(34.21 KiB) Downloaded 48 times

nitrofurano
Posts: 10
Joined: Sun Mar 21, 2010 3:07 pm

Re: Adding NES support to XC=BASIC

Post by nitrofurano » Sat Jan 04, 2020 10:58 am

now i replaced to basic the code lines that would move the ship to the left, and the behaviour from the result looks a bit weird..
Attachments
nes_2d_fromjonmoodystutorial.zip
(34.73 KiB) Downloaded 52 times

Post Reply