Create a free forum in seconds.
zIFBoards - Free Forum Hosting
Welcome to Cemetech Forum Home. We hope you enjoy your visit.


You're currently viewing our forum as a guest. This means you are limited to certain areas of the board and there are some features you can't use. If you join our community, you'll be able to access member-only sections, and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.


Join our community!


If you're already a member please log in to your account to access all of our features:

Name:   Password:


 

 Help With Interrupt Based Input
b-flat
Posted: Sep 15 2007, 05:16 PM


Newbie


Group: Members
Posts: 4
Member No.: 161
Joined: 13-September 07



What is wrong with the following code to get basic string input on the homescreen? The cursor blinking works fine (i.e. when I comment out all of the key input code), but once I put it back in, it doesn't matter if I press a key or not, I get an immediate RAM clear.

CODE
b_call(_clrlcdfull)
ld hl,0
ld (currow),hl
di
ld hl,int
ld ($993F),hl
ld ($997F),hl
ld ($99BF),hl
ld ($99FF),hl
ld a, $99
ld i,a
ld a,00001011b
out (3),a
im 2
ei
ld a, $EF
out (1),a

keyloop:
ld a,(keywait)
or a
jr z,key2
dec a
ld (keywait),a

key2:
in a,(1)
cp $FE
jp z,zero
cp $FD
jp z,one
cp $FB
jp z,four
cp $F7
cp z,seven
cp $EF
jp nz,keyloop
ld a,00001011b
out (3),a
im 1
ret

zero:
ld a,"0"
jr add
one:
ld a,"1"
jr add
four:
ld a,"4"
jr add
seven:
ld a,"7"

add:
ld b,a
ld a,(keywait)
or a
jp nz,keyloop
ld a,20
ld (keywait),a
ld a,b
b_call(_putc)

int:
ex af,af'
exx
xor a
out (3),a
ld a,(curtemp)
b_call(_putmap)
ld a,(counter)
dec a
ld (counter),a
or a
jp nz,int3
ld a,$30
ld (counter),a
ld a,(curtemp)
cp $20
jp z,int2
ld a,$20
ld (curtemp),a
jp int3

int2:
ld a,$E0
ld (curtemp),a

int3:
ld a,00001011b
out (3),a
ex af,af'
exx
ret

counter:
.db $30
curtemp:
.db $E0
keywait:
.db 20


Sorry that it might not be in the correct format, but I copied it by hand (coded on calc).


--------------------
Top
brandonw
Posted: Sep 16 2007, 01:49 AM


Newbie


Group: Members
Posts: 2
Member No.: 186
Joined: 15-September 07



I really don't recommend doing assembly oncalc, because it's just slow and is only going to cause you headaches and more trouble down the road, like right now.

Why are you using interrupts for this? It's completely unnecessary. You could use the usual _getKey loop and call _CursorOn beforehand, and _CursorOff to turn it off. The cursor will blink during _getKey.

Or even better, use the undocumented string input BCALL:
GetStringInput:
4E5Eh:
Gets a string of input from the user.
Input: MUST reset 6,(iy+1Ch) and set 7,(iy+9).
ioPrompt contains the prompt string.
Output: string stored in temporary equation 04h,2Dh,00h,00h.
It basically calls _newContext on 50h, Mon, then _newContext on 3Fh.
4E61h is identical except it does set 1,(iy+9) instead of reset (not sure of significance).

It's just like BASIC's Prompt or Input, and it's a little bit clunky, especially if you use [2nd]+[QUIT] (you'll get a memory leak because the program didn't end properly), so probably the smartest thing to do is jump into saferam and delete yourself, so that if you exit too early, you don't get a memory leak. But this also makes leaving the program a little bizarre, so it's up to you (you could set a keyhook earlier to block [2nd]+[QUIT] and stuff like that). Here's some code which uses it:

CODE

programStart:
       ld hl,codeStart
       ld de,appBackUpScreen
       ld bc,codeEnd-codeStart
       ldir;copy code to saferam
       ld hl,promptString
       ld de,ioPrompt
       bcall(_strcopy);copy prompt string
       jp appBackUpScreen
promptString:
       .db "Enter string:",0
codeStart:
       ld hl,userMem
       ld de,programEnd-programStart
       bcall(_DelMem);delete myself so no memory leaks
       ld b,(iy+9)
       ld c,(iy+1Ch)
       push bc;back up old flag values
       res 6,(iy+1Ch)
       set 7,(iy+9)
       bcall(4E5Eh);_GetStringInput
       pop bc
       res 4,b;restore old flag values
       ld (iy+9),b
       ld (iy+1Ch),c
       ld hl,2Dh
       ld (OP1+1),hl
       rst 10h;look up temporary equation 04h,2Dh,00h,00h
       ex de,hl
       ld c,(hl)
       inc hl
       ld b,(hl)
       inc hl
     ;HL points to data in RAM, BC is number of bytes
       bcall(_JForceCmdNoChar);done, return to OS
codeEnd:
programEnd:


I also wouldn't be using this exact method in a shell or game, it'd be better to set a keyhook to block the troublesome things (you can back up whatever old keyhook was installed first).
Top
calc84maniac
Posted: Sep 16 2007, 07:41 AM


Newbie


Group: Members
Posts: 3
Member No.: 172
Joined: 14-September 07



He's trying to code for the new OS. (He'll replace the text routines later I guess.)
Top
brandonw
Posted: Sep 16 2007, 11:51 PM


Newbie


Group: Members
Posts: 2
Member No.: 186
Joined: 15-September 07



And what new OS is this?
Top
kermmartian
Posted: Sep 17 2007, 06:41 AM


Omniscient Guru


Group: Admin
Posts: 3,789
Member No.: 1
Joined: 15-July 04



QUOTE (brandonw @ Sep 16 2007, 11:51 PM)
And what new OS is this?

I'd guess either the theoretical OS that OTBP members have been tossing around, or the new-and-improved Vera that Timendus wants to introduce.


--------------------
xsibhgrmz xsibhgrmz xsibhgrmz xsibhgrmz xsibhgrmz xsibhgrmz xsibhgrmz xsibhgrmz xsibhgrmz xsibhgrmz xsibhgrmz xsibhgrmz xsibhgrmz
user posted image
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | z80 Assembly | Next Newest »
DealsFor.me - The best sales, coupons, and discounts for you

Topic Options



Hosted for free by zIFBoards* (Terms of Use: Updated 2/10/2010) | Powered by Invision Power Board v1.3 Final © 2003 IPS, Inc.
Archive