Jump to content
IGNORED

Detect 2nd POKEY


Recommended Posts

Today, I wanted to familiarize myself with playing LZSS tunes. The player source code from DSMC is for mono, so I'd like to add duplication of channels in there is 2nd POKEY (e.g. "double mono").

I checked the original detection routine that comes with MADS and found several things that do not seem 100% correct.

 

https://github.com/tebe6502/Mad-Assembler/blob/master/examples/stereo_detect.asm

* -----------------------------
* |second POKEY detect routine|
* | answer in A register:     |
* |$00 - absent $80 - present |

 

- It does not return $00, but can also return $01.

- It uses "much" runtime due to the VCOUNT-based loops

- There are no labels/comments

 

Here's the proposal I came up with. It should be faster and shorter and correct. Tested so far in Altirra. Feedback is welcome.

 

pokmsk = $10

wsync = $d40a

nmien = $d40e

audf1 = $d200

audc1 = $d201

audctl = $d208 ;Audio control

stimer = $d209 ;Start all POKEY timers

irqen = $d20e ;Interrupts enable

irqst = $d20e ;Interrupts status

skctl = $d20f ;Scan keyboard control

 

.proc detect_stereo ;OUT: <A>=0 (single POKEY), 1 (dual POKEY)

 

offset = $10 ;Address offset of the 2nd POKEY

 

sei

lda #$03 ;Reset mask and bit mask for irqst

sta skctl+offset ;Reset 2nd POKEY

lda #$40 ;Switch channel 1 to 1.77 Mhz

sta audctl+offset

ldx #0 ;<X>:=0

stx audc1+offset ;Maximum frequency for 1st POKEY timer on 2nd POKEY

stx audf1+offset

inx ;<X>:=1

stx irqen+offset ;Enable 1st POKEY timer interrupt on 2nd POKEY

stx stimer+offset ;Start POKEY timers on 2nd POKEY

txa ;<A>:=1

ldx irqen

and irqst ;Check if interrupt flag for first timer is set on first POKEY

 

stx irqen ;Reset the bits in irqst

cli

rts

.endp

 

Link to comment
Share on other sites

https://github.com/tebe6502/Mad-Pascal/blob/master/lib/misc.pas

 

function DetectStereo: Boolean; assembler;
(*
@description:
Second POKEY detect routine

<http://atariki.krap.pl/index.php/Programowanie:_Detekcja_stereo>

author: KMK

@returns: X = 0 mono
@returns: X = 1 stereo

*)
asm
	txa:pha

	ldx #$00
	stx $d20f	;halt pokey 0
	stx $d21f	;halt pokey 1
	ldy #$03
	sty $d21f	;release pokey 1

	sta $d40a	;delay necessary for
	sta $d40a	;accelerator boards

	lda #$ff
loop	and $d20a	;see if pokey 0 is halted ($d20a = $ff)
	inx
	bne loop

	sty $d20f

	cmp #$ff
	bne mono

	inx
mono
	stx Result

	pla:tax
end;

 

  • Thanks 1
Link to comment
Share on other sites

The RANDOM one IMO would probably be simplest and best.

The time it takes - does that matter much?  You really only need to do it when the program starts and on warmstart.

About the only way the user could disable a 2nd Pokey by software method would be a hotkey or Monitor which would be pretty unlikely (real machine)

Of course you can change many config items on the fly in emulation but do we need to worry that much?

Link to comment
Share on other sites

Posted (edited)
9 hours ago, Rybags said:

About the only way the user could disable a 2nd Pokey by software method would be a hotkey or Monitor which would be pretty unlikely (real machine)

U1MB firmware controlled stereo upgrades are extremely common these days, although the detection code happens to run in ROM in those circumstances, so should be immune to CPU acceleration (and occuring only on warm/coldstart as you say).

Edited by flashjazzcat
Link to comment
Share on other sites

21 hours ago, Rybags said:

The RANDOM one IMO would probably be simplest and best.The time it takes - does that matter much? 

No, time of course does not really matter, but the VCOUNT loops in the original routine from Seban result of quite some additional initialization/cleanup. From what I written above, I also consider the KMK method the way to go and use it now. Thanks everybody for their input.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...