Skip to content
Merged
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
9 changes: 8 additions & 1 deletion arch/zx48k/backend/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def init():
OPTIONS.add_option('heap_start_label', str, 'ZXBASIC_MEM_HEAP')
# Labels for HEAP SIZE (might not be used if not needed)
OPTIONS.add_option('heap_size_label', str, 'ZXBASIC_HEAP_SIZE')
# Flag for headerless mode (No prologue / epilogue)
OPTIONS.add_option('headerless', bool, False)


def new_ASMID():
Expand Down Expand Up @@ -402,6 +404,9 @@ def _end(ins):
FLAG_end_emitted = True

output.append('%s:' % END_LABEL)
if OPTIONS.headerless.value:
return output + ['ret']

output.append('di')
output.append('ld hl, (%s)' % CALL_BACK)
output.append('ld sp, hl')
Expand Down Expand Up @@ -2164,7 +2169,9 @@ def __str__(self):
# Program Start routine
# -------------------------
def emit_start():
output = []
output = list()
if OPTIONS.headerless.value:
return output

output.append('org %s' % OPTIONS.org.value)

Expand Down
17 changes: 17 additions & 0 deletions tests/functional/headerless.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
ld a, (_a)
inc a
ld (_a), a
ld hl, 0
ld b, h
ld c, l
__END_PROGRAM:
ret

ZXBASIC_USER_DATA:
_a:
DEFB 02h
; Defines DATA END --> HEAP size is 0
ZXBASIC_USER_DATA_END EQU ZXBASIC_MEM_HEAP
; Defines USER DATA Length in bytes
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
END
6 changes: 6 additions & 0 deletions tests/functional/headerless.bas
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
REM a headerless (no prologuqe in ASM) program
#pragma headerless=true

DIM a as UByte = 2
LET a = a + 1

3 changes: 3 additions & 0 deletions zxb.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def main(args=None):
help='Add colon separated list of directories to add to include path. e.g. -I dir1:dir2')
parser.add_argument('--strict', action='store_true',
help='Enables strict mode. Force explicit type declaration')
parser.add_argument('--headerless', action='store_true',
help='Header-less mode: omit asm prologue and epilogue')
parser.add_argument('--version', action='version', version='%(prog)s {0}'.format(VERSION))

options = parser.parse_args(args=args)
Expand All @@ -166,6 +168,7 @@ def main(args=None):
OPTIONS.explicit.value = options.explicit
OPTIONS.memory_map.value = options.memory_map
OPTIONS.strict.value = options.strict
OPTIONS.headerless.value = options.headerless

if options.defines:
for i in options.defines:
Expand Down