Help opening a window in Pure C

C and PASCAL (or any other high-level languages) in here please

Moderators: exxos, simonsunnyboy, Mug UK, Zorro 2, Moderator Team

User avatar
TheNameOfTheGame
Atari God
Atari God
Posts: 1059
Joined: Mon Jul 23, 2012 8:57 pm
Location: Almost Heaven, West Virginia

Help opening a window in Pure C

Postby TheNameOfTheGame » Thu Oct 05, 2017 6:26 pm

I am trying for the first time to program Gem in Pure C and my program is hanging at v_opnwk. :?

Can someone check this short code out an tell me what I am doing wrong? Thanks for any help!

TEST.PRJ

Code: Select all

TEST.PRG
=
PCSTART.O         ;PC-Startup-Code
TEST.C            ;Main program

PCSTDLIB.LIB
PCTOSLIB.LIB
PCGEMLIB.LIB


TEST.C

Code: Select all

#include <tos.h>
#include <aes.h>
#include <vdi.h>

int work_in[11], work_out[57];

void event_loop ( void );

void main( int argc, char *argv[], char *envp[] ) {

   int i, x, app_handle, win_handle;
   int fullx, fully, fullw, fullh;
   char *win_text;

   /* application init */
   appl_init();

   /* open vwork */
   app_handle = graf_handle( &x, &x, &x, &x );
   work_in[0] = 2 + Getrez();
   for (i = 1; i < 10; work_in[i++] = 1);
   work_in[10] = 2;
   v_opnwk( work_in, &app_handle, work_out );  /* Hanging Here!  */

   /* setup window */
   wind_get ( 0, WF_WORKXYWH, &fullx, &fully, &fullw, &fullh );
   win_handle = wind_create( NAME|CLOSER, fullx, fully, fullw, fullh );
   wind_set( win_handle, WF_NAME, "Example", 0, 0);
   wind_open( win_handle, fullx, fully, 300, 200);
   win_text = "Hello World!" ;

   /* draw window text */
   v_gtext( app_handle, 10, 60, win_text );

   /* process events */
   event_loop();

   /* close window and exit program */
   wind_close( win_handle );
   wind_delete( win_handle );
   rsrc_free();
   v_clsvwk( app_handle );
   appl_exit();

}

void event_loop(  void ) {

   int msg_buf[8];

   do {
         evnt_mesag ( msg_buf );

   } while ( msg_buf[0] != WM_CLOSED );
}

czietz
Hardware Guru
Hardware Guru
Posts: 480
Joined: Tue May 24, 2016 6:47 pm

Re: Help opening a window in Pure C

Postby czietz » Thu Oct 05, 2017 7:26 pm

v_opnvwk! You cannot open a physical workstation for the screen, it's already open by the AES. You need a virtual workstation.
http://cd.textfiles.com/ataricompendium ... /CHAP7.HTM

Didn't have a look through the rest of the code...

User avatar
TheNameOfTheGame
Atari God
Atari God
Posts: 1059
Joined: Mon Jul 23, 2012 8:57 pm
Location: Almost Heaven, West Virginia

Re: Help opening a window in Pure C

Postby TheNameOfTheGame » Thu Oct 05, 2017 8:02 pm

Ok thanks. I'm following Peter Lane's AHCC guide so I knew I did something wrong. :lol:

Thanks for the link, I'll read it.

*Edit* Yep, I made a typo..I was using v_opnwk instead of v_opnvwk... :?

*Edit 2* Success! Thanks, that fixed it! :cheers:

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12005
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Help opening a window in Pure C

Postby wongck » Thu Oct 05, 2017 11:43 pm

Here's a bit of information by Dr CoolZic
viewtopic.php?t=14954
These will start your creative juice flowing.
My Stuff: FB/Falcon CT63+CTPCI_ATI_RTL8139 14+512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
TheNameOfTheGame
Atari God
Atari God
Posts: 1059
Joined: Mon Jul 23, 2012 8:57 pm
Location: Almost Heaven, West Virginia

Re: Help opening a window in Pure C

Postby TheNameOfTheGame » Thu Oct 05, 2017 11:56 pm

Thanks, I'm working through Peter Lane's guide now and adjusting it from AHCC to PureC. Last time I programmed GEM was over 20 years ago and that was in machine code. :lol:

It's starting to come back to me though. I'll go through the thread you linked. It seems like it will be very helpful! :cheers:

User avatar
TheNameOfTheGame
Atari God
Atari God
Posts: 1059
Joined: Mon Jul 23, 2012 8:57 pm
Location: Almost Heaven, West Virginia

Re: Help opening a window in Pure C

Postby TheNameOfTheGame » Fri Oct 06, 2017 1:04 pm

nvm...I found the answer in the Compendium! :cheers:

User avatar
TheNameOfTheGame
Atari God
Atari God
Posts: 1059
Joined: Mon Jul 23, 2012 8:57 pm
Location: Almost Heaven, West Virginia

Re: Help opening a window in Pure C

Postby TheNameOfTheGame » Tue Oct 10, 2017 12:09 am

After a couple days getting back into GEM, I have a functional window which can be moved around, resized, use the sliders, etc.

I was working with Peter Lane's AHCC guide, but I am using PureC so it required some changes. Also I made it simpler than Peter's. All the code is in one file. I attached the code and project file here if anyone wants to look at it. It is just a proof of concept as I am learning to program GEM in C and is not optimized.

However, there is one question I have. Printing the text in the window is by "v_gtext". However, I have to add some fudge factors to it to get the text in the work area of the window.

Code: Select all

      v_gtext( phys_handle, wrkx - (cols_offset * charw), wrky - 4 + (charh * ( i + 1 )), win_text[i + rows_offset] );


I am getting wrkx and wrky from:

Code: Select all

   wind_get( win_handle, WF_WORKXYWH, &wrkx, &wrky, &wrkw, &wrkh );


But if I don't add the fudge factor, wrky - 4 + charh * ( i + 1 ) it prints the first line under the info line. I have to start the first line basically 1 extra line down from wrky.
Without the other fudge factor wrky - 4 + charh * ( i + 1 ) it prints 4 pixel lines down from the bottom of the info bar.

With Fudge Factors__________________________________________Without Fudge Factor 1
Image Image

Anyone know why that is?

TEST.zip
You do not have the required permissions to view the files attached to this post.

User avatar
wongck
Ultimate Atarian
Ultimate Atarian
Posts: 12005
Joined: Sat May 03, 2008 2:09 pm
Location: Far East
Contact:

Re: Help opening a window in Pure C

Postby wongck » Tue Oct 10, 2017 11:01 am

Looks correct to me. It's your text alignment.
So if you write at 0,0 ( or your top left corner work space) then your last row of pixel of your text will be at row 0.
Take a look at vst_alignment(), if it makes sense to you.
My Stuff: FB/Falcon CT63+CTPCI_ATI_RTL8139 14+512MB 30GB HDD CF HxC_SD/ TT030 68882 4+32MB 520MB Nova/ 520STFM 4MB Tos206 SCSI
Shared SCSI Bus:ScsiLink ethernet, 9GB HDD,SD-reader @ http://phsw.atari.org
My Atari stuff for sale - click here for list

User avatar
TheNameOfTheGame
Atari God
Atari God
Posts: 1059
Joined: Mon Jul 23, 2012 8:57 pm
Location: Almost Heaven, West Virginia

Re: Help opening a window in Pure C

Postby TheNameOfTheGame » Tue Oct 10, 2017 2:48 pm

Ah, thanks. I looked at vst_alignment and see what you are saying.

That makes much more sense now. :D


Social Media

     

Return to “C / PASCAL etc.”

Who is online

Users browsing this forum: No registered users and 0 guests