Two interface files are provided: - "io.c" is only an skeleton file with minimal interface functions. - "softvideo.c" emulates the Rickards Guneé video-game hardware. The source file "io.c" contains 4 functions related with ports: byte porta_rd(core *pcore); byte portb_rd(core *pcore); void porta_wr(core *pcore); void portb_wr(core *pcore); "_rd" functions are called every time the core emulator wants to check the input status of porta or portb. This happens very often: more than one time for every clock cycle. This is due to timer & interrupt emulation. External stimuli can be "attached" to these functions providing the needed code. A relevant data is available in the "core" structure: pcore->porta Last value written to ports (not the actual output) pcore->portb pcore->trisa The current io direction of port pins pcore->trisb pcore->Clocks The number of cpu cycles (osc/4) elapsed since power on reset. pcore->freq The simulated clock frequency (osc/4: (Hz)) pcore->option Pull-ups configuration. All the bits that are programmed as outputs in the tris[ab] register are ignored when reading the port[ab] input. "_wr" functions are only called when a value is written to porta or portb respectively. They can be used to simulate an action on external hardware. The "do_periodic_update()" function allows the simulation of slow hardware without too much cpu loading. This function is called every 20ms. For instance, this function can be used to update the input pin values depending on PC keyboard status in order to simulate input buttons. The "trace_interrupt(core *pcore)" is another convenience function that is called just before the CPU is branching to an interrupt routine. This function can be used for debug and profiling purposes and it is also an efficient way to emulate synchronous hardware that generates interrupts. -------------------------------------------------------------------------- Video-Game interface: The emulation allows you to play tetris on an X11 screen. Emulation assumes: - Processor running @ 12 MHz (3 Mips) - RA0 is the composite sync output. - RB0 is the video output. - RB1 is the fire joystick input, active low -> "space" key. - RB2 is the down joystick input, active low -> "cursor down" key. - RB3 is the up joystick input, active low -> "cursor up" key. - RB4 is the right joystick input, active low -> "cursor right" key. - RB5 is the left joystick input, active low -> "cursor left" key. - RA4 is the sound output. (See sound emulation) The secondary joystick is not yet emulated, but it can be easily added to "softvideo.c" file. -------------------------------------------------------------------------- Sound emulation: The version 1.2 of picemu allows you to play the square-wave like output of a single PIC16F84 pin on your soundcard. The pin must be selected editing the sound.c file prior to the compilation. Sound emulation can be compiled or not depending on the Makefile settings. Edit the Makefile file prior to the compilation. The emulator samples the sound pin output on every cpu cycle, low-pass filters the output and reduces the sample rate to a soundcard compatible value. The low-pass filter is a second order comb filter with very low computational requirements. This filter provides some antialiasing characteristics and averages high frequency pin changes to an intermediate sound output level.