Animan, on Sat Sep 25, 2010 2:21 PM, said:
I want to load 4-bit data into half of PF1, and a different set of 4-bit data into the other half. How can I do this?
To set the lo nibble, you first want to clear its old value with an AND, then load its new value with an ORA:
LDA PF1_RAM ; some RAM byte that holds the value for PF1
AND #$F0 ; clear the lo nibble
ORA NEW_VAL ; some RAM byte that holds the new value
STA PF1_RAM
To set the hi_nibble, you first want to clear its old value with an AND, then load its new value with an ORA:
LDA PF1_RAM ; some RAM byte that holds the value for PF1
AND #$0F ; clear the hi nibble
ORA NEW_VAL ; some RAM byte that holds the new value
STA PF1_RAM
That's just a generic solution. For a more specific solution, it depends on how you're going to organize things.
For example, how are you going to store the data for the digits? When using characters that take up only a nibble, one approach is to store the same data in both nibbles of a byte. Then when you want to set the data for a nibble, load the whole byte, mask off the side you don't need, and ORA the remaining value with the byte you're changing:
; set the address pointers for the first digit
LDA #<digit_0
STA first_digit
LDA #>digit_0
STA first_digit+1
; set the address pointers for the second digit
LDA #<digit_1
STA second_digit
LDA #>digit_1
STA second_digit+1
; get 8 lines of data
LDY #7
load_digits
; get the first digit and store it
LDA (first_digit),Y
AND #$F0
STA result
; get the second digit and store it
LDA (second_digit),Y
AND #$0F
ORA result
STA result
; loop until done
DEY
BPL load_digits
; etc.
digit_0
BYTE %01000100
BYTE %11101110
BYTE %10101010
BYTE %10101010
BYTE %10101010
BYTE %10101010
BYTE %11101110
BYTE %01000100
digit_1
BYTE %11101110
BYTE %01000100
BYTE %01000100
BYTE %01000100
BYTE %01000100
BYTE %01000100
BYTE %11001100
BYTE %01000100
; etc.
Michael