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$(8);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=blockeditor (https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=blockeditor)
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.