Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"C Nonsense in BASIC"
#1
First case

I moved the main loop of my program into a sub, but I forgot to call the sub... so the program had nothing to do after DIMing and LETing some variables. The program returned to Sinclair BASIC with the error "C Nonsense in BASIC" instead of "0 OK".

Then I wrote a test program: just one sub, not called. The program returned to Sinclar BASIC with "0 OK". Strange. So there's something wrong with my program.

If I call the sub, or take its content out of the sub, everything works fine.

Second Case

But then I moved the main loop (out of any sub) to the end of the program... and the same error happened. I suspected two files I'm including, with character sets in assembler format, had something to do.

Here you are schematic versions of both cases:

This one works fine:

Code:
' ....most of the program here......
do
  ' MAIN LOOP
loop

#include "charset1.bas"
#include "charset2.bas"

def sub charset()
' bla bla
end sub
' END OF FILE

But this one simply returns with "Nonsense in basic":

Code:
' ....most of the program here......

#include "charset1.bas"
#include "charset2.bas"

def sub charset()
' bla bla
end sub

do
  ' MAIN LOOP
loop

' END OF FILE

Both included files have the same structure:

Code:
label:
asm
  defb 1,8,86,68,78,78,78,6
  ; hundreds of DEFB
  defb 1,8,86,68,78,78,78,6
end asm

So?

Both cases are not the same, but I suspected the included files are the reason of the strange error in the first case, when there was nothing to exectute; and the fact than the main loop is not found in the second case, and the error is returned.

I kept the main loop at the end of the program and removed the #includes. The program worked fine! Case 2 confirmed.

Then I moved the main loop into a sub but didn't called the sub... The program returned with a "0 OK" message as expected! Case 1 confirmed.

Will it happen with explicit (not #included) ASM sections? Let's see. I added some assembler lines right before the main loop sub, but the message was still "0 OK". It seems the strange behaviour is caused by #including the ASM sections.

Am I doing something wrong? Is there any limitation about the location of ASM sections or its including?
Reply
#2
Since you are working in MACHINE CODE, you must be careful when including binary files. What is happening there is the program execution is entering the charset.bas file and executing it as machine code. Such case is equivalent to this:

Code:
PRINT "HELLO WORLD"
ASM
  db 195, 0, 0 ; This is JP 0  !!!
END ASM
Compile and run it, and your program will reset the computer, because after the PRINT, it's executing JP 0 (ROM START).
To ensure the execution never reaches the included data files, just place an END. This will exit your program gracefully:
Code:
PRINT "HELLO WORLD"
END : REM Avoid entering the binary data

ASM
  db 195, 0, 0 ; This is JP 0  !!!
END ASM
This is useful, so you can include either ASM files, or even binary .bin files (object files) if they are relocatable, so you needn't compile them again (sort of binary libraries).
Reply
#3
Move the inclusions after the program (after a END instruction) because if there is a ASM block inside program execution, the Spectrun does not know that this is only DATA, he thinks that is is a Assembler program and tries to execute it. But it does not contain a valid program.
This is not a bug, this is normal behaviour of any computer.
Edit: Boriel was faster...
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply
#4
boriel Wrote:To ensure the execution never reaches the included data files, just place an END. This will exit your program gracefully:
Code:
PRINT "HELLO WORLD"
END : REM Avoid entering the binary data

ASM
  db 195, 0, 0 ; This is JP 0  !!!
END ASM

Ahhhhhhhhhhhh I'm executing the bytes of the charset, whatever they do Big Grin I forgot it's inline machine code right into the compiled code. Thank you.
Reply
#5
LCD Wrote:if there is a ASM block inside program execution...

Thank you too for the answer.

By the way, this makes me remember something: these days I've been thinking about and old project of mine, a huge text adventure written in Z80 assembler for the Spectrum. I worked on it for years in the 80's and the 90's. 700 KiB of pure assembler. It's unfinished but its language parser and its virtual world are very advanced (even by today standards in modern platforms). I've been thinking of resurrecting the project... with the help of ZX BASIC. My idea is to keep all the assembler algorithms and data under a new layer of compiled BASIC. They could mix perfectly... as I've just realized Smile
Reply
#6
I plan to resurrect some of my old projects too. Currently for testing the BorIDE I'm working on a very old project of me, called "Youkai Harvest" (it was planed as "Monster Dinner" in the 90's). Found the drafts some months ago again, But there are also more projects to resurrect after the BorIDE is finished.
------------------------------------------------------------
http://lcd-one.da.ru redirector is dead
Visit my http://members.inode.at/838331/index.html home page!
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)