Skip to content

Commit

Permalink
Move >IN to 7d00, saving 5 bytes.
Browse files Browse the repository at this point in the history
  • Loading branch information
meithecatte committed Apr 13, 2023
1 parent cff9c9c commit a9bcbc8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 11 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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!
Expand Down
2 changes: 1 addition & 1 deletion blocks/bootstrap.fth
Original file line number Diff line number Diff line change
@@ -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 + ;
Expand Down
16 changes: 9 additions & 7 deletions boot.s
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit a9bcbc8

Please sign in to comment.