Jump to content
IGNORED

Open a Screen cc65


Recommended Posts

I'm have a strange problem, I want to open a normal BASIC Mode 0 screen using cc65.

 

I've checked the header file and found a function _graphics() which says it uses the same parameters as BASIC

 

So _graphics(0) should give me a standard 40 column text mode screen, what I get is a black screen and it hangs (I think as I can't see anything :)).

 

If I remove the _graphics(0) call, my program runs fine (its the first line in my code).

 

While the call is not essential for this program, I may need to call this in future programs, so would like to resolve whats wrong, is there

something else I should be calling.

 

#include <stdio.h>
#include <conio.h>
#include <peekpoke.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <atari.h>

 

void main(void)
{
    flag=0;

    _graphics(0);
    clrscr();
    POKE(710,57);
    POKE(709,2);
    POKE(712,200);
    gotoxy(0,0);
    printf("---------------------------------------");

Link to comment
Share on other sites

See:

https://atariage.com/forums/topic/242757-black-screen-crash-when-using-_graphics-call-in-cc65/

(inspect explanation from "dmsc")

 

If you use the std. Atari configuration with the added byte for reserved memory:

FEATURES {
    STARTADDRESS: default = $2000;
}
SYMBOLS {
    __EXEHDR__:          type = import;
    __SYSTEM_CHECK__:    type = import;  # force inclusion of "system check" load chunk
    __AUTOSTART__:       type = import;  # force inclusion of autostart "trailer"
    __STACKSIZE__:       type = weak, value = $0800; # 2k stack
    __STARTADDRESS__:    type = export, value = %S;
    __RESERVED_MEMORY__: type = weak, value = $0001;
}
MEMORY {
    ZP:         file = "", define = yes, start = $0082, size = $007E;

# file header, just $FFFF
    HEADER:     file = %O,               start = $0000, size = $0002;

# "system check" load chunk
    SYSCHKHDR:  file = %O,               start = $0000, size = $0004;
    SYSCHKCHNK: file = %O,               start = $2E00, size = $0300;
    SYSCHKTRL:  file = %O,               start = $0000, size = $0006;

# "main program" load chunk
    MAINHDR:    file = %O,               start = $0000, size = $0004;
    MAIN:       file = %O, define = yes, start = %S,    size = $BC20 - __STACKSIZE__ - __RESERVED_MEMORY__ - %S;
    TRAILER:    file = %O,               start = $0000, size = $0006;
}
SEGMENTS {
    ZEROPAGE:  load = ZP,         type = zp;
    EXTZP:     load = ZP,         type = zp,                optional = yes;
    EXEHDR:    load = HEADER,     type = ro;
    SYSCHKHDR: load = SYSCHKHDR,  type = ro,                optional = yes;
    SYSCHK:    load = SYSCHKCHNK, type = rw,  define = yes, optional = yes;
    SYSCHKTRL: load = SYSCHKTRL,  type = ro,                optional = yes;
    MAINHDR:   load = MAINHDR,    type = ro;
    STARTUP:   load = MAIN,       type = ro,  define = yes;
    LOWBSS:    load = MAIN,       type = rw,                optional = yes;  # not zero initialized
    LOWCODE:   load = MAIN,       type = ro,  define = yes, optional = yes;
    ONCE:      load = MAIN,       type = ro,                optional = yes;
    CODE:      load = MAIN,       type = ro,  define = yes;
    RODATA:    load = MAIN,       type = ro;
    DATA:      load = MAIN,       type = rw;
    INIT:      load = MAIN,       type = rw,                optional = yes;
    BSS:       load = MAIN,       type = bss, define = yes;
    AUTOSTRT:  load = TRAILER,    type = ro;
}
FEATURES {
    CONDES: type    = constructor,
            label   = __CONSTRUCTOR_TABLE__,
            count   = __CONSTRUCTOR_COUNT__,
            segment = ONCE;
    CONDES: type    = destructor,
            label   = __DESTRUCTOR_TABLE__,
            count   = __DESTRUCTOR_COUNT__,
            segment = RODATA;
    CONDES: type    = interruptor,
            label   = __INTERRUPTOR_TABLE__,
            count   = __INTERRUPTOR_COUNT__,
            segment = RODATA,
            import  = __CALLIRQ__;
}

and build with it (option: -C configname ) or just the short variant:

 

cl65 -t atari  -D__RESERVED_MEMORY__=1 test.c -o test.xex



this code:

#include <stdio.h>
#include <conio.h>
#include <peekpoke.h>
#include <string.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
#include <atari.h>

 

void main(void)
{
    _graphics(0);
    clrscr();
    OS.color2 = 57;
    OS.color1 = 2;
    OS.color4 = 200;
    gotoxy(0,0);
    printf("---------------------------------------"); 

    while(1);
}

works:
 

screenshot.png

Edited by Irgendwer
Link to comment
Share on other sites

Many thanks for your reply, but I tried both methods and still get the black screen,

I even copy/pasted your example above and compiled it and that had the black screen too

I must be missing something here.

 

Using the config file with  :- cl65 -t atari -Catari.cfg --static-locals -o autodata.xex autodata.c

with this line modified in the atari.cfg file:-  __RESERVED_MEMORY__: type = weak, value = $0001;

 

I also tried :- cl65 -t atari -D__RESERVED_MEMORY__=1 --static-locals -o autodata.xex autodata.c

 

I'm using a 130XE, so memory size etc. as described in the link you provided shouldn't be an issue 

Link to comment
Share on other sites

Thanks @Wrathchild , that fixed it, I'll have to look and see why this is required, and what that switch does.

 

It seems strange though to have to do something like this for a straightforward screen opening which is handled

internally by the OS.

 

Do you know if this switch is required if you do it by using CIO calls to open "S:" as you would in assembler ?

Like this but in "C" code 

 

0680  SCREENOPEN LDA #CLOSE ; MAKE SURE CHANNEL IS CLOSED
0690     LDX #$10
0700     STA ICCOM,X
0710     JSR CIOV
0720     LDA #0      ; RESERVE MEMORY
0730     STA APPMHI  ; FOR NEW SCREEN
0740     LDA #$80    ; ELSE OPEN WILL FAIL
0750     STA APPMHI+1
0760     LDA #OPEN
0770     STA ICCOM,X
0780     LDA #NAME1&255
0790     STA ICBAL,X
0800     LDA #NAME1/256
0810     STA ICBAH,X
0820     LDA #3
0830     STA ICBLL,X
0840     LDA #0
0850     STA ICBLH,X
0860     LDA #$0C    ;R/W
0870     STA ICAX1,X
0880     LDA #8
0890     STA ICAX2,X
0920     JSR CIOV

930       RTS

1000 NAME1 .BYTE "S:",$9B

Link to comment
Share on other sites

9 hours ago, Wrathchild said:

But instead of passing the define to cl65 this needs to be passed onto the linker instead with: -Wl "-D__RESERVED_MEMORY__=1"

Interesting. My command line as given above works exactly as it should. "Linux Mint" cl65 V2.18 - Git a560052
Thanks for the solution!

Link to comment
Share on other sites

3 minutes ago, Irgendwer said:

cl65 V2.18

I have cl65 V2.17 - Git 5c8854f

 

I'm not sure what the behaviour, say with gcc is, but I think the use of -D is just to pass to the pre-processor?

 

If you've edited the atari.cfg to non-zero then because the define isn't passed to the linker then it would use that and so work in your case?

Link to comment
Share on other sites

1 hour ago, Wrathchild said:

I'm not sure what the behaviour, say with gcc is, but I think the use of -D is just to pass to the pre-processor?

If you've edited the atari.cfg to non-zero then because the define isn't passed to the linker then it would use that and so work in your case?

Just tried to reproduce what I did. Don't know - of course you are right and the "-Wl" is necessary.

I only wonder why @TGB1718 wasn't able to create a working exe with the adapted config.
Thanks again!

Link to comment
Share on other sites

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...