mirror of
https://github.com/hsoft/collapseos.git
synced 2024-11-27 13:38:05 +11:00
forth: straighten out "/MOD"
The removal of the "divide" routine highlighted the fact that nativeWord wasn't properly stabilized.
This commit is contained in:
parent
c2d8fc845d
commit
61bb22e8c9
Binary file not shown.
@ -106,8 +106,9 @@
|
|||||||
; *** Stable ABI ***
|
; *** Stable ABI ***
|
||||||
; Those jumps below are supposed to stay at these offsets, always. If they
|
; Those jumps below are supposed to stay at these offsets, always. If they
|
||||||
; change bootstrap binaries have to be adjusted because they rely on them.
|
; change bootstrap binaries have to be adjusted because they rely on them.
|
||||||
.fill 0x1a-$
|
.fill 0x17-$
|
||||||
JUMPTBL:
|
JUMPTBL:
|
||||||
|
jp nativeWord
|
||||||
jp next
|
jp next
|
||||||
jp chkPS
|
jp chkPS
|
||||||
|
|
||||||
@ -298,35 +299,6 @@ strskip:
|
|||||||
pop bc
|
pop bc
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; Borrowed from Tasty Basic by Dimitri Theulings (GPL).
|
|
||||||
; Divide HL by DE, placing the result in BC and the remainder in HL.
|
|
||||||
divide:
|
|
||||||
push hl ; --> lvl 1
|
|
||||||
ld l, h ; divide h by de
|
|
||||||
ld h, 0
|
|
||||||
call .dv1
|
|
||||||
ld b, c ; save result in b
|
|
||||||
ld a, l ; (remainder + l) / de
|
|
||||||
pop hl ; <-- lvl 1
|
|
||||||
ld h, a
|
|
||||||
.dv1:
|
|
||||||
ld c, 0xff ; result in c
|
|
||||||
.dv2:
|
|
||||||
inc c ; dumb routine
|
|
||||||
call .subde ; divide using subtract and count
|
|
||||||
jr nc, .dv2
|
|
||||||
add hl, de
|
|
||||||
ret
|
|
||||||
.subde:
|
|
||||||
ld a, l
|
|
||||||
sub e ; subtract de from hl
|
|
||||||
ld l, a
|
|
||||||
ld a, h
|
|
||||||
sbc a, d
|
|
||||||
ld h, a
|
|
||||||
ret
|
|
||||||
|
|
||||||
|
|
||||||
; Parse string at (HL) as a decimal value and return value in DE.
|
; Parse string at (HL) as a decimal value and return value in DE.
|
||||||
; Reads as many digits as it can and stop when:
|
; Reads as many digits as it can and stop when:
|
||||||
; 1 - A non-digit character is read
|
; 1 - A non-digit character is read
|
||||||
@ -782,10 +754,10 @@ ROUTINE:
|
|||||||
ld de, compiledWord
|
ld de, compiledWord
|
||||||
cp 'L'
|
cp 'L'
|
||||||
jr z, .end
|
jr z, .end
|
||||||
ld de, nativeWord
|
ld de, JUMPTBL
|
||||||
cp 'V'
|
cp 'V'
|
||||||
jr z, .end
|
jr z, .end
|
||||||
ld de, JUMPTBL
|
ld de, JUMPTBL+3
|
||||||
cp 'N'
|
cp 'N'
|
||||||
jr z, .end
|
jr z, .end
|
||||||
ld de, sysvarWord
|
ld de, sysvarWord
|
||||||
@ -800,7 +772,7 @@ ROUTINE:
|
|||||||
ld de, NUMBER
|
ld de, NUMBER
|
||||||
cp 'M'
|
cp 'M'
|
||||||
jr z, .end
|
jr z, .end
|
||||||
ld de, JUMPTBL+3
|
ld de, JUMPTBL+6
|
||||||
cp 'P'
|
cp 'P'
|
||||||
jr nz, .notgood
|
jr nz, .notgood
|
||||||
; continue to end on match
|
; continue to end on match
|
||||||
@ -1433,6 +1405,8 @@ MULT:
|
|||||||
jp next
|
jp next
|
||||||
|
|
||||||
|
|
||||||
|
; Borrowed from http://wikiti.brandonw.net/
|
||||||
|
; Divides AC by DE and places the quotient in AC and the remainder in HL
|
||||||
.db "/MOD"
|
.db "/MOD"
|
||||||
.fill 3
|
.fill 3
|
||||||
.dw $-MULT
|
.dw $-MULT
|
||||||
@ -1440,10 +1414,24 @@ MULT:
|
|||||||
DIVMOD:
|
DIVMOD:
|
||||||
.dw nativeWord
|
.dw nativeWord
|
||||||
pop de
|
pop de
|
||||||
pop hl
|
pop bc
|
||||||
call chkPS
|
call chkPS
|
||||||
call divide
|
ld a, b ; AC
|
||||||
push hl
|
ld b, 16
|
||||||
|
ld hl, 0
|
||||||
|
.loop:
|
||||||
|
scf
|
||||||
|
rl c
|
||||||
|
rla
|
||||||
|
adc hl, hl
|
||||||
|
sbc hl, de
|
||||||
|
jr nc, .skip
|
||||||
|
add hl, de
|
||||||
|
dec c
|
||||||
|
.skip:
|
||||||
|
djnz .loop
|
||||||
|
ld b, a
|
||||||
|
push hl ; REM
|
||||||
push bc
|
push bc
|
||||||
jp next
|
jp next
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@ CODE ROT
|
|||||||
HL POPqq, ( C )
|
HL POPqq, ( C )
|
||||||
DE POPqq, ( B )
|
DE POPqq, ( B )
|
||||||
BC POPqq, ( A )
|
BC POPqq, ( A )
|
||||||
ROUTINE P CALLnn,
|
chkPS,
|
||||||
DE PUSHqq, ( B )
|
DE PUSHqq, ( B )
|
||||||
HL PUSHqq, ( C )
|
HL PUSHqq, ( C )
|
||||||
BC PUSHqq, ( A )
|
BC PUSHqq, ( A )
|
||||||
|
Loading…
Reference in New Issue
Block a user