Author Topic: CPCBasic Unchained  (Read 7490 times)

0 Members and 1 Guest are viewing this topic.

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
CPCBasic Unchained
« on: 15:54, 26 September 19 »
Unchained? Yes, without a CPC, without a CPC emulator.
CPCBasic runs in a Browser. Compiled to JavaScript. Output to HTML5 canvas.
 
 I just finished v0.3 and put it on GitHub.
 
 If you want to try it with some samples:
 https://benchmarko.github.io/CPCBasic/cpcbasic.html
 
 Readme:
 https://github.com/benchmarko/CPCBasic/#readme
 
Ideas, thoughts, contributions are welcome.

 Have fun!
Marco
« Last Edit: 15:57, 26 September 19 by mv »

Offline Gryzor

  • Administrator
  • 6128 Plus
  • *****
  • Posts: 15.945
  • Country: gr
  • CPC-Wiki maintainer
    • CPCWiki
  • Liked: 3415
  • Likes Given: 6126
Re: CPCBasic Unchained
« Reply #1 on: 16:00, 26 September 19 »
That's fun! Going to come in handy when I come across a listing, instead of opening an emulator! :) Bookmarked!


Perhaps make the input window longer? [EDIT] ah I can drag it, never mind :D
« Last Edit: 16:03, 26 September 19 by Gryzor »

Offline BSC

  • CPC6128
  • ****
  • Posts: 265
  • Country: de
  • CPC 464 aspirant
    • my (Android) mobile game
  • Liked: 331
  • Likes Given: 300
Re: CPCBasic Unchained
« Reply #2 on: 21:47, 26 September 19 »
Ideas, thoughts, contributions are welcome.


That's awesome! Thanks for making and publishing it. If I had more lives, I would love to contribute, but I fear that I won't do that..
BUT I am looking forward to see this project evolve. Also, welcome back! (I assume you were not active on the CPC for a while)

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.892
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1104
  • Likes Given: 1867
Re: CPCBasic Unchained
« Reply #3 on: 02:15, 27 September 19 »
Marco, if you need some BASIC stuff to test my Silly Programming Ideas - Turning Text into Graphics has lots of stuff in it. My 1st example wasn't working, I'm guessing because of it using SYMBOL, though this example below wasn't working quite right either.
Code: [Select]
10 MODE 0:BORDER 0:INK 1,26:INK 0,0:INK 2,2:INK 3,11:INK 4,25
20 GOSUB 3000
30 x=100:y=100:p=1
40 WHILE p<>65
50 WHILE x<>132
60 PLOT x,y,o(p):p=p+1:x=x+4
70 WEND
80 x=100:y=y-2
90 WEND
100 WHILE INKEY$<>CHR$(13):WEND:MODE 2:END
3000 DIM o(64):FOR n=1 TO 64:READ o(n):NEXT n:RETURN
3010 DATA 1,0,0,0,0,0,0,1
3020 DATA 2,1,1,1,1,1,1,2
3030 DATA 2,3,3,4,4,4,3,2
3040 DATA 2,3,3,4,3,3,3,2
3050 DATA 2,3,4,4,4,3,3,2
3060 DATA 2,3,3,4,3,3,3,2
3070 DATA 2,3,4,4,4,4,3,2
3080 DATA 0,2,2,2,2,2,2,0



Otherwise a great bit of work.  :)


EDIT: Okay I see what's happening. :)  Isn't quite simulating MODE 0 yet, so will produce the colour scheme, but not the horizontal pixel axis.
« Last Edit: 02:26, 27 September 19 by AMSDOS »
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
Re: CPCBasic Unchained
« Reply #4 on: 22:40, 27 September 19 »
Marco, if you need some BASIC stuff to test my Silly Programming Ideas - Turning Text into Graphics has lots of stuff in it. My 1st example wasn't working, I'm guessing because of it using SYMBOL, though this example below wasn't working quite right either.EDIT: Okay I see what's happening. :)  Isn't quite simulating MODE 0 yet, so will produce the colour scheme, but not the horizontal pixel axis.
Thank you for the pointer. I will check it.SYMBOL was ok, but transparent mode with chr$(22) was not implemented. (I never used it.)I changed the canvas coding to use a pixelbuffer. No filigree lines any more but it looks more like a CPC.
And I also put in transpararent mode. Your example seems to work now...
« Last Edit: 22:44, 27 September 19 by mv »

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.892
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1104
  • Likes Given: 1867
Re: CPCBasic Unchained
« Reply #5 on: 01:07, 28 September 19 »
Thank you for the pointer. I will check it.SYMBOL was ok, but transparent mode with chr$(22) was not implemented. (I never used it.)I changed the canvas coding to use a pixelbuffer. No filigree lines any more but it looks more like a CPC.
And I also put in transpararent mode. Your example seems to work now...


Sorry my mistake regarding the SYMBOL command. I was able to try a few examples from my thread and discovered the condensed character set from it was working.  :)


So transparent mode was the culprit, the Block Editor program I posted in there now correctly functions in it.  :)


The only other demo I had from within there which wasn't working is this example:


Code: [Select]
10 MODE 0: INK 0,0:INK 1,26:INK 4,3:INK 6,1:INK 7,2:INK 8,4:INK 9,16
20 DIM col%(242):GOSUB 100:a%=1
30 WHILE (y%<>22)
40 FOR x%=1 TO 11
50 LOCATE x%,25:PEN col%(a%):PRINT CHR$(143);
60 a%=a%+1
70 NEXT x%:LOCATE 1,25:PRINT CHR$(10):y%=y%+1:WEND
80 CALL &BB18:PEN 1:MODE 2:END
100 ' Set up Colours
110 FOR a%=1 TO 241
120 READ c%
130 col%(a%)=c%
140 NEXT a%:RETURN
150 DATA 0,4,4,4,4,4,4,0,0,0,0
160 DATA 0,4,4,4,4,4,4,4,4,4,0
170 DATA 0,4,4,4,4,4,4,9,4,4,0
180 DATA 4,4,4,4,4,4,4,9,4,4,0
190 DATA 4,4,4,4,4,4,9,9,9,4,4
200 DATA 4,4,4,4,1,0,9,0,1,4,4
210 DATA 4,9,4,9,1,0,9,0,1,4,4
220 DATA 0,9,4,9,1,0,9,0,1,4,4
230 DATA 0,9,9,9,1,0,9,0,1,4,0
240 DATA 0,4,9,9,1,1,9,1,9,9,0
250 DATA 0,4,9,9,9,1,9,1,9,9,0
260 DATA 0,4,9,9,9,9,9,9,9,9,0
270 DATA 0,7,4,9,9,9,0,9,9,9,0
280 DATA 7,7,7,9,9,9,9,9,9,8,0
290 DATA 7,7,7,8,7,7,7,8,7,8,0
300 DATA 7,7,9,8,7,7,7,8,9,9,0
310 DATA 7,9,9,9,8,8,8,8,9,9,0
320 DATA 0,9,9,8,6,1,6,1,8,9,0
330 DATA 0,8,8,8,8,6,6,6,6,8,0
340 DATA 0,8,8,8,8,8,8,8,8,8,8
350 DATA 0,4,6,6,6,0,6,6,6,6,4
360 DATA 0,4,4,4,4,0,4,4,4,4,4


I understand now that you haven't implemented all the control codes though, which is why this isn't working. This one uses Control Code 10 to roll the screen up, so I'm not sure how difficult that would be to do in Javascript, but anyhow I guess they will be hurdles to come.  :)
« Last Edit: 01:09, 28 September 19 by AMSDOS »
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
Re: CPCBasic Unchained
« Reply #6 on: 00:50, 02 October 19 »
So transparent mode was the culprit, the Block Editor program I posted in there now correctly functions in it.

The only other demo I had from within there which wasn't working is this example:
...

I understand now that you haven't implemented all the control codes though, which is why this isn't working. This one uses Control Code 10 to roll the screen up, so I'm not sure how difficult that would be to do in Javascript, but anyhow I guess they will be hurdles to come.
It was not so difficult to get the rolling effect with chr$(10) working. To see it in the demo, insert "call &bd19" before the "wend", otherwise it would be too fast:
Code: [Select]
70 NEXT x%:LOCATE 1,25:PRINT CHR$(10):y%=y%+1:call &bd19:WEND
With chr$(11) implemented, https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=cpc464ch works as well (without blinking colors).

The block editor was also interesting. I followed the thread to find out why column 20 cannot be selected, but when allowing it and moving in column 20, I cannot see an issues.

I also tried another version of the block editor which uses the cursor keys for movement. Unfortunately it did not work because upper$(chr$(240)) was not chr$(240).
I learned that JavaScript String.toUpperCase() converts not only "a"-"z" but also some other characters, including the CPC cursor codes.

There were other little surprises, like a "for" loop which was an endless loop (from my own coding):
Code: [Select]
100 i=1:FOR i=i TO i+5 ?i;:next
The end condition was evaluated again and again.

BTW, may I take the code snippets and use them as CPCBasic samples?
I am also thinking of a separate collection of BASIC samples with unclear license or copyright.
« Last Edit: 00:53, 02 October 19 by mv »

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.892
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1104
  • Likes Given: 1867
Re: CPCBasic Unchained
« Reply #7 on: 13:51, 02 October 19 »
It was not so difficult to get the rolling effect with chr$(10) working. To see it in the demo, insert "call &bd19" before the "wend", otherwise it would be too fast:
Code: [Select]
70 NEXT x%:LOCATE 1,25:PRINT CHR$(10):y%=y%+1:call &bd19:WENDWith chr$(11) implemented, https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=cpc464ch works as well (without blinking colors).



 :)

Quote
The block editor was also interesting. I followed the thread to find out why column 20 cannot be selected, but when allowing it and moving in column 20, I cannot see an issues.


I think it has something to do with how the original BASIC 1.0 manages strings, what's that got to do with the Block Editor? In the Block Editor is some code which helps preserve the Block and when the Cursor Moves the Transparent Mode needs to be switched off , the PEN refers to the old x and y position of the array to set what colour block is there, LOCATE is used with the old x & y positions and Character 143 (a Solid Block) is Printed. In the original Preserve Block I used LOCATE first with the old x & y, PEN to refer to the Colour number from the Array and then I issued a Turn Transparent Mode Off followed by printing a block and then Turning the Transparent Mode On. I can't remember now how long now I've been emulating using 464 with BASIC 1.0. I wrote that in 2015 and I think in 464 Mode as I remember tying in some 1984 type-ins in 2014 as a bit of a tribute of them early programs.
Though getting back to the problem I had with the Block Editor, I recall Devilmarkus mentioned somewhere about control codes occupying space on the screen despite not being displayed, I'm not sure if it were a problem limited to BASIC 1.0 or if BASIC 1.1 had the same trouble, but in this case it was about having the Transparent Mode On/Off inbetween my chr$(143) block and having my LOCATE positioned before drawing the block which solved that 20x25 issue, otherwise previoiusly if I moved my cursor to Line 20 and Moved my Cursor Down the Screen the Cursor from above wasn't being Deleted.

Quote
I also tried another version of the block editor which uses the cursor keys for movement. Unfortunately it did not work because upper$(chr$(240)) was not chr$(240).
I learned that JavaScript String.toUpperCase() converts not only "a"-"z" but also some other characters, including the CPC cursor codes.



Yeah it's a funny way of handling the use of the cursor keys, it seems to be the only valid way using INKEY$ but I guess if I didn't have UPPER$ it would work, but would have to change the Lines to include upper and lower case letters in the IF statement. I think it was around that time I was trying to use INKEY() instead with the Key Number, but was too fast for a simple Block Editor.

Quote
There were other little surprises, like a "for" loop which was an endless loop (from my own coding):
Code: [Select]
100 i=1:FOR i=i TO i+5 ?i;:next

The end condition was evaluated again and again.



Yeah I'm unsure if the FOR Loop problem relates to this bit of code I posted here, but the following code in there works fine.

Quote
BTW, may I take the code snippets and use them as CPCBasic samples?
I am also thinking of a separate collection of BASIC samples with unclear license or copyright.



Feel free to use any of my samples, I have a number of other threads with some BASIC stuff in them too as well as little bits and pieces on the CPCWiki Source Code page. Some of the other threads I've made cover past BASIC type-ins from Magazines which I did to cover a problematic listing or something which could of been improved on, in terms of license or copyright if the authors are acknowledged you should be fine.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
Re: CPCBasic Unchained
« Reply #8 on: 23:13, 06 October 19 »
I think it has something to do with how the original BASIC 1.0 manages strings,...
Thank you for pointing to BASIC 1.0. I tried it with an emulated CPC 464, and there is the issue.
After some experiments, I found a subtile difference with printing "?chr$(22)+chr$(0);" and "chr$(22);chr$(0);" in the last column.
BASIC 1.0 seems to assume that the string "chr$(22)+chr$(0)" with length 2 does not fit in the line, even if it contains just control codes.
So we have another way to detect a CPC 464 (independend of current mode):
Code: [Select]
?chr$(30);chr$(10);chr$(;chr$(22)+chr$(0);:if pos(#0)=1 then ?"CPC 464" else ?"CPC 664/6128"

Quote
Yeah it's a funny way of handling the use of the cursor keys, it seems to be the only valid way using INKEY$ but I guess if I didn't have UPPER$ it would work, but would have to change the Lines to include upper and lower case letters in the IF statement. I think it was around that time I was trying to use INKEY() instead with the Key Number, but was too fast for a simple Block Editor.
That was an issue in CPCBasic, UPPER$(chr$(240))=chr$(240) is fixed now.

Quote
Yeah I'm unsure if the FOR Loop problem relates to this bit of code I posted here, but the following code in there works fine.
Also fixed.

Quote
Feel free to use any of my samples, I have a number of other threads with some BASIC stuff in them too as well as little bits and pieces on the CPCWiki Source Code page. Some of the other threads I've made cover past BASIC type-ins from Magazines which I did to cover a problematic listing or something which could of been improved on, in terms of license or copyright if the authors are acknowledged you should be fine.
Thank you. I integrated the block editor, with a sample and some slight modifications:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=blkedit
« Last Edit: 18:13, 27 April 20 by mv »

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.892
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1104
  • Likes Given: 1867
Re: CPCBasic Unchained
« Reply #9 on: 11:56, 07 October 19 »
I was getting some interesting results from My Simple Platform Game BASIC examples. Most of those are using Sprite Drivers which I know won't work with CPCBasic, but the 1st 2 examples are entirely in BASIC, the 1st using the standard Character set with simple character and one Redefined Hazard. The 2nd again uses the Transparent Mode and Redefines into the Colourful Graphics I have with the 8x8 Sprite Driver version of the game. I just had to add a CALL &BD19 into the Main Loop of the game for it to be playable, though just thought you maybe interested.


The only other thing I noticed with CPCBasic, was while POKE works, it doesn't work when POKEing a Byte to Screen (my other thread has an example of it written in BASIC). At the time I wrote it thought it might of been a bit pointless, though it seems to work well when CPC BASIC 3 Cross Compiler is used.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
Re: CPCBasic Unchained
« Reply #10 on: 01:54, 10 October 19 »
I was getting some interesting results from My Simple Platform Game BASIC examples. Most of those are using Sprite Drivers which I know won't work with CPCBasic, but the 1st 2 examples are entirely in BASIC, the 1st using the standard Character set with simple character and one Redefined Hazard. The 2nd again uses the Transparent Mode and Redefines into the Colourful Graphics I have with the 8x8 Sprite Driver version of the game. I just had to add a CALL &BD19 into the Main Loop of the game for it to be playable, though just thought you maybe interested.
Good to hear that it is playable. CPCBasic could also integrate some RSX for sprites. Or at least some pixel scrolling. From the sprite drivers you tested, do you remember which was most useful?
I also think of a simple multi-mode extension that could also be used for a true CPC with some extension.
For example, |MODE,m,area; where m is the mode number and area is the bit combination of the screen areas 0..5 (defined by the timer interrupt). |MODE does not clear the screen but only changes the mode for the following print and draw commands. You only need to use them in screen areas with a matching mode.
Quote
The only other thing I noticed with CPCBasic, was while POKE works, it doesn't work when POKEing a Byte to Screen (my other thread has an example of it written in BASIC). At the time I wrote it thought it might of been a bit pointless, though it seems to work well when CPC BASIC 3 Cross Compiler is used.
Good idea. Then I need to remember how the pixels are encoded in screen bytes. Would also allow to load and save screens someday.


Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.892
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1104
  • Likes Given: 1867
Re: CPCBasic Unchained
« Reply #11 on: 12:43, 10 October 19 »
Good to hear that it is playable. CPCBasic could also integrate some RSX for sprites. Or at least some pixel scrolling. From the sprite drivers you tested, do you remember which was most useful?


With CPCBasic I wasn't sure if you were coding it to have Locomotive BASIC perform like the Compiler, or if you were looking to eventually make it as accurate as Locomotive BASIC. My Second Simple Platform Game with the Multicoloured Graphics for instance runs like a Compiled BASIC and have just assumed that you're making it more like a Compiled BASIC because of the Compile Only. Anyway, I was only wondering in case you were after something based on accuracy, rather than speed. I had no objection.


All the Sprite Drivers I tested had their Good & Bad Points unfortunately. I put them all together because they all operated on a Text Coordinates principle with the exception of Spriting Back Utility which used some 80x50 grid for Sprite Placement, though with some Calculations, could work out a Text Coodinate position and use that instead of what AA had (an invisible square around the sprite to make it "appear" to move smoothly).


Spritemaker v2.3 had extra features the other Sprite Drivers didn't have and simply printing a Sprite with that was to have the Sprite in BASIC Data Statements, using the COMPILE command with the Start and End Line Numbers, the BASIC LOCATE command is used to Position the Sprite and a SPRITE command to display it. It has provision for Printing Sprite in Front or Behind the Background Sprites which both of my examples demonstrates as well, because it uses BASIC to position the Sprite with the LOCATE command Scrolling from the Firmware is supported, unlike Ariom Sprites or Spriting Back Utility which wouldn't allow because of the way Sprites were Handled when drawing to screen, but for those Sprite Drivers Drawing to screen was faster. Spritemaker v2.3 lacks a Sprite Editor, but found it quite easy to simply plant a Picture in Art Program and assign Numbers for each colour used and earlier this year I got permission from Sara Vilaplana RUA to use the Graphics from the unfinished Crocker game submitted at last years cpcretrodev compo using Spritemaker v2.3. The result from that was Crocked. I only other limitation I could find from it was because of all the Sprite Data being stored in DATA statements, the BASIC file quickly becomes quite large, there might have been some other way of loading the data seperately, though the only other option I recall noticing with Spritemaker was an IMPORT command to capture the Sprites onscreen using that command, though haven't tried it.


As you may have noticed though, I write all the Simple games around here and use the Simple tools, I use Assembly occasionally though even that has Firmware in it, I just wondered if a tool like 8BP would be more ideal? It works using Graphical coordinates rather than Text Cooridinates, unless you rather work towards that later I guess, that's the only reason I can think of why start with the simple stuff.  ;D

* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
Re: CPCBasic Unchained
« Reply #12 on: 01:18, 18 December 19 »
With CPCBasic I wasn't sure if you were coding it to have Locomotive BASIC perform like the Compiler, or if you were looking to eventually make it as accurate as Locomotive BASIC.
...
Accuracy or speed, that is the question. Always seems to be a compromise. I am still not sure which way to go with CPCBasic.
At first I thought it would be enough to get a BASIC program running, even with some efford.
Then I switched to more accuracy, so that a BASIC program can be run with minimal changes. And I found edge cases in BASIC that surprised me.
For example, what is the output of the following progam?
10 IF 1 THEN DATA 10:ELSE DATA 20
30 ELSE DATA 30
40 ELSE PRINT 35:DATA 40:READ a:PRINT a
50 DATA 50:READ a:PRINT a

I am still confused. At some point, improving arruracy is very time-consuming.

In the meantime, I was busy  putting in some sound and fixing issues when testing new BASIC programs.

And finally, I put in screen memory access with Peek&Poke. Some examples:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=test/scrtest
https://benchmarko.github.io/CPCBasic/cpcbasic.html?database=apps&example=demo/gdemo
gdemo used a very simple sprite driver. Coordinate calculations in BASIC but the drawing in assembler. I converted it to BASIC and it is still fast enough - with CPCBasic.
Time to check some of the sprite drivers you mentioned.

And I started another collection of BASIC programs:
https://github.com/benchmarko/CPCBasicApps/#readme

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.892
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1104
  • Likes Given: 1867
Re: CPCBasic Unchained
« Reply #13 on: 12:38, 19 December 19 »
I can't remember what I was thinking back in October regarding Speed Vs. Accuracy. I think it was to do with creating a Compiled or Intrepreted language, I was probably thinking with the compiled aspect it would be looking at more of a CPC BASIC 3 like language, though CPC BASIC 3 is it's own language replacing DEFINT and DEFREAL with DEFBYTE and DEFWORD for example, though including a lot of the Locomotive BASIC traits that work for the Compiler, and removing other parts of Locomotive BASIC that don't quite work with the Compiler.
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
Re: CPCBasic Unchained
« Reply #14 on: 00:47, 21 December 19 »
I can't remember what I was thinking back in October regarding Speed Vs. Accuracy. I think it was to do with creating a Compiled or Intrepreted language, I was probably thinking with the compiled aspect it would be looking at more of a CPC BASIC 3 like language, though CPC BASIC 3 is it's own language replacing DEFINT and DEFREAL with DEFBYTE and DEFWORD for example, though including a lot of the Locomotive BASIC traits that work for the Compiler, and removing other parts of Locomotive BASIC that don't quite work with the Compiler.
Ok, then maybe we are talking about different aspects.
 CPCBasic is not another language, but mainly Locomotive BASIC. The main difference is the execution speed, which results in a CPC equivalent of around 14-17 GHz for a simple BASIC loop, depending on the browser and the system on which it is running. You may check it with
https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=test/cpcmhz
 Most BASIC programs are not designed for this speed. They need a delay with e.g. call &bd19 here and there.

 Unfortunately BASIC cannot be compiled 1-to-1 in JavaScript. Many things are not known at compile time but only at runtime. Perhaps a subset of the BASIC (good idea!) or some restrictions where certain instructions can be used could help. For example, there is no GOTO in JavaScript. CPCBasic uses a large switch/case, with the case labels as line numbers. FOR and WHILE loops cannot converted to its JavaScript counterparts because jou can jump in and out in BASIC with GOTO, but not in JavaScript. So everything has to be done with the simulated GOTO using case labels. And additional labels, if you have to jump to instructions which are in the middle of a line.

 Speaking of DEFINT and DEFREAL, they can be anywhere in the program. That means that you do not know the type of a variable at compile time, unless it is marked with a type suffix %,! or $. That also means, you cannot simply write "a1=10.5" in JavaScript. A helper function "a1=vmAssign("a", 10.5)" must be used, where "a" is the first letter of the variable "a1" to determine its type at runtime. If there was a "DEFINT a" at runtime, "a1" is an integer and is given the (rounded!) value 11. If the programs always uses an explicit conversion with INT or ROUND (and you do not need a type check), such a helper function would not be necessary. (It lost roughly a "GHz".)
These are just a few aspects. The button "Compile only" only executes the BASIC->JavaScript compile step without running the programt. You can check and change the JavaScript and run it with the JavaScript "Run" button.

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.892
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1104
  • Likes Given: 1867
Re: CPCBasic Unchained
« Reply #15 on: 12:41, 22 December 19 »
Oh well, I just put this little thing together below, which is too slow in Interpreted BASIC. With CPC Basic it's very fast, even with a CALL &BD19 included, if I can get a similiar speed in Assembly that would be great.


Code: [Select]

100 MODE 0:DEFINT a-z:WINDOW#1,5,14,11,19:PAPER#1,1:CLS#1:PAPER#1,0
110 s$="1111111111223344433455544433222222221111"
120 p1=1:p2=1:p3=11
130 x=5:y=10:LOCATE x,y
140 WHILE p1 < p3
150   p=p1:GOSUB 1000
160   p1=p1+1:x=x+1
170 WEND
180 p2=p2+1:x=5:p1=p2:p3=p1+10
190 IF p2=40 THEN p2=1:p1=1:p3=p1+10
200 CALL &BD19
210 GOTO 130
1000 FOR y=1 TO VAL(MID$(s$,p,1))
1010   WINDOW#1,x,x,VAL(MID$(s$,p,1))+11,VAL(MID$(s$,p,1))+13:CLS#1
1020   LOCATE x,val(mid$(s$,p,1))+10:PRINT CHR$(143);:LOCATE x,val(mid$(s$,p,1))+14:PRINT CHR$(143);
1030 NEXT y
1040 RETURN
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
Re: CPCBasic Unchained
« Reply #16 on: 17:09, 22 December 19 »
Oh well, I just put this little thing together below, which is too slow in Interpreted BASIC. With CPC Basic it's very fast, even with a CALL &BD19 included, if I can get a similiar speed in Assembly that would be great.
If one CALL &BD19 delay is too short you can also use a timed delay. For e.g. half a second, I usually use...
Code: [Select]
t!=time+300/2:while time<t!:call &bd19:wend
(On a real CPC, CALL &BD19 busy-waits up to 1/50 second. With CPCBasic, it is 1/50 second, non-busy wait.)

And if you want to skip the delay with a keypress:
Code: [Select]
t!=time+300/2:while time<t! and inkey$="":wend
(No CALL &BD19 required, it is inserted by CPCBasic if inkey$ is called "too often".)



Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.892
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1104
  • Likes Given: 1867
Re: CPCBasic Unchained
« Reply #17 on: 11:30, 03 January 20 »
Just noticed that CINT() has been implented, but ROUND() hasn't. I'm unsure how different these 2 functions are as they seem to ROUND up to the next Decimal number. I'm guessing this relates to what you said earlier about Javascript not knowing what a variable type is at compile time, I'm a little confused because CINT() seem to work fine, though I'm normally in the habit of using ROUND().
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline SkulleateR

  • CPC6128
  • ****
  • Posts: 207
  • Country: de
  • Liked: 117
  • Likes Given: 69
Re: CPCBasic Unchained
« Reply #18 on: 00:04, 04 January 20 »
Just noticed this even works on my iPad, Great to test some routines when you're away from home  ;D


But you can't use keyboard, so no input routines  :P
« Last Edit: 00:05, 04 January 20 by SkulleateR »

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.892
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1104
  • Likes Given: 1867
Re: CPCBasic Unchained
« Reply #19 on: 00:29, 04 January 20 »
Just noticed this even works on my iPad, Great to test some routines when you're away from home  ;D


But you can't use keyboard, so no input routines  :P


On my Computer I have to click on the Screen, the Border goes from Light Grey to Dark, so it may simply be a matter of pressing the screen area and then the Input Routines will work.


I tested my little Locomotive Train demo from the Cool or Uncool? thread, but it doesn't like the ROUND functions returning a confusing error, apart from that it just needs a CALL &BD19, before the GOTO 570 on line 610 to slow it down a little.  :D
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline SkulleateR

  • CPC6128
  • ****
  • Posts: 207
  • Country: de
  • Liked: 117
  • Likes Given: 69
Re: CPCBasic Unchained
« Reply #20 on: 00:36, 04 January 20 »

On my Computer I have to click on the Screen, the Border goes from Light Grey to Dark, so it may simply be a matter of pressing the screen area and then the Input Routines will work.
Nope, the Keyboard won't open on iPad except inside the Input window at the top...

Offline AMSDOS

  • Supporter
  • 6128 Plus
  • *
  • Posts: 3.892
  • Country: au
    • index.php?action=treasury
    • Programs for Turbo Pascal 3
  • Liked: 1104
  • Likes Given: 1867
Re: CPCBasic Unchained
« Reply #21 on: 04:19, 04 January 20 »
Nope, the Keyboard won't open on iPad except inside the Input window at the top...


I see what you mean, have the same trouble on my Android Touch-screen phone, the funny thing about it is it worked on my old Android 4.4 phone using the Navigation Keys. Maybe @mv can setup a small touch screen keypad for it?
* Using the old Amstrad Languages :D   * with the Firmware :P
* I also like to problem solve code in BASIC :)   * And type-in Type-Ins! :D

Home Computing Weekly Programs
Popular Computing Weekly Programs
Your Computer Programs
Updated Other Program Links on Profile Page (Update April 16/15 phew!)
Programs for Turbo Pascal 3

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
Re: CPCBasic Unchained
« Reply #22 on: 01:50, 08 January 20 »
Just noticed that CINT() has been implented, but ROUND() hasn't. I'm unsure how different these 2 functions are as they seem to ROUND up to the next Decimal number. I'm guessing this relates to what you said earlier about Javascript not knowing what a variable type is at compile time, I'm a little confused because CINT() seem to work fine, though I'm normally in the habit of using ROUND().
There was an issue when using ROUND without the number of decimals parameter. Fixed it. Thank you for finding this.

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
Re: CPCBasic Unchained
« Reply #23 on: 02:17, 08 January 20 »

I see what you mean, have the same trouble on my Android Touch-screen phone, the funny thing about it is it worked on my old Android 4.4 phone using the Navigation Keys. Maybe @mv can setup a small touch screen keypad for it?
Good point. Currently, there is no input routine for the CPC screen on mobile. The input area below can be used to input some text and press Enter. Maybe I can put in more keys.

Offline mv

  • Supporter
  • CPC464
  • *
  • Posts: 34
  • Country: de
  • CPCBasic, CPCemu, CPC 6128
  • Liked: 75
  • Likes Given: 58
Re: CPCBasic Unchained
« Reply #24 on: 01:05, 23 January 20 »
I see what you mean, have the same trouble on my Android Touch-screen phone, the funny thing about it is it worked on my old Android 4.4 phone using the Navigation Keys. Maybe @mv can setup a small touch screen keypad for it?

Good point. Currently, there is no input routine for the CPC screen on mobile. The input area below can be used to input some text and press Enter. Maybe I can put in more keys.

Now I put in a virtual keyboard. For some reason, an extra line appears on my mobile.