Weird issue

If you have questions about any aspect of QBasic programming, or would like to help fellow programmers solve their problems, check out this board!

Moderators: Pete, Mods

Post Reply
TmEE
Veteran
Posts: 97
Joined: Mon Mar 17, 2008 11:14 am
Location: Estonia, Rapla
Contact:

Weird issue

Post by TmEE »

Code: Select all

DIM SHARED OrderTable%(255, 6) 'Order table
DIM SHARED CopyPaste&(63)      'CopyPaste buffer

COMMON SHARED HANDLE%, MBASE%, speed%, SCOUNT%, QUIT%, TMFROW%, ORDERROW%
COMMON SHARED TMFLEN%, TMFPAT%, EXITS%, PAGE%, MX%, MY%, MB%, COCTAVE%
COMMON SHARED KEYS%, TRACKPOS%, SAC%, PLAYMOD%, SEGM%, OFFSET&, OFFSET2&
COMMON SHARED Title$, Author$, Notes$, TMFdate$, CURPOS%, LASTCUR%, Ch1%
COMMON SHARED NOOT%, OKTAV%, OCTPLUS%, NOTE%, octave%, EFFECT%, VALUE%
COMMON SHARED EDITCH%, LCPOS%, CPOS%, DRUM%, i%, L%, C%, C2%, START%, ISPEED%
COMMON SHARED OFFS%, XOFF&, BYTES&, ERRR%, LASTCUR2%, CURPOS2%, EDITPOS%
COMMON SHARED ZSEG%, XSEG%, CDIR$, TMFfileName$, UPDATEPOS%, COPYSTART%
COMMON SHARED COPYLEN%, SHIFTON%, COPYCH%, COPYS%, COPYPASTELEN%, ERR2%
COMMON SHARED PLAYINLOOP%, LOOPVAL%, CHAN%, CTRL%, PATCH%, SPD%, DIR%
COMMON SHARED SHIFTSTART%, SHIFTEND%, LOOPORDER%, ECH%, EDITENABLE%


SUB EDITCOPY
COPYPASTELEN% = COPYLEN%
COPYEND% = COPYSTART% + COPYLEN%: ii% = 0
FOR i% = COPYSTART% TO COPYEND%
SELECT CASE EDITCH%
CASE 0: ECH% = 0
CASE 1: ECH% = 1
CASE 2: ECH% = 2
CASE 3: ECH% = 3
CASE 4: ECH% = 4
CASE 5: ECH% = 5
CASE 6: ECH% = 6
CASE 7: ECH% = 6
CASE 8: ECH% = 7
END SELECT
CopyPaste&(ii%) = Patterns&(i%, ECH%)
IF EDITCH% = 7 THEN CopyPaste&(ii%) = CopyPaste&(ii%) \ 65536
ii% = ii% + 1
NEXT i%
END SUB

SUB EDITDELETE
COPYEND% = COPYSTART% + COPYLEN%
FOR i% = COPYSTART% TO COPYEND%
SELECT CASE EDITCH%
CASE 0: ECH% = 0
CASE 1: ECH% = 1
CASE 2: ECH% = 2
CASE 3: ECH% = 3
CASE 4: ECH% = 4
CASE 5: ECH% = 5
CASE 6: ECH% = 6
CASE 7: ECH% = 6
CASE 8: ECH% = 7
END SELECT
IF ECH% = 6 THEN
A& = Patterns&(i%, ECH%)
IF EDITCH% = 6 THEN A& = (A& AND &HFFFF0000)
IF EDITCH% = 7 THEN A& = (A& AND 65535)
Patterns&(i%, ECH%) = A&
ELSE
Patterns&(i%, ECH%) = 0
END IF
NEXT i%
END SUB
Here's some part of the code in a tracker I'm making, and there's some weird shit going on.

To do CUT function, I call EDITCOPY and EDITDELETE, but when EDITDELETE is called, the CopyPaste buffer is empty....

Sorry for non-commented code...

any ideas ?
Mida sa loed ? Nagunii aru ei saa :P
mestrinho
Coder
Posts: 12
Joined: Mon Mar 31, 2008 10:44 am

Post by mestrinho »

1) In both your editcopy and editdelete SUBs, variable editch% is "non-varying" i.e., it is constant for the whole cycle, so why keep comparing it (select case) for the whole "for to" cycle if it always same ?

2) if copylen% is real length to copy, then should be:
COPYEND% = COPYSTART% + COPYLEN% - 1
otherwise you are copying one more "unit" than desired length in cycle:
FOR i% = COPYSTART% TO COPYEND%

3) What value should ECH% be when EDITCH% is not in range 0 thru 8 ?
TmEE
Veteran
Posts: 97
Joined: Mon Mar 17, 2008 11:14 am
Location: Estonia, Rapla
Contact:

Post by TmEE »

EDITCH% is the current channel i'm on the tracker and ECH% is there because there's 2 channels in 1 in one of the dimensions of the Patterns$ array... just a stupid way my tracker works after one addition.

COPYLEN% is already 1 unit smaller so need to make it smaller.

EDITCH% is ALWAYS in the range of 0...8, if not, there'll be an error.
Mida sa loed ? Nagunii aru ei saa :P
mestrinho
Coder
Posts: 12
Joined: Mon Mar 31, 2008 10:44 am

Post by mestrinho »

Simplify:

SUB EDITCOPY
COPYPASTELEN% = COPYLEN%
COPYEND% = COPYSTART% + COPYLEN%: ii% = 0
ECH% = EDITCH% + EDITCH% > 6
FOR i% = COPYSTART% TO COPYEND%
CopyPaste&(ii%) = Patterns&(i%, ECH%)
IF EDITCH% = 7 THEN CopyPaste&(ii%) = CopyPaste&(ii%) \ 65536
ii% = ii% + 1
NEXT i%
END SUB

SUB EDITDELETE
COPYEND% = COPYSTART% + COPYLEN%
ECH% = EDITCH% + EDITCH% > 6
FOR i% = COPYSTART% TO COPYEND%
IF ECH% = 6 THEN
Patterns&(i%, ECH%) = (Patterns&(i%, ECH%) AND &HFFFF0000)
ELSE
Patterns&(i%, ECH%) = 0
END IF
NEXT i%
END SUB


"IF EDITCH% = 7 THEN A& = (A& AND 65535)" will never be executed because it is in a if / then condition that is only executed when ECH% = EDITCH% = 6 !!!
TmEE
Veteran
Posts: 97
Joined: Mon Mar 17, 2008 11:14 am
Location: Estonia, Rapla
Contact:

Post by TmEE »

???? ECH% = EDITCH% + EDITCH% > 6 ?????

Your EDITDELETE won't work as it will kill both channels, it only needs to do so for one (one is first WORD, other is other...), depending on on ECH%. ECH% marks the Dimension in array, and EDITCH% the channels, and ECH% 6 contains 2 channels (EDITCH% 6 and 7)

my question was why one CopyPaste array is blank after EDITCOPY and EDITDELETE
Mida sa loed ? Nagunii aru ei saa :P
mestrinho
Coder
Posts: 12
Joined: Mon Mar 31, 2008 10:44 am

Post by mestrinho »

In your code, for each and every i%, results obtained are as follows:

Code: Select all

Case		Then
EDITCH%	ECH%
=			=	
0			0	Patterns&(i%, 0) = 0
1			1	Patterns&(i%, 1) = 0
2			2	Patterns&(i%, 2) = 0
3			3	Patterns&(i%, 3) = 0
4			4	Patterns&(i%, 4) = 0
5			5	Patterns&(i%, 5) = 0
6			6	Patterns&(i%, 6) = Patterns&(i%, 6) AND &HFFFF0000
7			6	Patterns&(i%, 6) = Patterns&(i%, 6) AND 65535
8			7	Patterns&(i%, 7) = 0
Is this what you pretend ?
TmEE
Veteran
Posts: 97
Joined: Mon Mar 17, 2008 11:14 am
Location: Estonia, Rapla
Contact:

Post by TmEE »

Yes, that's what I do
Mida sa loed ? Nagunii aru ei saa :P
mestrinho
Coder
Posts: 12
Joined: Mon Mar 31, 2008 10:44 am

Post by mestrinho »

TmEE

Are you sure that array Patterns&() has data in it when you call EditCopy and NO data when you call EditDelete ?

I am asking because EditCopy does not modify array Patterns&()... so if array Patterns&() really has data when SUB EditCopy is called and NO data when EditDelete is called, then it probably is because of another SUB you are using ... ? do not forget you are not modifying in any way Patterns&() in sub EditCopy...
TmEE
Veteran
Posts: 97
Joined: Mon Mar 17, 2008 11:14 am
Location: Estonia, Rapla
Contact:

Post by TmEE »

the Patterns& array is global too, I've forgotten the line in first post... it ALWAYS contains pattern data for all channels in all cases.

EditCopy does not have to modify the Patterns&, it has to copy certain amount of data form certain area to CopyPaste& array. That's for copying, CUT command is copy selection and delete it, and so I do EditCopy, data gets to buffer, and EditDelete that kills the selection in Patterns& that got copied to buffer, BUT, for some reason the buffer is empty after EditDelete... and EditDelete does not touch the buffer at all...
Mida sa loed ? Nagunii aru ei saa :P
mestrinho
Coder
Posts: 12
Joined: Mon Mar 31, 2008 10:44 am

Post by mestrinho »

oh well... there is a way to know if it is the EditDelete sub that is doing something... immediately before calling the sub, make a copy of the buffer, call the sub and on its exit, compare the buffers contents with its former copy...
TmEE
Veteran
Posts: 97
Joined: Mon Mar 17, 2008 11:14 am
Location: Estonia, Rapla
Contact:

Post by TmEE »

nothing's wrong.... I need to try sometihng... EDITCOPY, EDITDELETE, buffer empty, EDITCOPY, do something else then EDITDELETE, fine...... I'll put some extra between the two calls....

EDIT : Did weird stuffs, and nothing helped.... kinda seems like the array is wiped after EDITDELETE... now trying one other thing....

EDIT : I copied the code out of both routines and CopyPaste& gets wiped only when I modify Patterns& is modified.... and came out that the value I put into Patterns& in delete routine ends up in CopyPaste& too ..... !!!!! WTH is going on !?
Post Reply