Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added the ability to work bootBASIC in BIOS ROM. #3

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,36 @@
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 [email protected] -Dbootrom $(src)
dd if=/dev/zero of=$@ bs=1 count=1024
dd [email protected] of=$@ bs=1 conv=notrunc
./addchecksum $@ || rm $@
rm [email protected]

basic.img: $(src)
nasm -f bin -o $@ $(src)
nasm -f bin -o $@ -Dbootsect $(src)

basic.com: $(src)
nasm -f bin -o $@ -Dcom_file=1 $(src)
nasm -f bin -o $@ -Dcom_file $(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
runqemu: basic.img
.PHONY: runqemufd
runqemufd: basic.img
qemu-system-i386 -fda basic.img

.PHONY: runqemurom
runqemurom: basic.rom
qemu-system-i386 -net none -option-rom basic.rom
21 changes: 18 additions & 3 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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!


Expand Down
Binary file added addchecksum
Binary file not shown.
29 changes: 29 additions & 0 deletions addchecksum.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/* addchecksum.c -- Calculate byte-wise checksum and overwrite last byte for PCI
* Copyright (C) 2014, Tobias Kaiser <[email protected]>
*/

#include <stdio.h>
#include <stdlib.h>

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<f_size-1;i++) {
sum+=fgetc(f);
}
fputc((0x100-sum)&0xff, f);
fclose(f);
return 0;
}
32 changes: 20 additions & 12 deletions basic.asm
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,21 @@

cpu 8086

%ifndef com_file ; If not defined create a boot sector
com_file: equ 0
%endif

%if com_file
%ifdef com_file
org 0x0100
%else
%endif
%ifdef bootsect
org 0x7c00
%endif

%ifdef bootrom
org 0
rom_size_multiple_of equ 512
bits 16
; PCI Expansion Rom Header
; ------------------------
db 0x55, 0xAA ; signature
db rom_size/512; initialization size in 512 byte blocks
%endif
vars: equ 0x7e00 ; Variables (multiple of 256)
line: equ 0x7e80 ; Line input

Expand All @@ -160,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.
Expand Down Expand Up @@ -591,9 +595,13 @@ statements:
;
; Boot sector filler
;
%if com_file
%else
%ifdef bootsect
times 510-($-$$) db 0x4f
db 0x55,0xaa ; Make it a bootable sector
%endif

%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
; times rom_size - rom_end db 0 ; padding
%endif
Binary file modified basic.com
Binary file not shown.
Binary file modified basic.img
Binary file not shown.
Binary file added basic.rom
Binary file not shown.