Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge....
#1
Write a qbasic Quine, for those of you who don't know a quine is a program that when run outputs it's source, you may not use the open command that is just a weak hack and not really a true quine, but to give u a better idea of what needs to be done i'll show you a example using the hack...

Code:
Open "ThisFile.Bas" For input as #1
     While Not Eof(1)
            Line Input #1, ProgLine$
            Print ProgLine$
     Wend
Close #1

Save it as thisfile.bas and run it to see the results correctly.

Just remember you may not use anything similar to the above, it's just there to show you what your program should do.

Good luck it's not a easy challenge.
very F***ing song remains the same
To everyone who sucks-up for the fame
Out of strength you know we speak the truth
Every trend that dies is living proof

MasterMinds Software
Reply
#2
This challenge has already been proposed here...

My entry: Two lines and a comment
Code:
A$="PRINT MID$(A$,43);CHR$(34);A$;CHR$(34);A$'A$="
PRINT MID$(A$,43);CHR$(34);A$;CHR$(34);A$'A$=

edited:
In GW-BASIC it was easier:
Code:
1 LIST
Antoni
Reply
#3
I am guessing this will also be considered a cheap solution:

Code:
SHELL "type ThisProgram.bas"

*peace*

MB.
Reply
#4
Since everyone posted easy solutions, I now post a hard solution Wink

[syntax="QBasic"]'// ThisFile.bas
'// Prints out this file's contents Smile

'$INCLUDE: 'QB.BI'
DIM RegsX AS RegTypeX

'clear screen
CLS

'open the file
RegsX.ax = &H3D00
FILE$ = "THISFILE.BAS" + CHR$(0)
RegsX.ds = VARSEG(FILE$)
RegsX.dx = SADD(FILE$)
CALL INTERRUPTX(&H21, RegsX, RegsX)
Hand% = RegsX.ax

'read file data
RegsX.ax = &H3F00
RegsX.bx = Hand%
RegsX.cx = 1024
DIM Buffer AS STRING * 1024
RegsX.ds = VARSEG(Buffer)
RegsX.dx = VARPTR(Buffer)
CALL INTERRUPTX(&H21, RegsX, RegsX)

'close file
RegsX.ax = &H3E00
RegsX.bx = Hand%
CALL INTERRUPTX(&H21, RegsX, RegsX)

'convert \lf to nothing (leaving \cr only)
A$ = ""
FOR i = 1 TO LEN(Buffer)
IF MID$(Buffer, i, 1) <> CHR$(10) AND MID$(Buffer, i, 1) <> CHR$(0) THEN
A$ = A$ + MID$(Buffer, i, 1)
END IF
NEXT i
PRINT A$

END 'end the prog reading itself Smile[/syntax]

Have fun Smile

NOTE: It doesn't use QB's OPEN command Wink It uses DOS's commands for file handling Smile
Btw, did I use "anything similar"?


There are several options to work out this challenge:
#1: Using QB commands like OPEN like BinarySHOCK's example
#2: Hardcode like Antoni Gual's code
#3: Via shell like Meg's code
#4: Using DOS interrupts
And the last I can think of:
#5: Compile the program as EXE file, find the EXE location in memory, read EXE data and decode this to QB code.
Reply
#5
sorry guess i didn't notice the other quine challege, and as far as i could tell neo you just open the file up with interupts, which is esstentially the same thing IMO but as i didn't specify that...
very F***ing song remains the same
To everyone who sucks-up for the fame
Out of strength you know we speak the truth
Every trend that dies is living proof

MasterMinds Software
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)