0001 0000 ;; Clear the main display then loop around reading key codes 0002 0000 ;; and displaying any keys in the range '0' to '9' 0003 0000 0004 0000 CLRCODE: .EQU $10 ; Special code to clear the main display 0005 0000 MAINDISP: .EQU $F031 ; Address of output port for main display 0006 0000 KEYPAD: .EQU $F011 ; Address of input port for keypad 0007 0000 0008 0000 #define puts [PUTS] 0009 0000 0010 4000 .ORG $4000 ; Set program's origin to address $4000 0011 4000 0012 4000 ; initiallize the stack pointer 0013 4000 50 EF FF BLDSP $EFFF 0014 4003 0015 4003 ; set function pointers 0016 4003 A0 40 34 BLDX _PUTS 0017 4006 A9 40 7C BSTX [PUTS] 0018 4009 0019 4009 ; print welcome message 0020 4009 A0 40 6B BLDX MSG_000 0021 400C C9 40 34 JSR [_PUTS] 0022 400F 0023 400F ; main loop 0024 400F 91 F0 11 MAIN: LDA [KEYPAD] ; Load the accumulator from the keypad 0025 4012 D9 40 0F JN [MAIN] ; Jump to LOOP if N flag is set 0026 4015 99 40 7B STA [KEYCODE] ; save 0027 4018 0028 4018 ; print "KEYCODE: " message 0029 4018 A0 40 61 BLDX KEYMSG 0030 401B CB 40 7C JSR [puts] 0031 401E 0032 401E 91 40 7B LDA [KEYCODE] ; retrieve keycode 0033 4021 B2 PUSHA 0034 4022 ; process upper nibble 0035 4022 30 F0 AND $F0 0036 4024 71 SHR 0037 4025 71 SHR 0038 4026 71 SHR 0039 4027 71 SHR 0040 4028 C9 40 4F JSR [PUTHEX] 0041 402B 0042 402B ; process lower nibble 0043 402B B0 POPA 0044 402C 30 0F AND $0F 0045 402E C9 40 4F JSR [PUTHEX] 0046 4031 0047 4031 ; done 0048 4031 C1 40 0F JMP [MAIN] ; Jump to LOOP 0049 4034 0050 4034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 0051 4034 ; 0052 4034 ; Function PUTS: put a string to the display 0053 4034 ; 0054 4034 ; Input: X .. address of string 0055 4034 ; 0056 4034 ; Output: -- 0057 4034 ; 0058 4034 ; Uses: A, X, Z 0059 4034 ; 0060 4034 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 0061 4034 90 10 _PUTS: LDA CLRCODE ; Load accumulator with clear code 0062 4036 99 F0 31 STA [MAINDISP] ; Store accumulator to main display 0063 4039 0064 4039 A9 40 4D BSTX [PTR16] 0065 403C A0 00 00 BLDX 0 ; Load the index register with 0 0066 403F 95 40 4D PUTS1: LDA [[PTR16],X] ; Load accumulator with character 0067 4042 D1 40 4C JZ [PUTS2] ; end of string => return 0068 4045 99 F0 31 STA [MAINDISP] ; write character to display 0069 4048 82 INCX ; Increment the index register 0070 4049 C1 40 3F JMP [PUTS1] ; Jump back to LOOP 0071 404C 0072 404C CF PUTS2: RTS ; return from subroutine 0073 404D 0074 404D 00 00 PTR16: .BYTE 0,0 ; temp 16bit pointer 0075 404F 0076 404F ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 0077 404F ; 0078 404F ; Function PUTHEX: put a HEX digit to the display 0079 404F ; 0080 404F ; Input: A .. the digit 0081 404F ; 0082 404F ; Output: -- 0083 404F ; 0084 404F ; Uses: A, Z, Carry 0085 404F ; 0086 404F ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 0087 404F 60 09 PUTHEX: CMPA 9 0088 4051 E1 40 59 JC [LBL01] 0089 4054 10 30 ADD $30 0090 4056 C1 40 5D JMP [LBL02] 0091 4059 10 41 LBL01: ADD $41 0092 405B 20 0A SUB 10 0093 405D 99 F0 31 LBL02: STA [MAINDISP] ; ... else store accumulator to display 0094 4060 CF RTS 0095 4061 0096 4061 4B 45 59 43 KEYMSG: .BYTE $4B,$45,$59,$43,$4F,$44,$45,$3A,$20,$00 0096 4065 4F 44 45 3A 0096 4069 20 00 0097 406B 0098 406B 43 6C 69 63 MSG_000: .BYTE $43,$6C,$69,$63,$6B,$20,$61,$20,$6B,$65,$79,$20,$2E,$2E,$2E,$00 0098 406F 6B 20 61 20 0098 4073 6B 65 79 20 0098 4077 2E 2E 2E 00 0099 407B 0100 407B 10 KEYCODE: .BYTE CLRCODE 0101 407C 0102 407C 00 00 PUTS .DW ; pointer to puts() function 0103 407E 0104 407E .END ; This is the end of the program 0105 407E 0106 407E tasm: Number of errors = 0