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

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4941
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #90 on: May 11, 2023, 02:24:19 pm »
Thanks Lars. Seems that this sample will be hard for me to compile or even to try to port it to 32bits.

On a general thing I would like to have more documentation of which is the old API and which is the new one, to try to document it clearly on the EDM/2 wiki.
For the moment my reference is the EDM/2 wiki where I tried to separate the current CPI API from the 1.x one. http://www.edm2.com/index.php/Control_Program_Functions_(Summary)
But it would be very useful to have some source that says something like XXXX function had been replaced by xxxx function. I remember some old Magazine article with some partial documentation when OS/2 2.0 was released, but it was not much. Maybe it is under my nose, but I can not see it.

This article for example shows Semaphores functions on 1.x and 2.0: https://books.google.com.ec/books?id=NsgmyHnvDmUC&pg=PA428&redir_esc=y#v=onepage&q&f=false

Regards
« Last Edit: May 11, 2023, 03:00:35 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4987
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #91 on: May 11, 2023, 04:31:45 pm »
One thing I have been doing is searching for these functions in WATCOM\h. For example, from WATCOM\h\os21x\bsedos.h
Code: [Select]
typedef struct _DOSFSRSEM {
    USHORT cb;
    PID    pid;
    TID    tid;
    USHORT cUsage;
    USHORT client;
    ULONG  sem;
} DOSFSRSEM, FAR *PDOSFSRSEM;

Not the best documentation but at least it shows a function only exists in the 1.x API.
Also, I'd assume that Watcom could build the 16 bit examples.

Lars

  • Hero Member
  • *****
  • Posts: 1352
  • Karma: +69/-0
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #92 on: May 11, 2023, 05:04:21 pm »
Thanks Lars. Seems that this sample will be hard for me to compile or even to try to port it to 32bits.

On a general thing I would like to have more documentation of which is the old API and which is the new one, to try to document it clearly on the EDM/2 wiki.
For the moment my reference is the EDM/2 wiki where I tried to separate the current CPI API from the 1.x one. http://www.edm2.com/index.php/Control_Program_Functions_(Summary)

The 16-bit functions are all listed here: http://www.edm2.com/index.php/Category:Dos16
There might not be a staight 1:1 match between old 16-bit and new 32-bit.
Of course, you can still build the 16-bit examples. But you would not want to. If at all possible, convert them all to 32-bit. The only thing that comes to mind where you have to go through hoola hoops is when you try to run IOPL code (straight reads/write from/to IO ports). That still requires the core code to be 16-bit. And that in turn requires thunking so that you can call that from 32-bit code. But that's for another day (and I can provide example code as have done others).
« Last Edit: May 11, 2023, 05:07:24 pm by Lars »

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4941
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #93 on: May 15, 2023, 07:21:24 pm »
The 16-bit functions are all listed here: http://www.edm2.com/index.php/Category:Dos16

Thanks Lars, in fact it was under my nose. I will check the samples and try to compare the DOS functions calls to see if something can be improved.

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

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4941
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #94 on: May 15, 2023, 07:28:16 pm »
Hi

I'm trying to do a different thing now, instead of sample I want to compile a little PM game. I also want to compile it with gcc and see if it keeps working.
- https://github.com/OS2World/GAME-PUZZLE-PM_Robots

If I use wrc, it does not end the procedure.  I have only this three warnings left that I don't know how to solve.

Code: [Select]
gcc -Wall -Zomf -c -O2 robots.c -o robots.obj
robots.c: In function 'ClientWndProc':
robots.c:77:27: warning: unused variable 'hwndScore' [-Wunused-variable]
   77 |     static HWND hwndMenu, hwndScore;
      |                           ^~~~~~~~~
At top level:
robots.c:77:27: warning: 'hwndScore' defined but not used [-Wunused-variable]
gcc -Wall -Zomf -c -O2 game.c -o game.obj
game.c: In function 'NewLevel':
game.c:70:17: warning: implicit declaration of function 'AvailableMoves' [-Wimplicit-function-declaration]
   70 |    pgs->moves = AvailableMoves(*pgs);
      |                 ^~~~~~~~~~~~~~
game.c: In function 'Direction':
game.c:244:1: warning: control reaches end of non-void function [-Wreturn-type]
  244 | }
      | ^
gcc -Wall -Zomf -c -O2 hiscores.c -o hiscores.obj
wrc -r robots.rc
Open Watcom Windows and OS/2 Resource Compiler Version 2.0beta4 LA GKYMar  2 2022
Portions Copyright (c) 1993-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
robots.rc(73): Error! E049: Syntax error near "CTEXT"
robots.rc(91): Error! E049: Syntax error near "CTEXT"
make: *** [robots.res] Error 8

If I switch to rc.exe it compiles, but the executable does gives a POPUPLOG error.

Code: [Select]
05-15-2023  12:18:41  SYS3171  PID 0250  TID 0001  Slot 0082
C:\DEV\GAME-PUZZLE-PM_ROBOTS\ROBOTS.EXE
c0000005
000104db
P1=00000002  P2=0002fffc  P3=XXXXXXXX  P4=XXXXXXXX 
EAX=0000000d  EBX=80000170  ECX=00010250  EDX=00000001
ESI=1b32e89c  EDI=00031c80 
DS=0053  DSACC=d0f3  DSLIM=9fffffff 
ES=0053  ESACC=d0f3  ESLIM=9fffffff 
FS=150b  FSACC=00f3  FSLIM=00000030
GS=0000  GSACC=****  GSLIM=********
CS:EIP=005b:000104db  CSACC=d0df  CSLIM=9fffffff
SS:ESP=0053:00030000  SSACC=d0f3  SSLIM=9fffffff
EBP=00030bc8  FLG=00010206

ROBOTS.EXE 0001:000004db

Any tip is welcome to see if this can compile. It seems that is also something that was from the 1.x era, i just want to see if it can easily be working under these conditions (gcc), otherwise I will move on.

Regards

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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4987
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #95 on: May 15, 2023, 07:37:37 pm »
These sys3171's seem to be caused by too small of a stack. Remove the stack directive from the def file and it uses the default of a 1MB stack and seems to run fine. I'd suggest usually going with the default stack size. Adding -Zmap to the LDFLAGS will show the stack size at the bottom,
Code: [Select]
                        +-----------------------+
                        |   Linker Statistics   |
                        +-----------------------+

Stack size:  00100000 (1048576.)
Memory size:  00103ab0 (1063600.)
Entry point address: 0001:00000000
Link time: 00:00.06
Not sure about the problem with wrc.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4987
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #96 on: May 15, 2023, 07:58:14 pm »
The rc needs some commas according to the help, under differences from the IBM Resource Compiler,
Code: [Select]
--- ROBOTS.RC.orig      2023-05-15 10:54:30.000000000 -0700
+++ ROBOTS.RC   2023-05-15 10:54:44.000000000 -0700
@@ -70,7 +70,7 @@
    DIALOG "Help for Presentation Manager Robots",0,16,12,320,124,, FCF_TITLEBAR|FCF_DLGBORDER
       {
       CTEXT "Presentation Manager Robots"       -1, 60, 108, 200, 8
-      ICON ID_RESOURCE                          -1, 60, 100,   0, 0
+      ICON ID_RESOURCE,                          -1, 60, 100,   0, 0
       CTEXT "Keep Smiley alive by keeping"      -1, 10,  92, 300, 8
       CTEXT "him away from the Killer Robots."  -1, 10,  84, 300, 8
       CTEXT "The left mouse button moves Smiley in the direction of the pointer
." -1, 10, 68, 300, 8
@@ -88,7 +88,7 @@
    DIALOG "About Presentation Manager Robots",0,32,24,240,100,, FCF_TITLEBAR|FCF_DLGBORDER
       {
       CTEXT "Presentation Manager Robots v1.3"          -1, 30, 84, 180, 8
-      ICON ID_RESOURCE                                  -1, 16, 76,   0, 0
+      ICON ID_RESOURCE,                                  -1, 16, 76,   0, 0
       CTEXT "This game is free software."                -1, 30, 68, 180, 8
       CTEXT "Copyright (c) 1993,1994 by Kent Lundberg"  -1, 30, 58, 180, 8
       CTEXT "Freely copy and distribute this program."  -1, 20, 44, 200, 8

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4941
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #97 on: May 15, 2023, 09:33:19 pm »
Thanks Dave

With you two suggestions, the game compiled.
It runs but sadly the functionality is not fully working. The smiley only goes to the left and the buttons on the menu are not working. (even if I tried the original source code without my changes to remove the warnings). So, this game requires more work to come from the 16bits world to be compiled with a 32bits gcc.

I will keep checking it out to see if something can be worked out, otherwise I will move on.

Thanks a lot.
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4941
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #98 on: May 15, 2023, 09:43:52 pm »
...wait...wait... changing the USHORT for ULONG made the game work.

Seems to be working fine, the movement and the menus. I'm testing it right now. Nice.

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

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4941
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #99 on: May 15, 2023, 10:03:49 pm »
Hi

I need some help to know how to remove this two warnings:
Code: [Select]
game.c:70:17: warning: implicit declaration of function 'AvailableMoves' [-Wimplicit-function-declaration]
   70 |    pgs->moves = AvailableMoves(*pgs);
      |                 ^~~~~~~~~~~~~~
game.c: In function 'Direction':
game.c:244:1: warning: control reaches end of non-void function [-Wreturn-type]
  244 | }
      | ^

And also, I don't know why the game renders the "smiley face" and the "diamond" image wrong. If I open the BMP with PMView it looks fine, if I open it with the regular viewer, it looks wrong.

Regards
« Last Edit: May 15, 2023, 10:22:44 pm by Martin Iturbide »
Martin Iturbide
OS2World NewsMaster
... just share the dream.

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4987
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #100 on: May 15, 2023, 10:35:02 pm »
Using rc instead of wrc seems to fix it, though I'm not sure how the original looked.
One warning fix,
Code: [Select]
--- GAME.C.orig 2023-05-15 13:33:18.000000000 -0700
+++ GAME.C      2023-05-15 13:32:30.000000000 -0700
@@ -242,6 +242,7 @@
          return (gs.moves&MOVE_DR ? IDP_DOWNRIGHT : IDP_NOMOVE);

    }
+   return 0;
 }

 int AvailableMoves(GAMESTATE gs) {

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4941
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #101 on: May 16, 2023, 01:29:34 am »
Hi Dave

The one in the left is compiled by me, the one on the right is the original one.
The smiley face (and diamonds that around it) should be in color, but I don't know why they are downscale to two colors.

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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4987
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #102 on: May 16, 2023, 01:59:03 am »
Almost seems like a different pallette is being used. Open the diamond.bmp or player.bmp and they're in black and white with 2 colours.

Martin Iturbide

  • OS2World NewsMaster
  • Global Moderator
  • Hero Member
  • *****
  • Posts: 4941
  • Karma: +44/-1
  • Your Friend Wil Declares...
    • View Profile
    • Martin's Personal Blog
Re: Compiling a PM sample with GCC (2023)
« Reply #103 on: May 16, 2023, 02:25:19 am »
Almost seems like a different pallette is being used. Open the diamond.bmp or player.bmp and they're in black and white with 2 colours.
But if you open those files with PMView, they look in color, just like the image on the right.

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

Dave Yeo

  • Hero Member
  • *****
  • Posts: 4987
  • Karma: +110/-1
    • View Profile
Re: Compiling a PM sample with GCC (2023)
« Reply #104 on: May 16, 2023, 04:27:46 am »
Yes, when I open the folder, the colours are correct, if I then open them with the Picture Editor, they're in black and white.
I don't have PMView but IIRC, you can convert the images from OS/2 v1 bmp to OS/2 v2 bmp, might be worth trying, or changing the palette. I tried with Embelish but it crashed with a sys3175.