Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 385
» Latest member: DayanaAmoni
» Forum threads: 1,028
» Forum posts: 6,212

Full Statistics

Online Users
There are currently 606 online users.
» 0 Member(s) | 604 Guest(s)
Bing, Google

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: 715
Using Beepola with ZX BAS...
Forum: How-To & Tutorials
Last Post: edtoo
02-29-2024, 09:47 AM
» Replies: 15
» Views: 32,679
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,652
VAL = ? (solved)
Forum: Bug Reports
Last Post: zarsoft
01-03-2024, 11:44 PM
» Replies: 8
» Views: 3,195
Wrong math (solved)
Forum: Bug Reports
Last Post: zarsoft
01-03-2024, 11:38 PM
» Replies: 4
» Views: 1,747

 
  PRINT '''''' (solved)
Posted by: zarsoft - 01-27-2023, 08:48 PM - Forum: Help & Support - Replies (1)

How do I translate this to ZX BASIC?

PRINT ''''''

(print several blank lines)

Print this item

  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

Print this item

  -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

Print this item

  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

Print this item

  First public release of ZX BASIC
Posted by: zarsoft - 01-18-2023, 04:57 PM - Forum: Documentation - Replies (1)

When was the first public release of ZX BASIC?
2010?

Print this item

  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

Print this item

  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 this item

  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.

Print this item

  SIN and COS functions have bug ?
Posted by: papa_robot - 08-16-2022, 09:42 PM - Forum: Help & Support - Replies (2)

Hello to the zx basic community. I'm integrating the compiler into my own spectrum bot.

I created a sample sinewave graph

Code:
FOR x = 10 TO 245 STEP 2
  PLOT x,100+SIN(2*x*PI/180)*50
NEXT x

However I see the values jump around 90 deg, see video here

https://twitter.com/ZxSpectrumBot1/statu...twCv438ECA

I cannot find any reference in the doc , it is supposed to be sinclair compatible, but in sinclair basic it works ok

https://twitter.com/ZxSpectrumBot1/statu...twCv438ECA

thanks a lot

Print this item

  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

Print this item