Author Topic: CPCBasic Unchained  (Read 665 times)

0 Members and 1 Guest are viewing this topic.

Offline mv

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

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

Offline Gryzor

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


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

Offline BSC

  • CPC6128
  • ****
  • Posts: 205
  • Country: de
  • Yay! I became a 6128. Hope it wraps ..
    • my (Android) mobile game
  • Liked: 261
  • Likes Given: 219
Re: CPCBasic Unchained
« Reply #2 on: 21:47, 26 September 19 »
Ideas, thoughts, contributions are welcome.


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

Offline AMSDOS

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



Otherwise a great bit of work.  :)


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

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

Offline mv

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

Offline AMSDOS

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


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


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


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


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


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

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

Offline mv

  • CPC464
  • **
  • Posts: 12
  • Country: de
  • CPC6128
  • Liked: 44
  • Likes Given: 25
Re: CPCBasic Unchained
« Reply #6 on: 00:50, 02 October 19 »
So transparent mode was the culprit, the Block Editor program I posted in there now correctly functions in it.

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

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

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

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

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

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

Offline AMSDOS

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



 :)

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


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

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



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

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

The end condition was evaluated again and again.



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

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



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

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

Offline mv

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

Offline AMSDOS

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


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

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

Offline mv

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


Offline AMSDOS

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


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


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


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


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

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

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