• Messing around, creating a disk editor.

    From KP KP@3:770/3 to All on Tue Jun 6 16:55:34 2023
    I need some scrutinizing on my crappy coding expertise. Haven't made a program in years.. Could be junk or have no idea what I am doing. Gibberish? Lol.


    10 PRINT "***** C64 DISK EDITOR *****"
    20 PRINT
    30 INPUT "Enter the name of the disk file: "; FILENAME$
    40 PRINT
    50 OPEN 1, 8, 15, FILENAME$
    60 PRINT "1. Display sector"
    70 PRINT "2. Edit sector"
    80 PRINT "3. Save changes"
    90 PRINT "4. Quit"
    100 PRINT
    110 INPUT "Enter your choice: "; CHOICE
    120 PRINT

    130 IF CHOICE = 1 THEN
    140 INPUT "Enter the sector number to display: "; SECTOR
    150 PRINT
    160 SYS 64738
    170 PRINT
    180 GOTO 50
    190 ELSEIF CHOICE = 2 THEN
    200 INPUT "Enter the sector number to edit: "; SECTOR
    210 PRINT
    220 PRINT "WARNING: You are about to modify the sector contents."
    230 PRINT "Make sure you know what you're doing!"
    240 PRINT
    250 INPUT "Press any key to continue, or Q to cancel: "; KEY$
    260 IF KEY$ = "Q" OR KEY$ = "q" THEN GOTO 50
    270 PRINT
    280 SYS 64738
    290 PRINT
    300 GOTO 50
    310 ELSEIF CHOICE = 3 THEN
    320 PRINT "Saving changes..."
    330 PRINT
    340 CLOSE 1
    350 OPEN 1, 8, 2, FILENAME$
    360 CLOSE 1
    370 PRINT "Changes saved successfully!"
    380 PRINT
    390 GOTO 50
    400 ELSEIF CHOICE = 4 THEN
    410 CLOSE 1
    420 END
    430 ELSE
    440 PRINT "Invalid choice. Please try again."
    450 PRINT
    460 GOTO 50
    470 END IF

    480 GOTO 50

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Andreas Kohlbach@3:770/3 to KP KP on Tue Jun 6 21:52:28 2023
    On Tue, 6 Jun 2023 16:55:34 -0700 (PDT), KP KP wrote:

    I need some scrutinizing on my crappy coding expertise. Haven't made a program in years.. Could be junk or have no idea what I am
    doing. Gibberish? Lol.


    10 PRINT "***** C64 DISK EDITOR *****"
    20 PRINT
    30 INPUT "Enter the name of the disk file: "; FILENAME$
    40 PRINT
    50 OPEN 1, 8, 15, FILENAME$
    60 PRINT "1. Display sector"
    70 PRINT "2. Edit sector"
    80 PRINT "3. Save changes"
    90 PRINT "4. Quit"
    100 PRINT
    110 INPUT "Enter your choice: "; CHOICE
    120 PRINT

    130 IF CHOICE = 1 THEN
    140 INPUT "Enter the sector number to display: "; SECTOR
    150 PRINT
    160 SYS 64738

    That'll do a System-Reset, and the rest is ignored. Worse, you leaving a
    data channel open (line 50).

    170 PRINT
    180 GOTO 50
    190 ELSEIF CHOICE = 2 THEN

    Commodore BASIC (at least not of the C64) doesn't know "ELSE". May be of
    the C128? But I never used it.
    --
    Andreas

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From K-Guide@1:130/230 to All on Wed Jun 7 11:03:00 2023
    On Tue 6-Jun-2023 4:55p, Kp Kp@3:770/3.0 wrote:
    I need some scrutinizing on my crappy coding expertise. Haven't made a program in years.. Could be junk or have no idea what I am doing. Gibberish? Lol.

    10 PRINT "***** C64 DISK EDITOR *****"
    20 PRINT
    30 INPUT "Enter the name of the disk file: "; FILENAME$
    40 PRINT

    First and foremost, I am not an expert in C64/128 programming, I am just drawing from the cob-web infested parts of my brain here... So here are my thoughts.

    The C64 and 128 have dual character sets (UPPER/Gfx vs (Upper/Lower) and based on the above it appears your in Upper/lower. When in this mode commands like PRINT, INPUT, OPEN, AND Varables all need to be in lowercase.

    Also filename$ is too long. Varables on C64 & 128 can be up to two characters + a designator. They must start with a letter then you can have a letter, number, or designator. Haveing the $ at the end is fine as it tells the computer its a string. Use % for integers if you want to pick up a cycle or two. There are also designatores for single or double percision floating varables too.

    130 IF CHOICE = 1 THEN
    140 INPUT "Enter the sector number to display: "; SECTOR
    150 PRINT
    160 SYS 64738
    170 PRINT
    180 GOTO 50
    190 ELSEIF CHOICE = 2 THEN
    200 INPUT "Enter the sector number to edit: "; SECTOR

    The C64 nor C128 support this type of statement structure. The Syntex for IF statements are:

    IF <expression> THEN <statements> [:ELSE <statements>]

    They all must be contained on the same line!

    Once the THEN <statements> are run OR the ELSE <statements> are run the program will drop to the following line of code. This is why C64 & C128 has alot of spegitty code in their basic files, but with the use of GOSUB and GOTO carefully you can limit that to a point. If you make your program where its more of a Hub and Spoke design, it will be easier to follow then all kinds GOTO statement to jump over blockes of code. Something like this psudocode

    Main
    Print Banner
    Get Filename and store in fn$
    M1: GOSUB Display Menu (put user input into m)
    ONGOSUB m C1, C2, C3, etc...
    GOTO A:

    C1: Statements for Menu #1
    return
    01: Any routinmes for C1
    02: etc...

    C2: Statements for Menu #2
    03: Any routines for C2
    04: etc...

    This is much easier to follow. Like everything there is a balance here, so if you can handle it with just 3-5 lines of code in a block then no need for a routine. When it gets beyond that is when I start thinking about making a routine out of it.

    Also your line numbers can be from 0 - 65535 so give each routine a wide number range. Like MAIN = 100-500, Display Menu = 600-1000, etc... This way when you need to change things in the rotines your not suck. Once its finished use a renumber utility to restructure them with lower numbers and give youself a 100 line gap between sections. Just how I like to do things.

    Also I would move the OPEN statement in line 50 into the routines that need it. This way its only opened and closed when needed. I know its a bit more code, but make for easier to follow code.

    This along with the other posters comments you should have a good start. I would suggest you snag a copy of the C128 System Guide or the C64 Systems Guide they do a great job of laying out the syntex and rules plus the back is setup more as a referance for all the commands, so its easy to look stuff up. It should get you up to speed, or dare I say down to C64/128 Basic.

    Hope this helps....

    [+] K-Guide
    --- CNet/5
    * Origin: Future World II - fw2.cnetbbs.net:6800 (1:130/230)
  • From Myles Skinner@3:770/3 to KP KP on Thu Jun 8 16:10:24 2023
    On Tuesday, 6 June 2023 at 19:55:35 UTC-4, KP KP wrote:
    I need some scrutinizing on my crappy coding expertise. Haven't made a program in years.. Could be junk or have no idea what I am doing. Gibberish? Lol.

    Uh, so I have to ask...was this your own work? Because it looks suspiciously like some of the almost-but-not-quite-BASIC generated by ChatGPT that I've had the "pleasure" of critiquing lately: quite aside from the invalid keywords, I see the mixed-case
    PRINT strings, unreachable lines, opening and then closing a file for no reason, gratuitous calls to the system reset all as red flags...HIBT?

    ms

    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)