Skip to content

Commit

Permalink
fix fseek bug
Browse files Browse the repository at this point in the history
  • Loading branch information
jedeoric committed Nov 23, 2023
1 parent d3803fe commit 91f123c
Show file tree
Hide file tree
Showing 26 changed files with 337 additions and 212 deletions.
43 changes: 5 additions & 38 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,11 @@ init:
@mkdir -p build/usr/src/kernel/

kernel: $(SOURCE)

@echo Rom are built in $(PATH_PACKAGE_ROM)
@date +'.define __DATE__ "%F %R"' > src/build.inc
@echo Build kernelsd.rom for Telestrat

@$(AS) --verbose -s -tnone --debug-info -o kernel-telestrat.ld65 -DWITH_SDCARD_FOR_ROOT=1 $(SOURCE) $(ASFLAGS) > output.log
@$(LD) -tnone kernel-telestrat.ld65 -m kernel.map -o kernel-telestrat.ld65.rom -DWITH_ACIA=2 -DWITH_SDCARD_FOR_ROOT=1 -Ln kernel-telestrat.ca.sym > output.log
@echo Build kernelsd.rom for Twilighte board

@$(AS) --verbose -s -tnone --debug-info -o kernelsd.ld65 -DWITH_SDCARD_FOR_ROOT=1 $(SOURCE) $(ASFLAGS) > output.log
@$(LD) -tnone kernelsd.ld65 -m kernelsd.map -o kernelsd.rom -DWITH_SDCARD_FOR_ROOT=1 -DWITH_TWILIGHTE_BOARD=1 -Ln kernelsd.sym > output.log
@$(LD) -C src/kernel.cfg kernelsd.ld65 -m kernelsd.map -DWITH_SDCARD_FOR_ROOT=1 -DWITH_TWILIGHTE_BOARD=1 -Ln kernelsd.sym > output.log
@cp kernel.rom kernelsd.rom
@sed -re 's/al 00(.{4}) \.(.+)$$/\1 \2/' kernelsd.sym| sort > kernelsd2.sym > output.log
@cp kernelsd.rom $(PATH_PACKAGE_ROM)/
@cp kernelsd.sym $(PATH_PACKAGE_ROM)/
Expand All @@ -54,43 +48,16 @@ kernel: $(SOURCE)
@echo Build kernelus.rom for Twilighte board
@echo "WITH_TWILIGHTE_BOARD">$(PATH_PACKAGE_ROM)/kernelus.lst
@$(AS) --verbose -s -tnone --debug-info -o kernelus.ld65 $(SOURCE) $(ASFLAGS) > output.log
@$(LD) -tnone kernelus.ld65 -m kernelus.map -o kernelus.rom -DWITH_TWILIGHTE_BOARD=1 -Ln kernelus.sym > output.log

@echo Build kernelud.rom for Twilighte board
@$(AS) --verbose -s -tnone --debug-info -o kernelud.ld65 -DWITH_DEBUG_BOARD=1 $(SOURCE) $(ASFLAGS) > output.log
@$(LD) -tnone kernelud.ld65 -m kernelud.map -o kernelud.rom -DWITH_DEBUG_BOARD=1 -DWITH_TWILIGHTE_BOARD=1 -Ln kernelud.sym > output.log


@sed -re 's/al 00(.{4}) \.(.+)$$/\1 \2/' kernelus.sym| sort > kernelus2.sym
@cp kernelus.rom $(PATH_PACKAGE_ROM)/
@cp kernelus.sym $(PATH_PACKAGE_ROM)/
@cp kernelus.map $(PATH_PACKAGE_ROM)/

@echo Build kernelu0.rom for Twilighte board -ACIA
@echo "WITH_TWILIGHTE_BOARD">$(PATH_PACKAGE_ROM)/kernelu0.lst
@echo "WITH_ACIA=">>$(PATH_PACKAGE_ROM)/kernelu0.lst
@$(AS) --verbose -s -tnone --debug-info -o kernelu0.ld65 -DWITH_ACIA=1 $(SOURCE) $(ASFLAGS) > output.log
@$(LD) -tnone kernelu0.ld65 -m kernelu0.map -o kernelu0.rom -DWITH_TWILIGHTE_BOARD=1 -DWITH_ACIA=1 -Ln kernelu0.sym > output.log
@sed -re 's/al 00(.{4}) \.(.+)$$/\1 \2/' kernelu0.sym| sort > kernelu02.sym
@cp kernelu0.rom $(PATH_PACKAGE_ROM)/
@cp kernelu0.sym $(PATH_PACKAGE_ROM)/
@cp kernelu0.map $(PATH_PACKAGE_ROM)/

@echo Build kernlus.c02 : Kernel for 65C02
@$(AS) --cpu 65C02 --verbose -s -tnone --debug-info -o kernelusc02.ld65 $(SOURCE) $(ASFLAGS) > output.log
@$(LD) -tnone kernelusc02.ld65 -m kernelus.map -o kernelus.c02 -DWITH_TWILIGHTE_BOARD=1 -Ln kernelus.sym > output.log

@echo Build kernlus.c02 : Kernel for 65C816
@$(AS) --cpu 65816 --verbose -s -tnone --debug-info -o kernelus816.ld65 $(SOURCE) $(ASFLAGS) > output.log
@$(LD) -tnone kernelus816.ld65 -m kernelus.map -o kernelus.816 -DWITH_TWILIGHTE_BOARD=1 -Ln kernelus.sym > output.log
@$(LD) -C src/kernel.cfg kernelus.ld65 -m kernelus.map -DWITH_TWILIGHTE_BOARD=1 -Ln kernelus.sym > output.log
@cp kernel.rom kernelus.rom

unittest:
$(CC) $(CFLAGS) tests/mkdir.c -o tmkdir
$(CC) $(CFLAGS) tests/fwrite.c -o tfwrite

memmap:
@$(AS) --verbose -s -tnone --debug-info -o kernel-telestrat.ld65 -DWITH_SDCARD_FOR_ROOT=1 $(SOURCE) $(ASFLAGS) > memmap.md
@$(LD) -tnone kernel-telestrat.ld65 -m kernel.map -o kernel-telestrat.ld65.rom -DWITH_ACIA=2 -DWITH_SDCARD_FOR_ROOT=1 -Ln kernel-telestrat.ca.sym
@$(LD) -C src/kernel.cfg kernel-telestrat.ld65 -m kernel.map -o kernel-telestrat.ld65.rom -DWITH_ACIA=2 -DWITH_SDCARD_FOR_ROOT=1 -Ln kernel-telestrat.ca.sym
sh generate_memmap.sh

test:
Expand Down
1 change: 1 addition & 0 deletions docs/TR1.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# TR1
|MODIFY:KERNEL_XOPEN_PTR1:XFSEEK_ROUTINE
* _XEXEC
* _XFORK
* XMAINARGS_ROUTINE
Expand Down
1 change: 1 addition & 0 deletions docs/TR5.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
* kernel_create_process
* kernel_kill_process via XFREE_ROUTINE
* _XFORK via kernel_create_process
* XOPEN_ROUTINE
1 change: 1 addition & 0 deletions docs/TR6.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# TR6
* XFSEEK_ROUTINE
6 changes: 3 additions & 3 deletions docs/memmap_ram.md
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@
## Kernel bank 7
| Type | Name | Range | Size |
| :-------- |:---------------------------- |:------- |:-----|
|ROM|<span style="color:green">FREE</span> |$feea-$fff0| 262 |
|ROM|<span style="color:green">FREE</span> |$ff11-$fff0| 223 |
##Bank 0
| Type | Name | Range | Size |
| -------- | ---------------------------- | ------- |-----|
|BANK0|BUFBUF | $c080-$c0b6 | 54 |
|BANK0|BUFROU | $c500-$c54e | |
|BANK0|TELEMON_KEYBOARD_BUFFER_BEGIN | $c5c4-$c680 | |
|BANK0|XMALLOC (copy from kernel) | $fb9c-$fc48 | |
|BANK0|X<span style="color:green">FREE</span> (copy from kernel) | $fc48-$fecd | |
|BANK0|XMALLOC (copy from kernel) | $fbc3-$fc6f | |
|BANK0|X<span style="color:green">FREE</span> (copy from kernel) | $fc6f-$fef4 | |
10 changes: 6 additions & 4 deletions memmap.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ int KERNEL_MALLOC_FREE_CHUNK_MAX=0x5;
|MODIFY:RES:XWRITEBYTES_ROUTINE
|MODIFY:RESB:XWRITEBYTES_ROUTINE
|MODIFY:TR0:XFSEEK_ROUTINE
|MODIFY:TR7:XFSEEK_ROUTINE
|MODIFY:TR6:XFSEEK_ROUTINE
|MODIFY:TR7:XFSEEK_ROUTINE
|MODIFY:TR4:XFSEEK_ROUTINE
|MODIFY:RESB:XFSEEK_ROUTINE
|MODIFY:RES:XFSEEK_ROUTINE
|MODIFY:KERNEL_XOPEN_PTR1:XFSEEK_ROUTINE
|MODIFY:RES:XMKDIR_ROUTINE
|MODIFY:ptr1:XMKDIR_ROUTINE
|MODIFY:TR7:XMKDIR_ROUTINE
Expand Down Expand Up @@ -130,6 +131,7 @@ CALL:XOPEN:XRM_ROUTINE
|MODIFY:PTR_READ_DEST:kernel_try_to_find_command_in_bin_path
|MODIFY:RES:XOPEN_ROUTINE
|MODIFY:RESB:XOPEN_ROUTINE
|MODIFY:TR5:XOPEN_ROUTINE
|MODIFY:TR7:XOPEN_ROUTINE
|MODIFY:XOPEN_SAVE:XOPEN_ROUTINE
|MODIFY:XOPEN_FLAGS:XOPEN_ROUTINE
Expand Down Expand Up @@ -289,12 +291,12 @@ CALL:XOPEN:XRM_ROUTINE
|##MEMMAP: Kernel bank 7
|MEMMAP: Type | Name | Range | Size |
|MEMMAP: :-------- |:---------------------------- |:------- |:-----|
|MEMMAP:ROM|FREE |$fee8-$fff0| 264 |
|MEMMAP:ROM|FREE |$ff11-$fff0| 223 |
|##MEMMAP:Bank 0
|MEMMAP: Type | Name | Range | Size |
|MEMMAP: -------- | ---------------------------- | ------- |-----|
|MEMMAP:BANK0|BUFBUF | $c080-$c0b6 | 54 |
|MEMMAP:BANK0|BUFROU | $c500-$c54e | |
|MEMMAP:BANK0|TELEMON_KEYBOARD_BUFFER_BEGIN | $c5c4-$c680 | |
|MEMMAP:BANK0|XMALLOC (copy from kernel) | $fb9a-$fc46 | |
|MEMMAP:BANK0|XFREE (copy from kernel) | $fc46-$fecb | |
|MEMMAP:BANK0|XMALLOC (copy from kernel) | $fbc3-$fc6f | |
|MEMMAP:BANK0|XFREE (copy from kernel) | $fc6f-$fef4 | |
2 changes: 1 addition & 1 deletion run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ echo Error
exit
fi

ld65 -tnone -DWITH_SDCARD_FOR_ROOT=1 tmp/kernelsd.ld65 -o kernel.rom -Ln tmp/kernelsd.sym -m tmp/memmap.txt -vm
ld65 -C src/kernel.cfg -DWITH_SDCARD_FOR_ROOT=1 tmp/kernelsd.ld65 -Ln tmp/kernelsd.sym -m tmp/memmap.txt -vm
#cl65 -ttelestrat -C tests/orix-sdk/cfg/telestrat_900.cfg tests/multiples_files_opened.c tests/multiples_files_fopen.s tests/exec.s -o multi
#cl65 -ttelestrat -C tests/orix-sdk/cfg/telestrat_900.cfg tests/readdir.c tests/kernel_calls/readdir_extern.s -o b

Expand Down
109 changes: 59 additions & 50 deletions src/functions/files/XOPEN.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

.out .sprintf("|MODIFY:RES:XOPEN_ROUTINE")
.out .sprintf("|MODIFY:RESB:XOPEN_ROUTINE")
.out .sprintf("|MODIFY:TR5:XOPEN_ROUTINE")
.out .sprintf("|MODIFY:TR7:XOPEN_ROUTINE")
.out .sprintf("|MODIFY:XOPEN_SAVE:XOPEN_ROUTINE")
.out .sprintf("|MODIFY:XOPEN_FLAGS:XOPEN_ROUTINE")
Expand Down Expand Up @@ -151,7 +152,6 @@
iny

@don_t_add_slash:

sty RES

lda #$00
Expand Down Expand Up @@ -205,83 +205,83 @@
sty KERNEL_XOPEN_PTR1+1

@open_from_device:
ldy #_KERNEL_FILE::f_path ; skip /


; Reset flag to say that end of string is reached
lda #$01
sta XOPEN_SAVEA

@next_filename:
ldy #_KERNEL_FILE::f_path ; skip /

@next_filename:
lda #CH376_SET_FILE_NAME ;$2F
sta CH376_COMMAND

@next_char:
; $eb55
lda (KERNEL_XOPEN_PTR1),y
beq @slash_found_or_end_of_string_stop
cmp #"/"
beq @slash_found_or_end_of_string
cmp #"a" ; 'a'
bcc @do_not_uppercase
cmp #"z"+1 ; 'z'
bcs @do_not_uppercase
sbc #$1F
@do_not_uppercase:

; sta $bb80,y
jsr ch376_open_filename

cmp #$00
beq @slash_found_or_end_of_string_stop
bne @slash_found_or_end_of_string

sta CH376_DATA
iny
cpy #_KERNEL_FILE::f_path+KERNEL_MAX_PATH_LENGTH ; Max
bne @next_char
; error buffer overflow
; lda (KERNEL_XOPEN_PTR1),y
; beq @slash_found_or_end_of_string_stop
; cmp #"/"
; beq @slash_found_or_end_of_string
; cmp #"a" ; 'a'
; bcc @do_not_uppercase
; cmp #"z"+1 ; 'z'
; bcs @do_not_uppercase
; sbc #$1F

beq @exit_open_with_null
; @do_not_uppercase:
; sta CH376_DATA
; iny
; cpy #_KERNEL_FILE::f_path+KERNEL_MAX_PATH_LENGTH ; Max
; bne @next_char

; error buffer overflow
;beq @exit_open_with_null

@slash_found_or_end_of_string_stop:
sta XOPEN_SAVEA
cpy #_KERNEL_FILE::f_path+1 ; Do we reach $00 ? at the second char ? It means that it's '/' only
beq @open_and_register_fp
bne @S3
sta XOPEN_SAVEA
cpy #_KERNEL_FILE::f_path+1 ; Do we reach $00 ? at the second char ? It means that it's '/' only
beq @open_and_register_fp
bne @S3

@slash_found_or_end_of_string:
; do we reach / at the first char ? It should, then we enter
sta XOPEN_SAVEA
cpy #_KERNEL_FILE::f_path
bne @S3
sta CH376_DATA
sta XOPEN_SAVEA
cpy #_KERNEL_FILE::f_path
bne @S3
sta CH376_DATA

@S3:

.IFPC02
.pc02
stz CH376_DATA ; INIT
stz CH376_DATA ; INIT
.p02
.else
lda #$00 ; used to write in BUFNOM
sta CH376_DATA ; INIT
lda #$00 ; used to write in BUFNOM
sta CH376_DATA ; INIT
.endif

sty XOPEN_SAVEY
jsr _ch376_file_open
cmp #CH376_ERR_MISS_FILE
beq @file_not_found
sty XOPEN_SAVEY
jsr _ch376_file_open
cmp #CH376_ERR_MISS_FILE
beq @file_not_found

ldy XOPEN_SAVEY ; reload Y
lda XOPEN_SAVEA
beq @could_be_created
ldy XOPEN_SAVEY ; reload Y
lda XOPEN_SAVEA
beq @could_be_created
iny
lda (KERNEL_XOPEN_PTR1),y
bne @next_filename
cpy #_KERNEL_FILE::f_path+1
beq @open_and_register_fp


lda (KERNEL_XOPEN_PTR1),y
bne @next_filename
cpy #_KERNEL_FILE::f_path+1
beq @open_and_register_fp

bne @next_filename
bne @next_filename


@file_not_found:
Expand All @@ -296,7 +296,7 @@
cmp #O_CREAT
beq @could_be_created ; Yes, create

; When we have file not found, do we have O_WRONLY flag ?
; When we have 'file not found', do we have O_WRONLY flag ?
lda XOPEN_FLAGS ; Get flags
and #O_WRONLY
cmp #O_WRONLY
Expand All @@ -307,6 +307,16 @@
cmp #O_RDONLY
bne @could_be_created

; Le fichier n'a pas été trouvé,
; On va vérifier qu'on avait un fichier ouvert avant
lda kernel_process+kernel_process_struct::kernel_fd_opened ; if there is already a file open on ch376 if value <> $FF, if it's equal to $ff, there is no file opened
cmp #$FF
beq @exit_open_with_null

clc
adc #KERNEL_FIRST_FD
jsr open_full_filename

@exit_open_with_null:
lda KERNEL_XOPEN_PTR1
ldy KERNEL_XOPEN_PTR1+1
Expand Down Expand Up @@ -360,6 +370,7 @@
; Manage only 1 FP for instance FIXME bug
ldx #$00
ldy #(kernel_one_process_struct::fp_ptr+1)

@try_to_find_a_free_fp_for_current_process:
lda (RES),y ; Load high
beq @fp_is_not_busy ; If it's equal to $00, it means that it's empty because it's impossible to have a fp registered in zp
Expand Down Expand Up @@ -436,8 +447,6 @@
adc #KERNEL_FIRST_FD

; Store the id of the fp opened in ch376


.ifdef WITH_DEBUG2
pha
ldx #XDEBUG_FD
Expand Down
2 changes: 1 addition & 1 deletion src/functions/files/_ch376_seek_file32.asm
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
.proc _ch376_seek_file32
; A Y X RES : 32 bits
; A Y X RESB : 32 bits
pha
lda #CH376_BYTE_LOCATE
sta CH376_COMMAND
Expand Down
19 changes: 19 additions & 0 deletions src/functions/files/ch376_open_filename.asm
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
.proc ch376_open_filename

; Returns A=0 end of string
; else A<>0 : there is others strings

@loop_next_byte:
lda (KERNEL_XOPEN_PTR1),y
beq @send_end_out
cmp #'/'
beq @send
jsr XMINMA_ROUTINE
sta CH376_DATA
iny
bne @loop_next_byte

@send_end_out:
@send:
rts
.endproc
Loading

0 comments on commit 91f123c

Please sign in to comment.