English Amiga Board


Go Back   English Amiga Board > Main > Nostalgia & memories

 
 
Thread Tools
Old 01 May 2023, 12:22   #21
Bruce Abbott
Registered User
 
Bruce Abbott's Avatar
 
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,819
Quote:
Originally Posted by hooverphonique View Post
Is it even possible to reliably identify that some binary was compiled from C? I mean, you can generally tell by the structure of the disassembly if it originally was compiled from a higher level language, or written directly in asm, but how would you identify it as originating from C?
There are some general features of C vs other languages that may be visible in the machine code, eg. how parameters are passed on the stack. But each compiler also produces code that produces a unique 'fingerprint' specific to that compiler. Blitz BASIC code looks very different to SASC code, which is quite different from gcc code etc.
Bruce Abbott is offline  
Old 01 May 2023, 12:32   #22
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,686
What Bruce said. A lot of compilers have intrinsics to support C language features that are quite easy to spot once you've seen them before.
Karlos is online now  
Old 01 May 2023, 13:35   #23
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,649
ok.. so the answer is "no" when using the qualifiers "generally" and "reliably", but f/a 18 is probably compiled using some well-known compiler :-)
hooverphonique is offline  
Old 07 May 2023, 14:41   #24
8bitbubsy
Registered User
 
8bitbubsy's Avatar
 
Join Date: Sep 2009
Location: Norway
Posts: 1,723
Quote:
Originally Posted by Karlos View Post
I dunno, this decade you only have to identify as a nerd, and anyone contradicting you is a vicious bigot that must be cancelled.
More truthful words have never been spoken... It's a weird time we live in.
8bitbubsy is offline  
Old 08 May 2023, 01:07   #25
Bruce Abbott
Registered User
 
Bruce Abbott's Avatar
 
Join Date: Mar 2018
Location: Hastings, New Zealand
Posts: 2,819
Quote:
Originally Posted by hooverphonique View Post
ok.. so the answer is "no" when using the qualifiers "generally" and "reliably", but f/a 18 is probably compiled using some well-known compiler :-)
F/A 18 appears to be ~1/3rd C and 2/3rds assembler. The C code looks like Lattice, which would make sense since it was the official compiler for the Amiga. To prove it I would have to compile some code with an early version of Lattice C and see what it produced.
Bruce Abbott is offline  
Old 08 May 2023, 21:29   #26
A500
Registered User
 
Join Date: Jun 2017
Location: Finland
Posts: 378
This discussion is very intriguing, like watching a detective story of sorts
A500 is offline  
Old 23 May 2023, 00:08   #27
ara
Registered User
 
Join Date: Oct 2009
Location: Belgium
Age: 50
Posts: 42
I found a function in the binary that is only called when some bytes are set to 1. I don't see them being written anywhere in the code, so I guess it's a function meant for debugging.

The attached picture shows the result. The small diagonal line in the top left corner is drawn every odd frame. The three-digit number is the frame rate (but not in fps, the base seems to be 800000). The other two numbers are the x and y input of the input controller.
Attached Thumbnails
Click image for larger version

Name:	interceptor_debug.png
Views:	125
Size:	18.6 KB
ID:	79104  

Last edited by ara; 23 May 2023 at 00:53.
ara is offline  
Old 24 May 2023, 00:15   #28
Ray Norrish
Registered User
 
Ray Norrish's Avatar
 
Join Date: May 2005
Location: Cheshire, UK
Age: 56
Posts: 322
I recall when you look at code made in pure assembler in a decompiler, it looks "clean" in comparison for want of a better word. I seemed to remember encountering BCD more frequently in non-ASM compiled code.
Also, there's frequently obvious bloat in higher level compilers. I expect that the exec stub would have some kind of uniqueness, as well as what sort of mem alloc pieces there are.
I expect one of the number of ex-crackers on here would recognise code structure from their typical tracing experiences.
Ray Norrish is offline  
Old 24 May 2023, 16:45   #29
ara
Registered User
 
Join Date: Oct 2009
Location: Belgium
Age: 50
Posts: 42
The compilers in the 1980s were not as much optimizing as the modern ones. For example, I don't remember to have ever seen loop unrolling in old compiled code. In addition, in code written in assembly language you can find structures that don't appear in compiled code. Typical example: code shared between several functions, like this:
Code:
function1:
     some instructions
function:
     some instructions
     rts
That said, I have to say that the parts of the Interceptor game written in assembly (most of the game core) look rather ugly (sorry dear author) and I definitely have a much harder time to annotate it with meaningful symbols and type names than I had with Starglider 2 and Carrier Command.

Do you know which game was written almost entirely in C? Populous. The code is very easy to read. I started translating it to Java and actually finished the game initialization and rendering part (see the attached picture), but at some point implementing all the game logic became too boring (so many "if"s....)
Attached Thumbnails
Click image for larger version

Name:	pop.png
Views:	94
Size:	169.6 KB
ID:	79115  
ara is offline  
Old 24 May 2023, 20:13   #30
qz3fwd
Registered User
 
Join Date: Oct 2022
Location: Shelby Township
Posts: 85
Doesn’t IDA Pro decompile nowadays? Last time I looked at it about 10+ years ago I thought it did?
qz3fwd is offline  
Old 24 May 2023, 21:13   #31
A500
Registered User
 
Join Date: Jun 2017
Location: Finland
Posts: 378
Quote:
Originally Posted by ara View Post
Do you know which game was written almost entirely in C? Populous.

Theoretically speaking, would this mean that the game could be further optimized at least to a modestly significant degree by hand-written assembler? I'm assuming here that the compiled C code from 1991 is not as efficient.
A500 is offline  
Old 24 May 2023, 23:08   #32
ara
Registered User
 
Join Date: Oct 2009
Location: Belgium
Age: 50
Posts: 42
Quote:
Originally Posted by A500 View Post
Theoretically speaking, would this mean that the game could be further optimized at least to a modestly significant degree by hand-written assembler?

Here is a fragment of C code that I reverse-engineered with the help of Ghidra. It comes from a function that flattens a 9x9 patch of land for the AI player:
Code:
(player->action).id = 2;  // land lowering action
(player->action).x = x;
(player->action).y = y;
player->moveDone = 1;
Looks clean, right? Here are the actual machine instructions from the binary of the game:
Code:
movea.l   (-0xe,A5),A0
move.b    #0x2,(A0)
movea.l   (-0xe,A5),A0
move.b    d4,(0x1,A0)
movea.l   (-0xe,A5),A0
move.b    d5,(0x2,A0)
movea.l   (-0xe,A5),A0
move.w   #0x1,(0x8,A0)
There are some optimization opportunities
ara is offline  
Old 24 May 2023, 23:10   #33
Karlos
Alien Bleed
 
Karlos's Avatar
 
Join Date: Aug 2022
Location: UK
Posts: 4,686
Quote:
Originally Posted by ara View Post
Here is a fragment of C code that I reverse-engineered with the help of Ghidra. It comes from a function that flattens a 9x9 patch of land for the AI player:
Code:
(player->action).id = 2;  // land lowering action
(player->action).x = x;
(player->action).y = y;
player->moveDone= 1;
Looks clean, right? Here are the actual machine instructions from the binary of the game:
Code:
movea.l   (-0xe,A5),A0
move.b    #0x2,(A0)
movea.l   (-0xe,A5),A0
move.b    d4,(0x1,A0)
movea.l   (-0xe,A5),A0
move.b    d5,(0x2,A0)
movea.l   (-0xe,A5),A0
move.w   #0x1,(0x8,A0)
There are some optimization opportunities
It looks like the compiler didn't apply subexpression elimination for the pointer dereference.
Karlos is online now  
Old 24 May 2023, 23:10   #34
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,398
okay but do you really need more speed on that game? Our elders knew that compilers were crap, so they wrote critical parts in assembly already.

if so, I suppose that one could disassemble, remove the useless instructions / write more efficient code, reassemble.

But first, you'd have to profile the code to see where you'd have the best gain, else it's a lot of work for unguaranteed results.

PS: great job with the RE of Populous nevertheless. Granted, re-making those games for modern platform has little interest as those modern platforms can already emulate the real game. Unless you add features (HD, extensions...) which is another story...
jotd is online now  
Old 24 May 2023, 23:21   #35
ara
Registered User
 
Join Date: Oct 2009
Location: Belgium
Age: 50
Posts: 42
Quote:
Originally Posted by jotd View Post
Granted, re-making those games for modern platform has little interest as those modern platforms can already emulate the real game
True. For me, it's just a leisure activity and a kind of archeology. It's fun to see how much game play they could squeeze into a few kbytes of code. If a remake or extended version were the goal, it would be more interesting to directly start from Populous 2.
ara is offline  
Old 25 May 2023, 08:56   #36
jotd
This cat is no more
 
jotd's Avatar
 
Join Date: Dec 2004
Location: FRANCE
Age: 52
Posts: 8,398
Another useful thing when resourcing is you can figure out how data is done and create level editors for the original engine.
jotd is online now  
Old Yesterday, 18:41   #37
Oli1974
Registered User
 
Join Date: Jun 2024
Location: Bogotá, Colombia
Age: 49
Posts: 7
Quote:
Originally Posted by Thomas Richter View Post
That is not a line drawer. This is a circle drawer
Here's my own ellipse algorithm (filled and outline) which I basically implemented to avoid layers.library's buggy clipping.

Code:
SUB DrwEll(BYVAL x,BYVAL y,BYVAL r1,BYVAL r2, BYVAL f) STATIC
    STATIC x1,x2,ax,bx,xa0,xb0,cy,y1,a,a!,b!,p1,p2,p3,r12!,r1i!,r2i!,x2!
    r12!=r1^2
    r1i!=1/r12!
    r2i!=1/r2^2
    x2!=x^2
    a!=x2!*r1i!
    IF a!+y^2*r2i!<=1 AND a!+(255-y)^2*r2i!<=1 AND (639-x)^2*r1i!+y^2*r2i!<=1 AND (639-x)^2*r1i!+(255-y)^2*r2i!<=1 THEN
        IF f THEN                                ' Ellipse bedeckt kompletten Bildschirm?
            SetRast sRastPort&,GetAPen(sRastPort&)                ' --> wenn Parameter "f": Bildschirm füllen
        END IF                                    ' sonst: gar nichts tun
    ELSEIF x+r1>-1 OR x-r1<640 OR y+r2>-1 OR y-r2<256 THEN                ' Ellipse potentiell sichtbar?
        b!=-2*x*r1i!
        p1=MAX(f-1,y-r2)
        p2=MIN(255,y)
        p3=1
        xa0=-2-f
        iter:
        FOR cy=p1 TO p2 STEP p3
            IF cy=y-r2 OR cy=y+r2 THEN                    ' erste und letzte Zeile der Ellipse
                a=SQR(r1*(r1/r2))>>1
                x1=MAX(f-1,x-a)
                x2=MIN(640-f,x+a)
            ELSEIF cy=y THEN                        ' Zeile auf Höhe des Mittelpunktes
                x1=MAX(f-1,x-r1)
                x2=MIN(640-f,x+r1)
            ELSE                                ' alle anderen Zeilen
                x1=(b!+SQR(b!*b!-4*r1i!*(a!+(cy-y)^2*r2i!-1)))*-r12!>>1
                  x2=MIN(640-f,x+(x-x1))
                  x1=MAX(f-1,x1)
              END IF
              IF xa0=-2 THEN                            ' Startpunkt für Outline setzen
                xa0=x2
                xb0=x1
            END IF
              IF x2>-1 AND x1<640 THEN
                  y1=y*2-cy
                  IF f THEN                        ' ausfüllen
                    Move sRastPort&,x1,cy
                    Draw sRastPort&,x2,cy
                    IF p3 AND y1<256 THEN                ' nach unten spiegeln
                        Move sRastPort&,x1,y1 
                        Draw sRastPort&,x2,y1
                    END IF
                ELSE                            ' Konturlinien
                    ax=MIN(639,MAX(0,xa0))                ' links
                    bx=MAX(0,x1)
                    IF cy>-1 AND cy<256 AND (ax<>bx OR xa0>-1) THEN
                        Move sRastPort&,ax,cy
                        Draw sRastPort&,bx,cy
                        IF p3 AND y1<256 THEN            ' nach links unten spiegeln
                            Move sRastPort&,ax,y1 
                            Draw sRastPort&,bx,y1
                        END IF
                    END IF
                    ax=MIN(639,MAX(0,xb0))                ' rechts
                    bx=MIN(639,x2)
                    IF cy>-1 AND cy<256 AND (ax<>bx OR xb0<640) THEN
                        Move sRastPort&,ax,cy 
                        Draw sRastPort&,bx,cy
                        IF p3 AND y1<256 THEN            ' nach rechts unten spiegeln
                            Move sRastPort&,ax,y1 
                            Draw sRastPort&,bx,y1 
                        END IF
                    END IF
                    xa0=x1
                    xb0=x2
                END IF
            END IF
        NEXT cy
        IF p3=1 AND y-r2<0 AND y+r2>-1 THEN                    ' wegen Clipping nicht gespiegelten Rest rendern
            p1=MIN(256-f,y+r2)
            p2=MAX(0,y*2+1)
            p3=-1
            xa0=-2-f
            GOTO iter                            ' 2. Durchgang
        END IF    
    END IF
END SUB
Oli1974 is offline  
Old Yesterday, 23:16   #38
Minuous
Coder/webmaster/gamer
 
Minuous's Avatar
 
Join Date: Oct 2001
Location: Canberra/Australia
Posts: 2,699
Which version of layers.library? IIRC ThoR has already fixed all the known bugs in it.
Minuous is offline  
Old Today, 00:40   #39
A500
Registered User
 
Join Date: Jun 2017
Location: Finland
Posts: 378
Quote:
Originally Posted by jotd View Post
okay but do you really need more speed on that game? Our elders knew that compilers were crap, so they wrote critical parts in assembly already.

Well, when I run the game on a stock A500, the title screen animation (where pieces of the landscape fall from the sky) could use a few more frames to make it appear a little less jerky
A500 is offline  
Old Today, 14:27   #40
Oli1974
Registered User
 
Join Date: Jun 2024
Location: Bogotá, Colombia
Age: 49
Posts: 7
Quote:
Originally Posted by Minuous View Post
Which version of layers.library?
Code:
6.Workbench> version layers.library full
layers.library 40.1 (15.02.1993)
Ok, that looks like the original OS 3.1 layers.library isn't even patched in OS 3.9 which I am running. Anyway, my code is even older than 3.1, and before that you could easily crash the system by drawing FAR outside a ClipRect so I needed to implement my own code for ellipses, lines, and boxes.
Oli1974 is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
Most advanced game by year? rothers Amiga scene 51 15 April 2022 20:47
Best Game of Year 2021 Solo Kazuki Amiga scene 13 28 February 2022 15:08
EAB Game of the year poll mcgeezer Amiga scene 20 15 December 2021 08:05
From What year to what year You can use a stock Commodore Amiga 500? The Brave Ant Nostalgia & memories 3 10 June 2014 18:34
AGTW game of the Year Dizzy project.EAB 6 23 December 2006 17:58

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 17:48.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.14507 seconds with 16 queries