03 February 2014, 10:52 | #21 |
ex. demoscener "Bigmama"
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
|
and the reason why it crashes on exit is, as mentioned before, that the program doesn't reply to the workbench message.
|
03 February 2014, 11:36 | #22 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
How to get and reply to the WBStartup Message is covered in the Amiga ROM Kernel Manual: Libraries.
It's not too difficult: - Get a pointer to your Process structure, either read the ThisTask field in ExecBase or call FindTask(0). - Check the pr_CLI field. If that's zero, you're being run from Workbench. - In that case, call GetMsg() on your pr_MsgPort. Save the return value. - When your program exits, if you've been run from Workbench don't put a return value in D0 and RTS. Instead you need to call Forbid() then ReplyMsg() to the WBStartup message you saved earlier. Workbench handles unloading your program. Steve: If you post your current source code I'll add support for being run from Workbench to it. Last edited by mark_k; 03 February 2014 at 11:46. |
03 February 2014, 11:51 | #23 | |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
Quote:
|
|
03 February 2014, 19:59 | #24 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
Here is the latest source code.
|
03 February 2014, 20:20 | #25 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
Here's a modified version with support for running from Workbench. I didn't assemble or test it yet.
Edit to add: To use FindTask instead of the ExecBase ThisTask field to get a pointer to your Task/Process, instead of Code:
start movea.l _AbsExecBase.w,a6 move.l ThisTask(a6),a0 Code:
start moveq #0,d0 CALLSYS FindTask,_AbsExecBase movea.l d0,a0 Last edited by mark_k; 03 February 2014 at 20:29. |
03 February 2014, 20:27 | #26 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
|
03 February 2014, 20:30 | #27 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
It says missing close bracket on line 18. lea (pr_MsgPort,a0),a0
|
03 February 2014, 21:11 | #28 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
Whoops I used new-style syntax for that line. You can change it to
lea pr_MsgPort(a0),a0 or alternatively/equivalently adda.w #pr_MsgPort,a0 |
03 February 2014, 21:33 | #29 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
Thanks its getting there. I have had to add a few of the new library calls (like _LVOFindTask) to Defines2.i and I'm left with a couple of errors regarding pr_CLI and pr_MsgPort. Undefined symbol. Do I need to declare these as well?
Ok I managed to get it to compile and run properly by adding the 'INCLUDE dos/dosextens.i' line to the top of the program. Odd thing is it still says program failed suspend/reboot (on program exit) on my standard Wb 3.1 setup but still on my emulated uaegfx display it doesn't crash on exit. Strange but not really a big deal I guess. Last edited by Steve; 03 February 2014 at 22:10. |
03 February 2014, 22:12 | #30 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
Can you post your current executable here, I'll take a look at it with ReSource (a disassembler).
|
04 February 2014, 09:53 | #31 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
Ok, thanks. I just created a new executable and tried to run it again on my uaegfx wb setup and got the suspend/reboot message. Its like I'm not releasing some memory or something. Really odd. Anyway here is the new executable.
|
04 February 2014, 13:29 | #32 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
D'oh! I used the wrong address register for ReplyMsg. (Why did Commodore use A0 for GetMsg, but A1 for ReplyMsg???)
Before CALLSYS ReplyMsg,_AbsExecBase change movea.l d0,a0 to movea.l d0,a1 |
04 February 2014, 14:08 | #33 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
Hehe. I bet these kind of mistakes are sooooo easy to make in assembler. I'm from a C++/Java programming background so all this low-level stuff is new to me. I will try it out tonight and let you know how I get on.
|
05 February 2014, 10:31 | #34 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
I made the change but this program seems determined to crash on exit. Oh well. Thanks for trying.
|
05 February 2014, 12:21 | #35 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
Okay I think I missed one more thing. When you're getting the WBStartup message, you need to call WaitPort() before GetMsg(). At least, from looking at the code in several other programs that's what they do. Also, what I said before about execution not returning to your program after you ReplyMsg() to the WBStartup message was wrong. Change the start of your program to this: Code:
start moveq #0,d0 CALLSYS FindTask,_AbsExecBase movea.l d0,a2 tst.l pr_CLI(a2) bne.b run_from_cli lea pr_MsgPort(a2),a0 CALLSYS WaitPort,_AbsExecBase lea pr_MsgPort(a2),a0 CALLSYS GetMsg,_AbsExecBase move.l d0,wbstartupmsg Save for later run_from_cli ... |
06 February 2014, 11:26 | #36 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
Still no joy. However I did find this in the how to code AGA docs:
Code:
3. Your code won't run from an icon. ==================================== You stick an icon for your new demo (not everyone uses the CLI!) and it either crashes or doesn't give back all the RAM it uses. Why? Icon startup needs specific code to reply to the workbench message. With the excellent Hisoft Devpac assember, all you need to do is add the line include "misc/easystart.i" and it magically works! For those without Devpac, here is the relevent code: Code:
* some startup code to make a Workbench execute look like the CLI * based loosely on RKM Vol 1 page 4-36 * Include this at the front of your program * after any other includes * note that this needs exec/exec_lib.i IFND EXEC_EXEC_I include "exec/exec.i" ENDC IFND LIBRARIES_DOSEXTENS_I include "libraries/dosextens.i ENDC movem.l d0/a0,-(sp) save initial values clr.l returnMsg sub.l a1,a1 move.l 4.w,a6 jsr _LVOFindTask(a6) find us move.l d0,a4 tst.l pr_CLI(a4) beq.s fromWorkbench * we were called from the CLI movem.l (sp)+,d0/a0 restore regs bra end_startup and run the user prog * we were called from the Workbench fromWorkbench lea pr_MsgPort(a4),a0 move.l 4.w,a6 jsr _LVOWaitPort(A6) wait for a message lea pr_MsgPort(a4),a0 jsr _LVOGetMsg(A6) then get it move.l d0,returnMsg save it for later reply * do some other stuff here RSN like the command line etc nop movem.l (sp)+,d0/a0 restore end_startup bsr.s _main call our program * returns to here with exit code in d0 move.l d0,-(sp) save it tst.l returnMsg beq.s exitToDOS if I was a CLI move.l 4.w,a6 jsr _LVOForbid(a6) move.l returnMsg(pc),a1 jsr _LVOPermit(a6) exitToDOS move.l (sp)+,d0 exit code rts * startup code variable returnMsg dc.l 0 * the program starts here even _main |
06 February 2014, 13:06 | #37 |
Registered User
Join Date: Aug 2004
Location:
Posts: 3,335
|
I think I've finally noticed what the problem is. Please just kill me if it still doesn't work after this change!
FindTask takes its argument in A1, not D0. So replace the moveq #0,d0 before calling FindTask with suba.l A1,A1 instead. By the way, there's a typo in the code you quoted. It calls Permit instead of ReplyMsg at the end. |
06 February 2014, 21:08 | #38 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
Hallelujah, praise the lord, IT WORKS!! Thank you!!
Program attached. |
07 February 2014, 08:35 | #39 |
I Identify as an Ewok
Join Date: Jul 2001
Location: North Lincolnshire
Age: 45
Posts: 2,356
|
I'm not too sure what the line suba.l a1,a1 is actually doing. I understand it means subtract address. It seems to me that it is simply clearing the resister to 0 or is it more than that? If so why not just use move.l #0,a1?
|
07 February 2014, 10:40 | #40 |
Natteravn
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,496
|
suba.l a1,a1 is shorter (2 bytes instead of 6 bytes) and faster (6 cycles instead of 12 cycles on the 68000).
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
My old source code | gemanix | Coders. General | 36 | 09 July 2017 13:33 |
DoomAttack source code | MickJT | support.Games | 10 | 15 October 2013 13:03 |
Source Code | camelord | support.Games | 2 | 06 August 2010 17:45 |
the citadel source code | hippie2000 | Coders. General | 8 | 29 October 2007 15:10 |
Source Code | Thalion | project.WinUAE - Kaillera | 3 | 28 April 2006 09:55 |
|
|