Pascal/Turbo Pascal - programa en pascal para usb

 
Vista:

programa en pascal para usb

Publicado por sebas (1 intervención) el 08/11/2012 12:04:31
hola, no se si es posible lo que quiero hacer. quisiera escribrir un programa en pascal que encienda leds conectados al usb... el unico lenguaje que conosco es pascal por eso pregunto en este lenguaje.
Gracias saludos!
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

programa en pascal para usb

Publicado por ramon (2158 intervenciones) el 08/11/2012 20:58:03
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
{Como creo que sabrás el usb es algo prohibido para el dos y pascal es del dos pero se esta intentando la comunicación desde pascal mira te dejo un pequeño programa de prueba del usb
 desde pascal queda mucho que andar en esto pero se andará suerte
 esta  en dos portes }
 
{porte 1}
 program prueusb;
   {$G+}
  uses
     crt, dos;
  type
     USBRequest = record
          bmRequestType : Byte;
               bRequest : byte;
                 wValue : word;
                 wIndex : word;
                wLength : word;
               end;
 
  const
      deviceaddress = 1;
      preferredHWInterrupt = 3;
      preferredIOSpace = $120;
      SetAddressDescriptor : USBRequest =
                         (bmRequestType : $00;
                         bRequest : $5;
                         wValue : $0001;
                         wIndex : $000;wLength:$0000);
 
       GetHubDescriptor : USBRequest =
                       (bmRequestType : $A0;
                        bRequest : $06;
                        wValue : $0001;
                        wIndex : $0000;
                        wLength : $0012);
 
           SetConfiguration : USBRequest =
                       (bmRequestType : $00;
                        bRequest : $9;
                        wValue : $0001;
                        wIndex : $0000;
                        wLength : $000);
 
         GetConfiguration : USBRequest =
                        (bmRequestType : $00;
                         bRequest : $8;
                         wValue : $0001;
                         wIndex : $0000;
                         wLength : $000);
 
         GetHubStatus : USBRequest =
                       (bmRequestType : $A0;
                        bRequest : $0;
                        wValue : $000;
                        wIndex : $0000;
                        wLength : $004);
 
        GetDeviceDescriptor : USBRequest =
                              (bmRequestType : $80;
                               bRequest : $06;
                               wValue : $0001;
                               wIndex : $0000;
                               wLength : $008);
 
          SetHubPortPowerFeature : USBRequest =
                            (bmRequestType : $23;
                             bRequest : $3;
                             wValue : $0008;
                             wIndex : $0001;
                             wLength : $000);
 
 
  type
     LinkPointer = longint;
     BufferPointer = longint;
 
     FrameListPointer = longint;
     FrameListPointerArray = Array[0..1023] of FrameListPointer;
     FrameList = ^FrameListPointerArray;
 
     TransferDescriptor = record
               next : LinkPointer;
             ActLen : word;
             Status : byte;
              Flags : Byte;
              Token : longint;
          BufferPtr : BufferPointer;
                res : array[0..3] of longint;
          end;
 
 
 
 
  var
     USBDeviceID, USBVendorID : word;
     USBBusNumber, USBFunctionNumber : Byte;
     USBDescription : string;
     USBIOSpace : word;
     USBdetected : boolean;
     ISAdetected : boolean;
     ISADeviceID, ISAVendorID : word;
     ISABusNumber, ISAFunctionNumber : Byte;
     ISADescription : string;
     old_port4d0 : byte;
     old_port4d1 : byte;
     old_pirqd : byte;
     oldmasterintmask : byte;
     oldslaveintmask : byte;
     FrameListPtr : FrameList;
     FrameListBase : longint;
     FrameListHandle : pointer;
     p : pointer;
     DeviceID,VendorID : word;         { PCI-BUS USB Device }
     BusNumber, FunctionNumber : Byte;  { PCI-BUS Address    }
     Description : string;
     result : longint;
     IOSpace : word;
     hwint : word;
     dummytimer : word;
     hwactive : boolean;
     flbase : framelistpointer;
     flptr : framelist;
     testbuffer : array[0..1279] of byte;
     oldUsbInt : pointer;
     serviceInt : word;
 
 
 
  function hexs(xx:longint):String;
  var
    ss : String[8];
    h1,h2 : Byte;
  begin
      ss := '';
      h1 := 32;
  repeat
    dec(h1,4);
    h2 := (xx shr h1) and $f;
    if h2 > 9 then
    h2 := h2 + 7;
    h2 := h2 + 48;
    ss := ss + chr(h2);
  until h1 = 0;
     hexs := ss;
  end;
 
   function hexs16(xx:word):String;
   var
     ss : String[8];
    h1, h2 : Byte;
  begin
     ss := '';
     h1 := 16;
  repeat
    dec(h1,4);
    h2 := (xx shr h1) and $f;
    if h2 > 9 then
    h2 := h2 + 7;
    h2 := h2 + 48;
    ss := ss + chr(h2);
  until h1 = 0;
    hexs16 := ss;
  end;
 
  function detectPCIBios:boolean;assembler;
  asm
       mov ax,0b101h
       int 1ah
       jc @nopcibios
       mov ax,1
       ret
  @nopcibios:
       xor ax,ax
       ret
  end;
 
  function detectPCIdevice(DeviceID : Word; VendorID : Word;
                            VAR BusNumber : Byte;
                            VAR FunctionNumber : Byte) : boolean;
  var
    found : boolean;
    bn : byte;
    fn : byte;
begin
  bn := 0;
  fn := 0;
  found := false;
  asm
    db 66h;pusha
    mov cx,DeviceID
    mov dx,VendorID
    mov ax,0b102h
    xor si,si
    int 1ah
    jc @nodevice
    mov found,true
    mov bn,BH
    mov fn,BL
  @nodevice:
    db 66h;popa
  end;
  BusNumber := bn;
  FunctionNumber := fn;
  detectPCIdevice := found;
end;
 
function USBdetect(Var DeviceID, VendorID : word;
                    VAR BusNumber, FunctionNumber : Byte;
                    var Description : string) : boolean;
  var
    i : byte;
    error, found : boolean;
 begin
     BusNumber := 0;
     FunctionNumber := 0;
     USBdetect := false;
  i := 0;
  error := false;
  found := false;
  repeat
  case i of
    0 : begin
        deviceId := $7020;
        vendorId := $8086;
        description := 'Intel 82371SB USB controller';
        end;
    1 : begin
        deviceId := $7112;
        vendorId := $8086;
        description := 'Intel PIIX4 USB controller';
        end;
    2 : begin
        deviceId := $0571;
        vendorId := $1106;
        description := 'VIA AMD-645 USB controller';
        end;
    3 : begin
        deviceId := $A0F8;
        vendorID := $1045;
        description := 'Opti 82C750 (Vendetta) USB controller';
        end;
    4 : begin
        deviceId := $C861;
        vendorID := $1045;
        description := 'Opti 82C861/871 (Firelink/FireBlast) USB controller';
        end;
  end;
  inc(i);
  found := detectPCIdevice(deviceId, vendorId, BusNumber, FunctionNumber);
  error := i > 4;
  until error or found;
  USBdetect := found;
  end;
 
  function ISAdetect(Var DeviceID, VendorID : word;
                   VAR BusNumber, FunctionNumber : Byte;
                   var Description : string) : boolean;
  var
    i : byte;
    error, found : boolean;
  begin
     BusNumber := 0;
     FunctionNumber := 0;
     ISAdetect := false;
     i := 0;
     error := false;
     found := false;
  repeat
  case i of
    0 : begin
        deviceId := $7000;
        vendorId := $8086;
        description := 'Intel 82371SB ISA-PCI controller';
        end;
    1 : begin
        deviceId := $7110;
        vendorId := $8086;
        description := 'Intel PIIX4 ISA-PCI controller';
        end;
{    2: begin deviceId:=$0571;vendorId:=$1106; description:='VIA AMD-645 USB controller'; end;
    3: begin deviceId:=$A0F8;vendorID:=$1045; description:='Opti 82C750 (Vendetta) USB controller'; end;
    4: begin deviceId:=$C861;vendorID:=$1045; description:='Opti 82C861/871 (Firelink/FireBlast) USB controller'; end; }
  end;
  inc(i);
  found := detectPCIdevice(deviceId, vendorId, BusNumber, FunctionNumber);
  error := i > 2;
  until error or found;
  ISAdetect := found;
 end;
 
 function readPCIRegisterWord(RegisterNumber : word; BusNumber : Byte;
                           FunctionNumber : Byte;
                           var result : Word) : boolean;
 var
    okay : boolean;
    res : word;
 begin
    okay := false;
     res := 0;
  asm
    db 66h; pusha
    mov AX,0B109h
    mov BH,busNumber
    mov BL,functionNumber
    mov DI,RegisterNumber
    int 1Ah
    jc @noaction
    mov res,cx
    mov okay,true
  @noaction:
    db 66h; popa
  end;
  result := res;
  readPCIRegisterWord := okay;
 end;
 
  function USBGetDeviceIOSpace(var IOSpace : word) : boolean;
  var
    okay : boolean;
    result : word;
    setiospace : word;
 begin
    okay := false;
  if readPCIRegisterWord($20, USBBusNumber, USBFunctionNumber, result) then
    begin
      okay := true;
      IOSpace := result and $FFFE;
      USBIOSpace := IOSpace;
    end;
     USBGetDeviceIOSpace := okay;
 end;
 
 function readPCIRegisterByte(RegisterNumber : word; BusNumber : Byte;
                              FunctionNumber : Byte;
                              var result : byte) : boolean;
  var
    okay : boolean;
    res : byte;
 begin
  okay := false;
  res := 0;
  asm
    db 66h; pusha
    mov AX,0B108h
    mov BH,busNumber
    mov BL,functionNumber
    mov DI,RegisterNumber
    int 1Ah
    jc @noaction
    mov res,cl
    mov okay,true
  @noaction:
    db 66h; popa
  end;
  result := res;
  readPCIRegisterByte := okay;
 end;
 
 function writePCIRegisterByte(RegisterNumber : word;
                               BusNumber : Byte;
                               FunctionNumber : Byte;
                               input : byte) : boolean;
   var
     okay : boolean;
  begin
      okay := false;
  asm
    db 66h; pusha
    mov AX,0B10bh
    mov BH,busNumber
    mov BL,functionNumber
    mov DI,RegisterNumber
    mov CL,input
    int 1Ah
    jc @noaction
    mov okay,true
  @noaction:
    db 66h; popa
    end;
  writePCIRegisterByte := okay;
 end;
 
   function writePCIRegisterWord(RegisterNumber : word;
                                      BusNumber : Byte;
                                      FunctionNumber : Byte;
                                      input : word) : boolean;
   var
      okay : boolean;
  begin
     okay := false;
  asm
    db 66h; pusha
    mov AX,0B10ch
    mov BH,busNumber
    mov BL,functionNumber
    mov DI,RegisterNumber
    mov CX,input
    int 1Ah
    jc @noaction
    mov okay,true
  @noaction:
    db 66h; popa
  end;
    writePCIRegisterWord := okay;
 end;
 
  function writePCIRegisterDWord(RegisterNumber : word;
                                 BusNumber : Byte;
                                 FunctionNumber : Byte;
                                 input : longint) : boolean;
   var
      okay : boolean;
       res : byte;
  begin
     okay := false;
      res := 0;
  asm
    db 66h; pusha
    mov AX,0B10dh
    mov BH,busNumber
    mov BL,functionNumber
    mov DI,RegisterNumber
    db 66h; mov CX, word ptr input
    int 1Ah
    jc @noaction
    mov okay,true
  @noaction:
    db 66h; popa
   end;
    writePCIRegisterDWord := okay;
  end;
 
 
   function GetPtrBase(p:pointer):longint;
   begin
       GetPtrBase := longint(seg(p^)) shl 4 + longint(ofs(p^));
   end;
 
   function GetBasePtr(b:longint):pointer;
   var
      h1,h2 : longint;
   begin
     h1 := b shr 4;
     h2 := b and $f;
     GetbasePtr := Ptr(h1,h2);
 end;
 
 
 
    function bins8(xx : byte) : String;
    var
      ss : String[32];
       h1, h2 : Byte;
   begin
      ss := '';
      h1 := 8;
  repeat
    dec(h1);
    h2 := (xx shr h1) and $1;
    h2 := h2 + 48;
    ss := ss + chr(h2);
  until h1 = 0;
    bins8 := ss;
 end;
 
    function hexs8(xx:byte):String;
    var
       ss : String[8];
       h1, h2 : Byte;
   begin
      ss := '';
       h1 := 8;
  repeat
    dec(h1,4);
    h2 := (xx shr h1) and $f;
    if h2 > 9 then
    h2 := h2 + 7;
    h2 := h2 + 48;
    ss := ss + chr(h2);
  until h1 = 0;
     hexs8 := ss;
  end;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

programa en pascal para usb

Publicado por ramon (2158 intervenciones) el 08/11/2012 21:16:55
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{Como podrás apreciar tiene portes de asm trabajando en
 32 bits espero lo entiendas}
 
{Parte 2}
 
 function bins16(xx : word) : String;
   var
      ss : String[32];
      h1,h2 : Byte;
  begin
      ss := '';
      h1 := 16;
  repeat
    dec(h1);
    h2 := (xx shr h1) and $1;
    h2 := h2 + 48;
    ss := ss + chr(h2);
  until h1 = 0;
    bins16 := ss;
  end;
 
 procedure USBprintLinkPtr(L : LinkPointer);
 var
    h : longint;
    i : word;
  begin
      h := l and $fffffff0;
      write('LinkPtr:  ');
      if h = 0 then
       write('-EMPTY- [');
       write('- [',hexs(h));
      if l and 4 = 4 then
      write('] Vf ')
   else
      write('] -- ');
      if l and 2 = 2 then
      write(' Q ')
   else
      write(' - ');
      if l and 1 = 1 then
      write(' T ')
   else
      write(' - ');
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

programa en pascal para usb

Publicado por ramon (2158 intervenciones) el 08/11/2012 21:29:21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
{Esta en varias por fallo de carga recogerlo bien}
 
 writeln;
  end;
 
  procedure USBprintFrameList;
   var
     i,j : word;
     l : longint;
begin
  write('FrameList------[',hexs(FrameListBase),']------');
  for i := 0 to 1023 do
    begin
      if i mod 6 = 0 then
      writeln;
      l := FrameListPtr^[i];
      write('[',hexs(l),']');
      if l and 2 = 2 then
      write('Q')
   else
        write('-');
      if l and 1 = 1 then
      write('T')
   else
      write('-');
      write(' ');
    end;
     writeln;
     writeLn('---------------------');
  end;
 
  procedure USBprintTD(P : pointer);
   var
     td : ^TransferDescriptor;
     i : word;
     h : longint;
     hp : ^byte;
  begin
      td := p;
  with td^ do
    begin
      writeLn('Transfer Descriptor-----[',hexs(GetPtrBase(p)),']-------');
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

programa en pascal para usb

Publicado por ramon (2158 intervenciones) el 08/11/2012 21:55:43
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
{Como podras apreciar tiene portes de asm trabajando en
 32 bits espero lo entiendas}
 
{Parte 2}
 
 function bins16(xx : word) : String;
   var
      ss : String[32];
      h1,h2 : Byte;
  begin
      ss := '';
      h1 := 16;
  repeat
    dec(h1);
    h2 := (xx shr h1) and $1;
    h2 := h2 + 48;
    ss := ss + chr(h2);
  until h1 = 0;
    bins16 := ss;
  end;
 
 procedure USBprintLinkPtr(L : LinkPointer);
 var
    h : longint;
    i : word;
  begin
      h := l and $fffffff0;
      write('LinkPtr:  ');
      if h = 0 then
       write('-EMPTY- [');
       write('- [',hexs(h));
      if l and 4 = 4 then
      write('] Vf ')
   else
      write('] -- ');
      if l and 2 = 2 then
      write(' Q ')
   else
      write(' - ');
      if l and 1 = 1 then
      write(' T ')
   else
      write(' - ');
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

programa en pascal para usb

Publicado por ramon (2158 intervenciones) el 08/11/2012 22:00:05
Siento no poder mandar todo pero como ves surjen problemas de envió no se por que lo siento
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

programa en pascal para usb

Publicado por ramon (2158 intervenciones) el 08/11/2012 21:58:43
{Como podras apreciar tiene portes de asm trabajando en
32 bits espero lo entiendas}

{Parte 2}

function bins16(xx : word) : String;
var
ss : String[32];
h1,h2 : Byte;
begin
ss := '';
h1 := 16;
repeat
dec(h1);
h2 := (xx shr h1) and $1;
h2 := h2 + 48;
ss := ss + chr(h2);
until h1 = 0;
bins16 := ss;
end;



procedure USBprintFrameList;
var
i,j : word;
l : longint;
begin
write('FrameList------[',hexs(FrameListBase),']------');
for i := 0 to 1023 do
begin
if i mod 6 = 0 then
writeln;
l := FrameListPtr^[i];
write('[',hexs(l),']');
if l and 2 = 2 then
write('Q')
else
write('-');
if l and 1 = 1 then
write('T'%
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

programa en pascal para usb

Publicado por ramon (2158 intervenciones) el 10/11/2012 22:29:42
[2]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
function bins16(xx : word) : String;
   var
      ss : String[32];
      h1,h2 : Byte;
  begin
      ss := '';
      h1 := 16;
  repeat
    dec(h1);
    h2 := (xx shr h1) and $1;
    h2 := h2 + 48;
    ss := ss + chr(h2);
  until h1 = 0;
    bins16 := ss;
  end;
 
 procedure USBprintLinkPtr(L : LinkPointer);
 var
    h : longint;
    i : word;
  begin
      h := l and $fffffff0;
      write('LinkPtr:  ');
      if h = 0 then
       write('-EMPTY- [');
       write('- [',hexs(h));
      if l and 4 = 4 then
      write('] Vf ')
   else
      write('] -- ');
      if l and 2 = 2 then
      write(' Q ')
   else
      write(' - ');
      if l and 1 = 1 then
      write(' T ')
   else
      write(' - ');
      writeln;
  end;
 
  procedure USBprintFrameList;
   var
     i,j : word;
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar