English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 28 June 2008, 20:15   #21
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
Code and a weird ASM command

Hey guys

I sent this as a PM to Stingray, but answer here if you prefer

I decided I will resource the croak exe.. partly to fix the issues and also to find how it works!

It seems 100% system legal and uses system libraries etc. Take a look at the following code which is really early on.

Code:
 
lbC008376    BSR.B    lbC0083F4
    LEA    (lbL023ECC).L,A1
    LEA    (lbL023ECC).L,A2
    CMPA.L    A1,A2    ;Compare and branch if not equal, which wont happen as they are equal, same addy
    BNE.B    lbC008396
    MOVE.W    #$4A4,D1    ;1108 bytes for loop
    BMI.B    lbC008396
    MOVEQ    #0,D2    ;Put 0 into d2
lbC008390    MOVE.L    D2,(A1)+    ;Copy 0 to address in a1, then increment for 1188 bytes
    DBRA    D1,lbC008390    ;loop
lbC008396    MOVE.L    SP,(lbL025114).L
    MOVEA.L    (AbsExecBase).W,A6
    MOVE.L    A6,(_ExecBase).L
    MOVEM.L    D0/A0,-(SP)
    BTST    #4,($129,A6)
    BEQ.B    lbC0083C2
    LEA    (lbC0083BC,PC),A5
    JSR    (_LVOSupervisor,A6)
    BRA.B    lbC0083C2

lbC0083BC    CLR.L    -(SP)
    FRESTORE    (SP)+
    RTE

lbC0083C2    LEA    (doslibrary.MSG,PC),A1
    JSR    (_LVOOldOpenLibrary,A6)
    MOVE.L    D0,(_DOSBase).L
    BNE.B    lbC0083DE
    MOVE.L    #$38007,D7
    JSR    (_LVOAlert,A6)
    BRA.B    lbC0083E4

lbC0083DE    JSR    (lbC0083FC).L
lbC0083E4    ADDQ.W    #8,SP
    RTS

doslibrary.MSG    dc.b    'dos.library',0
Firstly the first couple lines load the same address in a1 and a2 then compares, now they are going to be the same, so I am guess it then runs some sort of delay using the dbra? no?


Also when it jumps into Supervisor mode what the hell is the FRESTORE command all about, I can't find any info on it!

And why is it btst #4,($129,a6)
BippyM is online now  
AdSense AdSense  
Old 28 June 2008, 20:32   #22
Galahad/FLT
Going nowhere

Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 44
Posts: 6,603
That BTST is for a processor check, I 'think' its an 030/040 check

the FRESTORE is probably a resource label put in, the previous instruction, clears a longword on the stack, and the FRESTORE (which should be code, look at it Action Replay to see what it is), resets the stack pointer from the use of the clr.l -(a7) instruction, or the stack will be misaligned when the RTE triggers.

the use of the dbra is to clear memory
Galahad/FLT is online now  
Old 28 June 2008, 20:39   #23
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 42
Posts: 19,934
It checks for FPU, FRESTORE = FPU command.

AttnFlags bits:

#define AFB_68010 0 /* also set for 68020 */
#define AFB_68020 1 /* also set for 68030 */
#define AFB_68030 2 /* also set for 68040 */
#define AFB_68040 3
#define AFB_68881 4 /* also set for 68882 */
#define AFB_68882 5
#define AFB_FPU40 6 /* Set if 68040 FPU */
(7 = 68060)
Toni Wilen is offline  
Old 28 June 2008, 20:43   #24
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,586
Quote:
Originally Posted by Galahad/FLT View Post
That BTST is for a processor check, I 'think' its an 030/040 check
The btst is a check for an fpu. (bit4=1: 68881 fpu present)

Quote:
the FRESTORE is probably a resource label put in, the previous instruction, clears a longword on the stack, and the FRESTORE (which should be code, look at it Action Replay to see what it is), resets the stack pointer from the use of the clr.l -(a7) instruction, or the stack will be misaligned when the RTE triggers.
FRESTORE is an fpu instruction, it loads the internal registers with a specified state frame. This is probably all compiler stuff so you can ignore it as I doubt that the game uses the fpu.

Edit: damn, Toni beat me.
StingRay is offline  
Old 28 June 2008, 20:45   #25
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
thanks guys.. Can anyone tell me why it only executes supervisor mode if the FPU exists?
BippyM is online now  
Old 28 June 2008, 20:47   #26
Galahad/FLT
Going nowhere

Galahad/FLT's Avatar
 
Join Date: Oct 2001
Location: United Kingdom
Age: 44
Posts: 6,603
You have to be in supervisor mode to modify caches and use FPU, just the way the 68000 series is designed.
Galahad/FLT is online now  
Old 28 June 2008, 20:48   #27
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,586
That's because frestore is a privileged instruction.
StingRay is offline  
Old 28 June 2008, 20:48   #28
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
ah so basically this code is simply disabling the fpu?
BippyM is online now  
Old 28 June 2008, 20:53   #29
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,586
No I'm pretty sure it just restores FPU state, i.e. there should be an FSAVE instruction somewhere in the code as well. See it as the fpu equivalent to movem.l d0-a6,-(a7) (FSAVE) and movem.l (a7)+,d0-a6 (FRESTORE).
StingRay is offline  
Old 28 June 2008, 20:54   #30
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
ahhh so that is most likely before hand

why does the game compare the same address (a0/a1)? It is obvious they will be the same if loaded with the same address and nothing is modified during the lea address,ax and the cmpa.l
BippyM is online now  
Old 28 June 2008, 20:55   #31
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,586
No idea, probably some "clever" compiler stuff ;D
StingRay is offline  
Old 28 June 2008, 20:56   #32
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
hmmm or not!

Serves no purpose as the code is going to be executed anyway!
BippyM is online now  
Old 28 June 2008, 20:57   #33
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,586
That's why I put "clever" in quotation marks. I've seen quite a lot of "clever" compiler code, Amiga compilers are particular good at that
StingRay is offline  
Old 28 June 2008, 21:09   #34
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
i'll remove that bit of code then speed up loading by a microsecond lol
BippyM is online now  
Old 28 June 2008, 21:49   #35
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
decided to merge the 2 threads

Right next bit of code I think I have, but lets see to be sure!

the game does the following

Code:
	PEA ($10000).l			;Poke address $10000 onto stack
	move.w	(LBW023eBC),d0		; 14 bytes into d0
	MULS	#6,d0			; Multiply by 6
	move.l do,-(sp)			; put d0 on the stack
	jsr	(_Allocatemem).l	; Allocmem

_Allocatemem	movem.l	(4,sp),D0/D1	; add 4 to the stack and move to d0 then d1.. what goes into each? $78 and $10000?
	Movea.l	(_ExecBase).l,a6	;Exec into a6
	jmp	(_LVOAllocmem,a6)
Basically I'm understanding PEA and stack usage here.. once I can get my head around that i'll be pleased
BippyM is online now  
Old 28 June 2008, 21:54   #36
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,586
Nothing too complex here. If you know that AllocMem takes 2 parameters (d0: size to allocate, d1: type of mem) then you shouldn't have problems to understand the code.
StingRay is offline  
Old 28 June 2008, 21:55   #37
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
I understand that, it's what is being moved into d0/d1 from the stack

The stack is quite complex I think
BippyM is online now  
Old 28 June 2008, 21:58   #38
StingRay
move.l #$c0ff33,throat

StingRay's Avatar
 
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 5,586
Yes I know that you meant that and still, read my post above and it answers your question. (hint: MEMF_CLEAR: 1<<16 = 65536 = $10000)
StingRay is offline  
Old 28 June 2008, 22:01   #39
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
so it is allocating 78bytes of best-Available ram!

Hmmm.. i'm figuring stack out more than anything.. it's the movem.l(4,sp)d0/d1 as I presume it adds 4 to the stack.. which is kinda backwards to me
BippyM is online now  
Old 28 June 2008, 22:21   #40
BippyM
Global Moderator

BippyM's Avatar
 
Join Date: Nov 2001
Location: Nottingham, UK
Age: 42
Posts: 8,621
Weird the stack is upside bloody down... a bit of light reading will help.. thanks redskulldc

edit: how do I know what size the stack is if it is not set?
BippyM is online now  
AdSense AdSense  
 


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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Darkmere WHD Problem Steve support.Games 7 06 March 2013 16:46
Possible problem with Battle Squadron WHD jimmy2x2x project.WHDLoad 8 20 May 2011 22:08
WHD-Problem Cannibalpinhead support.Games 1 14 November 2005 20:16
WHD Games Problem Shinobi support.WinUAE 2 24 September 2003 12:24
Same problem w several WHD installs benjamin79 support.Games 6 30 November 2002 22:14

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 01:42.


Powered by vBulletin® Version 3.8.8 Beta 1
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Page generated in 0.21344 seconds with 12 queries