Home
JAQForum Ver 24.01
Log In or Join  
Active Topics
Local Time 09:01 01 Aug 2025 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : PicoMiteVGA: some Entertainer-ment and some bugs (?)

     Page 1 of 3    
Author Message
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 12:41pm 08 Jun 2022
Copy link to clipboard 
Print this post

Hi folks,

Here's something musical that I'm working on.

It should work on MMB4W, CMM2 and PicoMite(VGA).

I am however having 2 issues specifically on the PicoMite:

   1. The usual OPTION BREAK 4 : ON KEY 3 trick doesn't seem to work to allow me to intercept the break key - so I can call PLAY STOP.

   2. If I try to play on more than 2 channels on the PicoMite then I get white noise playing on the additional channels - possibly this is a H/W issue; I'm using @Mixtel90's PicoGAME - prototype PCB.

Best wishes,

Tom

Option Base 0
Option Default None
Option Explicit On

' On Key 3 doesn't seem to work on PicoMite.
' Option Break 4
' On Key 3, on_break

If InStr(MM.Device$, "PicoMite") Then Save "entertainer.bas"

Dim channel1%(256), channel2%(256), channel3%(256), channel4%(256)
Dim err$

Dim s$
Do
 Line Input "How many channels (1-4)? ", s$
 Print
 Select Case Val(s$)
   Case 1 To 4 : Exit Do
 End Select
Loop
Dim num_channels% = Val(s$)

music.parse(channel1%(), "qD4,qD#4")

music.parse(channel1%(), "qE4,1C5,qE4,1C5,qE4,qC5")
music.parse(channel1%(), "2C5,q-,qC5,qD5,qD#5")
music.parse(channel1%(), "qE5,qC5,qD5,qE5,qE5,qB5,1D5")
music.parse(channel1%(), "3C5,qD4,qD#4")

music.parse(channel1%(), "qE4,1C5,qE4,1C5,qE4,qC5")
music.parse(channel1%(), "3C5,qA5,qG4")
music.parse(channel1%(), "qF#4,qA5,qC5,qE5,qE5,qD5,qC5,qA5")
music.parse(channel1%(), "3D5,qD4,qD#4")

music.parse(channel1%(), "qE4,1C5,qE4,1C5,qE4,qC5")
music.parse(channel1%(), "2C5,q-,qC5,qD5,qD#5")
music.parse(channel1%(), "qE5,qC5,qD5,qE5,qE5,qB5,1D5")
music.parse(channel1%(), "2C5,qC5,q-,qC5,qD5")

music.parse(channel1%(), "qE5,qC5,qD5,qE5,qE5,qC5,qD5,qC5")
music.parse(channel1%(), "qE5,qC5,qD5,qE5,qE5,qC5,qD5,qC5")
music.parse(channel1%(), "qE5,qC5,qD5,qE5,qE5,qB5,1D5")
music.parse(channel1%(), "2C5,qC5,qE4,qF4,qF#4")

' ---

music.parse(channel1%(), "1G4,qA5,qG4,qG4,qE4,qF4,qF#4")
music.parse(channel1%(), "1G4,qA5,qG4,qG4,qE5,qC5,qG4")
music.parse(channel1%(), "qA5,qB5,qC5,qD5,qE5,qD5,qC5,qD5")
music.parse(channel1%(), "2G4,qG4,qE4,qF4,qF#4")

music.parse(channel1%(), "1G4,qA5,qG4,qG4,qE4,qF4,qF#4")
music.parse(channel1%(), "1G4,qA5,qG4,qG4,qG4,qA5,qA#5")
music.parse(channel1%(), "1B5,q-,1B5,qA5,qF#4,qD4")
'music.parse(channel1%(), "qB5,q-,qB5,q-,qB5,qA5,qF#4,qD4")
music.parse(channel1%(), "2G4,qG4,qE4,qF4,qF#4")

music.parse(channel1%(), "1G4,qA5,qG4,qG4,qE4,qF4,qF#4")
music.parse(channel1%(), "1G4,qA5,qG4,qG4,qE5,qC5,qG4")
music.parse(channel1%(), "qA5,qB5,qC5,qD5,qE5,qD5,qC5,qD5")
music.parse(channel1%(), "2C5,qC5,qG4,qF#4,qG4")

music.parse(channel1%(), "1C5,qA5,qC5,qC5,qA5,qC5,qA5")
music.parse(channel1%(), "qG4,qC5,qE5,qG5,qG5,qE5,qC5,qG4")
music.parse(channel1%(), "1A5,1C5,qE5,1D5,qD5")
music.parse(channel1%(), "3C5")

' Placeholder code until I've transcribed the notes for the other channels.
' Play the same music on each channel offset by 1 beat.
LongString Append channel2%(), Chr$(0) + Chr$(0)
LongString Append channel3%(), Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0)
LongString Append channel4%(), Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0) + Chr$(0)
Dim i%
For i% = 0 To LLen(channel1%()) - 1
 LongString Append channel2%(), Chr$(LGetByte(channel1%(), i%))
 LongString Append channel3%(), Chr$(LGetByte(channel1%(), i%))
 LongString Append channel4%(), Chr$(LGetByte(channel1%(), i%))
Next

' Terminate each channel with 255
LongString Append channel1%(), Chr$(&hFF)
LongString Append channel2%(), Chr$(&hFF)
LongString Append channel3%(), Chr$(&hFF)
LongString Append channel4%(), Chr$(&hFF)

' Pad each channel with 255 until reach 64-bit boundary and they are all the same length.
Dim count% = Max(LLen(channel1%()), LLen(channel2%()))
count% = Max(count%, LLen(channel3%()))
count% = Max(count%, LLen(channel4%()))
Do While count% Mod 8 > 0 : Inc count% : Loop
Do While LLen(channel1%()) < count% : LongString Append channel1%(), Chr$(&hFF) : Loop
Do While LLen(channel2%()) < count% : LongString Append channel2%(), Chr$(&hFF) : Loop
Do While LLen(channel3%()) < count% : LongString Append channel3%(), Chr$(&hFF) : Loop
Do While LLen(channel4%()) < count% : LongString Append channel4%(), Chr$(&hFF) : Loop

' Combine the channels into a single music buffer.
Dim music%(1 + (count% / 2))
For i% = 0 To count% - 1
 LongString Append music%(), Chr$(LGetByte(channel1%(), i%))
 LongString Append music%(), Chr$(LGetByte(channel2%(), i%))
 LongString Append music%(), Chr$(LGetByte(channel3%(), i%))
 LongString Append music%(), Chr$(LGetByte(channel4%(), i%))
Next

' music.print_data(music%())

' Play music buffer via interrupt.
Dim music_ptr% = Peek(VarAddr music%()) + 8
SetTick 200, music.play_interrupt, 1
Do : Loop

End

Sub music.parse(buf%(), s$)
 Local s_idx% = 1
 Local ch$ = ","
 Do While ch$ = ","
   If music.parse_note%(s$, s_idx%, buf%()) <> 0 Then
     Error err$ + " : s_idx = " + Str$(s_idx%)
   EndIf
   Inc s_idx%
   ch$ = Mid$(s$, s_idx%, 1)
   Inc s_idx%
 Loop
End Sub

Sub on_break
 Play Stop
 Option Break 3
 End
End Sub

Function music.parse_note%(s$, s_idx%, buf%())
 music.parse_note% = -1
 Local ch$ = Mid$(s$, s_idx%, 1)

 ' Parse duration.
 Local duration!
 Select Case ch$
   Case "q": duration! = 0.5
   Case "1", "2", "3", "4": duration! = Val(ch$)
   Case Else
     err$ = "Syntax error: expected duration"
     Exit Function
 End Select

 Inc s_idx%
 ch$ = Mid$(s$, s_idx%, 1)

 ' Parse note.
 Local n% = 0 ' 0 = Rest, 1 = A0
 Select Case ch$
   Case "A" : n% = 1
   Case "B" : n% = 3
   Case "C" : n% = 4
   Case "D" : n% = 6
   Case "E" : n% = 8
   Case "F" : n% = 9
   Case "G" : n% = 11
   Case "-" : ' Do nothing
   Case Else
     err$ = "Syntax error: expected note"
     Exit Function
 End Select

 If n% = 0 Then
   LongString Append buf%(), Chr$(0)
   music.parse_note% = 0
   Exit Function
 EndIf

 Inc s_idx%
 ch$ = Mid$(s$, s_idx%, 1)

 ' Parse b or #.
 Local off% = 0
 Select Case ch$
   Case "b" : off% = -1
   Case "#" : off% = 1
 End Select
 If off% <> 0 Then
   Inc n%, off%
   Inc s_idx%
   ch$ = Mid$(s$, s_idx%, 1)
 EndIf

 ' Parse octave.
 If Not Instr("012345678", ch$) Then
   err$ = "Syntax error: expected octave"
   Exit Function
 EndIf
 Inc n%, 12 * Val(ch$)

 ' Write music data into buffer.
 Local i%
 For i% = 1 To 2 * duration!
   LongString Append buf%(), Chr$(n%)
 Next

 music.parse_note% = 0
End Function

Sub music.print_data(buf%())
 Local count% = 0, i%, p% = Peek(VarAddr buf%()) + 8
 Open "entertainer.inc" For Output As #1
 Print #1, "Data " Str$(LLen(buf%())) " ' Number of bytes of music data."
 For i% = 0 To LLen(buf%()) - 1 Step 8
   Print #1, Choice(count% = 0, "Data ", ", ");
   Print #1, "&h" Hex$(Peek(Integer p%), 16);
   Inc p%, 8
   Inc count%
   If count% = 4 Then Print #1 : count% = 0
 Next
 Close #1
End Sub

Sub music.play_interrupt()
 ' Play channel 1.
 Local n% = Peek(Byte music_ptr%)
 Select Case n%
   Case 0 : Play Sound 1, B, O
   Case 1 To 254 : Play Sound 1, B, S, 440 * 2^((n% - 49) / 12.0)
   Case 255 : Play Stop : End
 End Select
 Inc music_ptr%

 ' Play channel 2.
 If num_channels% > 1 Then
   n% = Peek(Byte music_ptr%)
   Select Case n%
       Case 0 : Play Sound 2, B, O
       Case 1 To 254 : Play Sound 2, B, S, 440 * 2^((n% - 49) / 12.0)
       Case 255 : Play Stop : End
   End Select
 EndIf
 Inc music_ptr%

 ' Play channel 3.
 If num_channels% > 2 Then
   n% = Peek(Byte music_ptr%)
   Select Case n%
       Case 0 : Play Sound 3, B, O
       Case 1 To 254 : Play Sound 3, B, S, 440 * 2^((n% - 49) / 12.0)
       Case 255 : Play Stop : End
   End Select
 EndIf
 Inc music_ptr%

 ' Play channel 4.
 If num_channels% > 3 Then
   n% = Peek(Byte music_ptr%)
   Select Case n%
       Case 0 : Play Sound 4, B, O
       Case 1 To 254 : Play Sound 4, B, S, 440 * 2^((n% - 49) / 12.0)
       Case 255 : Play Stop : End
   End Select
 EndIf
 Inc music_ptr%
End Sub

MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 12:48pm 08 Jun 2022
Copy link to clipboard 
Print this post

1
Option break 4
On key 3,myint
Do
Loop
Sub myint
Option break 3
End
End Sub

works as expected

2
Can't test until next week - no relevant H/W
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 01:22pm 08 Jun 2022
Copy link to clipboard 
Print this post

Something very fishy is going on:

This is my program "break_bug.bas":

Save "break_bug.bas"

Option Break 4
On Key 3,myint
Do
Loop

Sub myint
Option Break 3
End
End Sub


Now, I do the following:

> NEW
> LOAD "break_bug.bas"
> RUN
Ctrl-C doesn't work, need to use Ctrl-D
> RUN
Ctrl-C doesn't work, need to use Ctrl-D
> EDIT
F2:Run
Ctrl-C doesn't work, need to use Ctrl-D
> EDIT
Comment the first line, i.e.
' Save "break_bug.bas"

F2:Run
Ctrl-C "works" but the following error is reported:
[6] Loop
Error : Unknown command
> RUN
Ctrl-C "works" but the following error is reported:
[6] Loop

WTF ???

Best wishes,

Tom
Edited 2022-06-08 23:23 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 01:31pm 08 Jun 2022
Copy link to clipboard 
Print this post

saving a program in a program is pretty bizarre and should probably give an error but even with that in the program I can't replicate
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 01:36pm 08 Jun 2022
Copy link to clipboard 
Print this post

  matherp said  saving a program in a program is pretty bizarre and should probably give an error ...


Please don't, it's exceptionally useful on the 'mites otherwise I'm always losing work due to the EDITor not saving to the SD card.

  Quote  ... but even with that in the program I can't replicate


Very strange. Just to eliminate the obvious are you using the PicoMite or PicoMiteVGA firmware - I'm on the latter.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 01:39pm 08 Jun 2022
Copy link to clipboard 
Print this post

latter - b6 just posted
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 01:40pm 08 Jun 2022
Copy link to clipboard 
Print this post

The hardware won't make a difference. It's just the usual PWM audio on pins GP6 and GP7. After that there are just some links that replace the filter with a resistor for headphones.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 01:55pm 08 Jun 2022
Copy link to clipboard 
Print this post

Most perplexing, I have also updated to b6 and am now running this program:

On Key 97,my_int
Print "Hello"
Do : Loop
End
Sub my_int
Print "World"
End Sub


Pressing 'a' on the keyboard is not causing it to say "World".

However this program will print "World" when you press 'a':

On Key my_int
Print "Hello"
Do : Loop
End
Sub my_int
If Asc(Inkey$) = 97 Then Print "World"
End Sub


I repeat my earlier WTF ???

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 01:57pm 08 Jun 2022
Copy link to clipboard 
Print this post

What are you using as a terminal?
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 02:03pm 08 Jun 2022
Copy link to clipboard 
Print this post

  matherp said  What are you using as a terminal?


A VGA monitor (actually VGA video capture) and a PS/2 keyboard.

EDIT: ... and it works fine with Tera Term connected by USB. So looks like it is possibly something to do with the PS/2 support - this is a real (but modern) PS/2 keyboard that I've frequently used with my CMM1.

Best wishes,

Tom
Edited 2022-06-09 00:10 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 02:10pm 08 Jun 2022
Copy link to clipboard 
Print this post

  Quote  and a PS/2 keyboard.


Now had you said that at the beginning.......


PicoMiteVGA.zip
 
Michal
Senior Member

Joined: 02/02/2022
Location: Poland
Posts: 125
Posted: 02:18pm 08 Jun 2022
Copy link to clipboard 
Print this post

Hi matherp.

Could you upload the current version of your MMBASICW (because I'm already lost in the versions)?

Michal
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 02:51pm 08 Jun 2022
Copy link to clipboard 
Print this post

  matherp said  
  Quote  and a PS/2 keyboard.

Now had you said that at the beginning.......


Everyone's a critic. Thanks Peter, that works.

@Mixtel90 (or anyone else with a PicoMiteVGA board and audio output at hand) is there any chance you could run the program in the OP with 3/4 channels and confirm you are hearing white noise too ?

  Michal said  Could you upload the current version of your MMBASICW (because I'm already lost in the versions)?


Assuming you mean MMB4W then wrong thread, work backwards through this one looking for a download:

   https://www.thebackshed.com/forum/ViewTopic.php?FID=16&TID=14614&LastEntry=Y#187081.

Best wishes,

Tom
Edited 2022-06-09 00:52 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 03:29pm 08 Jun 2022
Copy link to clipboard 
Print this post

  Quote   is there any chance you could run the program in the OP with 3/4 channels and confirm you are hearing white noise too ?


Suggest you start with a simple test at the command line and see if you can set up 4 tones and hear them (or better see on the scope)
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 03:39pm 08 Jun 2022
Copy link to clipboard 
Print this post

  matherp said  
  Quote   is there any chance you could run the program in the OP with 3/4 channels and confirm you are hearing white noise too ?


Suggest you start with a simple test at the command line and see if you can set up 4 tones and hear them (or better see on the scope)


My scope is a toy operated by an ignoramus.

This generates white noise for me at the command-line:

Play Sound 1,B,S,500:Play Sound 2,B,S,560:Play Sound 3,B,S,600


Best wishes,

Tom
Edited 2022-06-09 01:40 by thwill
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 03:40pm 08 Jun 2022
Copy link to clipboard 
Print this post

Just white noise? or two tones with white noise as the third?
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 03:43pm 08 Jun 2022
Copy link to clipboard 
Print this post

  matherp said  Just white noise? or two tones with white noise as the third?


I *think* noise as the third - like you say, need a scope to be certain.

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 10310
Posted: 03:52pm 08 Jun 2022
Copy link to clipboard 
Print this post

Have you tried with lower volumes? e.g. set volume for each channel to say 5
 
Mixtel90

Guru

Joined: 05/10/2019
Location: United Kingdom
Posts: 7937
Posted: 04:11pm 08 Jun 2022
Copy link to clipboard 
Print this post

Just check something, Tom. The prototype board was messed up on the phone jack IIRC. Is yours working correctly? If in doubt take the links out of LB2 and check for the tones on the top two pins or the bottom two pins. Then compare with what you hear on the output jack when you put the links back.
Mick

Zilog Inside! nascom.info for Nascom & Gemini
Preliminary MMBasic docs & my PCB designs
 
thwill

Guru

Joined: 16/09/2019
Location: United Kingdom
Posts: 4311
Posted: 04:11pm 08 Jun 2022
Copy link to clipboard 
Print this post

  matherp said  Have you tried with lower volumes? e.g. set volume for each channel to say 5


I have now and that eliminates 95% of the issue, just a couple of clicks and pops remain.

For my education can you explain ?

Best wishes,

Tom
MMBasic for Linux, Game*Mite, CMM2 Welcome Tape, Creaky old text adventures
 
     Page 1 of 3    
Print this page
The Back Shed's forum code is written, and hosted, in Australia.
© JAQ Software 2025