Welcome, Guest |
You have to register before you can post on our site.
|
Online Users |
There are currently 243 online users. » 0 Member(s) | 240 Guest(s) Applebot, Bing, Yandex
|
Latest Threads |
Printing with FZX
Forum: Help & Support
Last Post: boriel
07-17-2025, 09:08 PM
» Replies: 1
» Views: 348
|
Strange Happenings
Forum: Bug Reports
Last Post: boriel
05-23-2025, 09:15 AM
» Replies: 4
» Views: 2,518
|
.tap file code not execut...
Forum: Help & Support
Last Post: Zoran
04-28-2025, 10:59 AM
» Replies: 4
» Views: 2,708
|
Exit from more than one l...
Forum: Wishlist
Last Post: Duefectu
04-23-2025, 10:06 PM
» Replies: 3
» Views: 2,257
|
put small ASM programs li...
Forum: How-To & Tutorials
Last Post: Zoran
04-18-2025, 02:02 PM
» Replies: 6
» Views: 5,254
|
Creating +3 Menus - Loadi...
Forum: Help & Support
Last Post: merlinkv
04-16-2025, 02:08 PM
» Replies: 6
» Views: 3,693
|
Randomize not very random...
Forum: Help & Support
Last Post: Zoran
04-08-2025, 10:40 AM
» Replies: 4
» Views: 3,425
|
Scope rules
Forum: Bug Reports
Last Post: Zoran
04-04-2025, 09:46 AM
» Replies: 2
» Views: 1,948
|
Using constants not allow...
Forum: Bug Reports
Last Post: baltasarq
03-19-2025, 10:00 PM
» Replies: 8
» Views: 4,733
|
404 page not found
Forum: Documentation
Last Post: boriel
03-08-2025, 07:16 PM
» Replies: 5
» Views: 5,424
|
|
|
Pascalated ZX BASIC Demo |
Posted by: zarsoft - 01-19-2023, 10:08 AM - Forum: Gallery
- Replies (2)
|
 |
To run online, click here: RUN ONLINE
Code: ' PROGRAM factorials
' Demo for the Pascalated language
' Language: Pascalated ZX BASIC (BORIEL) (compiled)
' Pascalated Sinclair BASIC (c) 1987 by ZarSoft
' Pascalated Boriel (c) 2023 by ZarSoft
' ZX BASIC compiler was created by Boriel
#include <input.bas>
'--- Pascalated Boriel ---
#define VAR DIM
#define INTEGER LONG
#define REAL FLOAT
#define TYPE AS
#define REPEAT DO
#define UNTIL LOOP UNTIL
#define PROCEDURE SUB
#define PROGRAM REM
REM Variable declarations
REM VAR - Global variables
REM Uppercase are different from lowercase
VAR limit TYPE INTEGER : REM max argument to build the list
PROCEDURE Introduction
CLS
PRINT AT 13,0
PRINT "+-----------------+"
PRINT "| factorial list |"
PRINT "+-----------------+"
PRINT " Demonstration for"
PRINT " Pascalated ZX BASIC (Boriel)"
PRINT " (c) 2023 by Zarsoft"
PRINT
PRINT
END PROCEDURE
PROCEDURE GetLimit
REPEAT
PRINT "Max argument = ";
limit = VAL( INPUT(9) ) : PRINT limit
IF limit >= 12 THEN
PRINT
PRINT "Must be lower than 34."
PRINT "Try again."
PRINT
ELSE IF limit < 0 THEN
PRINT
PRINT "Must be greater than 0."
PRINT "Try again."
PRINT
ELSE
PRINT
PRINT "Valid input."
PRINT
END IF
UNTIL (limit >= 0) AND (limit <= 33)
END PROCEDURE
FUNCTION CalculateFactorial (argument TYPE INTEGER) TYPE REAL
VAR result TYPE REAL
LET result = 1
WHILE argument > 1
LET result = result * argument
LET argument = argument-1
END WHILE
RETURN result
END FUNCTION
PROCEDURE WriteFactorials
VAR w TYPE INTEGER
VAR argument TYPE INTEGER
VAR result TYPE REAL
PRINT
FOR w = limit TO 0 STEP -1
LET argument = w
PRINT "fact(";argument;") = ";
result = CalculateFactorial(argument)
PRINT result
NEXT w
END PROCEDURE
PROCEDURE MainPROCEDURE
Introduction
GetLimit
REPEAT
WriteFactorials
PRINT
PRINT "Write 0 to terminate."
GetLimit
UNTIL limit = 0
END PROCEDURE
PROGRAM factorials
MainPROCEDURE
PROGRAM END
|
|
|
My first Boriel BASIC program: Guess Number |
Posted by: zarsoft - 11-30-2022, 10:54 AM - Forum: Gallery
- No Replies
|
 |
To run online, click here: RUN ONLINE
Here is the source:
Code: ' PROGRAM GUESS NUMBER
' (c) 2022 by Zarsoft
' Language: ZX BASIC (BORIEL) compiled
#include <input.bas>
#define REPEAT DO
#define UNTIL LOOP UNTIL
#define ROUTINE SUB
#define PROGRAM REM
REM Variable declarations
REM VAR - Global variables
DIM secret AS INTEGER : REM number 1-1000
DIM guess AS INTEGER : REM user guess
LET tries = 0 : REM number of tries
LET GoodGame = 0 : REM user guessed on few tries
LET YouGuessed = 0 : REM User guessed it right
ROUTINE Introduction
CLS
PRINT AT 13,0
PRINT "+------------------+"
PRINT "| GUESS THE NUMBER |"
PRINT "+------------------+"
PRINT " (c) Zarsoft, 2022"
PRINT " ZX BASIC (Boriel)"
PRINT
PRINT
END ROUTINE
ROUTINE PickNumber
PRINT
PRINT "I am thinking of a Number"
PRINT "between 1 and 1000"
PAUSE 50
LET secret = 1+INT (RND*1000)
REM PRINT "secret= ";secret
END ROUTINE
ROUTINE GetUserGuess
PRINT "What is your guess? ";
guess = VAL( INPUT(9) )
LET tries = tries + 1
END ROUTINE
ROUTINE TestGuess
IF guess = secret
LET YouGuessed = 1
PRINT
PRINT "Congratulations, human!"
PRINT "The number was ";secret
PRINT "On target in ";tries;" tries."
PAUSE 50
ELSEIF guess < secret
LET YouGuessed = 0
PRINT
PRINT "Try one bigger than ";guess
PAUSE 50
ELSE
LET YouGuessed = 0
PRINT
PRINT "Try one smaller than ";guess
PAUSE 50
ENDIF
END ROUTINE
ROUTINE TestGoodGame
IF tries <= 10
LET GoodGame = 1
ELSE
PRINT
PRINT "But, it took too much time."
PRINT "Lets try again!"
PAUSE 50
ENDIF
END ROUTINE
ROUTINE GameOver
PRINT
PRINT "GAME OVER - insert another coin"
PRINT
PRINT
PRINT
PRINT
END ROUTINE
ROUTINE Game
InitVariables
PickNumber
REPEAT
GetUserGuess
TestGuess
UNTIL YouGuessed
END ROUTINE
ROUTINE MainRoutine
Introduction
REPEAT
Game
TestGoodGame
UNTIL GoodGame
GameOver
END ROUTINE
PROGRAM GuessNumber
MainRoutine
PROGRAM END
|
|
|
REPEAT UNTIL (solved) |
Posted by: zarsoft - 11-28-2022, 06:54 PM - Forum: Wishlist
- Replies (3)
|
 |
Hi
I'd like to use the Pascal mode because it's simpler:
Code: REPEAT
[<sentences>]
UNTIL <condition>
I dont like to use:
Code: DO
[<sentences>]
LOOP UNTIL <condition>
|
|
|
Print color bug (*solved*) |
Posted by: Darkstar - 10-03-2022, 08:18 PM - Forum: Bug Reports
- Replies (19)
|
 |
Code: Declare sub CenterText (ByVal Row as ubyte, ByVal Text as string)
Ink 6
Paper 1
Print at 20, 0; "\k";
Ink 7
Paper 0
'Print ; 'Put here to update colors, there is a bug in the compiler.
CenterText (21, "Hello")
Sub CenterText (ByVal Row as ubyte, ByVal Text as string)
Dim i As UInteger
i = Len(Text) / 2
i = 16 - i
Print at Row, i; Text;
End sub
Hi there Boriel.
The above code does not work correctly, both the "K" and the word "Hello" come out with blue paper and yellow ink unless you unrem the print statement. Then the "Hello" comes out with black paper and white ink.
This was not a problem before, this is a recent problem. I can use this "print" workaround for the time being but there is a bug in the complier.
|
|
|
Binary into asm |
Posted by: Nando - 07-31-2022, 12:27 AM - Forum: Help & Support
- Replies (12)
|
 |
Hi everyone.
I'm trying to create a routine in assembly to copy an image from memory to the screen (a third of the screen, centered)
I know the assembly code to do this.
But, in ZX Basic, afaik, I must include the image from a bin file, and label it (I know how to do that)
So, if I need to use the address of the bin file, in Basic I would use @label (and this works)
But how to I use this label inside an asm routine?
Code: art:
asm
incbin "final.bin"
end asm
pause 0
paper 0: ink 7: border 0: CLS
asm
ld hl,(_art)
ld de,18434
ld bc,2048
ED
LDIR
RET
end asm
It's probably some syntax issue. I need to load HL with the address of the bin file, but get "error: Undefined GLOBAL label '._art'" when compiling
|
|
|
Set Number Layout to xx.00? |
Posted by: Lars_74 - 07-28-2022, 11:11 PM - Forum: Help & Support
- Replies (1)
|
 |
Hi,
I have been trying all evening to work on a very easy task. Well, I thought it would be easy... Nothing really worked and the only positive sideffect is that I learned a lot about ZX Basic.
I would like to set the number's layout to xx.00 Because it looks nicer.
Examples:
1.5 > 1.50
1 > 1.00
.1 > 0.10
The only thing I could come up is to work on two levels.
level a: the correct numbers the computer is working with, e.g. 12.012345
level b: the number handed over to a Sub-Routine which switches the number to a string, searches for "." and gives back a formated string to the main routine.
Thus: the Spectrum works with level a (number), the user only sees level b (string).
Is it really that difficult or is it me being just to stupid...?
Lars
|
|
|
Features breaking compilation in older ZXBasic programs |
Posted by: MrKOSMOS - 06-17-2022, 06:51 AM - Forum: Core
- Replies (1)
|
 |
Hello
So I've been using ZXBasic for a while, and after struggling for a while trying to compile some code finally realised some issues. To sum it up, I tried compiling Souls Remastered, since the keyboard input wasn't working on my Timex TC2048. However, while trying to compile I kept getting IF statement errors, which I attributed to the compiler itself. However, it turned out to be due to comments placed in front of the IFs, which were being recognized as one-line commands and "resolving" the IFs, creating errors with the END IFs afterwards. This seems to date back to a previous version before the one-line IF feature was implemented. In fact, many other ZXBasic games by Retrobytes and even the BerkzMan game from the tutorials page seem to expect this feature to be absent in order to compile, so providing a solution seems like a must.
So what do I propose? Well, I see two solutions: One, adding a legacy option for the compiler, say -L. This would be the easiest, and allow compilation of unmodified older code.
Two: implementing a routine that counts all IFs and END IFs in the program flow and checks if they are the same, as well as checking for comments in front of IFs. This may be a more robust solution, letting everyone program as they want without having to check some obscure command line option.
Aside from that, there seem to be a few other bugs. There seems to be no check for writing to memory above the 64k limit, since I have written a few programs that, when loaded through the BASIC loader, give an Out Of Memory error on the Spectrum. Other than that, there seems to be a bunch of data added along the print command, which I assume is a character set. But is this really necessary when the program only uses UDGs or spaces? In that case, the whole set could be left out, saving a decent amount of space. It could even be optionally left out, and swapped for the ROM character set.
Well that would be all, please say what you think
|
|
|
|