Schrijver
| z80 timing accuracy and M1 cycle
| ARTRAG msx master Berichten: 1686 | Geplaatst: 22 December 2005, 10:03   | Does anyone have details about the accuracy of the emulation
of the z80 timing in openMSX and blueMSX with respect to the s.c. M1 waitstate ?
The M1 waitstate does a HUGE difference in the PSG players that are cycle accurate.
I have been banging my head agains the fact that my 6ch player sounds odd in
openMSX even if on the paper all the frequencies where accurate with errors belove 0,5%
(the same in bluemsx but I didn't have done extensive tests in thi case)
As I do not have a true HW I was thinking to a problem of computations of the timings in my programs, nevertheless I would like to exclude an openMSX problem.
| | jltursan msx professional Berichten: 873 | Geplaatst: 22 December 2005, 18:29   | Where can be found a Z80 opcode table including the extra M1 waitstates?, does it exists anyway?
| | dvik msx master Berichten: 1312 | Geplaatst: 22 December 2005, 18:44   | openMSX and blueMSX does emulate the M1 waitstate. But of course it could be a bug in the emulation that makes it sound bad. What MSX machine are you running in your openMSX?
I've also been writing PSG players that require cycle accuracy. And I tested the emulators (both openMSX and blueMSX against real MSX and it seems to be in tune. If I get some time over xmas I'll do some more tests and double check my players to make sure I'm not remembering wrong.
| | dvik msx master Berichten: 1312 | Geplaatst: 22 December 2005, 18:48   | There are btw a couple of other PSG players that require the M1 waitstate to be emulated correctly. There was a game released last fall where they made a special release to make it playable on emus that doesn't emulate the M1 waitstate, e.g. fMSX and back then also blueMSX (but in blueMSX it's fixed a long time ago).
Anyone remember that game?
| | mars2000you msx master Berichten: 1723 | Geplaatst: 22 December 2005, 19:16   | | | ARTRAG msx master Berichten: 1686 | Geplaatst: 22 December 2005, 20:36   | Yes!! on openmsx 5.2 I hear a differnce between the two versions of the intro tune
and I feel that the tune for "emulators" sounds better,
nevertheless I could be wrong in the sense that I have no musical skills...
Btw I must try my player excluding the m1 state and trying to redo the coding on the melody...
If also in this case the "no m1" sound better the conclusion could only be ....
let me try...
| | dvik msx master Berichten: 1312 | Geplaatst: 22 December 2005, 23:07   | @ARTRAG. I just copied these questions from openMSX mailing list since I'm also very interested in this. I think openMSX and blueMSX have pretty similar timing so if there are bugs in openMSX they may apply to blueMSX as well.
----------------------
The extra M-cycle delay is implemented in openMSX. The timing of the Z80 *should*
be correct. But there can always be bugs of course. There are no known issues
though.
Why do you think the bug is in openMSX (and not in your routines  Did you
test on a real machine?
Can you give a list of Z80 instructions you use and how much T-states you expect
them to take, so we can check those against the openMSX code.
----------- | | mth msx freak Berichten: 192 | Geplaatst: 23 December 2005, 01:09   | There are other possible reasons why a PSG replayer might sound wrong. One such reason would be a bug in the PSG emulation, obviously.
Another reason might be the realtime behaviour of the emulator being wrong, resulting in distorted sound. To test whether this is the case, you can log the sound to a WAV file and play it later instead of having the emulator play it realtime. At least I think that in openMSX sound logging results in perfect playback without realtime artifacts, but I hope Wouter or Manuel can confirm or deny this.
| | ARTRAG msx master Berichten: 1686 | Geplaatst: 23 December 2005, 01:38   | @mth
please I do not have an HW, try to listen the wav file in
http://www.msx.org/Apology-MSX-Update.newspost3455.html
(I recorded it with sound-log of openmsx)
and to run apo.com on a true msx.
Tell me if you hear differences and, in case, what is the best play (emulator or true HW)
the computations where made accounting the m1 cycle and appears both in the excel file
and in the asm file as comments to the code
PS
do you need the .com file ?
I had trubles with te email filters so I couldn't sent it to mrc.
Send me an email and I'll send it back
| | pitpan msx master Berichten: 1379 | Geplaatst: 23 December 2005, 08:05   | I think that cycle-wise PSG emulation is not doable.
The same goes for PPI key-click samples. Although current emulation state is very good, it is not perfect. I think that it is not possible to emulate/reproduce faithfully as in the original hardware. If you listen to 1-bit samples, real MSX sound is smoother than in emulators (provided that you are using a FAST computer). I do not know how to explain this, but sound in emulators is more noisy. Perhaps it is not an emulator problem, but a PC hardware problem. It could be a good idea to implement an additional sound filter to this.
Another hard-to-emulate feature is that the MSX keymatrix can read *ANY* number of keypresses at the same time. For a PC, AFAIK, there is a limit due to hardware design constraints: 3 keys at a time.
| | dvik msx master Berichten: 1312 | Geplaatst: 23 December 2005, 08:31   | Quote:
| I think that cycle-wise PSG emulation is not doable.
|
Do you mean in emulators or in general?
I find synchronous code to be very difficult on real MSXes since minor hardware variations causes some differences in the desired output. I've noticed this when doing some synchronous VDP code for MSX. MSX1 machines seems to differer a bit in timing between models which makes it very hard to get good results on all machines. MSX2 seems to be more standardized and its easier to get similar results on different models.
Maybe it is easier to do synchronous code for the PSG than for the VDP though. Not sure.
On an emulator its typically a lot easier to do synchronous code since the emulation is more static and the behavior is predictable (no variations due to electrical components). So if ARTRAG used a timing table tuned for openMSX the result would probably be quite good. But then it may not sound the same on a real MSX of course.
Another good point pitpan makes is that the sound is typically smoother and warmer on real MSX compared to an emulator. This has several reasons I guess, one is that the electrical components used in the real hardware has built in filtering effects. I'm pretty sure it would be possible for an emulator to get closer with more advanced filters.
| | ARTRAG msx master Berichten: 1686 | Geplaatst: 23 December 2005, 10:09   | Does openmsx have those timings?
;------------------
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 Channel phychan,logchan,reg
exx ; 4 + 1
ld a,logchan ; 7 + 1
xor reg ; flip the appropriate bits of the ; 4 + 1
ld reg,a ; stored levels ; 4 + 1
ld l,a ; 4 + 1
PsgW phychan,(hl) ; 40
exx ; 4 + 1
ENDM ; total 40+25+8 = 73T
;------------------
macro onestep
dec b ; 4+1
jp nz,.Cc ; 10+1
ld a,(bchan) ; 14
ld b,a ; 7+1
Channel 8,01b,b ; 73
.Cc
dec c ; 4+1
jp nz,.Dc ; 10+1
ld a,(cchan) ; 14
ld c,a ; 7+1
Channel 8,10b,b
.Dc
dec d ; 4+1
jp nz,.Ec ; 10+1
ld a,(dchan) ; 14
ld d,a ; 7+1
Channel 9,01b,c
.Ec
dec e ; 4+1
jp nz,.Hc ; 10+1
ld a,(echan) ; 14
ld e,a ; 7+1
Channel 9,10b,c
.Hc
dec h ; 4+1
jp nz,.Lc ; 10+1
ld a,(hchan) ; 14
ld h,a ; 7+1
Channel 10,01b,d
.Lc
dec l ; 4+1
jp nz,.Bc ; 10+1
ld a,(lchan) ; 14
ld l,a ; 7+1
Channel 10,10b,d
.Bc
endm
;------------------
OUTPUT apo.com
org #100
PsgW 7,10111111b ; turn off AY's wave generator ; 40T
main di
exx
ld bc,#00
ld de,bc
ld hl,vols
exx
ld ix,dat
ld iyl,0
mainloop
ldi a,(ix) : ld (bchan),a
ldi a,(ix) : ld (cchan),a
ldi a,(ix) : ld (dchan),a
ldi a,(ix) : ld (echan),a
ldi a,(ix) : ld (hchan),a
ldi a,(ix) : ld (lchan),a
ldi a,(ix)
or a
jp z,fin
ld iyh,a
; registers b, c, d, e, h, l contain period counters for each channel.
; when they reach zero flip the square wave.
loop
rept 4
onestep ; 6*16 | 6*16 + N*(73+8+14)
endm
dec iyl ; 8+2
jp nz,loop ; 10+1
dec iyh ; 8+2
jp nz,loop ; 10+1
; mean total loop time 22/4 + 6*16 + 22/256/4 +6*5 = 101,52148T
jp mainloop
fin
ei
ret
;------------------
bchan db 0
cchan db 0
dchan db 0
echan db 0
hchan db 0
lchan db 0
ALIGN 256
vols db 0,13,13,15
dat
db 137 , 92 , 69 , 46 , 34 , 27 , 16
db 137 , 92 , 69 , 46 , 34 , 27 , 16
db 137 , 91 , 68 , 41 , 34 , 26 , 16
db 134 , 89 , 38 , 33 , 27 , 22 , 15
db 101 , 67 , 45 , 38 , 34 , 22 , 15
db 102 , 68 , 51 , 40 , 34 , 25 , 15
db 102 , 68 , 51 , 45 , 34 , 27 , 15
db 103 , 82 , 61 , 52 , 41 , 31 , 16
db 186 , 111 , 70 , 55 , 47 , 35 , 16
db 186 , 111 , 70 , 55 , 47 , 35 , 16
db 184 , 92 , 61 , 46 , 37 , 31 , 16
db 137 , 92 , 69 , 46 , 34 , 27 , 16
db 183 , 92 , 61 , 46 , 34 , 27 , 23
db 184 , 92 , 61 , 46 , 37 , 31 , 8
db 184 , 92 , 62 , 52 , 37 , 31 , 31
db 137 , 92 , 69 , 46 , 34 , 27 , 16
db 137 , 92 , 69 , 46 , 34 , 27 , 16
db 137 , 91 , 68 , 41 , 34 , 26 , 16
db 134 , 89 , 38 , 33 , 27 , 22 , 15
db 101 , 67 , 45 , 38 , 34 , 22 , 15
db 102 , 68 , 51 , 40 , 34 , 25 , 15
db 102 , 68 , 51 , 45 , 34 , 27 , 15
db 103 , 82 , 61 , 52 , 41 , 31 , 16
db 186 , 111 , 70 , 55 , 47 , 35 , 16
db 186 , 111 , 70 , 55 , 47 , 35 , 16
db 184 , 92 , 61 , 46 , 37 , 31 , 16
db 137 , 92 , 69 , 46 , 34 , 27 , 16
db 184 , 92 , 61 , 46 , 34 , 31 , 16
db 184 , 92 , 62 , 52 , 37 , 31 , 8
db 185 , 92 , 62 , 52 , 37 , 35 , 8
db 139 , 93 , 70 , 55 , 46 , 35 , 32
block 7,0
;A#2 F-3 A#3 F-4 A#4 D-5 2 beats
;A#2 F-3 A#3 F-4 A#4 D-5 2
;A#2 F-3 A#3 G-4 A#4 D#5 2
;A#2 F-3 G#4 A#4 D-5 F-5 2
;D#3 A#3 F-4 G#4 A#4 F-5 2
;D#3 A#3 D#4 G-4 A#4 D#5 2
;D#3 A#3 D#4 F-4 A#4 D-5 2
;D#3 G-3 C-4 D#4 G-4 C-5 2
;F-2 D-3 A#3 D-4 F-4 A#4 2
;F-2 D-3 A#3 D-4 F-4 A#4 2
;F-2 F-3 C-4 F-4 A-4 C-5 2
;A#2 F-3 A#3 F-4 A#4 D-5 2
;F-2 F-3 C-4 F-4 A#4 D-5 3
;F-2 F-3 C-4 F-4 A-4 C-5 1
;F-2 F-3 C-4 D#4 A-4 C-5 4
;A#2 F-3 A#3 F-4 A#4 D-5 2
;A#2 F-3 A#3 F-4 A#4 D-5 2
;A#2 F-3 A#3 G-4 A#4 D#5 2
;A#2 F-3 G#4 A#4 D-5 F-5 2
;D#3 A#3 F-4 G#4 A#4 F-5 2
;D#3 A#3 D#4 G-4 A#4 D#5 2
;D#3 A#3 D#4 F-4 A#4 D-5 2
;D#3 G-3 C-4 D#4 G-4 C-5 2
;F-2 D-3 A#3 D-4 F-4 A#4 2
;F-2 D-3 A#3 D-4 F-4 A#4 2
;F-2 F-3 C-4 F-4 A-4 C-5 2
;A#2 F-3 A#3 F-4 A#4 D-5 2
;F-2 F-3 C-4 F-4 A#4 C-5 2
;F-2 F-3 C-4 D#4 A-4 C-5 1
;F-2 F-3 C-4 D#4 A-4 A#4 1
;A#2 F-3 A#3 D-4 F-4 A#4 4
| | manuel msx guru Berichten: 3450 | Geplaatst: 23 December 2005, 11:36   | Quote:
| Another reason might be the realtime behaviour of the emulator being wrong, resulting in distorted sound. To test whether this is the case, you can log the sound to a WAV file and play it later instead of having the emulator play it realtime. At least I think that in openMSX sound logging results in perfect playback without realtime artifacts, but I hope Wouter or Manuel can confirm or deny this.
|
Sorry to disappoint you, but we still have only EmuTime synced sound logging. AFAIK Wouter was working on a realtime soundlogging thingie, but he never finished it. Maybe something for openMSX 0.6.1? | | manuel msx guru Berichten: 3450 | Geplaatst: 23 December 2005, 12:50   | | | m9710797 msx friend Berichten: 1 | Geplaatst: 24 December 2005, 14:45   | Quote:
|
ld b,a ; 7+1
ld c,a ; 7+1
ld d,a ; 7+1
ld e,a ; 7+1
ld h,a ; 7+1
ld l,a ; 7+1
|
I checked timimg for all instructions. It's the same as the timing in openMSX except for the instructions listed above. They only take 5 cycles. | |
| |
| |