nILS
September 23, 2007, 8:39pm
1
I just finished adding a little feature to the SID application. Basically it adds a second function to the (in my case 10) menu buttons. Pressing any two of them together makes the SID goes into “keyboard mode” allowing you to use the menu buttons as a miniature keyboard. Pressing the exec button goes back into regular mode.
If anyone else might find this useful, I’d love to run the 20-something lines of source by our asm-gurus and then post the mod + documentation here.
Cheerio,
nILS
nILS
September 23, 2007, 10:55pm
4
I was kinda hoping noone would care for it, and now I have to put comments in it. BTW, I wrote this for v1.7303b, but, since every other version seems to have more codespace and free RAM, it shouldn’t be a problem to use that mod in other versions. I’ll get cracking on the documentation and post what I have here, so you guys can point out my mistakes =)
nILS
September 24, 2007, 12:01am
5
This is the source. I added comments of what to do in a phpBB manner.
Changes to app_defines.h (could be done in main.asm, but it’s a little more tidy this way):
[INSERT]
CS_KEYMODE_NOTE EQU 0x69
CS_KEYMODE_FLAGS EQU 0x6a
[note: those adresses work with the v1.7303b. For other version you might need
to find some other free RAM]
[/code]
Changes to main.asm:
[code][FIND]
USER\_Init
[INSERT AFTER]
clrf CS\_KEYMODE\_FLAGS
bsf CS\_KEYMODE\_FLAGS, 0 ; comment out this line if you don't want to start in kyboard mode
clrf CS\_KEYMODE\_NOTE
[INSERT]
TEXT\_KEYMODE\_ENABLED STRING 19, 0x14, "\<KEYBOARD MODE\> "
;; note this setup is for a 2x40 LCD. If you use a different size, you
;; you might want to adjust the size and position of the string =)
CS\_KEYMODE\_DISPLAY\_MESSAGE
;; display keyboard mode note if enabled
btfss CS\_KEYMODE\_FLAGS, 0 ; skip displaying if mode is disabled
return
TABLE\_ADDR TEXT\_KEYMODE\_ENABLED ; display keyboard mode message
call MIOS\_LCD\_PrintString
return
[FIND]
USER\_Tick
[INSERT AFTER]
call CS\_KEYMODE\_DISPLAY\_MESSAGE ; display keyboard mode
[FIND]
CS\_MENU\_BUTTON\_Select\_Cont
[INSERT AFTER]
;; -----------------------------------------------------------------------------
;; start of keyboard mod
;; -----------------------------------------------------------------------------
;; Additional code for keyboard mode uses these two registers, see app\_defines.h
;; CS\_KEYMODE\_NOTE EQU 0x69
;; stores the note to be played
;; CS\_KEYMODE\_FLAGS EQU 0x6a
;; stores the flags (mode enabled, button down)
;; check for keyboard mode
btfss CS\_KEYMODE\_FLAGS, 0 ; if keymode is enabled...
goto CS\_KEYMODE\_SKIP ; ...don't do anything here
;; keymode is enabled
addlw h'30' ; add note offset to button number
movwf CS\_KEYMODE\_NOTE ; push note from wreg to CS\_KEYMODE\_NOTE
call MIOS\_MIDI\_BeginStream ; begin stream
movlw 0x90 ; push note event...
call MIOS\_MIDI\_RxBufferPut ; ...and receive it
movf CS\_KEYMODE\_NOTE, W ; push note event...
call MIOS\_MIDI\_RxBufferPut ; ...and receive it
;; check if the button is being pressed or released
movlw 0x64 ; set velocity to 100
btfsc MIOS\_PARAMETER2, 0 ; releasing?
movlw 0x00 ; ...set velocity to 0
call MIOS\_MIDI\_RxBufferPut ; receive the velocity
call MIOS\_MIDI\_EndStream ; end the stream
return ; done
CS\_KEYMODE\_SKIP ; keyboard mode is disabled
;; do nothing if button has been depressed
btfss MIOS\_PARAMETER2, 0 ; if the button is pressed
goto CS\_KEYMODE\_CHECK ; goto
clrf CS\_KEYMODE\_FLAGS ; else reset the keymode\_flags
return ; and exit
;; check if keymode should be enabled
CS\_KEYMODE\_CHECK
btfss CS\_KEYMODE\_FLAGS, 1 ; if button down bit is set...
goto CS\_KEYMODE\_SET\_BIT ; ...skip going to set it
call CS\_MENU\_BUTTON\_Exec ; simulate enter button to leave menu
bsf CS\_KEYMODE\_FLAGS, 0 ; else set the enabled bit...
bcf CS\_KEYMODE\_FLAGS, 1 ; reset button down bit
return ; and quit
CS\_KEYMODE\_SET\_BIT
bsf CS\_KEYMODE\_FLAGS, 1 ; set the button down bit and keep going
;; -----------------------------------------------------------------------------
;; end of keyboard mod
;; -----------------------------------------------------------------------------
;; uncomment the next line, which is needed if the keyboard mod is commented out
;; -----------------------------------------------------------------------------
;; do nothing if button has been depressed
;; IFSET MIOS\_PARAMETER2, 0, return
[note: the last line already exists in the source - to use the keyboard mod
you need to comment it out.]
This is an uncommented version of the source in main.asm (in case someone doesn’t like comments):
CS_MENU_BUTTON_Select_Cont
btfss CS_KEYMODE_FLAGS, 0
goto CS_KEYMODE_SKIP
addlw h'30'
movwf CS_KEYMODE_NOTE
call MIOS_MIDI_BeginStream
movlw 0x90
call MIOS_MIDI_RxBufferPut
movf CS_KEYMODE_NOTE, W
call MIOS_MIDI_RxBufferPut
movlw 0x64
btfsc MIOS_PARAMETER2, 0
movlw 0x00
call MIOS_MIDI_RxBufferPut
call MIOS_MIDI_EndStream
return
CS_KEYMODE_SKIP
btfss MIOS_PARAMETER2, 0
goto CS_KEYMODE_CHECK
clrf CS_KEYMODE_FLAGS
return
CS_KEYMODE_CHECK
btfss CS_KEYMODE_FLAGS, 1
goto CS_KEYMODE_SET_BIT
call CS_MENU_BUTTON_Exec
bsf CS_KEYMODE_FLAGS, 0
bcf CS_KEYMODE_FLAGS, 1
return
CS_KEYMODE_SET_BIT
bsf CS_KEYMODE_FLAGS, 1
;; IFSET MIOS_PARAMETER2, 0, return[/code]
Update 1: Included stryd's suggestion to have less of those evil jumps
… and you reckon you can’t do ASM?!
Looks good to me at a glance… Does it work?
You could optimise a tiny bit with stuff like the following perhaps… The gotos are a bit heavy… But I dunno if it’s worth the effort to be honest
IFSET MIOS_PARAMETER2, 0, goto CS_KEYMODE_NOTE_OFF
;; we're setting a note to on
movlw 0x64 ; set velocity to 100
goto CS_KEYMODE_DONE
CS_KEYMODE_NOTE_OFF
movlw 0x00 ; set velocity ti 0
CS_KEYMODE_DONE
could be:
;; set default note velocity
movlw 0x64 ; set velocity to 100
;; change to a note off if button has been released
IFSET MIOS_PARAMETER2, 0, movlw 0x00
nILS
September 24, 2007, 10:16am
7
Hmm =) Stryd, you’re right of course. The source *is* working, but I have not done any optimising yet. I’ll update the source above from time to adjust to the ideas and suggestions made here.
BTW, I never said I couldn’t do any asm, I just don’t like it and don’t do it much anymore Hooray for high-level languages (all but Java)
edit: spelling…