Equivalent of the NEW basic command ?

Since we do not have native C compilers on the Oric, this forum will be mostly be used by people using CC65 or the OSDK. But any general C related post will be welcome !
User avatar
Dbug
Site Admin
Posts: 2394
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Equivalent of the NEW basic command ?

Post by Dbug » Sat Jun 20, 2015 11:10 am

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
.)

User avatar
Hialmar
Flight Lieutenant
Posts: 318
Joined: Tue Mar 04, 2014 11:25 am
Location: Toulouse, France
Contact:

Re: Equivalent of the NEW basic command ?

Post by Hialmar » Sat Jun 20, 2015 11:59 am

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.
Hialmar
CEO and Silicium member.

User avatar
Hialmar
Flight Lieutenant
Posts: 318
Joined: Tue Mar 04, 2014 11:25 am
Location: Toulouse, France
Contact:

Re: Equivalent of the NEW basic command ?

Post by Hialmar » Sat Jun 20, 2015 9:23 pm

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).
Attachments
C2BasicTest.zip
(38.08 KiB) Downloaded 99 times
Hialmar
CEO and Silicium member.

Godzil
Squad Leader
Posts: 756
Joined: Sat May 21, 2011 7:21 pm
Location: Between UK and France
Contact:

Re: Equivalent of the NEW basic command ?

Post by Godzil » Mon Jun 22, 2015 2:42 pm

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?

User avatar
iss
Squad Leader
Posts: 518
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: Equivalent of the NEW basic command ?

Post by iss » Tue Jun 23, 2015 11:07 am

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.

User avatar
Hialmar
Flight Lieutenant
Posts: 318
Joined: Tue Mar 04, 2014 11:25 am
Location: Toulouse, France
Contact:

Re: Equivalent of the NEW basic command ?

Post by Hialmar » Tue Jun 23, 2015 4:27 pm

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.
Hialmar
CEO and Silicium member.

User avatar
Chema
Game master
Posts: 2081
Joined: Tue Jan 17, 2006 10:55 am
Location: Gijón, SPAIN
Contact:

Re: Equivalent of the NEW basic command ?

Post by Chema » Tue Jun 23, 2015 4:59 pm

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.

User avatar
iss
Squad Leader
Posts: 518
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: Equivalent of the NEW basic command ?

Post by iss » Tue Jun 23, 2015 6:39 pm

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 100 times

User avatar
Hialmar
Flight Lieutenant
Posts: 318
Joined: Tue Mar 04, 2014 11:25 am
Location: Toulouse, France
Contact:

Re: Equivalent of the NEW basic command ?

Post by Hialmar » Tue Jun 23, 2015 7:52 pm

Thanks a lot iss. That's exactly what I want to do :)

Let's hope it will work with the real programs.
Hialmar
CEO and Silicium member.

User avatar
Hialmar
Flight Lieutenant
Posts: 318
Joined: Tue Mar 04, 2014 11:25 am
Location: Toulouse, France
Contact:

Re: Equivalent of the NEW basic command ?

Post by Hialmar » Tue Jun 23, 2015 8:02 pm

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.
Hialmar
CEO and Silicium member.

User avatar
iss
Squad Leader
Posts: 518
Joined: Sat Apr 03, 2010 5:43 pm
Location: Bulgaria
Contact:

Re: Equivalent of the NEW basic command ?

Post by iss » Tue Jun 23, 2015 8:27 pm

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.

User avatar
Hialmar
Flight Lieutenant
Posts: 318
Joined: Tue Mar 04, 2014 11:25 am
Location: Toulouse, France
Contact:

Re: Equivalent of the NEW basic command ?

Post by Hialmar » Tue Jun 23, 2015 8:46 pm

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.
Hialmar
CEO and Silicium member.

User avatar
Hialmar
Flight Lieutenant
Posts: 318
Joined: Tue Mar 04, 2014 11:25 am
Location: Toulouse, France
Contact:

Re: Equivalent of the NEW basic command ?

Post by Hialmar » Tue Jun 23, 2015 8:57 pm

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.
Last edited by Hialmar on Tue Jun 23, 2015 9:06 pm, edited 1 time in total.
Hialmar
CEO and Silicium member.

User avatar
Dbug
Site Admin
Posts: 2394
Joined: Fri Jan 06, 2006 10:00 pm
Location: Oslo, Norway
Contact:

Re: Equivalent of the NEW basic command ?

Post by Dbug » Tue Jun 23, 2015 9:05 pm

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?

User avatar
Hialmar
Flight Lieutenant
Posts: 318
Joined: Tue Mar 04, 2014 11:25 am
Location: Toulouse, France
Contact:

Re: Equivalent of the NEW basic command ?

Post by Hialmar » Tue Jun 23, 2015 9:09 pm

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.
Hialmar
CEO and Silicium member.

Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests