To compile an ATmega128 to JavaScript use the command
emcc swavr_wrapper.c swavr/avr.c swavr/atmega128.c -o swavr.js -O3 -s RESERVED_FUNCTION_POINTERS=8 -s EXPORTED_FUNCTIONS="['_emsc_atmega128_get_pc', '_emsc_atmega128_get_instruction_name', '_emsc_atmega128_tick', '_emsc_atmega128_uart0_write', '_emsc_atmega128_pmem_write_byte', '_emsc_atmega128_destroy', '_emsc_atmega128_reinit', '_emsc_atmega128_init']"
If using more than one type of AVR, add them all to the command, like this command for compiling the ATmega128 and ATtiny1634
emcc swavr_wrapper.c swavr/attiny1634.c swavr/atmega128.c swavr/atmega328.c swavr/avr.c -o swavr.js -O3 -s RESERVED_FUNCTION_POINTERS=8 -s EXPORTED_FUNCTIONS="['_emsc_attiny1634_get_pc', '_emsc_attiny1634_get_instruction_name', '_emsc_attiny1634_tick', '_emsc_attiny1634_uart0_write', '_emsc_attiny1634_pmem_write_byte', '_emsc_attiny1634_destroy', '_emsc_attiny1634_reinit', '_emsc_attiny1634_init', '_emsc_atmega128_get_pc', '_emsc_atmega128_get_instruction_name', '_emsc_atmega128_tick', '_emsc_atmega128_uart0_write', '_emsc_atmega128_pmem_write_byte', '_emsc_atmega128_destroy', '_emsc_atmega128_reinit', '_emsc_atmega128_init', '_emsc_atmega328_get_pc', '_emsc_atmega328_get_instruction_name', '_emsc_atmega328_tick', '_emsc_atmega328_uart0_write', '_emsc_atmega328_pmem_write_byte', '_emsc_atmega328_destroy', '_emsc_atmega328_reinit', '_emsc_atmega328_init']"
The functions to export for each AVR type are:
_emsc_<AVR_type>_get_pc
_emsc_<AVR_type>_get_instruction_name
_emsc_<AVR_type>_tick
_emsc_<AVR_type>_uart0_write
_emsc_<AVR_type>_pmem_write_byte
_emsc_<AVR_type>_destroy
_emsc_<AVR_type>_reinit
_emsc_<AVR_type>_init
These should all be in swavr_wrapper.c
(minus the prepended '_' on each)
Include swavr.js
, which should have been generated by the above command and the appropriate JavaScript wrapper file(s) (e.g. atmega128.js
) in your html file