Tagged: Plus/4 Toggle Comment Threads | Keyboard Shortcuts

  • Jay Versluis 9:35 am on May 8, 2018 Permalink | Reply
    Tags: , , Plus/4   

    Categories: Commodore ( 41 ), Screencast ( 87 )   

    How to write a text input routine in Commodore BASIC 

    In this screencast I’ll show you how to write your own INPUT routine in Commodore BASIC. This comes in handy when you want to reject certain keys from being used when asking users for keyboard input. In my example I’m going to allow all alpha characters (A-Z), as well as SPACE, RETURN and the DELETE key.

    Here’s the code:





     
  • Jay Versluis 3:42 pm on April 17, 2018 Permalink | Reply
    Tags: , , , Plus/4   

    Categories: Commodore ( 41 )   

    Programmatic Loops in Commodore BASIC 

    In this screencast I’ll demonstrate how to use programmatic loops in Commodore BASIC.

    I’ll show you how to use the FOR/NEXT loop (available in all versions of Commodore BASIC), as well as the DO/WHILE loops (available on the Plus/4 and C128).

    Enjoy!





     
  • Jay Versluis 3:29 pm on April 16, 2018 Permalink | Reply
    Tags: , , , Plus/4   

    Categories: Commodore ( 41 )   

    Flow Control in Commodore BASIC 

    In this screencast I’ll explain the concept of Flow Control in Commodore BASIC. It’s kind of a video update of a post I did a while ago.

    In essence, it means that we can tell the programme to take a different route in the code depending on a condition that’s met. We’ll explore the IF/THEN and ON… GOTO/GOSUB statements (available on all versions of Commodore BASIC), as well as the expanded IF/THEN/ELSE version (available on the C128 and Plus/4 only).

    In addition, I’ll also show you how to use the BEGIN and BEND clauses that were introduced with the C128.





     
  • Jay Versluis 12:10 am on April 2, 2018 Permalink | Reply
    Tags: , , , Plus/4   

    Categories: Commodore ( 41 )   

    How to print Numbers as Columns in Commodore BASIC 

    In this video I’m demonstrating how to print numbers in evenly spaced columns in Commodore BASIC.

    On the C128 and the Plus/4 we can use a nifty little function called PRINT USING for this, with which we can format the output of any printed text or variable.

    On the C64 and VIC-20 that function doesn’t exist, so we’ll have to convert a numeric value into a string (using the STR$ function), and then determine how long our string is. Following that we’ll have to manually pad our string value with as many spaces as are required. (More …)





     
  • Jay Versluis 10:17 am on April 1, 2018 Permalink | Reply
    Tags: , , Plus/4,   

    Categories: Commodore ( 41 )   

    Sorting an Array on the Commodore 64 

    In this video I’ll demonstrate how to sort a numeric array on the Commodore 64. The same principle works for string arrays, and of course on all other Commodore BASIC computers.

    The technique I’m using here is called Bubble Sort: in effect we’re comparing the first two items in the array, and if the left one is larger than the right one, the values are swapped around. This loop continues until all items in the array have been compared and sorted (hence the smallest items “bubble” to the front of the array, much like the smallest bubbles in a soda float to the top first).

    Here’s the full code I’m building, including the lottery portion. The Bubble Sort code starts in line 200.

    10 x=rnd(-ti)
    20 for i=1 to 6
    30 rn=int(rnd(1)*49)+1
    40 for j=1 to i
    50 if n(j)=rn then 30
    60 next j
    70 n(i)=rn
    80 next i
    100 print:gosub 200
    110 for i=1 to 6
    120 print n(i);
    130 next
    140 print
    199 goto 20
    200 rem bubble sort
    210 for i=5 to 1 step -1
    220 for j=1 to i
    230 x=n(j):y=n(j+1)
    240 if x>y then n(j)=y:n(j+1)=x
    250 next:next
    299 return

    I’ve explained how to build the lottery generator in this code here: https://wpguru.co.uk/2018/03/how-to-generate-lottery-numbers-on-the-commodore-64/

    Happy retro hacking!





     
  • Jay Versluis 12:39 pm on March 31, 2018 Permalink | Reply
    Tags: , , Plus/4   

    Categories: Commodore ( 41 ), Screencast ( 87 )   

    How to generate Lottery Numbers on the Commodore 64 

    In this video I’ll demonstrate how to draw random lottery numbers on a Commodore 64. The secret sauce here is not only the RND function to generate random numbers, but also two loops inside each other that prevent the same number from coming up more than once.

    Here’s the lottery generator code:

    10 x=rnd(-ti)
    20 for i=1 to 6
    30 rn=int(rnd(1)*49)+1
    40 for j=1 to i
    50 if n(j)=rn then 30
    60 next j
    70 n(i)=rn
    80 next i
    100 print
    110 for i=1 to 6
    120 print n(i);
    130 next
    140 print
    199 end

    To adapt this listing to match your local lottery, change line 20 to the amount of numbers to be drawn from your pool (6 in my example), and change the value in line 30 to match the size of your pool (49 in my example).

    Any questions, please let me know below.

    Happy retro hacking!





     
  • Jay Versluis 11:43 am on March 14, 2018 Permalink | Reply
    Tags: , , Plus/4, VIC-20   

    Categories: Commodore ( 41 )   

    String Operations on Commodore Computers 

    Commodore BASIC has some interesting and simple string functions built in. Three of them are self explanatory: LEN, LEFT$ and RIGHT$. But others, like the mysterious MID$ and INSTR functions, are a little tricker, and I can never remember how they works.

    So here’s a quick recap on how they all work.

    LEN (A$)

    Returns the length of any given string. For example,

    a$=”the cake is a lie”

    print len (a$)
    17

    returns 17, which is the number of characters in our string.

    LEFT$ (A$,X)

    The LEFT$ function takes the x left characters from a given string. Here’s an example:

    a$="one-two-three"
    
    print left$(a$,3)
    one

    We get “one”, because those are the 3 leftmost characters in our string a$.

    RIGHT$ (A$,X)

    Likewise, RIGHT$ takes the x right characters from any given string:

    a$="one-two-three"
    
    print right$(a$,5)
    three

    Here we get “three”, because those are the 5 right characters of a$.

    MID$ (A$,X,Y)

    MID$ is a little more complex. It takes x characters from a given string, starting at position y. Let’s look at our earlier example again:

    a$="one-two-three"
    
    print mid$(a$,5,3)
    two

    We get “two”, because those are the 3 characters, starting at position 5. The first position in all these string operations counts as one rather than zero.

    But did you know that MID$ can also be used to assign and replace different characters in a string? Consider this:

    mid$(a$,5,3)="ten"
    
    print a$
    one-ten-three

    Now we’ve replaced the 3 characters in our string with another string, starting at position 5.

    I had no idea it cold do that! All these string operations work in all variations of the Commodore BASIC, except for the MID$ assignment which only works on the Plus/4 and the C128.

     

    INSTR (A$, B$)

    On the Plus/4 and C128, we can even check if one string is contained in another and at which position this occurs. Consider this:

    a$="the cake is a lie"
    
    b$="cake"
    
    print instr(a$,b$)
     5

    In our example, INSTR returns 5 because “cake” has been found at position 5 of “the cake is a lie”.

    We can also specify a position from which the search shall be started like this:

    print instr(a$,b$,6)
     0

    Now INSTR returns 0 because “cake” has not been found beyond position 6 of our input string.





     
  • Jay Versluis 11:04 pm on March 13, 2018 Permalink | Reply
    Tags: Plus/4   

    Categories: Commodore ( 41 )   

    How to play sounds and music on the Commodore Plus/4 

    The Plus/4 has a total of two voices thanks to its integrated TED chip, which is also responsible for rendering text and graphics on screen. The first voice can play square waves, while the second one can generate either square wave sounds or white noise.

    Let’s see how we can make him play a tune.

    We can use some BASIC keywords to make the Plus/4 be all musical. First we need to turn up the volume by using the VOL command. We can set this to anything between 0 and 8.

    VOL 8

    Next we can use the SOUND command to make each channel play a note, like so:

    SOUND 1,400,60

    This will play a one-second long note on channel 1.

    (More …)





     
  • Jay Versluis 5:16 pm on January 13, 2016 Permalink | Reply
    Tags: , , Plus/4   

    Categories: Commodore ( 41 )   

    How to use direct block access commands in Commodore DOS 

    Commodore-Logo-PaddedWe can access each sector’s raw data on Commodore disk drives with direct block access commands. Supported drives include the 1541, 1571, the VICE emulator as well as the SD2IEC card reader (for the most part).

    Each single sided floppy contains 35 sectors, while a double sided 1571 formatted disk contains 70 sectors. Each track contains between 17 and 21 sectors depending on how far inside or outside they are. Each sector contains 255 bytes we can read or write.

    Sectors are the same as blocks: only the directory refers to them as “blocks” and shows us how many we have available.

    We’ll need to open two channels to our disk drives: a command channel and a data channel. Here’s how to do it:
    (More …)





     
  • Jay Versluis 9:33 am on June 15, 2015 Permalink | Reply
    Tags: , , Plus/4   

    Categories: Commodore ( 41 )   

    How to split a long string into separate words in Commodore BASIC 

    Here’s a quick word splitter routine for CBM BASIC. It takes phrase and “explodes” all words into an array, removing spaces. Feel free to adopt it for your own needs.

    10 rem word splitter
    20 rem splits a long phrase into words at a space
    30 input "tell me something";a$
    40 rem clear current array of words
    50 for i=0 to 10: wd$(i)="": next: wd=1
    60 rem detect spaces
    70 for i=1 to len(a$)
    80 wd$(0)=mid$(a$,i,1)
    90 if wd$(0)=" " then wd=wd+1: next
    100 wd$(wd)=wd$(wd)+wd$(0): next
    110 print
    120 rem print all words
    130 for i=1 to 10
    140 if wd$(i)="" then 160
    150 print wd$(i)
    160 next
    

    Line 50 clears an array of 10 words called WD$(n). We also setup a word counter called WD. So in this example we can only detect a maximum of ten words. If you need more, you must DIM the array first.

    Lines 70 loops through all characters in our phrase. We make use of the first element in our array WD$(0) to store each single character. If it’s a space, we’ll increase the word counter and move on to the next character. If it’s not (line 80), then we’ll add this character to the current word which is stored in WD$(WD).

    The rest of the code simply prints each word on a new line to see our handy work.





     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel