EtchedPixels / CC6303

A C compiler for the 6800 series processors
Other
37 stars 7 forks source link

[feature request] Future support for the TMS9900? (if possible with minimal lib for the TI99/4A?) #19

Closed Fabrizio-Caruso closed 2 years ago

Fabrizio-Caruso commented 2 years ago

I have seen some of your very recent development for the TMS9995. Do you plan to also support the plain TMS9900. They almost have the set instruction set, with the TMS9995 maybe adding only 4 opcodes. If that is the case, would you also consider adding a target for the (memory expanded) TI99/4A with very minimal input/output (as you have done for the MC-10)?

For a reference on a similar project (GCC for TI99/4A) you may find this useful: https://atariage.com/forums/topic/164295-gcc-for-the-ti/

I have been able to use it here: https://github.com/Fabrizio-Caruso/CROSS-LIB/blob/master/src/games/chase/makefiles.chase/Makefile.gcc_tms9900_targets

Some of the tools and crt are described in the thread above. What I use for my project is also found here: https://github.com/Fabrizio-Caruso/CROSS-LIB/tree/master/tools/ti99

There is also a CONIO implementation here that may be useful: https://github.com/tursilion/libti99

EtchedPixels commented 2 years ago

I did play with the ti99/4a gcc initially but it was incredibly buggy.

I got a bit stuck with cc68 and tms9995 because it's got a lot of registers and despite my best efforts to make use of them the cc65 core doesn't really know how to do it. Instead see

https://github.com/EtchedPixels/pcc-tms9995-support

I have this building and running a few things. There is a bug in vararg handling (promotion of char to int for unprototyped parameters) at the moment but otherwise it seems to be doing reasonably okay on char, integer and some long.

For the 9900 I believe the only difference would be that you don't have DIVS so would need instead to use a small helper to switch the signs as needed and use DIV.

Fabrizio-Caruso commented 2 years ago

Cool! I am looking forward to seeing TMS9900 and TI99/4A if you ever implement it. I think TMS9900 is indeed so close to require a minor adaptation. Support for TI99/4A would just be a matter of using a crt, plugging in an implementation for getchar and putchar and generating a cartridge (or tape) image. Indeed GCC for TI is not reliable and moreover it is not easy to build as it has many dependencies and it won't build out of the box on all POSIX environments. I would be more than happy to ditch it and use your compiler.

Fabrizio-Caruso commented 2 years ago

By the way, if you ever produce a TMS9900 compiler if possible with minimal support for the TI99/4A, I will test it extensively and maybe spot some bugs and give you some hopefully useful feed-back.

EtchedPixels commented 2 years ago

All the hooks are now there, would need someone who knows about the 99/4a to write the crt0, set the memory map up etc

Fabrizio-Caruso commented 2 years ago

Great! Thanks! I am no expert but I may have all or most of what we need here. Have you taken a look at the links I have provided above? They include a working crt (which I have used successfully with the modded GCC): https://github.com/Fabrizio-Caruso/CROSS-LIB/tree/master/tools/ti99

My (very messy sorry) Makefile uses some of the tools that generate a rom image and may do most of what is left to be done: https://github.com/Fabrizio-Caruso/CROSS-LIB/blob/master/src/games/chase/makefiles.chase/Makefile.gcc_tms9900_targets

The other links above also point to code to do some trivial input output with the VDP.

EtchedPixels commented 2 years ago

Probably but without knowing how things are loaded, what the memory layout is etc not a lot.

Fabrizio-Caruso commented 2 years ago

Most homebrew developers build cartridge images for the TI99/4A. Cassettes are possible but not common now.

If I remember well, the cartridges do not provide a contiguous directly addressable unique block of memory. They provide several 8k banks of memory. So running from the cartridge would require bank-switching (which is close to impossible code to generate for a C compiler). So most games and tools assume you have a 32k RAM expansion and the code is "automatically" decompressed into it. The tools I use (see my links) should create cartridge images that will "explode" into the expanded RAM and run from RAM. This is already taken care of by the tools. No need to code this. Anyway most people assume a 32k real RAM is present. It is common to have both a cartridge and a 32k expansion. The modern memory expansion uses a "sidecar expansion". This is the most common "target" now for homebrews of the 21st century: 32k memory expansion with a cartridge.

For super small binaries with no bank switching, the code could reside on the cartridge and run from the cartridge. This should be limited to 8k of code + 256 of internal RAM (or +32k if a memory expansion is present).

In the old days (and maybe sometimes even now), the video RAM was also used to store data (and/or even code) but we can avoid this painful process.

Fabrizio-Caruso commented 2 years ago

I am looking at: https://www.unige.ch/medecine/nouspikel/ti99/architec.htm

Fabrizio-Caruso commented 2 years ago

I am not sure but it looks like GCC generates a raw ELF binary (relocatable binary?), which is converted to something a TI99/4A could run by Elf2Ea5 (which may also do a relocation it but I am no sure). In order to store it onto a self-exploding cartridge image, this has to be (internally) "split" into 8k blocks with EA5SPLIT. This tool also takes care of prepending the code that reads all the blocks and moves the code onto RAM and starts it.

I am looking at: https://github.com/jedimatt42/fcmd/wiki/tms9900gcc-Ubuntu-Installation-Guide

Fabrizio-Caruso commented 2 years ago

@EtchedPixels I am not sure 100% of all that what I have written. I am trying to use those tools with the binary produced by GCC to see how to use them. Last time I used GCC for TI to do something for the TI was a couple of years.

Fabrizio-Caruso commented 2 years ago

Maybe some useful information before we even starting considering real cartrdige/images. Classic99 emulator (http://www.harmlesslion.com/cgi-bin/onesoft.cgi?1) can read EA5 files (elf2ea5 should convert elf to ea5) with the following procedure: