Assembly Language
by Matt LovelessThe following assembly language program will allow a BASIC program the capability of selectively (masking) ignoring any key(s) on the keyboard. This function is accomplished by first using the BASIC program, SETUP, to choose those keys which are to be enabled or masked. The output of program SETUP is a file containing string data and machine code. This file may be appended to your own program as a subroutine and once called the desired masking effect will be enabled.
This routine puts to good use locations $208,$209, called VKEYBD. VKEYBD is accessed whenever a key is pressed on the keyboard. Normally VKEYBD contains $FFBE, the start of the system's keyboard interrupt service routine. Our setup, routine BEGIN (see listing) puts $620 the start of our own keyboard interrupt routine in locations $208,$209. Now whenever a key is pressed our routine is executed which either ignores a key by simply performing an RTI (return from interrupt) instruction or jumps to the normal system routine at $FFBE and allows the key to be accepted.
To use the BASIC program, SETUP, type it in and save it. When SETUP is executed it will ask whether keys should be Enabled(E) or Masked(M). When in mode E all keys are initially masked (disabled) and you must selectively re-enable each key. If M mode is chosen then all keys are initially enabled and you must selectively mask (disable) each key.
In the following example all computer output is printed in bold letters.
Would you like to ENABLE keys(E) or MASK keys(M)?
--ENABLE MODE--
WHICH LINE NUMBER TO START SUBROUTINE ON?
ENTER OUTPUT FILE NAME, INCLUDE DEVICE.
To test the TEST.BAS program.
E(return)
ALL KEYS ARE DISABLED.
PRESS KEY(s) YOU WANT TO ENABLE.
ABC(return)
(press START key)
2500(return)
D:TEST.BAS(return)
(NOTE: Subroutine will be written to disk at this point.)
NEW(return)
ENTER"D:TEST.BAS"(return)
RUN(return)
(NOTE: Only key A, B, and C will be recognized. All other keys are masked (disabled).
0000 10 .TITLE"KEY MASK 1.0" 20 ;******************************** 30 ;*** KEY MASK 1.0 *** 40 ;***(c) 1982 by, Matt Loveless*** 50 ;*** written especially for *** 60 ;*** ANTIC magazine *** 70 ;******************************** 80 ; 90 ;*** EQUATES *** 0100 ; D209 0110 KBCODE = $D209 ; Key board code 0208 0120 VKEYBD = $0208 ; Keyboard IRQ ve 00CB 0130 TABLE = $CB ; Free zero Page locations 0140 ; 0150 ;========================================================= 0160 ; INIT ROUTINE: Puts my keyboard handler online 0170 ;========================================================= 0000 0180 *= $0600 ; Page 6 0600 78 0190 BEGIN SEI ; Disable IRQ's 0601 AD0802 0200 LOA VKEYBD ; Point the keyboard vector to my 0604 8D3006 0210 STA JMPLOC+1 ; routine, and set my routine's JMP 0607 AD0902 0220 LOA VKEYBD+1 ; instruction to point to the OS's 060A 8D3106 0230 STA JMPLOC+2 ; routine 060D A920 0240 LOA #MYRTN&255 ; Lo byte of my routine 060F 8D0802 0250 STA VKEYBD 0612 A906 0260 LOA #MYRTN/256 ; Hi byte of my routine 0614 8D0902 0270 STA VKEYBD+l 0617 68 0280 PLA ; Remove USR amount byte 0618 68 0290 PLA ; Get hi byte of the mask string 0619 85CC 0300 STA TABLE+1 061B 68 0310 PLA ; Get lo byte 061C 85CB 0320 STA TABLE 061E 58 0330 CLI ; Re-Enable IRO's ! 061F 60 0340 RTS ; Return to BASIC 0350 ;========================================================= 0360 ;THE NEW KEYBOARD INTERRUPT ROUTINE 0370 ;========================================================= 0620 98 0380 MYRTN TYA ; Keyboard IRQ vector points here 0621 48 0390 PHA ; Save Y-register 0622 AC09D2 0400 LOY KBCODE ; Get the key code 0625 B1CB 0410 LOA (TABLE),Y ; and use it to index into the string 0627 D004 0420 BNE GONORM ; Is it masked out? 0629 68 0430 PLA ; YES - then ignore key and 062A A8 0440 TAY ; restore registers 062B 68 0450 PLA 062C 40 0460 RTI ; Exit the keyboard interrupt 0470 062D 68 0480 GONORM PLA ; Restore Y-register 062E A8 0490 TAY 062F 4C0000 0500 JMPLOC JMP $0000 ; Go to normal system keyboard routine 0632 0510 ENDListing: KEYMASK.SRC Download / View
ASSEMBLER LANGUAGE
The following products are recommended.
The ATARI Assembler
by Don & Kurt Inman
Reston Publishing Company
$14.95 whardbound.
Suitable for beginners. See review in this issue.
6502 Assembly Language Programming
by Lance Leventhal
Osborne/McGraw Hill, Inc.
$15.95
A necessary reference text. Over the heads of beginners, but an inevitable
purchase.
Assembler Editor language cartridge
Atari Inc.
$54.95
Most suitable for beginners. NOTE: EADASM from O.S.S. is very similar. For
experienced Assembly language users there are better packages, watch for our
recommendations in coming issues.