Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 687 online users. » 0 Member(s) | 685 Guest(s) Applebot, Bing
|
Latest Threads |
Includes in ASM
Forum: How-To & Tutorials
Last Post: bracckets
04-04-2024, 12:17 AM
» Replies: 2
» Views: 550
|
Intermittent errors
Forum: Help & Support
Last Post: zarsoft
03-12-2024, 12:39 PM
» Replies: 0
» Views: 310
|
Store array information i...
Forum: Help & Support
Last Post: rbiondi
03-10-2024, 09:42 PM
» Replies: 0
» Views: 399
|
ScrollLeft function scrol...
Forum: Bug Reports
Last Post: rbiondi
03-07-2024, 03:57 PM
» Replies: 2
» Views: 800
|
string.bas errors when co...
Forum: Bug Reports
Last Post: rbiondi
03-01-2024, 10:10 AM
» Replies: 2
» Views: 716
|
Using Beepola with ZX BAS...
Forum: How-To & Tutorials
Last Post: edtoo
02-29-2024, 09:47 AM
» Replies: 15
» Views: 32,694
|
Johnny Bravo
Forum: Gallery
Last Post: zarsoft
02-11-2024, 11:20 PM
» Replies: 0
» Views: 470
|
Compiling +D G+DOS progra...
Forum: ZX Basic Compiler
Last Post: boriel
01-22-2024, 08:32 AM
» Replies: 4
» Views: 8,653
|
VAL = ? (solved)
Forum: Bug Reports
Last Post: zarsoft
01-03-2024, 11:44 PM
» Replies: 8
» Views: 3,198
|
Wrong math (solved)
Forum: Bug Reports
Last Post: zarsoft
01-03-2024, 11:38 PM
» Replies: 4
» Views: 1,748
|
|
|
string slicing using len() |
Posted by: programandala.net - 04-19-2010, 04:09 PM - Forum: Help & Support
- Replies (3)
|
|
I didn't understand why a piece of my program didn't work as expected. I suspected something was wrong with the for-next loop. I tried some tests, simplified versions of the problem, and finally find out the following:
Code: dim text as string
dim i as ubyte
let text="hello world!"
cls
print "Fine:"
for i = 0 to len(text)-1
print i,text(to i)
next i
pause 0
cls
print "All texts are complete!:"
for i = 0 to len(text)-1
print i,;
let text = text(to len(text)-1)
print text
next i
stop
It was a surprise. The second loop prints the same original text every time.
I tried the equivalent code in Sinclair Basic, and of course it worked as expected:
Code: 10 LET A$="hello world!"
20 FOR I=0 TO LEN(A$)-1
30 PRINT I,;
40 LET A$=A$(TO LEN(A$)-1)
50 PRINT A$
60 NEXT I
70 STOP
Then I tried it without the loop:
Code: dim text as string
let text="hello world!"
cls
print text
let text = text(to len(text)-1)
print text
let text = text(to len(text)-1)
print text
let text = text(to len(text)-1)
print text
let text = text(to len(text)-1)
print text
let text = text(to len(text)-1)
print text
let text = text(to len(text)-1)
print text
let text = text(to len(text)-1)
print text
stop
And the problem remained.
Then I hardcoded some slicing values:
Code: dim text as string
let text="hello world!"
print text
let text = text(to 10)
print text
let text = text(to 9)
print text
let text = text(to 8)
print text
let text = text(to 7)
print text
let text = text(to 6)
print text
let text = text(to 5)
print text
stop
And it worked fine.
Is there something I'm missing in my code or is it a compiler issue?
|
|
|
How to change the compiling ORG address? |
Posted by: programandala.net - 04-19-2010, 12:52 PM - Forum: Help & Support
- Replies (1)
|
|
I wonder how to change the default address 32768. I've searched for "org" in the forum archive, but all references are about the assembler ORG. There's no mention in the wiki either.
I blindly tried this:
And this:
But they are not accepted. Then I tried this:
Code: asm
org 24000
end asm
print "hello"
stop
And got the following assembler:
Code: org 32768
__START_PROGRAM:
di
push ix
push iy
exx
push hl
exx
ld hl, 0
add hl, sp
ld (__CALL_BACK__), hl
ei
call __PRINT_INIT
#line 3
org 24000
#line 4
ld hl, __LABEL0
call PRINT_STR
call PRINT_EOL
ld a, 8
call __STOP
ld hl, 0
ld b, h
ld c, l
__END_PROGRAM:
di
ld hl, (__CALL_BACK__)
ld sp, hl
exx
pop hl
exx
pop iy
pop ix
ei
ret
I searched for "or" and "pragma" through the sources, but I found no clue.
|
|
|
About POS |
Posted by: programandala.net - 04-18-2010, 08:25 PM - Forum: ZX Basic Compiler
- Replies (5)
|
|
I just needed the POS function to adapt a code of mine from FreeBASIC... But I didn't suspect POS is already defined in ZX Basic! I realized when the compiler halted: it seems two POS functions are too much
By the way, this was my definition:
Code: #define systemSPOSN 23688
function pos() as ubyte
return 34-peek(systemSPOSN)
end function
First I made some tests, because I wasn't sure if the object code produced by the compiler uses the ROM routines and so the related system variables are updated as well. I find out the content of the S POSN system variable is not the same when the same code is executed by Sinclair Basic or compiled by ZX Basic:
Code: #define systemSPOSN 23688
cls
print at 0,0;peek(systemSPOSN) ' prints 34
print at 1,10;peek(systemSPOSN) ' prints 24
print at 2,20;peek(systemSPOSN) ' prints 14
print at 3,25;peek(systemSPOSN) ' prints 9
stop
' Sinclair Basic prints one less (33, 23, 13 and 8)!
Yes, the same program in Sinclair Basic returns lower values. It's interesting.
Anyway, it's great POS already exists. I took a look at its source file and the rest of library files. There are many interesting undocumented functions.
I created the POS page in the wiki.
|
|
|
conflict between "label EQU" and "#DEFINE label"? |
Posted by: programandala.net - 04-18-2010, 06:51 PM - Forum: Bug Reports
- Replies (1)
|
|
I got the following error:
Quote:random.asm:10: Error: Syntax error. Unexpected token '23672' [INTEGER]
I took a look at the random.asm library. Lines 10 are 11 are the following:
Code: LOCAL TAKE_FRAMES
LOCAL FRAMES
And line 31:
So I suspected the problem had something to do with this line of my program:
Code: #define FRAMES 23672
I defined FRAMES because I use it for several calculations.
I was right: I renamed it MYFRAMES and the error didn't happen again.
Does it means the EQU assembler labels conflict with #DEFINEd labels?
|
|
|
AttributeError: 'SymbolSTRSLICE' object has... (*solved*) |
Posted by: programandala.net - 04-18-2010, 02:49 PM - Forum: Bug Reports
- Replies (6)
|
|
For the second time, I get the following output (version 1.2.5):
Quote:marcos$ zxb.py --tap --autorun --BASIC --sinclair colegio_erevest_4.bas
Generating LALR tables
Generating LALR tables
WARNING: Token 'UMINUS' defined, but not used
WARNING: There is 1 unused token
Traceback (most recent call last):
File "/home/marcos/bin/zxb.py", line 255, in <module>
sys.exit(main(sys.argv)) # Exit
File "/home/marcos/bin/zxb.py", line 203, in main
zxbtrad.traverse(zxbtrad.FUNCTIONS) # This will fill MEMORY with pending functions
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 250, in traverse
traverse(l)
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 959, in traverse
traverse(i)
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 257, in traverse
traverse(i)
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 770, in traverse
traverse(tree.next[1])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 720, in traverse
traverse(tree.next[0])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 1004, in traverse
traverse(tree.next[i])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 1008, in traverse
traverse(tree.next[0])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 569, in traverse
traverse(tree.next[0])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 375, in traverse
traverse(tree.next[0])
File "/opt/zxbasic/1.2.5/zxbtrad.py", line 530, in traverse
if tree.next[0].token != 'STRING' and tree.next[0].token != 'ID' and tree.next[0].symbol._mangled[0] != '_':
AttributeError: 'SymbolSTRSLICE' object has no attribute '_mangled'
I've searched for "mangled" in the forums, but there's no message about it.
It seems it happens when no more syntax errors are found in the source, but I'm not sure. Any clue? Is it a compiler issue or is it caused by my program?
|
|
|
concatenation of a str and a str function result (*solved*) |
Posted by: programandala.net - 04-17-2010, 07:45 PM - Forum: Bug Reports
- Replies (13)
|
|
I cannot understand the reason of some errors I'm getting about converting a string into a value and a value into a string.
In order to debug, I wrote a simplified version of the code:
Code: dim a as ubyte
let a = 10
print "Yes: "+stringIF(a,"yes")+"..." ' ERROR: Cannot convert string to a value. Use VAL() function
print "Nothing: "+stringIF(0,"yes")+"..."
stop
function stringIf(condition as uinteger,text as string) as string
if condition then
return text
else
return ""
end if
end function
stringIf is a simple alternative to the Sinclair Basic use of AND with strings:
Code: LET A$ = "string" AND condition
So I can port it this way:
Code: let aString = stringIf(condition,"string")
I don't understand why the following line fails:
Code: print "Yes: "+stringIF(a,"yes")+"..." ' ERROR: Cannot convert string to a value. Use VAL() function
I tried an alternative, but nothing changed:
Code: dim a as ubyte
dim t as string
let a = 10
let t = "Yes: "+stringIF(a,"yes")+"..." ' ERROR: Cannot convert string to a value. Use VAL() function
let t = "Nothing: "+stringIF(0,"yes")+"..."
stop
Beside those simple tests, I did several tries in the original code, and noted "FINE" or "ERROR" (all variables are DIMed as ubyte):
Code: #define true 1
tell("Son las "+str(currentHour)+stringIf(currentMinute<>0,":"+stringIf(currentMinute<10,"0")+str(currentMinute))+" de la noche.") ' ERROR : Cannot convert string to a value. Use VAL() function
print "Son las "+str(currentHour)+stringIf(currentMinute<>0,":"+stringIf(currentMinute<10,"0")+str(currentMinute))+" de la noche.") ' ERROR : Cannot convert string to a value. Use VAL() function
print "Son las "+str(currentHour) ' FINE
print "Son las "+str(currentHour)+str(currentMinute)+" de la noche." ' FINE
print "Son las "+stringIf(currentMinute<>0,":") ' ERROR: Cannot convert string to a value. Use VAL() function
print "Son las "+stringIf(true,":") ' ERROR: Cannot convert string to a value. Use VAL() function
print stringIf(true,":") ' FINE
One of the tries caused both errors at the same time (string into value and vice versa!):
Code: #define true 1
dim temp as string
' the following line gets two errors:
' Cannot convert value to string. Use STR() function
' Cannot convert string to a value. Use VAL() function
let temp = "Son las "+stringIf(true,":")
print temp
The stringIf function is defined to return a string, so I cannot understand what's the problem.
I tried another thing... Maybe it has to do with concatenation... Let's see:
Code: print "Yes: ";stringIf(a,"yes");"..." ' FINE
it compiles! So the problem has something to do with string concatenation.
I'm stuck. I need some enlightenment.
|
|
|
A help forum |
Posted by: programandala.net - 04-17-2010, 07:16 PM - Forum: Wishlist
- Replies (2)
|
|
Boriel,
I miss a fourth forum for asking for help. I'm working on my second port from Sinclair Basic to ZX Basic, and sometimes I need some help about some issue that it's not in the docs, and I cannot find it in the sources. Meanwhile, I'll keep on using the bugs forum.
What do you think?
|
|
|
error line numbers affected by #if(n)def |
Posted by: programandala.net - 04-16-2010, 07:21 PM - Forum: Bug Reports
- No Replies
|
|
I realized the line numbers shown in the error reports don't include the lines discarded by #ifdef and #ifndef. I mean, the lines of the source discarded by #ifdef and #ifndef are not counted.
I guess the compiler discards those parts before doing the next pass, but the annoyng effect is the lines of errors and warnings are not real.
This is a problem, mainly with long programs where conditional compilation is used a lot.
|
|
|
const as string? |
Posted by: programandala.net - 04-16-2010, 06:29 PM - Forum: Bug Reports
- Replies (6)
|
|
I got the following error with both 1.2.5 and 1.2.6:
"Initializer expression is not constant"
The line is:
const prompt as string = chr(18,1,62,18,0,8)
I supossed the reason is the chr() calculation, so I put a literal string instead:
const prompt as string = "my prompt"
but nothing changed, the error remains.
The wiki page on CONST is not written, so I searched for CONST in the sources for examples. I searched all the sources for a "const as string" example (using a regular expression), but found nothing.
Are constant strings forbidden?
|
|
|
String Issues |
Posted by: britlion - 04-16-2010, 05:15 AM - Forum: Bug Reports
- Replies (3)
|
|
I'm having a weird issue. I have the following code setting a string:
Code: IF currentMatchType=FACUP then let faCupMatchCountString="Round "+STR$(faCupMatchCount)
IF faCupMatchCount=7 Then let faCupMatchCountString="Semi-Final"
ELSEIF faCupMatchCount=8 Then let faCupMatchCountString="Final"
END IF
Later on it prints that string. On a 1-6 it prints "Round 1" / "Round 2" and so on. As soon as the FaCupMatchCount hits 7 it prints gibberish and/or crashes...
Is there a potential issue in the string handling, or have I written more notoriously bad code?
The thing is, it works for the earlier numbers...
(yes, I can provide the whole program again if you wish... It's sometimes difficult to tell if I've done something amiss, or the compiler has - we've had array bounds checking issues already!)
If I change the code so both Ifs say "8" then it prints "Round 7" as expected, and then prints gibberish instead of "Final"
Here's the code that actually prints it at the point that it fails:
Code: if currentMatchType=FACUP then print "F.A.Cup Match - ";faCupMatchCountString
else PRINT "League Match - ";
IF division=4 then print "League 2"
elseif division=3 then print "League 1"
elseif division=2 then print "Championship"
else print "Premier League"
END IF
END IF
It prints "F.A. Cup Match - " and then gibberish on the screen.
|
|
|
|