I have written a command parser for which i would ask if someone would check my code to see if i have it correct please ?
Thanx in advance.
- Code: Select all
; Input DE points to command buffer start
; HL points to command table
parse
ld hl, table
eat_space
ld a, (de)
cp h'20 ; check for space
jp nz, parse_start
inc de
jp eat_space
parse_start
cp h'20 ; space means end of command
jp z, end_of_command
cp (hl) ; Compare a with first character in command table
jp nz, next_command ; Move HL to point to the first character of the next command in the table
inc de
inc hl
jp parse_start
next_command
cp '*' ; Is it the end off command * ?
jp z, forward ; Yes inc HL 3 times to set to begining of next command in the table
inc hl
jp next_command
forward
inc hl
inc hl
inc hl
jp parse_start
end_of_command
inc hl ; increase to *
inc hl ; Increase to point to jump vector for command
jp (hl)
; Command table below with all jump vectors.
table
dw "cls" ; Command
db '*' ; 1 byte
dw jumpvector1 ; 2 bytes
dw "videomode" ; Command
db '*' ; 1 byte
dw jumpvector2 ; 2 bytes