?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1.     module Gopher
  2. extractRequest:
  3.     ld hl, historyBlock.locator
  4.     ld de, requestbuffer
  5. .loop
  6.     ld a, (hl)
  7.     ld (de), a
  8.     inc hl
  9.     inc de
  10.     cp 0
  11.     jr z, .search
  12.     jr .loop
  13. .search
  14.     dec de
  15.     ld a, (historyBlock.mediaType)
  16.     cp MIME_INPUT
  17.     jr nz, .exit
  18.     ld hl, historyBlock.search
  19.     ld a, TAB
  20.     ld (de), a
  21.     inc de
  22. .searchCopy
  23.     ld a, (hl)
  24.     and a : jr z, .exit
  25.     ld (de), a
  26.     inc hl : inc de
  27.     jr .searchCopy
  28. .exit
  29.     xor a
  30.     ld (de), a
  31.     ret
  32.  
  33.  
  34. makeRequest:
  35.     call extractRequest
  36.  
  37.     ld hl, historyBlock.host
  38.     ld de, historyBlock.port
  39.     call Wifi.openTCP
  40.     ret c
  41.  
  42.     ld hl, requestbuffer
  43.     call Wifi.tcpSendZ
  44.     xor a : ld (Wifi.closed), a
  45.     ret
  46.  
  47.  
  48. loadBuffer:
  49.     ld hl, outputBuffer
  50.     ld (Wifi.buffer_pointer), hl
  51. .loop
  52.     call Wifi.getPacket
  53.     ld a, (Wifi.closed) : and a : ret nz
  54.     call Wifi.continue
  55.     jr .loop
  56.  
  57.     ifdef GS
  58. loadMod:
  59.     xor a : call GeneralSound.init
  60.     ld hl, .progress : call DialogBox.msgNoWait
  61.     call makeRequest : jp c, Fetcher.fetchFromNet.error
  62.     call GeneralSound.loadModule
  63. .loop
  64.     ld hl, outputBuffer, (Wifi.buffer_pointer), hl
  65.     call Wifi.getPacket
  66.     ld a, (Wifi.closed) : and a : jr nz, .exit
  67.     ld hl, outputBuffer, bc, (Wifi.bytes_avail)
  68. .loadLoop
  69.     ld a, b : or c : and a : jr z, .nextFrame
  70.     ld a, (hl) : call GeneralSound.sendByte
  71.     dec bc
  72.     inc hl
  73.     jr .loadLoop
  74. .nextFrame
  75.     call Wifi.continue
  76.     jr .loop
  77. .exit
  78.     call GeneralSound.finishLoadingModule
  79.     jp History.back
  80. .progress db "MOD downloading directly to GS!", 0
  81.     endif
  82.  
  83.  
  84. download:
  85.  
  86.     ld de, historyBlock.locator
  87.     ld hl, de
  88. .findFileName
  89.     ld a, (de) : inc de
  90.     cp '/' : jr nz, .skip
  91.     ld hl, de
  92. .skip
  93.     and a : jr nz, .findFileName
  94. .copy
  95.     ;; HL - filename pointer
  96.     ld de, DialogBox.inputBuffer
  97. .copyFileName
  98.     ld a, (hl) : and a : jr z, .finishCopy
  99.  
  100.     ld (de), a : inc hl, de
  101.     jr .copyFileName
  102. .finishCopy
  103.     ld (de), a
  104.     call DialogBox.inputBox.noclear
  105.     ld a, (DialogBox.inputBuffer) : and a : jp z, History.back
  106.    
  107.     call makeRequest : jp c, Fetcher.fetchFromNet.error
  108.  
  109.     ld b, Dos.FMODE_CREATE, hl, DialogBox.inputBuffer
  110.     call Dos.fopen
  111.     ld (.fp), a
  112.    
  113.     ld hl, .progress : call DialogBox.msgNoWait
  114. .loop
  115.     ld hl, outputBuffer, (Wifi.buffer_pointer), hl
  116.     call Wifi.getPacket
  117.     ld a, (Wifi.closed) : and a : jr nz, .exit
  118.    
  119.     ld a, (.fp), hl, outputBuffer, bc, (Wifi.bytes_avail)
  120.     call Dos.fwrite
  121.  
  122.     call Wifi.continue
  123.     jr .loop
  124. .exit
  125.     ld a, (.fp)
  126.     call Dos.fclose
  127.     jp History.back
  128. .error
  129.     ld a, (.fp)
  130.     call Dos.fclose
  131.  
  132.     ld hl, .err
  133.     call DialogBox.msgBox
  134.     jp History.back
  135. .err db "Operation failed! Sorry! Check filename or disk space!",0
  136. .progress db "Downloading in progress! Wait a bit!", 0
  137. .fp db 0
  138.  
  139. socket db 0
  140.  
  141. requestbuffer ds #1ff
  142.     endmodule
  143.