why wont this routine work.. works fine in 64 mode..

Started by stiggity, July 12, 2010, 07:25 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

LokalHorst

#25
that's not right, so I try to explain:

at the point labeled 'STR3' you've found the string descriptor of B$ (length of str, ptr to the str data)
STR3
INY
jsr fetch1 ;get length of B$
pha ;remember
INY
jsr fetch1  ;get lo byte of str. ptr.
STA $FD ;set up a second ZP-pointer
INY
jsr fetch  ;get hi byte of str. ptr.
STA $FE
PLA
TAY ;now Y holds the length of B$
Loop
LDA BUFFER,Y ;fetch your buffered data
JSR store1 ;store to B$
DEY
BNE Loop
RTS

store1 ldx #$FD ; use pointer $FD/$FE
stx $02b9
ldx #$01
jmp $ff77 ;INDSTA

fetch1 LDA  #$BB ;ZP pointer to use
LDX  #$01 ;bank index 1 (corrected)
JMP  $FF74 ;INDFET

I've renamed fet2 to store1 to avoid confusion. The string B$ has to be set up in advance with the max. # of chars that your input uses or you'll end up overwriting other strings.

stiggity

Lokal:
I appreciate you trying to explain, and i want this routine to work Sooooo bad, but im still lost.. here is what i have now that you have replied, and im even more lost. What you wrote didnt make any sense..

STROUT LDA $2F
STA $BB
LDA $30
STA $BC
STR1 LDY #$00
jsr fetch1
CMP #66
BNE STR2
INY
jsr fetch1
CMP #$80
BEQ STR3
STR2 CLC
LDA $BB
ADC #$07
STA $BB
LDA $BC
ADC #$00
STA $BC
JMP STR1
STR3 INY
jsr fetch1
pha
iny
jsr fetch1
sta $fd
iny
jsr fetch1
sta $fe
pla
tay
loo lda buffer0,y
jsr store1
dey
bne loo
rts

store1 ldx #$fd
sta $02b9
ldx #$01
jmp $ff77


please dont give up on me, im actually okay on the computer's.. ;-/

LokalHorst

#27
you forgot to tell which part don't make sense :)
(your last reply looks like mine without the fetch1 sub)
I found an error in your store1 sub - it has to be STX $02b9 not STA $02b9 (A holds the value to store)

stiggity

Lokal:
The part that doesnt make sense is this..

STROUT LDA $2f
STA $BB
LDA $30
STA $BC
STR1 LDY #$00
jsr fetch1
CMP #66
BNE STR2
INY
jsr fetch1
CMP #$80
BEQ STR3
STR2 CLC
LDA $BB
ADC #$07
STA $BB
LDA $BC
ADC #$00
STA $BC
JMP STR1
STR3 INY    ;when i get to STR3 I increase "Y" load in b$ length into accum, then store1
LDA NY
jsr fet2
INY       
LDA #<BUFFER0      ;lobyte of buffer0
jsr fet2  ; STA ($BB),Y ;store it
INY
LDA #>BUFFER0     ;hi byte of buffer0
jsr fet2  ; STA ($BB),Y  ;store it
RTS    ; now in basic i should be able to just type print b$ and the contents of BUFFR0 will be in b$, ive used this routine all the time on the 64.. maybe the last routine u sent me wasnt right or something, im not saying im right and your wrong, just trying to make sense of your 2nd to last reply..

store1 ldx #$bb
stx $02b9
ldx #$01
jmp $ff77


fetch1 LDA  #$BB ;ZP pointer to use
LDX  #1 ;bank index 15
JMP  $FF74 ;kernal

BigDumbDinosaur

Quote from: LokalHorst on July 17, 2010, 09:46 AM1. IRQ Clock on VDC -> possible but difficult (if concurrent access happens)
See Clock-Calendar 128 and the 80 Column Display Manager, the combination of which can drive a live clock display on a fixed status line without any ill effects from concurrent access.  It's all done through interrupts and the code runs under the kernel ROM.

Quote2. more ml space -> as you're using already the rs232 buffers ($0c00/$0d00) only one block in low mem remains $0b00-$0bff used during boot to hold the boot sector. More space by move the basic start up with graphic cmd for ex. (to $4000)
The sprite definition area ($0E00-$0FFF) is also available if he's not using sprites.  The 40 column text screen map ($0400-$07FF) is available if only the 80 column display will be in use.  Another possibility is lowering the top of BASIC pointer ($1212-$1213) and running his M/L in the space above.  The only problem is he won't be able to access any BASIC routines unless he places a custom cross-bank handler somewhere in low common RAM.  Can be done but starts to get messy, as existing cross-bank code in page 2 can't be disturbed without breaking much of the system.

Quote3. store to bank 1 -> kernal INDSTA $FF77
He could also directly call the STASH routine at $02AF, which is more flexible than using INDSTA.  The kernel call uses bank numbers that don't necessarily equate to the memory config he is running, whereas STASH uses the MMU config register mask in .X to establish any memory map that is desired.  There's a slight speed improvement as well, although not important unless many calls are being made inside a loop.
x86?  We ain't got no x86.  We don't need no stinking x86!

LokalHorst

that's not what I wrote:
STR3 INY    ;when i get to STR3 I increase "Y" load in b$ length into accum, then store1
- at this point you don't have any string length in acc & you ingnore the preceding lookup from above now in $bb/$bc

LDA NY  <- what is this ?
jsr fet2 <- this writes to the descriptor not the data
INY       
LDA #<BUFFER0      ;lobyte of buffer0 <- this is an address not data
jsr fet2  ; STA ($BB),Y ;store it
INY
LDA #>BUFFER0     ;hi byte of buffer0
jsr fet2  ; STA ($BB),Y  ;store it
RTS

each call to fetch1 or store1 reads/writes 1 byte from/to bank1 mem.
If you had copied my example and set up the B$ (you don't want to replicate string allocation/garbage collection) your routine would work as expected.
It looks like you're trying to replace the descriptor data - basic looks in bank1 only for descriptors and associated data, you can't replace it with a pointer to bank0.



stiggity

Lokal:
I appreciate the help. I got it working very well. I dont know what i was doing wrong last time.. heres a few _more_ questions..

1)Am i gong to have to (in BASIC) "fill" b$ with characters greater than the maximum length each time i use b$..

2)after my input routine, and i use the fetch/store1 routine u helped me discover, the buffer _is_ in b$, except the first character is whatever i used to "fill in" b$. Like if i type "STEVE" in, and store it into BUFFER, after i call the routine u helped me with, i'll do a "print b$" and itll say "-TEVE" its cutting off the first letter of the inputed data, and replacing it with the dummy characters i filled b$ with??? any thoughts? im going to play with the Y register and see what i can come up with .. thanks again, and i hope your not insulted that i was so stupid and didnt understand yer example code..

-Steve Bell
telnet://fodim.bounceme.net:23


bacon

Quote from: stiggity on July 17, 2010, 05:00 AM
Assuming im using bank15, my ML starts @ $1300 and right now goes as high as 1BFF. Where else can i store my machine language routines?? Is there a way to swap out basic, and store ML underneath? can i use $1300 to $3FFF?
Don't you read the answers to your posts? In my second reply I gave you two links to articles explaining all you need to know about this. Please read the material people point you to. Then, if you don't understand it, read it again. If you still don't get anywhere, then is the time to ask people on the forum for help.
Bacon
-------------------------------------------------------
Das rubbernecken Sichtseeren keepen das cotton-pickenen Hands in die Pockets muss; relaxen und watschen die Blinkenlichten.

stiggity

Bacon:
Of course i read replies.. im not an idiot. Lokalhorst has been helping me alot, and he doesnt freak-out when something is "sub-par" anywayz..

Lokalhorst:
I got your routine working perfectly, except this. somehow, im going to need a routine that corrects b$'s length.... I have the b$ len stored, but the way this routine works is, if i declare b$ with a b$="**********" 10 *'s.. and i have "STEVE" in buffer0, when i call your routine, b$ _does_ display "STEVE" but then a "print len(b$)" equals 10...and since i have no way of knowing the users desired string length, or a method to somehow change b$'sl length with the Y index of my buffer0, which is "NY"
any help, would rule..

-Steve

LokalHorst

Hi Steve,

yes there was a small bug in my example - I was lazy and used Y-reg as loop count and offset to the buffer - while loop count is ok, the offset isn't (points one byte to far).
correct with:
...
PLA ;length from stack
TAY
loop DEY
LDA Buffer0,Y
JSR store1
TYA
BNE loop
...

here are some interesting links which also point to examples how to interact ML with Basic, and a roughly documented ROM disassembly:
http://www.c128.net/infos/rominfo.htm

you can save a lot of ML-code by using the routines from ROM for variable-lookup etc.
the 2nd link from above mentioned site contains an example of an input ML-routine which returns a string.
http://rvbelzen.tripod.com/128intpt/index.html#13

stiggity

Lokal:
Thanks for the link, I quickly read it, and didnt really grasp it, but im sure the more i look at it, the more it will sink in. Thanks for adding the update to your given routine. I am having another issue with it. If the length of b$ equals 0, and i fill my BUFFER0 and call this routine, b$ equals nothing.. even after using the store1 correctly. Now if i make the length of b$ 40 random characters, then fill my BUFFER0 and call your routine, the correct contents of b$ are inserted, _BUT_ b$ still has the same length as the number of characters i used to fill it. What should i do now?? if b$ equals "STEVE" and i perform a ?len(b$), basic will report 40.. there has to be a way for me to _tell_ this routine how long the BUFFER0 is..and when i convert the buffer to b$, b$ should have the correct length.. Do you have any idea's??

-Steve

LokalHorst

Hi,

the problem with changing string-length (and also if B$ is "") is because your code bypasses basic's string management-routines. Basic maintains a so called string-stack, allocating space from top of the memory ($1feff) downwards. If you simply change the descriptor, this stack gets disturbed/corrupted - without the use of the string-management routines from ROM there is no other way than predefine the string which receives your data, so that a valid descriptor (+ string stack ptr.) exist. You can fill your string with zeros (chr$(0)) to be able to find the end of the actual input, and insert a check for zero length.
If you've downloaded the ROM-listing you're able to follow the example given in the link which uses the rom-code to assign and create a string from a input buffer. (you don't have to copy it exactly - only use the subroutines with locate & create the string of specified length)


stiggity

Lokal:
Your routine is cool, but will not work in my application. As b$ is constantly changing, wether its 1 chaacter, or 5, or 120. Maybe you could lend me another hand, at checking for string sizes, and null buffers?

-Sorry..
-Steve