Welcome, Guest. Please login or register.


Author Topic: Q&A (Read 56380 times)

Offline g0blinish

  • EP fan
  • *
  • Posts: 110
Re: Q&A
« Reply #135 on: 2016.January.12. 09:24:47 »
http://map.grauw.nl/sources/external/z80bits.html

seems here is an error with multiplication with squares

Offline Zozosoft

  • Global Moderator
  • EP addict
  • *
  • Posts: 14709
  • Country: hu
    • http://enterprise.iko.hu/
Re: Q&A
« Reply #136 on: 2016.January.12. 09:32:00 »
Thanks.

Zozo, could you for completeness include the code for multiplication and division procedures :oops:

Code: ZiLOG Z80 Assembler
  1. MUL_DE_BC       LD HL,0
  2.                 SLA E
  3.                 RL D
  4.                 JR NC,MUL1
  5.                 LD H,B
  6.                 LD L,C
  7. MUL1            EXX
  8.                 LD B,15
  9. MUL2            EXX
  10.                 ADD HL,HL
  11.                 RL E
  12.                 RL D
  13.                 JR NC,MUL3
  14.                 ADD HL,BC
  15.                 JR NC,MUL3
  16.                 INC DE
  17. MUL3            EXX
  18.                 DJNZ MUL2
  19.                 EXX
  20.                 RET
  21. DIV_ABC_DE      LD HL,0
  22.                 EXX
  23.                 LD B,24
  24. DIV1            EXX
  25.                 ;DB 0CBH,31H ;SLL C
  26.               SLA C
  27.               SET 0,C
  28.                 RL B
  29.                 RLA
  30.                 ADC HL,HL
  31.                 SBC HL,DE
  32.                 JR NC,DIV2
  33.                 ADD HL,DE
  34.                 DEC C
  35. DIV2            EXX
  36.                 DJNZ DIV1
  37.                 EXX
  38.                 RET

Offline IstvanV

  • EP addict
  • *
  • Posts: 4822
Re: Q&A
« Reply #137 on: 2016.January.13. 13:37:34 »
Using these routines, it is possible to optimize the code somewhat as shown above. Instead of
Code: ZiLOG Z80 Assembler
  1.                 LD BC,HL
  2.                 LD DE,1000
  3.                 CALL MUL_DE_BC
  4.                 LD BC,HL
  5.                 LD A,E
  6.                 LD DE,12485
  7.                 CALL DIV_ABC_DE
  8.                 OR A
  9.                 LD DE,6243
  10.                 SBC HL,DE
  11.                 JR C,NOTROUND
  12.                 INC C
  13. NOTROUND

One can first add 6 (32768 / 5249) and then multiply by 5249 (65536 * 1000 / 12485). I added 8 instead to account for the time taken by the IRQ handler. The result is then in DE.
Code: ZiLOG Z80 Assembler
  1.                 LD BC, 6
  2.                 ADD HL, BC
  3.                 LD BC, HL
  4.                 LD DE, 5249
  5.                 CALL MUL_DE_BC
  6.                 LD BC, DE
C compilers on PC use similar tricks to replace division by a constant with multiplication, which is faster.
« Last Edit: 2016.January.13. 13:52:52 by IstvanV »

Offline ssr86

  • EP user
  • *
  • Posts: 355
  • Country: pl
Re: Q&A
« Reply #138 on: 2016.January.14. 17:59:40 »
@IstvanV I saw that in your sprite example you were able to count the exact time of the drawing code. I hope it's not a stupid question to ask you for the principles of applying the waits to instruction timings... I guess it's based on the source/destination memory segment (if it has wait states) or is there another factor?

I'm asking because I'd need a way to limit the number of sprites drawn in a single frame. I thought that I could calculate the upper limit of the common code and then limit the number of sprites drawn in one frame to fit in single/double frame time. Then the sprites that wouldn't be drawn in the previous frame would get priority in the next frame. This would produce spriteflicker like on the nes but would allow to make the game in 50fps if chosen to... So I thought having the calculated available time (from Zozo and yours code) I would substract the cost of the common code (and/or optional code) and then while drawing the sprites I would substract their cost until I know I won't be able to draw more...

Maybe someone has another idea?

Well, I guess that an alternative would be to set an interrupt somewhere near the end of the frame where a marker would be set to inform that one cannot afford to draw more sprites.... However it's a less accurate way and that key code should be dealt with at the end of the frame which may not be the case...
« Last Edit: 2016.January.14. 18:07:29 by ssr86 »

Offline IstvanV

  • EP addict
  • *
  • Posts: 4822
Re: Q&A
« Reply #139 on: 2016.January.14. 18:49:24 »
@IstvanV I saw that in your sprite example you were able to count the exact time of the drawing code. I hope it's not a stupid question to ask you for the principles of applying the waits to instruction timings... I guess it's based on the source/destination memory segment (if it has wait states) or is there another factor?

Wait states generated by DAVE (if enabled on port BFh) are simple, they add 1 cycle to all memory accesses (00h) or only M1 reads (04h). The latter are the first byte of simple instructions with no prefix, or the first two bytes with CB/DD/ED/FDh prefix. Also, according to tests by Zozosoft, it seems that DAVE waits 2 cycles on turbo machines. But in programs where speed is important, wait states are disabled, so all the above does not matter.

Video memory and NICK I/O port timing are more complex: within each 889846 Hz "slot" (1 character), the Z80 is allowed access to one byte at a specific time, and it always needs to wait at least a certain amount of time (a few ns more than 5/16 of a character, and there is also few ns difference depending on the type of access - normal memory, M1 memory, and I/O). This is implemented by the NICK chip halting the Z80's clock, which it can do in 1/2 clock cycles (1/8000000 s on normal non-turbo machines). There is a test run on real machines here that measures the average time between video memory accesses at various intervals in Z80 cycles.

For the calculations in the sprite code, I used a simplified model: add 1.5 cycles to the time between the video memory accesses, and then round up the result to an integer multiple of 4.5 cycles, and that is the real amount of time, with the wait states (stopped Z80 clock) added. In other words, the best case is 1.5 cycles of wait, and the worst case is 5.5 cycles. This is not entirely accurate, but it gives a reasonable estimate.

When calculating video memory timing, it should also be taken into account exactly when the accesses occur within the instruction. This can be found in the Z80 documentation. For example, an LD (HL), A instruction is two memory accesses, an M1 read at 2 cycles, and a normal write at 6.5 cycles.

Offline ssr86

  • EP user
  • *
  • Posts: 355
  • Country: pl
Re: Q&A
« Reply #140 on: 2016.January.22. 11:33:33 »
@IstvanV
Could you fill such table:
Code: [Select]
|read memory type|write memory type| M1 delay| read delay| write delay| io read delay| io write delay|
It's for a person that is writing a z80 profiler so maybe he could add an enterprise mode.

Offline ssr86

  • EP user
  • *
  • Posts: 355
  • Country: pl
Re: Q&A
« Reply #141 on: 2016.April.24. 12:22:45 »
Is someone able to provide some working examples/routines for doing some ingame sound effects (noise-based or any other). I'd be really grateful.
« Last Edit: 2016.April.24. 12:30:11 by ssr86 »

Offline geco

  • Moderator
  • EP addict
  • *
  • Posts: 7069
  • Country: hu
    • Támogató Támogató
Re: Q&A
« Reply #142 on: 2016.April.24. 19:15:21 »
I can provide you digi effects only, other possibility to take out  effects from games, or if someone creates effects in basic then it could be adapted into your game without EXOS calls, I created a small routine which save DAVE registers during Basic sound playback, I could insert I Love Rock'n'Roll into Bricky Prise with this solution.

Offline ssr86

  • EP user
  • *
  • Posts: 355
  • Country: pl
Re: Q&A
« Reply #143 on: 2016.April.24. 23:56:17 »
hmm...
I dont really know how to take out sounds from games as I don't know what to look for. Maybe I could achieve something from basic... So I would appreciate the routine you mentioned.
My problem is I've never done sound effects so I don't really know how to achieve what I'm looking for...
Time is running out for the deadline and I feel I need to do some shortcuts to actually complete something...

Offline IstvanV

  • EP addict
  • *
  • Posts: 4822
Re: Q&A
« Reply #144 on: 2016.April.25. 13:12:16 »
For experimenting with DAVE sound generators, there is a davetest utility that lets you try all the effects.

I created a small routine which save DAVE registers during Basic sound playback, I could insert I Love Rock'n'Roll into Bricky Prise with this solution.

I used a somewhat similar solution with a Lua script to capture the music from Enterball for the Spectrum 128 conversion. This could be modified (and simplified) for playback on the Enterprise, although the file format is not very efficient, the converted Enterball music takes up almost 4 KB.

Offline geco

  • Moderator
  • EP addict
  • *
  • Posts: 7069
  • Country: hu
    • Támogató Támogató
Re: Q&A
« Reply #145 on: 2016.April.25. 15:51:43 »
You can try to ask Szipucsu, or Endi to create effects, they played a lot with sounds, if you have the sounds and you did not use Istvan's solution, then you can send me the snapshots, and i will give you the raw data, i can share also the code, but it is only a direct assembly to EP128emu as I remember, and when you entered it dave registers save starts

Offline ssr86

  • EP user
  • *
  • Posts: 355
  • Country: pl
Re: Q&A
« Reply #146 on: 2016.April.26. 08:35:31 »
The davetest doesn't help uch as you can't change the envelope etc.
What about the possibility to port ay sfx? Is it doable and pretty straightforward?
If I won't be able to get it done in basic or ay then I guess I'll ask szipucsu or endi...
I'd also want to learn how it's done...

I'll once again switch to other things then... as there is still quite a lot to do...

Offline geco

  • Moderator
  • EP addict
  • *
  • Posts: 7069
  • Country: hu
    • Támogató Támogató
Re: Q&A
« Reply #147 on: 2016.April.26. 08:41:54 »
AY SFX can be ported also, snd if you have some with sources, it would be the easiest one.

Offline ssr86

  • EP user
  • *
  • Posts: 355
  • Country: pl
Re: Q&A
« Reply #148 on: 2016.April.26. 09:13:20 »
I've googled this ayfxedit from http://shiru.untergrund.net/files/ayfxedit04.zip but I'm currently at work so can't really test it. But it seems to have many example effects from games. Anyone could tell me how to port the spectrum sfx to ep? Is there a tool for this?

Offline geco

  • Moderator
  • EP addict
  • *
  • Posts: 7069
  • Country: hu
    • Támogató Támogató
Re: Q&A
« Reply #149 on: 2016.April.26. 10:16:32 »
I've googled this ayfxedit from http://shiru.untergrund.net/files/ayfxedit04.zip but I'm currently at work so can't really test it. But it seems to have many example effects from games. Anyone could tell me how to port the spectrum sfx to ep? Is there a tool for this?
Are they contain only sound RAW data, or data + player assembly?
if it contains the player also, then you should insert to the player István's AY emulation routine, if it does not contain player, just raw data, then there are 2 possibilities, convert the data to DAVE and create a simple player, or does not convert, create a simple player for AY, and insert István's AY emulation routine.