Barebone emulator, or “generic emulator”, is a customizable emulator of CPU + memory + serial terminal. You can configure it by simple config file. Let’s long story short…
First of all, prepare a config file, e.g. “mycomputer.emu”. Extension “.emu” is mandatory. File should contain this:
cpu Z80memory.ram.from 0x1000memory.ram.to 0x13ffmemory.rom.from 0x0000memory.rom.to 0x0fff;serial simple;serial.in 1;serial.out 1;serial.status 0;serial.status.available 0x20;serial.status.ready 0x02serial 6850serial.data 0x81serial.control 0x80terminal.caps 1
Format is really simple: Each line contains one directive. Lines with “;” at the same beginning are comments. Here are parameters:
parameter | value (case sensitive) |
cpu | can be “I8080”, “Z80” or “C6502” |
memory.ram.from | starting address for RAM (please follow the 0x… convention for hexadecimal numbers) |
memory.ram.to | last address of RAM |
memory.rom.from, memory.rom.to | Same as above, but for ROM (your source code should lays here) |
serial | Type of serial port. You can select “6850” or “simple”. See below |
serial.data, serial.control | For 6850 serial – two ports. |
serial.in, serial.out | in and out ports for “simple serial port” |
serial.status | “Simple port” status. Read only port. It returns “serial.status.available” when there is any data for read, and “serial.status.ready” if port is ready to send a data. |
terminal.caps | 1 sets terminal to caps lock (default value 0 means “no caps”) |
serial.interrupt | value 1 means that terminal invoke CPU interrupt on keypress (=serial data is ready for read). Default 0 means “no interrupt”. |
Two serial ports are available – 6850 is the standard ACIA circuit, “simple” is a generic serial port with no complicated functions, just read and send bytes.
How to use it? It’s simple, just tell which emulator should use by the “.engine” directive (without “.emu”), like this:
org 0.engine mycomputerdild sp, 0x1400ld a, 15hout (80h),ald hl, hellocall printhlendless:call getajr z,endlessinc acall printajr endlessprinthl:ld a,(hl)or aret zcall printainc hljr printhlprinta:push afserdy:in a,80hand 02jr z,serdypop afout 81h,aretgeta:in a,80hand 01hret zin a,81hor arethello:db "Hello World!",0x0d,0x0a,0
It’s a simple “hello” program, using the above configuration. Just save it as “test.z80” and click to “Emulate (F10)”. It should compile and run emulator with given configuration.
For 6502-based computer you can use this config file (e.g.”my6502.emu”):
cpu C6502memory.ram.from 0x0000memory.ram.to 0x0fffmemory.rom.from 0xf000memory.rom.to 0xffffserial 6850serial.data 0xa001serial.control 0xa000serial.map 1
Please notice the “serial.map” directive. It means that serial port is not mapped into “I/O” space (like Z80/8080 does), but into memory space. Serial.data and serial.control are addresses now.
6502 requires RAM in a bottom part of address space, ROM at the top.
Try this code:
.engine my6502ACIA = $A000ACIACONTROL = ACIA+0ACIASTATUS = ACIA+0ACIADATA = ACIA+1.ORG $FFFCDW resetDW reset.org $f000RESET:LDX #$FFTXSLDA #$15STA ACIAControlLDY #0LOOP:LDA Message,YBEQ KEYJSR SEROUTINYBNE LOOPKEY: LDA ACIAStatusAND #1BEQ KEYLDA ACIAData; simple data manglingSECADC #0JSR seroutJMP KEYMessage:DB $0C,"My hovercraft is full of eels!",$0D,$0A,$00SEROUT: PHASO_WAIT: LDA ACIAStatusAND #2BEQ SO_WAITPLASTA ACIADataRTS
Other processors and peripherals are on its way…