Apropos to my earlier remark about reset protection, I thought it might be illustrative to show how the same task can be done as a native SDX relocatable COM file which becomes resident when it is first run.
; Example keyboard click toggle for SDX by FJC
S_ADDIZ SMB 'S_ADDIZ'
INSTALL SMB 'INSTALL'
U_GONOFF SMB 'U_GONOFF'
I_GETTD SMB 'I_GETTD'
COMTAB SMB 'COMTAB'
S_LOOKUP smb 'S_LOOKUP'
SYMBOL smb 'SYMBOL'
PRINTF smb 'PRINTF'
S_ADD smb 'S_ADD'
NoClick equ $02DB
; non-relocatable init section (jettisoned after use)
blk sparta $600
lda ClickSymbol,x ; copy our new symbol to SYMBOL
jsr S_LOOKUP ; has our symbol already been defined?
bne GotSym ; if so, skip installation
jsr S_ADD ; if symbol not found, add it
jsr S_ADDIZ ; run 'Main' on reset
lda #$00 ; initially set Quiet flag to false
dec INSTALL ; tell SDX to make main section resident
jmp Procedure ; read command args
lda Symbol+$0B ; we're already installed, so just jump into resident code
Adr = *-2
MainP .word Main ; pointer to Main address
.byte '@CLICK ',0 ; symbol defines new procedure
.word Procedure ; symbol value
; main (relocatable) section
blk reloc main
lda QuietFlag ; we come here on system reset: just ensure OS reflects state of internal flag
Procedure ; read args
jsr U_GONOFF ; 'ON' = Carry set, 'OFF' = Carry clear
.byte 'Click is OFF',0
.byte 'Click is ON',0
sta NoClick ; update OS flag
clc ; say OK
QuietFlag .byte 0
blk update address
The code is quite brief and does a couple of interesting things. The '@CLICK' symbol serves two purposes: it creates a resident procedure which is directly called from the command line when CLICK ON or CLICK OFF is subsequently typed. The presence of the symbol also signifies that the program has already been run once, is installed, and therefore need not be installed a second time. The state of the keyboard click should be preserved across system reset.
Not exhaustively tested, but I thought it may prove useful. It's loosely based on the example code in the MADS assembler download package, and MADS should be used to compile the source.
Edited by flashjazzcat, Sun Oct 4, 2015 7:12 AM.