Jump to content
IGNORED

cc65 graphics 18 (2+16) shows as mode 0


Recommended Posts

Hello ?

My goal here is to print text to GR mode 18.

what happens is:  text prints correctly, but it renders under GR mode 0 not graphics 18.

#include <atari.h>
#include <conio.h>
#include <stdio.h>
#include <unistd.h>

int main(void) {
  _graphics(18);
  printf("hello");
  sleep(4);
  printf(", world..\n");
  sleep(5);

  gotoxy(3,3);
  cputc('A');
  sleep(5);
  
  return(0);
}

The above is built using:
 

cl65 -t atari -Wl "-D__RESERVED_MEMORY__=0x3000" ./gr18.c -o ./gr18.xex

..and is executed using:

atari800.exe .\gr18.xex

(also tried in Altirra).

I've spent hours searching AA, YouTube, GH and plain Google. After seeing some posts that didn't research enough before asking, I doubled down on searching.

 

I'll admit I failed to find example documentation for `_graphics()` macro in the CC65 docs. I found HTML help text that said to look at Atari header link, but when you clicked there it only documented TGI modes, not the actual _graphics() macro, which means I just went in circles.

 

I found the raw `graphics.s` in GitHub, but unfortunately I don't get it from reading just that.  I looked at Bill's GemDrop source, but unfortunately it's a bit more complex than what I'm going for.

 

I'm ready to give up and just play with DOS coding instead, but I'm primarily interested in the A8, starting simple, and documenting what I learn. So what have I missed?

 

 

Edited by scottinNH
Link to comment
Share on other sites

CC65, for some reason, seems to have some kind of documentation problem. I don't know whether people can't find it, or they get sidetracked by old cc65.org stuff, or the docs at github are insufficient, or if they are just not clear. It's such a great dev system I hate to see people getting off on the wrong foot with it. Sanny - am I wrong?

  • Thanks 1
  • Haha 1
Link to comment
Share on other sites

3 hours ago, danwinslow said:

CC65, for some reason, seems to have some kind of documentation problem. I don't know whether people can't find it, or they get sidetracked by old cc65.org stuff, or the docs at github are insufficient, or if they are just not clear. It's such a great dev system I hate to see people getting off on the wrong foot with it. Sanny - am I wrong?

 

Question is not to me, but please indulge my response. ?

Yes, totally yes.

 

Caveat here: I'm new to C. Agreeing in advance: learning CC65 at the same time, is NOT a good idea. 100%

But usually I can dive in the deep end, and scope problems down till I figure it out. 

 

This exercise was off-putting (so yeah, if this is easier to find maybe more more folks adopt it). 

I've tried to do this before and gav up. But recently my work involves C, so I am again motivated..

 

And to be helpful:

If I want to add a missing example for GRAPHICS 2, do I just make a PR to atari.html

under https://github.com/cc65/doc?   

Probably somewhere else, like a directory, yeah? There will be more to submit (I'm progressing through an 80's book)

 

I'm trying to understand the pattern to contribute documentation (which in itself I could document).

 

 

 

 

 

 

 

 

 

 

 

Edited by scottinNH
typo, clarity
  • Like 1
Link to comment
Share on other sites

There are other ways to do what you want without using printf or cprintf

when you open a graphics screen with _graphics(18) most people forget the call returns a file handle

so if you do this:- 

 

void main(void)

{

    int fd;
    fd = _graphics(18);    
    write(fd,"Hello",6);
    write (fd,", World..",10);
    gotoxy(3,3);
    write(fd,"A",1);

}


you get your screen with the text, if your code continues then at the end you just

close(fd);

to close the screen channel

 

 

 

btw. the reason printf opens a graphics 2 screen is printf writes to stdout which is the default, C checks

if stdout is open and if not opens it so it can write to it hence graphics 0 is opened.

  • Like 1
Link to comment
Share on other sites

1 hour ago, scottinNH said:

If I want to add a missing example for GRAPHICS 2, do I just make a PR to atari.html

under https://github.com/cc65/doc?   

If not changed recently you have to apply changes to the "sgml" source files here:

 

https://github.com/cc65/cc65/tree/master/doc

 

The html files are generated out of those.

Edited by Irgendwer
  • Like 1
Link to comment
Share on other sites

1 hour ago, scottinNH said:

Question is not to me, but please indulge my response. ?

Yes, totally yes.

 

Caveat here: I'm new to C. Agreeing in advance: learning CC65 at the same time, is NOT a good idea. 100%

But usually I can dive in the deep end, and scope problems down till I figure it out. 

 

The cc65 documentation is not meant to teach people how to program for a specific system. It expects people to know their system, and emphasizes on how cc65 is implemented for that specific system.

 

 

1 hour ago, scottinNH said:

And to be help:

If I want to add a missing example for GRAPHICS 2, do I just make a PR to atari.html

under https://github.com/cc65/doc?  

 

The documentation for the _graphics() call is lacking. This is a function which mimics the BASIC function with the same name, so I thought there is not much extra documentation needed apart from the BASIC documentation.

 

And, sure, in BASIC after you execute "GRAPHICS 18", if you "PRINT" something instead of "PRINT#6", the screen reverts to 40x24 (GR.0).

 

I'm happy to accept documentation updates:

 

1 hour ago, scottinNH said:

I'm trying to understand the pattern to contribute documentation (which in itself I could document).

 

Go to https://github.com/cc65/cc65, download the source, and create a "pull-request". The documentation is in the "doc" subdirectory.

 

  • Thanks 1
Link to comment
Share on other sites

Can `cprintf()` not print to 2 lines consecutively?

 

The following using `write()` and is what I wanted

 

image.thumb.png.91c756a9d5c3960fae0afa03bf599dac.png

 

  cprintf("Hello\n");
  cprintf("World");

^.. OR with write() I can get rid of newline, and use "gotoxy(0,1)" before "World" -- that works also.

Problem is I am not able to replicate this formatting using cprintf();

 

With cprintf(), the "World" jumps to row 3.

 

#include <atari.h>
#include <conio.h>
#include <stdio.h>
#include <unistd.h> /* req. by write() */

int main(void) {
  char c;
  int fd;
  fd = _graphics(18);    /* fd needed for write() */
 
  /* results: row1="HELLOWORLD" */
  /* cprintf("Hello");
  cprintf("World"); */

  /* results: row1="HELLO", row3="WORLD" */
  /* cprintf("Hello\r\n");
  cprintf("World"); */

  /* results: row1="HELLO", row3="     WORLD" */
  /* cprintf("Hello\n");
  cprintf("World"); */

  /* results: row1="WORLD" */
  /* cprintf("Hello\r");
  cprintf("World"); */

  /* results: row1="HELLO", row3="WORLD" */
  /* cprintf("Hello");
  gotoxy(0,1);
  cprintf("World"); */

  /* row1="HELLO,WORLD.." */
  /* fd = _graphics(18);    
  write(fd,"Hello,",6);
  write (fd,"World..",7); */

  /* row1="HELLO,", row2="WORLD.." WHAT I WANT*/
  /* write(fd,"Hello,",6);
  gotoxy(0,1);
  write (fd,"World..",7); */

  /* row1="HELLO,", row2="WORLD.." WHAT I WANT*/
  write(fd,"Hello,\n",7);
  write (fd,"World..",7);

  c = cgetc();  /* avoid exiting until a keypress */
  return(0);
}

I am happy to just use write() which writes to row1 + row2, and write works perfect with gotoxy().

...and there would be 1 example.

 

But if cprintf() can be made to print 2 consecutive lines, that would be a second-form example.

 

Thanks.

Link to comment
Share on other sites

4 hours ago, sanny said:

what is not working? Please give an example program for your problem.

Thanks. The example above had all the combinations, but here are 2 direct examples:

#include <atari.h>
#include <conio.h>
#include <stdio.h>
#include <unistd.h> /* req. by write() */

int main(void) {
  char c;
  int fd;
  fd = _graphics(18);    /* fd needed for write() */
 
  /* results: row1="HELLO", row3="WORLD" */
  cprintf("Hello");
  gotoxy(0,1);
  cprintf("World");

  c = cgetc();  /* avoid exiting until a keypress */
  return(0);
}

and

#include <atari.h>
#include <conio.h>
#include <stdio.h>
#include <unistd.h> /* req. by write() */

int main(void) {
  char c;
  int fd;
  fd = _graphics(18);    /* fd needed for write() */
 
  /* results: row1="HELLO", row3="     WORLD" */
  cprintf("Hello\n");
  cprintf("World"); 

  c = cgetc();  /* avoid exiting until a keypress */
  return(0);
}

In both examples, "World" is inexplicably appearing on row3, but I am trying to get it to row 2.

Edited by scottinNH
Link to comment
Share on other sites

I think I know what's wrong, if you try this code using _graphics(0) you get this

    gotoxy(0,0);
    cprintf("Hello,");
    gotoxy(0,1);
    cprintf("World..");
    gotoxy(0,2);
    cprintf("Should be line 3");
    gotoxy(0,3);
    cprintf("Should be line 4");

    gotoxy(8,8);
    write(fd,"A",1);
 

image.thumb.png.d38d682759b401b99082679b529b902c.png

 

As expected, however with _graphics(18) you get this:-

image.thumb.png.416dcd5cfcac40301c6efd3a2a858532.png

 

I think there's a bug/ (feature) in the cprintf routine that always prints a 40 character line so if you use a mode

with less lines like in this example, cprintf covers 2 lines on screen.

 

So even though gotoxy(0,1) will move the cursor to the second line, cprintf is using a 40 character line so uses

the start of line 3 instead of 2 overriding the gotoxy call.

Link to comment
Share on other sites

I think this proves my earlier post, you program will work if you assume a 40 character line, see the following code:-

    gotoxy(0,0);
    cprintf("Hello,");
    gotoxy(20,0);
    cprintf("World..");
    gotoxy(0,1);
    cprintf("Should be line 3");
    gotoxy(20,1);
    cprintf("Should be line 4");

 

image.thumb.png.b2c6be47f06c25faa0363b9e236ddc22.png

  • Thanks 1
Link to comment
Share on other sites

You could try this for 20-char lines (untested)

 

;
; Christian Groessler, November-2002
;
; cursor handling, internal function

        .include "atari.inc"
        .import cursor,_mul20
        .export setcursor

.proc   setcursor

        ldy     #0
        ;lda     OLDCHR
        ;sta     (OLDADR),y

        lda     ROWCRS
        jsr     _mul20
        clc
        adc     SAVMSC          ; add start of screen memory
        sta     OLDADR
        txa
        adc     SAVMSC+1
        sta     OLDADR+1
        lda     COLCRS
        adc     OLDADR
        sta     OLDADR
        bcc     nc
        inc     OLDADR+1
nc:     lda     (OLDADR),y
        sta     OLDCHR

        ldx     cursor          ; current cursor setting as requested by the user
        beq     off
        ldx     #0
        beq     cont

off:    inx
cont:   stx     CRSINH          ; update system variable

        beq     turnon
        ;and     #$7f            ; clear high bit / inverse flag
finish: sta     (OLDADR),y      ; update on-screen display
        rts

turnon: ;ora     #$80            ; set high bit / inverse flag
        jmp     finish

.endproc

 

save it as mysetcursor.s or similar and add it to the cc65 command line

  • Like 1
Link to comment
Share on other sites

  • 5 weeks later...

Posted a PR for the "40 character line" behavior:

https://github.com/cc65/cc65/pull/1633

 

This is a more modest PR than I was intending... OK for now.

 

 

Between the website, wiki and other places it wasn't clear where to add new content, or how to index something like a samples/atari8 dir.  

 

Also I wanted to link the functref.sgml content to the actual .h files in Github. So you can just click from docs to the definition.

 

There's a lot of information being added to the wiki, but on the other hand search engines can't index the Git wiki at all...   

 

I've posted a message to the mailing list. No complaints; I just need to study the documentation framework and see which way the docs were trending.

Edited by scottinNH
Link to comment
Share on other sites

I've applied your PR.  And only then noticed that your text was in the wrong (machine independent) section. I've moved it to atari.sgml.

 

I think if you change src/cross_lib/display/init_graphics/cc65/atari/disable_setcursor.s of @Fabrizio Caruso's CROSS_CHASE (git@github.com:Fabrizio-Caruso/CROSS-CHASE.git) to use _mul20 instead of _mul40, it could "just work". I don't have time currently to really test it out.

 

regards,

chris

Edited by sanny
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...