Skip to content

Commit 914ac87

Browse files
Fix 2048 bug; optimize read/write routines
1 parent 55cd67b commit 914ac87

File tree

4 files changed

+113
-75
lines changed

4 files changed

+113
-75
lines changed

CEdev/include/lib/ce/fileioc.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ size_t ti_Write(const void *data, size_t size, size_t count, const ti_var_t slot
128128
* number of data chunks to read from the variable slot
129129
* slot:
130130
* varaible slot to read from
131-
* Returns the number of chuncks read (should be equal to count)
131+
* Returns the number of chunks read (should be equal to count)
132132
*/
133133
size_t ti_Read(const void *data, size_t size, size_t count, const ti_var_t slot);
134134

@@ -179,8 +179,8 @@ uint16_t ti_Tell(const ti_var_t slot);
179179
uint16_t ti_GetSize(const ti_var_t slot);
180180

181181
/**
182-
* Resizes the slot to the new size; note that the current file
183-
* offset is set to the beginning of the file
182+
* Resizes the file slot
183+
* The file offset is set to the beginning of the file
184184
*/
185185
int ti_Resize(size_t new_size, const ti_var_t slot);
186186

@@ -192,7 +192,6 @@ int ti_IsArchived(const ti_var_t slot);
192192
/**
193193
* Sets the varaible into either the archive or RAM
194194
* Returns zero if the operation fails if not enough memory or some other error
195-
* NOTE: This routine also closes the file handle. You must reopen the file afterwords.
196195
*/
197196
int ti_SetArchiveStatus(bool archived, const ti_var_t slot);
198197

CEdev/include/lib/ce/keypadc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ void kb_Reset(void);
163163
* Keyboard group 1
164164
*/
165165
#define kb_KeyGraph (kb_lkey_t)(1 << 8 | 1<<0)
166-
#define key_trace (kb_lkey_t)(1 << 8 | 1<<1)
166+
#define kb_KeyTrace (kb_lkey_t)(1 << 8 | 1<<1)
167167
#define kb_KeyZoom (kb_lkey_t)(1 << 8 | 1<<2)
168168
#define kb_KeyWindow (kb_lkey_t)(1 << 8 | 1<<3)
169169
#define kb_KeyYequ (kb_lkey_t)(1 << 8 | 1<<4)
@@ -214,7 +214,7 @@ void kb_Reset(void);
214214
#define kb_Key6 (kb_lkey_t)(5 << 8 | 1<<2)
215215
#define kb_Key9 (kb_lkey_t)(5 << 8 | 1<<3)
216216
#define kb_KeyRParen (kb_lkey_t)(5 << 8 | 1<<4)
217-
#define key_tan (kb_lkey_t)(5 << 8 | 1<<5)
217+
#define kb_KeyTan (kb_lkey_t)(5 << 8 | 1<<5)
218218
#define kb_KeyVars (kb_lkey_t)(5 << 8 | 1<<6)
219219

220220
/**

CEdev/include/lib/ce/tice.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ void os_ResetFlagBits(int16_t offset_pattern);
376376
#define timer_1_MatchValue_2 (*(uint32_t *)0xF2000C)
377377
#define timer_2_MatchValue_1 (*(uint32_t *)0xF20018)
378378
#define timer_2_MatchValue_2 (*(uint32_t *)0xF2001C)
379-
#define timer_Control (*(uint16_t *)0xF20030)
379+
#define timer_Control (*(uint32_t *)0xF20030)
380380
#define timer_IntMask (*(uint16_t *)0xF20038)
381381
#define timer_IntStatus (*(volatile uint16_t *)0xF20034)
382382

CEdev/lib/src/libraries/fileio_src/v2/fileio_lib.asm

Lines changed: 107 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ _Open:
178178
; Slot number if no error
179179
ld a,appVarObj
180180
_: ld (varTypeOpen),a \.r
181+
ld (op1),a
181182
push ix
182183
ld ix,0
183184
add ix,sp
@@ -211,17 +212,18 @@ _: ld (varTypeOpen),a \.r
211212
_: ld (currSlot),a
212213
ld hl,(ix+6)
213214
ld de,op1+1
214-
ld bc,9
215+
ld bc,8
215216
ldir
216217
xor a,a
217218
ld (de),a
218219
ld hl,(ix+9)
219220
ld a,(hl)
220221
cp a,'w'
222+
ld iy,flags
221223
jr nz,nooverwite
222224
call _PushOP1
223225
call _ChkFindSym
224-
call nc,_delvararc
226+
call nc,_DelVarArc
225227
call _PopOP1
226228
nooverwite:
227229
ld hl,(ix+9)
@@ -241,8 +243,6 @@ archivevar:
241243
call _ChkFindSym
242244
call _ChkInRam
243245
jr z,+_
244-
inc de
245-
inc de
246246
or a,a
247247
sbc hl,hl
248248
ex de,hl
@@ -251,8 +251,10 @@ archivevar:
251251
ld d,(hl)
252252
ex de,hl
253253
call _EnoughMem
254-
jp c,_ReturnNULL_PopIX \.r
254+
push af
255255
call _PopOP1
256+
pop af
257+
jp c,_ReturnNULL_PopIX \.r
256258
call _PushOP1
257259
call _Arc_Unarc
258260
call _PopOP1
@@ -277,9 +279,8 @@ _: call _ChkFindSym
277279
ld de,0
278280
ld e,a
279281
add hl,de
280-
ex (sp),hl
281-
add hl,de
282-
pop de
282+
ex de,hl
283+
pop hl
283284
jr _SavePtrs_ASM
284285
_: ld hl,(ix+9)
285286
ld a,(hl)
@@ -289,6 +290,7 @@ _: ld hl,(ix+9)
289290
sbc hl,hl
290291
varTypeOpen =$+1
291292
ld a,0
293+
ld iy,flags
292294
call _CreateVar
293295
_SavePtrs_ASM:
294296
push hl
@@ -309,7 +311,7 @@ _SavePtrs_ASM:
309311
ld a,(currSlot)
310312
ld l,a
311313
ret
312-
314+
313315
;-------------------------------------------------------------------------------
314316
_SetArchiveStatus:
315317
; Sets the archive status of a slot
@@ -318,8 +320,6 @@ _SetArchiveStatus:
318320
; arg1 : Slot number
319321
; Returns:
320322
; None
321-
ld a,appVarObj
322-
ld (varTypeOpenArc),a \.r
323323
pop hl
324324
pop de
325325
pop bc
@@ -332,10 +332,12 @@ _SetArchiveStatus:
332332
push af
333333
call _GetSlotVATPtr_ASM \.r
334334
ld hl,(hl)
335+
ld a,(hl)
336+
ld (OP1),a
335337
ld bc,-6
336338
add hl,bc
337339
ld b,(hl)
338-
ld de,op1+1
340+
ld de,OP1+1
339341
dec hl
340342
_: ld a,(hl)
341343
ld (de),a
@@ -344,28 +346,34 @@ _: ld a,(hl)
344346
djnz -_
345347
xor a,a
346348
ld (de),a
347-
varTypeOpenArc =$+1
348-
ld a,0
349-
ld (OP1),a
349+
call _PushOP1
350+
ld iy,flags
350351
call _ChkFindSym
351352
call _ChkInRam
352353
push af
353-
ld bc,0
354-
call _GetSlotVATPtr_ASM \.r
355-
ld (hl),bc
356354
pop bc
357355
pop af
358356
or a,a
359357
jr z,SetNotArchived
360358
SetArchived:
361359
push bc
362360
pop af
363-
jp z,_Arc_Unarc
364-
ret
361+
call z,_Arc_Unarc
362+
jr RelocateVar
365363
SetNotArchived:
366364
push bc
367365
pop af
368-
jp nz,_Arc_Unarc
366+
call nz,_Arc_Unarc
367+
RelocateVar:
368+
call _PopOP1
369+
call _ChkFindSym
370+
jp c,_ReturnNEG1L \.r
371+
push hl
372+
call _GetSlotVATPtr_ASM \.r
373+
pop bc
374+
ld (hl),bc
375+
call _GetSlotDataPtr_ASM \.r
376+
ld (hl),de
369377
ret
370378
371379
;-------------------------------------------------------------------------------
@@ -382,34 +390,62 @@ _Write:
382390
add iy,sp
383391
ld c,(iy+12)
384392
call _CheckIfSlotOpen \.r
385-
jp z,_ReturnNULL \.r
393+
jr z,_ReturnNULL_Close
394+
call _CheckInRAM_ASM \.r
395+
jr z,_ReturnNULL_Close
386396
ld bc,(iy+6)
387397
ld hl,(iy+9)
388-
call __smulu ; hl*bc
398+
call __smulu
399+
ld (CopySize_SMC),hl \.r
400+
push hl
401+
call _GetSlotOffset_ASM \.r
402+
pop hl
403+
add hl,bc
404+
push hl
405+
call _GetSlotSize_ASM \.r ; bc = size of file
406+
pop hl ; hl = needed size
407+
or a,a
408+
inc bc
409+
sbc hl,bc
410+
jr c,NoCoreNeeded
411+
inc hl
412+
ld (resizeBytes),hl
413+
call AddMemoryToVar \.r
414+
or a,a
415+
jr z,_ReturnNULL_Close
416+
NoCoreNeeded:
417+
call _GetSlotCurrDataPtr_ASM \.r
389418
ex de,hl
390-
call _CheckInRAM_ASM \.r
391-
jp c,_ReturnNULL_PopIX \.r
392419
ld hl,(iy+3)
420+
CopySize_SMC =$+1
393421
ld bc,0
394-
_: ld a,(hl)
395-
push hl
396-
push de
397422
push bc
398-
ld (charIn),a
399-
call _PutChar_ASM \.r
400-
rl h
401-
pop bc
402-
pop de
423+
ldir
424+
call _GetSlotOffset_ASM \.r
403425
pop hl
404-
jr c,_s ; was there a write error?
426+
add hl,bc
427+
ex de,hl
428+
call _GetSlotOffsetPtr_ASM \.r
429+
ld (hl),de
430+
ld hl,(iy+9)
431+
ret
432+
433+
_ReturnNULL_Close:
434+
xor a,a
435+
sbc hl,hl
436+
ret
437+
438+
_GetSlotCurrDataPtr_ASM:
439+
call _GetSlotDataPtr_ASM \.r
440+
ld hl,(hl)
441+
push hl
442+
call _GetSlotOffset_ASM \.r
443+
pop hl
444+
add hl,bc
405445
inc hl
406-
inc bc
407-
dec de
408-
ld a,e
409-
or a,d
410-
jr nz,-_
411-
jr _s ; jump to copy computations
412-
446+
inc hl
447+
ret
448+
413449
;-------------------------------------------------------------------------------
414450
_Read:
415451
; Performs an fread to an AppVar
@@ -424,36 +460,25 @@ _Read:
424460
add iy,sp
425461
ld c,(iy+12)
426462
call _CheckIfSlotOpen \.r
427-
jp z,_ReturnNULL \.r
463+
jr z,_ReturnNULL_Close
428464
ld bc,(iy+6)
429465
ld hl,(iy+9)
430-
call __smulu ; hl*bc
431-
ex de,hl
432-
ld hl,(iy+3)
433-
ld bc,0
434-
_: push hl
435-
push de
436-
push bc
437-
call _GetChar_ASM \.r
438-
rl h
439-
pop bc
440-
pop de
441-
pop hl
442-
jr c,_s
443-
ld (hl),a
444-
inc hl
445-
inc bc
446-
dec de
447-
ld a,e
448-
or a,d
449-
jr nz,-_
450-
_s: ld de,(iy+6)
451-
ex.s de,hl
452466
push hl
453-
ld l,c
454-
ld h,b
467+
call __smulu
468+
push hl
469+
call _GetSlotCurrDataPtr_ASM \.r
470+
ld de,(iy+3)
455471
pop bc
456-
jp __sdivu
472+
push bc
473+
ldir
474+
call _GetSlotOffset_ASM \.r
475+
pop hl
476+
add hl,bc
477+
ex de,hl
478+
call _GetSlotOffsetPtr_ASM \.r
479+
ld (hl),de
480+
pop hl
481+
ret
457482

458483
;-------------------------------------------------------------------------------
459484
_GetChar:
@@ -578,6 +603,8 @@ Increment:
578603
ex de,hl
579604
call AddMemoryToVar \.r
580605
pop bc
606+
or a,a
607+
jp z,_ReturnNEG1L \.r
581608
noIncrement:
582609
call _GetSlotDataPtr_ASM \.r
583610
ld hl,(hl)
@@ -631,6 +658,7 @@ _: pop de
631658
ld (OP1),a
632659
call _ChkFindSym
633660
jp c,_ReturnNULL \.r
661+
ld iy,flags
634662
call _DelVarArc
635663
scf
636664
sbc hl,hl
@@ -726,6 +754,12 @@ AddMemoryToVar:
726754
inc hl
727755
ex de,hl
728756
ld hl,(resizeBytes)
757+
push hl
758+
push de
759+
call _EnoughMem
760+
pop de
761+
pop hl
762+
jr c,_ReturnNULLC
729763
call _InsertMem
730764
pop hl
731765
ld hl,(hl)
@@ -767,8 +801,13 @@ SaveSize:
767801
ld (hl),e
768802
inc hl
769803
ld (hl),d ; write new size
804+
_ReturnNEG1C:
805+
ld a,255
770806
ret
771-
807+
_ReturnNULLC:
808+
xor a,a
809+
ret
810+
772811
_ReturnNULL_PopIX:
773812
pop ix
774813
_ReturnNULL:

0 commit comments

Comments
 (0)