home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 4 / DATAFILE_PDCD4.iso / utilities / utilsf / jfshared / Modules / ExtraKeys / EKSrc107 < prev    next >
Encoding:
Text File  |  1995-09-23  |  12.7 KB  |  428 lines

  1. App   ExtraKeys
  2. IN    -
  3. OUT   ExtraKeys
  4. TYPE  Module
  5.  
  6. DEFINE MODULE
  7.   Name     : ExtraKeys
  8.   Version  : 1.07
  9.   Date     : 24 Jun 1995
  10.   Author   : Justin Fletcher
  11.   Help     : Extra keys
  12.   Init     : initialise
  13.   Final    : finalise
  14.   Commands
  15.     Name   : ExtraKeys
  16.     Help   : ...
  17.      ExtraKeys provides some extra control key presses for snazzyness!|M
  18.        Use : Alt-Q for our address!|M
  19.              Alt-D for the current date|M
  20.              Alt-T for the current time|M
  21.              Alt-. for …|M
  22.              Alt-' for double quotes (curly)|M
  23.              Alt-"" for single quotes (curly)|M
  24.      The use of the quotes in reverse order is because the author uses the
  25.      double quote variety more frequently than the single quotes. The date
  26.      and time codes will give fixed length results without shift, and the
  27.      more usual written results if shift is held.
  28.   End Commands
  29. END MODULE
  30.  
  31. { The code contained here in is totally trustworthy, not!
  32.   No, seriously, it should work very well and I have as yet had no
  33.   problems with it.
  34.  
  35.   DISCLAIMER
  36.   ==========
  37.   The author accepts no responsibility for this modules activities, and does
  38.   not guarentee its suitablity for any specific purpose. The module may not
  39.   be copied without this source code file.
  40.  
  41.   MAKING THIS CODE
  42.   ================
  43.   This code requires the !JFPatch pre-assembler to make the code. This is a
  44.   simple text-to-basic assembler which takes a text assembler file, makes a
  45.   basic program from it to assemble, assembles it and returns any errors.
  46.   Currently, it is under development and requires a lot of work before it
  47.   will be released in any form. As such, this file is mostly useless, but
  48.   must be distributed with the resultant module.
  49.  
  50.   ALTERATIONS
  51.   ===========
  52.   The only alterations the author will allow are to the address on Alt-Q.
  53.   This module may be altered, either at the end of the program, or physically
  54.   in the module. If altering directly, the last byte must be 2 and any
  55.   “snazzy” characters, ie top bit set, must be preceeded by a 0 byte.
  56.  
  57. Contact
  58. -------
  59. Any comments, queries, donations or bug reports can be sent to :
  60.  
  61. Fidonet NetMail :  Justin Fletcher at Arcade (0181 655 4412) [2:254/27]
  62. E-Mail : Gerph@arcade.demon.co.uk
  63.  
  64. Snail Mail :
  65.     Justin Fletcher
  66.     “Galadriel”
  67.     17b Cromwell Road,
  68.     Weeting,
  69.     Brandon,
  70.     Suffolk.
  71.     IP27 0QT
  72.  
  73. }
  74.  
  75. .initialise
  76.     STMFD   (sp)!,{link}
  77.     BL      doclaim
  78.     LDMFD   (sp)!,{pc}
  79.  
  80. .doclaim
  81.     STMFD   (sp)!,{r0-r2,link}
  82.     MOV     r2,#0                 ; r12 will be 0 on entry to routines
  83.     MOV     r0,#&10               ; vector &10 - key press/release
  84.     ADR     r1,keypvector%        ; to be processed at keypvector%
  85.     BL      claimvector%
  86.     MOV     r0,#&14               ; vector &14 - insert vector
  87.     ADR     r1,insvector%         ; to be processed at keypvector%
  88.     BL      claimvector%
  89.     MOV     r0,#&0E
  90.     MOV     r1,#&0B
  91.     SWI     "XOS_Byte"            ; enable keypress vector
  92.     MOV     r0,#0
  93.     STRB    r0,doingnow
  94.     LDMFD   (sp)!,{r0-r2,pc}^
  95.  
  96. .finalise
  97.     STMFD   (sp)!,{r0-r2,link}
  98.     MOV     r0,#&0D
  99.     MOV     r1,#&0B
  100.     SWI     "XOS_Byte"            ; disable keypress vector
  101.     MOV     r2,#0
  102.     MOV     r0,#&10               ; keypress vector
  103.     ADR     r1,keypvector%
  104.     BL      releasevector%
  105.     MOV     r0,#&14               ; insert vector
  106.     ADR     r1,insvector%
  107.     BL      releasevector%
  108.     LDMFD   (sp)!,{r0-r2,pc}^
  109.  
  110. .claimvector%
  111.     STMFD   (sp)!,{r2,link}
  112.     BL      releasevector%
  113.     MOV     r2,#0
  114.     SWI     "XOS_Claim"
  115.     LDMFD   (sp)!,{r2,pc}^
  116.  
  117. .releasevector%
  118.     STMFD   (sp)!,{r0-r2,link}
  119. .retryrelease%
  120.     LDMFD   r13,{r0,r1}
  121.     MOV     r2,#0
  122.     SWI     "XOS_Release"
  123.     BVC     retryrelease%
  124.     CMP     pc,#0
  125.     LDMFD   (sp)!,{r0-r2,pc}^
  126.  
  127. .keypvector%
  128.     CMP    r0,#&0B                  ; is this a keypress ?
  129.     MOVNE  pc,link                  ; if not exit
  130.     STMFD  (sp)!,{r0-r2,r4,r5,link} ; stack regs
  131.     BL     setkeypressed
  132.     BL     setshiftflag
  133.     CMP    r5,#0           ; did we process a key ?
  134.     CMPNE  r1,#0           ; was this a key release ?
  135.     BEQ    exitvector      ; if so exit
  136.     LDRB   r0,laltkey      ; what is state of left alt key ?
  137.     CMP    r0,#0           ; if not pressed
  138.     LDREQB r0,raltkey      ; what is state of right alt key ?
  139.     CMPEQ  r0,#0           ; if not pressed (ie both not pressed
  140.     BEQ    exitvector      ; then exit
  141. :
  142.     LDRB   r0,openquote    ; what is state of open quote ?
  143.     CMP    r0,#1           ; if pressed
  144.     BEQ    wasopenquote    ; jump to wasopenquote
  145.     LDRB   r0,address      ; what is state of address ?
  146.     CMP    r0,#1           ; if pressed
  147.     BEQ    wasaddress      ; jump to wasaddress
  148.     LDRB   r0,date         ; what is state of date ?
  149.     CMP    r0,#1           ; if pressed
  150.     BEQ    wasdate         ; jump to wasdate
  151.     LDRB   r0,time         ; what is state of time ?
  152.     CMP    r0,#1           ; if pressed
  153.     BEQ    wastime         ; jump to wastime
  154.     LDRB   r0,dot          ; what is state of dot ?
  155.     CMP    r0,#1           ; if pressed
  156.     BEQ    wasdot          ; jump to wasdot
  157. .exitvector
  158.     LDMFD  (sp)!,{r0-r2,r4,r5,pc}^  ; and exit
  159. :
  160. .setkeypressed
  161. ;    MOV    r5,#&7000
  162. ;    STR    r2,[r5]        ; for testing the numbers
  163.     MOV    r5,#0
  164.     CMP    r2,#&60         ; is this right alt ?
  165.     STREQB r1,raltkey      ; if so then set its state
  166.     MOVEQ  r5,#1           ; Set the "we've processed a key" flag
  167.     CMP    r2,#&5E         ; how about left alt ?
  168.     STREQB r1,laltkey      ; set its state if so
  169.     MOVEQ  r5,#1           ; Set the "we've processed a key" flag
  170.     CMP    r2,#88          ; what about right shift
  171.     STREQB r1,rshift       ; store state ...
  172.     MOVEQ  r5,#1           ; Set the "we've processed a key" flag
  173.     CMP    r2,#76          ; and left shift
  174.     STREQB r1,lshift       ; and its state.
  175.     MOVEQ  r5,#1           ; Set the "we've processed a key" flag
  176.     CMP    r2,#70          ; is this '" ?
  177.     STREQB r1,openquote    ; set open quote if so
  178.     MOVEQ  r5,#1           ; Set the "we've processed a key" flag
  179.     CMP    r2,#39          ; is this Q ?
  180.     STREQB r1,address      ; set address if so
  181.     MOVEQ  r5,#1           ; Set the "we've processed a key" flag
  182.     CMP    r2,#62          ; is this D ?
  183.     STREQB r1,date         ; set date if so
  184.     MOVEQ  r5,#1           ; Set the "we've processed a key" flag
  185.     CMP    r2,#43          ; is this T ?
  186.     STREQB r1,time         ; set time if so
  187.     MOVEQ  r5,#1           ; Set the "we've processed a key" flag
  188.     CMP    r2,#86          ; is this full stop ?
  189.     STREQB r1,dot          ; set time if so
  190.     MOVEQ  r5,#1           ; Set the "we've processed a key" flag
  191.     MOV    pc,link
  192. :
  193. .setshiftflag
  194.     LDRB   r0,lshift
  195.     CMP    r0,#0
  196.     LDREQB r0,rshift
  197.     CMPEQ  r0,#0
  198.     MOVEQ  r4,#0         ; r4=0 if no shift
  199.     MOVNE  r4,#1         ; r4=1 if either shift
  200.     MOV    pc,link
  201.  
  202. .wasopenquote
  203.     ADD    r5,r4,#1            ; r5=1 for no shift, 2 for a shift
  204.     LDRB   r2,lastqstate
  205.     EOR    r2,r2,r5            ; invert the state of the quotes
  206.     STRB   r2,lastqstate       ; and store it again
  207.     AND    r2,r2,r5            ; leave just the interesting bit
  208.     MOV    r2,r2,LSR r4        ; and move it down
  209.     ADD    r2,r2,#148          ; add its offset to quote
  210.     SUB    r2,r2,r4,LSL #2     ; subtact the shift so that we get
  211.     ADR    r1,insertcode
  212.     B      setupjump
  213. .wasaddress
  214.     ADR    r1,addresscode
  215.     B      setupjump
  216. .wasdate
  217.     MOV    r2,#0          ; a date
  218.     STRB   r4,shiftstate
  219.     ADR    r1,datecode
  220.     B      setupjump
  221.  
  222. .wastime
  223.     MOV    r2,#1          ; a time
  224.     STRB   r4,shiftstate
  225.     ADR    r1,datecode
  226.     B      setupjump
  227. :
  228. .wasdot
  229.     CMP    r4,#1          ; was shift pressed ?
  230.     BEQ    exitvector     ; if so then exit - ie allow ÷
  231.     ADR    r1,dotcode
  232.     B      setupjump
  233. :
  234. ; Code to insert things into buffer
  235. .insertcode
  236.     STMFD  (sp)!,{r0-r9,link}
  237.     MOV    r0,#4
  238.     STRB   r0,ignorekeys
  239.     MOV    r0,#153
  240.     MOV    r1,#0
  241.     MOV    r2,#0
  242.     SWI    "XOS_Byte"
  243.     MOV    r0,#153
  244.     MOV    r1,#0
  245.     MOV    r2,r12
  246.     SWI    "XOS_Byte"
  247. :
  248.     MOV    r0,#0
  249.     STRB   r0,doingnow         ; no longer doing
  250.     LDMFD  (sp)!,{r0-r9,pc}^
  251. :
  252. ; Insert ... into buffer
  253. .dotcode
  254.     STMFD  (sp)!,{r0-r9,link}
  255.     MOV    r0,#4
  256.     STRB   r0,ignorekeys
  257.     MOV    r0,#153
  258.     MOV    r1,#0
  259.     MOV    r2,#0
  260.     SWI    "XOS_Byte"
  261.     MOV    r0,#153
  262.     MOV    r1,#0
  263.     MOV    r2,#ASC("…")
  264.     SWI    "XOS_Byte"
  265. :
  266.     MOV    r0,#0
  267.     STRB   r0,doingnow         ; no longer doing
  268.     LDMFD  (sp)!,{r0-r9,pc}^
  269.  
  270. :
  271. ; Code to insert the address into buffer
  272. .addresscode
  273.     STMFD  (sp)!,{r0-r9,link}
  274.     MOV    r4,#2               ; 2 for end of text
  275.     ADR    r6,addressstr
  276.     BL     insertstring
  277.     MOV    r0,#0
  278.     STRB   r0,doingnow         ; no longer doing
  279.     LDMFD  (sp)!,{r0-r9,pc}^
  280. :
  281. ; Code to insert the date into buffer
  282. .datecode
  283.     STMFD  (sp)!,{r0-r9,link}
  284.     ADR    r1,dateblock         ; block to read time into
  285.     MOV    r0,#3                ; code 3 - read time in cs
  286.     STR    r0,[r1]
  287.     MOV    r0,#14               ; code to read time
  288.     SWI    "OS_Word"            ; read time
  289.     CMP    r12,#1               ; was this a time ?
  290.     BEQ    maskfortime
  291. ; for dates
  292.     LDRB   r3,shiftstate
  293.     CMP    r3,#1                ; was shift pressed
  294.     ADREQ  r3,datelong          ; yes, long date encoding
  295.     LADRNE r3,dateshort         ; no, short date encoding
  296.     B      processstring
  297. .maskfortime
  298.     LDRB   r3,shiftstate
  299.     CMP    r3,#1                ; was shift pressed
  300.     LADREQ r3,timelong          ; yes, long time encoding
  301.     LADRNE r3,timeshort         ; no, short time encoding
  302. .processstring
  303.     ADR    r1,datestr           ; buffer for string
  304.     ADR    r0,dateblock         ; r0->date in cs
  305.     MOV    r2,#256              ; length of buffer
  306.     SWI    "OS_ConvertDateAndTime"
  307.     MOV    r4,#0                ; 0 for end of string
  308.     ADR    r6,datestr
  309.     BL     insertstring
  310.     SUB    r5,r5,#2             ; r5=length-2
  311.     SUB    r5,r5,r0
  312.     STRB   r5,ignorekeys        ; store at number to ignore
  313.     MOV    r0,#0
  314.     STRB   r0,doingnow          ; no longer doing
  315.     LDMFD  (sp)!,{r0-r9,pc}^
  316.  
  317. .insertstring
  318. ; > r6->string
  319. ;   r4=exit code
  320. ; < r5->last byte
  321.     STMFD  (sp)!,{r0-r4,link}
  322.     MOV    r5,#0
  323. .insstrloop
  324.     LDRB   r2,[r6,r5]
  325.     CMP    r2,r4              ; is it r4 ? (exit code)
  326.     BEQ    xinsertstring
  327.     MOV    r0,#153
  328.     MOV    r1,#0
  329.     SWI    "XOS_Byte"
  330.     ADD    r5,r5,#1
  331.     B      insstrloop
  332. .xinsertstring
  333.     LDMFD  (sp)!,{r0-r4,pc}^
  334. :
  335. ; set up call back code
  336. .setupjump
  337.     MOV     r5,pc
  338.     BIC     r4,r5,#1
  339.     TEQP    r4,#1                  ; set ? flag
  340.     MOVNV   r0,r0
  341.     LDRB    r0,doingnow
  342.     TEQ     r0,#0
  343.     BNE     alreadydoing
  344.     MOV     r0,r1                  ; r0=address
  345.     MOV     r1,r2
  346.     STMFD   (sp)!,{link}
  347.     SWI     "XOS_AddCallBack"
  348.     LDMFD   (sp)!,{link}
  349.     MOVVC   r0,#1
  350.     STRVCB  r0,doingnow            ; set doing
  351. .alreadydoing
  352.     TEQP    r5,#0                  ; Restore state
  353.     MOVNV   r0,r0
  354.     LDMFD   (sp)!,{r0-r2,r4,r5,pc}
  355. :
  356. .insvector%
  357.     STMFD   (sp)!,{r1-r7,link}
  358.     LDRB    r7,ignorekeys
  359.     CMP     r7,#0
  360.     BEQ     xinsvector
  361.     SUB     r7,r7,#1
  362.     STRB    r7,ignorekeys   ; decrement and store counter
  363.     LDRB    r7,last
  364.     CMP     r7,#0
  365.     CMPNE   r0,#ASC("^")
  366.     BNE     xinsvector
  367.     ADR     r7,swapfrom     ; swap ascii code table
  368.     MOV     r5,#0           ; start at beginning
  369. .insvloop
  370.     LDRB    r4,[r7,r5]      ; get the code
  371.     CMP     r4,#0           ; is code =0
  372.     BEQ     xinsvector      ; if no more then exit
  373.     CMP     r0,r4           ; compare
  374.     BEQ     insdoswap       ; if the same then jump to doswap
  375.     ADD     r5,r5,#1
  376.     B       insvloop
  377. .insdoswap
  378.     ADR     r6,swapto       ; addr of codes to swap to
  379.     LDR     r0,[r6,r5]
  380.     CMP     r0,#0
  381. .xinsvector
  382.     STRB    r0,last
  383.     LDMFD   (sp)!,{r1-r7,pc}
  384. :
  385.  
  386. ; Variables
  387. .dateblock :EQUD 0:EQUD 0   ; time in cs
  388. .datelong  :EQUS "%ZDY%ST %MO %CE%YR"+CHR$0
  389. .dateshort :EQUS "%DY %M3 %CE%YR"+CHR$0
  390. .timelong  :EQUS "%Z12:%MI %pm"+CHR$0
  391. .timeshort :EQUS "%24:%MI.%SE"+CHR$0
  392.     ALIGN
  393. .datestr
  394.     RES    256
  395.  
  396. .doingnow  :EQUB 0
  397. .laltkey   :EQUB 0
  398. .raltkey   :EQUB 0
  399. .lshift    :EQUB 0
  400. .rshift    :EQUB 0
  401. .openquote :EQUB 0
  402. .address   :EQUB 0
  403. .date      :EQUB 0
  404. .time      :EQUB 0
  405. .dot       :EQUB 0
  406. .lastqstate:EQUB 3
  407. .ignorekeys:EQUB 0
  408. .shiftstate:EQUB 0
  409.     ALIGN
  410. .swapfrom  :EQUS "^ŵêŷûîôâŴÊŶÛÎÔÂÅå°"
  411.             EQUS "ðÐ"
  412.             EQUB 0
  413.     ALIGN
  414. .swapto    :EQUS " weyuioaWEYUIOAAa "
  415.             EQUS CHR$0+CHR$0
  416.             EQUB 0
  417. .last      :EQUB 0
  418.     ALIGN
  419. .addressstr:EQUS CHR$0+"“Galadriel"+CHR$0+"”"+CHR$13
  420.            :EQUS "17b Cromwell Road,"+CHR$13
  421.            :EQUS "Weeting,"+CHR$13
  422.            :EQUS "Brandon,"+CHR$13
  423.            :EQUS "Suffolk."+CHR$13
  424.            :EQUS "IP27 0QT"+CHR$13
  425.            :EQUB 2
  426. # POST
  427. # RUN <CODE>
  428.