Newbie code attempt - advice please?
Posted: Sat Dec 08, 2012 12:04 am
Would appreciate it if some one could have a look at this code I have put together. It is supposed to read a latch that reflects the status of four switches (high nibble) and depending on which key is pressed, toggle the led at the low order nibble at the same address. What it does do is switch the leds on when you press the corresponding key, but doesn't toggle the led. If I press another key the led for that key goes on but only one led illuminates at one time. There is probably a lot wrong with the code it'd be great if you guys would give me an idea what I am doing wrong.
TIA
Code: Select all
ZPFPLED EQU $00 ;Zero page location holds status of fp leds
FPLED EQU $A002
FBSWTCH EQU FPLED
org $E000 ;Begining of ROM
;
;
;
SWCHTBL dw 0xE0D0 ;Look up table for fp switches
dw 0xB070 ;End lookup table
SWCHLUP dw 0x0804 ;Look up table for mask
dw 0x0201 ;End lookup table
SWCHCOM dw 0xF7FB ;Compliment of SWCHLUP table
dw 0xFDFE ;End lookup table
dw 0x0000
dw 0x0000
Reset01 ;Initialise machine
;
CLC ;Clear carry flag
CLD
SEI ;disable interupts
;
LDX #$FF
TXS ;Initialise Stack pointer
;
LDX #$0F
;
STX ZPFPLED ;Initialise zero page location holds status of leds
;
;
TXA
STA FPLED ;Make sure all leds are off
;
;
CLI
;
;
CLC
Labelend: LDA FBSWTCH ;read switch on front pannel
AND #$F0 ;Clear lower four bits
CMP #$F0 ;Key pressed at all?
BEQ NEXT001 ;If no key pressed exit
LDX #$03
NEXT002: CMP SWCHTBL,X ;Which Key was pressed
BEQ NEXT004
DEX
BNE NEXT002 ;Loop until we find match
NEXT004: TXA ;X holds index to key pressed
;
;
; Lamp control routine.
; that toggles individual Led's on or off.
;
TAX ;
LDA SWCHLUP,X ; Get mask for from table according to index
;
BIT ZPFPLED ;Test bits
;
BNE NEXT005
;Bit result is zero. Led is on need to switch off
LDA ZPFPLED
ORA SWCHLUP,X
STA ZPFPLED
BRA NEXT003
NEXT005: ; Bit is set. Led is off need to switch it on.
LDA ZPFPLED
AND SWCHCOM,X
STA ZPFPLED
;
;
NEXT003: LDA ZPFPLED
STA FPLED ;Output to panel leds
NEXT001: NOP
;
;
JMP Labelend