From a9bcbc894ba1ebb9ac6bb203efb3d95567074f87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maja=20K=C4=85dzio=C5=82ka?= Date: Thu, 13 Apr 2023 19:11:31 +0200 Subject: [PATCH] Move >IN to 7d00, saving 5 bytes. --- README.md | 6 +++--- blocks/bootstrap.fth | 2 +- boot.s | 16 +++++++++------- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 578059f..238c601 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Due to space constraints, variables such as `STATE` or `BASE` couldn't be expose separate words. Depending on the variable, the address is either hardcoded or pushed onto the stack on boot: - - `>IN` is a word at `0xa02`. It stores the pointer to the first unparsed character + - `>IN` is a word at `0x7d00`. It stores the pointer to the first unparsed character of the null-terminated input buffer. - The stack on boot is `LATEST STATE BASE HERE #DISK` (with `#DISK` on top). - `STATE` has a non-standard format - it is a byte, where `0` means compiling, @@ -181,8 +181,8 @@ Git or GitHub's web interface. This disparity is handled by two Python scripts: ## Free bytes -At this moment, not counting the `55 AA` signature at the end, **450** bytes are used, -leaving 60 bytes for any potential improvements. +At this moment, not counting the `55 AA` signature at the end, **445** bytes are used, +leaving 65 bytes for any potential improvements. Byte saving leaderboard: - Ilya Kurdyukov saved 24 bytes. Thanks! diff --git a/blocks/bootstrap.fth b/blocks/bootstrap.fth index 4cd6ce8..1be4af1 100644 --- a/blocks/bootstrap.fth +++ b/blocks/bootstrap.fth @@ -1,4 +1,4 @@ -: >in a02 ; : run >in ! ; swap : dp 0 | dup @ 2 - ! | ; +: >in 7d00 ; : run >in ! ; swap : dp 0 | dup @ 2 - ! | ; : drop dup - - ; : negate 0 swap - ; : + negate - ; : here dp @ ; : cell+ 2 + ; : cell- 2 - ; : cells dup + ; diff --git a/boot.s b/boot.s index 6bd2998..a8aed2a 100644 --- a/boot.s +++ b/boot.s @@ -30,7 +30,9 @@ F_LENMASK equ 0x1f InputBuf equ 0x500 BlockBuf equ 0x600 BlockBuf.end equ 0xa00 -InputPtr equ 0xa02 ; dw +; we put it at 7d00, since that's in the middle of CompressedData, +; which we effectively discard before the first access to InputPtr +InputPtr equ 0x7d00 ; dw RS0 equ 0xb00 SPECIAL_BYTE equ 0xff @@ -106,7 +108,7 @@ start: ReadLine: mov di, InputBuf - mov [InputPtr], di + mov [byte bp-BP_POS+InputPtr], di .loop: mov ah, 0 int 0x16 @@ -207,7 +209,7 @@ Return: ; BX = numeric value ; clobbers SI ParseWord: - mov si, [InputPtr] + mov si, [byte bp-BP_POS+InputPtr] ; repe scasb would probably save some bytes here if the registers worked out - scasb ; uses DI instead of SI :( .skiploop: @@ -231,7 +233,7 @@ ParseWord: cbw shl bx, 4 add bx, ax - mov [InputPtr], si + mov [byte bp-BP_POS+InputPtr], si lodsb jmp short .takeloop @@ -243,7 +245,7 @@ DiskPacket: ; rest is filled out at runtime, overwriting the compressed data, ; which isn't necessary anymore -BP_POS equ $ +BP_POS equ $ - $$ + 0x7c00 CompressedData: times COMPRESSED_SIZE db 0xcc @@ -364,7 +366,7 @@ DRIVE_NUMBER equ $+1 ;; Copies the rest of the line to buf. defcode LINE, "s:" ; ( buf -- buf+len ) - xchg si, [InputPtr] + xchg si, [byte bp-BP_POS+InputPtr] .copy: lodsb mov [bx], al @@ -374,7 +376,7 @@ defcode LINE, "s:" ; ( buf -- buf+len ) .done: dec bx dec si - xchg si, [InputPtr] + xchg si, [byte bp-BP_POS+InputPtr] defcode SWITCH, "|", F_IMMEDIATE xor byte[byte bp-BP_POS+STATE], 1