Request: Small BASIC programs...

A place to discuss everything Dragon related that doesn't fall into the other categories.
Post Reply
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Request: Small BASIC programs...

Post by jedie »

I would like to collect small BASIC programs.

Preferably Text only program, first.

e.g.: Display all characters:

Code: Select all

10 CLS
20 FOR I = 0 TO 255:
30 POKE 1024+(I*2),I
40 NEXT I
50 I$ = INKEY$:IF I$="" THEN 50
Last edited by jedie on Tue Aug 19, 2014 9:09 am, edited 1 time in total.
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
sorchard
Posts: 529
Joined: Sat Jun 07, 2014 9:43 pm
Location: Norwich UK

Re: Request: Smal BASIC programs...

Post by sorchard »

jedie wrote:I would like to collect small BASIC programs.
Here's one I wrote back in the day. It lists all the variables used in a BASIC program.

To actually make use of it you would need to remove the example array declarations from the start then renumber and add the remaining lines to your own program. You could also rename all the variables to avoid collisions.
Attachments
varlist.cas
(1.12 KiB) Downloaded 187 times
Stew
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Request: Small BASIC programs...

Post by jedie »

Thanks sorchard ... But i can currently not read .cas files :(


Here is the "DUMP PROGRAM" from Inside the Dragon in a working version. (The OCR in the PDF has made some errors):

Code: Select all

10 'DUMP PROGRAM
15 'Peeks a word (16 bits)
20 DEF FNW(A)=PEEK(A)*256+PEEK(A+1)
30 DIM ZZ(2),XX(2,1),ZZ$(2),XX$(2,1)
40 DIM XY(1,2,3)
50 'DEFINING VARIABLES BEFORE USE
60 FOR I=0 TO 2
70 ZZ(I)=I:ZZ$(I)=STR$(I)
80 FOR J=0 TO 1
90 XX(I,J)=C:XX$(I,J)=STR$(C)
100 XY(J,I,0)=C
110 C=C+1
120 NEXTJ,I
130 PS=0 'Program Start
140 PE=0 'Program End
150 VS=0 'Variables Start
160 VE=0 'Variables End
170 AS=0 'Array Start
180 AE=0 'Array End
190 DA=0 'Dump Address
200 NA=0 'Next Address
210 DV=0 'Device number
220 DBYTE=0:AN$="":SBYTE=0
230 R=0:H3=0:H2=0:H1=0:H0=0
240 PA=&H19
250 PS=FNW(PA) '19:1A contain PS address
260 VS=FNW(PA+2) '1B:1C contain VS address
270 AS=FNW(PA+4) '1D:1E contain AS address
280 PE=VS-1 'Variables are after program
290 VE=AS-1 'Arrays are after variables
300 AE=FNW(PA+6)-1 '1F:20 holds free space address
310 CLS
320 INPUT"OUTPUT TO PRINTER";AN$
330 IF AN$ = "Y" THEN DV=-2 ELSE DV=0
340 PRINT#DV,"PROGRAM START ADDRESS = ";:DBYTE=PS
350 GOSUB 1000:PRINT#DV
360 PRINT#DV,"PROGRAM END ADDRESS = ";:DBYTE=PE
370 GOSUB 1000:PRINT#DV
380 PRINT#DV,"VARIABLE START ADDRESS = ";:DBYTE=VS
390 GOSUB 1000:PRINT#DV
400 PRINT#DV,"VARIABLE END ADDRESS = ";:DBYTE=VE
410 GOSUB 1000:PRINT#DV
420 PRINT#DV,"ARRAY START ADDRESS = ";:DBYTE=AS
430 GOSUB 1000:PRINT#DV
440 PRINT#DV,"ARRAY END ADDRESS = ";:DBYTE=AE
450 GOSUB 1000:PRINT#DV
460 INPUT "DO YOU WISH A PROGRAM DUMP";AN$
470 IF AN$<>"Y" THEN GOTO 630
480 PRINT#DV,"PROGRAM DUMP"
490 DA=PS
500 NA=FNW(DA)
510 IF (NA=0) OR (DA=PE) THEN GOTO 620
520 PRINT#DV:PRINT#DV
530 DBYTE=DA:GOSUB 1000 'PRINT CURRENT ADDRESS
540 PRINT#DV
550 DBYTE=NA: GOSUB 1000 'PRINT NEXT ADDRESS
560 DA=DA+2
570 DBYTE=FNW(DA) : GOSUB 1000 'PRINT LINE NUMBER
580 DA=DA+2
590 SBYTE=PEEK(DA): GOSUB 2000 'PRINT LINE CONTENTS
600 DA=DA+1
610 IF DA<>NA THEN GOTO 590 ELSE GOTO 500
620 PRINT#DV
630 INPUT "DO YOU WANT A VARIABLE DUMP";AN$
640 IF AN$ <> "Y" THEN GOTO 690
650 PRINT#DV:PRINT#DV:PRINT#DV,"VARIABLE DUMP"
660 FOR DA = VS TO VE
670 SBYTE=PEEK(DA): GOSUB 2000
680 NEXT DA
690 PRINT#DV
700 INPUT "DO YOU WANT AN ARRAY DUMP";AN$
710 IF AN$ <> "Y" THEN GOTO 760
720 PRINT#DV:PRINT#DV:PRINT#DV,"ARRAY DUMP"
730 FOR DA = AS TO AE
740 SBYTE=PEEK(DA): GOSUB 2000
750 NEXT DA
760 PRINT#DV:PRINT#DV,"DUMP FINISHED"
770 STOP
1000 'PRINT 2 BYTES AS 4 HEX CHARS
1010 R=DBYTE
1020 H3=INT(R/4096): R=DBYTE-H3*4096
1030 H2=INT(R/256): R=R-H2*256
1040 H1=INT(R/16): H0=R-H1*16
1045 HW$=HEX$(H3)+HEX$(H2)+HEX$(H1)+HEX$(H0)
1050 PRINT#DV, USING "%  %"; HW$
1060 RETURN
2000 'PRINT 1 BYTE AS 2 HEX CHARS
2010 H1=INT(SBYTE/16): H0=SBYTE-H1*16
2020 PRINT#DV, USING"% %";HEX$(H1)+HEX$(H0);
2030 RETURN
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
sorchard
Posts: 529
Joined: Sat Jun 07, 2014 9:43 pm
Location: Norwich UK

Re: Request: Small BASIC programs...

Post by sorchard »

Sorry jedie, I didn't realise...

Code: Select all

10 SV=0:AV=0:EN=0:AD=0:I=0:V$=""
20 DIM A(0,1,2)
30 DIM BT$(10),Z(0),P$(1,1,1,1)
40 DIM EN(7,7)
99 '
100 SV=PEEK(27)*256+PEEK(28)
110 AV=PEEK(29)*256+PEEK(30)
111 EN=PEEK(31)*256+PEEK(32)
115 IF AV=SV THEN 200
117 PRINT"SIMPLE VARIABLES:"
120 AD=SV
130 GOSUB500
138 PRINTV$
140 AD=AD+7
150 IF AD<AV THEN130
200 IF EN=AV THEN 300
210 PRINT"ARRAY VARIABLES:"
220 AD=AV
230 GOSUB500
240 PRINTV$;"(";
242 FOR I=PEEK(AD+4) TO 1 STEP -1
244 PRINTPEEK(AD+I*2+3)*256+PEEK(AD+I*2+4);
246 NEXT
248 PRINT")"
250 AD=AD+PEEK(AD+2)*256+PEEK(AD+3)
260 IF AD<EN THEN230
300 '
490 END
500 V$=CHR$(PEEK(AD)):I=PEEK(AD+1)
510 IF I AND 127 THEN V$=V$+CHR$(I AND 127)
520 IF I AND 128 THEN V$=V$+"$"
530 RETURN
My program is not as sophisticated as the one from 'Inside the Dragon'. It just lists the variables.
Stew
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Request: Small BASIC programs...

Post by jedie »

Thanks, really nice!

It works, but it seems that ARRAY values are wrong. All values have a "offset" +1 ?!?
e.g.: The example array A(0,1,2) is displayed as A(1,2,3)

btw. i add your script here: https://gist.github.com/jedie/c31b7df2f ... /revisions and renumber it.
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
sorchard
Posts: 529
Joined: Sat Jun 07, 2014 9:43 pm
Location: Norwich UK

Re: Request: Small BASIC programs...

Post by sorchard »

jedie wrote:it seems that ARRAY values are wrong. All values have a "offset" +1
It is a bit misleading. The program is showing the size of the arrays. So for example DIM A(0,1,2) creates an array with 1*2*3 = 6 elements.

Note it is possible to create an array with one element: For example DIM Z(0). Not very useful but there it is.
Stew
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: Request: Small BASIC programs...

Post by JeeK »

sorchard wrote: [..]
Note it is possible to create an array with one element: For example DIM Z(0). Not very useful but there it is.
An array with just one element seems not very useful, but even for small arrays which are automatically defined or just simple variables DIM is useful, one could say elegant, to define the order of variables and array variables how they appear in the interpreter's internal variable list structure. And its "cheaper" (in space) compared to initializing assignments, too.This could be used to optimize the runtime (heavily used variables defined first prevent long linear variable searches).
The dragon on my side: http://klasek.at/hc/dragon/
sorchard
Posts: 529
Joined: Sat Jun 07, 2014 9:43 pm
Location: Norwich UK

Re: Request: Small BASIC programs...

Post by sorchard »

JeeK wrote:DIM is useful, one could say elegant, to define the order of variables
You are right of course. I wonder how much difference it could make?
Stew
User avatar
JeeK
Posts: 67
Joined: Fri Aug 16, 2013 10:45 am
Location: Vienna, Austria
Contact:

Re: Request: Small BASIC programs...

Post by JeeK »

sorchard wrote:
JeeK wrote:DIM is useful, one could say elegant, to define the order of variables
You are right of course. I wonder how much difference it could make?
This would be just one of a lot more steps to optimize a BASIC program. In summary this difference is remarkable. There are several summary ups of "golden rules" around (currently no link handy) to get the most out of BASIC programs MS-based interpreters.

E.g. in a program with many variables where auto defined variables are used, a newly introduced loop variable (after most of the variable are already defined) gets a massive time penalty on its access which multiplies with the loop count...
The dragon on my side: http://klasek.at/hc/dragon/
jedie
Posts: 655
Joined: Wed Aug 14, 2013 12:23 pm
Location: germany
Contact:

Re: Request: Small BASIC programs...

Post by jedie »

JeeK wrote:This would be just one of a lot more steps to optimize a BASIC program. In summary this difference is remarkable. There are several summary ups of "golden rules" around (currently no link handy) to get the most out of BASIC programs MS-based interpreters.
That would be interesting.

Maybe start a new page in out Wiki?
... too many ideas and too little time ... Related stuff written in Python:
Dragon 32 emulator / PyDC - Python Dragon 32 converter: https://github.com/jedie/DragonPy
DWLOAD server / Dragon-Lib and other stuff: https://github.com/6809
Post Reply