Detecting POKEY
From 8BitDev.org - Atari 7800 Development Wiki
Detection Code for POKEY in different locations
The following code (taken from 7800Basic, and originally adapted from GroovyBee's POKEY detection routine) checks both common POKEY locations ($450, and $4000) for the presence of a POKEY chip.
The code requires a pair of zero page locations (pokeybaselo and pokeybasehi) and another location (pokeydetected). If a POKEY chip is found, pokeydetected=0 and (pokeybaselo) will point at the POKEY memory location, through which you can access the POKEY registers indirectly. The POKEY will be left in an initialized ready-to-use state.
; Pokey register relative locations, since its base may be different ; depending on the hardware. PAUDF0 = $0 ; extra audio channels and frequencies PAUDC0 = $1 PAUDF1 = $2 PAUDC1 = $3 PAUDF2 = $4 PAUDC2 = $5 PAUDF3 = $6 PAUDC3 = $7 PAUDCTL = $8 ; Audio Control PRANDOM = $A ; 17 bit polycounter pseudo random PSKCTL = $F ; Serial Port control detectpokeylocation ;XBoard/XM... lda #%00010000 sta $470 ; tell XCTRL to enable the POKEY ldx #1 detectpokeyloop lda POKEYCHECKLO,x sta pokeybaselo lda POKEYCHECKHI,x sta pokeybasehi jsr checkforpokey lda pokeydetected beq foundpokeychip dex bpl detectpokeyloop foundpokeychip sta pokeydetected rts POKEYCHECKLO .byte <$4000, <$0450 POKEYCHECKHI .byte >$4000, >$0450 checkforpokey ldy #$0f lda #$00 sta pokeydetected resetpokeyregistersloop sta (pokeybase),y dey bpl resetpokeyregistersloop ldy #PAUDCTL sta (pokeybase),y ldy #PSKCTL sta (pokeybase),y ; let the dust settle... nop nop nop ; we're in reset, so the RANDOM register should read $ff... ldy #PRANDOM lda (pokeybase),y cmp #$ff bne nopokeydetected ; take pokey out of reset... ldy #PSKCTL lda #3 sta (pokeybase),y ldy #PAUDCTL lda #0 sta (pokeybase),y ; let the dust settle again... nop nop nop ; we're out of reset, so RANDOM should read non-$ff... ldy #PRANDOM lda (pokeybase),y cmp #$ff beq checkpokeyoncemore ;one $ff might be a fluke. try again... rts checkpokeyoncemore lda (pokeybase),y cmp #$ff beq nopokeydetected rts nopokeydetected dec pokeydetected rts