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