News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

CPCBasic Unchained

Started by mv, 13:54, 26 September 19

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

SkulleateR

Very nice, have to trry this out on my iPad this weekend  :D 8)

SkulleateR

#26
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 ....

mv

Quote from: SkulleateR on 12: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 ....
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/


SkulleateR

Quote from: mv on 20:34, 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
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:


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


Also works....

AMSDOS


Quote from: mv on 00:05, 23 January 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.
* 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

mv

#30
Quote from: SkulleateR on 20:44, 28 January 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
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.

mv

Quote from: AMSDOS on 21:54, 04 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.

AMSDOS

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>?



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"
* 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

SkulleateR

Quote from: mv on 22:32, 07 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)

mv

Quote from: AMSDOS on 09:56, 13 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:

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:


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.

AMSDOS

#35
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

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. :(
* 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

mv

Quote from: AMSDOS on 10: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.

10 MODE 0
20 ORIGIN 0,0,4,4,400,400
30 CLG 3


I wrote an article here 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...):

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:

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

AMSDOS

Quote from: mv on 17:22, 27 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


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.


* 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

mv

Quote from: AMSDOS on 10:04, 28 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

mv

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:


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.

Sykobee (Briggsy)

I wonder if my old 10 liner runs on this? 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)

AMSDOS

#41
Quote from: mv on 12: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).


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.  ???


Quote from: Sykobee (Briggsy) on 12:57, 12 June 20I wonder if my old 10 liner runs on this? https://www.cpc-power.com/index.php?page=detail&onglet=dumps&num=14242The 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 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:


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



* 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

mv

Quote from: Sykobee (Briggsy) on 12: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
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.


mv

Quote from: AMSDOS on 10:44, 18 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 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.

Sykobee (Briggsy)

Quote from: mv on 22:52, 18 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!).

AMSDOS

Quote from: mv on 23:34, 18 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?

QuoteAnd 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/
* 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

AMSDOS

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:


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
* 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

mv

Quote from: AMSDOS on 11: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:
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.

AMSDOS

Quote from: mv on 23:33, 22 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.


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


QuoteRegarding 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.
* 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

mv

Quote from: AMSDOS on 10:10, 23 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:


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

QuoteGetting 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.
QuoteIt 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.


Powered by SMFPacks Menu Editor Mod