Skip to content

Commit 2983f47

Browse files
committed
Add network_ioctl for atari, including test from C file
1 parent 80ef68f commit 2983f47

File tree

11 files changed

+146
-25
lines changed

11 files changed

+146
-25
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,6 @@ dkms.conf
5555
# generated files
5656
dist/
5757
obj/
58+
59+
# IDE files
60+
.vscode/

Changelog.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
- This changelog to instil a process of clean version documentation for the library.
1010
- Common Makefile
1111
- Initial implementations of atari functions:
12-
- network_close, network_open, network_read, network_write, network_status
12+
- network_close, network_open, network_read, network_write, network_status, network_ioctl
1313
- cross platform BDD testing framework, atari implementation done, c64 skeleton created
1414

1515
## Notes

README.md

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ Routines to use the FujiNet Network Adapter sub-device
44

55
Top level folder contains the .h API, one subfolder for each platform.
66

7+
## Building
8+
9+
If required, specify `TARGETS` list. The default is to clean, build and create release for all known platforms.
10+
11+
```shell
12+
$ make
13+
```
14+
15+
## Release
16+
17+
Use the make target `dist` which will zip the library, headers, and Changelog into version specific file at `dist/fujinet-network_VERSION.zip`.
18+
19+
## Testing
20+
21+
Testing is done with BDD features. See [Testing README](testing/bdd-testing/README.md)
22+
723
## TODO
824

925
### global
@@ -15,7 +31,7 @@ Top level folder contains the .h API, one subfolder for each platform.
1531

1632
|System | network_open() | network_close() | network_read() | network_write() | network_status() | network_ioctl() |
1733
|-------|----------------|-----------------|----------------|-----------------|------------------|-----------------|
18-
| Atari | `[ ]` | `[ ]` | `[ ]` | `[ ]` | `[ ]` | `[ ]` |
34+
| Atari | `[x]` | `[x]` | `[x]` | `[x]` | `[x]` | `[x]` |
1935
| Apple2| `[ ]` | `[ ]` | `[ ]` | `[ ]` | `[ ]` | `[ ]` |
2036
| ADAM | `[ ]` | `[ ]` | `[ ]` | `[ ]` | `[ ]` | `[ ]` |
2137
| CBM | `[ ]` | `[ ]` | `[ ]` | `[ ]` | `[ ]` | `[ ]` |
@@ -39,7 +55,7 @@ Listed:
3955
- [x] network_read()
4056
- [x] network_write()
4157
- [x] network_status()
42-
- [ ] network_ioctl()
58+
- [x] network_ioctl()
4359

4460
### target: apple2
4561

@@ -85,19 +101,3 @@ Listed:
85101
- [ ] network_write()
86102
- [ ] network_status()
87103
- [ ] network_ioctl()
88-
89-
## Building
90-
91-
If required, specify `TARGETS` list. The default is to clean, build and create release for all known platforms.
92-
93-
```shell
94-
$ make
95-
```
96-
97-
## Release
98-
99-
Use the make target `dist` which will zip the library, headers, and Changelog into version specific file at `dist/fujinet-network_VERSION.zip`.
100-
101-
## Testing
102-
103-
Testing is done with BDD features. See [Testing README](testing/bdd-testing/README.md)

atari/src/network_ioctl.s

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
.export _network_ioctl
2+
3+
.import _bus
4+
.import _io_status
5+
.import _network_unit
6+
.import addysp
7+
.import copy_cmd_data
8+
.import popa
9+
.import popax
10+
.import return1
11+
12+
.include "device.inc"
13+
.include "zp.inc"
14+
.include "macros.inc"
15+
16+
; uint8_t network_ioctl(uint8_t cmd, uint8_t aux1, uint8_t aux2, char* devicespec, ...);
17+
;
18+
; for atari this must always be called with:
19+
; uint8_t network_ioctl(uint8_t cmd, uint8_t aux1, uint8_t aux2, char* devicespec, [uint8_5 dstats, uint16_t dbuf, uint16_t dbyt]);
20+
;
21+
; CC65 uses 2 bytes for every variadic parameter, even if they are uint8_t (from cl65 output), so each param
22+
; should be done with popax.
23+
.proc _network_ioctl
24+
cpy #$0b ; 5 for standard args, 3 extra args at 2 bytes each = 5 + 6 = 11 bytes on stack. if not, we have been called incorrectly
25+
bne @args_error
26+
27+
; we have every DCB parameter on stack
28+
jsr popax ; dbyt
29+
axinto IO_DCB::dbytlo
30+
31+
jsr popax ; dbuf
32+
axinto IO_DCB::dbuflo
33+
34+
jsr popax ; dstats, ignore X. cc65 does 2 bytes on stack for all varargs, we only need 1 here
35+
sta IO_DCB::dstats
36+
37+
jsr popax ; devicespec, we can only get the UNIT out of this
38+
jsr _network_unit
39+
sta IO_DCB::dunit
40+
41+
jsr popa ; aux2
42+
sta IO_DCB::daux2
43+
44+
jsr popa ; aux1
45+
sta IO_DCB::daux1
46+
47+
jsr popa ; cmd
48+
sta IO_DCB::dcomnd
49+
50+
mva #$71, IO_DCB::ddevic ; device
51+
mva #$0f, IO_DCB::dtimlo ; timeout
52+
53+
jsr _bus
54+
jmp _io_status ; set return to the status
55+
56+
@args_error:
57+
; increase SP by Y to clear the params we received, and return error
58+
jsr addysp
59+
ldx #$00
60+
lda #$ff
61+
rts
62+
63+
.endproc

fujinet-network.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ uint8_t network_close(char* devicespec);
1414
uint8_t network_open(char* devicespec, uint8_t trans);
1515
uint8_t network_read(char* devicespec, uint8_t *buf, uint16_t len);
1616
uint8_t network_write(char* devicespec, uint8_t *buf, uint16_t len);
17-
18-
// TODO:
19-
// network_ioctl
17+
uint8_t network_ioctl(uint8_t cmd, uint8_t aux1, uint8_t aux2, char* devicespec, ...);
2018

2119
#endif /* FUJINET_NETWORK_H */
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
Feature: library test - network_ioctl
2+
3+
This tests fujinet-network network_ioctl
4+
See the associated test file which calls with:
5+
return network_ioctl('X', 1, 2, my_devicespec, my_dstats, my_dbuf, my_dbyt);
6+
7+
Scenario: execute _network_ioctl
8+
Given atari-fn-nw application test setup
9+
And I add common atari-io files
10+
And I add atari src file "network_ioctl.s"
11+
And I add atari src file "network_unit.s"
12+
And I add atari src file "network_status.s"
13+
And I add atari src file "io_status.s"
14+
And I add file for compiling "features/atari/test-apps/test_network_ioctl.c"
15+
And I add file for compiling "features/atari/stubs/bus_simple.s"
16+
And I set register X to $ff
17+
And I create and load application
18+
When I execute the procedure at _init for no more than 220 instructions
19+
20+
Then I expect to see DDEVIC equal $71
21+
And I expect to see DUNIT equal 3
22+
And I expect to see DCOMND equal $58
23+
And I expect to see DSTATS equal $40
24+
And I expect to see DBUFLO equal $bc
25+
And I expect to see DBUFHI equal $4a
26+
And I expect to see DTIMLO equal $0f
27+
And I expect to see DBYTLO equal $34
28+
And I expect to see DBYTHI equal $12
29+
And I expect to see DAUX1 equal 1
30+
And I expect to see DAUX2 equal 2
31+
32+
# DSTATS still in A, X forced to 0
33+
Then I expect register A equal $40
34+
And I expect register X equal 0
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#include "fujinet-network.h"
2+
3+
char *my_devicespec = "n3:FOO://bar";
4+
uint8_t my_dstats = 0x40;
5+
uint16_t my_dbuf = 0x4abc;
6+
uint16_t my_dbyt = 0x1234;
7+
8+
int main(void) {
9+
return network_ioctl('X', 1, 2, my_devicespec, my_dstats, my_dbuf, my_dbyt);
10+
}

testing/bdd-testing/features/test-setup/inc/fn-nw-app.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ FEATURES {
44
SYMBOLS {
55
__STACKSIZE__: type = weak, value = $0200;
66
__STARTADDRESS__: type = export, value = %S;
7+
__STACKSTART__: type = weak, value = $8000;
78
}
89
MEMORY {
910
ZP: file = "", define = yes, start = $0082, size = $007E;
@@ -24,6 +25,7 @@ SEGMENTS {
2425
CODE: load = MAIN, type = rw, define = yes;
2526
RODATA: load = MAIN, type = ro optional = yes;
2627
DATA: load = MAIN, type = rw optional = yes;
28+
STARTUP: load = MAIN, type = ro, optional = yes;
2729
# For malloc
2830
ONCE: load = MAIN, type = rw optional = yes;
2931

testing/bdd-testing/features/test-setup/inc/fn-nw-direct.cfg

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ FEATURES {
44
SYMBOLS {
55
__STACKSIZE__: type = weak, value = $0200;
66
__STARTADDRESS__: type = export, value = %S;
7+
__STACKSTART__: type = weak, value = $8000;
78
}
89
MEMORY {
910
ZP: file = "", define = yes, start = $0082, size = $007E;
@@ -24,6 +25,7 @@ SEGMENTS {
2425
CODE: load = MAIN, type = rw, define = yes;
2526
RODATA: load = MAIN, type = ro optional = yes;
2627
DATA: load = MAIN, type = rw optional = yes;
28+
STARTUP: load = MAIN, type = ro, optional = yes;
2729

2830
BSS: load = MAIN, type = bss, define = yes, optional = yes;
2931
BUS: load = BUS, type = rw, define = yes, optional = yes;

testing/bdd-testing/macros/atari.macro

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,27 @@ Given atari-fn-nw application test setup
1212
And I start compiling for none in "build/tests" with config "features/test-setup/inc/fn-nw-app.cfg"
1313
# These must come after the "start compiling"
1414
And I add compiler option "--asm-include-dir features/atari/inc"
15-
And I add compiler option "--asm-include-dir ../../atari/inc"
15+
And I add compiler option "--asm-include-dir ../../atari/src/inc"
1616
And I add compiler option "--asm-include-dir ../../common/inc"
17+
And I add compiler option "--include-dir ../../"
18+
And I add compiler option "--include-dir features/atari/inc"
19+
And I add compiler option "--include-dir ../../atari/src/inc"
20+
And I add compiler option "--include-dir ../../common/inc"
1721

1822
# Simple test that does no init, sets up minimal xex for loading and testing
1923
# feature calls function directly
2024
Given atari-fn-nw simple test setup
2125
Given common atari-fn-nw test setup
2226
And I start compiling for none in "build/tests" with config "features/test-setup/inc/fn-nw-direct.cfg"
2327
# These must come after the "start compiling"
28+
And I add compiler option "--asm-include-dir ../../"
2429
And I add compiler option "--asm-include-dir features/atari/inc"
25-
And I add compiler option "--asm-include-dir ../../atari/inc"
30+
And I add compiler option "--asm-include-dir ../../atari/src/inc"
2631
And I add compiler option "--asm-include-dir ../../common/inc"
32+
And I add compiler option "--include-dir ../../"
33+
And I add compiler option "--include-dir features/atari/inc"
34+
And I add compiler option "--include-dir ../../atari/src/inc"
35+
And I add compiler option "--include-dir ../../common/inc"
2736

2837
Given I add common atari-io files
2938
# The test implementation of BUS

0 commit comments

Comments
 (0)