![]() |
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 KingdomPosts: 4311 |
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$ 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 KingdomPosts: 10310 |
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 KingdomPosts: 4311 |
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 KingdomPosts: 10310 |
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 KingdomPosts: 4311 |
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. 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 KingdomPosts: 10310 |
latter - b6 just posted |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
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 KingdomPosts: 4311 |
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 KingdomPosts: 10310 |
What are you using as a terminal? |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
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 KingdomPosts: 10310 |
Now had you said that at the beginning....... PicoMiteVGA.zip |
||||
Michal Senior Member ![]() Joined: 02/02/2022 Location: PolandPosts: 125 |
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 KingdomPosts: 4311 |
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 ? 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 KingdomPosts: 10310 |
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 KingdomPosts: 4311 |
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 KingdomPosts: 10310 |
Just white noise? or two tones with white noise as the third? |
||||
thwill![]() Guru ![]() Joined: 16/09/2019 Location: United KingdomPosts: 4311 |
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 KingdomPosts: 10310 |
Have you tried with lower volumes? e.g. set volume for each channel to say 5 |
||||
Mixtel90![]() Guru ![]() Joined: 05/10/2019 Location: United KingdomPosts: 7937 |
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 KingdomPosts: 4311 |
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 ![]() ![]() |
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |