From 91f123c2f3fa8c8b16a2f28c84d41b848d66c84a Mon Sep 17 00:00:00 2001 From: jede Date: Thu, 23 Nov 2023 20:53:20 +0100 Subject: [PATCH] fix fseek bug --- Makefile | 43 +------ docs/TR1.md | 1 + docs/TR5.md | 1 + docs/TR6.md | 1 + docs/memmap_ram.md | 6 +- memmap.md | 10 +- run.sh | 2 +- src/functions/files/XOPEN.asm | 109 ++++++++++-------- src/functions/files/_ch376_seek_file32.asm | 2 +- src/functions/files/ch376_open_filename.asm | 19 +++ src/functions/files/checking_fp_exists.asm | 85 +++++--------- src/functions/files/open_full_filename.asm | 27 +++++ .../files/restore_position_into_file.asm | 23 ++++ .../files/send_0_to_ch376_and_open.asm | 14 +++ src/functions/files/xfseek.asm | 19 ++- src/functions/graphics/_xdrawr.asm | 6 + src/functions/graphics/xabox.asm | 47 ++++---- src/functions/graphics/xcircl.asm | 1 + src/functions/graphics/xcurse.asm | 1 + src/functions/graphics/xdrawa.asm | 1 + src/functions/graphics/xdrawr.asm | 4 +- src/functions/xvars/xvars.asm | 57 +++++---- src/include/process.inc | 2 +- src/kernel.asm | 19 ++- src/kernel.cfg | 44 +++++++ tests/Makefile | 5 +- 26 files changed, 337 insertions(+), 212 deletions(-) create mode 100644 src/functions/files/ch376_open_filename.asm create mode 100644 src/functions/files/open_full_filename.asm create mode 100644 src/functions/files/restore_position_into_file.asm create mode 100644 src/functions/files/send_0_to_ch376_and_open.asm create mode 100644 src/kernel.cfg diff --git a/Makefile b/Makefile index 088c9af..8b15f9a 100644 --- a/Makefile +++ b/Makefile @@ -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)/ @@ -54,35 +48,8 @@ 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 @@ -90,7 +57,7 @@ unittest: 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: diff --git a/docs/TR1.md b/docs/TR1.md index d05eaa0..025eecf 100644 --- a/docs/TR1.md +++ b/docs/TR1.md @@ -1,4 +1,5 @@ # TR1 +|MODIFY:KERNEL_XOPEN_PTR1:XFSEEK_ROUTINE * _XEXEC * _XFORK * XMAINARGS_ROUTINE diff --git a/docs/TR5.md b/docs/TR5.md index 9f49fcc..e067a95 100644 --- a/docs/TR5.md +++ b/docs/TR5.md @@ -3,3 +3,4 @@ * kernel_create_process * kernel_kill_process via XFREE_ROUTINE * _XFORK via kernel_create_process +* XOPEN_ROUTINE diff --git a/docs/TR6.md b/docs/TR6.md index ec98026..8aa68ec 100644 --- a/docs/TR6.md +++ b/docs/TR6.md @@ -1 +1,2 @@ # TR6 +* XFSEEK_ROUTINE diff --git a/docs/memmap_ram.md b/docs/memmap_ram.md index 373ad8d..4bcb67d 100644 --- a/docs/memmap_ram.md +++ b/docs/memmap_ram.md @@ -146,12 +146,12 @@ ## Kernel bank 7 | Type | Name | Range | Size | | :-------- |:---------------------------- |:------- |:-----| -|ROM|FREE |$feea-$fff0| 262 | +|ROM|FREE |$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|XFREE (copy from kernel) | $fc48-$fecd | | +|BANK0|XMALLOC (copy from kernel) | $fbc3-$fc6f | | +|BANK0|XFREE (copy from kernel) | $fc6f-$fef4 | | diff --git a/memmap.md b/memmap.md index 8331381..0696b9a 100644 --- a/memmap.md +++ b/memmap.md @@ -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 @@ -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 @@ -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 | | diff --git a/run.sh b/run.sh index babd272..2e20996 100644 --- a/run.sh +++ b/run.sh @@ -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 diff --git a/src/functions/files/XOPEN.asm b/src/functions/files/XOPEN.asm index 637598b..306df0c 100644 --- a/src/functions/files/XOPEN.asm +++ b/src/functions/files/XOPEN.asm @@ -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") @@ -151,7 +152,6 @@ iny @don_t_add_slash: - sty RES lda #$00 @@ -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: @@ -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 @@ -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 @@ -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 @@ -436,8 +447,6 @@ adc #KERNEL_FIRST_FD ; Store the id of the fp opened in ch376 - - .ifdef WITH_DEBUG2 pha ldx #XDEBUG_FD diff --git a/src/functions/files/_ch376_seek_file32.asm b/src/functions/files/_ch376_seek_file32.asm index c62583e..82f6810 100644 --- a/src/functions/files/_ch376_seek_file32.asm +++ b/src/functions/files/_ch376_seek_file32.asm @@ -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 diff --git a/src/functions/files/ch376_open_filename.asm b/src/functions/files/ch376_open_filename.asm new file mode 100644 index 0000000..a2615b2 --- /dev/null +++ b/src/functions/files/ch376_open_filename.asm @@ -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 diff --git a/src/functions/files/checking_fp_exists.asm b/src/functions/files/checking_fp_exists.asm index 1c0d76b..aa9b5f6 100644 --- a/src/functions/files/checking_fp_exists.asm +++ b/src/functions/files/checking_fp_exists.asm @@ -2,6 +2,8 @@ ; X fp to find ; Save A & X + + .out .sprintf("|MODIFY:RES:checking_fp_exists") .out .sprintf("|MODIFY:RESB:checking_fp_exists") .out .sprintf("|MODIFY:TR5:checking_fp_exists") @@ -16,7 +18,7 @@ cmp #KERNEL_MAX_FP ; Does X is greater than the fp ? bcs @doesnot_exists ; Yes error - ; When orix boots, kernel_fd_opened is equal to $FF, if the fd passed into arg is the same than kernel_fd_opened it means that we don't need to close and store + ; When orix boots, kernel_fd_opened is equal to $FF, if the fd passed into arg is the same than kernel_fd_opened it means that we don't need to close and store cmp kernel_process+kernel_process_struct::kernel_fd_opened beq @do_not_seek @@ -47,31 +49,43 @@ jsr compute_fp_struct - lda #CH376_SET_FILE_NAME ;$2F sta CH376_COMMAND lda #'/' sta CH376_DATA - jsr @send_0_to_ch376_and_open + jsr send_0_to_ch376_and_open + + ldy #_KERNEL_FILE::f_path+1 ; Skip first '/' +@set_filename: lda #CH376_SET_FILE_NAME ;$2F sta CH376_COMMAND - ldy #_KERNEL_FILE::f_path+1 ; Skip first '/' @loop_next_byte: - ;jmp @loop_next_byte - lda (KERNEL_XOPEN_PTR1),y - + jsr ch376_open_filename + cmp #$00 beq @send_end_out - cmp #'/' - beq @send - jsr XMINMA_ROUTINE - sta CH376_DATA + iny - bne @loop_next_byte - ; Here we should not reach this part except if there is an overflow + sty TR5 + + jsr send_0_to_ch376_and_open + + ldy TR5 + jmp @set_filename + +; lda (KERNEL_XOPEN_PTR1),y + +; beq @send_end_out +; cmp #'/' +; beq @send +; jsr XMINMA_ROUTINE +; sta CH376_DATA +; iny +; bne @loop_next_byte +; ; Here we should not reach this part except if there is an overflow @doesnot_exists: @@ -84,38 +98,11 @@ clc rts -@send: - iny - sty TR5 - - jsr @send_0_to_ch376_and_open - lda #CH376_SET_FILE_NAME ;$2F - sta CH376_COMMAND - - ldy TR5 - jmp @loop_next_byte @send_end_out: - jsr @send_0_to_ch376_and_open - - ldy #_KERNEL_FILE::f_seek_file - - lda (KERNEL_XOPEN_PTR1),y - sta RES - iny - lda (KERNEL_XOPEN_PTR1),y - sta RES+1 - iny - lda (KERNEL_XOPEN_PTR1),y - tax - iny - lda (KERNEL_XOPEN_PTR1),y - sta RESB + jsr send_0_to_ch376_and_open - lda RES - ldy RES+1 - - jsr _ch376_seek_file32 + jsr restore_position_into_file lda KERNEL_XFSEEK_SAVE_RESB sta RES @@ -125,20 +112,6 @@ jmp @do_not_seek -@send_0_to_ch376_and_open: - -.IFPC02 -.pc02 - stz CH376_DATA -.p02 -.else - lda #$00 - sta CH376_DATA -.endif - - jsr _ch376_file_open ; Open slash - rts - restore: ldy KERNEL_XWRITE_XCLOSE_XFSEEK_XFREAD_SAVE_Y ldx KERNEL_XWRITE_XCLOSE_XFSEEK_XFREAD_SAVE_X diff --git a/src/functions/files/open_full_filename.asm b/src/functions/files/open_full_filename.asm new file mode 100644 index 0000000..c3549c9 --- /dev/null +++ b/src/functions/files/open_full_filename.asm @@ -0,0 +1,27 @@ +.proc open_full_filename + jsr compute_fp_struct + +@set_filename: + lda #CH376_SET_FILE_NAME ;$2F + sta CH376_COMMAND + + jsr ch376_open_filename + cmp #$00 + beq @send_end_out + +; send + + iny + sty TR5 + + jsr send_0_to_ch376_and_open + + ldy TR5 + jmp @set_filename + +@send_end_out: + jsr send_0_to_ch376_and_open + jsr restore_position_into_file + + rts +.endproc diff --git a/src/functions/files/restore_position_into_file.asm b/src/functions/files/restore_position_into_file.asm new file mode 100644 index 0000000..66e874b --- /dev/null +++ b/src/functions/files/restore_position_into_file.asm @@ -0,0 +1,23 @@ +.proc restore_position_into_file + + ldy #_KERNEL_FILE::f_seek_file + + lda (KERNEL_XOPEN_PTR1),y + sta RES + iny + lda (KERNEL_XOPEN_PTR1),y + sta RES+1 + iny + lda (KERNEL_XOPEN_PTR1),y + tax + iny + lda (KERNEL_XOPEN_PTR1),y + sta RESB + + lda RES + ldy RES+1 + + jmp _ch376_seek_file32 + +.endproc + diff --git a/src/functions/files/send_0_to_ch376_and_open.asm b/src/functions/files/send_0_to_ch376_and_open.asm new file mode 100644 index 0000000..30cddd3 --- /dev/null +++ b/src/functions/files/send_0_to_ch376_and_open.asm @@ -0,0 +1,14 @@ +.proc send_0_to_ch376_and_open + +.IFPC02 +.pc02 + stz CH376_DATA +.p02 +.else + lda #$00 + sta CH376_DATA +.endif + + jmp _ch376_file_open ; Open slash + +.endproc diff --git a/src/functions/files/xfseek.asm b/src/functions/files/xfseek.asm index 1f6128f..62d3be7 100644 --- a/src/functions/files/xfseek.asm +++ b/src/functions/files/xfseek.asm @@ -4,18 +4,17 @@ ; [IN] RESB position 0 to 31 ; [IN] RES fd .out .sprintf("|MODIFY:TR0:XFSEEK_ROUTINE") - .out .sprintf("|MODIFY:TR7:XFSEEK_ROUTINE") + .out .sprintf("|MODIFY:TR6:XFSEEK_ROUTINE") .out .sprintf("|MODIFY:TR7:XFSEEK_ROUTINE") .out .sprintf("|MODIFY:TR4:XFSEEK_ROUTINE") .out .sprintf("|MODIFY:RESB:XFSEEK_ROUTINE") .out .sprintf("|MODIFY:RES:XFSEEK_ROUTINE") + .out .sprintf("|MODIFY:KERNEL_XOPEN_PTR1:XFSEEK_ROUTINE") ; From checking_fp_exists ;EBADF : le descripteur de flux (FILE *) passé en paramètre est invalide. ;EINVAL : le référentiel proposé (paramètre whence) n'est pas valide. - - - sta TR0 + sta TR0 ; 09 lda RES sta KERNEL_XFSEEK_SAVE_RES lda RES+1 @@ -27,7 +26,7 @@ lda RESB+1 sta RES5+1 - sty TR7 ; save Y + sty TR7 ; save Y $02 stx TR4 ldx KERNEL_XFSEEK_SAVE_RES ; Load FP in order to store @@ -40,7 +39,7 @@ @continue_xfseek: ldx TR4 ; Whence - ldy TR7 ; save Y + ldy TR7 ; get Y lda KERNEL_XFSEEK_SAVE_RES sta RES @@ -52,7 +51,6 @@ lda KERNEL_XFSEEK_SAVE_RESB+1 sta RESB+1 - cpx #SEEK_CUR beq @move cpx #SEEK_END @@ -106,6 +104,7 @@ jsr compute_fp_struct ldy #_KERNEL_FILE::f_seek_file + lda (KERNEL_XOPEN_PTR1),y clc adc TR0 @@ -142,7 +141,7 @@ rts @go_beginning: - sta TR6 + ;sta TR6 ; Seek from the beginning of the file lda #$00 tay @@ -156,8 +155,8 @@ lda RES5+1 sta RESB - ldy TR7 - lda TR6 + ldy TR7 ; Get Y + lda TR0 ldx RES5 diff --git a/src/functions/graphics/_xdrawr.asm b/src/functions/graphics/_xdrawr.asm index 7bd919f..7c2fed1 100644 --- a/src/functions/graphics/_xdrawr.asm +++ b/src/functions/graphics/_xdrawr.asm @@ -32,6 +32,7 @@ eor #$FF ; dX I sta HRS1 ; I inc HRS1 ; à 2 I + @S1: bit HRS2+1 ; dY négatif ? <------------------------------------ bpl @S2 ; non ---------------------------------------------- @@ -39,6 +40,7 @@ eor #$FF ; dY I sta HRS2 ; I inc HRS2 ; à 2 I + @S2: lda HRS1 ; on teste dX et dY <------------------------------- cmp HRS2 @@ -52,13 +54,16 @@ bne LE8C0 ; dX<>dY ----------------------------------- I I lda #$FF ; dX=dY, la tangente est 1 I I I sta RES ; en fait, -1, mais c'est la même chose I I I + LE8C0: bit HRS1+1 ; I bpl @S2 ; I dX>0 ------------------------------------- I I jsr XHRSCG_ROUTINE ; I dX<0, on d?place le curseur à gauche I I I jmp @S3 ; I--- I I I + @S2: jsr XHRSCD_ROUTINE ; II on on déplace le curseur à droite <------- I I + @S3: clc ; I-->a-t-on parcouru une valeur de la tangente I I lda RES ; I I I @@ -69,6 +74,7 @@ LE8C0: bmi @S4 ; I oui ------------------------------- I I I jsr XHRSCB_ROUTINE ; I non, on déplace le curseur I I I I jmp @S5 ;I---vers le bas I I I I + @S4: jsr XHRSCH_ROUTINE ; II on déplace vers le haut <---------- I I I @S5: diff --git a/src/functions/graphics/xabox.asm b/src/functions/graphics/xabox.asm index 898116e..10f755a 100644 --- a/src/functions/graphics/xabox.asm +++ b/src/functions/graphics/xabox.asm @@ -17,37 +17,42 @@ XABOX_ROUTINE: ldy #$06 ; On place les 4 paramètres (poids faible seulement) ldx #$03 -LE830 + +LE830: lda HRS1,y ; de HRSx sta DECFIN,x ; dans $06-7-8-9 dey dey dex bpl LE830 + LE83A: - ldx #$03 ; on va tracer 4 traits + ldx #$03 ; on va tracer 4 traits + LE83C: - stx DECDEB+1 ; dans $05 <---------------------------------------- + stx DECDEB+1 ; dans $05 <---------------------------------------- lda table_for_rect,x ; on lit le code coordonn?es I - sta DECDEB ; dans $04 I - ldx #$06 ; on va extraire 8 bits I + sta DECDEB ; dans $04 I + ldx #$06 ; on va extraire 8 bits I + LE845: - lda #$00 ; A=0 <---------------------------------------- I - sta HRS1+1,c ; poids fort HRSx ? 0 et positif I I - lsr DECDEB ; on sort 2 bits I I - rol ; dans A I I - lsr DECDEB ; I I - rol ; I I - tay ; et Y I I - lda $0006,y ; on lit la coordonnée correspondante I I - sta HRS1,x ; et on stocke dans HRSx I I - dex ; I I - dex ; I I - bpl LE845 ; on fait les 4 coordonnées ADRAW ------------- I - jsr XDRAWA_ROUTINE ; on trace le trait en absolu I - ldx DECDEB+1 ; I - dex ; I - bpl LE83C ; et on fait 4 traits ------------------------------ + lda #$00 ; A=0 <---------------------------------------- I + sta HRS1+1,x ; poids fort HRSx ? 0 et positif I I + lsr DECDEB ; on sort 2 bits I I + rol ; dans A I I + lsr DECDEB ; I I + rol ; I I + tay ; et Y I I + lda $0006,y ; on lit la coordonnée correspondante I I + sta HRS1,x ; et on stocke dans HRSx I I + dex ; I I + dex ; I I + bpl LE845 ; on fait les 4 coordonnées ADRAW ------------- I + jsr XDRAWA_ROUTINE ; on trace le trait en absolu I + ldx DECDEB+1 ; I + dex ; I + bpl LE83C ; et on fait 4 traits ------------------------------ rts + table_for_rect: .byt $26,$67,$73,$32 diff --git a/src/functions/graphics/xcircl.asm b/src/functions/graphics/xcircl.asm index 4bc85d2..c1bbe3b 100644 --- a/src/functions/graphics/xcircl.asm +++ b/src/functions/graphics/xcircl.asm @@ -148,6 +148,7 @@ sta TR6 ; on place la partie fractionnaire dans $12 stx TR7 ; et la partie enti?re dans $13 ldx TR0 ; X=N tel que Rayon<2^N + @L1: lda TR7 ; on garde le signe du résultat rol diff --git a/src/functions/graphics/xcurse.asm b/src/functions/graphics/xcurse.asm index 6313666..7764335 100644 --- a/src/functions/graphics/xcurse.asm +++ b/src/functions/graphics/xcurse.asm @@ -3,6 +3,7 @@ ldx HRS1 ; X=HRSX FIXME ldy HRS2 ; Y=HRSY FIXME jsr hires_verify_position ; on vérifie les coordonnées + put: jsr hires_put_coordinate ; on place le curseur en X,Y diff --git a/src/functions/graphics/xdrawa.asm b/src/functions/graphics/xdrawa.asm index 75fdee3..1a72b22 100644 --- a/src/functions/graphics/xdrawa.asm +++ b/src/functions/graphics/xdrawa.asm @@ -16,6 +16,7 @@ bcs @S1 ; si DX<0, on inverse le signe de HRS1 stx HRS1+1 ; dec $4E aurait été mieux... sec + @S1: lda HRS4 ; on prend Y2 sbc HRS2 ; -Y1 diff --git a/src/functions/graphics/xdrawr.asm b/src/functions/graphics/xdrawr.asm index eb47f07..123f2cc 100644 --- a/src/functions/graphics/xdrawr.asm +++ b/src/functions/graphics/xdrawr.asm @@ -84,7 +84,7 @@ LE8ED: lda HRS2 ; I on trace la droite selon dY <--------------------- beq LE8EA ; ---dY=0, on sort ldx HRS1 ; X=dX - jsr Le921 ; on calcule dX/dY dans RES + jsr Le921 ; on calcule dX/dY dans RES LE8F6: bit HRS2+1 bpl LE900 ; dY>0 --------------------------------------------- @@ -102,8 +102,10 @@ LE903: bpl LE916 ; dX>0 ------------------------------------ I jsr XHRSCG_ROUTINE ; dX<0, on déplace vers I I jmp LE919 ; ---la gauche I I + LE916: jsr XHRSCD_ROUTINE ; I on déplace vers la droite <-------------- I + LE919: jsr XHRSSE_ROUTINE ; -->on affiche le point <----------------------------- dec HRS2 ; et on décrit dY FIXME diff --git a/src/functions/xvars/xvars.asm b/src/functions/xvars/xvars.asm index bbad23e..2015ce0 100644 --- a/src/functions/xvars/xvars.asm +++ b/src/functions/xvars/xvars.asm @@ -186,7 +186,7 @@ ; Y contains if the type of bank ; Y=0 RAM ; Y=1 ROM - cpy #01 ; Is rom ? + cpy #$01 ; Is rom ? beq @not_managed ldx #$00 @@ -198,7 +198,7 @@ bcc @found inx - cpx #08 ; For instance, manage only 8 banks + cpx #$08 ; For instance, manage only 8 banks beq @error bne @search_available_bank ; not found @@ -208,6 +208,7 @@ stx RES ; Save lda #01 ; 4 + @continue: asl dex ; 0 @@ -342,32 +343,41 @@ bank: rts .endproc +; Arg = $09 .proc xvars_get_fd_list ; Y contains the fd to get + ; Returns : X the mode of the opened file$ + tya + sec + sbc #KERNEL_FIRST_FD + asl tax - jsr kernel_get_struct_process_ptr - sta RES - sty RES+1 - lda RES - bne continue - - lda RES+1 - bne continue + lda kernel_process+kernel_process_struct::fp_ptr,x + sta RES + lda kernel_process+kernel_process_struct::fp_ptr+1,x + beq @no_ptr + sta RES+1 - rts + ; Get the mode + ldy #_KERNEL_FILE::f_mode + lda (RES),y + tax -continue: lda #_KERNEL_FILE::f_path clc adc RES bcc @S1 inc RES+1 + @S1: - ; A is valid + ; A is valid path ldy RES+1 + rts +@no_ptr: + ldy #$00 rts .endproc @@ -378,6 +388,7 @@ continue: ldy #$01 ; Because we store the number of line ldx #$00 + @loop_copy_free_chunk_begin_low: lda kernel_malloc+kernel_malloc_struct::kernel_malloc_free_chunk_begin_high,x beq @free_slot_not_used ; Begin low is equal to 0 ? Yes, it's empty @@ -419,7 +430,6 @@ continue: ; Store number of line at the first byte - rts .endproc @@ -472,7 +482,6 @@ continue: lda TR0 sta (RES),y - rts .endproc @@ -486,9 +495,8 @@ continue: tax jsr kernel_get_struct_process_ptr - - rts + @init: lda #$00 ; Return null if it's init ldy #$00 @@ -517,28 +525,29 @@ continue: rts .endproc - XVARS_TABLE_VALUE_LOW: .byt KERNEL_ERRNO XVARS_TABLE: XVARS_TABLE_LOW: - .byt kernel_process + .byt >kernel_process ; 0 .byt >kernel_malloc .byt >KERNEL_CH376_MOUNT .byt >KERNEL_CONF_BEGIN @@ -546,7 +555,7 @@ XVARS_TABLE_HIGH: .byt KERNEL_MALLOC_FREE_CHUNK_MAX .byt $00 .byt $00 ; ; Table high - .byt $00 ; KERNEL_MAX _PROCESS + .byt KERNEL_MAX_FP ; 8 KERNEL_MAX _PROCESS for low, MAX FP for high .byt >osname ; 9 .byt >kernel_process+kernel_process_struct::kernel_pid_list ; $0A diff --git a/src/include/process.inc b/src/include/process.inc index f881819..f8d49fd 100644 --- a/src/include/process.inc +++ b/src/include/process.inc @@ -2,7 +2,7 @@ .define KERNEL_NUMBER_OF_CHILD_PER_PROCESS 1 .define KERNEL_MAX_LENGTH_COMMAND 8 .define KERNEL_MAX_FP_PER_PROCESS 2 ; Can't be greater than KERNEL_MAX_FP -.define KERNEL_MAX_FP 2 ; Max filepointer available can +.define KERNEL_MAX_FP 2 ; Max filepointers availables .define KERNEL_USERZP_SAVE_LENGTH 16 ; Each process has userzp variable, this value says that the kernel needs to save this size .define KERNEL_LENGTH_MAX_CMDLINE 37 diff --git a/src/kernel.asm b/src/kernel.asm index 7b05f82..c23e16a 100644 --- a/src/kernel.asm +++ b/src/kernel.asm @@ -117,8 +117,19 @@ FLPO0 := $87 ; 2- Flush page 0,2,4,5 : Because on atmos memory are not set to 0, if it's not set to 0, we have strange behavior (as keyboard), don't change it ! ; 3- Launch mount on the device but don't test the result, because we don't care at this step : it's a quick hack to mount quickly mass storage gadget + +.segment "BANK8" +; .bss +.res 100 + +.segment "BANK0" +; .bss +.res 100 + +.segment "BANK7" + .org $C000 -.code + start_rom: .proc _main @@ -1755,6 +1766,12 @@ XCHECK_VERIFY_USBDRIVE_READY_ROUTINE: .include "functions/files/_ch376_seek_file32.asm" .include "functions/files/byte_wr_go.asm" .include "functions/files/compute_path_relative.asm" +.include "functions/files/ch376_open_filename.asm" +.include "functions/files/send_0_to_ch376_and_open.asm" +.include "functions/files/restore_position_into_file.asm" +.include "functions/files/open_full_filename.asm" + + .include "functions/process/kernel_get_struct_process_ptr.asm" .include "functions/strings/xminma.asm" diff --git a/src/kernel.cfg b/src/kernel.cfg new file mode 100644 index 0000000..7687253 --- /dev/null +++ b/src/kernel.cfg @@ -0,0 +1,44 @@ +FEATURES { + STARTADDRESS: default = $1000; +} +SYMBOLS { + __STACKSIZE__: type = weak, value = $0800; # 2k stack + __STACKSTART__: type = weak, value = $8000; + __ZPSTART__: type = weak, value = $0080; +} +MEMORY { + BANK0: type = ro, start = $C000,size = $FFFF,file = "kernelr.rom"; + BANK7: type = ro, start = $C000,size = $FFFF,file = "kernel.rom"; + BANK8: type = ro, start = $C000,size = $FFFF,file = "kernel2.rom"; + ZP: file = "", define = yes, start = __ZPSTART__, size = $001F; + MAIN: file = %O, start = %S, size = __STACKSTART__ - __STACKSIZE__ - %S; +} +SEGMENTS { + ZEROPAGE: load = ZP, type = zp; + STARTUP: load = MAIN, type = ro, optional = yes; + LOWCODE: load = MAIN, type = ro, optional = yes; + ONCE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = rw; + RODATA: load = MAIN, type = rw; + DATA: load = MAIN, type = rw; + BSS: load = MAIN, type = bss, define = yes; + BANK8: load = BANK8, type = ro; + BANK7: load = BANK7, type = ro; + BANK0: load = BANK0, type = ro; +} +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = ONCE; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; + CONDES: type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__, + segment = RODATA, + import = __CALLIRQ__; +} + diff --git a/tests/Makefile b/tests/Makefile index b6d4ddd..5a81e7b 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -9,4 +9,7 @@ all : testkernel testkernel: - cl65 -ttelestrat test_kernel.c xvars_operation/_xvalues_get_free_ram_bank_routine.s \ No newline at end of file + cl65 -ttelestrat test_kernel.c xvars_operation/_xvalues_get_free_ram_bank_routine.s + cl65 -ttelestrat multiples_files_opened.c -o 1000 --start-addr 2048 + cl65 -ttelestrat multiples_files_opened.c -o 1256 --start-addr 2304 + orix-sdk/bin/relocbin.py3 -o kopened -2 1000 1256