Skip to content

Commit

Permalink
Configuration file for framework features (#7)
Browse files Browse the repository at this point in the history
* Add option to build for real hardware
* Introduce centralized configuration for build process.
* Use addchip.bootblock sources. Perpare ADF in Makefile.
* Add chip & fast preallocated memory sizes to config.mk
* Redirect logging to serial port.
* Choose where to output diagnostic and log messages.
* Add extra comments to kputchar
* Rewrite based on exec's RawPutChar
* Reimplement DPutChar by looking at PRawPutChar from ddebug.lib

Co-authored-by: Krystian Bacławski <[email protected]>
  • Loading branch information
spookbench and cahirwpz committed Nov 30, 2022
1 parent b833ff2 commit ae3941c
Show file tree
Hide file tree
Showing 14 changed files with 316 additions and 39 deletions.
9 changes: 4 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ TOPDIR = $(realpath .)

SUBDIRS = tools lib system effects intro
EXTRA-FILES = tags cscope.out
CLEAN-FILES = bootloader.bin
CLEAN-FILES = bootloader.bin a500rom.bin addchip.bootblock.bin

all: a500rom.bin bootloader.bin build
all: a500rom.bin bootloader.bin addchip.bootblock.bin build

include $(TOPDIR)/build/common.mk
addchip.bootblock.bin: VASMFLAGS += -phxass -cnop=0

a500rom.bin: ASFLAGS += -phxass
bootloader.bin: ASFLAGS += -phxass
include $(TOPDIR)/build/common.mk

FILES := $(shell find include lib system -type f -iname '*.[ch]')

Expand Down
163 changes: 163 additions & 0 deletions addchip.bootblock.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
; Downloaded from https://github.com/earok/close-and-run-amiga68k

include 'lvo/exec_lib.i'
include 'lvo/intuition_lib.i'

Height EQU 50
zeropage EQU $100

RT_INIT EQU $16
lib_Version EQU $14
LibList EQU $17a
io_Device EQU $14
KS20 EQU 36


boot dc.b 'DOS',0
dc.b 'r05s' ;tagged
dc.l 880

start movem.l d2-d5/a2/a5,-(a7)

moveq #-1,d0 ;disable externals drives
movea.l io_Device(a1),a1
movea.l $3c(a1),a1 ;the 'old times mod'
lea $34(a1),a1
move.l d0,(a1)+ ;df1:
move.l d0,(a1)+ ;df2:
move.l d0,(a1) ;and why not.. df3:

moveq #0,d4
cmpi.w #KS20,lib_Version(a6) ;fork
shs d4

lea zeropage.w,a5 ;a0jmp
move.l a5,d5
lea a0jmp(pc),a0
moveq #(endscreen-a0jmp)/4-1,d0
_l move.l (a0)+,(a5)+
dbf d0,_l ;at end a5=zerobss

movea.l LibList(a6),a0
lea intuitionlib(pc),a1
jsr _LVOFindName(a6)
move.l d0,(a5)+ ;intuitionbase
beq.b _exit

lea intuitionlib(pc),a1
jsr _LVOFindResident(a6)
tst.l d0 ;can be omitted..
beq.b _exit

lea wbname(pc),a1 ;'Workbench Screen',0
moveq #doslib-wbname,d1 ;strlen
bsr.b findstrres
move.l a0,title-(zerobss+4)(a5)

move.l d4,(a5)+ ;v36?
beq.b notags
moveq #10,d1 ;strlen
clr.b -1(a1,d1.w) ;'Workbench',0
bsr.b findstrres
move.l a0,pubname-(zerobss+8)(a5)


notags lea doslib(pc),a1
jsr _LVOFindResident(a6)
tst.l d0
beq.b _exit
movea.l d0,a1
move.l RT_INIT(a1),(a5) ;dosinit

tst.l d4 ;v36?
beq.b _done
move.w #Height,_h-(zerobss+8)(a5) ;set height for >=v36
jsr _LVOCacheClearU(a6)

_done moveq #-1,d0
_exit movea.l d5,a0 ;a0jmp
not.l d0
movem.l (sp)+,d2-d5/a2/a5
rts


;input: d0=resident base
; d1=strlen
; a1=string to search
;output: a0=&str
;used: d2/d3/a2 saved by main, a0 as return code

findstrres movea.l d0,a0
_search move.w d1,d2
subq.w #2,d2 ;-(dbne,+)
movea.l a1,a2
move.b (a2)+,d3
_s1 cmp.b (a0)+,d3
bne.b _s1
_s2 cmpm.b (a2)+,(a0)+
dbne d2,_s2
bne.b _search
suba.l d1,a0
rts

wbname dc.b 'Workbench Screen',0
doslib dc.b 'dos.library',0
intuitionlib dc.b 'intuition.library',0

cnop 0,4

fakechecksum dc.l $b99c2e9d

a0jmp lea zerobss(pc),a5
movea.l (a5)+,a6 ;intuitionbase
jsr _LVOOpenIntuition(a6) ;KS1.x mandatory (undocumented)
lea wbscreen(pc),a0
tst.l (a5)+
bne.b v36
jsr _LVOOpenScreen(a6)
bra.s dos
v36 lea tagitems(pc),a1 ;Workbench need to be Pub
jsr _LVOOpenScreenTagList(a6)
dos movea.l (a5),a0 ;dosinit
jmp (a0) ;start amigados
cnop 0,4

tagitems dc.l $8000002f ;SA_PubName
pubname dc.l 0 ;'Workbench',0
; dc.l 0 ;TAG_DONE (fixed to wbscreen struct)
;
wbscreen dc.w 0 ;WORD LeftEdge
dc.w 0 ;WORD TopEdge
dc.w 640 ;WORD Widht
_h dc.w 200 ;WORD Height (KS1.x min height)
dc.w 1 ;WORD Depth
dc.b 0,1 ;UBYTE DetailPen, BlockPen
dc.w $8000 ;UWORD ViewModes -> HIRES
dc.w 1 ;UWORD Type -> WBENCHSCREEN
dc.l 0 ;struct TextAttr *Font, defaults
title dc.l 0 ;UBYTE *DefaultTitle, ROM
dc.l 0 ;struct Gadget *Gadgets, UNUSED
dc.l 0 ;struct BitMap *CustomBitMap, NULL
endscreen ;
;
zerobss ; ;(fixed to wbscreen struct)
;intuitionbase ;zerobss+0
; ds.l 1
;stag ;zerobss+4
; ds.l 1
;dosinit ;zerobss+8
; ds.l 1
endzero

cnop 0,16
ver dc.b '$VER: addchip.bootblock 1.1 (27.07.2017) by ross',0

cnop 0,16
message dc.b ' This code snippet allows you to regain some precious chip ram. '
cnop 0,16
dc.b '* Greetings to all Evergreen Amiga Board members! *'
even

END

; vim: ft=asm68k:ts=8:sw=8:et
13 changes: 9 additions & 4 deletions build/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@ LDSCRIPT := $(TOPDIR)/system/amiga.lds

# Don't reload library base for each call
CPPFLAGS += -D__CONSTLIBBASEDECL__=const
CPPFLAGS += -DCHIPMEM_KB=$(CHIPMEM) -DFASTMEM_KB=$(FASTMEM) -DLOGOUT=$(LOGOUT)

# Default configuration
FRAMES_PER_ROW ?= 6
include $(TOPDIR)/config.mk

ifeq ($(UAE), 1)
CPPFLAGS += -DUAE
endif

ifeq ($(AMIGAOS), 1)
CPPFLAGS += -DAMIGAOS
endif

# Pass "VERBOSE=1" at command line to display command being invoked by GNU Make
ifneq ($(VERBOSE), 1)
ifeq ($(VERBOSE), 0)
.SILENT:
QUIET := --quiet
endif
Expand Down
20 changes: 17 additions & 3 deletions build/effect.mk
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,14 @@ CRT0 = $(TOPDIR)/system/crt0.o
MAIN ?= $(TOPDIR)/effects/main.o
BOOTLOADER = $(TOPDIR)/bootloader.bin
ROMSTARTUP = $(TOPDIR)/a500rom.bin
BOOTBLOCK = $(TOPDIR)/addchip.bootblock.bin

EXTRA-FILES += $(DATA_GEN) $(EFFECT).img $(EFFECT).adf $(EFFECT).rom
CLEAN-FILES += $(DATA_GEN) $(EFFECT).exe $(EFFECT).exe.dbg $(EFFECT).exe.map
EXTRA-FILES += $(DATA_GEN) $(EFFECT).adf
CLEAN-FILES += $(DATA_GEN) $(EFFECT).exe $(EFFECT).exe.dbg $(EFFECT).exe.map

ifeq ($(AMIGAOS), 0)
EXTRA-FILES += $(EFFECT).img $(EFFECT).rom
endif

all: build

Expand Down Expand Up @@ -66,6 +71,7 @@ data/%.c: data/%.sync
@echo "[SYNC] $(DIR)$< -> $(DIR)$@"
$(SYNC2C) $(SYNC2C.$*) $< > $@ || (rm -f $@ && exit 1)

ifeq ($(AMIGAOS), 0)
%.img: %.exe $(DATA) $(DATA_GEN)
@echo "[IMG] $(addprefix $(DIR),$*.exe $(DATA) $(DATA_GEN)) -> $(DIR)$@"
$(FSUTIL) create $@ $(filter-out %bootloader.bin,$^)
Expand All @@ -77,6 +83,14 @@ data/%.c: data/%.sync
%.rom: %.img $(ROMSTARTUP)
@echo "[ROM] $(DIR)$< -> $(DIR)$@"
$(ROMUTIL) $(ROMSTARTUP) $< $@
else
%.adf: %.exe $(BOOTBLOCK)
@echo "[ADF] $(DIR)$< -> $(DIR)$@"
echo $< > startup-sequence
xdftool $@ format dos + write $< + makedir s + write startup-sequence s
dd if=$(BOOTBLOCK) of=$@ conv=notrunc status=none
rm startup-sequence
endif

# Default debugger - can be changed by passing DEBUGGER=xyz to make.
DEBUGGER ?= gdb
Expand All @@ -97,4 +111,4 @@ $(TOPDIR)/gdb-dashboard:
make -C $(TOPDIR) gdb-dashboard

.PHONY: run debug run-floppy debug-floppy
.PRECIOUS: $(BOOTLOADER) $(EFFECT).img
.PRECIOUS: $(BOOTLOADER) $(BOOTBLOCK) $(EFFECT).img
29 changes: 29 additions & 0 deletions config.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 1 => Use fs-uae dependant features i.e. call-traps (see `include/uae.h`)
# to aid debugging and profiling. This may render executable files
# unusable (most likely crash) on real hardware.
# 0 => Disable use of aforementioned features. Required for a release!
UAE := 1

# [only when UAE=0] Redirect diagnostic and log messages to:
# 0 => null output (drop messages)
# 1 => parallel port
# 2 => serial port
LOGOUT := 2

# 1 => Make executable files compatible with AmigaOS. Created ADFs will
# be formatted with Old Filesystem (KS1.3) and contain special bootblock
# that maximizes amount of chip memory. Executable file will be started
# automatically facilitating `startup-sequence` feature of AmigaDOS.
# 0 => Executable files must be started from ROM or ADF since they require
# custom environment created by bootstrap code.
AMIGAOS := 0

# [only when AMIGAOS=1] Amount of chip and fast (or public) memory
# (in kilobytes!) passed to our custom memory allocator.
# To calculate total memory taken after an executable file
# is loaded into memory please use `m68k-amigaos-objdump` tool.
CHIPMEM := 160
FASTMEM := 288

# Pass "VERBOSE=1" at command line to display command being invoked by GNU Make
VERBOSE ?= 0
2 changes: 2 additions & 0 deletions include/custom_regdef.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ struct Custom {
#define intena 0x09a
#define intreqr 0x01e
#define intreq 0x09c
#define serdatr 0x018
#define serdat 0x030

#endif

Expand Down
5 changes: 5 additions & 0 deletions include/system/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
#define Log(...) UaeLog(__VA_ARGS__);
#define Panic(...) { UaeLog(__VA_ARGS__); PANIC(); }
#else
#if LOGOUT > 0
void Log(const char *format, ...)
__attribute__ ((format (printf, 1, 2)));
__noreturn void Panic(const char *format, ...)
__attribute__ ((format (printf, 1, 2)));
#else
#define Log(...)
#define Panic(...) HALT()
#endif
#endif

#ifdef _SYSTEM
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ pycodestyle
pygments
zopflipy
blessings
amitools
5 changes: 2 additions & 3 deletions system/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
TOPDIR := $(realpath ..)

# AMIGAOS => save & restore AmigaOS context
# (for intros or trackmos that can be launched from AmigaOS)
CPPFLAGS += -D_SYSTEM

LIBNAME := system
SOURCES := \
amigaos.c \
autoinit.c \
debug.c \
debug-putchar.S \
dputchar.S \
kputchar.S \
effect.c \
loader.c \
profiler.c \
Expand Down
4 changes: 2 additions & 2 deletions system/amigaos.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ static ExcVecT oldExcVec;
static void *oldSysStack;

/* Memory for framework allocator. */
static __aligned(4) __bss_chip char ChipMem[160 * 1024];
static __aligned(4) char FastMem[288 * 1024];
static __aligned(4) __bss_chip char ChipMem[CHIPMEM_KB * 1024];
static __aligned(4) char FastMem[FASTMEM_KB * 1024];

/* Normally BootDataT is provided by the boot loader. Since we were started
* from AmigaOS we have to fill this structure and pass it to Loader. */
Expand Down
19 changes: 0 additions & 19 deletions system/debug-putchar.S

This file was deleted.

Loading

0 comments on commit ae3941c

Please sign in to comment.