BigEd wrote:
There's an interesting trick in
the code Daryl added to Microchess:
Code:
AND #$01 ; is board square white or blk?
BNE Pout25 ; black, print space
LDA #"*" ; white, print *
.BYTE $2c ; used to skip over LDA #$20
Pout25 LDA #$20 ; ASCII space
JSR syschout ; print one ASCII CHR - space
This is an ancient programming technique that has been around as long as the 6502. A similar method for a single byte jump would be:
Code:
clc
.byte $24 ;BIT zp instruction
sec
...program continues...
If executed from the CLC instruction, the MPU will see:
Code:
clc
bit $38 ;BIT zp instruction
sec
...program continues...
You should consider that using the BIT opcode as illustrated in Daryl's code opens the door to a potential booby-trap. Depending on the value being loaded into the accumulator at POUT25, the BIT operation could inadvertently touch a chip register, with undefined results. For example, suppose the code is:
Code:
AND #$01
BNE Pout25
LDA #"*"
.BYTE $2c
Pout25 LDA #$D0
JSR syschout
What the MPU would see immediately before POUT25 would be BIT $D0A9. A lot of 6502 systems have their I/O in the $D000 block and often do not fully decode the address space. Depending on the I/O space address decoding, that BIT $D0A9 could be seen by hardware as BIT $D009. On my POC unit:
Code:
D009 sr_92b =io_acia+dr_srb ;ch B status (R)
which means a BIT on that address causes a read operation on the DUART's channel B status register. No telling what might happen in such a case.