Equivalent of the NEW basic command ?
- Hialmar
- Flight Lieutenant
- Posts: 349
- Joined: Tue Mar 04, 2014 11:25 am
- Location: Toulouse, France
- Contact:
Equivalent of the NEW basic command ?
I have some problems when switching from my C program to a Basic program.
I think my C program is messing with the place where the Basic stores variables and arrays.
I'd like to restore those pointers before switching to the Basic program.
So basically what I would need is a C or ASM equivalent to the NEW basic command.
Maybe I just need to "call" some ROM routine for that ?
I think my C program is messing with the place where the Basic stores variables and arrays.
I'd like to restore those pointers before switching to the Basic program.
So basically what I would need is a C or ASM equivalent to the NEW basic command.
Maybe I just need to "call" some ROM routine for that ?
Re: Equivalent of the NEW basic command ?
Something you could try first, is to see that the BASIC program correctly calls HIMEM to specify the top of memory it can use, and have you C or assembler programs only access behind that.Hialmar wrote:I have some problems when switching from my C program to a Basic program.
I think my C program is messing with the place where the Basic stores variables and arrays.
I'd like to restore those pointers before switching to the Basic program.
By default the ORIC Basic puts the variable toward the end of memory, so if you overwrite that the BASIC is not going to be happy.
- Hialmar
- Flight Lieutenant
- Posts: 349
- Joined: Tue Mar 04, 2014 11:25 am
- Location: Toulouse, France
- Contact:
Re: Equivalent of the NEW basic command ?
The problem is that both the basic and C programs use almost all memory.
That's why I switch from one to another.
In fact, after several trial and error I have located my problem.
I use the line8.s line drawing routine (found on miniserve) and it is something there that breaks the switch to basic program.
If I replace the DrawLine8 call by a curset and a draw it works.
It's sad because the DrawLine8 calls were way faster than curset and draw
That's why I switch from one to another.
In fact, after several trial and error I have located my problem.
I use the line8.s line drawing routine (found on miniserve) and it is something there that breaks the switch to basic program.
If I replace the DrawLine8 call by a curset and a draw it works.
It's sad because the DrawLine8 calls were way faster than curset and draw
Re: Equivalent of the NEW basic command ?
Could be an issue with zero page variables being overwritten, or perhaps some of the BSS tables where I generate the line addresses.Hialmar wrote:In fact, after several trial and error I have located my problem.
I use the line8.s line drawing routine (found on miniserve) and it is something there that breaks the switch to basic program.
If I replace the DrawLine8 call by a curset and a draw it works.
It's sad because the DrawLine8 calls were way faster than curset and draw
If you can produce a minimal test case that shows the problem, that could help
Re: Equivalent of the NEW basic command ?
Yeso, or at least put the file generated by osdk_showmap. I bet something important is being overwritten in the zero page
- Hialmar
- Flight Lieutenant
- Posts: 349
- Joined: Tue Mar 04, 2014 11:25 am
- Location: Toulouse, France
- Contact:
Re: Equivalent of the NEW basic command ?
assinie on oric.org had the same problem, it was because the program overwrites the Basic stack pointer in #87.
I now put a 0 there and it works.
If you want to test you can use my small example here:
http://torguet.net/Hialmar/OSDK/
* http://torguet.net/Hialmar/OSDK/C2BasicTest.zip is the OSDK project.
* you'll also need either
http://torguet.net/Hialmar/OSDK/bas2tap.exe
or
http://torguet.net/Hialmar/OSDK/tap2dsk.exe
or run the namer.com program in the dsk so that the basic program is correctly called.
Thanks to everyone.
I now put a 0 there and it works.
If you want to test you can use my small example here:
http://torguet.net/Hialmar/OSDK/
* http://torguet.net/Hialmar/OSDK/C2BasicTest.zip is the OSDK project.
* you'll also need either
http://torguet.net/Hialmar/OSDK/bas2tap.exe
or
http://torguet.net/Hialmar/OSDK/tap2dsk.exe
or run the namer.com program in the dsk so that the basic program is correctly called.
Thanks to everyone.
- Hialmar
- Flight Lieutenant
- Posts: 349
- Joined: Tue Mar 04, 2014 11:25 am
- Location: Toulouse, France
- Contact:
Re: Equivalent of the NEW basic command ?
Ah well, I now have another error farther in the real Basic code
At the end of the program we look at the free memory and it crashes the program trying to execute opcode #72 in #20C9.
I will try to generate a small program with that but so far it didn't work.
At the end of the program we look at the free memory and it crashes the program trying to execute opcode #72 in #20C9.
I will try to generate a small program with that but so far it didn't work.
- Hialmar
- Flight Lieutenant
- Posts: 349
- Joined: Tue Mar 04, 2014 11:25 am
- Location: Toulouse, France
- Contact:
Re: Equivalent of the NEW basic command ?
Ok I have made another small program isolating the error.
It is available here:
http://torguet.net/Hialmar/OSDK/C2BasicTest.zip
(as before you either have to use the NAMER.COM program or my versions of tap2dsk or bas2tap which name correctly COMBAT.COM).
The problem is not exactly the same as with my complete programs. Here I end up in an infinite loop around #D6DA.
On the C side, I draw a diagonal line (which uses a different asm code as the horizontal/vertical lines that crashed the Basic stack).
If you comment out the last DrawLine8(); (line 86) the code works.
Edit: I just regenerated the zip file as I had forgotten to update the map.
If you only want to see the map it's here: http://torguet.net/Hialmar/OSDK/map.htm
It is available here:
http://torguet.net/Hialmar/OSDK/C2BasicTest.zip
(as before you either have to use the NAMER.COM program or my versions of tap2dsk or bas2tap which name correctly COMBAT.COM).
The problem is not exactly the same as with my complete programs. Here I end up in an infinite loop around #D6DA.
On the C side, I draw a diagonal line (which uses a different asm code as the horizontal/vertical lines that crashed the Basic stack).
If you comment out the last DrawLine8(); (line 86) the code works.
Edit: I just regenerated the zip file as I had forgotten to update the map.
If you only want to see the map it's here: http://torguet.net/Hialmar/OSDK/map.htm
- Hialmar
- Flight Lieutenant
- Posts: 349
- Joined: Tue Mar 04, 2014 11:25 am
- Location: Toulouse, France
- Contact:
Re: Equivalent of the NEW basic command ?
assinie, again, found a solution.
I saved bytes from 84 to 88 at the beginning of the C program and restored them just before switching to basic and it worked.
It had something to do with the keyboard buffer.
I saved bytes from 84 to 88 at the beginning of the C program and restored them just before switching to basic and it worked.
It had something to do with the keyboard buffer.
Re: Equivalent of the NEW basic command ?
That code could surely crash BASIC because it is overwritting some zero page pointers which are used by the ROM routines. According to Geoff Phillips' book (http://home.btconnect.com/geffers/files/chap5.htm):
So the solution could be to store those vars in locations #00 up to #0B, which are unused by BASIC. How? Well, the OSDK compiler places the vars automatically when they are defined. You can replace (maybe) the code which does something like:
with something like:
Something like that. You could also use the operator *=$00 after the .zero directive, but I think this would restart the location of zero page variables and I am not sure if there could be any lateral effects.
Or, of course, you could try to save the value of those pointers before calling the routine, and put them back afterwards...
Code: Select all
#86 – Address of last temporary string.
#88 – #90 – A table of temporary strings.
Code: Select all
.zero
curBit .byt 00
chunk .byt 00
lastSum .byt 00
Code: Select all
#define curBit $00
#define chunk $01
#define lastSum $02
Or, of course, you could try to save the value of those pointers before calling the routine, and put them back afterwards...
- Hialmar
- Flight Lieutenant
- Posts: 349
- Joined: Tue Mar 04, 2014 11:25 am
- Location: Toulouse, France
- Contact:
Re: Equivalent of the NEW basic command ?
Yes thank you I have added a few more bytes to the ones I save at the beginning of the program and restore just before loading the basic program.
So far so good.
My program works correctly.
Again thank you, Chema and Dbug.
Edit: I'll try to relocate things as well, as I might corrupt some data used by some ROM routines I use.
So far so good.
My program works correctly.
Again thank you, Chema and Dbug.
Edit: I'll try to relocate things as well, as I might corrupt some data used by some ROM routines I use.
Re: Equivalent of the NEW basic command ?
Hmm, I guess a worthy addition to XA could be to have an automatic support for 'system safe' zero page allocation.
Could be an optional mode where instead of saying "start at $50" it would automatically allocate in a list of known "safe" areas?
Could be an optional mode where instead of saying "start at $50" it would automatically allocate in a list of known "safe" areas?
Re: Equivalent of the NEW basic command ?
Why don't they start at $00, btw?
Re: Equivalent of the NEW basic command ?
That was the value they (Fabrice, Vangelis, Alexios) chose in the original C SDKChema wrote:Why don't they start at $00, btw?
- Hialmar
- Flight Lieutenant
- Posts: 349
- Joined: Tue Mar 04, 2014 11:25 am
- Location: Toulouse, France
- Contact:
Re: Equivalent of the NEW basic command ?
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 ?
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 ?