Skip to content

Instantly share code, notes, and snippets.

@spelufo
Created March 17, 2015 02:25
Show Gist options
  • Save spelufo/d33392f6da0897970d7a to your computer and use it in GitHub Desktop.
Save spelufo/d33392f6da0897970d7a to your computer and use it in GitHub Desktop.
#!/bin/bash
SOURCE="${1/.*/}"
# Clean
rm "$SOURCE" "$SOURCE".o
# Build
z80-unknown-coff-as -z80 -g -as -gstabs+ -o "$SOURCE".o "$SOURCE".s
z80-unknown-coff-ld --oformat coff-z80 -e 0xB000 -Ttext 0xB000 -o "$SOURCE" "$SOURCE".o
z80-unknown-coff-objdump -j .text -j .data -t "$SOURCE"
# Debug
echo "Starting qemu-system-z80 on the background" >&2
qemu-system-z80 -io-output-file "${2:-out.txt}" -io-input-file "${3:-in.txt}" -monitor file:temp -io-output-log-file "${4:-output.log}" -nographic -serial null -S -s &
gdb-z80 -ex "set prompt (qemu-gdb)" -ex "target extended-remote :1234" -ex "file $SOURCE" -ex "load"

z80-tools en linux

Testeado en Linux Mint 17.1 'Rebecca':

$ uname -a
Linux santiago 3.13.0-24-generic #47-Ubuntu SMP Fri May 2 23:30:00 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux

Assembler

sudo apt install binutils-z80

Es una version mas nueva que la del curso, y los ejecutables son z80-unknown-coff-{as,ld,objdump,...}.

Debugger

sudo apt install flex
git clone https://github.com/legumbre/gdb-z80
cd gdb-z80
mkdir build && cd build
CFLAGS=-Wno-error=sizeof-pointer-memaccess ../configure --target=z80
make
sudo ln -s `pwd`/gdb/gdb /usr/bin/gdb-z80

Emulador

git clone https://github.com/legumbre/qemu-z80
cd qemu-z80
./configure --target-list=z80-softmmu --disable-sdl --disable-kvm --disable-xen --disable-vnc-tls --disable-vnc-sasl --disable-curl --disable-bluez --disable-vde --disable-nptl --disable-pthread
make
sudo make install

Sublime Text

git clone https://github.com/psbhlw/sublime-text-z80asm
ln -s sublime-text-z80asm/z80asm ~/.config/sublime-text-3/Packages/

Funciona con los archivos de terminación .asm o .a80, porque los archivos .s son del predecesor lenguage R, S.

Correrlos

chmod +x el archivo z80 y ponerlo en el $PATH. Luego se puede compilar, arrancar el emulador y arrancar gdb conectado al emulador con z80 <source> [io-output-file] [io-input-file] [io-output-log-file]. Probarlo con z80 test.s.

@xqft
Copy link

xqft commented Mar 9, 2023

8 años despues otro usuario de Linux se frustro de ver tantos .exe en la carpeta del setup y gracias a vos pude hacer andar todo :)

Nada mas tuve que meter el flag -w al generar el Makefile para el debugger, e instale localmente binutils-z80 usando debtap (mi distro es Arch), el resto anduvo excelente.

Aporto mi granito de arena y dejo un Makefile que reemplaza todas las funciones de los macros de notepad (no lo probe exhaustivamente), para algun user futuro. Saludos!

UTIL = z80-unknown-coff

# Build variables
START_ADDR = 0xB000
COMPFLAGS = -z80 -g -as -gstabs+
LDFLAGS = --oformat coff-z80 -e $(START_ADDR) -Ttext $(START_ADDR)

SRC = test.s
OBJ = build/test.o
BIN = test

# Other
LAB_DE0_PATH = lab-de0
# lab-de0/ may contain lab-intup.cdf, lab-intup.sof and update_in_system_memory.tcl

.PHONY: all build qemu jtag rom fpga clean

all: qemu

build: $(BIN)

qemu: build
	qemu-system-z80 -io-output-file "out.txt" -io-input-file "in.txt" -monitor file:temp -io-output-log-file "output.log" -nographic -serial null -S -s &
	gdb-z80 -ex "set prompt (qemu-gdb)" -ex "target extended-remote :1234" -ex "file $(BIN)" -ex "load"

jtag: build
	jtagconfig
	gdb -ex "target extended-remote :1234" -ex "file $(BIN)" -ex "load"

rom: $(BIN)
	mkdir -p rom/
	$(UTIL)-objcopy -j .text -O srec $< rom/$<.srec
	srec_cat rom/$<.srec -data-only -o rom/$<.hex -intel -obs=1 -address-length=2 -enable=footer
	quartus_stp -t $(LAB_DE0_PATH)/update_in_system_memory.tcl rom/$<.hex

fpga: rom
	quartus_pgm -c1 $(LAB_DE0_PATH)/lab-intup.cdf

build/%.o: %.s
	mkdir -p build/
	$(UTIL)-as $(COMPFLAGS) -o $@ $^

$(BIN): $(OBJ)
	$(UTIL)-ld $(LDFLAGS) -o $@ $^
	$(UTIL)-objdump -j .text -j .data -t $@

clean:
	rm -rf build
	rm -rf rom
	rm $(BIN)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment