1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
|
;
; 2012-10-16, Oliver Schmidt
; 2014-07-16, Greg King
;
; unsigned char __fastcall__ _syschdir (const char* name);
;
.export __syschdir
.import diskinit, fnunit, curunit, initcwd
.importzp ptr1, tmp1, tmp2
;--------------------------------------------------------------------------
; __syschdir
.proc __syschdir
; Save name
sta ptr1
stx ptr1+1
; Process first character
ldy #0
lda (ptr1),y
beq err
jsr getdigit
bcs err
tax
; Process second character
iny
lda (ptr1),y
beq init
jsr getdigit
bcs err
stx tmp1 ; First digit
sta tmp2 ; Second digit
; Multiply first digit by 10
txa
asl a ; * 2
asl a ; * 4, carry cleared
adc tmp1 ; * 5
asl a ; * 10, carry cleared
; Add second digit to product
adc tmp2
tax
; Process third character
iny
lda (ptr1),y
bne err
; Check device readiness
init: txa
jsr diskinit
bne done
; Success, update cwd
lda fnunit ; Set by diskinit
sta curunit
jmp initcwd ; Returns with A = 0
; Return with error in A
err: lda #9 ; "Illegal device"
done: rts
.endproc
;--------------------------------------------------------------------------
; getdigit -- Converts PetSCII to binary.
; Sets carry if the character is outside of '0'-'9'.
.proc getdigit
sec
sbc #'0'
bcs @L0
sec
rts
@L0: cmp #10
rts
.endproc
|