diff --git a/.gitignore b/.gitignore
index fa117e2..c1051a7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,9 +3,11 @@
*.lx2
*.o
*.swp
-cpu/boot_code.bin
-cpu/boot_code.txt
-cpu/brainfuck.bin
-cpu/brainfuck.txt
-cpu/memdump.txt
-cpu/memdump.bin
+*.memdump
+*.lxt # Not sure when those crop up
+boot_code/brainfuck.bin
+boot_code/brainfuck.txt
+boot_code/brainfuck_mandelbrot.bin
+boot_code/brainfuck_mandelbrot.txt
+system/boot_code.bin
+system/boot_code.txt
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..0018688
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,35 @@
+# This file is part of the 9086 project.
+#
+# Copyright (c) 2023 Efthymios Kritikos
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+
+SYSTEM_VVP=system/system.vvp
+BOOT_CODE=boot_code/brainfuck.txt
+GTKWSAVE=./gtkwave_savefile.gtkw
+
+
+include common.mk
+
+
+boot_code/%txt:
+ ${Q}make ${MAKEOPTS} -C boot_code $(subst boot_code/,,$@)
+
+${SYSTEM_VVP}:
+ ${Q}make ${MAKEOPTS} -C system system.vvp
+
+clean:
+ ${Q}make ${MAKEOPTS} -C system clean
+ ${Q}make ${MAKEOPTS} -C boot_code clean
diff --git a/README.md b/README.md
index 0fa6325..8880349 100644
--- a/README.md
+++ b/README.md
@@ -12,8 +12,7 @@ A CPU that aims to be binary compatible with the 8086 and with as many optimisat
* [ ] Is superscalar
### Building it
-To build it you need Icarus Verilog, bin86, GNU make, xxd and the posix coreutils.
-Go into the cpu directory and run `make`
+To build this project you need Icarus Verilog, bin86, GNU make, xxd and the posix coreutils and run `make` on the top level directory.
At the time of development the versions used are :
diff --git a/boot_code/Makefile b/boot_code/Makefile
new file mode 100644
index 0000000..15dc791
--- /dev/null
+++ b/boot_code/Makefile
@@ -0,0 +1,14 @@
+SOURCE=$(shell ls |grep asm$)
+BINARIES=$(subst .asm,.txt,${SOURCE})
+BUILD_FILES=${BINARIES}
+BUILD_FILES+=$(subst .asm,.memdump,${SOURCE})
+BUILD_FILES+=$(subst .asm,.lx2,${SOURCE})
+BUILD_FILES+=$(subst .asm,.bin,${SOURCE})
+
+all: ${BINARIES}
+
+include ../common.mk
+
+clean:
+ $(call QUIET_CLEAN,boot_code)
+ ${Q}rm -f $(BUILD_FILES) *lxt
diff --git a/cpu/brainfuck.asm b/boot_code/brainfuck.asm
similarity index 100%
rename from cpu/brainfuck.asm
rename to boot_code/brainfuck.asm
diff --git a/boot_code/brainfuck_mandelbrot.asm b/boot_code/brainfuck_mandelbrot.asm
new file mode 100644
index 0000000..ae39f2f
--- /dev/null
+++ b/boot_code/brainfuck_mandelbrot.asm
@@ -0,0 +1,264 @@
+; brainfuck.asm - Naive and unoptimised implementation of a brainfuck interpreter
+;
+; This file is part of the 9086 project.
+;
+; Copyright (c) 2023 Efthymios Kritikos
+;
+; This program is free software: you can redistribute it and/or modify
+; it under the terms of the GNU General Public License as published by
+; the Free Software Foundation, either version 3 of the License, or
+; (at your option) any later version.
+;
+; This program is distributed in the hope that it will be useful,
+; but WITHOUT ANY WARRANTY; without even the implied warranty of
+; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+; GNU General Public License for more details.
+;
+; You should have received a copy of the GNU General Public License
+; along with this program. If not, see .
+
+mov si,#prog
+mov BX,#data
+mov CX,#bracket
+dec si
+INTERPRET:
+inc si
+mov al,[si]
+cmp al,#'+
+jz WAS_PLUS
+cmp al,#'-
+jz WAS_MINUS
+cmp al,#'>
+jz WAS_MR
+cmp al,#'<
+jz WAS_ML
+cmp al,#'[
+jz WAS_PL
+cmp al,#']
+jz WAS_PR
+cmp al,#'.
+jz WAS_PRINT
+jmp PROG_END
+
+WAS_PLUS:
+inc BYTE [BX]
+JMP INTERPRET
+
+WAS_MINUS:
+dec BYTE [BX]
+JMP INTERPRET
+
+WAS_MR:
+inc bx
+JMP INTERPRET
+
+WAS_ML:
+dec bx
+JMP INTERPRET
+
+WAS_PL:
+MOV AL,[BX]
+cmp AL,#0
+jz SKIP_CODE_BLOCK
+;have to enter loop
+MOV AX,SI
+inc CX
+inc CX
+MOV SI,CX
+mov [SI],AX
+mov SI,AX
+JMP INTERPRET
+
+SKIP_CODE_BLOCK:
+;have to skip loop
+MOV DX,#0
+SKIP_LOOP:
+INC SI
+mov AL,[SI]
+CMP AL,#']
+JZ WAS_CLOSE1
+CMP AL,#'[
+JZ WAS_OPEN1
+JMP SKIP_LOOP
+
+WAS_CLOSE1:
+CMP DX,#0
+JZ INTERPRET
+DEC DX
+JMP SKIP_LOOP
+WAS_OPEN1:
+INC DX
+JMP SKIP_LOOP
+
+WAS_PR:
+mov AL,[BX]
+cmp AL,#0
+JZ EXIT_PR
+MOV SI,CX
+mov ax,[SI]
+mov si,ax
+JMP INTERPRET
+
+
+EXIT_PR:
+DEC CX
+DEC CX
+jmp INTERPRET
+
+
+WAS_PRINT:
+mov ah, #0x02
+MOV DL,[BX]
+int #0x21
+JMP INTERPRET
+
+PROG_END:
+hlt
+
+bracket: .BLKB 280
+data: .BLKB 560
+;prog db '++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++.f'
+prog:.ASCII '+++++++++++++[->++>>>+++++>++>+<<<<<<]>>>>>++++++>--->>>>>>>>>>+++++++++++++++[['
+.ASCII '>>>>>>>>>]+[<<<<<<<<<]>>>>>>>>>-]+[>>>>>>>>[-]>]<<<<<<<<<[<<<<<<<<<]>>>>>>>>[-]+'
+.ASCII '<<<<<<<+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>>>+>>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II '>>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<'
+.ASCII '<<<]>>>>>>>>-<<<<<[-]+<<<]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>->[>>>'
+.ASCII '>>>[->>+<<]>>>]<<<<<<<<<[>[-]<->>>>>>>>[-<<<<<<<<+>[<->-<<+>>]<[->+<]>>>>>>>>]<<'
+.ASCII '<<<<<[->>>>>>>+<<<<<<<]<+<<<<<<<<<]>+++++[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>'
+.ASCII '+>>>>>>>>>>>>>>>>>>>>>>>>>>>+<<<<<<[<<<<<<<<<]>>>>>>>>>[>>>>>>[-<<<<<<->>>>>>]+<'
+.ASCII '<<<<<[->>>>>>->>[-<<<<<<<<+>>>>>>>>]<<<<<<<<[->>>>>>>>+<<<<<<<<<<<<<<<<<[<<<<<<<'
+.ASCII '<<]>>>>[-]+>>>>>[>>>>>>>>>]>+<]]+>>>>>>>>[-<<<<<<<<->>>>>>>>]+<<<<<<<<[->>>>>>>>'
+.ASCII '-<<[-<<<<<<+>>>>>>]<<<<<<[->>>>>>+<<<<<<<<<<<<<<<[<<<<<<<<<]>>>[-]+>>>>>>[>>>>>>'
+.ASCII '>>>]>[-]+<]]+>[-<[>>>>>>>>>]<<<<<<<<]>>>>>>>>]<<<<<<<<<[<<<<<<<<<]>>>>[-]<<<++++'
+.ASCII '+[-[->>>>>>>>>+<<<<<<<<<]>>>>>>>>>]>>>>>->>>>>>>>>>>>>>>>>>>>>>>>>>>-<<<<<<[<<<<'
+.ASCII '<<<<<]]>>>]'
diff --git a/common.mk b/common.mk
new file mode 100644
index 0000000..f6490ba
--- /dev/null
+++ b/common.mk
@@ -0,0 +1,49 @@
+QUIET=1
+
+ifeq "${QUIET}" "1"
+ QUIET_AS = @echo ' AS '$@;
+ QUIET_VVP = @echo ' VVP '$@;
+ QUIET_IVERILOG = @echo ' IVERILOG '$@;
+ QUIET_CLEAN = @printf ' CLEAN %s\n' $1;
+ Q = @
+ MAKEOPTS=--no-print-directory
+.SILENT:
+else
+ Q =
+endif
+
+run: ${BOOT_CODE} ${SYSTEM_VVP}
+ ${QUIET_VVP}
+ ${Q}vvp "${SYSTEM_VVP}" -lxt2 +BOOT_CODE="$<" +WAVEFORM="$(subst .txt,.lx2,$<)" +MEMDUMP="$(subst .txt,.memdumptxt,$<)"
+ ${Q}grep -v '^//' "$(subst .txt,.memdumptxt,$<)" | xxd -ps -c 2 -r > "$(subst .txt,.memdump,$<)"
+ ${Q}rm "$(subst .txt,.memdumptxt,$<)"
+
+wave: $(subst .txt,.wave,${BOOT_CODE})
+disas: $(subst .txt,.disas,${BOOT_CODE})
+
+# Assembling code
+%.txt:%.bin
+ ${Q}dd if=/dev/zero bs=1 count=16384 of="$(subst .bin,.stage,$<)" status=none
+ ${Q}dd if="$<" of="$(subst .bin,.stage,$<)" conv=notrunc,nocreat status=none
+ ${Q}xxd -ps -c 2 "$(subst .bin,.stage,$<)" > "$@"
+ ${Q}rm "$(subst .bin,.stage,$<)"
+
+%.bin:%.asm
+ ${QUIET_AS}
+ ${Q}as86 -0 "$<" -b "$@"
+
+# Running simulation
+%.lx2 %.memdump: %.txt ${SYSTEM_VVP}
+ ${QUIET_VVP}
+ ${Q}vvp "${SYSTEM_VVP}" -lxt2 +BOOT_CODE="$<" +WAVEFORM="$(subst .txt,.lx2,$<)" +MEMDUMP="$(subst .txt,.memdumptxt,$<)"
+ ${Q}grep -v '^//' "$(subst .txt,.memdumptxt,$<)" | xxd -ps -c 2 -r > "$(subst .txt,.memdump,$<)"
+ ${Q}rm "$(subst .txt,.memdumptxt,$<)"
+
+.PHONY: disas
+%.disas: %.bin
+ objdump -D -b binary -m i8086 $^ | less
+
+# Tools
+.PHONY: %.wave
+%.wave : %.lx2
+ gtkwave "$<" "${GTKWSAVE}"
diff --git a/cpu/Makefile b/cpu/Makefile
deleted file mode 100644
index c782ba7..0000000
--- a/cpu/Makefile
+++ /dev/null
@@ -1,59 +0,0 @@
-# This file is part of the 9086 project.
-#
-# Copyright (c) 2023 Efthymios Kritikos
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program. If not, see .
-#
-SOURCES=processor.v testbench.v memory.v registers.v alu.v
-INCLUDES=proc_state_def.v alu_header.v config.v
-VVP=processor.vvp
-
-.PHONY: brainf
-brainf: ${VVP} brainfuck.txt
- vvp ${VVP} +BOOT_CODE=brainfuck.txt
- grep -v '^//' memdump.txt | xxd -ps -c 2 -r > memdump.bin
-
-.PHONY: run
-run: ${VVP} boot_code.txt
- vvp ${VVP}
- grep -v '^//' memdump.txt | xxd -ps -c 2 -r > memdump.bin
-
-.PHONY: build
-build: ${VVP}
-
-.PHONY: wave
-wave: ${VVP} brainfuck.txt
- vvp ${VVP} -lxt2 #+BOOT_CODE=brainfuck.txt
- gtkwave test.lx2 gtkwave_savefile.gtkw
- grep -v '^//' memdump.txt | xxd -ps -c 2 -r > memdump.bin
-
-${VVP} : ${SOURCES} ${INCLUDES}
- iverilog -g2012 ${SOURCES} -o $@
-
-%.txt:%.bin
- dd if=/dev/zero bs=1 count=16384 of=$(subst .bin,.stage,$^) status=none
- dd if=$^ of=$(subst .bin,.stage,$^) conv=notrunc,nocreat status=none
- xxd -ps -c 2 $(subst .bin,.stage,$^) > $@
- rm $(subst .bin,.stage,$^)
-
-%.bin:%.asm
- as86 -0 $< -b $@
-
-.PHONY: disas
-disas: brainfuck.bin
- objdump -D -b binary -m i8086 $^ | less
-
-.PHONY: clean
-clean:
- rm -f ${VVP} test.lx2 boot_code.txt boot_code.bin brainfuck.txt brainfuck.bin memdump.txt
diff --git a/cpu/test b/cpu/test
deleted file mode 100644
index 294f401..0000000
Binary files a/cpu/test and /dev/null differ
diff --git a/cpu/gtkwave_savefile.gtkw b/gtkwave_savefile.gtkw
similarity index 100%
rename from cpu/gtkwave_savefile.gtkw
rename to gtkwave_savefile.gtkw
diff --git a/system/Makefile b/system/Makefile
new file mode 100644
index 0000000..ecc9e31
--- /dev/null
+++ b/system/Makefile
@@ -0,0 +1,35 @@
+# This file is part of the 9086 project.
+#
+# Copyright (c) 2023 Efthymios Kritikos
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see .
+#
+SOURCES=processor.v testbench.v memory.v registers.v alu.v
+INCLUDES=proc_state_def.v alu_header.v config.v
+SYSTEM_VVP=system.vvp
+BOOT_CODE=boot_code.txt
+GTKWSAVE=../gtkwave_savefile.gtkw
+
+include ../common.mk
+
+# COMPILING
+${SYSTEM_VVP} : ${SOURCES} ${INCLUDES}
+ ${QUIET_IVERILOG}
+ ${Q}iverilog -g2012 ${SOURCES} -o $@
+
+
+.PHONY: clean
+clean:
+ $(call QUIET_CLEAN,system)
+ ${Q}rm -f ${SYSTEM_VVP} *.lx2 boot_code.txt boot_code.bin *memdump *memdumptxt
diff --git a/cpu/alu.v b/system/alu.v
similarity index 100%
rename from cpu/alu.v
rename to system/alu.v
diff --git a/cpu/alu_header.v b/system/alu_header.v
similarity index 100%
rename from cpu/alu_header.v
rename to system/alu_header.v
diff --git a/cpu/boot_code.asm b/system/boot_code.asm
similarity index 97%
rename from cpu/boot_code.asm
rename to system/boot_code.asm
index e6c3215..51c8ba3 100644
--- a/cpu/boot_code.asm
+++ b/system/boot_code.asm
@@ -16,6 +16,7 @@ inc [si]
inc [si]
inc [si]
dec [si]
+dec cx
cmp CX,#0x00
jz start
HLT
diff --git a/cpu/config.v b/system/config.v
similarity index 100%
rename from cpu/config.v
rename to system/config.v
diff --git a/cpu/memory.v b/system/memory.v
similarity index 87%
rename from cpu/memory.v
rename to system/memory.v
index a31985c..e3d1381 100644
--- a/cpu/memory.v
+++ b/system/memory.v
@@ -21,8 +21,10 @@ module mem(input [19:0] address,inout wire [15:0] data ,input rd,input wr,input
reg [15:0] memory [0:8191];
initial begin
string boot_code;
- if(!$value$plusargs("BOOT_CODE=%s",boot_code))
- boot_code="boot_code.txt";
+ if(!$value$plusargs("BOOT_CODE=%s",boot_code))begin
+ $display("No boot code specified. Please add +BOOT_CODE= to your vvp args");
+ $finish;
+ end
$readmemh(boot_code, memory);
end
diff --git a/cpu/proc_state_def.v b/system/proc_state_def.v
similarity index 100%
rename from cpu/proc_state_def.v
rename to system/proc_state_def.v
diff --git a/cpu/processor.v b/system/processor.v
similarity index 100%
rename from cpu/processor.v
rename to system/processor.v
diff --git a/cpu/registers.v b/system/registers.v
similarity index 100%
rename from cpu/registers.v
rename to system/registers.v
diff --git a/cpu/testbench.v b/system/testbench.v
similarity index 89%
rename from cpu/testbench.v
rename to system/testbench.v
index 508f0e0..0d70c28 100644
--- a/cpu/testbench.v
+++ b/system/testbench.v
@@ -38,9 +38,17 @@ clock_gen #(.FREQ(1000)) u1(clk_enable, clock);
assign romcs=0;
integer cycles=0;
+string memdump_name;
initial begin
- $dumpfile("test.lx2");
+ string waveform_name;
+ if(!$value$plusargs("WAVEFORM=%s",waveform_name))begin
+ waveform_name="waveform.lx2";
+ end
+ $dumpfile(waveform_name);
$dumpvars(0,p,u1);
+ if(!$value$plusargs("MEMDUMP=%s",memdump_name))begin
+ memdump_name="memdump.txt";
+ end
reset = 0;
clk_enable <= 1;
@@ -51,7 +59,7 @@ end
always @(posedge HALT) begin
$display("Processor halted.\nCycles run for: %d",cycles);
- $writememh("memdump.txt", sysmem.memory);
+ $writememh(memdump_name, sysmem.memory);
#(`CPU_SPEED) //Just for the waveform
$finish;
end
@@ -59,7 +67,7 @@ end
always @(posedge ERROR) begin
clk_enable <= 0;
$display("PROCESSOR RUN INTO AN ERROR.\nCycles run for: %d",cycles);
- $writememh("memdump.txt", sysmem.memory);
+ $writememh(memdump_name, sysmem.memory);
#(`CPU_SPEED) //Just for the waveform
$finish;
end