Welcome, Guest |
You have to register before you can post on our site.
|
Forum Statistics |
» Members: 287
» Latest member: _glPl
» Forum threads: 997
» Forum posts: 6,125
Full Statistics
|
Online Users |
There are currently 73 online users. » 0 Member(s) | 72 Guest(s) Bing
|
Latest Threads |
мешки для мусора
Forum: ZX Basic Compiler
Last Post: _egKl
Yesterday, 02:15 PM
» Replies: 0
» Views: 1
|
Error: STRING CONSTant
Forum: Bug Reports
Last Post: boriel
06-04-2023, 10:52 AM
» Replies: 1
» Views: 26
|
Pascalated ZX BASIC Demo ...
Forum: Gallery
Last Post: zarsoft
06-03-2023, 11:31 AM
» Replies: 0
» Views: 7
|
Compiles OK then crashed
Forum: Bug Reports
Last Post: Neo-Rio
05-30-2023, 11:11 AM
» Replies: 2
» Views: 57
|
Pascalated ZX BASIC Demo ...
Forum: Gallery
Last Post: zarsoft
05-21-2023, 01:07 PM
» Replies: 0
» Views: 41
|
Pascalated ZX BASIC Demo ...
Forum: Gallery
Last Post: zarsoft
05-15-2023, 02:21 PM
» Replies: 0
» Views: 66
|
Pascalated ZX BASIC Demo ...
Forum: Gallery
Last Post: zarsoft
05-06-2023, 07:56 PM
» Replies: 0
» Views: 60
|
No more loading messages ...
Forum: Help & Support
Last Post: zarsoft
05-06-2023, 10:00 AM
» Replies: 2
» Views: 116
|
Pascalated ZX BASIC Demo ...
Forum: Gallery
Last Post: zarsoft
04-29-2023, 04:33 PM
» Replies: 0
» Views: 69
|
Pascalated ZX BASIC Demo ...
Forum: Gallery
Last Post: zarsoft
04-23-2023, 05:37 PM
» Replies: 0
» Views: 66
|
|
|
Pascalated ZX BASIC Demo #2 - Laser |
Posted by: zarsoft - 01-27-2023, 11:49 AM - Forum: Gallery
- No Replies
|
 |
To run online, click here: RUN ONLINE
Code: ' PROGRAM LASER
' Demo for Pascalated BASIC contest
' Version ZX81 (c) 1982 by Zarsoft
' Version ZX BASIC Boriel (c) 2023 by Zarsoft
' Language: Pascalated ZX BASIC (BORIEL) compiled
#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
VAR TRUE TYPE INTEGER = 1
VAR FALSE TYPE INTEGER = 0
REM Variable declarations
REM VAR - Global variables
REM LINA routine variables
VAR SX0 = 0 : VAR SXN = 255
VAR SY0 = 0 : VAR SYN = 175-10
VAR X0 = 0 : VAR Y0 = 88 : ' first point
VAR M TYPE REAL : VAR B TYPE REAL : ' y = mX+b
REM other variables
VAR enemies = 0
VAR enemyX = 0
VAR enemyY = 0
VAR TRON = 1
PROCEDURE LINA
VAR x,y TYPE REAL
VAR dx,dy TYPE INTEGER
VAR w$ TYPE STRING = "0" : ' string starts at index 0
LET y = M*SX0+B: IF y >= SY0 THEN IF y <= SYN THEN LET w$ = w$+CHR$(SX0)+CHR$(y)
LET y = M*SXN+B: IF y >= SY0 THEN IF y <= SYN THEN LET w$ = w$+CHR$(SXN)+CHR$(y)
LET x = (SY0-B)/(M+1E-15): IF x >= SX0 THEN IF x <= SXN THEN LET w$ = w$+CHR$(x)+CHR$(SY0)
LET x = (SYN-B)/(M+1E-15): IF x >= SX0 THEN IF x <= SXN THEN LET w$ = w$+CHR$(x)+CHR$(SYN)
IF LEN(w$)-1 > 2 THEN
PLOT INK 8;CODE(w$(1)),CODE(w$(2))
FOR i=3 TO LEN(w$)-1 STEP 2
dx = CODE(w$(i))-CODE(w$(i-2))
' dy = dy*0 + CODE(w$(i+1))-CODE(w$(i-1)) : ' need to cast to INTEGER (bug?!)
' dy = -1 + CODE(w$(i+1))-CODE(w$(i-1)) + 1 : ' need to cast to INTEGER (bug?!)
dy = CAST(INTEGER,0) + CODE(w$(i+1)) - CODE(w$(i-1)) : ' need to cast to INTEGER (bug?!)
DRAW INK 8;dx,dy
NEXT i
END IF
END PROCEDURE
PROCEDURE GameOver
INK 1
PRINT AT 21,5;"> Well done! Goodbye.";
END PROCEDURE
PROCEDURE Explosion
INK 3
CIRCLE enemyX-1,enemyY+1,4
CIRCLE enemyX+1,enemyY+1,4
CIRCLE enemyX+1,enemyY-1,4
OVER 0
FOR q=1 TO 30: BEEP .002,20+5*RND: NEXT q
PAUSE 100
END PROCEDURE
PROCEDURE OnTarget
LET SXN = enemyX
OVER 1: INK 2
LINA : PAUSE 5 : LINA
OVER 0
LINA
LET enemies = enemies-1
PRINT PAPER 6;INK 0;AT 0,15;" Enemies: ";enemies;" "
Explosion
END PROCEDURE
PROCEDURE TestShot (angle TYPE REAL)
VAR y TYPE REAL
LET M = TAN(angle): LET B = Y0-M*X0
LET y = M*enemyX+B:
IF ABS(y-enemyY) < 5 THEN
OnTarget
ELSE
LET SXN = 255
INK 2
LINA
:FOR q=-10 TO 29: BEEP .005,50-ABS q: NEXT q
ENDIF
END PROCEDURE
FUNCTION ReadAngle TYPE REAL
VAR angle TYPE REAL
REPEAT
PRINT AT 23,0;"Angle = ";
angle = VAL( INPUT(5) )
UNTIL angle > -90 AND angle < 90
PRINT AT 23,0;" ";
LET angle = angle*PI/180 : REM degrees to radians
RETURN angle
END FUNCTION
PROCEDURE ShowEnemy
LET enemyX = 64+RND*182
LET enemyY = 44+RND*122
INK 1
CIRCLE enemyX,enemyY,4
END PROCEDURE
PROCEDURE DrawScreen
CLS
PRINT PAPER 0;INK 7;AT 0,0;" LASER "
PRINT PAPER 6;INK 0;AT 0,15;" Enemies: ";enemies;" "
INK 0
PLOT 0,0: DRAW 0,175 : ' vertical line
PLOT 0,88: DRAW 255,0 : ' horizontal line
END PROCEDURE
PROCEDURE InitVariables
LET enemies = 5
END PROCEDURE
PROCEDURE MainRoutine
VAR angle TYPE REAL
InitVariables
REPEAT
DrawScreen
ShowEnemy
angle = ReadAngle
TestShot(angle)
UNTIL enemies = 0
GameOver
END PROCEDURE
PROGRAM Laser
MainRoutine
PROGRAM END
|
|
|
-1 = 255 (solved) |
Posted by: zarsoft - 01-19-2023, 02:54 PM - Forum: Bug Reports
- Replies (1)
|
 |
Why this gives different results?
How can I force to give -1 ?
PRINT CODE("012"(1)) - CODE("012"(2)) ' gives -1
LET w$="012": PRINT CODE(w$(1))-CODE(w$(2)) ' gives 255
|
|
|
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 |
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 (13)
|
 |
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
|
|
|
|