Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fileioc: improve garbage collect handling #270

Merged
merged 15 commits into from
Aug 10, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 92 additions & 4 deletions src/fileioc/fileioc.asm
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,13 @@ library 'FILEIOC', 5
;-------------------------------------------------------------------------------
export ti_ArchiveHasRoom

;-------------------------------------------------------------------------------
; v6 functions
;-------------------------------------------------------------------------------
export ti_SetPostGCHandler



;-------------------------------------------------------------------------------
vat_ptr0 := $d0244e
vat_ptr1 := $d0257b
Expand Down Expand Up @@ -461,7 +468,7 @@ ti_SetArchiveStatus:
.set_archived:
push bc
pop af
call z, _Arc_Unarc
call z, util_Arc_Unarc
jr .relocate_var
.set_not_archived:
push bc
Expand Down Expand Up @@ -1206,7 +1213,7 @@ ti_Rename:
inc de
call _Mov8b
call _PushOP1 ; save old name
ld hl, _Arc_Unarc
ld hl, util_Arc_Unarc
ld (.smc_archive), hl
pop hl ; new name
ld de, OP1 + 1
Expand All @@ -1224,7 +1231,7 @@ ti_Rename:
ld hl, $f8 ; $f8 = ret
ld (.smc_archive), hl
call _PushOP1
call _Arc_Unarc
call util_Arc_Unarc
call _PopOP1
jr .locate_program
.in_archive:
Expand Down Expand Up @@ -1257,7 +1264,7 @@ ti_Rename:
ldir
.is_zero:
call _PopOP1
call _Arc_Unarc
call util_Arc_Unarc
.smc_archive := $-3
call _PopOP1
call _ChkFindSym
Expand Down Expand Up @@ -1393,6 +1400,26 @@ ti_ArchiveHasRoom:
dec a
ret

;-------------------------------------------------------------------------------
ti_SetPostGCHandler:
;Set handler for setting up the screen after a garbage collect
; args:
; sp + 3 : pointer to handler. Set to 0 to use default handler (xlibc palette)
beckadamtheinventor marked this conversation as resolved.
Show resolved Hide resolved
; return:
; None
pop de
ex (sp),hl
push de
add hl,de
or a,a
sbc hl,de
jr nz,.notdefault
ld hl,util_gfx_restore_default_handler
.notdefault:
ld (util_gfx_restore_handler),hl
ex hl,de
jp (hl)

;-------------------------------------------------------------------------------
; internal library routines
;-------------------------------------------------------------------------------
Expand Down Expand Up @@ -1573,6 +1600,67 @@ util_set_offset:
ld (hl), bc
ret

util_Arc_Unarc: ;properly handle garbage collects :P
call _ChkFindSym
push hl
call _ChkInRAM
pop hl
jr nz,.arc_unarc ;if the file is already in archive, we won't trigger a gc
call _LoadDEInd_s
ld hl,12
add hl,de
call _FindFreeArcSpot ;check if we will trigger a gc
jr nz,.arc_unarc ;gc will not be triggered
ld a,(mpLcdCtrl)
cp a,lcdBpp16
jr z,.arc_unarc ;already in OS 16bpp graphics mode
push af ;save lcd mode
call _ClrLCDFull
call _DrawStatusBar
ld a,lcdBpp16
ld (mpLcdCtrl),a
beckadamtheinventor marked this conversation as resolved.
Show resolved Hide resolved
call _Arc_Unarc
pop af ;restore lcd mode
ld (mpLcdCtrl),a
jp util_gfx_restore_default_handler
beckadamtheinventor marked this conversation as resolved.
Show resolved Hide resolved
util_gfx_restore_handler:=$-3
.arc_unarc:
jp _Arc_Unarc


util_gfx_restore_default_handler:
call _RunIndicOff
di ; turn off indicator
ld hl,$D40000
ld (hl),l
ld bc,320*240
push hl
pop de
inc de
ldir
.setup:
ld a,lcdBpp8
ld (mpLcdCtrl),a ; operate in 8bpp
ld hl,mpLcdPalette
ld b,0
.loop:
ld d,b
ld a,b
and a,192
srl d
rra
ld e,a
ld a,31
and a,b
or a,e
ld (hl),a
inc hl
ld (hl),d
inc hl
inc b
jr nz,.loop
ret
beckadamtheinventor marked this conversation as resolved.
Show resolved Hide resolved

;-------------------------------------------------------------------------------
; Internal library data
;-------------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions src/fileioc/fileioc.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,14 @@ uint8_t ti_RclVar(const uint8_t var_type, const char *var_name, void **data_stru
*/
bool ti_ArchiveHasRoom(uint24_t num_bytes);


/**
* Set routine to run after a garbage collect.
* @param routine Routine to run following a garbage collect. If this is 0, the default handler will be used.
beckadamtheinventor marked this conversation as resolved.
Show resolved Hide resolved
* @note Useful for setting up the graphics palette.
* */
void ti_SetPostGCHandler((void)(*routine)(void));

/**
* Allocates space for a real variable
* @returns Pointer to variable
Expand Down