Skip to content

Commit

Permalink
lib/streamio: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
ry755 committed Jan 9, 2025
1 parent 4007c35 commit 0a7cf8c
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 3 deletions.
14 changes: 11 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ IMAGE_SIZE := 16777216
ROM_IMAGE_SIZE := 196608
BOOTLOADER := bootloader/bootloader.bin

all: fox32os.img romdisk.img
all: base_image/streamio.lbr fox32os.img romdisk.img

base_image:
mkdir -p base_image
Expand Down Expand Up @@ -130,15 +130,23 @@ ROM_FILES = \
base_image/loadfont.fxf \
base_image/tasks.fxf

fox32os.img: $(BOOTLOADER) $(FILES)
base_image/%.lbr: $(wildcard libraries/*/*.asm)
cd libraries && $(MAKE)

fox32os.img: $(BOOTLOADER) $(FILES) $(wildcard libraries/*/*.asm)
$(RYFS) -s $(IMAGE_SIZE) -l fox32os -b $(BOOTLOADER) create $@.tmp
for file in base_image/*.lbr; do $(RYFS) add $@.tmp $$file; done
for file in $(FILES); do $(RYFS) add $@.tmp $$file; done
mv $@.tmp $@

romdisk.img: $(BOOTLOADER) $(ROM_FILES)
romdisk.img: $(BOOTLOADER) $(ROM_FILES) $(wildcard libraries/*/*.asm)
$(RYFS) -s $(ROM_IMAGE_SIZE) -l romdisk -b $(BOOTLOADER) create $@.tmp
for file in base_image/*.lbr; do $(RYFS) add $@.tmp $$file; done
for file in $(ROM_FILES); do $(RYFS) add $@.tmp $$file; done
mv $@.tmp $@

clean:
cd libraries && $(MAKE) clean
rm -f $(FILES)

.PHONY: clean
12 changes: 12 additions & 0 deletions libraries/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FOX32ASM := ../../fox32asm/target/release/fox32asm

FILES = \
../base_image/streamio.lbr

all: $(FILES)

../base_image/%.lbr: %/main.asm
$(FOX32ASM) $< $@

clean:
rm -f $(FILES)
84 changes: 84 additions & 0 deletions libraries/streamio/main.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
opton

jump_table:
data.32 print_character
data.32 print_string
data.32 print_decimal
data.32 0x00000000 ; end jump table

const ROM_string_length: 0xF0046018
const OS_write: 0x00000D20

; print a single character to the given stream
; inputs:
; r0: character byte
; r1: stream pointer
; outputs:
; none
print_character:
push r2

push r0
mov r2, rsp
mov r0, 1
call [OS_write]
pop r0

pop r2
ret

; print a null-terminated string to the given stream
; inputs:
; r0: pointer to null-terminated string
; r1: stream pointer
; outputs:
; none
print_string:
push r0
push r2

mov r2, r0
call [ROM_string_length]
call [OS_write]

pop r2
pop r0
ret

; print a decimal integer to the given stream
; inputs:
; r0: integer
; r1: stream pointer
; outputs:
; none
print_decimal:
push r0
push r10
push r11
push r12
push r13
mov r10, rsp
mov r12, r0

push.8 0
print_decimal_loop:
push r12
div r12, 10
pop r13
rem r13, 10
mov r11, r13
add r11, '0'
push.8 r11
cmp r12, 0
ifnz jmp print_decimal_loop

mov r0, rsp
call print_string

mov rsp, r10
pop r13
pop r12
pop r11
pop r10
pop r0
ret

0 comments on commit 0a7cf8c

Please sign in to comment.