Jump to content

Recommended Posts

Hi all, I am somewhat new to all of this. However I am having a few issues getting some things to work as expected.

 

Basically if I define:

char buffer[960] = {1};

I expect that all the elements of the array will be initialised as 1 in this global variable. However printing the contents on screen:

char *screen;
screen = (char*)0x3028; // character scren memory start address

*screen = buffer[0];

It displays a black background at position zero on screen, this is on an aquarius, zero = black, 1 = red.

 

It doesnt seem that the arrays or indeed any global variables are being initialised :/.

 

Perhaps I am doing something wrong in compilation? I am building each file as a .rel (relocatable object) and linking them myself with:

sdcc -mz80 --no-std-crt0 --compile-only -o out/ source/notmain.c
sdld -m -u -f link.lk

The link.lk contains:

-mjwx
-i out\final\hello.ihx
-b _CODE = 0xe000
-b _DATA = 0xf000
-k C:\RETRO\COMPILERS\SDCC\bin\..\lib\z80
-l z80
out\notmain.rel

-e

Finally

I noticed in the .rst file that the data initialisation code is being produced it just doens't seem be getting run...

   F3C2                      70 __xinit__screen_map:
   F3C2 01                   71 	.db #0x01	;  1
   F3C3 00                   72 	.db 0x00
...
Edited by Atirez
Link to comment
https://forums.atariage.com/topic/228034-sdcc-variable-initialisation/
Share on other sites

I'm not familiar with the Aquarius or your compiler but crt0 is responsible for copying the "DATA" section from ROM to RAM as well as clearing the "BSS" section. Both of these steps are needed before main is called otherwise your "C" code won't work as expected. From your previous example you weren't doing either of those actions in your start-up code.

 

A brief look at the Aquarius memory map shows that $F000 is game cart ROM so you don't want the DATA section there. The DATA section contains initialised "C" variables in RAM. As a temporary workaround you can change your :-

 

char buffer[960] = {1};
to

 

const char buffer[960] = {1};
And that will place it in ROM.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...