SID app mod - "Keyboard mode"

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

exellent idea :slight_smile:

Send it over bud :slight_smile:

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 =)

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\>&nbsp; &nbsp; "  
&nbsp; &nbsp; &nbsp; &nbsp; ;; note this setup is for a 2x40 LCD. If you use a different size, you  
&nbsp; &nbsp; &nbsp; &nbsp; ;; you might want to adjust the size and position of the string =)  
  
CS\_KEYMODE\_DISPLAY\_MESSAGE  
&nbsp; &nbsp; &nbsp; &nbsp; ;; display keyboard mode note if enabled  
&nbsp; &nbsp; &nbsp; &nbsp; btfss CS\_KEYMODE\_FLAGS, 0&nbsp; &nbsp; &nbsp; &nbsp;; skip displaying if mode is disabled  
&nbsp; &nbsp; &nbsp; &nbsp; return  
  
&nbsp; &nbsp; &nbsp; &nbsp; TABLE\_ADDR TEXT\_KEYMODE\_ENABLED ; display keyboard mode message  
&nbsp; &nbsp; &nbsp; &nbsp; call&nbsp; &nbsp; &nbsp; &nbsp; MIOS\_LCD\_PrintString  
&nbsp; &nbsp; &nbsp; &nbsp; return  
  
[FIND]  
USER\_Tick  
  
[INSERT AFTER]  
&nbsp; &nbsp; &nbsp; &nbsp; 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  
;;&nbsp; &nbsp; &nbsp; CS\_KEYMODE\_NOTE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;EQU&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x69  
;;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stores the note to be played  
;;&nbsp; &nbsp; &nbsp; CS\_KEYMODE\_FLAGS&nbsp; &nbsp; &nbsp; &nbsp; EQU&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;0x6a  
;;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; stores the flags (mode enabled, button down)  
;; check for keyboard mode  
&nbsp; &nbsp; &nbsp; &nbsp; btfss&nbsp; &nbsp;CS\_KEYMODE\_FLAGS, 0&nbsp; &nbsp; &nbsp;; if keymode is enabled...  
&nbsp; &nbsp; &nbsp; &nbsp; goto&nbsp; &nbsp; CS\_KEYMODE\_SKIP&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; ...don't do anything here  
;; keymode is enabled  
&nbsp; &nbsp; &nbsp; &nbsp; addlw&nbsp; &nbsp;h'30'&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; add note offset to button number  
&nbsp; &nbsp; &nbsp; &nbsp; movwf&nbsp; &nbsp;CS\_KEYMODE\_NOTE&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; push note from wreg to CS\_KEYMODE\_NOTE  
&nbsp; &nbsp; &nbsp; &nbsp; call&nbsp; &nbsp; MIOS\_MIDI\_BeginStream&nbsp; &nbsp;; begin stream  
&nbsp; &nbsp; &nbsp; &nbsp; movlw&nbsp; &nbsp;0x90&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; push note event...  
&nbsp; &nbsp; &nbsp; &nbsp; call&nbsp; &nbsp; MIOS\_MIDI\_RxBufferPut&nbsp; &nbsp;; ...and receive it  
&nbsp; &nbsp; &nbsp; &nbsp; movf&nbsp; &nbsp; CS\_KEYMODE\_NOTE, W&nbsp; &nbsp; &nbsp; ; push note event...  
&nbsp; &nbsp; &nbsp; &nbsp; call&nbsp; &nbsp; MIOS\_MIDI\_RxBufferPut&nbsp; &nbsp;; ...and receive it  
;; check if the button is being pressed or released  
&nbsp; &nbsp; &nbsp; &nbsp; movlw&nbsp; &nbsp;0x64&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; set velocity to 100  
&nbsp; &nbsp; &nbsp; &nbsp; btfsc&nbsp; &nbsp;MIOS\_PARAMETER2, 0&nbsp; &nbsp; &nbsp; ; releasing?  
&nbsp; &nbsp; &nbsp; &nbsp; movlw&nbsp; &nbsp;0x00&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; ...set velocity to 0  
&nbsp; &nbsp; &nbsp; &nbsp; call&nbsp; &nbsp; MIOS\_MIDI\_RxBufferPut&nbsp; &nbsp;; receive the velocity  
&nbsp; &nbsp; &nbsp; &nbsp; call&nbsp; &nbsp; MIOS\_MIDI\_EndStream&nbsp; &nbsp; &nbsp;; end the stream  
&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; done  
CS\_KEYMODE\_SKIP&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;; keyboard mode is disabled  
;; do nothing if button has been depressed  
&nbsp; &nbsp; &nbsp; &nbsp; btfss&nbsp; &nbsp;MIOS\_PARAMETER2, 0&nbsp; &nbsp; &nbsp; ; if the button is pressed  
&nbsp; &nbsp; &nbsp; &nbsp; goto&nbsp; &nbsp; CS\_KEYMODE\_CHECK&nbsp; &nbsp; &nbsp; &nbsp; ; goto  
&nbsp; &nbsp; &nbsp; &nbsp; clrf&nbsp; &nbsp; CS\_KEYMODE\_FLAGS&nbsp; &nbsp; &nbsp; &nbsp; ; else reset the keymode\_flags&nbsp;   
&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; and exit  
;; check if keymode should be enabled  
CS\_KEYMODE\_CHECK  
&nbsp; &nbsp; &nbsp; &nbsp; btfss&nbsp; &nbsp;CS\_KEYMODE\_FLAGS, 1&nbsp; &nbsp; &nbsp;; if button down bit is set...  
&nbsp; &nbsp; &nbsp; &nbsp; goto&nbsp; &nbsp; CS\_KEYMODE\_SET\_BIT&nbsp; &nbsp; &nbsp; ; ...skip going to set it  
&nbsp; &nbsp; &nbsp; &nbsp; call&nbsp; &nbsp; CS\_MENU\_BUTTON\_Exec&nbsp; &nbsp; &nbsp;; simulate enter button to leave menu  
&nbsp; &nbsp; &nbsp; &nbsp; bsf&nbsp; &nbsp; &nbsp;CS\_KEYMODE\_FLAGS, 0&nbsp; &nbsp; &nbsp;; else set the enabled bit...  
&nbsp; &nbsp; &nbsp; &nbsp; bcf&nbsp; &nbsp; &nbsp;CS\_KEYMODE\_FLAGS, 1&nbsp; &nbsp; &nbsp;; reset button down bit  
&nbsp; &nbsp; &nbsp; &nbsp; return&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ; and quit  
CS\_KEYMODE\_SET\_BIT  
&nbsp; &nbsp; &nbsp; &nbsp; bsf&nbsp; &nbsp; &nbsp;CS\_KEYMODE\_FLAGS, 1&nbsp; &nbsp; &nbsp;; 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  
;;&nbsp; &nbsp; &nbsp; &nbsp; 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?! :wink:

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 :slight_smile:

        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

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 :smiley: Hooray for high-level languages (all but Java)

edit: spelling…