コード例 #1
0
ファイル: strudel.c プロジェクト: michaelmacinnis/strudel
static void stream_request_cb(pa_stream *s, size_t length, void *data) {
    M6502 *mpu = (M6502 *) data;
	int max = 0;

    redraw = 0;

    pa_stream_begin_write(s, (void**) &sndbuf, &length);

   	memset(sndbuf, 128, length);

    max = length * 6250 / 539;
    if (max > 20454)
		fprintf(stderr, "Cycles = %u!\n", (unsigned int) max);

    cycles = 0;
    while (cycles < max) {
        if (trace)
            M6502_disassemble(mpu);

        cycles += M6502_run(mpu);
    }

   	pa_stream_write(s, sndbuf, length, NULL, 0, PA_SEEK_RELATIVE);

    redraw = 1;
}
コード例 #2
0
ファイル: lib1.c プロジェクト: Johnicholas/Hello-Github
int main()
{
  M6502    *mpu = M6502_new(0, 0, 0);	/* Make a 6502 */
  unsigned  pc  = 0x1000;		/* PC for 'assembly' */

  /* Install the two callback functions defined above.
   */
  M6502_setCallback(mpu, call, WRCH, wrch);	/* Calling FFEE -> wrch() */
  M6502_setCallback(mpu, call,    0, done);	/* Calling 0 -> done() */

  /* A few macros that dump bytes into the 6502's memory.
   */
# define gen1(X)	(mpu->memory[pc++]= (uint8_t)(X))
# define gen2(X,Y)	gen1(X); gen1(Y)
# define gen3(X,Y,Z)	gen1(X); gen2(Y,Z)

  /* Hand-assemble the program.
   */
  gen2(0xA2, 'A'     );	// LDX #'A'
  gen1(0x8A          );	// TXA
  gen3(0x20,0xEE,0xFF);	// JSR FFEE
  gen1(0xE8          );	// INX
  gen2(0xE0, 'Z'+1   );	// CPX #'Z'+1
  gen2(0xD0, -9      );	// BNE 0x1002
  gen2(0xA9, '\n'    );	// LDA #'\n'
  gen3(0x20,0xEE,0xFF);	// JSR FFEE
  gen2(0x00,0x00     ); // BRK

  /* Just for fun: disssemble the program.
   */
  {
    char     insn[64];
    uint16_t ip= 0x1000;
    while (ip < pc)
      {
	ip += M6502_disassemble(mpu, ip, insn);
	printf("%04X %s\n", ip, insn);
      }
  }

  /* Point the RESET vector at the first instruction in the assembled
   * program.
   */
  M6502_setVector(mpu, RST, 0x1000);

  /* Reset the 6502 and run the program.
   */
  M6502_reset(mpu);
  M6502_run(mpu);
  M6502_delete(mpu);	/* We never reach here, but what the hey. */

  return 0;
}