From 39ea8d54cae3eb3880cfc9586d553e2787516cb9 Mon Sep 17 00:00:00 2001 From: Sergei Dolin Date: Fri, 11 Nov 2022 17:20:59 +0300 Subject: [PATCH 1/2] The first sketches of the ROM BASIC. Testing required. --- Makefile | 21 ++++++++++++++++----- addchecksum.c | 29 +++++++++++++++++++++++++++++ basic.asm | 27 ++++++++++++++++++--------- 3 files changed, 63 insertions(+), 14 deletions(-) create mode 100644 addchecksum.c diff --git a/Makefile b/Makefile index 98594a9..70bfc22 100644 --- a/Makefile +++ b/Makefile @@ -3,22 +3,33 @@ src = basic.asm .PHONY: all -all: basic.img basic.com +all: basic.img basic.com basic.rom + +basic.rom: $(src) addchecksum + nasm -f bin -o $@ -Dbootrom=1 -Dbootsect=0 -Dcom_file=0 $(src) + ./addchecksum $@ || rm $@ basic.img: $(src) - nasm -f bin -o $@ $(src) + nasm -f bin -o $@ -Dbootsect=1 -Dbootrom=0 -Dcom_file=0 $(src) basic.com: $(src) - nasm -f bin -o $@ -Dcom_file=1 $(src) + nasm -f bin -o $@ -Dcom_file=1 -Dbootsect=0 -Dbootrom=0 $(src) + +addchecksum: addchecksum.c + gcc -o $@ $< -Wall .PHONY: clean clean: - $(RM) basic.img basic.com + $(RM) basic.img basic.com basic.rom addchecksum .PHONY: rundosbox rundosbox: basic.com dosbox $< -.PHONY: runqemu +.PHONY: fdrunqemu runqemu: basic.img qemu-system-i386 -fda basic.img + +.PHONY: romrunqemu +runqemu: basic.rom + qemu-system-i386 -net none -option-rom basic.rom diff --git a/addchecksum.c b/addchecksum.c new file mode 100644 index 0000000..a49703d --- /dev/null +++ b/addchecksum.c @@ -0,0 +1,29 @@ +/* addchecksum.c -- Calculate byte-wise checksum and overwrite last byte for PCI + * Copyright (C) 2014, Tobias Kaiser + */ + +#include +#include + +int main(int argc, char *argv[]) { + if(argc!=2) { + fprintf(stderr, "Usage: %s FILE\n\n", argv[0]); + exit(1); + } + FILE *f=fopen(argv[1], "r+"); + if(!f) { + perror("fopen failed"); + exit(1); + } + fseek(f, 0, SEEK_END); + int f_size=ftell(f); + fseek(f, 0, SEEK_SET); + unsigned char sum=0; + int i; + for(i=0;i Date: Sat, 12 Nov 2022 01:05:49 +0300 Subject: [PATCH 2/2] Added the ability to create a ROM image for a network card. --- Makefile | 17 ++++++++++------- README | 21 ++++++++++++++++++--- addchecksum | Bin 0 -> 9064 bytes basic.asm | 13 ++++++------- basic.com | Bin 504 -> 504 bytes basic.img | Bin 512 -> 512 bytes basic.rom | Bin 0 -> 1024 bytes 7 files changed, 34 insertions(+), 17 deletions(-) create mode 100755 addchecksum create mode 100644 basic.rom diff --git a/Makefile b/Makefile index 70bfc22..b3fc9ca 100644 --- a/Makefile +++ b/Makefile @@ -6,14 +6,17 @@ src = basic.asm all: basic.img basic.com basic.rom basic.rom: $(src) addchecksum - nasm -f bin -o $@ -Dbootrom=1 -Dbootsect=0 -Dcom_file=0 $(src) + nasm -f bin -o $@.tmp -Dbootrom $(src) + dd if=/dev/zero of=$@ bs=1 count=1024 + dd if=$@.tmp of=$@ bs=1 conv=notrunc ./addchecksum $@ || rm $@ + rm $@.tmp basic.img: $(src) - nasm -f bin -o $@ -Dbootsect=1 -Dbootrom=0 -Dcom_file=0 $(src) + nasm -f bin -o $@ -Dbootsect $(src) basic.com: $(src) - nasm -f bin -o $@ -Dcom_file=1 -Dbootsect=0 -Dbootrom=0 $(src) + nasm -f bin -o $@ -Dcom_file $(src) addchecksum: addchecksum.c gcc -o $@ $< -Wall @@ -26,10 +29,10 @@ clean: rundosbox: basic.com dosbox $< -.PHONY: fdrunqemu -runqemu: basic.img +.PHONY: runqemufd +runqemufd: basic.img qemu-system-i386 -fda basic.img -.PHONY: romrunqemu -runqemu: basic.rom +.PHONY: runqemurom +runqemurom: basic.rom qemu-system-i386 -net none -option-rom basic.rom diff --git a/README b/README index 064ceaf..45c7bad 100644 --- a/README +++ b/README @@ -5,7 +5,7 @@ | |_) | (_) | (_) | |_| |_/ / | | |/\__/ /_| |_| \__/\ |_.__/ \___/ \___/ \__\____/\_| |_/\____/ \___/ \____/ -bootBASIC interpreter in 512 bytes (boot sector or COM file) +bootBASIC interpreter in 512 bytes (boot sector, ROM BIOS or COM file) by Oscar Toledo G. Jul/22/2019 http://nanochess.org @@ -20,14 +20,29 @@ If you want to assemble it, you must download the Netwide Assembler Use this command line: - nasm -f bin basic.asm -Dcom_file=1 -o basic.com - nasm -f bin basic.asm -Dcom_file=0 -o basic.img + nasm -f bin basic.asm -Dcom_file -o basic.com + nasm -f bin basic.asm -Dbootsect -o basic.img + +To create a ROM image, you need to calculate the checksum. To do this, +there is a program addchecksum. It can be compiled with the gcc +compiler. As a result, the assembly of the ROM image will look +like this: + + gcc addchecksum.c -o addchecksum + nasm -f bin basic.asm -Dbootrom -o basic.rom + ./addchecksum basic.rom || rm basic.rom Tested with VirtualBox for Mac OS X running Windows XP running this interpreter, it also works with DosBox and probably with qemu: qemu-system-x86_64 -fda basic.img +or + + qemu-system-i386 -net none -option-rom basic.rom + +for ROM BIOS. + Enjoy it! diff --git a/addchecksum b/addchecksum new file mode 100755 index 0000000000000000000000000000000000000000..0b9c29e1fbd31004fc3b17edd6f9181f3a7ad055 GIT binary patch literal 9064 zcmeHNeQaCR6~DHdG)-H_DW&uS=-b*(g(yP_-{rnl>?Q(t@Tj#HKb?r?wzX3X_=jQB55JmcUp8bR|Ng-Z}T3 zV?V#x8k#g|e{iGs&ON_-&bjxV`|<9%&ZFV34zI@}IC;gr0=cPbO+xlth-WuQmarDF zOlV@GxK&gGQU#ADOOV<*rVC`6X${HwfG&Zj#cKmCUQK40-fF{8gPpjANU^?R(kN@w z$7^ktsSt_;P!HQ0@JkkGzsxWlrgn@IWj$n3Z!76-B|WAy)G(&pKkOSmJ!G%Ps{x0+ zhD5Z>cafqjru}bNQOrNEOtL^VnPJ*w!-6U6eF^liogX&^NU)pgtK^q?>K{{L#kNFz zpt)&VBHECMC$nP>V=c`M%}r`1rEZt~M*AqcYj3ZtiT$VmhizUB56%HBf9%q?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IV&+#VzU%(6+heXq%&>o%#r=ZMPKgXpD*eOWv_A<}(D#$qX3-K#eFf6SU zU#!P;!KKgV|6$VScCrQ5WBvwY5aa%j)46=Cg1*9vM19bBY=6*&vp)VZ>`W+&iD^CL zxo%lNuW!@Fv4RB&cd^nAuN|lU6t!Q$j}xTZ;n@Zc_aFB%OgPQU)jvZQgD<;`yX*fq Dt2ZZ* literal 0 HcmV?d00001 diff --git a/basic.asm b/basic.asm index 8c104fe..9e4ca06 100644 --- a/basic.asm +++ b/basic.asm @@ -138,13 +138,13 @@ cpu 8086 - %if com_file + %ifdef com_file org 0x0100 %endif - %if bootsect + %ifdef bootsect org 0x7c00 %endif - %if bootrom + %ifdef bootrom org 0 rom_size_multiple_of equ 512 bits 16 @@ -165,8 +165,7 @@ max_length: equ 20 ; Maximum length of line max_size: equ max_line*max_length ; Max. program size start: - %if com_file - %else + %ifndef com_file push cs ; For boot sector push cs ; it needs to setup push cs ; DS, ES and SS. @@ -596,11 +595,11 @@ statements: ; ; Boot sector filler ; - %if bootsect + %ifdef bootsect times 510-($-$$) db 0x4f db 0x55,0xaa ; Make it a bootable sector %endif - %if bootrom + %ifdef bootrom db 0 ; reserve at least one byte for checksum rom_end equ $-$$ rom_size equ (((rom_end-1)/rom_size_multiple_of)+1)*rom_size_multiple_of diff --git a/basic.com b/basic.com index 1abd83633500bfca0e4586627418ba17071223e6..a62e4a389f2c5a3bea1bfdc9a1aa81bc9d560fb2 100644 GIT binary patch delta 15 Wcmeyt{DXNzI3siO0g=g3jPn392L1y2P})*@3Dg%}|i;;x&&L+3WXkKr4Bmp4MHswU;b z-7PTRNlKn~-hltAAGF#zED}6KVh&SrjXZ2U6*v#UrsFP{RAJiIHn}I|*DtXCmFdsFHRxoFZ$z>x8c1W3X_9@Q$9%V3_X- zGz0B<+yM;3>O<#{pxJ&8J*69fvUtg`pdhiPo?vH|Kq_E)E(+*yT+g;CN zktbbGXft=50Sz0To=JV+O%aGU&E@G?9ES~hfQO1js_>t}3i=qPLtL@w5Icy25Tw6E z0snY-%eUwxj|m$ZgF!0S;uwOOVymxZX!MEtK=6PBrid7GH^U&!m#fTxNQE0k5?!p6 n4R)7A%f=#S4hRaxPj7N_Q%}; literal 0 HcmV?d00001