Skip to content

Commit ec7c844

Browse files
committed
Add kernel RNG and refactor boot
1 parent 1b4fa9f commit ec7c844

File tree

13 files changed

+171
-334
lines changed

13 files changed

+171
-334
lines changed

Makefile

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,13 +71,7 @@ TI84pCSE: BOOT := 3FC000
7171
TI84pCSE: LENGTH := 0x400000
7272
TI84pCSE: kernel $(OUTDIR)
7373

74-
SKIPON:=NO
75-
76-
ifeq ($(SKIPON),YES)
77-
DEFINES=--define $(PLATFORM) --define SKIPON
78-
else
7974
DEFINES=--define $(PLATFORM)
80-
endif
8175
BINDIR=$(OUTDIR)$(PLATFORM)/
8276
INCLUDE=include/;$(BINDIR)
8377

include/kernelmem.inc

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,10 @@ clip_mask .equ currentContrast + 2 ; 1 byte
5151

5252
color_mode .equ clip_mask + 1 ; 1 byte
5353

54+
random_seed .equ color_mode + 1 ; 8 bytes
55+
5456
flashFunctions .equ stateMemory + stateMemorySize
5557
kernelGarbage .equ flashFunctions + flashFunctionSize
5658

57-
#ifdef DEBUG
58-
debugBuffer .equ kernelGarbage + kernelGarbageSize
59-
userMemory .equ debugBuffer + 0x300
60-
userMemorySize .equ 0xFFFF - userMemory ; user memory extends to 0xFFFF
61-
#else
6259
userMemory .equ kernelGarbage + kernelGarbageSize
6360
userMemorySize .equ 0xFFFF - userMemory ; user memory extends to 0xFFFF
64-
#endif

src/00/base.asm

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
; Base file for KnightOS kernel
2-
#define DEBUG
32

43
#include "platforms.inc"
54
#include "defines.inc"
@@ -44,13 +43,10 @@ drawHexHL .equ 0x0D01
4443
#include "keyboard.asm"
4544

4645
#include "math.asm"
46+
#include "random.asm"
4747
#include "strings.asm"
4848
#include "util.asm"
4949

50-
#ifdef DEBUG
51-
#include "debug.asm"
52-
#endif
53-
5450
.echo "Assigned kernel memory:"
5551
.echo "threadTable: 0x{0:X4}" threadTable
5652
.echo "libraryTable: 0x{0:X4}" libraryTable

src/00/boot.asm

Lines changed: 7 additions & 103 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,7 @@ _: di
3737

3838
ld sp, kernelGarbage + kernelGarbageSize
3939

40-
#ifndef SKIPON
4140
call suspendDevice
42-
#endif
4341
;; reboot [System]
4442
;; Restarts the device.
4543
reboot:
@@ -63,118 +61,24 @@ reboot:
6361
out (PORT_BANKB), a
6462
#endif
6563

66-
; Manipulate protection states
67-
#ifdef CPU15 ; TI-83+ SE, TI-84+, TI-84+ SE, TI-84+ CSE
6864
call unlockFlash
69-
; Remove RAM Execution Protection
70-
xor a
71-
out (PORT_RAMEXEC_LOWLIMIT), a ; RAM Lower Limit ; out (25), 0
72-
dec a
73-
out (PORT_RAMEXEC_UPLIMIT), a ; RAM Upper Limit ; out (26), $FF
74-
75-
; Remove Flash Execution Protection
76-
out (PORT_FLASHEXEC_LOWLIMIT), a ; Flash Lower Limit ; out (22), $FF
77-
out (PORT_FLASHEXEC_UPLIMIT), a ; Flash Upper Limit ; out (23), $FF
65+
call unprotectRAM
66+
call unprotectFlash
7867
call lockFlash
7968

80-
; Set CPU speed to 15 MHz
69+
#ifdef CPU15
8170
ld a, BIT_CPUSPEED_15MHZ
8271
out (PORT_CPUSPEED), a
83-
84-
#else ; TI-73, TI-83+
85-
#ifndef TI73 ; RAM does not have protection on the TI-73
86-
87-
; Remove RAM/Flash protection
88-
call unlockFlash
89-
xor a
90-
out (PORT_RAM_PAGING), a
91-
out (PORT_FLASHEXCLUSION), a
92-
93-
ld a, 0b000000001
94-
out (PORT_RAM_PAGING), a
95-
xor a
96-
out (PORT_FLASHEXCLUSION), a
97-
98-
ld a, 0b000000010
99-
out (PORT_RAM_PAGING), a
100-
xor a
101-
out (PORT_FLASHEXCLUSION), a
102-
103-
ld a, 0b000000111
104-
out (PORT_RAM_PAGING), a
105-
xor a
106-
out (PORT_FLASHEXCLUSION), a
107-
call lockFlash
108-
#endif
10972
#endif
11073

111-
; Set interrupt mode
11274
ld a, INT_ON | INT_TIMER1 | INT_LINK
11375
out (PORT_INT_MASK), a
114-
; Set timer frequency (TODO)
115-
116-
; Clear RAM
117-
ld hl, 0x8000
118-
ld (hl), 0
119-
ld de, 0x8001
120-
ld bc, 0x7FFF
121-
ldir
12276

12377
call formatMem
124-
125-
; Set all file handles to unused
126-
ld hl, fileHandleTable
127-
ld (hl), 0xFF
128-
ld de, fileHandleTable + 1
129-
ld bc, 8 * maxFileStreams
130-
ldir
131-
132-
ld a, threadRangeMask ; When the first thread is allocated, this will wrap to 0
133-
ld (lastThreadId), a
134-
135-
#ifdef COLOR
136-
; Set GPIO config
137-
ld a, 0xE0
138-
out (PORT_GPIO_CONFIG), a
139-
ld a, 1
140-
ld (color_mode), a
141-
#else
142-
; Initialize LCD
143-
ld a, 1 + LCD_CMD_AUTOINCDEC_SETX
144-
call lcdDelay
145-
out (PORT_LCD_CMD), a ; X-Increment Mode
146-
147-
ld a, 1 + LCD_CMD_SETOUTPUTMODE
148-
call lcdDelay
149-
out (PORT_LCD_CMD), a ; 8-bit mode
150-
151-
ld a, 1 + LCD_CMD_SETDISPLAY
152-
call lcdDelay
153-
out (PORT_LCD_CMD), a ; Enable screen
154-
155-
ld a, 7 + LCD_CMD_POWERSUPPLY_SETLEVEL ; versus +3? TIOS uses +7, and that's the only value that works (the datasheet says go with +3)
156-
call lcdDelay
157-
out (PORT_LCD_CMD), a ; Op-amp control (OPA1) set to max (with DB1 set for some reason)
158-
159-
ld a, 3 + LCD_CMD_POWERSUPPLY_SETENHANCEMENT ; B
160-
call lcdDelay
161-
out (PORT_LCD_CMD), a ; Op-amp control (OPA2) set to max
162-
163-
; Different amounts of contrast look better on different models
164-
#ifdef USB
165-
ld a, 0x2F + LCD_CMD_SETCONTRAST
166-
#else
167-
#ifdef TI73
168-
ld a, 0x3B + LCD_CMD_SETCONTRAST
169-
#else
170-
ld a, 0x34 + LCD_CMD_SETCONTRAST
171-
#endif
172-
#endif
173-
174-
ld (currentContrast), a
175-
call lcdDelay
176-
out (PORT_LCD_CMD), a ; Contrast
177-
#endif
78+
call initRandom
79+
call initFilesystem
80+
call initMultitasking
81+
call initDisplay
17882

17983
ld de, init
18084
call fileExists

src/00/debug.asm

Lines changed: 0 additions & 210 deletions
This file was deleted.

0 commit comments

Comments
 (0)