Welcome, Guest. Please login or register.

Author Topic: Exec permit and forbid functions (taking over the machine ;) ...)  (Read 3675 times)

Description:

0 Members and 1 Guest are viewing this topic.

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Hey dudes;) I was fiddling around with some stuff and got this doubt, you know me, lazy and without much time, so I decided to ask you this (I'll probably look into it myself anyway but...) for quicker results:
I want to stop multitasking and take over the machine to writte my own copper list and mess around with the data fetch registers and playfield pointers, modulo and ham and that type of stuff;) To prevent other tasks from interfering and screwing everything I read that I need to use the Exec forbid function. At the end of my prog I use permit func to restore multitasking.
But...
Will this restore the register I been messing around with to their initial values? Many registers are writte only, so does this means that the OS stores a copy of their values somewhere?
If this doesn't restores the register values how can I do it?
What else should be done to restore the "initial" state?

Thx & cheers
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Exec permit and forbid functions (taking over the machine ;) ...)
« Reply #1 on: February 16, 2004, 10:14:28 PM »
Quote
I want to stop multitasking and take over the machine to writte my own copper list and mess around with the data fetch registers and playfield pointers, modulo and ham and that type of stuff;) To prevent other tasks from interfering and screwing everything I read that I need to use the Exec forbid function. At the end of my prog I use permit func to restore multitasking.

What you really should do, is to install your custom input handler that eats all user input events, and then LoadView(NULL) + WaitTOF() + WaitTOF() to get rid of the system view. That way you have full multitasking system available, which has several benefits. You can use high priority (say 3 or 4) if you can't afford to lose CPU time.

When restoring you should poke back the graphics copperlist ptr and LoadView() + WaitTOF() + WaitTOF() the original view.

Quote

But...
Will this restore the register I been messing around with to their initial values?

No.
Quote
Many registers are writte only, so does this means that the OS stores a copy of their values somewhere?

OS knows how to write back sane values for most things, if you use proper startup. OS can't restore copper ptr however, or CIA register values. You should use ciaa and ciab resources to allocate these, if needed. Also OwnBlitter() + WaitBlit() before using blitter. When done, WaitBlit() + DisowbBlitter(). Audio channels should be allocated and released using audio.device if used.

Quote
If this doesn't restores the register values how can I do it?
What else should be done to restore the "initial" state?

Lots of stuff. You probably want to take a look at DemoStartUp.lha. Even though this is a OS compatible startup code, it includes lots of useful stuff.

I'll look into my ASM source archive and see if I can come up with some example code.
 

Offline xeron

  • Hero Member
  • *****
  • Join Date: Mar 2002
  • Posts: 2533
    • Show only replies by xeron
    • http://www.petergordon.org.uk
Re: Exec permit and forbid functions (taking over the machine ;) ...)
« Reply #2 on: February 16, 2004, 10:16:14 PM »
OK, well, you shouldn't really be doing this these days, but it is fun :)

If you really want to make your own startup-code, do this:

1) Store the current view and coplist from graphicsbase (offsets 34 and 38 ;-) ).
2) Call LoadView() with nothing in A1. This removes the intuition display, and will switch out Picasso96 screens etc.
3) Do two "WaitTOF()"s. This allows enough time for interlaced displays to be turned off
4) Call "OwnBlitter()" and "WaitBlit()" to take over control of the blitter safely
5) Call Forbid() to turn off multitasking
6) Store DMACONR, INTENAR, INREQR and ADKCONR, or'd with $8000 for later
7) Put $7fff into DMACON, INTENA and ADKCON to turn off all DMA an interrupts
8) Load your copperlist into Cop1lc, and write to Copjmp1
9) Set up your interrupts. Remember to use VBR if there is a 68020+ present! Also save any interrupt vectors before you overwrite them
10) Turn on DMA and interrupts you require

To restore the system:

1) Put $7fff into DMACON, INTENA and ADKCON
2) Restore system interrupt pointers
3) Restore copper from gfxbase into cop1lc, and write to copjmp1
4) Move the stored (and $8000 or'd) DMACONR, INTENAR and ADKCONR values into DMACON, INTENA and ADKCON
5) Call LoadView() with the view you stored from graphicbase. This will bring P96 screens back etc.
6) Call DisownBlitter()
7) Call Permit()

Some notes:

* Detect the processor, and use VBR if necessary
* If you use sprites, set the resolution in BPLCON3, since LoadView(NULL) fails to reset it if the user has a hires mousepointer. If BPLCON3 is in your coplist that would cover that anyway.
* Set Intreq twice at the end of interrupts. This is a workaround for 040 & 060 based A4000 systems. For example, a level 6 interrupt should look like:

movem.l d0-d7/a0-a6,-(sp)
lea $dff000,a6

; .... code ....

move.w #$2000,Intreq(a6)
move.w #$2000,Intreq(a6)
movem.l (sp)+,d0-d7/a0-a6
rte

This way your code should gracefully kill and restore the OS on everything from a 256k KS1.x A1000 up to an OS3.9 mediator based A4000 and everything inbetween.
Playstation Network ID: xeron6
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Exec permit and forbid functions (taking over the machine ;) ...)
« Reply #3 on: February 17, 2004, 12:55:44 AM »
Here is a small startup routine that doesn't forbid or disable the system, but take it over nevertheless:
hwstartup.asm

If total takeover is needed, just do it in the main as described.
 

Offline Karlos

  • Sockologist
  • Global Moderator
  • Hero Member
  • *****
  • Join Date: Nov 2002
  • Posts: 16867
  • Country: gb
  • Thanked: 4 times
    • Show only replies by Karlos
Re: Exec permit and forbid functions (taking over the machine ;) ...)
« Reply #4 on: February 17, 2004, 12:59:06 AM »
Mmmmmm....metal bashing. Man it has been a while - somewhere I sold my soul and went all RTG.

@xeron

That sequence of take over / recover steps reminds me of some old library I saw once. I can't recall the name, but I dimly remember it basically wrapped a lot of this into a few functions.

Anybody else remember it?
int p; // A
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: Exec permit and forbid functions (taking over the machine ;) ...)
« Reply #5 on: February 17, 2004, 01:21:03 AM »
Nice! I'll have to look more into some stuff though, mainly system control hardware. So far I've only read the playfield, copper, and part of the blitter chapters on the HRM... This is getting me more trouble than I thought, you're all insane :O :)
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: Exec permit and forbid functions (taking over the machine ;) ...)
« Reply #6 on: May 16, 2004, 11:52:59 PM »
Hi! Just out of curiosity why do DMACONR, INTENAR, INREQR and ADKCONR, have to be or'ed with $8000 :-?

I know there are some addresses on the custom chipset's registers that are not needed to be writte fully, cause it's the custom chips that are woking with them and they have a more restric address area. But the since the contents of the registers are to be placed on the very same registers later on, why do they need to be or'ed :-?
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline JoseTopic starter

  • Hero Member
  • *****
  • Join Date: Feb 2002
  • Posts: 2869
    • Show only replies by Jose
Re: Exec permit and forbid functions (taking over the machine ;) ...)
« Reply #7 on: May 18, 2004, 12:32:04 PM »
Ok, dunno if anyone cares but I already knew the answer... Remembered this night when I woke up at 5:30... don't ask me why :lol:
Bit 14 of those registers works as the set/clear bit. If it wasn't a 1, the other set bits would be cleared.
\\"We made Amiga, they {bleep}ed it up\\"
 

Offline Piru

  • \' union select name,pwd--
  • Hero Member
  • *****
  • Join Date: Aug 2002
  • Posts: 6946
    • Show only replies by Piru
    • http://www.iki.fi/sintonen/
Re: Exec permit and forbid functions (taking over the machine ;) ...)
« Reply #8 on: May 18, 2004, 12:43:51 PM »
@Jose

Correct, though it's bit 15. 1 << 15 = $8000.