Utility to test 6309 modes

Hardware Hacking, Programming and Game Solutions/Cheats
Post Reply
pser1
Posts: 1672
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Utility to test 6309 modes

Post by pser1 »

Hello,
I was making tests in XRoar and with a Dragon64 with a 63C09 and a Lafumat controller.
I was testing every D.O.S. version we have (15 different ones from Dragon Data, Eurohard, SuperDos, Cumana and DosPlus),
and have no problems to copy them to RAM, then switch to MAP1 and send BASIC and DOS to their right places, and then
just JMP $C002 to start the new DOS. So far no problems.
When I wanted to go back to the DOS in ROM (switching to Map0), the systems crashes or simply hangs, needing a cold
restart to come back to life.
I tried to change $71 and $72-73 to force a warm or cold start with a JMP $B3B4 but got the very same results.
I have not been able to find a way to make the Dragon perform this jump-back

Any advice on that subject will be really very, very appreciated. Help!!

I am developping a small program that extends BASIC commands (for practicing purposes) adding some,
most of the info to do that has been found in our forums or in internet docs.
These are the added commands:
WCPU to know the CPU installed in the machine
WMODE to know the mode you are in (emulation or native if a 63x09 exists)
NAT63 switches to native mode
EMU68 back to emulation mode
HMRAM tells if there are 64k or 32k
RPTON turns on autorepeat
RPTOF turns that off
WDOS shows wich of the 15 known DOS is active now
WMAP to know the map you are in
GMAP1 to switch to map 1

GMAP0 this is the one that crashes

They all can be used in BASIC programs or from the command prompt and use a small amount of unused variables to store results
that can be read later. Shows messages, but has an implemented silent mode not to disturb user screen in programs.
I thought this would help making tests to compare both 6309 modes, simply including the change of mode command inside the benchmark
programs anyone could want to build.

I attach zip file containing:
- an vdk image with the sources in DREAM format (I'm using DSKDREAM) together with the binary and a Basic program to
install and test it
- three WAVs with the binary and basic programs to load right to Dragon or XRoar
- a text file with the source code as commented as I could.
- a Read me file

Pere
Attachments
NewCommands (2013) - PereSerrat.zip
(43.87 KiB) Downloaded 196 times
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Re: Utility to test 6309 modes

Post by zephyr »

The following code is all that's needed to safely return to MAP0 mode.

6809e code

Code: Select all

ORCC  #$50      * Disable IRQ/FIRQ interrupts
CLR   $FFDE     * Switch to MAP0 mode
ANDCC #$AF      * Enable IRQ/FIRQ interrupts
RTS
63x09e code

Code: Select all

ORCC  #$50      * Disable IRQ/FIRQ interrupts
LDMD  #0        * Disable 6309 Native mode (FCB $11,$3D,0)
CLR   $FFDE     * Switch to MAP0 mode
ANDCC #$AF      * Enable IRQ/FIRQ interrupts
RTS
pser1
Posts: 1672
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Re: Utility to test 6309 modes

Post by pser1 »

Hello Zephyr,
thanks a lot.
I forgot to surround the change of mode and map with the disable - enable interrupts.
Once done that, it works, but only if the DOS in RAM is the same that resides in ROM. Only in this case it jumps back to MAP0 without any problem.
But, when I first load a different DOS to MAP1 and start it, I can work with this different DOS but, I cannot jump back to the ROM DOS with just CLR $FFDE (with the ORCC, ANDCC), then it crashes / hangs as it did before.
Any idea about why is this happening?
I could try to copy the ROM DOS first to RAM MAP1 but if I start it up with JMP $C002 this ends the program that makes this call, so no further command
could be programmed (change back to MAP0)

best regards
Pere

PS. By the way I saw that page zero variables $EA to $F6 are used by the DOS, so I changed mines to $FA - $FE (to avoid future problems)
zephyr
Posts: 1474
Joined: Mon Jul 21, 2008 1:18 am

Re: Utility to test 6309 modes

Post by zephyr »

pser1 wrote: I could try to copy the ROM DOS first to RAM MAP1 but <snip>
The easiest way would be to get your program to do the above, patch out the RAM test routine at $B3CA-$B3D8 with a simple LDX #$7FFE, BRA $B3D9, patch BASIC so that it jumps to your program init routine in RAM instead of returning to the command prompt, disable IRQ/FIRQ, and jump to the software init routine at $B3BA. After the BASIC/DOS cold start, your program can then switch back to MAP0 and return control to the BASIC command prompt.
pser1
Posts: 1672
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Re: Utility to test 6309 modes

Post by pser1 »

Hello Zephyr,
Thanks for your help. I haven't had much time to devote to this practices.
I have done what you explained, but for sure my way is not 100% correct, then it works fine just the very first time you execute it.
I mean, after having switched to MAP1, if I want to go back with the command GMAP0, it does what I programmed and returns the prompt on MAP0. OK, but . . . I have found these side-effects by now:
a) it has recovered all of the RAM and re-positioned the stack (more than 23K free when I had only 3K because of a PCLEAR0: CLEAR 200,&H1FFF)
b) despite the utility ensures its re-installation on reentry from Basic, if you do GMAP1 and then GMAP0 again, then it does the same . . . but this (second) time it hangs the system after having moved to MAP0!
I enclose the part of code that tries to go back to MAP0

Code: Select all

GMAP0  PSHS  A,X,U
       BSR   TMAP              * DETECT ACTUAL MAP TYPE
       LEAX  ALON,PCR          * POINT TO 'ALREADY THERE' MESSAGE
       TSTA
       BEQ   EGM0              * ALREADY IN THIS MAP, GO OUT
       LBSR  CPUMOD            * TEST ACTIVE MODE
       LDA   MMOD              * GET ACTIVE MODE
       CMPA  #8                * IS EMULATION?
       BEQ   GM00              * YES, NO NEED TO SWITCH MODE
       ORCC  #$50
       FCB   $11,$3D,$00
*      LDMD  #0                  SWITCH TO EMULATION MODE
       ANDCC #$AF
       LDA   #8       
       STA   MMOD              * MARK EMULATION MODE
       LEAX  SWEMU,PCR         * POINT TO MESSAGE
       LBSR  SHOW              * SHOW IT
*   THIS IS THE PART THAT DEALS WITH THE RAM/DOS MODIFICATIONS
GM00   ORCC  #$50              * DISABLE INTERRUPTS
       LDX   #$C000            * POINT TO DOS ROM INIT ($C000)
CPY1   STA   $FFDE             * GO ROM MAP
       LDU   ,X                * READ A WORD
       STA   $FFDF             * GO RAM MAP
       STU   ,X++              * WRITE WORD, POINT TO NEXT ONE
       CMPX  #$FEFE            * END OF RAM
       BLS   CPY1              * NO, KEEP ON
*       
       LDX   #$8E7F            * PATCH RAM TEST ROUTINE
       LDU   #$B3CA            * 8E7FFE =>  LDX $7FFE
       STX   ,U++
       LDX   #$FE20
       STX   ,U++
       LDX   #$0A12            * 200A   =>  BRA $B3D9
       STX   ,U                * 12     =>  NOP
*
       LDX   #$B418            * ZONE TO BE NOPED
       LDA   #$12              * TO PREVENT OVER-WRITING
GM01   STA   ,X+               * OF NEW COMMANDS' STUB
       CMPX  #$B426
       BLS   GM01
*
       LEAX  GM0E,PCR
       STX   $B467             * PATCH DOS TO RE-ENTER UTILITY AT GM0E
       ANDCC #$AF
       JMP   $B3C3             * CALLS PATCHED SYSTEM START       
* RE-ENTRY POINT CALLED BY BASIC
GM0E   PSHS  A,X
       LBSR  NEWSET            * RE-INSTALL UTILITY
       ORCC  #$50
       STA   $FFDE             * GO ROM MAP
       ANDCC #$AF
       CLRA
       STA   MMAP              * UPDATE MMAP TO SHOW WE ARE IN ROM MAP
       LEAX  SWMAP0,PCR        * POINT TO MAP1 (RAM) MESAGE
       LBSR  SHOW
       PULS  A,X,PC
EGM0   LBSR  SHOW              * SHOW MESSAGE
EGM01  PULS  A,X,U,PC
I have tested it with different DOS in RAM than the one that resides in ROM, it works changing to the ROM-DOS (always the first time you try)
I'm sure I'm forgetting something, but it is not easy to Debug since DSKDream doesn't like the interrupts being disabled.
Any advice will be greatly appreciated.
I will try further this experiment along next weekend.
Thanks beforehand
Pere
pser1
Posts: 1672
Joined: Sun Mar 25, 2012 7:32 pm
Location: Barcelona (SPAIN)

Re: Utility to test 6309 modes

Post by pser1 »

Hello,
back again.
It turned out that I was fooling the stack on going back to map0
I have changed the re-entry code so that after reinstalling the utility, it moves the stack to a safe area and so limits the RAM for BASIC in order to prevent it overwritting the utility code.
By now it seems it works but I need to make more tests, I can say that it accepts changing maps , to MAP1 and then to MAP0 as many times as you want and it worked OK with three different DOS in RAM (different from the one in ROM)
Have a nice week-end
Pere
Post Reply