Skip to content

Commit b29b971

Browse files
authored
Merge pull request #2 from wildbitscomputing/feat/iec-command-channel
feat: IEC status/command channel support
2 parents d82a136 + 5fee5ca commit b29b971

4 files changed

Lines changed: 202 additions & 6 deletions

File tree

hardware/iec.asm

Lines changed: 138 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -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
@@ -284,6 +284,8 @@ _ops
284284
.word format
285285
.word mkdir
286286
.word rmdir
287+
.word read_block
288+
.word write_block
287289

288290
seek
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

kernel/api.asm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,8 @@ fs_t .struct
158158
.union
159159
format .dstruct fs_mkfs_t
160160
mkfs .dstruct fs_mkfs_t
161+
read_block .dstruct fs_block_t
162+
write_block .dstruct fs_block_t
161163
.endu
162164
.ends
163165
fs_mkfs_t .struct
@@ -166,6 +168,12 @@ cookie .byte ?
166168
label = args.buf
167169
label_len = args.buflen
168170
.ends
171+
fs_block_t .struct ; ReadBlock / WriteBlock (IEC: status/command channel)
172+
drive .byte ?
173+
cookie .byte ?
174+
buf = args.buf ; Data buffer (command to send or response received)
175+
buflen = args.buflen ; Buffer length
176+
.ends
169177
170178
; File Calls
171179
file_t .struct

kernel/calls.asm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ MkFS .word kernel.fs.mkfs
122122
CheckFS .word dummy
123123
Mount .word dummy
124124
Unmount .word dummy
125-
ReadBlock .word dummy
126-
WriteBlock .word dummy
125+
ReadBlock .word kernel.fs.read_block
126+
WriteBlock .word kernel.fs.write_block
127127
.endn
128128

129129
File .namespace

kernel/fs.asm

Lines changed: 54 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ MKFS .word ?
3131
FORMAT .word ?
3232
MKDIR .word ?
3333
RMDIR .word ?
34+
READ_BLOCK .word ? ; Read from device (IEC: read status channel)
35+
WRITE_BLOCK .word ? ; Write to device (IEC: send command)
3436
.endv
3537

3638
MAX_ENTRIES = 8
@@ -600,7 +602,7 @@ _out
600602
rmdir
601603
jsr open_common
602604
bcs _out
603-
605+
604606
; Set the command
605607
lda #RMDIR
606608
sta args.command,y
@@ -612,7 +614,57 @@ rmdir
612614
lda kernel.stream.entry.driver,x
613615
tax
614616
jsr kernel.device.dev.send
615-
617+
618+
; Return the stream
619+
pla
620+
_out
621+
rts
622+
623+
read_block
624+
; Read from device command/status channel (IEC: reads error channel)
625+
; IN: drive, cookie, buflen
626+
; OUT: event with response data in buf
627+
628+
jsr open_common
629+
bcs _out
630+
631+
; Set the command
632+
lda #READ_BLOCK
633+
sta args.command,y
634+
635+
; Save the stream for later return
636+
phx
637+
638+
; Queue the command
639+
lda kernel.stream.entry.driver,x
640+
tax
641+
jsr kernel.device.dev.send
642+
643+
; Return the stream
644+
pla
645+
_out
646+
rts
647+
648+
write_block
649+
; Write to device command/status channel (IEC: sends command)
650+
; IN: drive, cookie, buf, buflen
651+
; OUT: event confirming completion
652+
653+
jsr open_common
654+
bcs _out
655+
656+
; Set the command
657+
lda #WRITE_BLOCK
658+
sta args.command,y
659+
660+
; Save the stream for later return
661+
phx
662+
663+
; Queue the command
664+
lda kernel.stream.entry.driver,x
665+
tax
666+
jsr kernel.device.dev.send
667+
616668
; Return the stream
617669
pla
618670
_out

0 commit comments

Comments
 (0)