@@ -89,7 +89,7 @@ _loop sta channels,x
8989
9090 ; Wait before enabling IEC operations.
9191 stz awake
92- lda #5
92+ lda #1
9393 jsr kernel .clock.insert
9494
9595 phy
@@ -269,7 +269,7 @@ dev_send
269269_go
270270 ldx kernel.fs.args.command,y
271271 jmp (_ops,x)
272- _ops
272+ _ops
273273 .word open
274274 .word open_dir
275275 .word open_new
284284 .word format
285285 .word mkdir
286286 .word rmdir
287+ .word read_block
288+ .word write_block
287289
288290seek
289291_err
@@ -1474,6 +1476,140 @@ _out
14741476 jsr kernel .stream.free
14751477 jmp kernel .event.enque
14761478
1479+ read_block
1480+ ; Read from IEC device status/error channel (channel 15)
1481+ ; Y->event, X->stream
1482+ ; Returns status string in event buffer
1483+
1484+ ldx kernel.fs.args.stream,y
1485+
1486+ ; Mount the buffer for writing
1487+ jsr mount_buf
1488+
1489+ ; Save the max buffer size
1490+ lda kernel.fs.args.requested,y
1491+ sta requested
1492+
1493+ ; TALK to the device
1494+ lda kernel.stream.entry.device,x
1495+ jsr platform .iec.TALK
1496+ bcs _err
1497+
1498+ ; Request data from the command/status channel (15)
1499+ lda #$0f
1500+ jsr platform .iec.DEV_SEND
1501+ bcs _close
1502+
1503+ ; Read bytes into buffer until EOI
1504+ phy
1505+ ldy #0
1506+ _loop
1507+ jsr platform .iec.IECIN
1508+ bcs _read_done
1509+ sta (kernel.dest),y
1510+ iny
1511+ cpy requested ; Don't overflow buffer
1512+ beq _read_done
1513+ bvc _loop ; Continue until EOI
1514+
1515+ _read_done
1516+ ; Save the count
1517+ tya
1518+ ply
1519+ sta kernel.event.entry.file.data .read,y
1520+
1521+ _close
1522+ ; Close the TALK session
1523+ php
1524+ lda kernel.stream.entry.device,x
1525+ jsr platform .iec.UNTALK
1526+ plp
1527+ bcs _err
1528+
1529+ ; Send success event
1530+ lda #kernel.event.fs.DATA
1531+ bra _send
1532+
1533+ _err
1534+ lda #kernel.event.fs.ERROR
1535+ _send
1536+ sta kernel.event.entry.type,y
1537+
1538+ ; Free the stream and queue the event
1539+ txa
1540+ jsr kernel .stream.free
1541+ jmp kernel .event.enque
1542+
1543+
1544+ write_block
1545+ ; Write command to IEC device command channel (channel 15)
1546+ ; Y->event, X->stream
1547+ ; Sends command string from event buffer
1548+
1549+ ldx kernel.fs.args.stream,y
1550+
1551+ ; Mount the buffer for reading
1552+ jsr mount_buf
1553+
1554+ ; Save the byte count to send
1555+ lda kernel.fs.args.requested,y
1556+ sta requested
1557+
1558+ ; LISTEN to the device
1559+ lda kernel.stream.entry.device,x
1560+ jsr platform .iec.LISTEN
1561+ bcs _err
1562+
1563+ ; Open the command channel (15)
1564+ lda #$0f
1565+ jsr platform .iec.OPEN
1566+ bcs _err
1567+
1568+ ; Send bytes from buffer
1569+ lda requested
1570+ beq _unlisten ; Nothing to send
1571+ phy
1572+ ldy #0
1573+ _wloop
1574+ lda (kernel.dest),y
1575+ jsr platform .iec.IECOUT
1576+ bcs _write_err
1577+ iny
1578+ cpy requested
1579+ bne _wloop
1580+
1581+ ; Save bytes written
1582+ tya
1583+ ply
1584+ sta kernel.event.entry.file.wrote.wrote,y
1585+ bra _unlisten
1586+
1587+ _write_err
1588+ ply
1589+
1590+ _unlisten
1591+ ; Close the LISTEN session
1592+ jsr platform .iec.UNLISTEN
1593+ bcs _err
1594+
1595+ ; Command was sent successfully
1596+ ; Note: Don't read status here - drive may be busy processing.
1597+ ; Caller can use ReadBlock to check status separately.
1598+
1599+ ; Send success event
1600+ lda #kernel.event.fs.WROTE
1601+ bra _send
1602+
1603+ _err
1604+ lda #kernel.event.fs.ERROR
1605+ _send
1606+ sta kernel.event.entry.type,y
1607+
1608+ ; Free the stream and queue the event
1609+ txa
1610+ jsr kernel .stream.free
1611+ jmp kernel .event.enque
1612+
14771613 .send
14781614 .endn
14791615 .endn
0 commit comments