News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu

BASIC programming tips

Started by arnoldemu, 14:23, 22 May 09

Previous topic - Next topic

0 Members and 2 Guests are viewing this topic.

AMSDOS

 :-[  Unfortunately I'm guilty of over complicating as usual by applying Math for LOCATE to use when the same result works without LOCATE and getting the job done in under 7 seconds with a Single Loop:



100 MODE 0:BORDER 0:INK 14,15:INK 15,9
110 DEFINT a-z
120 t1!=TIME
130 FOR a=1 TO 500
140   PEN INT(RND*15)+1
150   PRINT CHR$(248);
160 NEXT a
170 t2!=TIME
180 PEN 1:PRINT"Time =";(t2!-t1!)/300
190 END



I'm following up on this example from above to create a Game Screen with Ladders and Platforms using a Memory Array. It comes two parts, the 1st part fills the memory array with 32 (Lines 1010-1030), poke the platforms & pen colours to the memory array (Lines 1040-1070, Lines 140-180), Line 1060 also places gaps within the Platforms where the Ladders go, this is not needed through as Lines 1080-1090 place the Ladders over those areas from the Routine on lines 200-240. Lines 250-260 handles the Screen Character data and Lines 270-280 is used to store PEN colours.
Once that's done a Time is display onscreen for the Setup Time & Press any key to launch the 2nd part which draws the screen Lines 300-360 followed by the time it takes to do that. Just to play around with the Code a bit I added Line 311 which if the platform character is detected use PAPER 8 for it's background, otherwise it uses PAPER 0. Having that Line there also determines how fast the screen draws with different timings becoming the result as well as if Line 311 is commented, that also changes the Timings too.




100 MODE 2:BORDER 0:INK 1,26:INK 3,3
110 SYMBOL 255,255,0,24,36,66,129,0,255
120 SYMBOL 254,129,129,255,129,129,129,255,129
130 GOTO 1000
140 FOR x=1 TO 20
150   POKE &9FEB+x+(y*20),255
160   p=3:GOSUB 270
170 NEXT x
180 RETURN
200 FOR y=3 TO 20
210   GOSUB 250
220   GOSUB 270
230 NEXT y
240 RETURN
250 POKE &9FEB+x+(y*20),v
260 RETURN
270 POKE &A1EB+x+(y*20),p
280 RETURN
300 MODE 0:t1!=TIME
310 FOR a=0 TO 479
311   IF PEEK(&A000+a)=255 THEN PAPER 8 ELSE PAPER 0
320   PEN PEEK(&A200+a):PRINT CHR$(PEEK(&A000+a));
330 NEXT a
340 t2!=TIME
350 PEN 1:LOCATE 1,23:PRINT"Draw Time = ";USING"#.##";(t2!-t1!)/300
360 RETURN
1000 DEFINT a-z:MEMORY &9FFF:t1!=TIME
1010 FOR a=1 TO 500
1020   POKE &9FFF+a,32
1030 NEXT a
1040 FOR y=3 TO 21 STEP 3
1050   GOSUB 140
1060   IF y<>21 THEN x=2:v=32:GOSUB 250:x=18:GOSUB 250
1070 NEXT y
1080 x=2:v=254:p=1:GOSUB 200
1090 x=18:GOSUB 200
1100 t2!=TIME
1110 LOCATE 1,1:PRINT"Setup Time =";(t2!-t1!)/300
1120 CALL &BB18
1130 GOSUB 300
1140 END






* 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

Fabrizio

Is there a way in pure BASIC (+ possibly ROM-only routines) to read the character at a given position, e.g., cursor position.
I know the CPC only has graphics screens. I supposed that a text buffer is used. I have seen simply Assembly used in BASIC to do that. I have not found a BASIC-only (+ROM-only routines) solution. My solution has been to implement myself a buffer to remember the characters on the screen.

Does anyone here have a better idea?

pelrun

#127
BASIC 1.1 has COPYCHR$(), which will return the character at the cursor position. It does a graphical comparison against the character set, there's no internal char buffer.
Of course, that means 464's are out of luck, but the function is available in the ROM and can be accessed with a small asm routine. There's an example here: https://www.sean.co.uk/books/amstrad/amstrad2.shtm#COPYCHR
There's also some other examples of how to do it at http://www.cpcwiki.eu/forum/programming/study-of-464-only-game-helicopter-destination-saturn-from-acu/

AMSDOS

Quote from: Fabrizio on 22:32, 19 January 20Is there a way in pure BASIC (+ possibly ROM-only routines) to read the character at a given position, e.g., cursor position.I know the CPC only has graphics screens. I supposed that a text buffer is used. I have seen simply Assembly used in BASIC to do that. I have not found a BASIC-only (+ROM-only routines) solution. My solution has been to implement myself a buffer to remember the characters on the screen.Does anyone here have a better idea?



As @pelrun mentioned COPYCHR$() is the function to use, apart from it being BASIC 1.1 only, the only other reason I can think of, of why not to use it, is a speed decrease during gameplay.


Other examples include Diamond Hunt. In those examples the BASIC 1.1 version uses COPYCHR$() and the screen is setup quicker than in my Revised version which used an array, but once the gameplay starts my version is faster than the original. In Bomb Drop which had a few COPYCHR$() in them, I replaced all that with a MEMORY Array and used POKE & PEEK to store and retreive the contents, it too has some setup time before the game starts, the original game can be found within the Depth Charge zip file in this thread, from memory the original had some problems if the Bombs were placed undernearth one another, which meant you couldn't get to them. When I switched the game to using a MEMORY Array, I was able to rectify that problem too.
Another approach (compatable on all systems) if you don't like Array's, is to use TEST(). Unfortunately TEST() only checks for a single Pixel using Graphical co-ordinates, though with Block calculations being used to obtain the XPOS & YPOS. The only problem with that is each graphic would need it's own Identifying Colour pixels and the TEST would have to be done on a spot where all Graphics has it's Colour Representation. I wrote a little BASIC game here, which does that.


It really up to you to decide what works best.
* 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

Sykobee (Briggsy)

If you have a map or similar in-memory representation/abstraction of what is being displayed on screen, then always compare against the map rather than the very slow COPYCHR$ command.


Most games should have a map, or at least the current screen, in memory (2K for a full BASIC MODE 1 screen built up on character sized blocks, using an INT% array) - it all depends on the game really.

AMSDOS


For anyone interested, I made a simple comparision programme to test COPYCHR$, TEST using Functions, TEST using direct values and a BASIC Array (results in the Screenshot below).


The Test simply prints a Man moving Left to Right of the screen replacing and restoring background as it moves, the Gaps in the scenary are a part of testing TEST and have setup a short 2 byte array (a$) so if a gap is found 0 is returned and restores as printing that gap, otherwise it's CHR$(127), which represents 1.


Obviously with the test including COPYCHR$, this will be BASIC 1.1 only, the other tests are compatable in BASIC 1.0 and will work if Lines 210-350 are omitted.




100 MODE 1:DEFINT a-z:a$(0)=CHR$(32):a$(1)=CHR$(127):DIM m$(40):DEF FNxp=((x-1)*16):DEF FNyp=398-((y-1)*16)
110 BORDER 0:INK 0,11:INK 1,26
120 LOCATE 1,10:PRINT STRING$(40,127);
130 FOR x=1 TO 40:m$(x)=CHR$(127):NEXT x
140 FOR a=1 TO 3
150   x=(RND*38)+1
160   WHILE TEST(FNxp,398-(9*16))=0
170     x=(RND*38)+1
180   WEND
190   m$(x)=" ":MOVE FNxp,398-(9*16):TAG:PRINT CHR$(32);:TAGOFF
200 NEXT a
210 x=1:y=10
220 LOCATE x,y:a$=COPYCHR$(#0)
230 PRINT CHR$(250);
240 t1!=TIME
250 WHILE x<>40
260   LOCATE x,y
270   x=x+1
280   PRINT a$;
290   LOCATE x,y:a$=COPYCHR$(#0)
300   PRINT CHR$(250);
310 WEND
320 t2!=TIME
330 LOCATE 1,1:PRINT "COPYCHR$ Time =";USING"##.##";(t2!-t1!)/300
340 CALL &BB18
350 LOCATE 40,10:PRINT CHR$(127);
360 x=1:y=10
370 p=TEST(FNxp,FNyp)
380 MOVE FNxp,FNyp:TAG:PRINT CHR$(250);:TAGOFF
390 t1!=TIME
400 WHILE x<>40
410   MOVE FNxp,FNyp
420   x=x+1
430   TAG:PRINT a$(p);
440   MOVE FNxp,FNyp
450   p=TEST(FNxp,FNyp)
460   PRINT CHR$(250);:TAGOFF
470 WEND
480 t2!=TIME
490 LOCATE 1,2:PRINT "TEST using Functions Time =";USING"##.##";(t2!-t1!)/300
500 CALL &BB18
510 LOCATE 40,10:PRINT CHR$(127);
520 x=0:y=254
530 p=TEST(x,y)
540 MOVE x,y:TAG:PRINT CHR$(250);:TAGOFF
550 t1!=TIME
560 WHILE x<>624
570   MOVE x,y
580   x=x+16
590   TAG:PRINT a$(p);
600   MOVE x,y
610   p=TEST(x,y)
620   PRINT CHR$(250);:TAGOFF
630 WEND
640 t2!=TIME
650 LOCATE 1,3:PRINT "TEST with direct values Time =";USING"##.##";(t2!-t1!)/300
660 CALL &BB18
670 LOCATE 40,10:PRINT CHR$(127);
680 x=1:y=10
690 v$=m$(x)
700 LOCATE 1,10:PRINT CHR$(250);
710 t1!=TIME
720 WHILE x<>40
730   LOCATE x,y
740   x=x+1
750   PRINT v$;
760   LOCATE x,y
770   v$=m$(x)
780   PRINT CHR$(250);
790 WEND
800 t2!=TIME
810 LOCATE 1,4:PRINT "Array Time =";USING"##.##";(t2!-t1!)/300
820 END




* 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 03:12, 25 January 20
For anyone interested, I made a simple comparision programme to test COPYCHR$, ...
Hey, great! Without knowing about your test (I will try it later), I also made a test for COPYCHR$, today. It has also some machine code for all CPCs...

Did you know that COPYCHR$ (or call &BB60, TXT RD CHAR) not only recognizes a character with the selected PEN, but also its inverse with the selected PAPER?
That means the PEN or PAPER can be pixelized without affecting the result, but not both. This also means that an inverted character cannot be recognized.
And if no PEN bits and no PAPER bits are set, there is a slight difference: The CPC 664/6128 returns space (char 32) and the CPC 464 the inverse of space (char 143).
Any more subtle findings?

Demo:

10 REM fancy - test copychr$
20 MODE 1:CLEAR:DEFINT a-z:RANDOMIZE TIME:PEN 1:PAPER 0
30 useCopychr=0: 'set this to use copychr$
40 c$=CHR$(&CD)+CHR$(&60)+CHR$(&BB)+CHR$(&32)+CHR$(0)+CHR$(0)+CHR$(&C9): 'call &BB60 (TXT RD CHAR)
50 fancy$="F"+CHR$(15)+CHR$(2)+"a"+CHR$(15)+CHR$(3)+"n"+CHR$(15)+CHR$(1)+CHR$(24)+"cy"+CHR$(24)+" s"+CHR$(14)+CHR$(2)+"t"+CHR$(14)+CHR$(3)+"u"+CHR$(14)+CHR$(0)+"ff"+"!"
60 LOCATE 1,1:PRINT fancy$;" ";fancy$
70 ' pixelize the first 12 characters
80 xstart=0
90 FOR i=1 TO 12
100 ckeep=1:IF i=2 OR i=3 OR i=7 OR i=10 THEN ckeep=0: 'the color to keep (1=pen or 0=paper)
110 FOR y=0 TO 7:FOR x=0 TO 7
120 xp=xstart+x*2:yp=399-y*2
130 IF TEST(xp,yp)=ckeep THEN 160
140 c=INT(RND*3+0.5):IF c=ckeep THEN 140
150 PLOT xp,yp,c :'set random color which is not the kept color
160 NEXT x,y
170 xstart=xstart+2*8
180 CALL &BD19:NEXT i
190 ' recognize characters in first line
200 a$="":FOR i=1 TO 12*2+1:LOCATE i,1:
210 GOSUB 290
220 a$=a$+t$
230 NEXT
240 LOCATE 1,5:PRINT a$;
250 t!=TIME+600:WHILE TIME<t! AND INKEY$="":CALL &BD19:WEND:LOCATE 1,5:PRINT CHR$(18);
260 GOTO 80
270 '
280 'call &BB60 (TXT RD CHAR) as COPYCHR$ on any CPC
290 IF useCopychr OR PEEK(&BB60)<>&CF THEN t$=COPYCHR$(#0):GOTO 330: 'flag set or CPCBasic
300 a%=UNT(PEEK(@c$+1)+PEEK(@c$+2)*&100)
310 CALL a%:b%=PEEK(0)
320 t$=CHR$(b%)
330 RETURN


(Can be found on: https://benchmarko.github.io/CPCBasic/cpcbasic.html?example=test/fancy)

AMSDOS

Quote from: mv on 19:05, 25 January 20
Did you know that COPYCHR$ (or call &BB60, TXT RD CHAR) not only recognizes a character with the selected PEN, but also its inverse with the selected PAPER?


Yes, I found out about that when I was fixing up Destination Saturn.

QuoteThat means the PEN or PAPER can be pixelized without affecting the result, but not both. This also means that an inverted character cannot be recognized.


QuoteAnd if no PEN bits and no PAPER bits are set, there is a slight difference: The CPC 664/6128 returns space (char 32) and the CPC 464 the inverse of space (char 143).



er? As long as the PEN & PAPER checks match the colour when the COPYCHR$ check is done, it should be fine, but I found on a 464 it doesn't seem to matter.




QuoteAny more subtle findings?


If a different Graphical colour is used, COPYCHR$ won't pickup on it unless it's in the same colour scheme, I made a test programme of it here, which you've proabably seen.


* 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

I made a little routine to print out the Line Lengths of a BASIC programme, useful for working out which category your BASIC programme belongs in or adjusting it to size for those 10-Liners.


60000 a=&170
60010 v=PEEK(&170)
60020 n=0
60030 FOR l=1 TO 10
60040 PRINT v
60050 n = a + v
60060 a = n
60070 v = PEEK(n)
60080 CALL &BB18
60090 NEXT l
* 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

Gryzor

But this will increase your listing length 😄

AMSDOS

Quote from: Gryzor on 11:31, 15 February 20
But this will increase your listing length 😄


Only to show a rundown of the process involved, it's that short a routine that it can be entered as a series of statements like this:


a=&170:v=PEEK(&170):n=0:FOR L=1 TO 10:PRINT v:n = a + v:a = n:v = PEEK(n):CALL &BB18:NEXT L


or from a KEY <num>,... statement.


The code works by obtaining the actual length of each line, BASIC programmes begin at &170 or 368 with the 1st byte representing that Line Length, so to get the Line Length of the second line and so on, the address (a) is added with the Line Length value (v) to get the new value (n) and then address (a) becomes that new value (n) and v becomes the next Line Length and so on until L = 10.


So I tested it on the Red's Exit game I wrote back in 2017 for the BASIC 10-Liners Contest and to my surprise 1 of the 10 Lines exceeded the Length category the game was put in, the funny thing about that is when a character count is carried out, it comes up shorter, which kind of explains why in some cases if too many variables are used on the same line a "Line Too Long" Error results.


Though here are the results I got from Red's Exit:
102
80
89
115
66
113
127
108
91
71
* 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

GFXOR

The normal use of TAG / MOVE is that if you PRINT"HELLO EVERYBODY" too close from the right side of the screen, the text will be cut, where I would prerfer it to go on writing on the left. I guess the system is detecting if the text is exceeding the right limit of "640 pixels", where I would prefer it to going on writing wherever it is.

Do you know if there is a magical POKE to let the text write ?

[ot]Out of this subject :
As I am not really fluent english speaker, I don't read all the topics, so I juste discovered the old Morri question, 3 years after.
Quote from: MorriDoes anyone have some simple BASIC code to have the following sequence of numbers...
1 2 3 2 1 2 3 2 1 2 3 etc...
I can do it in the following code but just wondering if someone can do it faster
I am surprised not to have read a such simple solution :
10 FOR x=-1 to 2:PRINT 1+ABS(x);:NEXT
[/ot]
Supersly from the Les sucres en morceaux

ZbyniuR

Limits of graphics area are sets by command ORIGIN. If setting this way doesn't work, you can try by POKE.

Kernel guide shows adress of pixel x margin:

for 6128 at &B69B and &B69D (2byte both)
for  464 at &B330 and &B332

Let me know is it help. :)
In STARS, TREK is better than WARS.

ZbyniuR

#138
New version of  "Hello World"  in one line of pure Basic. :)

10 MODE 0:BORDER 0:FOR i=0 TO 15:INK i,ASC(MID$("@YXOFCDHQTKBAIRV",i+1,1))-64:NEXT:WHILE-1:FOR p=1 TO 15 STEP 0.5:PEN p:s=(s+1)MOD 18:LOCATE VAL(MID$("112345678998765432",s+1,1)),1:PRINT"Hello World!"CHR$(30)CHR$(11):NEXT:WEND

In STARS, TREK is better than WARS.

McArti0

#139

32k colors show in Asic CPC6128 plus. Only native Basic. Flashing method for 5bits per colour. The Screenshot will not show this effect. (JavaCPC can to bind two frames but not emulated CPCPlus range)


The interesting fact is that i found how to disable/enable interrupts for Basic program (6128)


REM is simple delay command :)


Flashing work best on ShugarBox with Vsync options. (Who knows better emulator?)


Not ideal but ...

https://youtu.be/weUUQ4mQ9rg



1 GOTO 8
2 POKE &B9B7,&F3:POKE &BA44,&F3:POKE &BA4F,&F3:RETURN:'DISABLE INTERRUPT
3 POKE &BA44,&FB:POKE &BA4F,&FB:POKE &B9B7,&FB:CALL &B9B7:RETURN:'ENABLE INTERRUPT
8 GOSUB 2:'DISABLE INTERRUPT
9 'ASIC-UNLOCK SEQUENCE
10 FRAME:OUT &BC00,&FF:OUT &BC00,&0:OUT &BC00,&FF:OUT &BC00,&77:OUT &BC00,&B3:OUT &BC00,&51:OUT &BC00,&A8:OUT &BC00,&D4:OUT &BC00,&62:OUT &BC00,&39:OUT &BC00,&9C:OUT &BC00,&46:OUT &BC00,&2B:OUT &BC00,&15:OUT &BC00,&8A:OUT &BC00,&CD:OUT &BC00,&EE
20 MEMORY &3FFF:OUT &7FB8,&B8:'ASIC RAM Enable
30 OUT &BC00,7:OUT &BD00,34:'SCREEN UP
40 DEFINT x,a,r,g,b,c,t,d,w:w=1
45 a=&6401:b=&6400
46 d=1:'number frames of DELAY
50 g=1:WINDOW#2,1,80,24,25:PAPER#2,2:INK 2,13:CLS#2:BORDER 0
60 SPEED INK 1,1:POKE &B7F8,255:'INK FLASH COUNTER
65 ON ERROR GOTO 215
71 POKE a,0:POKE b,0
73 c=256:d=200:r=0:g=1:x=0:GOSUB 80
74 c=256:d=200:r=0:g=0:x=0:GOSUB 80
75 a=&6400:b=&6401:POKE b,0:c=256:g=1:GOSUB 80
76 c=256:g=-1:GOSUB 80:c=256:g=1:w=2:GOSUB 80:c=256:g=0:GOSUB 80:w=1:
77 a=&6401:b=&6400:c=0:d=1:r=0:g=0:x=0:GOSUB 80
78 POKE a,0:POKE b,0:a=&6403:b=&6402:c=0:r=0:g=1:x=0:GOSUB 1100:GOSUB 80
79 GOSUB 3:END
80 REM
90 FRAME
100 GOSUB 220
120 FOR t=1 TO d
125 FRAME
130 GOSUB 240
140 POKE &B7F8,25
150 FRAME
160 GOSUB 220
170 NEXT
172 IF c>255 THEN c=0:RETURN ELSE POKE b,C:x=x+1
180 FRAME
190 GOSUB 240
200 IF x=16 THEN x=-15:r=r+16 ELSE C=r+ABS(x)
210 GOTO 90
215 RETURN
220 IF g=1 THEN 280 ELSE 270
240 IF g=1 THEN 280 ELSE 250
250 REM
255 REM
260 REM
270 REM
280 REM
285 ON w GOTO 900,1000
900 POKE a,1:POKE a,2:POKE a,3:POKE a,4:POKE a,5:POKE a,6:POKE a,7:POKE a,8:POKE a,9:POKE a,10:POKE a,11:POKE a,12:POKE a,13:POKE a,14:POKE a,15:POKE a,0
910 RETURN
1000 POKE a,16:POKE a,32:POKE a,48:POKE a,64:POKE a,80:POKE a,96:POKE a,112:POKE a,128:POKE a,144:POKE a,160:POKE a,176:POKE a,192:POKE a,208:POKE a,224:POKE a,240:POKE a,0
1010 RETURN
1100 CLS:FOR n=1 TO 4:FOR ch=0 TO 255:PRINT CHR$(1)+CHR$(ch);:NEXT:NEXT:RETURN
CPC 6128, Whole 6128 and Only 6128, with .....
NewPAL v3 for use all 128kB RAM by CRTC as VRAM
TYPICAL :) TV Funai 22FL532/10 with VGA-RGB-in.

McArti0

#140
Thanks to the CPCEC emulator, I can show these images in real appearance...
CPC 6128, Whole 6128 and Only 6128, with .....
NewPAL v3 for use all 128kB RAM by CRTC as VRAM
TYPICAL :) TV Funai 22FL532/10 with VGA-RGB-in.

McArti0

#141
Quote from: arnoldemu on 14:23, 22 May 0940 CALL &BFFE-35, &C970,&2371,&166,&DD00,&6EDD,&ED18,&4623,&4E23,&23EB,&19EB,&A28
,&B37A,&2B56,&235E,&EB00,&1,&170,&1100,@last%

Brilliant trick!

On this way...
Copy memory (LDIR):
64000 CALL &BFF2,&C9,&B0ED,Size,&100,Source,&2100,Target:RETURN:REM Copy Size from Source to Target.

poke... peek.
65000 CALL &BFF8,&C9,ADDRESS,&22EB,VALUE      :REM poke16
65001 CALL &BFF8,&C9,ADDRESS,&327B,VALUE      :REM poke8bit
65002 CALL &BFF8,&C9,@v%,&321A,ADDRESS        :REM peek8bit  result in V%
65003 CALL &BFF2,&C9,@v%,&53ED,&5623,&5EEB, ADDRESS:   REM peek16bit result in V%

any code (allocatable) of any length up to 60 bytes (backword)
65004 CALL &BFFC,&E9DD, .......................................... DDE9 is code JP (IX)

A string as a code container
65005 CALL &BFF6,&E9,&EB56,&235E,&23EB,"String with machine code ... "
CPC 6128, Whole 6128 and Only 6128, with .....
NewPAL v3 for use all 128kB RAM by CRTC as VRAM
TYPICAL :) TV Funai 22FL532/10 with VGA-RGB-in.

ZbyniuR

Did you ever played MASK command?  No big deal, yet another screensaver.  ribbon.bas
Who think only 4 colors sound dull?  Try 4colors.bas  :)
In STARS, TREK is better than WARS.

ZbyniuR

#143
This fractal shape is called the dragon curve. I found this program for Spectrum in the old magazine. 
And this film show how is made that shape. :)

10 DEFINT a-z:x=6:MODE 1:DIM c(20):PLOT 480,140,3
20 DRAWR x,y:k=1
30 IF c(k)=0 THEN 50
40 c(k)=0:k=k+1:IF k=13 THEN END ELSE 30
50 c(k)=1:k=k+1:IF c(k)=0 THEN 70
60 z=x:x=y:y=-z:GOTO 20
70 z=x:x=-y:y=z:GOTO 20


https://www.youtube.com/watch?v=UBuPWdSbyf8
In STARS, TREK is better than WARS.

TotO

Impresive to see that dragon curve to unfold and never overlap.
"You make one mistake in your life and the internet will never let you live it down" (Keith Goodyer)

McArti0

Is it possible to make a useful overscan in basic?  :o

1 SPEED INK 1,1:BORDER 3:MEMORY &3FFF
3 OUT &BC00,7:OUT &BD00,18:OUT &BC00,6:OUT &BD00,16:OUT &BC00,1:OUT &BD00,48:OUT &BC00,2:OUT &BD00,50
4 FRAME:CALL &BFF8,&C976,&7676,&7676:CALL &B92A:REM 4xHALT, Keyboard Scan needed
10 EVERY 1,3 GOSUB 100
15 EVERY 1,2 GOSUB 200
16 EVERY 1,1 GOSUB 300
17 EVERY 1,0 GOSUB 400
19 ON BREAK GOSUB 500:POKE &B7C6,&40:PAPER 3:CLS:INK 3,9:LOCATE 5,19:PRINT"LAST LINE visible in &4000 BANK";:POKE &B7C6,&C0:PAPER 0:CLS:PRINT"space or 2xESC ending dynamic frame split and overscan."
20 REM
25 IF INKEY(47)=0 THEN GOTO 500
30 GOTO 20
100 OUT &BC00,4:OUT &BD00,15:OUT &BC00,12:OUT &BD00,&10
110 RETURN
200 RETURN
300 RETURN
400 OUT &BC00,4:OUT &BD00,22:OUT &BC00,12:OUT &BD00,&30: REM OUT &7F00,&10:OUT &7F00,&5F
410 RETURN
500 DI:OUT &BC00,4:OUT &BD00,38:OUT &BC00,12:OUT &BD00,&30:OUT &BC00,6:OUT &BD00,25:OUT &BC00,7:OUT &BD00,30:OUT &BC00,1:OUT &BD00,40:OUT &BC00,2:OUT &BD00,46:CLEAR INPUT

CPC 6128, Whole 6128 and Only 6128, with .....
NewPAL v3 for use all 128kB RAM by CRTC as VRAM
TYPICAL :) TV Funai 22FL532/10 with VGA-RGB-in.

zhulien

A couple of tips to make your code a bit more readable in Locomotive BASIC - althrough it does make it a tiny bit slower.

Line Numbering:

Renum your code from 100 or 1000 so that the indents for most part are consistent.  These are indents you are going to put in after the line numbers.

1000 PRINT "Hello, World!"
If Then:

Use If then in a way with indents to make your code more readable.

1000 IF x = 1 THEN ELSE 1040
1010    IF y = 1 THEN ELSE 1030
1020      PRINT "Hello, World!"
1030    'END IF
1040 'END IF

If Then Else:

As per If Then, you can nest them.

1000 IF x = 1 THEN ELSE 1030
1010   PRINT "Do This"
1020   GOTO 1050
1030 'ELSE
1040   PRINT "Do That"
1050 'END IF

While Wend:

Indent.

1000 X = 5
1010 WHILE x > 0
1020   PRINT "Hello, World!"
1030   x = x - 1
1040 WEND


Manuel3D

Does anyone know how we can load an image that remains in the background as if it were "paper" and that allows us, for example, to draw on it with the basic plot and draw commands? The idea is to use that image, for example in .scr format, to draw lines above it and create a basic copy of the image below. The idea is like when as children we copied an image by putting onion paper on top. Thank you for help me. 




Manuel3D

explanation to my previous message.....
I am making a program in Basic Locomotive for Amstrad CPC to draw with the plot and draw commands in a simple way by moving the cursor around the screen. The fact is that if I want to copy a drawing that I like from the Internet, I have to print it, paste  on the Amstrad screen with tape and move the cursor to draw the lines necessary to convert that drawing to the lines format of the Amstrad Basic. .(it is a primitive method like when a child draws on a TV screen by sticking a piece of paper on the TV screen) It would be much easier if I converted that image to screen format with a program like CovImgcpc and loaded that image as the background of my Amstrad screen and I run the program over it and draw like someone who copies a drawing by pasting a piece of paper on the computer screen. I don't know if it is possible to do this in Amstrad Basic. I have tried and I can't, but I'm sure there is a way that I don't know about.

BSC

#149
Quote from: Manuel3D on 16:12, 14 October 23Does anyone know how we can load an image that remains in the background as if it were "paper" and that allows us, for example, to draw on it with the basic plot and draw commands? The idea is to use that image, for example in .scr format, to draw lines above it and create a basic copy of the image below. The idea is like when as children we copied an image by putting onion paper on top. Thank you for help me.

Hi, if you want to do it in BASIC then you need something to display/restore your background image. That's impossible in pure BASIC for performance reasons, so you need something written in assembly language. The easiest solution I see, depending on how you plan to draw and plot on top of that image, would be to load the image to an off-screen memory area (e.g. &4000), have some piece of code which transfers from there to screen memory and then you would call this code every time you need to recover that image. One downside of this is that all the plot/draw commands you enter will cover much of the screen real quick, so you will end up doing a lot of iterations of drawing and restoring. And there's might be some trial and error involved for finding the right screen coordinates.
** My SID player/tracker AYAY Kaeppttn! on github **  Some CPC music and experiments ** Other music ** More music on scenestream (former nectarine) ** Some shaders ** Some Soundtrakker tunes ** Some tunes in Javascript

My hardware: ** Schneider CPC 464 with colour screen, 64k extension, 3" and 5,25 drives and more ** Amstrad CPC 6128 with M4 board, GreaseWeazle.

Powered by SMFPacks Menu Editor Mod