Hi people, I am again facing the debug of a cycle accurate PCM player,
have a look at this code (compile with sjasm plus)
;------------------
MACRO PsgW reg,value
ld a,reg ; select AY channel A volume register ; 7+1
out (#A0),a ; 11+1
ld a,value ; 7+1
out (#A1),a ; and write back to the AY ; 11+1
ENDM ; total 36+4 = 40T
;------------------
MACRO Wait28
.4 nop ; 5*4 = 20
cp 0 ; 8
ENDM ; total 28
MACRO Wait68
.2 ex (sp),hl ; 20*2 =40
Wait28
ENDM ; total 68
;------------------
MACRO next reg
ld a,(hl) ; 8
.4 rrca ; 4*5
and 15 ; 8
ld reg,a ; 5
ld a,(hl) ; 8
and 15 ; 8
exx ; 5
ld reg,a ; 5
exx ; 5
inc hl ; 7
ENDM ; tot = 79
;------------------
OUTPUT wavplay.com
ORG 100h
START:
di
PsgW 0,255
PsgW 1,255
PsgW 2,255
PsgW 3,255
PsgW 4,255
PsgW 5,255
PsgW 6,255
PsgW 7,10111111B
;-------------------------------------
; IN HL - Sample Start address
; HL'- Sample length
;-------------------------------------
ld hl, SAMPLE
ld bc,#0101
ld de,bc
exx
ld hl, FINISH-SAMPLE+1
ld c,#A1
.LOOP:
exx ; 5
dec b ; 5
jp nz,waitA ; 11
next b ; 79
1 dec d ; 5
jp nz,waitB ; 11
next d ; 79
2 dec e ; 5
jp nz,waitC ; 11
next e ; 79
3 exx ; 5
ld a,8 ; 8
out (#a0),a ; 12
inc a ; 5
out (c),b ; 14
out (#a0),a ; 12
inc a ; 5
out (c),d ; 14
out (#a0),a ; 12
out (c),e ; 14
Wait28
dec hl ; 7
ld a,h ; 5
or l ; 5
jp nz,.LOOP ; 11
; tot = 447T
ret
waitA Wait68 ; 68
jp 1B ; 11
; tot = 79
waitB Wait68 ; 68
jp 2B ; 11
; tot = 79
waitC Wait68 ; 68
jp 3B ; 11
; tot = 79
; b7b6b5b4|b3b2b1b0
; NumTick |LevVolum
SAMPLE:
include "C:\MATLAB6p5\work\out.txt"
FINISH: