Skip to content
Permalink
Browse files

Start writing C headers, add kernel-headers target

  • Loading branch information...
ddevault committed Nov 15, 2014
1 parent 59c9b39 commit 94f59c35c814f0851480501d5c52eaf23330ab4a
Showing with 116 additions and 2 deletions.
  1. +1 −0 .gitignore
  2. +23 −2 Makefile
  3. +1 −0 headers/README
  4. +71 −0 headers/display.h
  5. +2 −0 headers/kernel.h.end
  6. +11 −0 headers/kernel.h.start
  7. +7 −0 headers/package.config
@@ -1,2 +1,3 @@
bin/
*.swp
*.pkg
@@ -3,6 +3,7 @@ AS=sass
ASFLAGS=--encoding "Windows-1252"
.DEFAULT_GOAL=TI84pSE
PLATFORM:=TI84pSE
TAG:=$(shell git describe --abbrev=0)
OUTDIR=bin/

# Platforms:
@@ -68,7 +69,7 @@ DEFINES=--define $(PLATFORM)
BINDIR=$(OUTDIR)$(PLATFORM)/
INCLUDE=include/;$(BINDIR)

.PHONY: clean kernel baserom \
.PHONY: clean kernel baserom kernel-headers \
TI73 TI83p TI83pSE TI84p TI84pSE TI84pCSE

run: TI84pSE
@@ -79,12 +80,32 @@ kernel: baserom $(OUTDIR)$(PLATFORM)/00.bin $(OUTDIR)$(PLATFORM)/01.bin $(OUTDIR
$(BINDIR)00.bin:0x00 $(BINDIR)01.bin:0x4000 \
$(BINDIR)02.bin:0x8000 $(BINDIR)boot.bin:0x$(BOOT) \
$(BINDIR)privileged.bin:0x$(PRIVILEGED)
# Generate assembly headers
mkdir -p $(BINDIR)../include/
patchrom src/00/jumptable.config $(BINDIR)kernel.rom 00 < $(BINDIR)00.sym > $(BINDIR)00.inc
patchrom src/01/jumptable.config $(BINDIR)kernel.rom 01 < $(BINDIR)01.sym > $(BINDIR)01.inc
patchrom src/02/jumptable.config $(BINDIR)kernel.rom 02 < $(BINDIR)02.sym > $(BINDIR)02.inc
cat include/kernel.inc include/kernelmem.inc include/defines.inc include/constants.asm $(BINDIR)00.inc $(BINDIR)01.inc $(BINDIR)02.inc > $(BINDIR)../kernel.inc
cat include/kernel.inc include/kernelmem.inc include/defines.inc include/constants.asm $(BINDIR)00.inc $(BINDIR)01.inc $(BINDIR)02.inc > $(BINDIR)../include/kernel.inc
# Generate C headers
patchrom -c src/00/jumptable.config $(BINDIR)kernel.rom 00 < $(BINDIR)00.sym > $(BINDIR)00.h
patchrom -c src/01/jumptable.config $(BINDIR)kernel.rom 01 < $(BINDIR)01.sym > $(BINDIR)01.h
patchrom -c src/02/jumptable.config $(BINDIR)kernel.rom 02 < $(BINDIR)02.sym > $(BINDIR)02.h
cat headers/kernel.h.start $(BINDIR)00.h $(BINDIR)01.h $(BINDIR)02.h headers/kernel.h.end > $(BINDIR)../include/kernel.h
cp headers/*.h $(BINDIR)../include/
# Generate kernel upgrade file
mktiupgrade -p -k keys/$(KEY).key -d $(DEVICE) $(BINDIR)kernel.rom $(BINDIR)kernel.$(UPGRADEEXT) 00 01 02 03

kernel-headers-$(TAG).pkg:
rm -rf temp
mkdir -p temp/root/include
cp headers/package.config temp/
cp -r bin/include temp/root/
echo "version=$$(git describe --abbrev=0)" >> temp/package.config
kpack -c temp/package.config kernel-headers-$(TAG).pkg temp/root/
rm -rf temp

kernel-headers: kernel-headers-$(TAG).pkg

baserom:
mkdir -p $(BINDIR)
mkrom $(BINDIR)kernel.rom $(LENGTH) /dev/null:0x00
@@ -0,0 +1 @@
This directory contains headers for userspace programs written in C.
@@ -0,0 +1,71 @@
#ifndef __DISPLAY_H
#define __DISPLAY_H

#include <kernel.h>

typedef unsigned char SCREEN;

unsigned char left_margin = 0;

inline void get_lcd_lock() __naked {
__asm
PCALL(GETLCDLOCK)
__endasm;
}

SCREEN *create_screen() __naked {
__asm
PCALL(ALLOCSCREENBUFFER)
PUSH IY
POP HL
RET
__endasm;
}

void clear_buffer(SCREEN *screen) {
__asm
POP IX
POP IY
PCALL(CLEARBUFFER)
PUSH IY
PUSH IX
__endasm;
screen;
}

void fast_copy(SCREEN *screen) {
__asm
POP IX
POP IY
PCALL(FASTCOPY)
PUSH IY
PUSH IX
__endasm;
screen;
}

inline void set_left_margin(unsigned char margin) {
left_margin = margin;
}

void draw_str(SCREEN *screen, unsigned char x, unsigned char y, const char *string) {
__asm
POP IX
POP IY
POP DE
ld hl, _left_margin
ld b, (hl)
POP HL
ld a, d
ld d, e
ld e, a
PCALL(DRAWSTR)
PUSH HL
PUSH DE
PUSH IY
PUSH IX
__endasm;
screen; x; y; string;
}

#endif
@@ -0,0 +1,2 @@

#endif
@@ -0,0 +1,11 @@
#ifndef __JUMPTABLE_H
#define __JUMPTABLE_H

#define PCALL(ADDRESS) \
.if ADDRESS & 0xFF \ \
rst 0x20 \ \
.dw ADDRESS \ \
.else \ \
call 0x4000 - (((ADDRESS >> 8) + 1) * 3) \ \
.endif

@@ -0,0 +1,7 @@
name=kernel-headers
repo=core
description=Development headers for the KnightOS kernel
# The headers are in the public domain, because they describe an API
# The implementation (i.e. the kernel itself) is still MIT/X11
copyright=Public Domain
infourl=http://www.knightos.org/documentation/reference/

0 comments on commit 94f59c3

Please sign in to comment.
You can’t perform that action at this time.