aboutsummaryrefslogtreecommitdiffstats
path: root/src/programs.asm
diff options
context:
space:
mode:
authoruser <user@clank>2026-09-24 23:08:46 +0200
committeruser <user@clank>2026-09-24 23:08:46 +0200
commit4bfe20f88b93645f9a277c9903620d75f0ddc179 (patch)
treeba8af4184f10645fecc59adc9b0b0454658ad278 /src/programs.asm
parentterm: ESC[2J, so clear(1) can actually clear (diff)
downloadgbos-4bfe20f88b93645f9a277c9903620d75f0ddc179.tar.gz
gbos-4bfe20f88b93645f9a277c9903620d75f0ddc179.tar.xz
gbos-4bfe20f88b93645f9a277c9903620d75f0ddc179.zip
usr: sort, cmp, strings, du, time
- sort [-r] [-n]: everything in RAM, which bounds it - a task has 8 KiB and a file caps at 3 KiB, so 96 lines of 2400 bytes with room for the stack. Insertion sort over an index; at that size the simple thing is fast and costs far less ROM. `uniq -c f | sort -n -r` finally works. NB the key needs a scratch SLOT of its own: gt() compares table entries, so reusing slot i as scratch overwrites the entries being shifted into it. - cmp: reports the first differing byte, silent when the files match. There was no way to check a copy on the machine - you had to haul both to a host. - strings [-n N]: pairs with xxd now that /bin/<prog> is readable. It finds "gbos sm83 (Game Boy Color)" inside /bin/uname. - du [dir]: 256-byte blocks, the unit df and the filesystem use. Bytes overflow - /bin alone is 52 x 16 KiB, which wrapped a 16-bit counter and printed 32768. Recurses by re-opendir'ing, since the kernel keeps only one "directory being listed" cursor. - time CMD: 1/64 s resolution from the tick counter. It rebuilds the child's command line at $A000 - which is its own argument area, so everything is copied to the stack first.
Diffstat (limited to '')
-rw-r--r--src/programs.asm63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/programs.asm b/src/programs.asm
index e9e1be9..96229f4 100644
--- a/src/programs.asm
+++ b/src/programs.asm
@@ -196,6 +196,33 @@ ProgCut:
SECTION "prog_uniq", ROMX[$4000], BANK[53]
ProgUniq:
INCBIN "build/usr/uniq.bin"
+SECTION "prog_sort", ROMX[$4000], BANK[54]
+ProgSort:
+ INCBIN "build/usr/sort.bin"
+SECTION "prog_cmp", ROMX[$4000], BANK[55]
+ProgCmp:
+ INCBIN "build/usr/cmp.bin"
+SECTION "prog_strings", ROMX[$4000], BANK[56]
+ProgStrings:
+ INCBIN "build/usr/strings.bin"
+SECTION "prog_du", ROMX[$4000], BANK[57]
+ProgDu:
+ INCBIN "build/usr/du.bin"
+SECTION "prog_time", ROMX[$4000], BANK[58]
+ProgTime:
+ INCBIN "build/usr/time.bin"
+SECTION "prog_clear", ROMX[$4000], BANK[59]
+ProgClear:
+ INCBIN "build/usr/clear.bin"
+SECTION "prog_ln", ROMX[$4000], BANK[60]
+ProgLn:
+ INCBIN "build/usr/ln.bin"
+SECTION "prog_ntpdate", ROMX[$4000], BANK[61]
+ProgNtpdate:
+ INCBIN "build/usr/ntpdate.bin"
+SECTION "prog_date", ROMX[$4000], BANK[62]
+ProgDate:
+ INCBIN "build/usr/date.bin"
; -----------------------------------------------------------------------------
; PROG_SH (bank 3) - the shell, now written in C (usr/sh.c): parses >/</| and
@@ -342,6 +369,24 @@ ProgramTable::
dw ProgCut
db LOW(BANK(ProgUniq)), HIGH(BANK(ProgUniq))
dw ProgUniq
+ db LOW(BANK(ProgSort)), HIGH(BANK(ProgSort))
+ dw ProgSort
+ db LOW(BANK(ProgCmp)), HIGH(BANK(ProgCmp))
+ dw ProgCmp
+ db LOW(BANK(ProgStrings)), HIGH(BANK(ProgStrings))
+ dw ProgStrings
+ db LOW(BANK(ProgDu)), HIGH(BANK(ProgDu))
+ dw ProgDu
+ db LOW(BANK(ProgTime)), HIGH(BANK(ProgTime))
+ dw ProgTime
+ db LOW(BANK(ProgClear)), HIGH(BANK(ProgClear))
+ dw ProgClear
+ db LOW(BANK(ProgLn)), HIGH(BANK(ProgLn))
+ dw ProgLn
+ db LOW(BANK(ProgNtpdate)), HIGH(BANK(ProgNtpdate))
+ dw ProgNtpdate
+ db LOW(BANK(ProgDate)), HIGH(BANK(ProgDate))
+ dw ProgDate
ProgramTableEnd::
; -----------------------------------------------------------------------------
@@ -453,4 +498,22 @@ NameTable::
db PROG_CUT
db "uniq", 0
db PROG_UNIQ
+ db "sort", 0
+ db PROG_SORT
+ db "cmp", 0
+ db PROG_CMP
+ db "strings", 0
+ db PROG_STRINGS
+ db "du", 0
+ db PROG_DU
+ db "time", 0
+ db PROG_TIME
+ db "clear", 0
+ db PROG_CLEAR
+ db "ln", 0
+ db PROG_LN
+ db "ntpdate", 0
+ db PROG_NTPDATE
+ db "date", 0
+ db PROG_DATE
db 0