EtchedPixels / CC6303

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

[question/feature] Where is the MC10 code located by default? #20

Open Fabrizio-Caruso opened 2 years ago

Fabrizio-Caruso commented 2 years ago

Where is the code for the MC10 target located by default when compiled by running the following command?

cc68 -tmc10 foo.c -o foo

Is it located at $4200 just after text mode video ram? I am asking because I fear that this would break any program that uses graphics mode (as they may take 3k or $4000-$4BFFF) if I am doing the math correctly.

Where are the different sections in memory? rodata? Maybe the code starts at $4C00 but it maybe the C software stack or the rodata is somewhere in $4000-$4BFFF and it is interfering with the graphics.

I have tried to use the -C and --start-addr options with cc68 but they are not available. I have not found a cfg linker file to control where the sections are in memory (such as the ones in CC65).

Is there a way to output a map file that shows where variables are in memory?

I see there may be a way to do this by using the linker ld68 command, though.

EtchedPixels commented 2 years ago

The -C option to the linker sets the code address (-B bss -D data, but those otherwise just follow the code) and -Z for the direct page

The default for the MC10 is -b -C 17500 -Z 0x90 (-b is binary)

The machine locates its own system variables and possibly stack (not sure where basic puts it initially) straight after the video memory. It also vectors the interrupts there, so you can't use the internal interrupt timer in graphics mode unless you are very clever (and work a jump bit pattern into the fixed part of your graphics at the right spot)

Fabrizio-Caruso commented 2 years ago

Thanks for replying! "Hires" 4 color 128x96 graphics takes $4000-$4BFF (19455). So a more general default would be $4C00 (19456), because it would allow all programs to run at the cost of memory when no graphics is used. Strangely I can have a loop writing into $4000-$4BFF without a crash/freeze. I am compiling with the cc68 but I see that I should do it with the linker command to avoid such problems. Is there a way to tell the high level command cc68 to start at $4C00 (so that programs with graphics would run without a crashing)? Would you please consider adding an option for this in the future?

Fabrizio-Caruso commented 2 years ago

If the top level cc68 command does not have an option for the start-address, would you please consider having such an option to pass it to the linker for the sake of convenience? If that is not possible or too much work, would you consider $4C00 as default?

For my specific case I can rewrite my Makefile to use the explicit compile only cc68, the linker command and the tool to generate a tape image as separate commands.

EtchedPixels commented 2 years ago

17500.. it's the right start spot for most MC-10 code, especially as you've usually on got 4K of RAM.

I'll look at a setting to change the code base or a variant MC10 build type.

Fabrizio-Caruso commented 2 years ago

@EtchedPixels I understand. If a setting is too much of a hassle, a second target, e.g mc10exp, with start address at $4C00 (19456) should also do because $0C00=3k=128x96 in 4 colors, which is the highest possible resolution on an unmodified M-10. For the unexpanded mc10, why exactly 17500? If my math is correct, $4200 (16896) would be enough for the default screen text mode and provide more memory for the code. Plain text mode should only take 32x16=512 ($0200) bytes. So my guess is that maybe you wanted to leave 1k for the super low res graphics 64x64 in 4 colors.

EtchedPixels commented 2 years ago

17500 was what I was told to use - I assume there's a bit below it still being used by basic and system variables on the load/exec.

Fabrizio-Caruso commented 2 years ago

@EtchedPixels I am no expert. I would like to run some experiments with lower and higher start address. Do I only need to change all occurrences of 17500 in cc.c or is 17500 also coded elsewhere?

EtchedPixels commented 2 years ago

It's only in cc.c I think - and maybe in tapeify