Code check required

ZX evolution software and hardware

Postby justine » 20 Mar 2012, 19:21

Hi i am attempting to write my own OS using my Evo and TS-LABS config.
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



User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby lvd » 20 Mar 2012, 19:24

I think that unless you are Linus Torvalds, your OS should start from anything but not code writing :-)
Многого нет здесь: http://lvd.nedopc.com
Image
User avatar
lvd
 
Posts: 1786
Joined: 07 Apr 2007, 22:28
Group: Registered users

Postby justine » 20 Mar 2012, 19:29

I was only asking if some kind hearted person could check my parse routine and show me mistakes.
User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby breeze » 20 Mar 2012, 19:40

Seems all right at first look.

justine wrote:dw "cls"      ; Command

justine wrote:dw "videomode"


But, maybe you mean DB ?

ps. I need a parser for my script engine . Can I use your code?
User avatar
breeze
 
Posts: 764
Joined: 07 Feb 2009, 17:19
Location: Оттуда
Group: Registered users

Postby justine » 20 Mar 2012, 19:44

Thanx Breeze,
Isn't dw for data word and db for data byte ?
Feel free to use my code, its good to know i am of use to someone ;-)
User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby breeze » 20 Mar 2012, 19:49

justine wrote:Isn't dw for data word and db for data byte ?


"db" is single char 1 byte, "dw" is world - 2 bytes.
If you try to compile like "dw" you will receive error "Bytes lost":

justine.asm(46): error: Bytes lost

justine wrote:Feel free to use my code, its good to know i am of use to someone ;-)


Thanks ;)
User avatar
breeze
 
Posts: 764
Joined: 07 Feb 2009, 17:19
Location: Оттуда
Group: Registered users

Postby justine » 20 Mar 2012, 19:56

Ah yes your right :agree: Was just a silly mistake would have found out when i got home and tried to compile it.

Thanx
User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby justine » 20 Mar 2012, 20:08

Revised code compiled using IAR EWZ80

Code: Select all
; Input DE points to command buffer start
; HL points to command table
; Output DE points to space after last character of command
; HL points to command jump vector

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
      defb 'cls'                   ; Command
      defb '*'                     ; 1 byte
      defw jumpvector1      ; 2 bytes
         
      defb 'videomode'      ; Command
      defb '*'                    ; 1 byte
      defw jumpvector2     ; 2 bytes


User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby justine » 20 Mar 2012, 20:26

Added function to check for end of command by looking for a space of enter in buffer.

Code: Select all
; Input DE points to command buffer start
; HL points to command table
; Output DE points to space after last character of command
; HL points to command jump vector

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 h'0d         ; Enter 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
      defb 'cls'      ; Command
      defb '*'         ; 1 byte
      defw jumpvector1      ; 2 bytes
         
      defb 'videomode'      ; Command
      defb '*'         ; 1 byte
      defw jumpvector2      ; 2 bytes

User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby justine » 20 Mar 2012, 20:28

checking for a space at the end of the command is handy as you can then have additional parameters to supply to the called routine. The called routine just checks for other characters after this space.
If it was an enter then there are no parameters to be passed.
User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Next

Return to Пентева - софт и железо

Who is online

Users browsing this forum: No registered users and 1 guest