Page 2 of 4

Re: Equivalent of the NEW basic command ?

Posted: Sat Jun 20, 2015 11:10 am
by Dbug
I wonder if having a 'swap zero page' routine that would use a 256 bytes memory buffer could solve the problem.

(COPY ZERO PAGE) <- so we have some sane values to avoid crashing interrupts and whatever
Run BASIC code
(SWAP ZERO PAGE)
Run some C or Assembler code
(SWAP ZERO PAGE)
Back to basic

The code itself would be something like that:

Code: Select all

SwapBuffer  .dsb 256

CopyZeroPage
.(	
	ldy #0
loop
	lda $00,y
	sta CopyZeroPage,y
	iny
	bne loop
	rts
.)


SwapZeroPage
	jmp SwapZeroPage
.(	
	ldy #0
loop
	lda $00,y
	tax
	lda SwapBuffer,y
	sta $00,y
	txa
	sta SwapBuffer,y
	iny
	bne loop
	rts
.)

Re: Equivalent of the NEW basic command ?

Posted: Sat Jun 20, 2015 11:59 am
by Hialmar
Thanks I will try that.

My fear is about the pointers in page 0 that points to the borders of variables, arrays and strings.
I suppose I should reset them to initial values. Like what the NEW command does.

Re: Equivalent of the NEW basic command ?

Posted: Sat Jun 20, 2015 9:23 pm
by Hialmar
I did exactly what you told (sorry about my previous message, I failed to see that you wanted to save the page 0 before doing anything else).

But when I switch back from C to the Basic program I end up in a strange state:
- the Basic program does not load ;
- I'm at the prompt but it doesn't move and I don't see the characters I type;
- Going HIRES and back to TEXT get me back to a normal state but LIST returns nothing (the program doesn't load).

I suppose I'm breaking something with Sedoric.

Edit: I will try to generate a simple example of all this.
Done. It's attached to this file.
It doesn't do exactly like I describe. The Basic program runs but the state is still strange. Need to do HIRES and TEXT to get back to normal.

You need to do:
CPZEROP
LABY
and it goes to Hires and Back to text when you hit a key and then tries to load COMBAT (Basic program).

Re: Equivalent of the NEW basic command ?

Posted: Mon Jun 22, 2015 2:42 pm
by Godzil
Hialmar wrote:Looks like I still have some problems with interactions from my basic programs and my C programs.

I get some Out Of Memory errors when I switch from Basic to C and back about 15 times.

Is it possible to put a breakpoint with Oricutron before the Out Of Memory error message is print out so that I can check the Stack Pointer ?
Out Of Memory should not be a stack beeing full, do you know who display this OOM message? It is the Basic or your own code?

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 11:07 am
by iss
Hialmar, did you fixed the issue?
I took a quick look at attached example and I have some concerns about the way you store/restore zero page.
- cpzerop.s: it saves modified ZP, because it's linked with OSDK start-up code where 'sp' byte is used;
- main.c: 'restorePageZero' uses 'memcpy' which uses ZP too - unpredictable results can happen;
- save/restore buffer is at 0xb800 - nothing wrong but consider that this area is moved together with character sets when switching between hires and text.

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 4:27 pm
by Hialmar
No I didn't solve the problem.

Thanks a lot.

So basically I should rewrite the cpzerop.s with a monitor/assembler directly on Oricutron.
Rewrite my restorePageZero function in assembler.
No problem with 0xb800 as I only do the switching when in text mode.
I don't know where else to put this as the Basic program almost fill all normal RAM.

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 4:59 pm
by Chema
Yes. The code Dbug posted should work, except for the jmp SwapZeroPage which I think should be removed (would loop infinitely). You can compile it with OSDK, along with your C program.

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 6:39 pm
by iss
I touched here and there in sources. Attached zip file contains DSK file and moded sources.
Please check if this helps. If not - probably I didn't understand the problem and ignore this post :).
CBasic-mod.zip
(25.88 KiB) Downloaded 170 times

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 7:52 pm
by Hialmar
Thanks a lot iss. That's exactly what I want to do :)

Let's hope it will work with the real programs.

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 8:02 pm
by Hialmar
Ah I have a problem.

I tried to switch back to #9800 as I really need the whole RAM for my Basic program and now I cannot make a .tap because the linker says I have no _main symbol.
How can I use XA to do that ?

Edit: I think I got it using
SET OSDKLINK=-B

Edit2: strange I had to switch back to #B800 because a part of the #9800 area was somewhat overwritten when going to hires mode or doing the cls.

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 8:27 pm
by iss
Yes, $9800 is used for standard chars when in hires. That's why I set to $9700 the swap area and protected it with HIMEM#9700 in basic.
But in your case it's OK to use $b800 and use all free memory.

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 8:46 pm
by Hialmar
There is still something that is breaking my program. :(
It takes more than 10 exchanges from C to Basic and then I get the Out of Memory error.

I will try to put a breakpoint on this dreaded Out of Memory error and find out what is broken.

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 8:57 pm
by Hialmar
Godzil wrote: Out Of Memory should not be a stack beeing full, do you know who display this OOM message? It is the Basic or your own code?
There is a routine in ROM documented on page 82 of "l'Oric a Nu" that actually checks if there is enough room on the stack and if not gets to the Out of Memory error. It's called "Verifier place sur la pile" in "l'Oric a Nu".

The routine sits in #C43B or #C437 (depending on the version of the ROM).

Edit: OOM error is in #C47C that's where I will put my breakpoint.

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 9:05 pm
by Dbug
Hialmar wrote:There is still something that is breaking my program. :(
It takes more than 10 exchanges from C to Basic and then I get the Out of Memory error.
I will try to put a breakpoint on this dreaded Out of Memory error and find out what is broken.
What do you mean by *exchanges* ?

Are you doing BASIC calls C calls BASIC calls C calls BASIC?
or are you calling C from BASIC, then back to BASIC; call C again and then back to BASIC?

Re: Equivalent of the NEW basic command ?

Posted: Tue Jun 23, 2015 9:09 pm
by Hialmar
First I backup the zero page, then I start my C program, it then loads the Basic program, which loads back the C program and so on for about 10 times.

I have 9 levels in the game and I basically switch levels in the Basic program and visit them in the C program.
When I do them in sequence it crashes in level 7 IIRC.
So that's about 14 exchanges.

I just got the error.
- SP is 13D so it should be ok.
- Start of Basic is ok : 0501
- End of Basic is ok : 4A3D
- End of Vars is ok : 4A7C
- End of arrays is ok : 4CA7
- End of strings is : 97FF way too high
That's my problem. Too many strings. I'll try to put calls to the FRE function.