1
0
mirror of https://github.com/hsoft/collapseos.git synced 2024-11-27 12:08:07 +11:00

zasm: reuse code from core

This commit is contained in:
Virgil Dupras 2019-04-16 17:00:19 -04:00
parent 9acca52e44
commit b3af6e0115
4 changed files with 17 additions and 61 deletions

View File

@ -5,7 +5,7 @@ libz80/libz80.so: libz80/Makefile
make -C libz80 make -C libz80
kernel.h: glue.asm kernel.h: glue.asm
scas -o - $< | ./bin2c.sh KERNEL > $@ scas -o - -I ../../../parts $< | ./bin2c.sh KERNEL | tee $@ > /dev/null
zasm.h: ../zasm.asm zasm.h: ../zasm.asm
scas -o - -I ./emul $< | ./bin2c.sh ZASM > $@ scas -o - -I ./emul $< | ./bin2c.sh ZASM | tee $@ > /dev/null

View File

@ -3,7 +3,12 @@
ZASM_INPUT .equ 0xa000 ZASM_INPUT .equ 0xa000
ZASM_OUTPUT .equ 0xd000 ZASM_OUTPUT .equ 0xd000
jr init jr init ; 2 bytes
; *** JUMP TABLE ***
jp strncmp
jp addDE
jp upcase
init: init:
di di
ld hl, RAMEND ld hl, RAMEND

View File

@ -1,3 +1,8 @@
RAMSTART .equ 0x8000 RAMSTART .equ 0x8000
RAMEND .equ 0xffff RAMEND .equ 0xffff
USER_CODE .equ RAMSTART USER_CODE .equ RAMSTART
; *** JUMP TABLE ***
JUMP_STRNCMP .equ 0x02
JUMP_ADDDE .equ 0x05
JUMP_UPCASE .equ 0x08

View File

@ -5,60 +5,6 @@ ld b, 0
ld c, a ; written bytes ld c, a ; written bytes
ret ret
; CORE COPY PASTE - TODO: call in kernel
; Compares strings pointed to by HL and DE up to A count of characters. If
; equal, Z is set. If not equal, Z is reset.
strncmp:
push bc
push hl
push de
ld b, a
.loop:
ld a, (de)
cp (hl)
jr nz, .end ; not equal? break early. NZ is carried out
; to the called
cp 0 ; If our chars are null, stop the cmp
jr z, .end ; The positive result will be carried to the
; caller
inc hl
inc de
djnz .loop
; We went through all chars with success, but our current Z flag is
; unset because of the cp 0. Let's do a dummy CP to set the Z flag.
cp a
.end:
pop de
pop hl
pop bc
; Because we don't call anything else than CP that modify the Z flag,
; our Z value will be that of the last cp (reset if we broke the loop
; early, set otherwise)
ret
; add the value of A into DE
addDE:
add a, e
jr nc, .end ; no carry? skip inc
inc d
.end:
ld e, a
ret
; Transforms the character in A, if it's in the a-z range, into its upcase
; version.
upcase:
cp 'a'
ret c ; A < 'a'. nothing to do
cp 'z'+1
ret nc ; A >= 'z'+1. nothing to do
; 'a' - 'A' == 0x20
sub 0x20
ret
; ZASM code
; Sets Z is A is ' ', CR, LF, or null. ; Sets Z is A is ' ', CR, LF, or null.
isSep: isSep:
cp ' ' cp ' '
@ -82,7 +28,7 @@ readWord:
ld a, (hl) ld a, (hl)
call isSep call isSep
jr z, .success jr z, .success
call upcase call JUMP_UPCASE
ld (de), a ld (de), a
inc hl inc hl
inc de inc de
@ -108,7 +54,7 @@ matchPrimaryRow:
push hl push hl
ld hl, curWord ld hl, curWord
ld a, 4 ld a, 4
call strncmp call JUMP_STRNCMP
pop hl pop hl
ret ret
@ -125,7 +71,7 @@ parseLine:
call matchPrimaryRow call matchPrimaryRow
jr z, .match jr z, .match
ld a, 7 ld a, 7
call addDE call JUMP_ADDDE
jr .loop jr .loop
.nomatch: .nomatch:
@ -134,7 +80,7 @@ parseLine:
ret ret
.match: .match:
ld a, 6 ; upcode is on 7th byte ld a, 6 ; upcode is on 7th byte
call addDE call JUMP_ADDDE
ld a, (de) ld a, (de)
pop de pop de
ld (de), a ld (de), a