English Amiga Board


Go Back   English Amiga Board > Coders > Coders. General

 
 
Thread Tools
Old 30 September 2019, 21:53   #1
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Startup code, taking over the system

So, I've decided the startup code I've been using is not the best. Is there an accepted standard piece of code that everyone is using to take over and return the system?

For context, this is what I'm currently using:

Code:
void TakeSystem(void) {
    KPrintF("In TakeSystem.\n");

    AndTen();

    ActiView = GfxBase->ActiView; // store current view

    OwnBlitter();
    WaitBlit();

    Disable();
    
    systemADKCON = custom->adkconr;
    systemINTENA = custom->intenar;
    systemDMACON = custom->dmaconr;

    custom->intena = INTF_INTEN | INTF_ALL; // disable all interrupts
    custom->intreq = INTF_INTEN | INTF_ALL; // clear any interrupts that were pending
    
    WaitVbl();
    WaitVbl();

    custom->dmacon = DMAF_SPRITE;

    LoadView(NULL);

    WaitTOF();
    WaitTOF();

    WaitVbl();
    WaitVbl();

    // save system interrupt handers
    for (int i = 0; i < 6; i++)
        systemInterruptHandlers[i] = VBR[25 + i];

    WaitVbl();
    
    custom->intena = INTF_INTEN | INTF_ALL; // disable all interrupts
    custom->intreq = INTF_INTEN | INTF_ALL; // clear any interrupts that were pending
}
Obviously I'm into C at the moment, I'll probably translate any assembly into that.
deimos is offline  
Old 03 October 2019, 11:57   #2
phx
Natteravn
 
phx's Avatar
 
Join Date: Nov 2009
Location: Herford / Germany
Posts: 2,500
Looks good so far, although I don't know why you disable interrupts twice.

Additionally you may want to reset FMODE and BPLCONx to standard values, in case you have to disable AGA/ECS.
phx is offline  
Old 03 October 2019, 12:08   #3
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Quote:
Originally Posted by phx View Post
Looks good so far, although I don't know why you disable interrupts twice.

Additionally you may want to reset FMODE and BPLCONx to standard values, in case you have to disable AGA/ECS.
I disabled them twice because LoadView(NULL) seemed to reenable the VERTB interupt. That's something I need to check again.

I'll add the code to reset FMODE and BPLCONx.
deimos is offline  
Old 03 October 2019, 12:15   #4
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,522
Don't disable interrupts before calling waittof() or loadview(). It most likely causes a hang if system has active RTG board that use hardware vertical blank interrupts.
Toni Wilen is offline  
Old 03 October 2019, 13:36   #5
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Quote:
Originally Posted by Toni Wilen View Post
Don't disable interrupts before calling waittof() or loadview(). It most likely causes a hang if system has active RTG board that use hardware vertical blank interrupts.
Do I even need to call LoadView(NULL) if the first thing I'm going to do is disable interrupts and load my own copperlist?

Last edited by deimos; 03 October 2019 at 13:42.
deimos is offline  
Old 03 October 2019, 14:53   #6
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,476
Quote:
Originally Posted by deimos View Post
Do I even need to call LoadView(NULL) if the first thing I'm going to do is disable interrupts and load my own copperlist?
Sure. How could you switch from a graphics card to the default chipset video output?
ross is offline  
Old 03 October 2019, 16:25   #7
Toni Wilen
WinUAE developer
 
Join Date: Aug 2001
Location: Hämeenlinna/Finland
Age: 49
Posts: 26,522
Yeah, without LoadView(NULL) RTG mode stays active, unless you have separate monitor connected to Amiga's built-in video out. And even if you have separate monitor, native refresh rate may not be standard PAL or NTSC without LoadView(NULL).

Something like this should be safe:

Forbid() (so that no other task can change graphics modes etc before interrupts get disabled)
loadview/waittof stuff
OwnBlitter()
WaitBlitter()
Disable interrupts

the rest

Enable interrupts
DisownBlitter()
loadview back to original
Permit()
Toni Wilen is offline  
Old 03 October 2019, 18:02   #8
ross
Defendit numerus
 
ross's Avatar
 
Join Date: Mar 2017
Location: Crossing the Rubicon
Age: 53
Posts: 4,476
Quote:
Originally Posted by Toni Wilen View Post
Forbid() (so that no other task can change graphics modes etc before interrupts get disabled)
loadview/waittof stuff
OwnBlitter()
WaitBlitter()
Disable interrupts

the rest

Enable interrupts
DisownBlitter()
loadview back to original
Permit()
I was wondering.. Is OwnBlitter() essential?

What are the possible contraindications to use this?:

Forbid()
loadview / waittof stuff
Disable interrupts
myWaitBlitter()

Yes, it's a simple call that certainly doesn't hurt, it's just curiosity

EDIT: hmm, perhaps the answer is simple, another process that has a blitter-chain that absolutely cannot be interrupted, under penalty of data corruption
the partial results are always valid, unless we refer to pre-set and shared registers between operations

Last edited by ross; 03 October 2019 at 19:16.
ross is offline  
Old 03 October 2019, 19:22   #9
a4k-oerx
Registered User
 
Join Date: Oct 2008
Location: EU
Posts: 163
The CD32 Developer Notes (pdf at kaiiv.de) have hints on what to use when and why e.g. Q4 page 91 "Which of the following ... can we safely take over and hit directly?"
a4k-oerx is offline  
Old 03 October 2019, 20:40   #10
hooverphonique
ex. demoscener "Bigmama"
 
Join Date: Jun 2012
Location: Fyn / Denmark
Posts: 1,624
Quote:
Originally Posted by deimos View Post
So, I've decided the startup code I've been using is not the best. Is there an accepted standard piece of code that everyone is using to take over and return the system?

Short answer is no - there will be hundreds of variants over the same concepts..
hooverphonique is offline  
Old 04 October 2019, 14:04   #11
Hewitson
Registered User
 
Hewitson's Avatar
 
Join Date: Feb 2007
Location: Melbourne, Australia
Age: 41
Posts: 3,773
Quote:
Originally Posted by hooverphonique View Post
Short answer is no - there will be hundreds of variants over the same concepts..
Exactly. But as a starting point maybe check out startup code posted by StingRay and/or Photon. Hope this helps.
Hewitson is offline  
Old 04 October 2019, 22:25   #12
Photon
Moderator
 
Photon's Avatar
 
Join Date: Nov 2004
Location: Eksjö / Sweden
Posts: 5,611
Here's mine - it's divided into a wrapper and a startup. The wrapper is what turns off and on the OS and the startup starts a template screen once you've take over that you can flesh out and customize as you want - I used to have it as one file, but the reason for the separation into two files is this customization.

So you only need translate the wrapper. It returns to RTG on exit.

It has a few hardcoded offsets to not immediately require dependencies. -222 is LoadView(), -408 is OldOpenLib(), and offset 297 in Exec is to check for 68000, to detect VBR safely.

Last edited by Photon; 31 January 2020 at 20:10.
Photon is offline  
Old 05 October 2019, 09:13   #13
deimos
It's coming back!
 
deimos's Avatar
 
Join Date: Jul 2018
Location: comp.sys.amiga
Posts: 762
Quote:
Originally Posted by Photon View Post
Here's mine - it's divided into a wrapper and a startup. The wrapper is what turns off and on the OS and the startup starts a template screen once you've take over that you can flesh out and customize as you want - I used to have it as one file, but the reason for the separation into two files is this customization.

So you only need translate the wrapper. It returns to RTG on exit.

It has hardcoded offset to not immediately require dependencies. -222 is LoadView(), -408 is OldOpenLib(), and offset 297 in Exec is to check for 68000, which means it's not safe to detect VBR with movec.
Thank you. If I'd known that was there I would have gone straight to it.
deimos 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
non-system startup code time/clock problem modrobert Coders. Asm / Hardware 89 14 December 2018 15:37
AROS startup code patrik Coders. Nextgen 5 30 April 2017 21:13
startup/system takeover sidewinder Coders. General 15 28 February 2016 16:33
Startup Code (from Icon ) - Forbid function Asman Coders. System 2 04 January 2014 10:45
Taking over the system... lpopman Coders. General 5 03 December 2004 01:52

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 22:24.

Top

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