Jump to content

SID app mod - "Keyboard mode"


nILS
 Share

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

.... 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

Link to comment
Share on other sites

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

edit: spelling...

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...