Code check required

ZX evolution software and hardware

Postby breeze » 20 Mar 2012, 20:32

justine wrote:Revised code compiled


So, add example for call, plz

how i can see, like this.

Code: Select all
      ld de, parseString
      call parse
      ret

parseString      defb "cls",0


String need to be terminated with zero or h'0D or h'0a ?

And how about call parser with params?

Code: Select all
command param1 param2 param3
User avatar
breeze
 
Posts: 764
Joined: 07 Feb 2009, 17:19
Location: Оттуда
Group: Registered users

Postby justine » 20 Mar 2012, 20:58

Example call :

ld de, command_line_buffer_address_start
call parse

No the string doesn't need to be terminated with a zero , the routine checks if there is a space at the end of the command in the buffer which would mean there maybe more parameters that the called routine could read or if its an enter 0D its the end of the command in the buffer.

The routine that is called must check if there are extra parameters to be fetched / executed.
User avatar
justine
 
Posts: 101
Joined: 06 Jul 2011, 00:50
Location: Scotland
Group: Registered users

Postby justine » 20 Mar 2012, 21:10

This might work better

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
      push af
      ld a, '*'
      cp (hl)                ; Is it the end off command * ?
      jp z, forward         ; Yes inc HL 3 times to set to begining of next command in the table
      ld a, '@'          ; Table end reached ?
      cp (hl)
      jp no_match
      pop af
      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)

no_match
   ; Routine to print "Unkown command error"
   ret


; 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, 21:52

Forgot to add at the end of the table place this line so the routine knows its reached the end of the table.

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

Postby lvd » 21 Mar 2012, 00:17

justine wrote:I was only asking if some kind hearted person could check my parse routine and show me mistakes.

Well, shouldn't you compile it, load into debugger and check whether it works or not, and then debug it? In such a way you'll get 100% working code...
Многого нет здесь: http://lvd.nedopc.com
Image
User avatar
lvd
 
Posts: 1786
Joined: 07 Apr 2007, 22:28
Group: Registered users

Postby breeze » 03 Apr 2012, 18:46

Hi Justine, AGAin =)

I looked through your code and found some errors. :smoke:

I would like to draw your attention for a command line buffer is not always ends as space (20) code (for example commands without parameters), so I added check zero code for end of buffer. :yes:

At label "parse_start" I added "ld a,(de)". You increase DE but never had rereading value to the A. <_<

At line where you is checked "@" - wrong JP. I replaced "jp no_match" on the "jp z,no_match".

You store "PUSH AF" but forgot remove it from stack! :badevil: I added "pop af" at line with label "forward" and "no_match".

You did not properly invoke the command "JP (HL)" %) First we need to read a value into the register pair HL, and then make a jump to the address. ;)

So... now i think, code right a bit and work correctly. In the archive you will find source code and snapshot for emulator. :agree:

I compiled with the help of sjasmplus, so you may need to replace hex values of numbers, for example #20 to the h'20 :confused:
Attachments
justine.zip
(1.83 KB) Downloaded 1056 times
User avatar
breeze
 
Posts: 764
Joined: 07 Feb 2009, 17:19
Location: Оттуда
Group: Registered users

Previous

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

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron