CPCWiki forum

General Category => Emulators => Topic started by: mv on 15:54, 26 September 19

Title: CPCBasic Unchained
Post by: mv 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 (https://benchmarko.github.io/CPCBasic/cpcbasic.html)
 
 Readme:
 https://github.com/benchmarko/CPCBasic/#readme (https://github.com/benchmarko/CPCBasic/#readme)
 
Ideas, thoughts, contributions are welcome.

 Have fun!
Marco
Title: Re: CPCBasic Unchained
Post by: Gryzor 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
Title: Re: CPCBasic Unchained
Post by: BSC 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)
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 02:15, 27 September 19
Marco, if you need some BASIC stuff to test my Silly Programming Ideas - Turning Text into Graphics (http://www.cpcwiki.eu/forum/programming/silly-programming-ideas-turning-text-into-graphics/msg15975/#msg15975) 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.
Title: Re: CPCBasic Unchained
Post by: mv on 22:40, 27 September 19
Marco, if you need some BASIC stuff to test my Silly Programming Ideas - Turning Text into Graphics (http://www.cpcwiki.eu/forum/programming/silly-programming-ideas-turning-text-into-graphics/msg15975/#msg15975) 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...
Title: Re: CPCBasic Unchained
Post by: AMSDOS 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 (http://www.cpcwiki.eu/forum/programming/silly-programming-ideas-turning-text-into-graphics/msg95828/#msg95828) 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.  :)
Title: Re: CPCBasic Unchained
Post by: mv 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 (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.
Title: Re: CPCBasic Unchained
Post by: AMSDOS 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 (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 (http://www.cpcwiki.eu/forum/programming/silly-programming-ideas-turning-text-into-graphics/msg34479/#msg34479), but the following code (http://www.cpcwiki.eu/forum/programming/silly-programming-ideas-turning-text-into-graphics/msg34530/#msg34530) 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.
Title: Re: CPCBasic Unchained
Post by: mv 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
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 11:56, 07 October 19
I was getting some interesting results from My Simple Platform Game BASIC (http://www.cpcwiki.eu/forum/programming/my-basic-simple-platform-game-w-alternative-sprite-drivers/msg166853/#msg166853) 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.
Title: Re: CPCBasic Unchained
Post by: mv on 01:54, 10 October 19
I was getting some interesting results from My Simple Platform Game BASIC (http://www.cpcwiki.eu/forum/programming/my-basic-simple-platform-game-w-alternative-sprite-drivers/msg166853/#msg166853) 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.

Title: Re: CPCBasic Unchained
Post by: AMSDOS 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 (https://www.cpc-power.com/index.php?page=detail&num=16012). 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

Title: Re: CPCBasic Unchained
Post by: mv 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
Title: Re: CPCBasic Unchained
Post by: AMSDOS 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.
Title: Re: CPCBasic Unchained
Post by: mv 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.
Title: Re: CPCBasic Unchained
Post by: AMSDOS 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
Title: Re: CPCBasic Unchained
Post by: mv 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".)


Title: Re: CPCBasic Unchained
Post by: AMSDOS 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().
Title: Re: CPCBasic Unchained
Post by: SkulleateR 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
Title: Re: CPCBasic Unchained
Post by: AMSDOS 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? (http://www.cpcwiki.eu/forum/general-discussion/cool-or-uncool/msg182020/#msg182020) 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
Title: Re: CPCBasic Unchained
Post by: SkulleateR 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...
Title: Re: CPCBasic Unchained
Post by: AMSDOS 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 (http://www.cpcwiki.eu/forum/index.php?action=profile;u=3387) can setup a small touch screen keypad for it?
Title: Re: CPCBasic Unchained
Post by: mv 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.
Title: Re: CPCBasic Unchained
Post by: mv 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 (http://www.cpcwiki.eu/forum/index.php?action=profile;u=3387) 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.
Title: Re: CPCBasic Unchained
Post by: mv 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 (https://www.cpcwiki.eu/forum/index.php?action=profile;u=3387) 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.
Title: Re: CPCBasic Unchained
Post by: SkulleateR on 11:03, 23 January 20
Very nice, have to trry this out on my iPad this weekend  :D 8)
Title: Re: CPCBasic Unchained
Post by: SkulleateR on 13:26, 25 January 20
Ok, works nicely with Android/Chrome, doesn't work on iOS/Safari on my iPad Mini


The buttons below the emulation windows do not work at all. I´ll try an other browser on iOS later ...


edit : just checked, works fine with Safari on my MacBook, hmmm ....
Title: Re: CPCBasic Unchained
Post by: mv on 21:34, 28 January 20
Ok, works nicely with Android/Chrome, doesn't work on iOS/Safari on my iPad Mini
The buttons below the emulation windows do not work at all. I´ll try an other browser on iOS later ...
edit : just checked, works fine with Safari on my MacBook, hmmm ....
It seems that iOS/Safari added support for pointer events just recently with iOS 13.
There is a fallback to use touch events. I do not have an iOS device so I cannot check.

I have put in some debug output in CPCBasic. Please try the following link and check the console output when pressing a virtual key:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?debug=2&example=test/keyboard&showInput=false&showKeyboard=true&showConsole=true
The output can be lengthy. When pressing e.g. "1", there should be an onVirtualKeyboardKeydown/Keyup event and
fnPressCpcKey: sPressedKey=49Digit1, affected cpc key=64

It would be also interesting to know if another virtual keyboard works on iOS:
https://virtual-keyboard.js.org/

Title: Re: CPCBasic Unchained
Post by: SkulleateR on 21:44, 28 January 20
It seems that iOS/Safari added support for pointer events just recently with iOS 13.
There is a fallback to use touch events. I do not have an iOS device so I cannot check.
Sorry, only an old iOS here, iPad Mini second gen I think, no "modern" iOS >:(
Quote
I have put in some debug output in CPCBasic. Please try the following link and check the console output when pressing a virtual key:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?debug=2&example=test/keyboard&showInput=false&showKeyboard=true&showConsole=true (https://benchmarko.github.io/CPCBasic/cpcbasic.html?debug=2&example=test/keyboard&showInput=false&showKeyboard=true&showConsole=true)
The output can be lengthy. When pressing e.g. "1", there should be an onVirtualKeyboardKeydown/Keyup event and
fnPressCpcKey: sPressedKey=49Digit1, affected cpc key=64
Anyway, THAT works fine ... the only thing that won't work in the original link : the keyboard won't show up when pressing "KEYBOARD", maybe I should have mentioned it before :picard:


Quote
It would be also interesting to know if another virtual keyboard works on iOS:
https://virtual-keyboard.js.org/ (https://virtual-keyboard.js.org/)


Also works....
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 22:54, 04 February 20

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


I tried it earlier (see attachment pic), but my screen is so small...


Silly me didn't realise I could purchase a Bluetooth Keyboard, so I'll have a go with that.
Title: Re: CPCBasic Unchained
Post by: mv on 23:32, 07 February 20
Anyway, THAT works fine ... the only thing that won't work in the original link : the keyboard won't show up when pressing "KEYBOARD", maybe I should have mentioned it before
Oh, now I understand. I was confused about "buttons". The virtual keyboard has buttons but "Keyboard" is just a clickable field in HTML. I assume that all green "buttons" do not work with iOS.It seems that iOS has some issues with event bubbling of the "click" event:
https://gravitydept.com/blog/js-click-event-bubbling-on-ios (https://gravitydept.com/blog/js-click-event-bubbling-on-ios)
There are several workarounds that I do not really like.
I put in real buttons and hope that it is ok for iOS.
Thank you for testing.
Title: Re: CPCBasic Unchained
Post by: mv on 17:54, 12 February 20
I tried it earlier (see attachment pic), but my screen is so small...

Silly me didn't realise I could purchase a Bluetooth Keyboard, so I'll have a go with that.

The screen on my mobile is also very small. I have checked with a bluetooth keyboard (good idea, did not use it for years). And yes, it is an option, even if it is a small one and has not all the keys.
And there are other options now:
- Select a layout with fewer keys, or
- Move the virtual keyboard over the CPC screen (best by dragging the "Keyboard" button)

The next step would be to let the user select the keys... ;)

And recently I have put in flashing colors. Helps to follow the cursor in the block editor.
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 10:56, 13 February 20
I went ahead purchasing a Bluetooth Keyboard which had turned my Phone into a small Computer & Monitor, I was able to get a Tablet resting Cushon and put my phone in that with Keyboard on top. Some Bluetooth Keyboards already have that, though were more expensive, just a pity Bluetooth drains the Battery. :o


---


I've been working out how to redefine lots of characters while avoiding using SYMBOL, I knew by default Locomotive BASIC reserves Characters 240 to 255, which from a BASIC 10-Liner Perspective saves me from using SYMBOL AFTER 240 since it's defined by Default, however when I lower the number, HIMEM is lowered and the new Character Definitions becomes HIMEM+1, which means I can use POKE with the Graphic Data as Characters (0 to 255) representing the Graphic. I don't know if this is meaningful for a couple of Graphical Characters, but maybe in a whole set it might save some space?


I tested this in CPC BASIC without reault as well as other Emulators to determine it being valid. The funny thing is HIMEM in CPC BASIC is set at 42619, so normally Locomotive BASIC has 15x8 places reserved for the last 15 characters 42620 onwards. The only other pain in my routine is the Graphical Data being represented in Characters and not really having much say into which Higher Characters I want to get from the Mac, on a PC from memory it's CTRL+0<key number>?


Code: [Select]
100 a=HIMEM+1
110 FOR c=1 TO 2
120   READ a$
130   FOR p=1 TO 8
140     POKE a,ASC(MID$(a$,p,1))
150     a=a+1
160   NEXT p
170 NEXT c
200 DATA"ABCDEFGH","HGFEDCBA"
Title: Re: CPCBasic Unchained
Post by: SkulleateR on 12:07, 13 February 20
I put in real buttons and hope that it is ok for iOS.
Amazing, works really fine on iOS now ....
Quote
Thank you for testing.
Thx for putting it online, nice work so far  8)
Title: Re: CPCBasic Unchained
Post by: mv on 00:30, 16 February 20
I've been working out how to redefine lots of characters while avoiding using SYMBOL, I knew by default Locomotive BASIC reserves Characters 240 to 255, which from a BASIC 10-Liner Perspective saves me from using SYMBOL AFTER 240 since it's defined by Default, however when I lower the number, HIMEM is lowered and the new Character Definitions becomes HIMEM+1, which means I can use POKE with the Graphic Data as Characters (0 to 255) representing the Graphic. I don't know if this is meaningful for a couple of Graphical Characters, but maybe in a whole set it might save some space?

I tested this in CPC BASIC without reault as well as other Emulators to determine it being valid. The funny thing is HIMEM in CPC BASIC is set at 42619, so normally Locomotive BASIC has 15x8 places reserved for the last 15 characters 42620 onwards. The only other pain in my routine is the Graphical Data being represented in Characters and not really having much say into which Higher Characters I want to get from the Mac, on a PC from memory it's CTRL+0<key number>?


Nice trick to access the character map at HIMEM+1. I also think that it could be useful for BASIC 10-liners so I put it in.
Moving the character map to another place should also work, e.g. with SYMBOL AFTER 256:MEMORY &7FFF:SYMBOL AFTER 0.
It gets more tricky when setting the screen base to &4000 or switching RAM banks. I stopped there, so you will not see the character map on the screen as it is on a real CPC.

CTRL+0<key number>: Do you mean how to type in ASCII codes on a PC? That is ALT+0<key number> on the numpad.

And I did some tests with DATA lines and which lower or higher characters you can put in.
When using chr$(25) to set the SYMBOLs, your example with simple letter data can also be written as:
Code: [Select]
100 read a$,b$:?a$;b$;
110 ?CHR$(240);CHR$(241)
120 DATA "ðABCDEFGH", "ñHGFEDCBA"

Not sure how compatible this is when copying as ASCII between systems. The chr$(25) character does not need to be part of the data, can also be added in line 100.

Unfortunately there are other characters which should not be in DATA lines. A test program with characters 14-127,129-255 in DATA lines:

Code: [Select]
100 MODE 1:a$="":i=14
110 WHILE i<=255
120 READ a$
130 FOR p=1 TO LEN(a$)
140 c$=MID$(a$,p,1):b=ASC(c$):IF b<32 THEN c$=CHR$(1)+c$
150 IF i=&80 THEN i=i+1
152 PRINT c$;HEX$(b,2);
154 IF b<>i THEN PRINT"<>";HEX$(i,2);
155 PRINT" ";
157 i=i+1
160 NEXT p
170 WEND
180 CALL &BB18
190 STOP
195 DATA ""
200 DATA " ",!"#$%&'()*+,","
210 DATA "-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
220 DATA "‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖ×ØÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ"

Comma and colon must be quoted. And quotes must not be quoted and also not the first character of a data item.

Maybe some sort of uuencoding would be better.
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 12:58, 24 April 20
I found another problem in CPC BASIC v0.8 while using ORIGIN, which made me discover the Y-screen resolution being 0 to 400 instead of 0..398, while using this little programme. :o

Code: [Select]
10 MODE 0
20 ORIGIN 0,0,4,4,400,400
30 CLG 3

I wrote an article:


https://www.linkedin.com/pulse/filling-them-ol-basic-10-liners-464-out-bush/


with a recoded ACU BASIC 10-Liner altered to work on a 464, which I think is where I noticed a flaw when ORIGIN Fills in the Main House Body.


EDIT: Disregard that regarding the earlier ORIGIN programme here because it occurs on Emulators as well, I don't know the reason for it which makes it annoying even more so when I thought it might of been a bug in BASIC 1.0, though it also occurs in BASIC 1.1! The Link I gave to the House Demo is producing a slightly different result in CPC BASIC v0.8 from the emulators, with the culprit being "ORIGIN 0,0,54,396,298,52" in line 10. To having it look the same as the other emulators it needs to be changed to "ORIGIN 0,0,54,396,300,52", again I don't know why that last bit of line isn't being filled in when the emulators are running it fine. :(
Title: Re: CPCBasic Unchained
Post by: mv on 19:22, 27 April 20
I found another problem in CPC BASIC v0.8 while using ORIGIN, which made me discover the Y-screen resolution being 0 to 400 instead of 0..398, while using this little programme.

Code: [Select]
10 MODE 0
20 ORIGIN 0,0,4,4,400,400
30 CLG 3

I wrote an article here (https://www.linkedin.com/pulse/filling-them-ol-basic-10-liners-464-out-bush/) with a recoded ACU BASIC 10-Liner altered to work on a 464, which I think is where I noticed a flaw when ORIGIN Fills in the Main House Body.
EDIT: Disregard that regarding the earlier ORIGIN programme here because it occurs on Emulators as well, I don't know the reason for it which makes it annoying even more so when I thought it might of been a bug in BASIC 1.0, though it also occurs in BASIC 1.1! The Link I gave to the House Demo is producing a slightly different result in CPC BASIC v0.8 from the emulators, with the culprit being "ORIGIN 0,0,54,396,298,52" in line 10. To having it look the same as the other emulators it needs to be changed to "ORIGIN 0,0,54,396,300,52", again I don't know why that last bit of line isn't being filled in when the emulators are running it fine. :(
That one was a bit tricky. Not only that my experiments with "direct input mode" only hid the small line and I fixed some other issues first.
The right side of the garage door was also not properly filled.
An all that because CPCBasic always uses a resolution of 640x400 pixels. When drawing, all pixels belonging to a CPC pixel must be set.
So to fix the "lifted roof", I changed the ORIGIN graphical window so that it also extends in y direction if necessary.

Some other issues fixed:
- ORIGIN: Accept parameter order right, left; origin for CPC pixels
- CLG x: Also set GRAPHICS PAPER to x
- TEST: returns GRAPHICS PAPER when testing outside graphics window
- DRAW: Extend the target coordinate to full CPC pixels, for both horizontal directions. That fixes the "garage door"

Some test code, drawing lines from left->right, top->bottom and vice versa (I know, real CPC always draws in one direction, but...):
Code: [Select]
1 rem line test 1
5 m=0
7 xd=2^(2-min(m,2)):yd=((m=3)+2)
10 mode m:border 5
12 im=10
15 move 99+im,399:draw 99+im,349-im*yd,3:plot 0,0,1
20 x1=0:x2=99:y=399:gosub 320
30 x1=99:x2=0:y=349:gosub 320
35 move 150,300-im:draw 200+im*xd,300-im,3:plot 0,0,1
40 y1=399:y2=300:x=150:gosub 380
50 y1=300:y2=399:x=200:gosub 380
100 locate 1,20:call &bb18:stop
310 '
320 for i=1 to im
330 move x1,y:draw x2,y
340 x1=x1+1:x2=x2+1:y=y-yd
350 next
360 return
370 '
380 for i=1 to im
390 move x,y1:draw x,y2
400 y1=y1-1:y2=y2-1:x=x+xd
410 next
420 return


Some test code that ORIGIN is set for CPC pixels:
Code: [Select]
5 rem ORIGIN and TEST
10 mode 0
20 plot 0,0,1
25 for h=0 to 4
30 origin 10+h,10+h*30,10+h,20+h,10+h*30,20+h*30:clg 3
35 plot 0,0,1:plot 0+4,0,2
40 for i=0 to 11
50 ?test(i,0);
60 if i mod 4=3 then ?
70 next
80 next

Nice demo, drawing a filled house in 9 lines of code without using FILL. I put it in the apps collection:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?database=apps&example=demo/house


Another new feature: blkedit can load an save now using local storage of the browser:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=blkedit
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 12:04, 28 April 20

Nice demo, drawing a filled house in 9 lines of code without using FILL. I put it in the apps collection:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?database=apps&example=demo/house (https://benchmarko.github.io/CPCBasic/cpcbasic.html?database=apps&example=demo/house)


Unfortunately I forgot to acknowledge the authors of the original graphical demo, which was written by Simon Baker and Kevin Parker. I've tracked down the original source as published in April '91 issue of ACU which makes me wonder how I could of replaced all them FILLs with 464 compatable routines and still find room for it to work.


Title: Re: CPCBasic Unchained
Post by: mv on 00:41, 30 April 20
Unfortunately I forgot to acknowledge the authors of the original graphical demo, which was written by Simon Baker and Kevin Parker. I've tracked down the original source as published in April '91 issue of ACU which makes me wonder how I could of replaced all them FILLs with 464 compatable routines and still find room for it to work.
Thank you. I think I forgot it. It is clearly written in the article. I have put in the credits now, also on: https://github.com/benchmarko/CPCBasicApps#house-for-sale
Title: Re: CPCBasic Unchained
Post by: mv on 14:28, 12 June 20
I have updated CPCBasic to v0.9.6.

Now you can upload individual files, disk images (DSK) or event ZIP files to the app, using drag&drop on the CPC canvas.
The files in ZIP and DSK containers are extracted and stored in browser's localStorage memory (which is usually permanent after browser restarts).
They can be selected if "storage" is used in the first selection field.
LOAD, CAT, and the AMSDOS commands like |ERA,... also work.
Tokenized BASIC is converted to ASCII when loading. (Also GENA3 assembler sources, but that is not so relevent for CPCBasic).


Another nice feature I am experimenting with: mouse clicks on the CPC canvas.
After a MOVE 1000,1000, a mouse click does a MOVE at the click position (after the canvas has been selected).
This can be detected by a BASIC program.

Another effect of a mouse click:
When clicking on a character written in text mode, it is put in the keyboard input queue and can be read with INKEY$.
This is useful for menus like 1)... 2)...,  or A)... B)... for selecting an option. Without changing the BASIC program.

An example of a simple painting program that is controlled with mouse clicks:

Code: [Select]
10 rem mousepa: Mouse Painting
20 rem CPCBasic only
30 mode 1
40 window #1,1,15,25,25
50 d$(0)="plot":d$(1)="draw":d$(2)="fill":d=-1
60 '
70 d=d+1:d=d mod 3:locate #1,1,1:?#1,d$(d); 'switch drawing mode
80 '
90 x0=xpos:y0=ypos
100 locate #1,5,1:?#1,x0;y0;chr$(18); 'show coordinates
110 move 1000,1000 'activate move on mouse click
120 '
130 call &bd19
135 t$=inkey$:if t$<>"" then ?t$; 'side effect: click on text
140 if xpos=1000 and ypos=1000 then 130
150 x=xpos:y=ypos
160 if x<16*4 and y<16 then move x0,y0:goto 70
170 if d=0 then plot x,y
180 if d=1 then move x0,y0:draw x,y
190 if d=2 then if test(x,y)=2 then fill 3 else fill 2
200 goto 90

It can be tested here:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=test/mousepa


And there is a "Text View" that shows the text output as it appears on the canvas.
Title: Re: CPCBasic Unchained
Post by: Sykobee (Briggsy) on 14:57, 12 June 20
I wonder if my old 10 liner runs on this? https://www.cpc-power.com/index.php?page=detail&onglet=dumps&num=14242 (https://www.cpc-power.com/index.php?page=detail&onglet=dumps&num=14242)
The listing should be on the .dsk (in both 10 liner and exploded format)
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 12:44, 18 June 20
I have updated CPCBasic to v0.9.6.

Now you can upload individual files, disk images (DSK) or event ZIP files to the app, using drag&drop on the CPC canvas.
The files in ZIP and DSK containers are extracted and stored in browser's localStorage memory (which is usually permanent after browser restarts).
They can be selected if "storage" is used in the first selection field.
LOAD, CAT, and the AMSDOS commands like |ERA,... also work.
Tokenized BASIC is converted to ASCII when loading. (Also GENA3 assembler sources, but that is not so relevent for CPCBasic).


I noticed some files from the Block Editor were in the Storage area, though I can't seem to Load them back into the Block Editor from that, selecting that file replaces the Block Editor with the file it uses to display that image, trying to enter the filename through the Block Editor just brings up some other error.  ???


I wonder if my old 10 liner runs on this? https://www.cpc-power.com/index.php?page=detail&onglet=dumps&num=14242 (https://www.cpc-power.com/index.php?page=detail&onglet=dumps&num=14242)The listing should be on the .dsk (in both 10 liner and exploded format)


I don't see why not, a couple of examples had issues with Sound, the Clear Path game seems to be one of them, the modified House 10-Liner I reconstructed to work on all computers almost plays the Tune in entirly with the end being clipped. Maybe the only problem being having the CALL &BD19 in the code to run close to Realtime.



@mv (https://www.cpcwiki.eu/forum/index.php?action=profile;u=3387) was reading something regarding MASK in the help file, I wrote this a couple of years ago to try understand what MASK might look like in BASIC (as well as having something like it on a 464), I don't know if it would be useful for you, but it produces some nice colourful patterns:


Code: [Select]
100 MODE 0:BORDER 11:INK 0,11:INK 1,18:INK 14,9:INK 15,15
110 DEFINT a-z
120 y=398
130 a$="10011001":x=0:d=640:c=INT(RND*15):GOSUB 1000
140 FOR a=0 TO 1
150 a$="10111101":x=0:d=640:y=y-2:c=INT(RND*15):GOSUB 1000
160 NEXT a
170 y=y-2
180 a$="10011001":x=0:d=640:c=INT(RND*15):GOSUB 1000
190 y=y-4
200 IF y>0 THEN GOTO 130
210 CALL &BB18
220 END
1000 WHILE l<d\32
1010   FOR p=1 TO LEN(a$)
1020     IF MID$(a$,p,1)="1" THEN PLOT x,y,VAL(MID$(a$,p,1))+c
1030     x=x+4
1040   NEXT p
1050   l=l+1
1060 WEND:l=0
1070 RETURN


Title: Re: CPCBasic Unchained
Post by: mv on 00:52, 19 June 20
I wonder if my old 10 liner runs on this? https://www.cpc-power.com/index.php?page=detail&onglet=dumps&num=14242 (https://www.cpc-power.com/index.php?page=detail&onglet=dumps&num=14242)
The listing should be on the .dsk (in both 10 liner and exploded format)
If it is pure BASIC, it should run.
Let me check... Oh, way too fast! The game ends before it starts.

I usually put a CALL &BD19 in a place where the keyboard is checked.
(There is no automatism for inserting delays except for INKEY$, but here we have INKEY.)
It seems the game loop starts at line 880, so line 885 would be a good place.
With a single CALL &BD19, it is still too fast. Maybe a speed for very advanced players.

So lets measure the speed on a real CPC or emulator:
885 locate #2,1,1:?#2,time-t0!;spc(5);:t0!=time
It's around 77 without movement and 80 or 84 with movement.
So we can insert a delay, say 75:
885 t!=time+75:while time<t!:call &bd19:wend
This would be fine for CPCBasic.

With a CPC, it slows down a lot, so it's better to split the line up and reduce the delay by processing time:
885 t!=time+75
And at the end of the loop:
1255 while time<t!:call &bd19:wend

Or again everything in one line (assuming t! is 0 the first time):
885 while time<t!:call &bd19:wend: t!=time+75

Hey, nice game. I just collected all $. Uh, need the enemies too...
And nice tricks to shorten the program like DEF FN for INKEY's.

If you don't mind, I'll put it in CPCBasicApps.

Title: Re: CPCBasic Unchained
Post by: mv on 01:34, 19 June 20

I noticed some files from the Block Editor were in the Storage area, though I can't seem to Load them back into the Block Editor from that, selecting that file replaces the Block Editor with the file it uses to display that image, trying to enter the filename through the Block Editor just brings up some other error.

...
@mv (https://www.cpcwiki.eu/forum/index.php?action=profile;u=3387) was reading something regarding MASK in the help file, I wrote this a couple of years ago to try understand what MASK might look like in BASIC (as well as having something like it on a 464), I don't know if it would be useful for you, but it produces some nice colourful patterns:

Uhm, I modified the storage format 3 days ago an put in an identifier.
If you have previously saved the examples, you cannot load them with the current version.
Either use |ERA,"*.*" to remove the old stuff, or open the dev tools, navigate to Application, Local storage, find your file(s) and let the value start with: CPCBasic;
Then it should work again. I was not aware that someone was already using it to store data.

And thank you for the MASK example in BASIC.
I never used the MASK instruction, so with
1000 MASK VAL("&X"+a$):MOVE x,y:DRAW d,y,c:RETURN
the program should produce the same pattern.
Title: Re: CPCBasic Unchained
Post by: Sykobee (Briggsy) on 01:49, 19 June 20

Hey, nice game. I just collected all $. Uh, need the enemies too...
And nice tricks to shorten the program like DEF FN for INKEY's.

If you don't mind, I'll put it in CPCBasicApps.


Thanks :)
Sure, please go ahead (with the additional slowdowns - that certainly wasn't a problem on the CPC and would have used valuable token space in the 10 lines!).
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 13:18, 19 June 20
Uhm, I modified the storage format 3 days ago an put in an identifier.
If you have previously saved the examples, you cannot load them with the current version.
Either use |ERA,"*.*" to remove the old stuff, or open the dev tools, navigate to Application, Local storage, find your file(s) and let the value start with: CPCBasic;
Then it should work again. I was not aware that someone was already using it to store data.


No, wasn't saving anything, though when I selected the Storage Tab, I could see some files with .blk extension, maybe I wasn't meant to see them, or save to my computer?

Quote
And thank you for the MASK example in BASIC.
I never used the MASK instruction, so with
1000 MASK VAL("&X"+a$):MOVE x,y:DRAW d,y,c:RETURN
the program should produce the same pattern.


I think so, thought you don't necessarily need to have a string called a$ returning a binary number through VAL, that was just my way of placing a string series and using MID$ to gather the data. The original thread is there which includes a BASIC 1.1 version using MASK simply has a binary number following the MASK, and when a Pattern is defined that's the outcome from the MASK command. I simply created one in BASIC, followed by some Assembly examples when I couldn't find an example for MASK, though I think I've since seen one.


Original thread is here:
https://www.cpcwiki.eu/forum/programming/mask-patterns-on-a-cpc464/ (https://www.cpcwiki.eu/forum/programming/mask-patterns-on-a-cpc464/)
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 13:07, 20 June 20
Regarding MASK, the only thing I forgot to mention (because my interpretation of it doesn't support it), is the 2nd parameter, which can be used to switch the bits, effectively inverting the pattern, check this small programme out:

Code: [Select]
100 MODE 0:INK 14,18:INK 15,16:DEFINT a-z:n=1
110 FOR y=398 TO 0 STEP -2
120   MASK &X10101010,n
130   MOVE 0,y:DRAW 638,y,INT(RND*15)+1
140   n=n+1:IF n=2 THEN n=0
150   CALL &BB18
160 NEXT y
Title: Re: CPCBasic Unchained
Post by: mv on 01:33, 23 June 20
Regarding MASK, the only thing I forgot to mention (because my interpretation of it doesn't support it), is the 2nd parameter, which can be used to switch the bits, effectively inverting the pattern, check this small programme out:
I updated CPCBasic to 0.9.9 two days ago and found the MASK instruction ok:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=test/linemask
There are 3 parts:
1. MASK instruction
2. BASIC loop with numeric mask
3. BASIC loop with string mask
I thought the numeric mask was faster than the string mask but it wasn't. In Assembler you have nice bit shift and rotate instructions, in BASIC you can only multiply by 2.

Your second test shows a difference.
I do not understand why for x=0 a pixel is set when the first pixel flag is 0.
It seems that in this case only the bitmask is not rotating.

Regarding the clipped sound in the house demo, there are simple workarounds like:
WHILE INKEY$="":WEND
or:
WHILE SQ(1)>=128:CALL &BD19:WEND:CALL &BB18
But I think I need to fix this.
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 12:10, 23 June 20
I updated CPCBasic to 0.9.9 two days ago and found the MASK instruction ok:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=test/linemask
There are 3 parts:
1. MASK instruction
2. BASIC loop with numeric mask
3. BASIC loop with string mask
I thought the numeric mask was faster than the string mask but it wasn't. In Assembler you have nice bit shift and rotate instructions, in BASIC you can only multiply by 2.

Your second test shows a difference.
I do not understand why for x=0 a pixel is set when the first pixel flag is 0.
It seems that in this case only the bitmask is not rotating.

Sorry, are you referring to my assembly example from the other thread? My Assembly isn't the greatest (the code would show that), and it works as an all in one command (MASK & PLOT pattern). From what I can tell, x & y are graphical positions, so x=0 for the Left Most Pixel, 'dest' is best described as length, is a Text Coordinated way of specifying how long, so if 'dest' is 1, the routine handles it in 8 pixels lengths at a time, which is a limitation from the BASIC 1.1 Command since a Pattern could cease midway though the Pattern Matrix. I think I only wrote it like that so I could fill an entire screen with Patterns.

Getting back to what you said about bit shifts and rotates, in BASIC I was able to Shift the values with XOR 255, which shifts the 1s and 0s.

Code: [Select]
100 a$="10101010"
110 n=VAL("&X"+a$)
120 n = n XOR 255
130 a$=BIN$(n,8)
140 PRINT a$
run
01010101

Quote
Regarding the clipped sound in the house demo, there are simple workarounds like:
WHILE INKEY$="":WEND
or:
WHILE SQ(1)>=128:CALL &BD19:WEND:CALL &BB18
But I think I need to fix this.

It seems to be a bit like when a Tune is being Played in BASIC on the Amstrad, though BASIC is focused on playing that tune and do nothing else and towards the end of Ready pops up while playing the last notes, except here the Tune Stops if a Ready were displayed, if that makes sense.
Title: Re: CPCBasic Unchained
Post by: mv on 01:36, 28 June 20
Sorry, are you referring to my assembly example from the other thread? My Assembly isn't the greatest (the code would show that), and it works as an all in one command (MASK & PLOT pattern). From what I can tell, x & y are graphical positions, so x=0 for the Left Most Pixel, 'dest' is best described as length, is a Text Coordinated way of specifying how long, so if 'dest' is 1, the routine handles it in 8 pixels lengths at a time, which is a limitation from the BASIC 1.1 Command since a Pattern could cease midway though the Pattern Matrix. I think I only wrote it like that so I could fill an entire screen with Patterns.
Sorry for the confusion, I was referring to the two examples in this thread. The second example did not work because I shifted the bit position in the wrong direction. Now it is fixed (hopefully).

And I have updated the linemask test. Here is the main part:

Code: [Select]
10 mode 0:ink 14,9:ink 15,16
40 DEFINT a-z
50 dim pa(7) 'bit position array
60 b=1:for p=0 to 7:pa(p)=b:b=b*2:next
180 k=&X10110100 'mask
190 x1=320:x2=x1+4*64-1:y1=398:y2=0
210 c=1 'color
220 f=1 'first pixel flag
230 p=7 'bit position for pa
240 for y=y1 to y2 step -2
250 gosub 410
260 c=c+1:if c>15 then c=1:f=f xor 1:k=k+1:p=7
270 next
275 stop
390 '
400 REM method 2: BASIC MASK simulation
410 fd=0:if f=0 then fd=4 'skip first pixel
420 for x=x1+fd to x2 step 4
430 b=pa(p)
440 IF (k and b)=b then PLOT x,y,c else plot x,y,0
450 p=p-1:if p<0 then p=7
460 next
470 return

Changes are:
- Numerical mask
- The first mask is not symmetric to test the direction
- The bit position for the mask is retained in a color block (15 pixel lines) to test several DRAWs
- After a color block, the first pixel flag f is switched, the mask k is incremented and the bit position p is initialized

Quote
Getting back to what you said about bit shifts and rotates, in BASIC I was able to Shift the values with XOR 255, which shifts the 1s and 0s.
Nice trick to shift a pattern with alternating bits.
Quote
It seems to be a bit like when a Tune is being Played in BASIC on the Amstrad, though BASIC is focused on playing that tune and do nothing else and towards the end of Ready pops up while playing the last notes, except here the Tune Stops if a Ready were displayed, if that makes sense.
When waiting for a keypress, sound (and other) events are processed now, so the house demo plays the full sound.

Title: Re: CPCBasic Unchained
Post by: mv on 18:34, 29 October 20
I just learned that the transparent background mode  GRAPHICS PEN ,1  also affects DRAW with MASK.
You can see the effect in the linemask example:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=test/linemask

Now the searchlight in the Amstrad CPC 6128 Demo also works:
https://github.com/benchmarko/CPCBasicApps#amstrad-cpc-6128-demo
Title: Re: CPCBasic Unchained
Post by: AMSDOS on 23:57, 30 October 20
I just learned that the transparent background mode  GRAPHICS PEN ,1  also affects DRAW with MASK.
You can see the effect in the linemask example:
https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=test/linemask (https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=test/linemask)

Now the searchlight in the Amstrad CPC 6128 Demo also works:
https://github.com/benchmarko/CPCBasicApps#amstrad-cpc-6128-demo (https://github.com/benchmarko/CPCBasicApps#amstrad-cpc-6128-demo)


Its used to set the Graphic Write Mode, though in the firmware it's part of the Screen Pack (SCR ACCESS), with 0 = Normal, 1 = XOR, 2 = AND and 3 = OR. All the Graphical Statements adbide by it though, PLOT, DRAW, etc. On a 464 it's only accessable with PRINT CHR$(23);CHR$(n); with 'n' representing one of those values. I used the OR writing mode a couple of years ago to write Red's Exit, which helped produce that Maze effect. So essentually this is the Graphical equivalent of Transparent Mode CHR$(22); though a little different, XOR can be used to create Multicoloured Images like Transparent Mode, though can be cleared by simply printing over the Image again.
Title: Re: CPCBasic Unchained
Post by: mv on 22:11, 08 November 20
I am working on a pretty print feature for BASIC. It seems to work pretty well already.
For testing purpose, the differences are put in the JavaScript window (except for lowercase and uppercase).
Undo and redo is also possible.

It has a fixed style with an extra space inserted between commands and arguments. But not always. If there is a stream, no space is inserted:
Code: [Select]
10 INPUT"key";a$ :'not pretty
20 INPUT "key";a$:'pretty
30 INPUT#2,"key";a$:'pretty
Not sure if this a good approach.

For arithmetic operations, it only keeps the necessary parentheses determined from the operator precedences.
This could be an issue, if parentheses are used to prevent an overflow, e.g.
Code: [Select]
10 ?1E+38*(10/100)
20 ?1E+38*10/100

Maybe the pretty print feature can also be used to minify BASIC later...
Title: Re: CPCBasic Unchained
Post by: genesis8 on 23:16, 15 November 20
I would like to add CPCBasic Unchained on my web site, and load ascii basic files while calling CPCBasic, is it possible ?
Title: Re: CPCBasic Unchained
Post by: mv on 19:00, 19 November 20
I would like to add CPCBasic Unchained on my web site, and load ascii basic files while calling CPCBasic, is it possible ?
Good point.
If you are happy with the current CPCBasic UI, you can put it in an IFrame like:
https://benchmarko.github.io/CPCBasic/test/testIFrames.html

To get your own examples, set the parameter databaseDirs as I did in https://github.com/benchmarko/CPCBasic/blob/master/cpcconfig.js:
databaseDirs: "examples,https://benchmarko.github.io/CPCBasicApps/apps,storage"

This parameter can also be used as an URL parameter, e.g.
https://benchmarko.github.io/CPCBasic/cpcbasic.html?databaseDirs=https://<mySite>/myExamples

From this location, a file 0index.js is loaded with the "diectory" of the samples:
https://github.com/benchmarko/CPCBasic/blob/master/examples/0index.js
Code: [Select]
cpcBasic.addIndex("./examples", function () { /*
[
    {
        "key": "1st",
        "title": "First Program (empty)"
    },
...
    {
        "key": "archi/archidr",
        "title": "Little Architect Draw (BASIC)"
    },
    {
        "key": "archi/archi1.bil",
        "title": "Drawing Set 1",
        "meta": "D"
    },
...
]
*/ });

Use meta: "D" to mark a file containing data, not be selectable on the UI.


As files, you can use plain ASCII/BASIC, or BASE64 encoded files with a prefix containing file type ASCII (A), tokenized BASIC (T) or Binary (B) and the format:
CPCBasic;<file type>;<load addess>;<length>;<entry>;base64;<BASE64 encoded data>

- Plain ASCII, BASIC:
https://github.com/benchmarko/CPCBasic/blob/master/examples/blkedit.js
Code: [Select]
cpcBasic.addItem("", function () { /*
10 rem blkedit - Block Editor
...
*/ });

- Tokenized BASIC (T;<load addess>;<length>;<entry>;base64;<BASE64 encoded data>):
https://github.com/benchmarko/CPCBasic/blob/master/examples/math/ninedig2.js
Code: [Select]
cpcBasic.addItem("", function () { /*
CPCBasic;T;368;1126;0;base64,EgBkA...
*/ });

- Binary (B;<load addess>;<length>;<entry>;base64;<BASE64 encoded data>):
https://github.com/benchmarko/CPCBasic/blob/master/examples/archi/archi1.bil.js
Code: [Select]
cpcBasic.addItem("", function () { /*
CPCBasic;B;16384;3728;0;base64,Dl8ANg...
*/ });

If you plan to create your own UI for CPCBasic, please tell me. Maybe we can define an API to make it easier.
And if you prefer, you can also put the whole stuff on your site.