I've been working on this program for some time (no, not since the 1980's) Its coming along pretty good,but I hit a snag with having the program detect "space" you know char(32) I've even tried char(255) .
right know it's supposed to look for chunks of the users data that matches the GTN code and then convert the data to "now compressed" code that can be transmitted by train.
for right now, if no match is found then the program asumes its a space. but if you type a "." "?" or some other char thats not "ABCDEFGHIJKLMNOPQRSTUVWXYZ " the program pukes.
If you have any suggestions, That would be great.
here is the code and the compression file.
http://www.dsprototyping.com/GTN-0010.BAShttp://www.dsprototyping.com/gtnmx.txtof course they both have to be placed in the:
CODE
c:\GTN-code\
Well, you could change that..
this is the code:
CODE
DECLARE SUB trnbox (over!, down!, ctrr!)
DECLARE SUB bin (datta!)
DECLARE SUB Sartup ()
DECLARE SUB Calcs (data$, Tnotctr!)
DECLARE SUB DataIN (data$)
DECLARE SUB Display ()
DECLARE SUB test (bit())
DECLARE SUB readprinterport ()
DIM SHARED Tnotctr AS SINGLE
DIM SHARED endflag AS STRING
DIM SHARED bit(1 TO 8) AS SINGLE
DIM SHARED line1 AS STRING
DIM SHARED line2 AS STRING
DIM SHARED line3 AS STRING
DIM SHARED line4 AS STRING
DIM SHARED line5 AS STRING
DIM SHARED line6 AS STRING
DIM SHARED line7 AS STRING
DIM SHARED line8 AS STRING
DIM SHARED line9 AS STRING
DIM SHARED line10 AS STRING
DIM SHARED line11 AS STRING
DIM SHARED line12 AS STRING
DIM SHARED line13 AS STRING
DIM SHARED line14 AS STRING
DIM SHARED line15 AS STRING
DIM SHARED line16 AS STRING
DIM SHARED line17 AS STRING
DIM SHARED line18 AS STRING
DIM SHARED line19 AS STRING
DIM SHARED line20 AS STRING
DIM SHARED GTNcode(1 TO 33, 1 TO 33) AS STRING
DIM SHARED train(1 TO 10) AS STRING
DIM SHARED trainV(1 TO 15) AS SINGLE
DIM SHARED trainH(1 TO 15) AS SINGLE
'* Great Train Network controll program.
'* Versions:
'* GTN-00-00-0000
'* GTN-11-25-2008
'* GTN-02-10-2009 screen and subs added
'* GTN-02-17-2009 binary conv added
'* GTN-08-20-2009 added compressor and files (remed out)
'* GTN-08-21-2009 loaded the matrix (well tried)
'* GTN-08-21-2009 matrix(compressor files) loaded into one GTNcode() aray by one file instead of four.
'* GTN-09-19-2009 compressor re write, not looping correctly
'* GTN-09-19-2009 compressor almost works need SPACE detection
'* GTN-09-19-2009 adding train graphics
'* GTN-09-24-2009 worked on train grapics logic, trying to make trainbox
'* GTN-09-28-2009 space detect works, working on train graphics placement.
'* GTN-09-28-2009 added train load routine
Sartup
CLS
SCREEN 13
LOCATE 3, 2: PRINT "Great Train network"
DO WHILE endflag$ = "no"
Display
DataIN data$
Calcs data$, Tnotctr
LOOP
END
SUB bin (datta)
XXX = datta
FOR ctr = 1 TO 8 'reset value to 0
bit(ctr) = 0
NEXT ctr
DO WHILE XXX > 1
'LOCATE 5, 5: PRINT "data"; datta; "XXX "; XXX
SELECT CASE XXX
CASE IS > 128
bit(8) = 1
XXX = XXX - 128
CASE IS > 64
bit(7) = 1
XXX = XXX - 64
CASE IS > 32
bit(6) = 1
XXX = XXX - 32
CASE IS > 16
bit(5) = 1
XXX = XXX - 16
CASE IS > 8
bit(4) = 1
XXX = XXX - 8
CASE IS > 4
bit(3) = 1
XXX = XXX - 4
CASE IS > 2
bit(2) = 1
XXX = XXX - 2
CASE IS > 1
bit(1) = 1
XXX = XXX - 1
END SELECT
LOOP
END SUB
SUB Calcs (data$, Tnotctr)
IF data$ = "exit" OR data$ = "EXIT" THEN
endflag$ = "yes"
GOTO cmpEND1 'skip the rest of the calculations
END IF
IF data$ = "test" THEN
test bit()
GOTO cmpEND1 'skip the rest of the calculations
END IF
'*------------------------------------------------------------------------
'* find the legnth of data$
'lengthdata = LEN(data$)
'* setup loop to run the length of data$ (eg data$ = 4 chars long then loop 4 times)
'* comprPT is our current position in the data$
notctr = 1
lengthdata = LEN(data$)
comprPT = 1
DO WHILE comprPT < lengthdata
'* start from the left and grab some chars
'*-------------------------------------------------------------
compare4:
chunksize = 4 'starting chunk size
chunk4flag$ = "yes"
chunk$ = MID$(data$, comprPT, chunksize) 'grab a chunk
Vctr = 25: Hctr = 1 'start of the 4 chunks
DO WHILE chunk4flag$ = "yes"
IF GTNcode(Vctr, Hctr) = chunk$ THEN 'compare chars to the chart
'train(notctr) = GTNcode(Vctr, Hctr) 'notctr = the number of trains it will take to send the data.
trainV(notctr) = Vctr '
trainH(notctr) = Hctr '
notctr = notctr + 1 'num-of-trains
comprPT = comprPT + 4
chunk4flag$ = "done"
'LOCATE 17, 2: INPUT "found a 4 size chunk:"; enter$
GOTO cmpEND4
ELSE
IF Vctr = 32 AND Hctr = 32 THEN
GOTO cmpEND4
ELSE
IF Hctr > 32 THEN
Hctr = 1
Vctr = Vctr + 1
IF Vctr > 32 THEN
Vctr = 1
END IF
ELSE
Hctr = Hctr + 1
END IF
END IF
END IF
'LOCATE 10, 2: PRINT "# trains-="; notctr
'LOCATE 11, 2: PRINT "comprPT---="; comprPT
'LOCATE 12, 2: PRINT "Vctr-----="; Vctr
'LOCATE 13, 2: PRINT "Hctr-----="; Hctr
'LOCATE 14, 2: PRINT "chunk$---="; chunk$
'LOCATE 15, 2: PRINT "GTNcode--="; GTNcode(Vctr, Hctr)
'LOCATE 17, 2: INPUT "is this the match"; enter$
LOOP 'NEXT
cmpEND4:
'*-------------------------------------------------------------
'* compare3: 'check for size 3 chunk
'Vctr = 18
'Hctr = 15
compare3:
chunksize = 3 'starting chunk size
chunk3flag$ = "yes"
chunk$ = MID$(data$, comprPT, chunksize) 'grab a chunk
Vctr = 18: Hctr = 15 'start of the 4 chunks
DO WHILE chunk3flag$ = "yes"
IF GTNcode(Vctr, Hctr) = chunk$ THEN 'compare chars to the chart
'train(notctr) = GTNcode(Vctr, Hctr) 'notctr = the number of trains it will take to send the data.
trainV(notctr) = Vctr '
trainH(notctr) = Hctr '
notctr = notctr + 1 'num-of-trains
comprPT = comprPT + 3
chunk4flag$ = "done"
'LOCATE 17, 2: INPUT "found a 3 size chunk:"; enter$
GOTO cmpEND3
ELSE
IF Vctr = 24 AND Hctr = 32 THEN
GOTO cmpEND3
ELSE
IF Hctr > 32 THEN
Hctr = 1
Vctr = Vctr + 1
IF Vctr > 32 THEN : Hctr = 1
ELSE
Hctr = Hctr + 1
END IF
END IF
END IF
'LOCATE 10, 2: PRINT "# trains-="; notctr
'LOCATE 11, 2: PRINT "compPT---="; compPT
'LOCATE 12, 2: PRINT "Vctr-----="; Vctr
'LOCATE 13, 2: PRINT "Hctr-----="; Hctr
'LOCATE 14, 2: PRINT "chunk$---="; chunk$
'LOCATE 15, 2: PRINT "GTNcode--="; GTNcode(Vctr, Hctr)
'LOCATE 17, 2: INPUT "is this the match"; enter$
LOOP 'NEXT
cmpEND3:
'*
'*-------------------------------------------------------------
'* compare2: 'check for size 2 chunk
'Vctr = 2
'Hctr = 5
compare2:
chunksize = 2 'starting chunk size
chunk2flag$ = "yes"
chunk$ = MID$(data$, comprPT, chunksize) 'grab a chunk
Vctr = 2: Hctr = 5 'start of the 2 chunks
DO WHILE chunk2flag$ = "yes"
IF GTNcode(Vctr, Hctr) = chunk$ THEN 'compare chars to the chart
'train(notctr) = GTNcode(Vctr, Hctr) 'notctr = the number of trains it will take to send the data.
trainV(notctr) = Vctr '
trainH(notctr) = Hctr '
notctr = notctr + 1 'num-of-trains
comprPT = comprPT + 2
chunk4flag$ = "done"
'LOCATE 17, 2: INPUT "found a 2 size chunk:"; enter$
GOTO cmpEND2
ELSE
IF Vctr = 18 AND Hctr = 14 THEN
GOTO cmpEND2
ELSE
IF Hctr > 32 THEN
Hctr = 1
Vctr = Vctr + 1
IF Vctr > 32 THEN
Vctr = 1
END IF
ELSE
Hctr = Hctr + 1
END IF
END IF
END IF
'LOCATE 10, 2: PRINT "# trains-="; notctr
'LOCATE 11, 2: PRINT "compPT---="; compPT
'LOCATE 12, 2: PRINT "Vctr-----="; Vctr
'LOCATE 13, 2: PRINT "Hctr-----="; Hctr
'LOCATE 14, 2: PRINT "chunk$---="; chunk$
'LOCATE 15, 2: PRINT "GTNcode--="; GTNcode(Vctr, Hctr)
'LOCATE 17, 2: INPUT "is this the match"; enter$
LOOP 'NEXT
cmpEND2:
'*
'*-------------------------------------------------------------
'* 'check for size 1 chunk
compare1:
'CLS
chunksize = 1 'starting chunk size
chunk1flag$ = "yes"
chunk$ = MID$(data$, comprPT, chunksize) 'grab a chunk
Vctr = 1: Hctr = 1 'start of the
DO WHILE chunk1flag$ = "yes" '1 chunks.
IF GTNcode(Vctr, Hctr) = chunk$ THEN 'compare chars to the chart
train(notctr) = GTNcode(Vctr, Hctr) 'notctr = the number of trains it will take to send the data.
trainV(notctr) = Vctr '
trainH(notctr) = Hctr '
notctr = notctr + 1 'num-of-trains
comprPT = comprPT + 1
chunk1flag$ = "done"
'LOCATE 17, 2: INPUT "found a 1 size chunk:"; enter$
GOTO cmpEND1
ELSE
IF Vctr = 2 AND Hctr = 4 THEN
trainV(notctr) = 1 'Vctr '1-27 = " " = BLANK
trainH(notctr) = 27 'Hctr 'if nothing matched MAKE IT BLANK
notctr = notctr + 1 'num-of-trains
comprPT = comprPT + 1
chunk1flag$ = "done"
'LOCATE 17, 2: PRINT "hit the end of the ones (2-4)"
GOTO cmpEND1 '
ELSE
IF Hctr > 31 THEN
Hctr = 1
Vctr = Vctr + 1
IF Vctr > 32 THEN
Vctr = 1
END IF
ELSE
Hctr = Hctr + 1
END IF
END IF
END IF
'LOCATE 10, 2: PRINT "# trains-="; notctr
'LOCATE 11, 2: PRINT "compPT---="; compPT
'LOCATE 12, 2: PRINT "Vctr-----="; Vctr
'LOCATE 13, 2: PRINT "Hctr-----="; Hctr
'LOCATE 14, 2: PRINT "chunk$---="; chunk$
'LOCATE 15, 2: PRINT "GTNcode--="; GTNcode(Vctr, Hctr)
'
LOOP 'NEXT
'*
'*-------------------------------------------------------------
cmpEND1:
'* notctr = notctr + 1
'* train(notctr) = RET
Tnotctr = notctr
'LOCATE 17, 2: PRINT "# of trains:"; notctr
'LOCATE 18, 2: INPUT "press enter :"; enter$
LOOP
'*------------------------------------------------------------------------
'* convert each char into marbles (the data that represents the marbles)
'* pull asci char, convert to decmail
'* change decmial # to our decmail code.
'* change decmial code to binary.
'ascitemp$ = MID$(a$, 10, 5)
'datta2= ASC(ascitemp$)
line20$ = line19$
line19$ = line18$
line18$ = line17$
line17$ = line16$
line16$ = line15$
line15$ = line14$
line14$ = line13$
line13$ = line12$
line12$ = line11$
line11$ = line10$
line10$ = line9$
line9$ = line8$
line8$ = line7$
line7$ = line6$
line6$ = line5$
line5$ = line4$
line4$ = line3$
line3$ = line2$
line2$ = line1$
line1$ = data$
END SUB
SUB DataIN (data$)
LOCATE 24, 2
INPUT "GTN:"; data$
END SUB
SUB Display
CLS
LOCATE 2, 2: PRINT line20$ '* text box. what you type gets
LOCATE 3, 2: PRINT line19$ '* gets displayed here.
LOCATE 4, 2: PRINT line18$
LOCATE 5, 2: PRINT line17$
LOCATE 6, 2: PRINT line16$
LOCATE 7, 2: PRINT line15$
LOCATE 8, 2: PRINT line14$
LOCATE 9, 2: PRINT line13$
LOCATE 10, 2: PRINT line12$
LOCATE 11, 2: PRINT line11$
LOCATE 12, 2: PRINT line10$
LOCATE 13, 2: PRINT line9$
LOCATE 14, 2: PRINT line8$
LOCATE 15, 2: PRINT line7$
LOCATE 16, 2: PRINT line6$
LOCATE 17, 2: PRINT line5$
LOCATE 18, 2: PRINT line4$
LOCATE 19, 2: PRINT line3$
LOCATE 20, 2: PRINT line2$
LOCATE 21, 2: PRINT line1$
LOCATE 22, 2: PRINT "type exit to exit"
LINE (2, 2)-(2, 175), 1 'left side line
LINE (250, 2)-(250, 175), 1 'right side line
LINE (2, 2)-(250, 2), 1 'top line
LINE (2, 175)-(250, 175), 1 'bottom line
LINE (252, 2)-(252, 175), 3 'left side line
LINE (315, 2)-(315, 175), 3 'right side line
LINE (252, 2)-(315, 2), 3 'top line
LINE (252, 175)-(315, 175), 3 'bottom line
LINE (2, 177)-(2, 195), 2 'left side line
LINE (315, 177)-(315, 195), 2 'right side line
LINE (2, 177)-(315, 177), 2 'top line
LINE (2, 195)-(315, 195), 2 'bottom line
'*_________________________________________________________________________
'* Trians going out
over = 252
down = 3
IF Tnotctr > 0 THEN
FOR TBctr = 1 TO Tnotctr 'draw a box for each train that well need
trnbox over, down, TBctr
down = down + 11
NEXT TBctr
END IF
END SUB
SUB loadtrain
'read train loader status
'look for READY state
'x% = INP(&H3FC)
'call a train from the buffer
'TLout = "00010101" 'something like this
'OUT &H3FC, TLout
'look for TRAIN-READY state
'get that bit
'do while that-bit = 0
'read printer port
'x% = INP(&H3FC)
'next
'load train
'TLout = first car data 'first train car
'OUT &H3FC, TLout
'TLout = advance train
'OUT &H3FC, TLout
'look for TRAIN-READY state
'get that bit
'do while that-bit = 0
'read printer port
'x% = INP(&H3FC)
'next
'TLout = first car data 'second train car
'OUT &H3FC, TLout
'TLout = advance train
'OUT &H3FC, TLout
'look for TRAIN-READY state
'get that bit
'do while that-bit = 0
&