-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathopen.asm
153 lines (142 loc) · 1.81 KB
/
open.asm
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
; open esxDOS file stream
include "lib/sysvars.asm"
include "lib/hooks.asm"
include "lib/zxrom.asm"
include "lib/empty-usage.asm"
arg_e: equ 3400h
execute:ld a,(hl)
cp "#"
jr nz,nohash
inc hl
nohash: call numarg
jr c,usage
jr z,usage
ld a,e
ld (s_num),a
ld de,f_name
call strarg
jr nz,usage
ld hl,serv
ld de,chinfo
push hl
push de
ld b,serv_l
openl: ld a,(de)
cp (hl)
jr nz,setserv
inc hl
inc de
djnz openl
pop de
pop hl
jr doopen
setserv:ld hl,(chans)
bit 7,h
jr nz,rep_o ; ZX85 coroutines cannot do this
ld bc,serv_l
push bc
dec hl ; move CHANS as well
rst 18h
defw make_room
pop bc
pop de
pop hl
push bc
ldir
pop bc
dec hl
ld de,(chans)
dec de
lddr
doopen: ld b,09h
ld a,"*"
ld hl,f_name
rst 8
defb fopen
ret c
ld (fd),a
s_num: equ $ + 1
zxopen: ld a,0
rst 18h
defw str_data0
ld a,b
or c
jr z,open1
ex de,hl
ld hl,(chans)
add hl,bc
inc hl
inc hl
inc hl
ld a,(hl)
ex de,hl
cp "K"
jr z,open1
cp "S"
jr z,open1
cp "P"
jr z,open1
rep_o: rst 18h
defw report_o_2
open1: push hl
ld hl,(prog)
dec hl
ld bc,fch_e-fch
push bc
rst 18h
defw make_room
ld hl,fch_e - 1
pop bc
lddr
ld hl,(chans)
ex de,hl
and a
sbc hl,de
inc hl
inc hl
ex de,hl
pop hl
ld (hl),e
inc hl
ld (hl),d
and a
ret
include "lib/numarg.asm"
include "lib/strarg.asm"
include "lib/atob.asm"
include "lib/puts.asm"
serv: equ $
org chinfo
ld ix,(curchl)
ld a,(ix+5)
ld bc,1
ret
fin: call chinfo
ld ix,membot
rst 8
defb fread
dec c
ld a,(membot)
scf
ret z
or c
ret
fout: ld (membot),a
call chinfo
ld ix,membot
rst 8
defb fwrite
ret nc
rst 8
defb 12h
serv_l: equ $ - chinfo
org serv + serv_l
usaget: defb "Usage: open [#]stream filename", 0dh, 00h
fch: defw fout
defw fin
defb "F"
fd: defb 0
defs 3
defw fch_e - fch
fch_e: equ $
f_name: include "lib/align512.asm"