Login
Back to forumReply to this topicGo to last reply

Posted By

Dunric
on 2009-02-02
10:36:12
 Need help with telephone program

My cousin wrote a small telephone management program in BASIC a long time ago. It doesn't work as it should. I wanted to ask someone for help with debugging it. Here is the disk file, works under Vice commodore emulator:

http://www.geocities.com/dunric/ryandisk.zip

Load up the directory with LOAD"$",8 and search for the program "telephone".

Load that up and look at the code. Please see if you can debug it so that it works.
It is supposed to keep track of up to 8 telephone numbers, and the name of the person, too. But it doesn't do that.

Send me an email at: dunric@yahoo.com

Thanks!

Paul

Posted By

Rachy
on 2009-02-04
12:42:15
 Re: Need help with telephone program

You do know that it is a Commodore 64 program, right?

Posted By

Dunric
on 2009-02-07
09:13:29
 Re: Need help with telephone program

I am trying to debug a telephone program my cousin wrote in the late-1980s. Here is the source code:

1 DIM RI$(50),RT$(50)
5 OPEN15,8,15,"I"
10 F$="0:PHONES"
50 PRINT"[CLR]"
100 POKE53280,0:POKE 53281,0
110 PRINTTAB(11);"[RVS ON][RED] TELEPHONE NUMBERS "
120 PRINT"[RVS ON][PURPLE][DOWN] NAME NUMBER "
130 PRINT"[BLUE]#1":PRINT"#2":PRINT"#3":PRINT"#4":PRINT"#5":PRINT"#6":PRINT"#7"
150 INPUT"[WHITE][4 DOWN][7 RIGHT]PRESS ANY KEY TO CONTINUE";R$
160 PRINT"[RVS ON][WHITE][CLR][2 DOWN] SAVE NEW # [6 RIGHT]1"
165 PRINT"[RVS ON][RED][2 DOWN] DIRECTORY [6 RIGHT]2"
170 PRINT"[RVS ON][CYAN][2 DOWN] GET RID OF A # [6 RIGHT]3"
175 INPUT"[RVS ON][PURPLE] MAKE A SELECTION ";RU$
180 IFRU$="1"THEN210
190 IFRU$="2"THEN270
200 IFRU$="3"THEN330
210 INPUT"[BLUE] ENTER NAME";RI$
220 PRINT:INPUT"[WHITE] ENTER NUMBER";RT$
221 PRINT"[CLR]":OPEN1,8,3,F$+",S,R":I=1
222 PRINTTAB(11);"[RVS ON][RED] TELEPHONE NUMBERS "
223 PRINT"[RVS ON][PURPLE][DOWN] NAME NUMBER "
224 PRINT"[BLUE]#1":PRINT"#2":PRINT"#3":PRINT"#4":PRINT"#5":PRINT"#6":PRINT"#7"
225 PRINT"[HOME][3 DOWN]"
226 FORA=1TOI
227 INPUT#1,RI$(I):INPUT#1,RT$(I)
228 PRINTTAB(5)RI$(I)TAB(28)RT$(I)
229 IFRI$=CHR$(160)THENGOTO231
230 I=I+1:IFST=0THEN227
231 CLOSE1
232 PRINT"[WHITE]"TAB(5)RI$TAB(28)RT$:OPEN2,8,2,F$+",S,W":OPEN1,8,3,"PHONES,A"
240 PRINT#1,RI$:PRINT#1,RT$
250 CLOSE1:CLOSE2
260 GOTO150
270 PRINT"[CLR]":OPEN1,8,3,F$+",S,R":I=1
271 PRINTTAB(11);"[RVS ON][RED] TELEPHONE NUMBERS "
272 PRINT"[RVS ON][PURPLE][DOWN] NAME NUMBER "
273 PRINT"[BLUE]#1":PRINT"#2":PRINT"#3":PRINT"#4":PRINT"#5":PRINT"#6":PRINT"#7"
275 PRINT"[HOME][3 DOWN]"
280 FORA=1TOI
290 INPUT#1,RI$(I):INPUT#1,RT$(I)
300 PRINTTAB(5)RI$(I)TAB(28)RT$(I)
310 IFRI$=CHR$(160)THENGOTO150
320 I=I+1:IFST=0THEN290
325 CLOSE1:GOTO150
330 PRINT:INPUT"[WHITE]ARE YOU SURE";RU$
331 IFRU$="Y"THEN340
332 IFRU$="N"THEN150
340 PRINT#15,"S0:PHONES,S,W":CLOSE15
370 GOTO 150

You can grab the disk image where telephone resides here:

http://www.geocities.com/dunric/ryandisk.zip

Any ideas as to why this doesn't work? It is supposed to store up to 7 telephone numbers, along with names. But it just keeps spinning the disk drive without doing anything.

Paul

Posted By

Csio
on 2009-02-07
14:09:08
 Re: Need help with telephone program

try to change the 100st line to this!
100 poke65301,41:poke65305,41

Posted By

Csabo
on 2009-02-07
17:08:33
 Re: Need help with telephone program

Hey Paul,

First of all, this program is very poorly written, there are multiple problems with it, both technical and design problems. It's not worthy of our time. You also haven't said anything about whether you've already tried to debug it and if so, where you got stuck. You must realize that your "standing" on this forum is not very high, so it's really too much to ask from basically random people - why should we work on fixing this problem for you? The fact that you don't seem to realize this must be due to your illness, that's the only reason I'm giving you credit.

Nevertheless, here are some of the issues.

1) Line 100 is the telltale sign of a C64 program as others have pointed it out. The rest is standard basic so it'll run fine on the Plus/4. If the white color wasn't used (but unfortunately it was), it would be perfect. The question as to how to detect if we are running on a C64 or a Plus/4 is actually an interesting one though. That address is free RAM on the Plus/4, but poking there on the C16 will kill the BASIC program.

On the C64, peeking back the poked value will return 240, as the upper four bits are unused and will always be set to 1. So adding this line:

105 IF PEEK(53280)=0 THEN POKE 65301,0 : POKE 65305,0

makes it run fine on both machines. (We want to avoid the COLOR command as the token for that would not be recognized by the C64.) Moving on.

2) Lines 110-130 are useless and should be deleted.

3) Bug: if the user chooses anything besides 1, 2 or 3, it's still treated as "1". You need to add

205 GOTO 175

to fix this. This still leaves the user no option to exit the program.

4) The actual problem is with saving the data. Lines 221-231 should be deleted, that is duplicated "direction" functionality that's not needed for saving a new number. Line 232 should be changed to

232 OPEN 1, 8, 3, F$+",S,W"

The original has ",A", but that's invalid. I'm assuming the author was thinking "Append"? Also line 250 changes to only closing channel 1 (delete the CLOSE 2 part).

5) The third menu item's description should change to "GET RID OF ALL #S" as it appears to be deleting the data file. You should use this before entering new data, or just delete the original data file, I don't think the one on the disk is in the proper format.

Making the above changes will cause the program to function better, but it's still not very good. There's nothing in there to try and make sure only 7 numbers can be entered, etc. Whew, there's goes 30 minutes of my life that I will never get back. Now, let us never speak of this again.

Posted By

Dunric
on 2009-02-07
17:28:41
 Re: Need help with telephone program

Thanks for the reply. I think I've got it working now. Thanks.

Paul

Posted By

gerliczer
on 2009-02-08
08:54:42
 Re: Need help with telephone program

Zero checking 53280 ($D020) is not a reliable way to determine if the program runs on a C64 or Plus/4. Large programs or BASIC programs that use a lot of variables may overwrite that RAM area in a Plus/4. Without initializing (reset) it should be considered to be in indetermined state.
It would be better to check something like reset vector ($FFFC/&FFFD) or IRQ vector ($FFFE/$FFFF) or KERNAL jump table (from $FF81) or KERNAL vector table data or BASIC vectors around $300 or maybe the processor port data direction register ($00).
Actually, even these methods could be seen as unreliable because they don't consider possible system expansions.

Posted By

Csabo
on 2009-02-08
10:06:27
 Re: Need help with telephone program

You are right of course, but from your first statement it's clear that you haven't looked at his program. It does set $D020 to zero in line 100. Adding line 105 above was a quick and dirty way of getting it to work for this particular program (I also wanted to minimize the changes so I don't have to republish the entire listing).

The most reliable check IMHO would still be a TED or SID register that is "free" on the other machine. The FF15 would be fine as well as the highest bit is also always one. I tried it and it seems to work fine:

0 POKE 65301, 0 : IF PEEK ( 65301 ) = 128 THEN PRINT "C16/PLUS4" : ELSE PRINT "C64"

Posted By

gerliczer
on 2009-02-08
10:35:34
 Re: Need help with telephone program

Sorry! I really didn't check the program. In this case your solution is fine (line 105) but generally in programs that are intended to be multi-platform doing anything machine specific before checking the runtime environment is a straight road to "unexplainable" errors. Checking system specific registers is a great solution but as it writes into "random" memory locations I still don't like it. Reading unconnected memory spaces and checking for different read values seems to be safer for me. Or maybe one should try to read timer or raster registers.

Posted By

gerliczer
on 2009-02-08
11:04:43
 Re: Need help with telephone program

Proof of concept code:

10 I=PEEK(64912):REM UNCONNECTED SPACE $FD90
20 FORJ=0TO200
30 IFI<>PEEK(64912)THENPRINT"264":END
40 NEXT:PRINT"NON 264"

This should also work with $ff00 - timer1 low byte.

Posted By

Dunric
on 2009-02-19
12:21:38
 Re: Need help with telephone program

That sounds like it could work. But why does the drive keep spinning?

Paul

Posted By

Csabo
on 2009-02-19
20:48:27
 Re: Need help with telephone program

I thought I explained it pretty clearly. The drive keeps spinning because the program has a bug. Take a look at item 4) in my previous post. If you apply all the fixes listed in that post, your program will work properly and the drive won't keep spinning.



Back to topReply to this topic


Copyright © Plus/4 World Team, 2001-2024. Support Plus/4 World on Patreon