Human68k CUI emulator with sound.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

v68.h 3.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. #pragma once
  2. #include <stdio.h>
  3. #include <stdint.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include <fcntl.h>
  7. #include <ctype.h>
  8. #include "v68human.h"
  9. #include "okim6258.h"
  10. #include "ym2151.h"
  11. #include "dmac.h"
  12. #include "vgm.h"
  13. #define XHEAD_SIZE 0x40 /* Xファイルのヘッダサイズ */
  14. #define HUMAN_HEAD 0x6800 /* Humanのメモリ管理ブロック位置 */
  15. #define FCB_WORK 0x20F00 /* DOSCALL GETFCB用ワーク領域 */
  16. #define HUMAN_WORK 0x21000 /* 割り込み処理先等のワーク領域 */
  17. #define ENV_TOP 0x21C00
  18. #define ENV_SIZE 0x2000
  19. #define STACK_TOP ENV_TOP + ENV_SIZE
  20. #define STACK_SIZE 0x10000 /* 64KB */
  21. #define MB_SIZE 16
  22. #define PSP_SIZE MB_SIZE + 240
  23. #define PROG_TOP (STACK_TOP + STACK_SIZE + PSP_SIZE)
  24. #define NEST_MAX 20
  25. #define RAS_INTERVAL 10000 /* ラスタ割り込みの間隔 */
  26. #define verbose(v, fmt...) { if(v68.verbosity >= v) printf(fmt); }
  27. #define verbose1(fmt...) verbose(1, "[1] " fmt);
  28. #define verbose2(fmt...) verbose(2, "[2] " fmt);
  29. #define verbose3(fmt...) verbose(3, "[3] " fmt);
  30. #define verbose4(fmt...) verbose(4, "[4] " fmt);
  31. #define logcall(fmt...) { if(v68.log_calls) printf(fmt); }
  32. struct v68 {
  33. int log_dasm, verbosity;
  34. /* VM */
  35. uint8_t *ram;
  36. size_t ram_size;
  37. int reset_pulsed;
  38. /* MFP */
  39. int int_vec;
  40. /* CPU timing */
  41. int cpu_clock, cpu_cycle_remainder, cpu_ended_timeslice;
  42. /* Sound Timing */
  43. int sound_touched;
  44. int16_t *bufL, *bufR, *tmpBufL, *tmpBufR;
  45. int sample_rate;
  46. int samples_remainder, buf_remaining;
  47. int prev_sound_cycles, remaining_tstates;
  48. /* Peripheral timing */
  49. int periph_timers_altered, in_periph_timing, periph_cycles;
  50. /* OPM */
  51. struct ym2151 opm;
  52. uint8_t opm_addr_latch;
  53. int opm_clka, opm_clkb, opm_flags, opm_ct;
  54. int opm_timera_cycles, opm_timerb_cycles;
  55. int opm_timera_counter, opm_timerb_counter;
  56. /* ADPCM */
  57. struct okim6258 oki;
  58. int oki_sample_counter, oki_sample_cycles;
  59. int oki_resample_remainder, oki_freq;
  60. /* 8255 PPI */
  61. uint8_t ppi_regs[4];
  62. /* DMAC */
  63. struct dmac dmac;
  64. /* VGM logging */
  65. struct vgm_logger *logger;
  66. /* OS */
  67. /* Memory allocation */
  68. int heap_start, heap_top;
  69. #define V68_CMD_QUEUE_LEN 8
  70. int running;
  71. char cmd_queue[V68_CMD_QUEUE_LEN][1024];
  72. int cmd_queue_pos;
  73. uint32_t cur_prog_addr; // address of currently running program
  74. int log_calls;
  75. };
  76. extern struct v68 v68;
  77. int v68_init(int clock, int ram_size, int sample_rate);
  78. void v68_boot(void);
  79. void v68_run(void);
  80. int v68_fill_buffer(int samples, int16_t *bufL, int16_t *bufR, int16_t *tmpBufL, int16_t *tmpBufR);
  81. int v68_shutdown(void);
  82. /* Traps */
  83. int v68_trap(int which);
  84. uint32_t v68_int_ack_handler(int int_level);
  85. unsigned int m68k_read_memory_8(unsigned int addr);
  86. unsigned int m68k_read_memory_16(unsigned int addr);
  87. unsigned int m68k_read_memory_32(unsigned int addr);
  88. void m68k_write_memory_8(unsigned int addr, unsigned int data);
  89. void m68k_write_memory_16(unsigned int addr, unsigned int data);
  90. void m68k_write_memory_32(unsigned int addr, unsigned int data);
  91. unsigned int m68k_read_disassembler_8 (unsigned int addr);
  92. unsigned int m68k_read_disassembler_16 (unsigned int addr);
  93. unsigned int m68k_read_disassembler_32 (unsigned int addr);
  94. uint32_t v68_int_ack_handler(int int_level);
  95. int v68_trap(int which);