scottinNH Posted December 21, 2021 Share Posted December 21, 2021 (edited) 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 December 21, 2021 by scottinNH Quote Link to comment Share on other sites More sharing options...
sanny Posted December 21, 2021 Share Posted December 21, 2021 You are using 'printf' which is using E: Use 'cprintf' instead to write to the GR.18 screen. 1 Quote Link to comment Share on other sites More sharing options...
danwinslow Posted December 21, 2021 Share Posted December 21, 2021 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? 1 1 Quote Link to comment Share on other sites More sharing options...
scottinNH Posted December 21, 2021 Author Share Posted December 21, 2021 5 hours ago, sanny said: You are using 'printf' which is using E: Use 'cprintf' instead to write to the GR.18 screen. THANKS! 2 Quote Link to comment Share on other sites More sharing options...
scottinNH Posted December 21, 2021 Author Share Posted December 21, 2021 (edited) 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 December 21, 2021 by scottinNH typo, clarity 1 Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted December 21, 2021 Share Posted December 21, 2021 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. 1 Quote Link to comment Share on other sites More sharing options...
Irgendwer Posted December 21, 2021 Share Posted December 21, 2021 (edited) 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 December 21, 2021 by Irgendwer 1 Quote Link to comment Share on other sites More sharing options...
sanny Posted December 21, 2021 Share Posted December 21, 2021 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. 1 Quote Link to comment Share on other sites More sharing options...
scottinNH Posted December 22, 2021 Author Share Posted December 22, 2021 Can `cprintf()` not print to 2 lines consecutively? The following using `write()` and is what I wanted 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. Quote Link to comment Share on other sites More sharing options...
sanny Posted December 22, 2021 Share Posted December 22, 2021 what is not working? Please give an example program for your problem. Quote Link to comment Share on other sites More sharing options...
scottinNH Posted December 22, 2021 Author Share Posted December 22, 2021 (edited) 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 December 23, 2021 by scottinNH Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted December 23, 2021 Share Posted December 23, 2021 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); As expected, however with _graphics(18) you get this:- 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. Quote Link to comment Share on other sites More sharing options...
TGB1718 Posted December 23, 2021 Share Posted December 23, 2021 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"); 1 Quote Link to comment Share on other sites More sharing options...
sanny Posted December 25, 2021 Share Posted December 25, 2021 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 1 Quote Link to comment Share on other sites More sharing options...
scottinNH Posted January 24, 2022 Author Share Posted January 24, 2022 (edited) 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 January 24, 2022 by scottinNH Quote Link to comment Share on other sites More sharing options...
sanny Posted January 24, 2022 Share Posted January 24, 2022 (edited) 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 January 24, 2022 by sanny Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.