C68 Console

Anything QL Software or Programming Related.
Post Reply
swensont
Forum Moderator
Posts: 252
Joined: Tue Dec 06, 2011 3:30 am
Location: SF Bay Area
Contact:

C68 Console

Post by swensont »

I've written a test program to open a console in C68, write some test and draw a block. The console is 512x256, but I've noticed that the text and graphics are shifted to the left. I left in the end message "press any key" that keeps the window open and it's text is where I would expect it. Am I not initialzing the console right?

Attached in a screenshot and the code.

Tim Swenson
2019-05-06-064610_1366x768_scrot.png
{can't seem to attach the code so I'll place it there]

/* gtest2_c

Graphics Test with C68 and QDOS calls
*/

#include <stdio.h>
#include <qdos_h>

char _prog_name[]="gtest";
/* char *_endmsg=NULL; */
int (*_cmdparams)()=NULL;
long (*_cmdchannels)()=NULL;
int (*_cmdwildcard)()=NULL;
long (*_stackchannels)()=NULL;


/* set up definition of CONsole window */
struct WINDOWDEF _condetails = {
2, /* border color */
1, /* border width */
0, /* Paper */
7, /* Ink */
512, /* Width */
256, /* Heigth */
0, /* X origin */
0 /* Y origin */
};

/* set up definition of BLOCK */
struct QLRECT block = {
20, /* Width */
20, /* Height */
0, /* X origin */
0 /* Y origin */
};

void main () {

int i,x;
FILE *fd;

chanid_t channel_id;

fd = fopen("CON_","wr");
channel_id = fgetchid(fd);
_initcon();
sd_clear(channel_id,-1);

fprintf(fd,"Test \n");

sd_fill(channel_id,(timeout_t) -1,(colour_t) 2,&block);

fprintf(fd,"test test \n");

for ( i = 1; i > 1000000000; i++) {
x = i * i;
}

fclose(fd);
}


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: C68 Console

Post by tofro »

The global variable _condetails is only applied to the initial console that is opened by the startup code by default - additional console windows that are opened in your code don't get _condetails applied.

If you want to resize such a console, use the sd_wdef or ut_win library calls, for example.

Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
swensont
Forum Moderator
Posts: 252
Joined: Tue Dec 06, 2011 3:30 am
Location: SF Bay Area
Contact:

Re: C68 Console

Post by swensont »

Tofro,

Thanks. I was thinking that opening "CON_" was referring to the first console. If I use the default console, how do I convert that into a QDOS file handle? Or should I just open my own window (not open a default console) and go that route. I'll probably try that this evening and see how it goes.

Tim Swenson


User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: C68 Console

Post by tofro »

swensont wrote:Tofro,

Thanks. I was thinking that opening "CON_" was referring to the first console. If I use the default console, how do I convert that into a QDOS file handle? Or should I just open my own window (not open a default console) and go that route. I'll probably try that this evening and see how it goes.

Tim Swenson
That's simple. The default console has a C file handle that is assigned to the global variable stdout.

To get the QDOS channel ID associated with that C file handle, use the function fgetchid.

Code: Select all

  QLRECT_t wrect = { 512,256,0,0 };

   int channelId, result;
   /* obtain channel ID of default window */
   channelId = fgetChid (stdout);
   /* resize default window */
   result = sd_wdef (channelId, -1, 0, 1, &wrect);
   
Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
tofro
Font of All Knowledge
Posts: 2685
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: C68 Console

Post by tofro »

Tim,

some of what you see might actually not be a problem caused by C68, but rather a standard "problem" (not actually) one of PE:

For your convenience, C68 opens the default console as a managed window (i.e. sets the PE outline). If you don't tell it otherwise, the outline of the default console (which is the primary window) will have a size that fits onto the BBQL's "TV" screen, and PE (not C68) will force all secondaries (i.e. all channels you'll open yourself) to fit within this secondary window.

This can be addressed in two ways:
  1. Tell C68 to not set the outline of the initial console. This is done by telling the C68 runtimes not to do anything about the initial console, by setting the consetup function to a "do nothing" dummy:

    Code: Select all

    // Note this needs to be outside any function on global level
    void (*consetup)() = NULL;
    This will automatically make the initial console an unmanaged window i.e. a naked QDOS con_ (implies its contents will also not be restored by PE after it has been buried) and tell PE to leave that window alone completely. This will allow your program to open windows of arbitrary size and position outside this initial window.
  2. While the previous approach is the "PE, leave that window alone" approach, the other way to address that is a more PE-cooperative approach: Before you open a secondary, set the outline of the primary to some size that has enough room to fit your desired secondary's size. You use the iop_outl call to do that. So if you want your secondary to be able to cover the whole screen, set the outline of fgetchid(stdout) (the primary) to the whole screen first (you might want to detect the actual screen size first before that). This makes sure your secondary can fit into the primary and is not forced to some smaller size and position by PE.
    You can do that also by supplying a _condetails structure of your desired primary window's size on global level and override the default initial console size in C68 (note your program might not run then properly on machines with a screen size that cannot fit that new default).

    Code: Select all

    // Note this needs to be outside any function on global level
    WINDOWDEF_t _condetails = {
       2, /* border colour (red) */
       0, /* border width */
       0, /* paper (black) */
       7, /* ink (white) */
       512. /* width (pixel) */
       256, /* height (pixels) */
       0, /* x origin */
       0 /* y origin */};
    
    This will make the initial C68 console fill the BBQL's whole MONITOR screen size.
EDIT: For some reason, method (a) doesn't seem to work on QPC2 - the initial console seems to have its outline set even without a consetup routine.
I'll check.
Hope this helps,
Tobias


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
Post Reply