Re: Is is possible for INPUT to have a default value?
Posted: Wed Apr 12, 2023 2:50 pm
If you write your program in Basic, and run out of memory, then enabling RAM in 8-16k won't help. Basic does not use RAM in 8-16k.
Discussion forums for users of the Sinclair 8-bit range of computers - ZX80, ZX81, ZX Spectrum, Z88, clones...
https://sinclairzxworld.com/
If you write your program in Basic, and run out of memory, then enabling RAM in 8-16k won't help. Basic does not use RAM in 8-16k.
Code: Select all
10 LET A$=“B=10*2”
20 PRINT AT 10,0;A$;“ ”;
30 LET I$=INKEY$
40 IF I$=“” THEN GOTO 30
50 IF I$<=“Z” THEN LET A$=A$+I$
60 LET I=CODE I$
70 IF I=119 THEN IF LEN A$>0 THEN LET A$=A$( TO LEN A$-1)
80 IF I<>118 THEN GOTO 20
Do you use just letters/numbers and math symbols? I found an elegant way to display and edit a line in BASIC. I use a single string and track cursor position so you can move and delete/add within the edit. Works pretty well--but no keywords. Does allow inverted letters using graphics mode. I store the string being edited in a single variable and just print using array slicing. Not as fast as INPUT, but not horrible to edit either and not a ton of code.alowe wrote: ↑Wed Apr 12, 2023 2:24 pm Yes, I already did this but it was so slow even after optimising it as far as possible. I managed to write a really elegant solution but the problem was that printing the output after each keypress took 90% of the execution time. It made the program unusable so I tried it with INPUT instead and that fixed the problem. I suppose I could figure it out all again (deleted all the notes, duh). It took about a week to perfect it as I work 16 hours a day and barely get the time. Maybe poking the D_FILE directly would speed things up.
Oh, goodness. No fun. Yeah, don't change hardware wettings. I usually save between runs just in case. I have PTSD from typing in programs in the 80's and them not saving/crashing/disappearing. Although I will say the program is usually better the second time around. LOL.alowe wrote: ↑Wed Apr 12, 2023 2:24 pm Just spent 6 hours and 30 minutes retyping the program today after discovering that the printer had somehow become disconnected . On EightyOne when you connect the printer it wipes your program. Added a couple more changes and ran out of memory with 48k. So now have to retype the whole program again after enabling RAM in 8k-16k and figuring out how to use that again.
Code: Select all
10 REM **DEF-INPUT**SLR/2023**
20 REM **SET A DEFAULT VALUE**
30 GOSUB 750
40 PRINT "WHAT IS YOUR FAVORITE COLOR?"
50 GOSUB 1000
60 PRINT AT 1,0;"YOU SAID: ";D$
70 PAUSE 4E4
80 CLS
90 RUN
500 SAVE "DEFI#b3"
510 RUN
750 REM **RANDOM DEFAULT COLOR**
760 RAND
770 LET L=INT (RND*10)
780 LET D$="BLUE"
790 IF L=1 THEN LET D$="RED"
800 IF L=2 THEN LET D$="GREEN"
810 IF L=3 THEN LET D$="YELLOW"
820 IF L=4 THEN LET D$="PINK"
830 IF L=5 THEN LET D$="ORANGE"
840 IF L=6 THEN LET D$="BLACK"
850 IF L=7 THEN LET D$="BROWN"
860 IF L=8 THEN LET D$="WHITE"
870 IF L=9 THEN LET D$="PURPLE"
880 RETURN
1000 REM **STRING INPUT**
1010 LET POS=LEN D$
1015 LET G=0
1020 PRINT AT 21,0;D$( TO POS);"#b1#ac"(G+1);D$(POS+1 TO );" "
1025 REM IF POS<LEN D$ THEN PRINT D$(POS+1 TO )
1030 LET K$=INKEY$
1040 IF K$="" THEN GOTO 1020
1045 LET K=CODE K$
1050 IF K=119 THEN GOSUB 1200
1060 IF K=114 THEN LET POS=POS-(POS>0)
1070 IF K=115 THEN LET POS=POS+(POS<LEN D$)
1075 IF K=116 THEN LET G=NOT G
1080 IF K>11 AND K<64 THEN GOSUB 1230
1090 IF K<>118 THEN GOTO 1020
1100 IF G=0 THEN GOTO 1130
1110 LET G=0
1120 GOTO 1030
1130 PRINT AT 21,0;" ";
1140 RETURN
1200 IF POS<1 THEN RETURN
1205 LET D$=D$( TO POS-1)+D$(POS+1 TO )
1210 LET POS=POS-1
1220 RETURN
1230 IF G=1 THEN LET K=K+128
1240 LET D$=D$( TO POS)+CHR$ K+D$(POS+1 TO )
1250 LET POS=POS+1
1260 RETURN
Actually, I rewrote parts of the program to use that RAM, so it is possible, if a bit tedious. But then figured out a better solution so that the extra memory wasn't necessary.
Oh, I don't change the settings. The emulator does that for me randomly.SafePit wrote: ↑Fri Apr 14, 2023 3:00 amYeah, don't change hardware wettings. I usually save between runs just in case. I have PTSD from typing in programs in the 80's and them not saving/crashing/disappearing. Although I will say the program is usually better the second time around. LOL.alowe wrote: ↑Wed Apr 12, 2023 2:24 pm Yes, I already did this but it was so slow even after optimising it as far as possible. I managed to write a really elegant solution but the problem was that printing the output after each keypress took 90% of the execution time. It made the program unusable so I tried it with INPUT instead and that fixed the problem. I suppose I could figure it out all again (deleted all the notes, duh). It took about a week to perfect it as I work 16 hours a day and barely get the time. Maybe poking the D_FILE directly would speed things up.
Nice clean code.1024MAK wrote: ↑Wed Apr 12, 2023 4:08 pm This is a very simple line editor. It does not have a cursor and the only editing keys are RUBOUT and NEWLINE.
For it to run quickly, it needs to be at the very start of the BASIC program. So replace line 10 with 10 GOTO 100, add 90 RETURN, then call it using GOSUB 20. And put your program after it starting from line 100 onwards.
7B3313DA-A9EE-4673-B361-C96A47243272.jpegCode: Select all
10 LET A$=“B=10*2” 20 PRINT AT 10,0;A$;“ ”; 30 LET I$=INKEY$ 40 IF I$=“” THEN GOTO 30 50 IF I$<=“Z” THEN LET A$=A$+I$ 60 LET I=CODE I$ 70 IF I=119 THEN IF LEN A$>0 THEN LET A$=A$( TO LEN A$-1) 80 IF I<>118 THEN GOTO 20
Mark
Code: Select all
5 LET S$="@D316399*256+@D316398-1"
10 LET A$="B=10*2"
20 PRINT AT 10,0;A$;" ";
25 POKE VAL S$,195
30 LET I=CODE INKEY$
40 IF NOT I THEN GOTO 30
50 IF I<64 THEN LET A$=A$+CHR$ I
60 IF I=119 THEN IF LEN A$>0 THEN LET A$=A$( TO LEN A$-1)
70 POKE VAL S$,(I AND I<64)+128 AND I<118
80 IF I<>118 THEN GOTO 20
Code: Select all
5 LET S$="@D316399*256+@D316398-1"
10 LET A$="B=10*2"
20 PRINT AT 10,0;A$;" ";
25 POKE VAL S$,195
30 LET I=CODE INKEY$
40 IF NOT I THEN GOTO 30
50 IF I<64 THEN LET A$=A$+CHR$ I
60 IF I=119 THEN IF LEN A$>0 THEN LET A$=A$( TO LEN A$-1)
70 POKE VAL S$,(I AND I<64)+128 AND I<118
80 IF I<>118 THEN GOTO 20
100 FOR A=1 TO LEN A$-1
110 GOSUB 1000
120 IF F THEN LET A$=A$(1 TO A-1)+F$+A$(A+(2 AND F=66)+(3 AND F=199)+(3 AND F=200) TO)
130 IF F THEN GOTO 100
140 NEXT A
150 PRINT AT 12,0;A$; AT 14,0;"=";VAL A$(3 TO)
160 STOP
1000 LET F=0
1001 LET F$=""
1002 IF A$(A TO A+1)="PI" THEN LET F=66
1003 IF LEN A$<A+2 THEN GOTO 1006
1004 IF A$(A TO A+2)="COS" THEN LET F=200
1005 IF A$(A TO A+2)="SIN" THEN LET F=199
1006 IF F THEN LET F$=CHR$ F
1007 RETURN