Skip to content

Commit

Permalink
Apple2: Rewrite rewinddir() in assembly
Browse files Browse the repository at this point in the history
  • Loading branch information
colinleroy authored and oliverschmidt committed Nov 17, 2024
1 parent f663ee4 commit 21030c2
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 132 deletions.
63 changes: 0 additions & 63 deletions libsrc/apple2/dir.h

This file was deleted.

69 changes: 0 additions & 69 deletions libsrc/apple2/rewinddir.c

This file was deleted.

70 changes: 70 additions & 0 deletions libsrc/apple2/rewinddir.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
;
; Colin Leroy-Mira <[email protected]>, 2024
;
; void __fastcall__ rewinddir (DIR* dir)
;
.export _rewinddir
.import read_dir_block_ptr1

.import pusha, pusha0, pushax
.import pushptr1, popptr1
.import incaxy
.import _lseek, _memset

.importzp ptr1, sreg

.include "dir.inc"
.include "stdio.inc"

.proc _rewinddir
sta ptr1
stx ptr1+1
jsr pushptr1 ; Backup ptr1, destroyed by _lseek

; Rewind directory file
ldy #DIR::FD
lda (ptr1),y
jsr pusha0 ; Push dir->fd

tya ; Y = 0 here
jsr pusha0
jsr pusha0 ; Push 0L

lda #SEEK_SET ; X = 0 here
jsr _lseek

ora sreg ; Check lseek returned 0L
ora sreg+1
bne @rewind_err
txa
bne @rewind_err

jsr popptr1 ; Restore ptr1

; Read directory key block
jsr read_dir_block_ptr1
bcs @rewind_err

; Skip directory header entry
lda #$01
ldy #DIR::CURRENT_ENTRY
sta (ptr1),y
rts

@rewind_err:
jsr popptr1 ; Restore ptr1

; Assert that no subsequent readdir() finds an active entry
lda ptr1
ldx ptr1+1
ldy #DIR::BYTES + DIR::CONTENT::ENTRIES
jsr incaxy
jsr pushax

lda #$00
jsr pusha

lda #<.sizeof(DIR::BYTES)
ldx #>.sizeof(DIR::BYTES)
jmp _memset
.endproc

0 comments on commit 21030c2

Please sign in to comment.