[Featured][Beta] API - Why hasn't this been done yet?!

Here you can find side projects of the staff and great projects which we think should get extra support. (Note that featured projects are not projects by staff members of MaxCoderz)

Moderator: MaxCoderz Staff

CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

qarnos wrote:It's basically a file which tells search engines which files they shouldn't index. Might be of some use to you.
Many spiders ignore robots.txt.
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

I wonder if I should upload the stable API to Ticalc.org under routines or something, and add a link to the website. It needs to get a bit more attention. I already e-mailed Ticalc.org about featuring it as a newsitem several days ago, but I don't think they'll do that.

By the way, Ben:
benryves wrote:(I'll try to remember to post my routines at some point, but they probably aren't good enough).
First; I have never seen anything coming from you that wasn't worth it's file size in gold :P
Second; it's an open source project, so if it's not good enough someone else will probably optimize it. But I'd like to see a bit more functionality in it first, optimization can wait a bit I think.
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
gangsta
Sir Posts-A-Lot
Posts: 171
Joined: Wed 12 Oct, 2005 10:46 pm

Post by gangsta »

get kv to feature it on the MaxCoderz frontpage!
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

Nah, I doubt he'll do that :) Besides, more people visit this forum than maxcoderz.net...
I just added the website to two Ti webrings, let's see if I get accepted, and how much it'll help ;)
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
threefingeredguy
Calc King
Posts: 2195
Joined: Sun 27 Mar, 2005 4:06 am
Location: sleeping
Contact:

Post by threefingeredguy »

Get MV to feature it on ticalc and Nikky/Andy to do it on CG.
Image
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

I guess I could give that a try :)
I'll pop into #tcpa some time soon.
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Timendus wrote:By the way, Ben:
benryves wrote:(I'll try to remember to post my routines at some point, but they probably aren't good enough).
First; I have never seen anything coming from you that wasn't worth it's file size in gold :P
Second; it's an open source project, so if it's not good enough someone else will probably optimize it. But I'd like to see a bit more functionality in it first, optimization can wait a bit I think.
Problem is, the only generic routines that would be of any use relate to eachother - so string reverse relies on a string length, but you already have a string length yet I cannot use that as my string length needs the string at hl. Things like that ;)
Also, they're all standalone, so use strange non-TI equates (system._linkport instead of bport, for example).
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

I have an idea, just post the seperate routines here so people (probably me, but let's keep the idea of open development ;)) can rewrite parts of it before we add them.
benryves wrote:but you already have a string length yet I cannot use that as my string length needs the string at hl. Things like that ;)
So does this. If you don't want to use the macro, you can define it's api_use_whatever, and call the routine:

Code: Select all

#DEFINE api_use_string_size
ld hl,str
call api_string_size
; bc = length
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

You asked for it... (note, XML tags are from an old helpfile generator I no longer use).

Strings:

Code: Select all

;<file>String manipulation and formatting functions</file>

;<function=_s_disp_a>
;<summary>Print out the unsigned number in the accumulator in decimal form</summary>
;<input>A=The number to print. It will be printed unsigned.</input>
;<destroyed>AF</destroyed>
_s_disp_a:

	ld b,0
_s_d_a_100:
	cp 100	; > 100?
	jr c,_s_d_a_s_100
	inc b
	sub 100
	jr _s_d_a_100
_s_d_a_s_100:
	push af
	ld a,b
	or a
	jr z,_s_d_a_s_n_100
	add a,'0'
	call _t_put_c
_s_d_a_s_n_100:
	pop af	


	ld b,0
_s_d_a_10:
	cp 10	; > 10?
	jr c,_s_d_a_s_10
	inc b
	sub 10
	jr _s_d_a_10
_s_d_a_s_10:
	push af
	ld a,b
	or a
	jr z,_s_d_a_s_n_10
	add a,'0'
	call _t_put_c
_s_d_a_s_n_10:
	pop af
	add a,'0'
	call _t_put_c
	ret
;</function>

;<function=_s_disp_a_hex>
;<summary>Displays the value [00->FF] held in A in hexadecimal form</summary>
;<input>A=The value to display</input>
_s_disp_a_hex:
	push af
	push af
	srl a
	srl a
	srl a
	srl a
	call _s_disp_a_hex_nibble
	pop af
	and %00001111
	call _s_disp_a_hex_nibble
	pop af
	ret
;</function>

;<function=_s_disp_a_hex_nibble>
;<summary>Displays the lower nibble [0->F] of A in hexadecimal form.</summary>
;<input>A=The value to display</input>
;<remarks>Not intended to be called on its own; it is better to call _s_disp_a_hex</remarks>
_s_disp_a_hex_nibble:
	push af
	and %00001111
	cp 10
	jr c,_s_d_h_n_10
	sub 10
	add a,'A'
	call _t_put_c
	pop af
	ret
_s_d_h_n_10:
	add a,'0'
	call _t_put_c
	pop af
	ret
;</function>
	
;<function=_s_cmp>
;<summary>Check if two strings are equal to eachother</summary>
;<destroyed>HL,DE,AF</destroyed>
;<input>HL=Pointer to first string,DE=Pointer to second string</input>
;<output>Z=Equality of strings: Z if they are the same or NZ if they are different.</output>
_s_cmp:
	ld a,(de)
	or a
	jr z,_s_cmp_len
	xor (hl)
	ret nz	; Nonidentical
	inc hl
	inc de
	jr _s_cmp
_s_cmp_len:
	or (hl)
	ret
;</function>


;<function=_s_length>
;<summary>Get the length of a string</summary>
;<destroyed>AF</destroyed>
;<input>HL=Pointer to the string</input>
;<output>A=Length of the string</output>
_s_length:
	push hl
	push bc
	ld b,0
_s_length_get:
	ld a,(hl)
	or a
	jr z,_s_length_found
	inc hl
	inc b
	jr _s_length_get
_s_length_found:
	ld a,b
	pop bc
	pop hl
	ret
;</function>

;<function=_s_reverse>
;<summary>Reverse a string</summary>
;<destroyed>AF</destroyed>
;<input>HL=Pointer to the string</input>
;<remarks>The string is overwritten by the new, reversed version.</remarks>
_s_reverse:
	call _s_length
	or a
	ret z
	srl a
	or a
	ret z	; <2 character string

	push bc
	push hl
	push de

	ld b,a

	ld d,h
	ld e,l

_s_rev_f_eod:
	ld a,(de)
	or a
	jr z,_s_rev_eod
	inc de
	jr _s_rev_f_eod

_s_rev_eod:
	dec de

	; At this point, DE=pointer to last char, HL=pointer to start char, B=length>>1

_s_rev_loop:
	ld c,(hl)
	ld a,(de)
	ld (hl),a
	ld a,c
	ld (de),a

	inc hl
	dec de
	djnz _s_rev_loop

	pop de
	pop hl
	pop bc
	ret
;</function>

;<function=_s_get_value>
;<summary>Returns a 16-bit value corresponding to the string pointed to by HL</summary>
;<input>HL=Pointer to the string to convert</input>
;<destroyed>AF</destroyed>
;<output>HL=Value</output>
;<warning>This function trashes the string, so if it is imporant call this function on a copy of it.</warning>
_s_get_value:

	push bc
	push de

	call _s_reverse	;Reverse so it's in units-tens-hundreds-thousands... order	

	ld b,h
	ld c,l

	ld de,1
	ld hl,0

_s_gv_get_next:
	ld a,(bc)
	or a
	jr z,_s_gv_totalled
	sub '0'
	jr z,_s_gv_got_digit

	push bc
	ld b,a
_s_gv_get_unit:
	add hl,de
	djnz _s_gv_get_unit
	pop bc

_s_gv_got_digit:

	; HL = running total. Save it away...
	push hl

	; Now we need to DE*10:
	ex de,hl
	add hl,hl
	ld d,h
	ld e,l
	add hl,hl
	add hl,hl
	add hl,de
	ex de,hl
	pop hl
	inc bc
	jr _s_gv_get_next
_s_gv_totalled:

	pop de
	pop bc

	ret
;</function>

;<function=_s_get_arg_v>
;<summary>Returns a command-line argument as a string</summary>
;<remarks>Argument number 0 will always be the name of the program being run.</remarks>
;<destroyed>AF,HL,DE,BC</destroyed>
;<input>HL=Location of buffer to store the resulting string in,A=Which argument to return (0-indexed),B=Size of buffer to store result in (stops overflows)</input>
;<important>Use of any function that accesses the _input_buffer will overwrite the current command. If need be, call this function at the start of your program and save the returned value to a safe location in RAM.</important>
_s_get_arg_v:
	ld de,_input_buffer
	push bc
	or a
	jr z,_s_gav_found
	ld b,a
_s_gav_find:
	ld a,(de)
	cp ' '
	jr z,_s_gav_found_nearly
	or a
	jr z,_s_gav_found_null
	inc de
	jr _s_gav_find

_s_gav_found_nearly:
	inc de
	djnz _s_gav_find
_s_gav_found:
	pop bc

_s_gav_copy:
	ld a,(de)
	cp ' '
	jr nz,_s_gav_copy_notspace
	xor a
_s_gav_copy_notspace:
	ld (hl),a
	inc hl
	inc de
	or a
	ret z
	djnz _s_gav_copy
	; Run off the end...
	dec hl
	ld (hl),0
	ret

_s_gav_found_null:	; Past the end of the input string
	pop bc
	ld (hl),0
	ret
;</function>


;<function=_s_get_arg_c>
;<summary>Returns the number of command-line arguments</summary>
;<remarks>Note that it will always be at least 1 - the command itself is considered an argument!</remarks>
;<destroyed>AF</destroyed>
;<important>Use of any function that accesses the _input_buffer will overwrite the current command. If need be, call this function at the start of your program and save the returned value to a safe location in RAM.</important>
;<output>A=Number of command-line arguments</output>
_s_get_arg_c:
	push hl
	push bc
	ld c,1
	ld hl,_input_buffer

_s_gac_calc:
	ld a,(hl)
	or a
	jr z,_s_gac_found
	cp ' '
	jr nz,_s_gac_nospace
	inc c
_s_gac_nospace:
	inc hl
	jr _s_gac_calc

_s_gac_found:
	ld a,c
	pop bc
	pop hl
	ret
;</function>
Link:

Code: Select all

;<file>TI-OS compatible link routines</file>
;<function=_l_send_byte>
;<summary>Send a byte over the link port</summary>
;<destroyed>AF</destroyed>
;<input>A=Byte to send</input>
;<output>Z=Success or failure (Z for success; NZ for failure)</output>
;<remarks>As far as I know, this routine is entirely compatible with the official TI byte-transfer protocol.</remarks>
_l_send_byte:
	push hl
	push bc
	ld c,a

	ld hl,_link_timeout_l
_l_send_wait_reset:
	in a,(_linkport)
	and 3
	cp 3
	jr z,_l_send_waited_reset
	dec hl
	ld a,h
	or l
	jr nz,_l_send_wait_reset
	jr _l_sb_timeout_q

_l_send_waited_reset:

	ld b,8
_l_send_bit:
	push bc

	ld a,c
	and 1
	jr nz,_l_send_a
	ld l,2
	jr _l_send_b
_l_send_a:
	ld l,1
_l_send_b:

	ld a,l
	xor 3
	out (_linkport),a

	ld b,_link_timeout
_l_send_wait_ack:
	in a,(_linkport)
	and l
	jr z,_l_send_waited_ack
	jr _l_send_wait_ack
	jr _l_sb_timeout


_l_send_waited_ack:
	xor a
	out (_linkport),a

	pop bc
	srl c

	djnz _l_send_bit
	pop bc
	pop hl
	xor a
	ret

_l_sb_timeout:
	pop bc
_l_sb_timeout_q:
	pop bc
	pop hl
	or $FF
	ret

;</function>

;<function=_l_get_byte>
;<summary>Receive a byte over the link port</summary>
;<destroyed>AF</destroyed>
;<output>A=Received byte,Z=Success or failure (Z for success; NZ for failure)</output>
;<remarks>As far as I know, this routine is entirely compatible with the official TI byte-transfer protocol.</remarks>
_l_get_byte:
	push de
	push hl
	push bc
	; E will be the value we store the byte in
	ld e,0
	ld b,8
_l_get_next_bit:
	push bc

	ld b,_link_timeout
_l_get_bit:
        in a,(_linkport)
        and 3
	ld c,a	; Store the value in C [eg 01]
        cp 3
	jr nz,_l_got_bit
	djnz _l_get_bit	; Nothing being sent... yet.
	; TIMEOUT
	jr _l_gb_timeout

_l_got_bit:

	; One of the lines has been pulled LOW.
	; We have got a bit. L needs to be budged up to fit the next but in.
	srl e
	; Now, was it a '1'?
	cp 2
	jr z,_l_gb_not_1
	; Set the bit...
	ld a,%10000000
	or e
	ld e,a
_l_gb_not_1:
	; Now we have recorded the bit, we need to pull the OTHER line low.
	ld a,c
	out (_linkport),a	; Output the toggled value. [eg 10]
	; Now we need to wait for the OTHER line to go back up...
	ld a,c
	xor 3
	ld c,a

	ld b,_link_timeout
_l_gb_wait_backup:
	in a,(_linkport)
	and c
	jr nz,_l_gb_got_backup
	djnz _l_gb_wait_backup	; Nothing being sent... yet.
	; TIMEOUT
	jr _l_gb_timeout

_l_gb_got_backup:
	; Bring both lines back up
	xor a
	out (_linkport),a
	pop bc
	djnz _l_get_next_bit
	xor a
	ld a,e
	pop bc
	pop hl
	pop de
	ret

_l_gb_timeout:	; Branches here if the system times out.
	pop bc
	pop bc
	pop hl
	pop de
	or $FF
	ret
;</function>
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

Wow, looking good :)
I'll see what I can do asap.
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

I adapted your routines to work for the API. Haven't tested anything yet, I don't have the time for that now. Please check if I didn't make too many stupid mistakes :)

Code: Select all

; ***
; [routine]int.decToString(?str,#val)[/routine]
;
; Formats #val to be outputted in decimal form. Result at str.
;
; Example:
;  Write example
;
; Size:
;  ?? bytes routine + ?? bytes invocation
;
; Depends on:
;  Add dependencies
;
; Written by:
;  Ben Ryves
;

#IFDEF api_defines
#IFNDEF api_routines

   #DEFINE   int.decToString(str,val) ld hl,str
   #DEFCONT  \ ld a,val
   #DEFCONT  \ call api_int_decToString
   #DEFCONT  \ #DEFINE api_use_int_decToString

#ENDIF
#ENDIF

#IFDEF api_routines
#IFDEF api_use_int_decToString

api_int_decToString:

   ; hl = str
   ; a = val

	ld b,0
_s_d_a_100:
	cp 100	; > 100?
	jr c,_s_d_a_s_100
	inc b
	sub 100
	jr _s_d_a_100
_s_d_a_s_100:
	push af
	ld a,b
	or a
	jr z,_s_d_a_s_n_100
	add a,'0'
	ld (hl),a
	inc hl
_s_d_a_s_n_100:
	pop af	


	ld b,0
_s_d_a_10:
	cp 10	; > 10?
	jr c,_s_d_a_s_10
	inc b
	sub 10
	jr _s_d_a_10
_s_d_a_s_10:
	push af
	ld a,b
	or a
	jr z,_s_d_a_s_n_10
	add a,'0'
	ld (hl),a
	inc hl
_s_d_a_s_n_10:
	pop af
	add a,'0'
	ld (hl),a
	inc hl
	ld (hl),0
	ret

#ENDIF
#ENDIF
I think my int.toString is pretty much the same as your _s_disp_a_hex

string.compare: I think yours is faster and smaller than mine :)

Code: Select all

Routine string.compare(?str1,?str2)	Edit

; ***
; [routine]string.compare(?str1,?str2)[/routine]
;
; Compares two zero terminated strings for equality, returns z flag:
;  z:  <i>str1</i> == <i>str2</i>
;  nz: <i>str1</i> != <i>str2</i>
;
; Example:
;  kbd.readln.home(buffer,8)
;  string.compare(buffer,compstr)
;  jr z,equalgo
;  home.println(notequal)
;  ret
;  ...
;  buffer: .fill 9,0
;  compstr: .db "FILENAME",0
;  notequal: .db "Not equal",0
;  equal: .db "Equal",0
;
; Written by:
;  Ben Ryves
;

#IFDEF api_defines
#IFNDEF api_routines

   #DEFINE   string.compare(str1,str2)   ld      hl,str1
   #DEFCONT  \ ld      de,str2
   #DEFCONT  \ call    api_string_compare
   #DEFCONT  \ #DEFINE api_use_string_compare

#ENDIF
#ENDIF

#IFDEF api_routines
#IFDEF api_use_string_compare

api_string_compare:

   ; hl = str1
   ; de = str2
   ; Return z = equal, nz = not equal

_s_cmp:
	ld a,(de)
	or a
	jr z,_s_cmp_len
	xor (hl)
	ret nz	; Nonidentical
	inc hl
	inc de
	jr _s_cmp
_s_cmp_len:
	or (hl)
	ret

#ENDIF
#ENDIF
I think my string.size if smaller and faster than your _s_length, not really sure though. Any way it's easier to use with string.reverse:

Code: Select all

; ***
; [routine]string.reverse(?str)[/routine]
;
; Reverses a string at str. String should be less than 255 chars long.
;
; Example:
;  Write example
;
; Size:
;  ?? bytes routine + ?? bytes invocation
;
; Depends on:
;  string.size
;
; Written by:
;  Ben Ryves
;

#IFDEF api_defines
#IFNDEF api_routines

   #DEFINE   string.reverse(str) ld hl,str
   #DEFCONT  \ call api_string_reverse
   #DEFCONT  \ #DEFINE api_use_string_reverse

#ENDIF
#ENDIF

#IFDEF api_routines
#IFDEF api_use_string_reverse

	#DEFINE api_use_string_size

api_string_reverse:

   ; hl = str

_s_reverse:
	push hl
	call api_string_size
	dec hl
	ex de,hl
	pop hl    ; hl = pointer to start, de = pointer to end
	ld a,b
	or a
	ret nz     ; bail out if string longer than 255 chars
	or c
	ret z     ; bail out if string 0 chars long
	srl a
	or a
	ret z	  ; bail out if string 1 char long

	ld b,a

	; At this point, DE=pointer to last char, HL=pointer to start char, B=length>>1

_s_rev_loop:
	ld c,(hl)
	ld a,(de)
	ld (hl),a
	ld a,c
	ld (de),a

	inc hl
	dec de
	djnz _s_rev_loop

	ret

#ENDIF
#ENDIF

Code: Select all

; ***
; [routine]string.toDouble(?str)[/routine]
;
; Converts a decimal string to a 16-bit value in hl
;
; Example:
;  Write example
;
; Size:
;  ?? bytes routine + ?? bytes invocation
;
; Depends on:
;  string.reverse
;
; Written by:
;  Ben Ryves
;

#IFDEF api_defines
#IFNDEF api_routines

   #DEFINE   string.toDouble(str) ld hl,str
   #DEFCONT  \ call api_string_toDouble
   #DEFCONT  \ #DEFINE api_use_string_toDouble

#ENDIF
#ENDIF

#IFDEF api_routines
#IFDEF api_use_string_toDouble

   #DEFINE api_use_string_reverse

api_string_toDouble:

   ; hl = str

_s_get_value:

   call api_string_reverse  ;Reverse so it's in units-tens-hundreds-thousands... order   

   ld b,h
   ld c,l

   ld de,1
   ld hl,0

_s_gv_get_next:
   ld a,(bc)
   or a
   jr z,_s_gv_totalled
   sub '0'
   jr z,_s_gv_got_digit

   push bc
   ld b,a
_s_gv_get_unit:
   add hl,de
   djnz _s_gv_get_unit
   pop bc

_s_gv_got_digit:

   ; HL = running total. Save it away...
   push hl

   ; Now we need to DE*10:
   ex de,hl
   add hl,hl
   ld d,h
   ld e,l
   add hl,hl
   add hl,hl
   add hl,de
   ex de,hl
   pop hl
   inc bc
   jr _s_gv_get_next
_s_gv_totalled:

   ret 

#ENDIF
#ENDIF
What exactly is the use of _s_get_arg_v and _s_get_arg_c?

I'm not sure if your link routines are of much use. We can use the Ti-OS ones, while this was designed with the idea that you were writing a replacement OS. I think using the Ti-OS routines with some error-handling-wrapping-stuff would be smaller.

Code: Select all

; ***
; [routine]link.write(#byte)[/routine]
;
; Sends a byte through the link port using the Ti protocol
; Returns succes in z flag:
;  z = success
;  nz = failure
;
; Example:
;  Write example
;
; Size:
;  ?? bytes routine + ?? bytes invocation
;
; Depends on:
;  Add dependencies
;
; Written by:
;  Ben Ryves
;

#IFDEF api_defines
#IFNDEF api_routines

   #DEFINE   link.write(byte) ld a,byte
   #DEFCONT  \ call api_link_write
   #DEFCONT  \ #DEFINE api_use_link_write

#ENDIF
#ENDIF

#IFDEF api_routines
#IFDEF api_use_link_write

api_link_write:

   ; a = byte

_l_send_byte:
   push hl
   push bc
   ld c,a

   ld hl,_link_timeout_l
_l_send_wait_reset:
   in a,(bport)
   and 3
   cp 3
   jr z,_l_send_waited_reset
   dec hl
   ld a,h
   or l
   jr nz,_l_send_wait_reset
   jr _l_sb_timeout_q

_l_send_waited_reset:

   ld b,8
_l_send_bit:
   push bc

   ld a,c
   and 1
   jr nz,_l_send_a
   ld l,2
   jr _l_send_b
_l_send_a:
   ld l,1
_l_send_b:

   ld a,l
   xor 3
   out (bport),a

   ld b,_link_timeout
_l_send_wait_ack:
   in a,(bport)
   and l
   jr z,_l_send_waited_ack
   jr _l_send_wait_ack
   jr _l_sb_timeout


_l_send_waited_ack:
   xor a
   out (bport),a

   pop bc
   srl c

   djnz _l_send_bit
   pop bc
   pop hl
   xor a
   ret

_l_sb_timeout:
   pop bc
_l_sb_timeout_q:
   pop bc
   pop hl
   or $FF
   ret

#ENDIF
#ENDIF

Code: Select all

; ***
; [routine]link.read()[/routine]
;
; Reads a byte from the link port in a using the Ti protocol
; Returns succes in z flag:
;  z = success
;  nz = failure
;
; Example:
;  Write example
;
; Size:
;  ?? bytes routine + ?? bytes invocation
;
; Depends on:
;  Add dependencies
;
; Written by:
;  Ben Ryves
;

#IFDEF api_defines
#IFNDEF api_routines

   #DEFINE   link.read() call api_link_read
   #DEFCONT  \ #DEFINE api_use_link_read

#ENDIF
#ENDIF

#IFDEF api_routines
#IFDEF api_use_link_read

api_link_read:

_l_get_byte:

   ; E will be the value we store the byte in
   ld e,0
   ld b,8
_l_get_next_bit:
   push bc

   ld b,_link_timeout
_l_get_bit:
   in a,(bport)
   and 3
   ld c,a   ; Store the value in C [eg 01]
   cp 3
   jr nz,_l_got_bit
   djnz _l_get_bit   ; Nothing being sent... yet.
   ; TIMEOUT
   jr _l_gb_timeout

_l_got_bit:

   ; One of the lines has been pulled LOW.
   ; We have got a bit. L needs to be budged up to fit the next but in.
   srl e
   ; Now, was it a '1'?
   cp 2
   jr z,_l_gb_not_1
   ; Set the bit...
   ld a,%10000000
   or e
   ld e,a
_l_gb_not_1:
   ; Now we have recorded the bit, we need to pull the OTHER line low.
   ld a,c
   out (bport),a   ; Output the toggled value. [eg 10]
   ; Now we need to wait for the OTHER line to go back up...
   ld a,c
   xor 3
   ld c,a

   ld b,_link_timeout
_l_gb_wait_backup:
   in a,(bport)
   and c
   jr nz,_l_gb_got_backup
   djnz _l_gb_wait_backup   ; Nothing being sent... yet.
   ; TIMEOUT
   jr _l_gb_timeout

_l_gb_got_backup:
   ; Bring both lines back up
   xor a
   out (bport),a
   pop bc
   djnz _l_get_next_bit
   xor a
   ld a,e

   ret

_l_gb_timeout:   ; Branches here if the system times out.
   pop bc
   or $FF
   ret 

#ENDIF
#ENDIF
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
User avatar
benryves
Maxcoderz Staff
Posts: 3087
Joined: Thu 16 Dec, 2004 10:06 pm
Location: Croydon, England
Contact:

Post by benryves »

Timendus wrote:What exactly is the use of _s_get_arg_v and _s_get_arg_c?
_s_get_arg_c returns the number of command-line arguments in the input buffer, _s_get_arg_v gets a particular argument (by index) as a string. Not very useful, I guess (I just copied and pasted the general strings file).
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

Unless someone uses the API for making a command prompt thingy :)
So I adapted them anyway.

Code: Select all

; ***
; [routine]string.countWords(→str)[/routine]
;
; Returns the number of words (or arguments in a command line situation) found in the string at str in registers a and c.
;
; Example:
;  Write example
;
; Size:
;  ?? bytes routine + ?? bytes invocation
;
; Depends on:
;  Add dependencies
;
; Written by:
;  Ben Ryves
;

#IFDEF api_defines
#IFNDEF api_routines

   #DEFINE   string.countWords(str) ld hl,str
   #DEFCONT  \ call api_string_countWords
   #DEFCONT  \ #DEFINE api_use_string_countWords

#ENDIF
#ENDIF

#IFDEF api_routines
#IFDEF api_use_string_countWords

api_string_countWords:

   ; hl = str
   ld c,1

_s_gac_calc:
   ld a,(hl)
   or a
   jr z,_s_gac_found
   cp ' '
   jr nz,_s_gac_nospace
   inc c
_s_gac_nospace:
   inc hl
   jr _s_gac_calc

_s_gac_found:
   ld a,c
   ret

#ENDIF
#ENDIF

Code: Select all

; ***
; [routine]string.getWord(>str,>word,#index,#maxwordsize)[/routine]
;
; Stores the <i>index</i>th word in the string at <i>str</i> in memory at <i>word</i>. Use <i>maxwordsize</i> to prevent overflow at <i>word</i>.
;
; Example:
;  Write example
;
; Size:
;  ?? bytes routine + ?? bytes invocation
;
; Depends on:
;  Add dependencies
;
; Written by:
;  Ben Ryves
;

#IFDEF api_defines
#IFNDEF api_routines

   #DEFINE   string.getWord(str,word,index) ld de,str
   #DEFCONT  \ ld hl,word
   #DEFCONT  \ ld a,index
   #DEFCONT  \ ld b,maxwordsize
   #DEFCONT  \ call api_string_getWord
   #DEFCONT  \ #DEFINE api_use_string_getWord

#ENDIF
#ENDIF

#IFDEF api_routines
#IFDEF api_use_string_getWord

api_string_getWord:

   ; hl = word
   ; de = str
   ; a = index
   ; b = maxwordsize

_s_get_arg_v:
   push bc
   or a
   jr z,_s_gav_found
   ld b,a
_s_gav_find:
   ld a,(de)
   cp ' '
   jr z,_s_gav_found_nearly
   or a
   jr z,_s_gav_found_null
   inc de
   jr _s_gav_find

_s_gav_found_nearly:
   inc de
   djnz _s_gav_find
_s_gav_found:
   pop bc

_s_gav_copy:
   ld a,(de)
   cp ' '
   jr nz,_s_gav_copy_notspace
   xor a
_s_gav_copy_notspace:
   ld (hl),a
   inc hl
   inc de
   or a
   ret z
   djnz _s_gav_copy
   ; Run off the end...
   dec hl
   ld (hl),0
   ret

_s_gav_found_null:   ; Past the end of the input string
   pop bc
   ld (hl),0
   ret 

#ENDIF
#ENDIF
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
User avatar
Timendus
Calc King
Posts: 1729
Joined: Sun 23 Jan, 2005 12:37 am
Location: Netherlands
Contact:

Post by Timendus »

I added Ben's routines, plus the sprite routines from Sean's "The Best Damn Sprite Routines Period" package. I think everything should work properly, but I'd appreciate it if some people could run some tests with those routines. They also all need examples. So feel free to edit/add :)
http://clap.timendus.com/ - The Calculator Link Alternative Protocol
http://api.timendus.com/ - Make your life easier, leave the coding to the API
http://vera.timendus.com/ - The calc lover's OS
User avatar
kv83
Maxcoderz Staff
Posts: 2735
Joined: Wed 15 Dec, 2004 7:26 pm
Location: The Hague, Netherlands
Contact:

Post by kv83 »

Just to give you an update;

We discussed featuring this project and came to the conclusion that we want to wait a little longer to see how this project develops... It has a good chance though :)
Image
Post Reply