News:

Printed Amstrad Addict magazine announced, check it out here!

Main Menu
avatar_d_kef

Albireo ACEspansion plugin problem writing data

Started by d_kef, 14:49, 03 March 24

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

d_kef

Quote from: OffseT on 19:39, 26 February 24
Quote from: d_kef on 19:05, 26 February 24But...
I've just discovered that also writing to CP/M image files is not working.
I'm not using raw sector commands.
For writing I'm using:
cmd_set_filename
cmd_file_open
cmd_byte_locate
cmd_byte_write
cmd_wr_req_data
cmd_byte_wr_go
cmd_file_close
I guess you are using a sequence which is different from both Jede's OS and UniDOS that is not be emulated by the current ch376 library. Could you please open a new topic dedicated to Albireo ACEpansion plugin with additional information about the programming sequence you are using? I could have a look at it when I have time. It might not be a big deal to fix it.
It seems that commands cmd_byte_write, cmd_wr_req and cmd_byte_wr_go are not executed at all.
I first tested it with Ubuntu 22.04 and thought that there was something wrong with my file permissions but the same thing happens in Windows 11 too.
The code I use is the following (either albrdsect or albwrsect is called in order to read or write a pseudo-sector respectively):
; Albireo routines

; I/O ports
aldatport    equ    #fe80
alcmdport    equ    #fe81

; CH376 commands (Albireo and USIfAC)
cmd_check_exist        equ    #06
cmd_set_usb_mode    equ    #15
cmd_get_status        equ    #22
cmd_rd_usb_data0    equ    #27
cmd_write_host_data    equ    #2c
cmd_wr_req_data        equ    #2d
cmd_set_filename    equ    #2f
cmd_disk_mount        equ    #31
cmd_file_open        equ    #32
cmd_file_close        equ    #36
cmd_byte_locate        equ    #39
cmd_byte_read        equ    #3a
cmd_byte_rd_go        equ    #3b
cmd_byte_write        equ    #3c
cmd_byte_wr_go        equ    #3d

cmd_disk_read        equ    #54
cmd_disk_rd_go        equ    #55
cmd_disk_write        equ    #56
cmd_disk_wr_go        equ    #57

; CH376 respond codes (Albireo and USIfAC)
cmd_ret_success        equ    #51

usb_int_success        equ    #14
usb_int_disk_read    equ    #1d
usb_int_disk_write    equ    #1e
usb_int_disk_error    equ    #1f

err_open_dir        equ    #41
err_miss_file        equ    #42
err_found_name        equ    #43
err_file_close        equ    #b4

;----------------------------------------------------
; Read Albireo virtual sector from file on SD card
; entry A=CP/M image file number 00-99
;    DE,HL=LBA of virtual sector
;    (BUFADD)=address of data buffer
;  exit A=status, carry set on error
;  uses AF, BC, DE, HL
;----------------------------------------------------
albrdsect:
    call    alopen
    ret    c
    call    alsetlba
    call    nc,alread
    jp    alclose

;----------------------------------------------------
; Write Albireo virtual sector to file on SD card
; entry A=CP/M image file number 00-99
;    DE,HL=LBA of virtual sector
;    (BUFADD)=address of data buffer
;  exit A=status, carry set on error
;  uses AF, BC, DE, HL
;----------------------------------------------------
albwrsect:
    call    alopen
    ret    c
    call    alsetlba
    call    nc,alwrite
    jp    alclose

;----------------------------------------------------
; Open Albireo file on SD card
; entry A=CP/M image file number 00-99
;  exit A=status, carry set on error
;  uses AF, BC
;----------------------------------------------------
alopen:    push    hl   

    ld    hl,alfnr
    call    a2asc2        ; set image file number

    ld    a,cmd_set_filename
    ld    bc,alcmdport
    out    (c),a
    dec    c
    ld    hl,alfname
    ld    a,14        ; send 14 characters
alfnrep:
    inc    b
    outi
    dec    a
    jr    nz,alfnrep
alopen1:
    ld    bc,alcmdport
    ld    a,cmd_file_open
    out    (c),a
    call    alrdresp    ; read response
    pop    hl
    cp    usb_int_success    ; is it open
    ret    z
    scf
    ret            ; return on error

alfname:
    db    "/CPMDSK"
alfnr:    db    "01.IMG",0

;----------------------------------------------------
; Close Albireo file on SD card
; entry -
;  exit A=status, carry set on error
;  uses AF, BC
;----------------------------------------------------
alclose:
    ld    a,cmd_file_close
    ld    bc,alcmdport
    out    (c),a
    dec    c
    xor    a
    out    (c),a        ; file length update is not allowed
    call    alrdresp    ; read response
    cp    usb_int_success    ; is it closed
    ret    z
    scf
    ret

;----------------------------------------------------
; Set Albireo byte number pointer
; entry DE,HL=LBA of virtual sector
;  exit A=status, carry set on error
;  uses AF, BC, E, HL
;----------------------------------------------------
alsetlba:
    sla    l        ; virtual sector LBA to byte number
    rl    h
    rl    e
    ld    a,cmd_byte_locate
    ld    bc,alcmdport
    out    (c),a
    dec    c
    xor    a
    out    (c),a        ; is always 0
    out    (c),l
    out    (c),h
    out    (c),e
    call    alrdresp    ; read int response
    cp    usb_int_success
    ret    z
    scf
    ret

;----------------------------------------------------
; Read Albireo file virtual sector
; entry (BUFADD)=address of data buffer
;  exit A=status, carry set on error
;  uses AF, BC, HL
;----------------------------------------------------
alread:
    ld    a,cmd_byte_read
    ld    bc,alcmdport
    out    (c),a
    dec    c
    ld    hl,ssize    ; read #0200 bytes
    out    (c),l
    out    (c),h
    ld    hl,(bufadd)    ; DMA address
rdnxtarsp:
    call    alrdresp    ; read int response
    cp    usb_int_disk_read
    jr    z,aldoread
    cp    usb_int_success
    jr    nz,alrderr
    ret
alrderr:
    scf            ; error
    ret
aldoread:
    ld    bc,alcmdport
    ld    a,cmd_rd_usb_data0
    out    (c),a
    dec    c
    in    a,(c)        ; wait for response = data lentght <= 255
alnextrd:            ; read data to buffer
    ini
    inc    b
    dec    a
        jr    nz,alnextrd
    ld    bc,alcmdport
    ld    a,cmd_byte_rd_go
    out    (c),a
    jr    rdnxtarsp

;----------------------------------------------------
; Write Albireo disk sector
; entry (BUFADD)=address of data buffer
;  exit A=status, carry set on error
;  uses AF, BC, HL
;----------------------------------------------------
alwrite:
    ld    a,cmd_byte_write
    ld    bc,alcmdport
    out    (c),a
    dec    c
    ld    hl,ssize    ; write #0200 bytes
    out    (c),l
    out    (c),h
    ld    hl,(bufadd)    ; DMA address
wrnxtarsp:
    call    alrdresp    ; read int response
    cp    usb_int_disk_write
    jp    z,aldowrite
    cp    usb_int_success
    jr    nz,alwrerr
    ret
alwrerr:
    scf            ; error
    ret
aldowrite:
    ld    bc,alcmdport
    ld    a,cmd_wr_req_data
    out    (c),a
    dec    c
    in    a,(c)        ; wait for response = data lentght <= 255
alnextwr:            ; write data from buffer
    inc    b
    outi
    dec    a
        jr    nz,alnextwr
    ld    bc,alcmdport
    ld    a,cmd_byte_wr_go
    out    (c),a
    jr    wrnxtarsp

;----------------------------------------------------
; Get Albireo response
; entry -
; exit  A=Albireo response
; uses AF, BC
;----------------------------------------------------
alrdresp:
    ld    bc,alcmdport
alrespr:
    in    a,(c)
    rlca            ; wait for interrupt
    jr    c,alrespr
    ld    a,cmd_get_status
    out    (c),a
    dec    c
    in    a,(c)        ; response in a
    ret

;----------------------------------------------------
; Detect Albireo
; entry -
; exit  A=Albireo response, zero set on detection
; uses AF, BC
;----------------------------------------------------
albchk:    ld    bc,alcmdport
    ld    a,cmd_check_exist
    out    (c),a
    dec    c
    ld    a,#55        ; send control byte
    out    (c),a
    in    a,(c)        ; read response
    cp    #aa        ; check the result is logical NOT of control byte
    ret    nz
    inc    c
    ld    a,cmd_set_usb_mode
    out    (c),a
    dec    c
    ld    a,#03        ; SD mode
    out    (c),a
    ld    b,#10
sdelay:    nop            ; wait some time
    djnz    sdelay
    ld    bc,aldatport
    in    a,(c)        ; get status
    cp    cmd_ret_success
    ret    nz
    ld    bc,alcmdport
    ld    a,cmd_disk_mount
    out    (c),a
    call    alrdresp
    cp    usb_int_success
    ret

;__________________________________________________
; Convert 1 or 2 digit number to decimal ASCII format and save it
; entry A = number to convert
;    HL = address to save string
;  exit -
;  uses AF, BC, HL
;__________________________________________________
a2asc2:    ld    c,-10        ; 2-digit
    call    na1
a2asc1:    ld    c,-1        ; 1-digit
na1:    ld    b,'0'-1
na2:    inc    b
    add    a,c
    jr    c,na2
    sub    c
    push    af
    ld    a,b
    ld    (hl),a
    inc    hl
    pop    af   
    ret


d_kef

OffseT


Powered by SMFPacks Menu Editor Mod