1
0
mirror of synced 2026-01-30 05:34:52 +00:00

Add BootROM support.

This commit is contained in:
Matthieu Bucchianeri
2025-01-12 00:36:46 -08:00
committed by Ted Fried
parent 5662d3988e
commit d2f95788e5
7 changed files with 265 additions and 2 deletions

2
XTMax/Drivers/BootROM/.gitignore vendored Normal file
View File

@@ -0,0 +1,2 @@
bootrom
bootrom.com

View File

@@ -0,0 +1,20 @@
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build with NASM",
"type": "shell",
"command": ".\\build.cmd",
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [],
"group": {
"kind": "build",
"isDefault": true
}
}
]
}

View File

@@ -0,0 +1,72 @@
bits 16
%ifndef AS_COM
;
; BIOS will look for the AA55 signature between C8000-DFFFF in 2KB increments.
; We choose an address in that range.
;
org 0xce000
dw 0AA55h
db 4 ; times 512 bytes
%else
;
; Building as a COM file for testing.
;
org 0x100
%endif
entry:
%ifndef AS_COM
mov ax, 0xc000
mov ds, ax
mov es, ax
%endif
mov si, welcome
call print_string
%ifndef AS_COM
retf
%else
;
; DOS exit program.
;
mov ah, 0x4c
xor al, al
int 0x21
%endif
;
; Utilities
;
print_string:
push bx
xor bx,bx
.loop:
lodsb
or al, al
jz .done
mov ah, 0x0E
int 0x10
jmp .loop
.done:
pop bx
ret
;
; Strings
;
welcome db 'BootROM for XTMax v0.1', 0x0D, 0x0A, 0
%ifndef AS_COM
;
; Pad to 2KB. We will try to keep our ROM under that size.
;
times 2047-($-$$) db 0
db 0 ; will be used to complete the checksum.
%endif

View File

@@ -0,0 +1,2 @@
..\Driver_Build_Tools\NASM\nasm.exe -f bin -o bootrom.com -DAS_COM .\bootrom.asm
..\Driver_Build_Tools\NASM\nasm.exe -f bin -o bootrom .\bootrom.asm & python checksum.py

View File

@@ -0,0 +1,23 @@
# https://stackoverflow.com/questions/53808694/how-do-i-format-a-python-list-as-an-initialized-c-array
def to_c_array(values, ctype="float", name="table", formatter=str, colcount=8):
# apply formatting to each element
values = [formatter(v) for v in values]
# split into rows with up to `colcount` elements per row
rows = [values[i:i+colcount] for i in range(0, len(values), colcount)]
# separate elements with commas, separate rows with newlines
body = ',\n '.join([', '.join(r) for r in rows])
# assemble components into the complete string
return '{} {}[] = {{\n {}}};'.format(ctype, name, body)
with open("bootrom", "rb") as f:
b = bytearray(f.read())
# compute the checksum and store a byte to
b[-1] = 256 - sum(b[0:-1]) & 0xff
with open("bootrom", "wb") as f:
f.write(b)
with open("../../Code/XTMax/bootrom.h", "w") as f:
f.write("#define BOOTROM_ADDR 0xCE000\n")
f.write(to_c_array(b, ctype="unsigned char", name="BOOTROM", colcount=16))