From 878cc67a83859873c658713ec7bc92d1f8b856c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Juhani=20Krekel=C3=A4?= Date: Sun, 19 Mar 2023 20:49:03 +0200 Subject: [PATCH] Extract globals as well as syscalls from the symbol map --- Makefile | 6 +++--- add_syscalls.py => extract_symbols.py | 20 +++++++++++++++++--- ponydos.asm | 2 +- ponydos_nosyscall.inc => ponydos_static.inc | 1 + 4 files changed, 22 insertions(+), 7 deletions(-) rename add_syscalls.py => extract_symbols.py (68%) rename ponydos_nosyscall.inc => ponydos_static.inc (81%) diff --git a/Makefile b/Makefile index 245bed2..3c303ca 100644 --- a/Makefile +++ b/Makefile @@ -11,10 +11,10 @@ FS_FILES = wallpaper.bin shell.bin ponydos.img: ponydos.bin $(FS_FILES) $(PYTHON) assemble_floppy.py $@ ponydos.bin $(FS_FILES) -ponydos.inc: ponydos.asm ponydos_nosyscall.inc - $(NASM) -fbin -d SYMBOLS -o /dev/null ponydos.asm | $(PYTHON) add_syscalls.py $@ ponydos_nosyscall.inc +ponydos.inc: ponydos.asm ponydos_static.inc + $(NASM) -fbin -d SYMBOLS -o /dev/null ponydos.asm | $(PYTHON) extract_symbols.py $@ ponydos_static.inc -ponydos.bin: ponydos_nosyscall.inc +ponydos.bin: ponydos_static.inc shell.bin: ponydos.inc diff --git a/add_syscalls.py b/extract_symbols.py similarity index 68% rename from add_syscalls.py rename to extract_symbols.py index 3ae4028..0005173 100644 --- a/add_syscalls.py +++ b/extract_symbols.py @@ -6,6 +6,12 @@ syscalls = { 'draw_rect': None, } +variables = { + 'mouse_column': None, + 'mouse_row': None, + 'mouse_buttons': None, +} + if len(sys.argv) != 3: print(f'Usage: {sys.argv[0]} outfile infile', file=sys.stderr) sys.exit(1) @@ -28,12 +34,12 @@ while True: section = None for line in mapfile: line = line.split() - if len(line) == 4 and all(c == '-' for c in line[0]) and line[1] == 'Section' and all(c == '-' for c in line[3]): - section = line[2] - if section == '.text' and len(line) == 3: + if len(line) == 3: address, _, name = line if name in syscalls: syscalls[name] = int(address, 16) + if name in variables: + variables[name] = int(address, 16) header += f'\n;This was automatically generated\n' @@ -43,5 +49,13 @@ for syscall, address in syscalls.items(): sys.exit(1) header += f'SYS_{syscall.upper()} equ 0x{address:x}\n' +header += '\n' + +for variable, address in variables.items(): + if address is None: + print(f'{sys.argv[0]}: Error: global {variable} not found', file=sys.stderr) + sys.exit(1) + header += f'GLOBAL_{variable.upper()} equ 0x{address:x}\n' + with open(outfile, 'w') as f: f.write(header) diff --git a/ponydos.asm b/ponydos.asm index 97bd571..6e80047 100644 --- a/ponydos.asm +++ b/ponydos.asm @@ -1,7 +1,7 @@ %ifdef SYMBOLS [map symbols] %endif -%include "ponydos_nosyscall.inc" +%include "ponydos_static.inc" cpu 286 bits 16 diff --git a/ponydos_nosyscall.inc b/ponydos_static.inc similarity index 81% rename from ponydos_nosyscall.inc rename to ponydos_static.inc index 487b2e0..d9005c9 100644 --- a/ponydos_nosyscall.inc +++ b/ponydos_static.inc @@ -3,3 +3,4 @@ PONYDOS_SEG equ 0 GLOBAL_WALLPAPER equ 0x500 WM_INITIALIZE equ 0 +WM_PAINT equ 1