On-Calc handwriting

Got a brilliant program idea? Let us know!

Moderator: MaxCoderz Staff

Spengo
Calc Master
Posts: 1116
Joined: Sat 15 Jan, 2005 3:56 am
Location: ooga booga land
Contact:

Post by Spengo »

Mike K wrote: for example... Key A is one key to the left of Key B

Key A --(.1 sec)--> Key B = 1 pixel
Key A --(.2 sec)--> Key B = 2 pixels
Key A --(.3 sec)--> Key B = 4 pixels
Key A --(.4 sec)--> Key B = 8 pixels

etc. Now, .1 seconds is quite a lot so you could of couse use a much smaller unit of time.
Say, I just noticed...isn't that backwards? :insane: The slower you move, the less pixels it should go?
bananas... o.o
lecks
Extreme Poster
Posts: 484
Joined: Fri 09 Sep, 2005 1:56 am

Post by lecks »

threefingeredguy wrote:he does ASM? send him to www.revsoft.org, we want to talk to him. And you.
hes not interested in programming calcs.. he only has an 82.. and no way in hell is he touching my 84si
lecks
Extreme Poster
Posts: 484
Joined: Fri 09 Sep, 2005 1:56 am

Post by lecks »

CoBB wrote:I made that routine, and it did account for the speed of action and could handle any key combination pressed too. However, you can't read handwriting on such limited hardware. It's not just a programming task, but also requires a lot of theoretical knowledge (neural and hybrid systems and the relevant mathematics).
can i get a copy? you know, you could make it like a paint program, instead of a language... thats what i was gonna use it for.

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
the hell is wrong with my quotes??
CoBB
MCF Legend
Posts: 1601
Joined: Mon 20 Dec, 2004 8:45 am
Location: Budapest, Absurdistan
Contact:

Post by CoBB »

I'm lazy to upload it, so... Sorry, the layout is a bit broken due to the lack of tabs here.

test.asm:

Code: Select all

; Mouse test

#ifdef PLUS
VScreen 	.equ	$9340	; Plotsscreen, 768 bytes
 .org $9D93
 .byte $BB,$6D
 ret
#else
VScreen 	.equ	$8E29	; Plotsscreen, 768 bytes
 .org $9329
 .byte "š9_[V?",0
#endif
 jr nc,Start
 .byte "Mouse",0

Start:
 ld hl,48*256
 ld (MouseX),hl
 ld hl,32*256
 ld (MouseY),hl
Main:
 call ReadKeyboard
 call ValidateKeys
 ld a,(KeyPressed+6)
 and $80
 ret z
 ld a,(ValidKey)
 and $02
 jr nz,LeftOk
 ld a,(MM_Speed)
 dec a
 cp 2
 jr c,LeftOk
 ld (MM_Speed),a
LeftOk:
 ld a,(ValidKey)
 and $04
 jr nz,RightOk
 ld a,(MM_Speed)
 inc a
 cp 200
 jr nc,RightOk
 ld (MM_Speed),a
RightOk:
 call MouseMove
 call ClearScreen
 ld a,(MM_Speed)
 ld (VScreen),a
 ld a,(MouseY+1)
 cp 64
 jr nc,NoCursor
 add a,a
 add a,a
 ld e,a
 ld d,0
 ld hl,VScreen
 add hl,de
 add hl,de
 add hl,de
 ld a,(MouseX+1)
 cp 96
 jr nc,NoCursor
 ld e,a
 srl e
 srl e
 srl e
 add hl,de
 and 7
 ld c,128
 jr z,CurOkay
 ld b,a
CurShift:
 rrc c
 djnz CurShift
CurOkay:
 ld a,c
 or (hl)
 ld (hl),a
NoCursor:
 call FlipScreen
 jr Main

ClearScreen:			; Clearing the virtual screen at HL (~6500 cycles)
 ld (CS_saveSP+1),sp	; Backing up SP
CS_hackSize1:
; ld de,768
; add hl,de
 ld hl,VScreen+768
 ld sp,hl
 ld hl,0
CS_hackSize2:
 ld b,48
CS_loop:
 push hl				; 16 bytes are cleared in 8*11+13=101 cycles
 push hl				; That would be 16*21=336 with LDIR and 16*16+13=269 with LDIs
 push hl
 push hl
 push hl
 push hl
 push hl
 push hl
 djnz CS_loop
CS_saveSP:
 ld sp,0
 ret

FlipScreen:				; Copies the screen at HL to the LCD in ~52000 cycles (ION FastCopy)
 ld a,$80
 out ($10),a
; ld de,755
; add hl,de
 ld hl,VScreen+755
 ld a,$20
 ld c,a
 inc hl
 dec hl
FS_column:
 ld b,64
 inc c
 ld de,-767
 out ($10),a
 add hl,de
 ld de,10
FS_inner:
 add hl,de
 inc hl
 inc hl
 inc de
 ld a,(hl)
 out ($11),a
 dec de
 djnz FS_inner
 ld a,c
 cp $2c
 jp nz,FS_column
 ret

#include "mouse.inc"
#include "input.inc"

.end
END
mouse.inc:

Code: Select all

; KeyPressed+1..5 bits 5..1 (& 0x3e)

MouseMove:
 call MouseAverage
 ld a,h
 or a
 jr nz,MM_NonZero
 ld a,128		; No more input
 ld (MouseXX+1),a
 ret
MM_NonZero:
 ld e,h			; D=0 here (after MouseAverage)
 ld hl,MouseDivTable
 add hl,de
 ld h,(hl)
 ld a,(MouseXX+1)
 cp 128
 jr nz,MM_Difference	; Storing initial coordinates if equal
 ld e,b			; Calculating X average
 ld a,h
 call Mul_H_E
 ld (MouseXX),hl
 ld h,a
 ld e,c			; Calculating Y average
 call Mul_H_E
 ld (MouseYY),hl
MM_Speed = $+1
 ld a,16
 ld (MouseSpd),a
 ret
MM_Difference:		; Moving with the difference
 push hl
 ld de,(KeyPressed+1)
 ld hl,(PrevKeyPressed+1)
 or a
 sbc hl,de
 jr nz,MM_DiffOK
 ld de,(KeyPressed+3)
 ld hl,(PrevKeyPressed+3)
 sbc hl,de
 jr nz,MM_DiffOK
 ld hl,(KeyPressed+5)
 ld a,(PrevKeyPressed+5)
 cp l
 jr nz,MM_DiffOK
 pop hl
 ld a,(MouseSpd)
 dec a
 cp 1
 ret c
 ld (MouseSpd),a
 ret
MM_DiffOK:
 pop hl
 ld e,b			; Calculating X difference
 ld a,h
 call Mul_H_E
 push hl
 ld de,(MouseXX)
 or a
 sbc hl,de
 ld de,(MouseSpd)
 ld b,e
 ld de,(MouseX)		; Moving horizontally
 ex de,hl
MM_DiffX:
 add hl,de
 djnz MM_DiffX
 ld (MouseX),hl
 pop hl
 ld (MouseXX),hl	; Updating average
 ld h,a
 ld e,c			; Calculating Y difference
 call Mul_H_E
 push hl
 ld de,(MouseYY)
 or a
 sbc hl,de
 ld a,(MouseSpd)
 ld b,a
 ld de,(MouseY)		; Moving vertically
 ex de,hl
MM_DiffY:
 add hl,de
 djnz MM_DiffY
 ld (MouseY),hl
 pop hl
 ld (MouseYY),hl	; Updating average
 ret

MouseAverage:
 ld h,0			; divisor
 ld b,h			; X acc
 ld c,h			; Y acc
 ld d,h
 ld a,(KeyPressed+1) \ cpl \ and $3e \ jr z,MA_1_OK
 ld ix,MouseSumTable \ ld e,a \ add ix,de
 ld c,(ix)
 ld h,(ix+1)
 ld a,h \ add a,a \ add a,a \ ld b,a
MA_1_OK:
 ld a,(KeyPressed+2) \ cpl \ and $3e \ jr z,MA_2_OK
 ld ix,MouseSumTable \ ld e,a \ add ix,de
 ld a,(ix) \ add a,c \ ld c,a
 ld a,(ix+1) \ ld l,a \ add a,h \ ld h,a
 ld a,l \ add a,a \ add a,l \ add a,b \ ld b,a
MA_2_OK:
 ld a,(KeyPressed+3) \ cpl \ and $3e \ jr z,MA_3_OK
 ld ix,MouseSumTable \ ld e,a \ add ix,de
 ld a,(ix) \ add a,c \ ld c,a
 ld a,(ix+1) \ ld l,a \ add a,h \ ld h,a
 ld a,l \ add a,a \ add a,b \ ld b,a
MA_3_OK:
 ld a,(KeyPressed+4) \ cpl \ and $3e \ jr z,MA_4_OK
 ld ix,MouseSumTable \ ld e,a \ add ix,de
 ld a,(ix) \ add a,c \ ld c,a
 ld a,(ix+1) \ ld l,a \ add a,h \ ld h,a
 ld a,l \ add a,b \ ld b,a
MA_4_OK:
 ld a,(KeyPressed+5) \ cpl \ and $3e \ jr z,MA_5_OK
 ld ix,MouseSumTable \ ld e,a \ add ix,de
 ld a,(ix) \ add a,c \ ld c,a
 ld a,(ix+1) \ add a,h \ ld h,a
MA_5_OK:
 ; b/h = x; c/h = y
 ret

MouseSumTable:
 .db 0, 0	; 00000
 .db 4, 1	; 00001
 .db 3, 1	; 00010
 .db 7, 2	; 00011
 .db 2, 1	; 00100
 .db 6, 2	; 00101
 .db 5, 2	; 00110
 .db 9, 3	; 00111
 .db 1, 1	; 01000
 .db 5, 2	; 01001
 .db 4, 2	; 01010
 .db 8, 3	; 01011
 .db 3, 2	; 01100
 .db 7, 3	; 01101
 .db 6, 3	; 01110
 .db 10, 4	; 01111
 .db 0, 1	; 10000
 .db 4, 2	; 10001
 .db 3, 2	; 10010
 .db 7, 3	; 10011
 .db 2, 2	; 10100
 .db 6, 3	; 10101
 .db 5, 3	; 10110
 .db 9, 4	; 10111
 .db 1, 2	; 11000
 .db 5, 3	; 11001
 .db 4, 3	; 11010
 .db 8, 4	; 11011
 .db 3, 3	; 11100
 .db 7, 4	; 11101
 .db 6, 4	; 11110
 .db 10, 5	; 11111

MouseDivTable:
 .db 0
; .db 255, 128, 85, 64, 51
; .db 43, 37, 32, 28, 26
; .db 23, 21, 20, 18, 17
; .db 16, 15, 14, 13, 13
; .db 12, 12, 11, 11, 10
 .db 64, 32, 21, 16, 13
 .db 11, 9, 8, 7, 6
 .db 6, 5, 5, 5, 4
 .db 4, 4, 4, 3, 3
 .db 3, 3, 3, 3, 3

Mul_H_E:
  ld d,0
  ld l,d
  ld b,8
Mul_H_E_Loop:
  add hl,hl
  jp nc,Mul_H_E_Skip
  add hl,de
Mul_H_E_Skip:
  djnz Mul_H_E_Loop
  ret

MouseX:
 .db 0, 48
MouseY:
 .db 0, 32
MouseXX:
 .db 0, 128
MouseYY:
 .db 0, 128
MouseSpd:
 .db 0
input.inc:

Code: Select all

ReadKeyboard:		; Fills 7 bytes at KeyPressed; if a key is pressed, the corresponding
 ld hl,KeyPressed
 ld de,PrevKeyPressed
 ld bc,7
 ldir
 ld hl,KeyPressed	; bit is set to ZERO. Works with disabled interrupts as well.
 ld b,7
 ld c,$fe
RK_Loop:
 ld a,$ff
 out (1),a
 ld a,c
 out (1),a
 in a,(1)
 ld (hl),a
 inc hl
 rlc c
 djnz RK_Loop
 ret

ValidateKeys:		; Fills the ValidKey array; if a key was just pressed, the corresponding
 ld hl,KeyPressed	; bit is reset (zeroed). Must be called after ReadKeyboard.
 ld de,KeyState
 ld ix,ValidKey
 ld b,7
VK_Loop:
 ld a,(de)
 or (hl)
 ld (ix),a
 ld a,(hl)
 cpl
 ld (de),a
 inc hl
 inc de
 inc ix
 djnz VK_Loop
 ret

; Data used by input.inc

KeyPressed:		; bit:	7	6	5	4	3	2	1	0
 .byte 255		;					up	right	left	down
 .byte 255		;		clear	^	/	*	-	+	enter
 .byte 255		;		vars	tan	)	9	6	3	(-)
 .byte 255		;	stat	prgm	cos	(	8	5	2	.
 .byte 255		;	X	matrx	sin	,	7	4	1	0
 .byte 255		;	alpha	math	x^-1	x^2	log	ln	sto
 .byte 255		;	del	mode	2nd	y=	window	zoom	trace	graph

KeyState:		; Auxiliary array to validate keys
 .byte 0,0,0,0,0,0,0

ValidKey:		; Valid keys: keys pressed since the last check
 .byte 255,255,255,255,255,255,255

PrevKeyPressed:		; Previous values of KeyPressed
 .byte 255,255,255,255,255,255,255
notes I wrote:

Code: Select all

buttons used for movement:

x^-1 sin cos tan  ^
x^2   ,   (   )   /
log   7   8   9   *
 ln   4   5   6   -
 ->   1   2   3   +

algorithm:

- calculate average x, y
- subtract previous average
- divide by frame time / accumulate changes
- use average of changes over some frames' time

average:

01100 - xx += 3; yy += 2*0; d += 2
11000 - xx += 1; yy += 2*1; d += 2
00010 - xx += 2; yy += 1*2; d += 1
00000 - xx += 0; yy += 0*3; d += 0
00000 - xx += 0; yy += 0*4; d += 0

x: (1+2+0+1+3)/5=7/5=1.4=xx/d
y: (0+0+1+1+2)/5=4/5=0.8=yy/d

      X  D
00000 0  0
00001 4  1
00010 3  1
00011 7  2
00100 2  1
00101 6  2
00110 5  2
00111 9  3
01000 1  1
01001 5  2
01010 4  2
01011 8  3
01100 3  2
01101 7  3
01110 6  3
01111 10 4
10000 0  1
10001 4  2
10010 3  2
10011 7  3
10100 2  2
10101 6  3
10110 5  3
10111 9  4
11000 1  2
11001 5  3
11010 4  3
11011 8  4
11100 3  3
11101 7  4
11110 6  4
11111 10 5

a/x-b/y=(ya-xb)/xy

a/x=a*256/x/256

256/x; x=0..25:
oo
255, 128, 85, 64, 51
43, 37, 32, 28, 26
23, 21, 20, 18, 17
16, 15, 14, 13, 13
12, 12, 11, 11, 10
KevinJB
Calc Wizard
Posts: 501
Joined: Sat 28 May, 2005 5:34 am
Location: Chesapeake, Virginia
Contact:

Post by KevinJB »

:excited: :excited: :excited:

Thanks! Not that I understand ((1/4)^(2/1)^(1/2)4/1) / 1 of that, but oh well...
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
KevinJB | RevSoft
Patori
Maxcoderz Staff
Posts: 1479
Joined: Sat 18 Dec, 2004 3:51 am
Location: Toledo, Ohio, USA

Post by Patori »

Fixed the Spam in this thread....
Fixed lecks quotes

Nice, CoBB
Currently coming up with a new signature idea... since my forum avatar changer was killed by an upgrade...
User avatar
kalan_vod
Calc King
Posts: 2932
Joined: Sat 18 Dec, 2004 6:46 am
Contact:

Post by kalan_vod »

CoBB can you compile it for us who are too lazy? :D
Mike K
New Member
Posts: 59
Joined: Sun 16 Jan, 2005 3:25 am
Location: St. Louis
Contact:

Post by Mike K »

Wow I'm surprised this came to concept code. I'll try compiling it and get a video or something.

BTW, cobb, since you've played around with the program, can you think of any practical uses for it?

-Mike
User avatar
KermMartian
Calc Wizard
Posts: 549
Joined: Tue 05 Jul, 2005 11:28 pm
Contact:

Post by KermMartian »

I made this in BASIC after seeing this thread...the code was 3 lines, and incredibly fast for basic. Awesome concept.
Image Image Image
DarkerLine
Calc Wizard
Posts: 526
Joined: Tue 08 Mar, 2005 1:37 am
Location: who wants to know?
Contact:

Post by DarkerLine »

post?
just try to be nice to people.
_________________
My TI Blog - http://mpl.unitedti.org/
KevinJB
Calc Wizard
Posts: 501
Joined: Sat 28 May, 2005 5:34 am
Location: Chesapeake, Virginia
Contact:

Post by KevinJB »

After all, if it's truly only three lines and that fast?
09 F9 11 02 9D 74 E3 5B D8 41 56 C5 63 56 88 C0
KevinJB | RevSoft
User avatar
KermMartian
Calc Wizard
Posts: 549
Joined: Tue 05 Jul, 2005 11:28 pm
Contact:

Post by KermMartian »

The applicable lines:
BASIC Code wrote::Repeat K=105:getKey→K
:If K>45 and K<96:Then:int(.1K)-7→A
:K-3-10int(.1K)→B:End

Generated by SourceCoder, © 2005 Cemetech
Here's the whole program, let's you sketch with the touch keyboard method:
BASIC Code wrote::ClrDraw
:DelVar ADelVar B
:47→C:31→D
:Repeat K=105
:getKey→K
:If K>45 and K<96:Then
:int(.1K)-7→A
:K-3-10int(.1K)→B
:End
:A+D→D:B+C→C
:If D<0:Then
:0→A:0→D:End
:If D>61:Then
:0→A:61→D:End
:If C<0:Then
:0→B:0→C:End
:If C>94:Then
:0→B:94→C:End
:Pxl-On(D,C
:End
Generated by SourceCoder, © 2005 Cemetech
(and yes, I know I can optimize all those 0→N lines. :)
Image Image Image
User avatar
kalan_vod
Calc King
Posts: 2932
Joined: Sat 18 Dec, 2004 6:46 am
Contact:

Post by kalan_vod »

Doesn't source coder do that?
Wow kerm this works amazingly well, and it's fast enough so it would need to be asm :P.

Edit: Download it here if your too lazy from getting it on your calc.
User avatar
KermMartian
Calc Wizard
Posts: 549
Joined: Tue 05 Jul, 2005 11:28 pm
Contact:

Post by KermMartian »

kalan_vod wrote:Doesn't source coder do that?
Wow kerm this works amazingly well, and it's fast enough so it would need to be asm :P.

Edit: Download it here if your too lazy from getting it on your calc.
Please wait while the system analyzes the sarcasm content of previous input...
Image Image Image
User avatar
kalan_vod
Calc King
Posts: 2932
Joined: Sat 18 Dec, 2004 6:46 am
Contact:

Post by kalan_vod »

KermMartian wrote:
kalan_vod wrote:Doesn't source coder do that?
Wow kerm this works amazingly well, and it's fast enough so it would need to be asm :P.

Edit: Download it here if your too lazy from getting it on your calc.
Please wait while the system analyzes the sarcasm content of previous input...
Hehe, yeah I meant that if your too lazy to put it into the debugger and and change the -> and the optimization of the 0->N.
Post Reply