Xemu [doxygen]  hyppo 0a42be3a057156924bc1b626a687bd6e27349c45 @ Sat 19 Mar 02:15:11 CET 2022
apu.c
Go to the documentation of this file.
1 /* Xep128: Minimalistic Enterprise-128 emulator with focus on "exotic" hardware
2  Copyright (C)2014,2015,2016 LGB (Gábor Lénárt) <lgblgblgb@gmail.com>
3  http://xep128.lgb.hu/
4 
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14 
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
18 
19 #include "xep128.h"
20 #include "apu.h"
21 #include "cpu.h"
22 
23 #include <math.h>
24 
25 /* From my JSep emulator:
26  *
27  * (C)2014 Gábor Lénárt LGB http://ep.lgb.hu/jsep/
28  * Part of my JavaScript based Enterprise-128 emulator ("JSep" aka "webemu").
29  * Am9511 "APU" FPU emulation, somewhat (ehhh, a lot!) incorrect
30  *
31  * Thanks to Povi for testing APU support.
32  *
33  * http://www.hartetechnologies.com/manuals/AMD/AMD%209511%20FPU.pdf
34  * http://www.joelowens.org/z80/am9511algorithms.pdf
35  * http://www.joelowens.org/z80/am9511fpmanual.pdf
36  *
37  * Major problems with my emulation:
38  *
39  * Precision: converts data between APU formats and JS numeric, real Am9511 may give a sightly different results in case of floats.
40  * Timing: uses constant timings, real APU varies execution times depending on the operands.
41  * Stack content: real APU destroys some elements in case of some OPS other than TOS. This is not emulated.
42  * APU status: I am not always sure what status flags modified and how.
43  * Results: I am not always sure even about the result of ops. Eg: SMUL/SMUU, what happens on signed values, etc, result can be even WRONG.
44  * Usage: emulation always assumes Z80 will be stopped, no WAIT/SRV etc (so bit 7 of command does not count either)
45  * Cleanness: my code uses pop/push primitives which is often quite expensive, but the code is more compact and it's enough for a few MHz chip emulation in JS still :)
46  */
47 
48 static Uint8 _apu_stack[16];
49 static int _apu_tos;
50 static Uint8 _apu_status;
51 
52 // Note: NEGARG,ZERODIV,LARGE are truely not independent, you should not mix them, but use only one! Others can be "mixed"
53 
54 #define _APU_F_CARRY 1
55 #define _APU_F_OVERFLOW 2
56 #define _APU_F_UNDERFLOW 4
57 #define _APU_F_NEGARG 8
58 #define _APU_F_ZERODIV 16
59 #define _APU_F_LARGE 24
60 #define _APU_F_ZERO 32
61 #define _APU_F_SIGN 64
62 //#define _APU_F_BUSY 128 // this is not used, as APU for EP is used to stop Z80 while working, so Z80 will never found this bit set, thus there is no need to set ...
63 
64 
65 void apu_reset ( void )
66 {
67  _apu_status = 0;
68  _apu_tos = 0;
69  memset(_apu_stack, 0, sizeof _apu_stack);
70 }
71 
72 
74 {
75  return _apu_status;
76 }
77 
78 
79 static void _apu_move( int n)
80 {
81  _apu_tos = (_apu_tos + n) & 0xF;
82 }
83 
84 
85 static Uint8 _apu_look8(int depth)
86 {
87  return _apu_stack[(_apu_tos - depth) & 0xF];
88 }
89 
90 
91 static Uint8 _apu_pop8()
92 {
93  _apu_move(-1);
94  return _apu_look8(-1);
95 }
96 
97 
99 {
100  return _apu_pop8();
101 }
102 
103 
104 static void _apu_push8(Uint8 data)
105 {
106  _apu_move(1);
107  //_apu_tos = (_apu_tos + 1) & 0xF;
108  _apu_stack[_apu_tos] = data; // will be trucated to byte
109 }
110 
111 
113 {
114  _apu_push8(data);
115 }
116 
117 
118 static int _apu_pop_fix16(void) {
119  int data = _apu_pop8() << 8;
120  data |= _apu_pop8();
121  if (data & 0x8000) data = data - 0x10000; // two's complement correction
122  return data;
123 }
124 
125 // push fix16 format, also updates the status (zero, sign, overflow)
126 static void _apu_push_fix16(int data) {
127  if (data == 0) _apu_status |= _APU_F_ZERO; // zero flag
128  else if (data < 0) {
129  _apu_status |= _APU_F_SIGN; // negative flag
130  data += 0x10000; // two's complement correction
131  }
132  if (data > 0xFFFF || data < 0) _apu_status |= _APU_F_OVERFLOW; // overflow flag [WTF]
133  _apu_push8(data);
134  _apu_push8(data >> 8);
135 }
136 
137 static Sint64 _apu_pop_fix32(void) {
138  Sint64 data = _apu_pop8() << 24;
139  data |= _apu_pop8() << 16;
140  data |= _apu_pop8() << 8;
141  data |= _apu_pop8();
142  if (data > 2147483647L) data = data - 4294967296L; // two's complement correction
143  return data;
144 }
145 
146 static void _apu_push_fix32(Sint64 data) {
147  if (data == 0) _apu_status |= _APU_F_ZERO;
148  else if (data < 0) {
149  _apu_status |= _APU_F_SIGN;
150  data += 4294967296L;
151  }
152  if (data > 4294967295UL || data < 0) _apu_status |= _APU_F_OVERFLOW;
153  _apu_push8(data);
154  _apu_push8(data >> 8);
155  _apu_push8(data >> 16);
156  _apu_push8(data >> 24);
157 }
158 
159 /* Foreword for FLOAT handling: I use natural float (well, double ...)
160  * numberic format of C, using pop/push APU functions to convert from/to.
161  * This is kinda messy, and not bit-exact emulation of Am9511.
162  * Even my crude push/pop functions can be done much better!!
163  */
164 
165 
166 static double _apu_pop_float()
167 {
168  int exp = _apu_pop8();
169  int data = _apu_pop8() << 16;
170  double fdata;
171  data |= _apu_pop8() << 8;
172  data |= _apu_pop8();
173  if (!(data & 0x800000)) return 0.0; // MSB of mantissa must be 1 always, _except_ for the value zero, where all bytes should be zero (including the MSB of mantissa)
174  if (exp & 128) data = -data;
175  if (exp & 64) exp = (exp & 63) - 64; else exp &= 63;
176  fdata = pow(2, exp) * ((double)data / 16777216.0);
177  //DEBUG("APU: float is internally pop'ed: %f" NL, fdata);
178  return fdata;
179 }
180 
181 
182 static void _apu_push_float(double data)
183 {
184  int neg, exp , i;
185  if (!isfinite(data)) { // this should be true for the whole condition of argument is NaN of Infinity ...
186  _apu_push8(0); // bad result for NaN, but something should be there (_apu_move() would be better one to "rollback" the stack?!)
187  _apu_push8(0);
188  _apu_push8(0);
189  _apu_push8(0);
190  _apu_status |= _APU_F_LARGE;
191  return;
192  }
193  if (data == 0) { // if value is zero, we handle it as a special case, as logarithm function would panic on value of zero.
194  _apu_push8(0);
195  _apu_push8(0);
196  _apu_push8(0);
197  _apu_push8(0);
198  _apu_status |= _APU_F_ZERO; // zero flag
199  return;
200  }
201  neg = data < 0; // remember the sign of the value (bool)
202  data = fabs(data);
203  exp = log2(data);
204  data = data / pow(2, exp);
205  i = (data * 16777216.0);
206  if (i >= 16777216) {
207  // ehm, not normalized mantissa or such a problem?
208  i >>= 1;
209  exp++;
210  } else if (i == 0) {
211  exp = 0;
212  _apu_status |= _APU_F_ZERO | _APU_F_UNDERFLOW; // since we handled zero case at the begining, zero value here means the underflow-gap, I guess
213  }
214  if (exp > 63) {
215  exp &= 63;
216  _apu_status |= _APU_F_OVERFLOW;
217  } else if (exp < -64) {
218  //exp = -((-exp) & 63); // WRONG! TODO, FIXME, HELP, ETC :D
219  exp = ((64 + exp) & 63) | 64;
220  _apu_status |= _APU_F_OVERFLOW;
221  } else if (exp < 0) {
222  exp = ((64 + exp) & 63) | 64;
223  }
224  if (neg) {
225  exp |= 128;
226  _apu_status |= _APU_F_SIGN; // negative flag
227  }
228  //if (data && (!(data & 0x800000)))
229  // DEBUG("APU: warning: irregular manitssa: ", data);
230  // Pushing 8 bit bytes onto the APU stack
231  _apu_push8(i);
232  _apu_push8(i >> 8);
233  _apu_push8(i >> 16);
234  _apu_push8(exp); // this byte holds the exponent, and also the sign of the mantissa
235  //if (data == 0) _apu_status |= _APU_F_UNDERFLOW; // hmmm. zero case is handled at the beginning, so if it's zero we are in the underflow-gap of the format. or whatever :D
236 }
237 
238 
239 // set S and Z flags of status on TOS, interpreting it as fixed 16 format
240 static void _apu_sz_fix16(void) {
241  if (_apu_look8(0) & 128) _apu_status |= _APU_F_SIGN;
242  if (_apu_look8(0) + _apu_look8(1) == 0) _apu_status |= _APU_F_ZERO; // this testing method for zeroness works as apu_look8() gives back only unsigned bytes ...
243 }
244 static void _apu_sz_fix32(void) {
245  if (_apu_look8(0) & 128) _apu_status |= _APU_F_SIGN;
246  if (_apu_look8(0) + _apu_look8(1) + _apu_look8(2) + _apu_look8(3) == 0) _apu_status |= _APU_F_ZERO;
247 }
248 static void _apu_sz_float(void) {
249  if (_apu_look8(0) & 128) _apu_status |= _APU_F_SIGN;
250  if ((_apu_look8(1) & 128) == 0) _apu_status |= _APU_F_ZERO; // we use only a single bit to test the zeroness of a float.
251 }
252 
253 
254 static void _apu_xchg(int d1, int d2) {
255  Uint8 n = _apu_look8(d1);
256  _apu_stack[(_apu_tos - d1) & 0xF] = _apu_look8(d2);
257  _apu_stack[(_apu_tos - d2) & 0xF] = n;
258 }
259 static void _apu_copy(int from, int to) {
260  _apu_stack[(_apu_tos - to) & 0xF] = _apu_look8(from);
261 }
262 
263 
264 /* Note, call of this function should be AFTER calling _apu_push* functions as those may set overflow flag we want to keep as cleared here ...
265  * I am still not sure about the difference of overflow and underflow, also not the over-/underflow and carry. For the second problem:
266  * it's said that the maximal (or minimal value) can be extended by the carry flag, so there are three cases basically: a number can
267  * be represented without overflow and carry, the number can be represented as carry to be thought of the extension of the result,
268  * and the overflow, when the result can't represented even with the extended result size by the carry bit. Hmmm. But then, should
269  * carry to be set in case of overflow, or not?
270  * */
271 static void _apu_carry ( Sint64 val, Sint64 limit )
272 {
273  if (val >= limit * 2 || val < -limit * 2) {
274  _apu_status |= _APU_F_OVERFLOW;
275  // should carry set here????????????????
276  _apu_status |= _APU_F_CARRY;
277  } else if (val >= limit || val < -limit) {
278  _apu_status &= 255 - _APU_F_OVERFLOW;
279  _apu_status |= _APU_F_CARRY;
280  }
281 }
282 
283 
284 /* Note: most of the command emulation uses the fix32/fix16/float POP/PUSH functions.
285  * In some cases it's not the optimal solution (performance) but it's much simplier.
286  * However in case of floats it can cause some odd things, ie APU-float<->C-double conversion
287  * rounding problems on POP/PUSH ... Well maybe I will deal with this later versions,
288  * now the short solution ... */
290 {
291  int i;
292  Sint64 l;
293  double f;
294  //int _apu_tos_old = _apu_tos;
295  int clocks = 0;
296  _apu_status = 0; // I am still not sure that ops according to spec which "do not affect a flag" means that it is UNCHANGED from the previous op, or simply zero and never set. Hmmm.
297  switch (cmd & 0x7F) { // note, SR (bit7) field of command is currently ignored!
298  /* --------------------------------------- */
299  /* ---- 16 bit fixed point operations ---- */
300  /* --------------------------------------- */
301  case 0x6C: // SADD: Add TOS to NOS. Result to NOS. Pop Stack.
302  i = _apu_pop_fix16() + _apu_pop_fix16();
303  _apu_push_fix16(i);
304  _apu_carry(i, 0x8000);
305  clocks = 17;
306  break;
307  case 0x6D: // SSUB: Substract TOS from NOS. Result to NOS. Pop Stack.
308  i = _apu_pop_fix16();
309  i = _apu_pop_fix16() - i;
310  _apu_push_fix16(i);
311  _apu_carry(i, 0x8000);
312  clocks = 31;
313  break;
314  case 0x6E: // SMUL: Multiply NOS by TOS. Lower result to NOS. Pop Stack.
315  i = _apu_pop_fix16() * _apu_pop_fix16();
316  _apu_push_fix16(i);
317  clocks = 89;
318  break;
319  case 0x76: // SMUU: Multiply NOS by TOS. Upper result to NOS. Pop Stack.
320  i = _apu_pop_fix16() * _apu_pop_fix16();
321  _apu_push_fix16(i >> 16);
322  clocks = 87;
323  break;
324  case 0x6F: // SDIV: Divide NOS by TOS. Result to NOS. Pop Stack.
325  i = _apu_pop_fix16(); // TOS
326  if (i) {
327  _apu_push_fix16(_apu_pop_fix16() / i);
328  clocks = 89;
329  } else { // TOS = 0, divide by zero error
330  // TOS = 0 case, APU simply puts old NOS as result, that is, leave the original NOS, which is now the TOS
331  _apu_status |= _APU_F_ZERODIV;
332  clocks = 14;
333  }
334  break;
335  /* --------------------------------------- */
336  /* ---- 32 bit fixed point operations ---- */
337  /* --------------------------------------- */
338  case 0x2C: // DADD: Add TOS to NOS. Result to NOS. Pop Stack.
339  l = _apu_pop_fix32() + _apu_pop_fix32();
340  _apu_push_fix32(l);
341  _apu_carry(l, 0x80000000L);
342  clocks = 21;
343  break;
344  case 0x2D: // DSUB: Substract TOS from NOS. Result to NOS. Pop Stack.
345  l = _apu_pop_fix32();
346  l = _apu_pop_fix32() - l;
347  _apu_push_fix32(l);
348  _apu_carry(l, 0x80000000L);
349  clocks = 39;
350  break;
351  case 0x2E: // DMUL: Multiply NOS by TOS. Lower result to NOS. Pop Stack.
352  l = _apu_pop_fix32() * _apu_pop_fix32();
353  _apu_push_fix32(l);
354  clocks = 200;
355  break;
356  case 0x36: // DMUU: Multiply NOS by TOS. Upper result to NOS. Pop Stack.
357  l = _apu_pop_fix32() * _apu_pop_fix32();
358  _apu_push_fix32(l >> 32);
359  clocks = 200;
360  break;
361  case 0x2F: // DDIV: Divide NOS by TOS. Result to NOS. Pop Stack.
362  l = _apu_pop_fix32(); // TOS
363  if (l) {
364  _apu_push_fix32(_apu_pop_fix32() / l);
365  clocks = 200;
366  } else { // TOS = 0, divide by zero error
367  // TOS = 0 case, APU simply puts old NOS as result, that is, leave the original NOS, which is now the TOS
368  _apu_status |= _APU_F_ZERODIV;
369  clocks = 18;
370  }
371  break;
372  /* -------------------------------------------------- */
373  /* ---- 32 bit floating point primary operations ---- */
374  /* -------------------------------------------------- */
375  case 0x10: // FADD: Add TOS to NOS. Result to NOS. Pop Stack.
376  f = _apu_pop_float();
377  _apu_push_float(_apu_pop_float() + f);
378  clocks = (f ? 200 : 24);
379  break;
380  case 0x11: // FSUB: Substract TOS from NOS. Result to NOS. Pop Stack.
381  f = _apu_pop_float();
382  _apu_push_float(_apu_pop_float() - f);
383  clocks = (f ? 200 : 26);
384  break;
385  case 0x12: // FMUL: Multiply NOS by TOS. Result to NOS. Pop Stack.
386  _apu_push_float(_apu_pop_float() * _apu_pop_float());
387  clocks = 150;
388  break;
389  case 0x13: // FDIV: Divide NOS by TOS. Result to NOS. Pop Stack.
390  f = _apu_pop_float();
391  if (f) {
392  _apu_push_float(_apu_pop_float() / f);
393  clocks = 170;
394  } else { // TOS = 0, divide by zero error
395  // TOS = 0 case, APU simply puts old NOS as result, that is, leave the original NOS, which is now the TOS
396  _apu_status |= _APU_F_ZERODIV;
397  clocks = 22;
398  }
399  break;
400  /* -------------------------------------------------- */
401  /* ---- 32 bit floating point derived operations ---- */
402  /* -------------------------------------------------- */
403  case 0x01: // SQRT: Square Root of TOS. Result to TOS.
404  f = _apu_pop_float();
405  _apu_push_float(sqrt(fabs(f))); // we still want to do something with negative number ..., so use fabs() but set the error status on the next line too
406  if (f < 0) _apu_status |= _APU_F_NEGARG; // negative argument signal
407  clocks = 800;
408  break;
409  case 0x02: // SIN: Sine of TOS. Result to TOS.
410  _apu_push_float(sin(_apu_pop_float()));
411  clocks = 4000;
412  break;
413  case 0x03: // COS: Cosine of TOS. Result to TOS.
414  _apu_push_float(cos(_apu_pop_float()));
415  clocks = 4000;
416  break;
417  case 0x04: // TAN: Tangent of TOS. Result to TOS.
418  _apu_push_float(tan(_apu_pop_float()));
419  clocks = 5000;
420  break;
421  case 0x05: // ASIN: Inverse Sine of TOS. Result to TOS.
422  _apu_push_float(asin(_apu_pop_float()));
423  clocks = 7000;
424  break;
425  case 0x06: // ACOS: Inverse Cosine of TOS. Result to TOS.
426  _apu_push_float(acos(_apu_pop_float()));
427  clocks = 7000;
428  break;
429  case 0x07: // ATAN: Inverse Tangent of TOS. Result to TOS.
430  _apu_push_float(atan(_apu_pop_float()));
431  clocks = 5000;
432  break;
433  case 0x08: // LOG: Common Logarithm of TOS. Result to TOS.
434  f = _apu_pop_float();
435  if (f > 0) {
436  _apu_push_float(log10(f));
437  clocks = 5500;
438  } else {
439  _apu_status |= _APU_F_NEGARG;
440  _apu_move(4);
441  clocks = 20;
442  }
443  break;
444  case 0x09: // LN: Natural Logarithm of TOS. Result to TOS.
445  f = _apu_pop_float();
446  if (f > 0) {
447  _apu_push_float(log(f));
448  clocks = 5500;
449  } else {
450  _apu_status |= _APU_F_NEGARG;
451  _apu_move(4);
452  clocks = 20;
453  }
454  break;
455  case 0x0A: // EXP: "e" raised to power in TOS. Result to TOS.
456  f = _apu_pop_float();
457  _apu_push_float(pow(M_E, f));
458  clocks = (f > 32 ? 34 : 4000);
459  break;
460  case 0x0B: // PWR: NOS raised to power in TOS. Result to TOS. Pop Stack.
461  f = _apu_pop_float();
462  _apu_push_float(pow(_apu_pop_float(), f));
463  clocks = 10000;
464  break;
465  /* ------------------------------------------------ */
466  /* ---- data and stack manipulation operations ---- */
467  /* ------------------------------------------------ */
468  case 0x00: // NOP: does nothing (but clears status, however it's the first instruction done in the main func already
469  clocks = 4;
470  break;
471 
472  case 0x1F: // FIXS: Convert TOS from floating point format to fixed point format (16 bit).
473  _apu_push_fix16(_apu_pop_float());
474  clocks = 150;
475  break;
476  case 0x1E: // FIXD: Convert TOS from floating point format to fixed point format (32 bit).
477  _apu_push_fix32(_apu_pop_float());
478  clocks = 200;
479  break;
480  case 0x1D: // FLTS: Convert TOS from fixed point format (16 bit) to floating point format.
481  _apu_push_float(_apu_pop_fix16());
482  clocks = 100;
483  break;
484  case 0x1C: // FLTD: Convert TOS from fixed point format (32 bit) to floating point format.
485  _apu_push_float(_apu_pop_fix32());
486  clocks = 200;
487  break;
488 
489  case 0x74: // CHSS: Change sign of fixed point (16 bit) operand on TOS.
490  _apu_push_fix16(-_apu_pop_fix16());
491  clocks = 23;
492  break;
493  case 0x34: // CHSD: Change sign of fixed point (32 bit) operand on TOS.
494  _apu_push_fix32(-_apu_pop_fix32());
495  clocks = 27;
496  break;
497  case 0x15: // CHSF: Change sign of floating point operand on TOS. Note: that does not seem to be a big issue, as a single bit should be modified??
498  if (_apu_look8(1) & 128) { // if number is not zero
499  _apu_stack[_apu_tos] ^= 128;
500  if (_apu_stack[_apu_tos] & 128) _apu_status |= _APU_F_SIGN;
501  } else // if number is zero, nothing happens (but we sets zero flag)
502  _apu_status |= _APU_F_ZERO;
503  clocks = 18;
504  break;
505 
506  case 0x77: // PTOS: Push stack. Duplicate NOS to TOS.
507  _apu_move(2);
508  _apu_copy(2, 0);
509  _apu_copy(3, 1);
510  _apu_sz_fix16();
511  clocks = 16;
512  break;
513  case 0x37: // PTOD: Push stack. Duplicate NOS to TOS.
514  _apu_move(4);
515  _apu_copy(4, 0);
516  _apu_copy(5, 1);
517  _apu_copy(6, 2);
518  _apu_copy(7, 3);
519  _apu_sz_fix32();
520  clocks = 20;
521  break;
522  case 0x17: // PTOF: Push stack. Duplicate NOS to TOS.
523  _apu_move(4);
524  _apu_copy(4, 0);
525  _apu_copy(5, 1);
526  _apu_copy(6, 2);
527  _apu_copy(7, 3);
528  _apu_sz_float();
529  clocks = 20;
530  break;
531 
532  case 0x78: // POPS: Pop stack. Old NOS becomes new TOS, old TOS rotates to bottom.
533  _apu_move(-2);
534  _apu_sz_fix16(); // set "sz" (S and Z status flags) by inspecting (new) TOS
535  clocks = 10;
536  break;
537  case 0x38: // POPD: Pop stack. Old NOS becomes new TOS, old TOS rotates to bottom.
538  _apu_move(-4);
539  _apu_sz_fix32();
540  clocks = 12;
541  break;
542  case 0x18: // POPF: Pop stack. Old NOS becomes new TOS, old TOS rotates to bottom.
543  _apu_move(-4);
544  _apu_sz_float();
545  clocks = 12;
546  break;
547 
548  case 0x79: // XCHS: Exchange NOS and TOS. (16 bit fixed)
549  _apu_xchg(0, 2);
550  _apu_xchg(1, 3);
551  _apu_sz_fix16();
552  clocks = 18;
553  break;
554  case 0x39: // XCHD: Exchange NOS and TOS. (32 bit fixed)
555  _apu_xchg(0, 4);
556  _apu_xchg(1, 5);
557  _apu_xchg(2, 6);
558  _apu_xchg(3, 7);
559  _apu_sz_fix32();
560  clocks = 26;
561  break;
562  case 0x19: // XCHF: Exchange NOS and TOS. (float stuff)
563  _apu_xchg(0, 4);
564  _apu_xchg(1, 5);
565  _apu_xchg(2, 6);
566  _apu_xchg(3, 7);
567  _apu_sz_float();
568  clocks = 26;
569  break;
570 
571  case 0x1A: // PUPI: Push floating point constant PI onto TOS. Previous TOS becomes NOS.
572  _apu_push8(0xDA);
573  _apu_push8(0x0F);
574  _apu_push8(0xC9);
575  _apu_push8(0x02);
576  clocks = 16;
577  break;
578 
579  default:
580  DEBUG("APU: not implemented/unknown Am9511 command: %02Xh" NL, cmd);
581  clocks = 4; // no idea what happens.
582  break;
583  }
584  clocks *= CPU_CLOCK;
585  z80ex_w_states((clocks % APU_CLOCK) ? ((clocks / APU_CLOCK) + 1) : (clocks / APU_CLOCK));
586 }
z80ex_w_states
void z80ex_w_states(unsigned w_states)
Definition: z80ex.c:307
_APU_F_SIGN
#define _APU_F_SIGN
Definition: apu.c:61
apu_write_data
void apu_write_data(Uint8 data)
Definition: apu.c:113
_APU_F_NEGARG
#define _APU_F_NEGARG
Definition: apu.c:57
apu.h
m65-memcontent-generator.data
data
Definition: m65-memcontent-generator.py:119
apu_read_data
Uint8 apu_read_data()
Definition: apu.c:99
Uint8
uint8_t Uint8
Definition: fat32.c:51
cpu.h
_APU_F_ZERODIV
#define _APU_F_ZERODIV
Definition: apu.c:58
APU_CLOCK
#define APU_CLOCK
Definition: apu.h:22
_APU_F_LARGE
#define _APU_F_LARGE
Definition: apu.c:59
_APU_F_CARRY
#define _APU_F_CARRY
Definition: apu.c:54
apu_reset
void apu_reset(void)
Definition: apu.c:66
apu_write_command
void apu_write_command(Uint8 cmd)
Definition: apu.c:290
NL
#define NL
Definition: fat32.c:37
xep128.h
L
#define L
Definition: macros.h:30
CPU_CLOCK
#define CPU_CLOCK
Definition: tvc.h:30
_APU_F_ZERO
#define _APU_F_ZERO
Definition: apu.c:60
DEBUG
#define DEBUG(...)
Definition: emutools_basicdefs.h:167
_APU_F_UNDERFLOW
#define _APU_F_UNDERFLOW
Definition: apu.c:56
apu_read_status
Uint8 apu_read_status(void)
Definition: apu.c:74
_APU_F_OVERFLOW
#define _APU_F_OVERFLOW
Definition: apu.c:55