Skip to content

Commit 9f4d464

Browse files
authored
Merge pull request #4 from nihirash/file_api_fixing
File API fixing
2 parents 40f4c3f + 20456d4 commit 9f4d464

File tree

12 files changed

+149
-68
lines changed

12 files changed

+149
-68
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ jobs:
2828
prerelease: false
2929
release_name: CI build ${{ steps.version.outputs.version }}
3030
tag_name: ${{ steps.version.outputs.version }}
31+
body_path: CHANGELOG.md
3132
env:
3233
GITHUB_TOKEN: ${{ github.token }}
3334

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Changelog
2+
3+
## 2024.04.02
4+
5+
* File leak fixed
6+
7+
* Compute file size call implemented
8+
9+
* More correct error handling(allows Turbo Pascal execution)
10+
11+
## 2024.04.27
12+
13+
* First public build(system version call returns version 2.9)
14+
15+
* Basic console and file operations implemented(Mike's Enhanced Small C Compiler works, Microsoft Basic, Tasty Basic, Zork and many other utils working)

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ $(BINARY): $(EDOS) $(SOURCES) .version
99
(cd src && ez80asm -i zinc.asm ../$(BINARY))
1010

1111
$(EDOS): $(SOURCES)
12-
(cd src/edos && ez80asm -i edos.asm)
12+
(cd src/edos && ez80asm -i -l edos.asm)
1313

1414
.version:
1515
date '+%Y.%m.%d' >.version

src/config.asm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ZINC_EXIT: equ ZINC_BASE + 4
2222
;; By changing this value you can change used memory page for CP/M application
2323
EDOS_BASE: equ $A0000
2424
;; Origin address for EDOS(BDOS equivalent in ZINC)
25-
EDOS_ORG: equ EDOS_BASE + $f000
25+
EDOS_ORG: equ EDOS_BASE + $F500
2626
;; TPA area starts here
2727
EDOS_TPA: equ EDOS_BASE + $100
2828

src/edos/buffers.asm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ ffs_attr: ds 1
3434
ffs_name: ds 13
3535
ffs_lfn: ds 256
3636

37-
ds 16
38-
bios_stack:
3937
ds 32
38+
bios_stack:
39+
40+
ds 64
4041
stack:

src/edos/core.asm

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,12 @@ LF: equ $0A
2020
CR: equ $0D
2121
2222
include "mos.asm"
23-
jp entrypoint
23+
entrypoint:
24+
jp edos
2425
jp init
2526

2627
;; "BDOS" entrypoint - routing functions
27-
entrypoint:
28+
edos:
2829
ld a, c
2930
ld (fun), a
3031
cp NFUNC
@@ -34,6 +35,8 @@ entrypoint:
3435
ld (user_stk), sp
3536
ld sp, stack
3637
ei
38+
push ix
39+
push iy
3740

3841
ld hl, bdos_return
3942
push hl
@@ -58,6 +61,8 @@ entrypoint:
5861

5962
bdos_return:
6063
di
64+
pop iy
65+
pop ix
6166
ld sp, (user_stk)
6267
ei
6368
ret
@@ -66,9 +71,11 @@ fun_table:
6671
dw bye ; 00 Reset
6772
dw console_in ; 01 Console in
6873
dw console_out ; 02 Console out
74+
6975
dw trace ; 03 Aux read
7076
dw trace ; 04 Aux write
7177
dw do_nothing ; 05 Printer write
78+
7279
dw raw_io ; 06 Raw IO
7380
dw get_io_byte ; 07 Get IO Byte
7481
dw set_io_byte ; 08 Set IO Byte
@@ -98,13 +105,13 @@ fun_table:
98105
dw do_nothing ; 32 Get user area
99106
dw fread_rnd ; 33 Random read
100107
dw fwrite_rnd ; 34 Random write
101-
dw trace ; 35 Compute file size
108+
dw calc_size ; 35 Compute file size
102109
dw trace ; 36 Update random access pointer
103110
dw do_nothing ; 37 reset selected disks
104-
dw do_nothing ; 38 not used in CP/M 2.2
105-
dw do_nothing ; 39 not used in CP/M 2.2
111+
dw trace ; 38 not used in CP/M 2.2
112+
dw trace ; 39 not used in CP/M 2.2
106113
dw trace ; 40 fill random access block with zeros
107-
dw do_nothing ; 41
114+
dw trace ; 41
108115

109116
bye:
110117
jp.lil ZINC_EXIT
@@ -135,5 +142,6 @@ dma_ptr: dl EDOS_BASE + $80
135142
user_stk: dw $00
136143

137144
align $100
145+
138146
include "ebios/index.asm"
139147
include "buffers.asm"

src/edos/disk.asm

Lines changed: 89 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
get_drives:
77
ld hl,1
8+
xor a
89
ret
910

1011
get_drive:
@@ -83,6 +84,9 @@ scan_ok:
8384
ld hl, ffs_lfn
8485
call ascciz_to_fcb
8586

87+
xor a
88+
ret
89+
8690
;; Calculation file lenght
8791
;; Routine works not very correct, but many CP/M emulators skip this step
8892
;; Honestly, not most necessary part of this project :-)
@@ -120,7 +124,7 @@ scan_ok:
120124
ret
121125

122126
mask:
123-
defb 12, '?'
127+
db "????????????"
124128

125129
init_dir:
126130
ld hl, path_buffer
@@ -139,16 +143,9 @@ init_dir:
139143
MOSCALL MOS_OPENDIR
140144
ret
141145

142-
fopen:
143-
ld hl, (args)
144-
ld de, FCB_FP
145-
add hl, de
146-
ld a, (hl)
147-
148-
or a
149-
jr z, @skip
150-
call fclose
151-
@skip:
146+
_open:
147+
ld c, 0
148+
MOSCALL MOS_FCLOSE
152149

153150
ld hl, (args)
154151
call fcb_to_asciiz_name
@@ -157,18 +154,22 @@ fopen:
157154
ld c, FA_READ + FA_WRITE
158155
MOSCALL MOS_FOPEN
159156

160-
or a
161-
jr z, @err
162-
163-
ld hl, (args)
164-
ld de, FCB_FP
157+
;; Store file pointer
158+
ld de, (args)
159+
ld hl, FCB_FP
165160
add hl, de
166161
ld (hl), a
162+
ld c, a
167163

168-
xor a
169164
ret
170-
@err:
171-
ld a, #ff
165+
166+
fopen:
167+
call _open
168+
169+
or a
170+
jp z, err
171+
172+
xor a
172173
ret
173174

174175
frename:
@@ -196,39 +197,22 @@ frename:
196197

197198
fcreate:
198199
ld hl, (args)
199-
200200
call fcb_to_asciiz_name
201-
201+
202202
ld hl, dos_name
203203
ld c, FA_READ + FA_WRITE + FA_CREATE
204204
MOSCALL MOS_FOPEN
205205

206206
or a
207-
jr z, @err
208-
ld hl, (args)
209-
ld de, FCB_FP
210-
add hl, de
211-
ld (hl), a
207+
jp z, err
212208

213209
xor a
214210
ret
215-
@err:
216-
ld a, #ff
217-
ret
218211

212+
;; Not it's just dummy implementation - all files will be closed on any file operations
213+
;; And exit from CP/M emulator
219214
fclose:
220-
ld de, (args)
221-
ld hl, FCB_FP
222-
add hl, de
223-
ld a, (hl)
224-
or a
225-
ret z
226-
227-
ld c, a
228-
MOSCALL MOS_FCLOSE
229-
230215
xor a
231-
ld (hl), a
232216
ret
233217

234218
fdelete:
@@ -240,24 +224,38 @@ fdelete:
240224

241225
;; Random write
242226
fwrite_rnd:
227+
call _open
228+
or a
229+
jr z, err
243230
call set_rnd_offset
244231
jr do_write
245232

246233
;; Sequental write
247234
fwrite:
235+
call _open
236+
or a
237+
jr z, err
238+
248239
ld hl, FCB_FP
249-
add hl, de
250-
ld a, (hl)
251-
ld c, a
240+
ld (hl), a
252241

242+
call fcb_calc_offset
253243
do_write:
244+
MOSCALL MOS_FSEEK
245+
254246
ld.lil hl, (dma_ptr)
255247
ld de, $80
256248
MOSCALL MOS_FWRITE
257-
call fcb_next_record
258249

250+
call fcb_next_record
251+
252+
ld hl, 0
253+
ld bc, 0
259254
xor a
260255
ret
256+
err:
257+
ld a, #ff
258+
ret
261259

262260
clean_dma:
263261
ld de, (dma_ptr)
@@ -291,11 +289,15 @@ set_rnd_offset:
291289
add.lil hl, hl ; *32
292290
add.lil hl, hl ; *64
293291
add.lil hl, hl ; *128
294-
ld e, 0
292+
ld de, 0
295293
ret
296294

297295
;; Random read
298296
fread_rnd:
297+
call _open
298+
or a
299+
jp z, err
300+
299301
call clean_dma
300302
call set_rnd_offset
301303

@@ -305,26 +307,61 @@ fread_rnd:
305307
fread:
306308
call clean_dma
307309
308-
ld de, (args)
309-
ld hl, FCB_FP
310-
add hl, de
311-
ld a, (hl)
312-
ld c, a
310+
call _open
311+
or a
312+
jp z, err
313313

314314
call fcb_calc_offset
315315
read_offset:
316316
MOSCALL MOS_FSEEK
317317

318318
ld.lil hl, (dma_ptr)
319-
ld de, 128
319+
ld de, $80
320320
MOSCALL MOS_FREAD
321321

322322
ld a, d
323323
or e
324-
ld a, $ff
324+
ld a, $01
325325
ret z
326326

327327
call fcb_next_record
328+
328329
xor a
329330
ret
330331

332+
;; DE - FCB
333+
calc_size:
334+
ex de, hl
335+
call fcb_to_asciiz_name
336+
337+
ld.lil de, dos_name
338+
ld.lil hl, ffs_file_struct
339+
MOSCALL MOS_FSTAT
340+
or a
341+
jr nz, @nope
342+
343+
ld.lil hl, (ffs_size)
344+
add.lil hl, hl
345+
346+
ld a, l
347+
and $7f
348+
jr z, @skip
349+
350+
ld de, $100
351+
add.lil hl, de
352+
@skip:
353+
ld.lil (@buff), hl
354+
355+
ld hl, (args)
356+
ld de, FCB_RN
357+
add hl, de
358+
359+
ld de, (@buff + 1)
360+
ld (hl), de
361+
xor a
362+
ret
363+
@nope:
364+
ld a, $ff
365+
ret
366+
@buff:
367+
dl 0

src/edos/ebios/index.asm

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ CONOUT: JP bios_out
1717

1818
LIST: JP nothing
1919
PUNCH: JP nothing
20-
READER: JP nothing
20+
READER: JP reader
2121

2222
HOME: JP nothing
2323
SELDSK: JP bios_seldsk
@@ -33,6 +33,10 @@ nothing:
3333
ld a, $ff
3434
ret
3535

36+
reader:
37+
ld a, 26
38+
ret
39+
3640
direct:
3741
ld hl, @msg
3842
ld bc, 0

0 commit comments

Comments
 (0)