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 'read printer port 'x% = INP(&H3FC) 'next 'TLout = first car data 'thrid 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 'clear that train from the list ' x% = INP(&H3FC) 'Read COM1 Modem Control Register. ' OUT &H3FC, TLout ' LOCATE 15, 15: PRINT "Data Out "; ctr ' LOCATE 20, 10: PRINT bit(1); bit(2); bit(3); bit(4); bit(5); bit(6); bit(7); bit(8) END SUB SUB Notes '* http://courses.ece.uiuc.edu/ece390/books/labmanual/parallel-comm-asm.html '* http://et.nmsu.edu/~etti/fall96/computer/printer/printer.html '* Machine-language control uses OUT instructions to transfer a byte from register '* AL of the CPU to the adapter's Out latches, or IN instructions to transfer data '* from the In buffers to register AL. A simplified logic diagram is shown in Figure '* 13-2. Machine language control is straightforward but several peculiarities of the '* Mario & Zelda Big Band Live - Yoshi's Island - Theme of Athletic '* adapter logic must be noted: '* Data is sent to the printer by OUTputting a byte from register AL to the Data '* Out Latch. This latch has tri-state outputs which are always enabled. Thus, the '* printer's Data lines CANNOT be used for input; the Data In Buffer can only be '* used to read back to data in the Data Out Latch. '* Status signals from the printer are INput into register AL via the Status In Buffer '* (bits 3-7 only). Table 13-3 shows the meaning assigned to the various bits. Note that '* some signals are complemented between the connector and the In Buffer. (The status '* byte returned by BIOS call 17h register AH has a timeout indicator added in bit 0 and, '* for some reason, has bits 3 and 6 complemented by software.) '*Table 13-3. Register AL Bit Assignments for Printer Status Signals '*---------------------------------------------------------------------------- '*pin 0 = nc '*pin 1 = nc '*pin 2 = nc '*pin 3 = I/O error lprint '*pin 4 = selected '*pin 5 = out of papper '*pin 6 = Ack '*pin 7 = busy '*pin 10 = Ack '*pin 11 = busy '*pin 12 = out of paper '*pin 13 = selected '*pin 15 = I/O error '* Printer Data Port Status Control '* LPT1 0x03bc 0x03bd 0x03be '* LPT2 0x0378 0x0379 0x037a '* LPT3 0x0278 0x0279 0x027a '* To definitively identify the assignments for a particular machine, use the DOS debug program to display memory locations 0040:0008. For example: '* >debug '* -d 0040:0008 L8 '* 0040:0008 78 03 78 02 00 00 00 00 '*Note in the example that LPT1 is at 0x0378, LPT2 at 0x0278 and LPT3 and LPT4 are not assigned. '* Thus, for this hypothetical machine; '* '* Printer Data Port Status Control '* LPT1 0x0378 0x0379 0x037a '* LPT2 0x0278 0x0279 0x027a '* LPT3 NONE '* LPT4 NONE END SUB SUB readprinterport trainload = INP(&H3FC) 'look to see if theres a train waiting END SUB SUB Sartup endflag$ = "no" SCREEN 12 'DIM GTNcode(1 TO 32, 1 TO 32) AS STRING '----------------------------------------------------------- OPEN "c:\GTN-code\gtnmx.txt" FOR INPUT AS #1 Hctr = 1 Vctr = 1 entermatrx: FOR Hctr = 1 TO 32 INPUT #1, GTNcode(Vctr, Hctr) 'PRINT #2 "Vctr "; Vctr; " Hctr "; Hctr; " "; GTNcode(Vctr, Hctr) NEXT Hctr Vctr = Vctr + 1 IF Vctr > 32 THEN GOTO nextstep ELSE GOTO entermatrx END IF CLOSE #1 nextstep: '----------------------------------------------------------- 'OPEN "c:\GTN-code\gtn-lst.txt" FOR OUTPUT AS #2 ' Hctr = 1 ' Vctr = 1 'entermatrx2: ' FOR Hctr = 1 TO 32 ' PRINT #2, "Vctr "; Vctr; " Hctr "; Hctr; " "; GTNcode(Vctr, Hctr) ' NEXT Hctr ' Vctr = Vctr + 1 ' IF Vctr > 32 THEN ' GOTO nextstep2 ' ELSE ' GOTO entermatrx2 ' END IF 'CLOSE #2 'nextstep2: '___________________________________________________________ VP = 1 HP = 1 Vctr = 1 zev: FOR Hctr = 1 TO 32 LOCATE VP, HP: PRINT GTNcode(Vctr, Hctr) 'LOCATE 28, 1: INPUT "press enter"; entr$ VP = VP + 1 IF VP > 28 THEN : VP = 1: HP = HP + 5 IF HP > 79 THEN : HP = 1 NEXT Hctr Vctr = Vctr + 1 IF Vctr > 32 THEN GOTO neo ELSE Hctr = 1 GOTO zev END IF neo: LOCATE 29, 1: INPUT "press enter"; entr$ '----------------------------------------------------------- line20$ = " 0000000" line19$ = " 000 000" line18$ = " 00 00" line17$ = " 0 0" line16$ = " 0 0" line15$ = " 0 0" line14$ = " 0 0" line13$ = " 00 00" line12$ = " 000 000" line11$ = " 0000000" line10$ = " " line9$ = " " line8$ = " " line7$ = " The Great Train Network" line6$ = " " line5$ = " A4S8B7, No2pencil, tewk," line4$ = " jollydoughnut, Ted, Myself" line3$ = " " line2$ = " " line1$ = " a 2025 notacon premier." END SUB SUB test (bit()) ctr = 1 pause = 10000 DIM bitcolor(1 TO 8) AS SINGLE FOR ctr = 1 TO 256 'OUT &H3FC, ctr ' LOCATE 15, 15: PRINT "Data Out "; ctr ' LOCATE 20, 10: PRINT bit(1); bit(2); bit(3); bit(4); bit(5); bit(6); bit(7); bit(8) '* use 3 and 4 for color and the bit value. bin ctr FOR testbitctr = 1 TO 8 SELECT CASE bit(testbitctr) CASE IS = 1 bitcolor(testbitctr) = 4 CASE IS = 0 bitcolor(testbitctr) = 3 END SELECT NEXT testbitctr 'LOCATE 5, 5: PRINT bitcolor(1); bitcolor(2); bitcolor(3); bitcolor(4); bitcolor(5); bitcolor(6); bitcolor(7); bitcolor(8) LINE (116, 90)-(204, 110), 3, BF 'TEST BOX LINE (118, 96)-(126, 104), bitcolor(1), BF LINE (129, 96)-(137, 104), bitcolor(2), BF LINE (140, 96)-(148, 104), bitcolor(3), BF LINE (151, 96)-(159, 104), bitcolor(4), BF LINE (162, 96)-(170, 104), bitcolor(5), BF LINE (173, 96)-(181, 104), bitcolor(6), BF LINE (183, 96)-(191, 104), bitcolor(7), BF LINE (194, 96)-(202, 104), bitcolor(8), BF FOR rtc = 1 TO pause: NEXT rtc NEXT ctr END SUB SUB trnbox (over, down, ctrr) DIM bitcolor(1 TO 13) AS SINGLE 'over = 1 'down = 1 'TBover = 254 'TBdown = 4 LINE (over, down)-(over + 63, down + 8), 3, BF 'draw TRIAN BOX bin trainV(ctrr) 'bit() var is shared 'bits = first 5 bits of train. 'grab the bits before converting next number FOR testbitctr = 1 TO 5 'we only need the first 5 bits SELECT CASE bit(testbitctr) CASE IS = 1 'assign a graphic color to bitcolor(testbitctr) = 4 'each bit. CASE IS = 0 bitcolor(testbitctr) = 3 END SELECT NEXT testbitctr bin trainH(ctrr) 'convert the horizontal code 'bits = next 5 bits of train. 'convert trian data ti binary FOR testbitctr = 1 TO 5 'again we only need 5 bits SELECT CASE bit(testbitctr) CASE IS = 1 'assign a graphic color to bitcolor(testbitctr + 5) = 4 'each bit. CASE IS = 0 bitcolor(testbitctr + 5) = 3 END SELECT NEXT testbitctr bitcolor(11) = 3 bitcolor(12) = 3 LINE (over + 2, down + 2)-(over + 5, down + 7), bitcolor(1), BF 'draw the bits LINE (over + 7, down + 2)-(over + 10, down + 7), bitcolor(2), BF 'if its a one its red LINE (over + 12, down + 2)-(over + 15, down + 7), bitcolor(3), BF 'if its a one its red LINE (over + 17, down + 2)-(over + 20, down + 7), bitcolor(4), BF 'if its a zero its the LINE (over + 22, down + 2)-(over + 25, down + 7), bitcolor(5), BF 'same color as the background. LINE (over + 27, down + 2)-(over + 30, down + 7), bitcolor(6), BF LINE (over + 32, down + 2)-(over + 35, down + 7), bitcolor(7), BF LINE (over + 37, down + 2)-(over + 40, down + 7), bitcolor(8), BF 'if its a one its red LINE (over + 42, down + 2)-(over + 45, down + 7), bitcolor(9), BF LINE (over + 47, down + 2)-(over + 50, down + 7), bitcolor(10), BF LINE (over + 52, down + 2)-(over + 55, down + 7), bitcolor(11), BF LINE (over + 57, down + 2)-(over + 60, down + 7), bitcolor(12), BF END SUB