make a Soft Reset with Gendev

SGDK only sub forum

Moderator: Stef

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

make a Soft Reset with Gendev

Post by bastien » Tue Dec 21, 2010 12:31 pm

Hi,
i search a way to do a Soft Reset( just Soft not an Hard) with Gendev but it seems no have function for it, and i don't know the ASM...
.
but i can enter piece of ASM code directly with Gendev so if anyone of you can write me just a simple code wich can do that :D

Thanks :P

Shiru
Very interested
Posts: 786
Joined: Sat Apr 07, 2007 3:11 am
Location: Russia, Moscow
Contact:

Post by Shiru » Tue Dec 21, 2010 12:51 pm

What you mean by Soft reset? You can just jump to start of the code, and it will reinitialize everything.

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Tue Dec 21, 2010 1:34 pm

same thing as the Reset button of the console.

i have build a multigame cartridge with Reset function ( with a counter) , if you press reset button it will change the game ( i have make a topic and another thanks for the people who helped me).

but i would add a screen selection menu which make the reset:
-for exemple:
-if you press start with the game 1 selected the console make one reset and it launch the game.
-start with the second game : two reset
ect...

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Tue Dec 21, 2010 8:42 pm

Just jmp through the reset vector in the exception table at the start of the rom.

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Tue Dec 21, 2010 9:33 pm

huh ? :oops:

Chilly Willy
Very interested
Posts: 2984
Joined: Fri Aug 17, 2007 9:33 pm

Post by Chilly Willy » Tue Dec 21, 2010 10:37 pm

The long at address 4 is the reset vector. It points to where the MD should start when you push the reset button.

In assembly

Code: Select all

    movea.l 4.w,a0
    jmp (a0)
and in C

Code: Select all

    (*(int*)4)();

TmEE co.(TM)
Very interested
Posts: 2442
Joined: Tue Dec 05, 2006 1:37 pm
Location: Estonia, Rapla City
Contact:

Post by TmEE co.(TM) » Wed Dec 22, 2010 6:57 am

To differentiate between Soft and Hard reset, games read controller ports to see if they're initialized or not. Soft reset does not alter controller port config, but Hard Reset puts them into default values.
Mida sa loed ? Nagunii aru ei saa ;)
http://www.tmeeco.eu
Files of all broken links and images of mine are found here : http://www.tmeeco.eu/FileDen

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Wed Dec 22, 2010 8:53 am

thanks you very much Chilly Willy but i have wrote this :

Code: Select all

 if( jeu==1 && start) // lancement du jeu 1 on fait un reset
               {
                       (*(int*)4)(); // pointage sur le vecteur 4
               }
and Gendev tells me " called object is not a function "

ElBarto
Very interested
Posts: 160
Joined: Wed Dec 13, 2006 10:29 am
Contact:

Post by ElBarto » Wed Dec 22, 2010 9:16 am

Then declare a function pointer, init to 4 and call the function. Should work.

HardWareMan
Very interested
Posts: 746
Joined: Sat Dec 15, 2007 7:49 am
Location: Kazakhstan, Pavlodar

Post by HardWareMan » Wed Dec 22, 2010 10:53 am

M68K can push the reset button (actually, make VRES signal active) for prepare own hardware. There are "RESET" opcode (0x4E70), wich does things:
Description: Asserts the RSTO signal for 512 (124 for MC68000, MC68EC000, MC68HC000, MC68HC001, MC68008, MC68010, and MC68302) clock periods, resetting all external devices. The processor state, other than the program counter, is unaffected, and execution continues with the next instruction.
I think it usefull to use this opcode before jump to inital vector. So, do it this way:

Code: Select all

reset
movea.w (4),a0
jmp (a0)
ASM inline can be used, does it?

Code: Select all

 0x4E70, 0x2078, 0x0004, 0x4ED0
But, I don't know for sure, affects this opcode on MegaDrive hardware or not. But VRES is directly connected to RESET pin of M68K, so cartrige hardware can be reset this way.

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Wed Dec 22, 2010 12:04 pm

i have try to write this but no effect:

Code: Select all


        if( jeu==1 && start) // lancement du jeu 1 on fait un reset
               {
                   
                  asm ("movea.l   4, %a0");
                  asm ("jmp (%a0)"); 
                  
               
               }
if have not "%" don't works.

TascoDLX
Very interested
Posts: 262
Joined: Tue Feb 06, 2007 8:18 pm

Post by TascoDLX » Wed Dec 22, 2010 12:24 pm

Note, if you want to do a proper soft reset, you'll need to reset the stack pointer.

This should work:

Code: Select all

asm volatile ( "move   #0x2700,%sr\n\t"
               "move.l 0,%a7\n\t"
               "move.l 4,%a0\n\t"
               "jmp    (%a0)" );

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Wed Dec 22, 2010 1:04 pm

it works perfectly thanks tasco !

Stef
Very interested
Posts: 3131
Joined: Thu Nov 30, 2006 9:46 pm
Location: France - Sevres
Contact:

Post by Stef » Fri Dec 24, 2010 12:53 am

I just released version SGDK v0.7, i internally implemented a correct soft reset method (just called "reset()") which keep some internals states unchanged as ram which wasn't the case before.
You can also detect it in our main() method which now accept one parameter : main(u16 param)
(param != 0) --> hard reset
(param == 0) --> soft reset

See in the dedicated topic

bastien
Very interested
Posts: 208
Joined: Mon Jun 25, 2007 7:19 pm
Location: Besançon,France
Contact:

Post by bastien » Fri Dec 24, 2010 9:15 am

i have a question.
is this reset do exactly the same thing as the button reset.

for exemple my cartridge with bankswitch use the Reset signal with the cartrdige port B27.
is the code do the same thing, so it will up the counter ?

Image

Post Reply