Author Topic: Compiling a PM sample with GCC (2023)  (Read 99130 times)

Lars

  • Hero Member
  • *****
  • Posts: 1298
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #195 on: June 21, 2023, 09:54:37 am »
Just tried my built executable under Panorama: also works ok. Even with shadow buffer enabled. I am using 64k colors.
Also tried 16M colors, also works.
« Last Edit: June 21, 2023, 10:00:58 am by Lars »

Lars

  • Hero Member
  • *****
  • Posts: 1298
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #196 on: June 21, 2023, 09:56:31 am »
Hi Lars

I tried the compiled beehive.exe with different colors settings on my VM:
- with 16M does not run
- with 65K does not run
- with 256 does not run

What "does not run" means? it loads and exists quickly without showing anything on the screen. It does not produces any POPUPLOG. I don't know if I can take any other log.

Regards

The .PCX files need to be in the same directory as the EXE, of course.

Lars

  • Hero Member
  • *****
  • Posts: 1298
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #197 on: June 21, 2023, 10:02:10 am »
Cannot get a working executable built with gcc. It just won't do whatever I try. VAC rules !

Lars

  • Hero Member
  • *****
  • Posts: 1298
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #198 on: June 21, 2023, 10:15:12 am »
Ok, found the prob with gcc: the "fgetc" function as using in "ReadFile" seems to work differently in LIBC than for the VAC supplied library. It leads to an early abort when reading the file data. It might better be replaced by fread and reading only one character. Something is wrong with the "fgetc" function that LIBC provides ...

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4831
  • Karma: +101/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #199 on: June 21, 2023, 04:39:00 pm »
Hi Lars

I tried the compiled beehive.exe with different colors settings on my VM:
- with 16M does not run
- with 65K does not run
- with 256 does not run

What "does not run" means? it loads and exists quickly without showing anything on the screen. It does not produces any POPUPLOG. I don't know if I can take any other log.

Regards

Long story short: the executable that I attached works perfectly on my system. I am using eCS under Virtualbox. Even full screen support works but under Virtualbox, it does not make much sense (as it does not stretch across the full screen, of course).
I am using plain GENGRADD in the eCS guest (anything else will not improve performance anyways).
If you use Panorama: the problem is that Panorama and DIVE do not go together well. I think you will need to disable "shadow buffer". But of course, Panorama will then become totally unresponsive.

Actually, you didn't seem to attach an executable. Building your beehive_b3 with VACPP gives me a mostly working beehive.exe except the sprite isn't fully drawn, most noticeable when the sprite is moving left where it is just some dots. Full screen works as well.
What doesn't work is capturing a screen capture, get a grey screen.
I still see these warnings, which I'm not sure of the fix and may be the failure point, eg not reading the PCX files in binary mode would do it.
Code: [Select]
gcc -Wall -c -Zomf -g pcxload.c -o pcxload.obj
pcxload.c: In function 'ExtractPalette':
pcxload.c:61:26: warning: pointer targets in passing argument 1 of 'fopen' differ in signedness [-Wpointer-sign]
   61 |    if( ( pFile = fopen ( pszFile, "rb" ) ) == NULL )
      |                          ^~~~~~~
      |                          |
      |                          PSZ {aka unsigned char *}
In file included from pcxload.c:28:
W:/usr/include/stdio.h:280:7: note: expected 'const char * restrict' but argument is of type 'PSZ' {aka 'unsigned char *'}
  280 | FILE *fopen(const char * __restrict, const char * __restrict);
      |       ^~~~~
pcxload.c: In function 'ReadFile':
pcxload.c:246:26: warning: pointer targets in passing argument 1 of 'fopen' differ in signedness [-Wpointer-sign]
  246 |    if( ( pFile = fopen ( pszFile, "rb" ) ) == NULL )
      |                          ^~~~~~~
      |                          |
      |                          PSZ {aka unsigned char *}
In file included from pcxload.c:28:
W:/usr/include/stdio.h:280:7: note: expected 'const char * restrict' but argument is of type 'PSZ' {aka 'unsigned char *'}
  280 | FILE *fopen(const char * __restrict, const char * __restrict);

Here's the VACPP compiled binary, does it work for you Martin, might need to be run in the source directory
 
« Last Edit: June 21, 2023, 04:53:49 pm by Dave Yeo »

Lars

  • Hero Member
  • *****
  • Posts: 1298
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #200 on: June 21, 2023, 10:26:07 pm »
I did a final fix and now it correctly builds with gcc.
In the end, it was indeed a code error that needed to be fixed and funny enough it worked with VAC even though it should also have failed ...

Find the sources and the tweaked makefile attached.

Lars

  • Hero Member
  • *****
  • Posts: 1298
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #201 on: June 21, 2023, 10:28:44 pm »
Hi Lars

I tried the compiled beehive.exe with different colors settings on my VM:
- with 16M does not run
- with 65K does not run
- with 256 does not run

What "does not run" means? it loads and exists quickly without showing anything on the screen. It does not produces any POPUPLOG. I don't know if I can take any other log.

Regards

Long story short: the executable that I attached works perfectly on my system. I am using eCS under Virtualbox. Even full screen support works but under Virtualbox, it does not make much sense (as it does not stretch across the full screen, of course).
I am using plain GENGRADD in the eCS guest (anything else will not improve performance anyways).
If you use Panorama: the problem is that Panorama and DIVE do not go together well. I think you will need to disable "shadow buffer". But of course, Panorama will then become totally unresponsive.

Actually, you didn't seem to attach an executable. Building your beehive_b3 with VACPP gives me a mostly working beehive.exe except the sprite isn't fully drawn, most noticeable when the sprite is moving left where it is just some dots. Full screen works as well.
What doesn't work is capturing a screen capture, get a grey screen.
I still see these warnings, which I'm not sure of the fix and may be the failure point, eg not reading the PCX files in binary mode would do it.
Code: [Select]
gcc -Wall -c -Zomf -g pcxload.c -o pcxload.obj
pcxload.c: In function 'ExtractPalette':
pcxload.c:61:26: warning: pointer targets in passing argument 1 of 'fopen' differ in signedness [-Wpointer-sign]
   61 |    if( ( pFile = fopen ( pszFile, "rb" ) ) == NULL )
      |                          ^~~~~~~
      |                          |
      |                          PSZ {aka unsigned char *}
In file included from pcxload.c:28:
W:/usr/include/stdio.h:280:7: note: expected 'const char * restrict' but argument is of type 'PSZ' {aka 'unsigned char *'}
  280 | FILE *fopen(const char * __restrict, const char * __restrict);
      |       ^~~~~
pcxload.c: In function 'ReadFile':
pcxload.c:246:26: warning: pointer targets in passing argument 1 of 'fopen' differ in signedness [-Wpointer-sign]
  246 |    if( ( pFile = fopen ( pszFile, "rb" ) ) == NULL )
      |                          ^~~~~~~
      |                          |
      |                          PSZ {aka unsigned char *}
In file included from pcxload.c:28:
W:/usr/include/stdio.h:280:7: note: expected 'const char * restrict' but argument is of type 'PSZ' {aka 'unsigned char *'}
  280 | FILE *fopen(const char * __restrict, const char * __restrict);

Here's the VACPP compiled binary, does it work for you Martin, might need to be run in the source directory

Look here:
https://www.os2world.com/forum/index.php?action=dlattach;topic=3324.0;attach=9755

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4792
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #202 on: June 21, 2023, 10:41:01 pm »
Hi Lars.

Your "beehive_b4.zip " compile fine here under gcc with some warnings (I will check on those later). Now it loads and works (VM with 16M colors). The only thing is that bee looks bad (Picture attached), which means the PCX of the bee are not rendering fine. If I go down to 64K colors, it is the same.   Is that something in my machine?

But it is working now, that's good !!!

Regards

« Last Edit: June 21, 2023, 11:00:38 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4792
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #203 on: June 21, 2023, 10:53:56 pm »
Hi

Here goes my beehive_b5.zip, removed the warnings.

I did something with this warning:
Quote
beehive.c:346:16: warning: variable 'hdc' set but not used [-Wunused-but-set-variable]
  346 |    static HDC  hdc;                 // Device context for client window
      |                ^~~
hdc was used for:
  hdc = WinOpenWindowDC( hwnd );
I just commented out "static HDC  hdc;" leave it as
 WinOpenWindowDC( hwnd );

It keeps running, but I'm not sure if I did something harmless.

Regards

 
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Lars

  • Hero Member
  • *****
  • Posts: 1298
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #204 on: June 21, 2023, 10:57:09 pm »
reading the beehive readme, it sounded like the pictures are in fact "spotty".

There is another thing that showed up as a bug: the "rand" function is not reinitialized with the "seed" function. Which means, the "rand" function will always return the same result and therefore all bees will start to fly into the same direction.
Another fix to do ...

Funny enough, again, that worked with the VAC provided "rand". I assume that the VAC provided "rand" calls "seed" internally in case the programmer forgets ...

But the function definition of "rand" clearly states that you have to call "seed" every time before you call "rand" if you want to have random result.

Lars

  • Hero Member
  • *****
  • Posts: 1298
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #205 on: June 21, 2023, 10:59:54 pm »
Hi

Here goes my beehive_b5.zip, removed the warnings.

I did something with this warning:
Quote
beehive.c:346:16: warning: variable 'hdc' set but not used [-Wunused-but-set-variable]
  346 |    static HDC  hdc;                 // Device context for client window
      |                ^~~
hdc was used for:
  hdc = WinOpenWindowDC( hwnd );
I just commented out "static HDC  hdc;" leave it as
 WinOpenWindowDC( hwnd );

It keeps running, but I'm not sure if I did something harmless.

Regards

 

You can remove that whole call. The created hdc is not used anywhere in the code. A creating one without closing it is not a good idea anyways.

Lars

  • Hero Member
  • *****
  • Posts: 1298
  • Karma: +65/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #206 on: June 21, 2023, 11:30:49 pm »
And here is the last shot. I fxed the "rand" problem. Now the bees start off in different directions (hit the "h" key ...).
Hit the "f" key for toggling between desktop and fullscreen mode.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4792
  • Karma: +41/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #207 on: June 22, 2023, 06:30:04 pm »
Hello

I need a little help here with this TEMPLATE PM sample. It compiles with gcc and works, but with a trick, generating first the "main.res" and later compiling all together with the makefile. 

I need to know how from main.rc can I generate template.res from the makefile (there is no template.rc).

I guess it is something very simple on the makefile that I don't know how to do.

Regards
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4831
  • Karma: +101/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #208 on: June 23, 2023, 02:00:30 am »
Simple fix,
Code: [Select]
--- makefile.orig       2023-06-22 16:41:32.000000000 -0700
+++ makefile    2023-06-22 16:54:14.000000000 -0700
@@ -14,9 +14,9 @@

 all : template.exe

-template.exe: $(OBJS)
-       gcc -Zomf -Zmap $(OBJS) template.def main.res -o template.exe
-       wrc main.res
+template.exe: $(OBJS)  template.res
+       gcc -Zomf -Zmap $(OBJS) template.def template.res -o template.exe
+       wrc template.res

 main.obj: main.c $(HEADER)
        gcc $(CFLAGS) $(DEBUGFLAGS) main.c -o main.obj
@@ -45,8 +45,9 @@
 thrd.obj: thrd.c $(HEADERS)
        gcc $(CFLAGS) $(DEBUGFLAGS) thrd.c -o thrd.obj

-main.res: main.rc main.ico template.dlg help.rc prodinfo.bmp $(HEADERS)
+template.res: main.rc main.ico template.dlg help.rc prodinfo.bmp $(HEADERS)
        wrc -r main.rc
+       mv main.res template.res

 clean :
        rm -rf *exe *res *obj *lib *.hlp

Perhaps better solution,
Code: [Select]
--- makefile.orig       2023-06-22 16:41:32.000000000 -0700
+++ makefile    2023-06-22 16:58:54.000000000 -0700
@@ -14,9 +14,9 @@

 all : template.exe

-template.exe: $(OBJS)
-       gcc -Zomf -Zmap $(OBJS) template.def main.res -o template.exe
-       wrc main.res
+template.exe: $(OBJS) template.res
+       gcc -Zomf -Zmap $(OBJS) template.def template.res -o template.exe
+       wrc template.res

 main.obj: main.c $(HEADER)
        gcc $(CFLAGS) $(DEBUGFLAGS) main.c -o main.obj
@@ -48,5 +48,8 @@
 main.res: main.rc main.ico template.dlg help.rc prodinfo.bmp $(HEADERS)
        wrc -r main.rc

+template.res: main.res
+       $(shell mv main.res template.res)
+
 clean :
        rm -rf *exe *res *obj *lib *.hlp

Not sure if mv should have an argument or it could be cp instead, still might need an argument
Edit:fix typo
« Last Edit: June 23, 2023, 02:02:23 am by Dave Yeo »

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4831
  • Karma: +101/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #209 on: June 23, 2023, 02:50:12 am »
Reading up on it, we can make the makefile simpler,
Code: [Select]
# make makefile
#
# Tools used:
#  Compile::Resource Compiler
#  Compile::GNU C
#  Make: make

CFLAGS=-Wall -Zomf -c -O2
DEBUGFLAGS=-g
#CFLAGS+=$(DEBUGFLAGS)

HEADERS = main.h xtrn.h help.c
OBJS = main.o user.o init.o pnt.o dlg.o help.o file.o edit.o thrd.o
ALL_IPF = template.ipf file.ipf edit.ipf help.ipf dlg.ipf menu.ipf

all : template.exe

template.exe: $(OBJS) template.res
        gcc -Zomf -Zmap $(OBJS) template.def template.res -o $@
        wrc template.res

main.res: main.rc main.ico template.dlg help.rc prodinfo.bmp $(HEADERS)
        wrc -r main.rc

template.res: main.res
        $(shell mv main.res template.res)

.PHONY : clean

clean :
        rm -rf *exe *res *obj *.o *lib *.hlp *.map

The .PHONY thing is in case there is a file named clean and recommended.
To do is to have a debug target instead of commenting out the debugflags line.
Guess a help rule for the IPF's too