diff options
| author | B. Watson <urchlay@slackware.uk> | 2026-04-25 03:34:30 -0400 |
|---|---|---|
| committer | B. Watson <urchlay@slackware.uk> | 2026-04-25 03:34:30 -0400 |
| commit | c93e82fa285edf0d5ed2447e0b32b9f6ce17f49e (patch) | |
| tree | 9d4e7d80c17727750b0afe790652f14d0e16e354 /src | |
| parent | a50e1e52fd7c62fda2d1804a3c7a860e47bf74a4 (diff) | |
| download | fujinet-chat-c93e82fa285edf0d5ed2447e0b32b9f6ce17f49e.tar.gz | |
Fix steal_line(), no more crashes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/memclear.s | 2 | ||||
| -rw-r--r-- | src/pool.c | 34 |
2 files changed, 26 insertions, 10 deletions
diff --git a/src/memclear.s b/src/memclear.s index 1bd7e89..7a814cc 100644 --- a/src/memclear.s +++ b/src/memclear.s @@ -1,6 +1,8 @@ ; void memclear(const char *addr, unsigned int len) ; really does have to be an int for the length. + ; NOTE: length must be <= $7fff. not much of a problem, do you + ; ever need to zero out >= 32K of RAM at once? ; this is basically bzero(), but optimized for size, not speed. ; bzero() is around 2.3x as fast as this, but it's 3.3x as @@ -1,6 +1,7 @@ #include <atari.h> -#include "pool.h" -#include "addrs.h" +#include "screen.h" +// #include "pool.h" +// #include "addrs.h" #include "memclear.h" screen_t screens[MAX_SCREENS]; @@ -19,6 +20,11 @@ void init_pools(void) { if((u16)OS.memlo < SCR_LOW_END - sizeof(pool_t)) add_to_pool(0, (u16)OS.memlo, SCR_LOW_END); + + /* TODO: for pool 0, add whatever RAM exists between the end + of the BSS and $3600. also, under-OS XL RAM if enabled. */ + + /* TODO: support pools 1 and up for other banks! */ } void add_to_pool(char p, u16 start, u16 end) { @@ -55,7 +61,7 @@ char get_smallest_pool(void) { } line_t *steal_line(char s) { - line_t *l; + line_t *l, *last_l; char candidate, victim; u16 maxheight; @@ -66,6 +72,9 @@ line_t *steal_line(char s) { /* only steal from the same pool */ if(screens[candidate].pool != screens[s].pool) continue; + /* only steal from screens that exist */ + if(screens[candidate].status == SCR_UNUSED) + continue; /* steal from the screen with the most lines */ if(screens[candidate].line_count > maxheight) { maxheight = screens[candidate].line_count; @@ -74,15 +83,20 @@ line_t *steal_line(char s) { } /* find 2nd to last line of the victim screen */ - for(l = screens[victim].line_list; l->next->next != (line_t *)END_MARKER; l = l->next) - ; + l = screens[victim].line_list; + while(l->next != (line_t *)END_MARKER) { + last_l = l; + l = l->next; + } + /* at the end of the loop, l is the last line before the + end marker (the line we're stealing), and last_l is the line + before that. */ - /* prepend last line to screen s */ - l->next->next = screens[s].line_list; - screens[s].line_list = l->next; - memclear(screens[s].line_list->data, LINE_LEN); + /* make old_l the last line */ + last_l->next = (line_t *)END_MARKER; - l->next = (line_t *)END_MARKER; + /* clear out old screen data, then return the stolen line */ + memclear(l->data, LINE_LEN); return l; } |
