diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2024-11-06 16:47:33 -0500 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2024-11-06 16:47:33 -0500 |
commit | f1d017401b0efef229a45d1b4ffeca95a287594b (patch) | |
tree | bebdddcf994342af0c4188a2d8cc864e56e51317 /gwfetch.bas | |
download | GWFetch-f1d017401b0efef229a45d1b4ffeca95a287594b.tar.gz GWFetch-f1d017401b0efef229a45d1b4ffeca95a287594b.zip |
Initial commit with functioning CPU detection code
Diffstat (limited to 'gwfetch.bas')
-rw-r--r-- | gwfetch.bas | 155 |
1 files changed, 155 insertions, 0 deletions
diff --git a/gwfetch.bas b/gwfetch.bas new file mode 100644 index 0000000..b7b509d --- /dev/null +++ b/gwfetch.bas @@ -0,0 +1,155 @@ +10 TMPFILE$ = "TEST.TMP"
+19 REM Determine the OS and interpretter
+20 REM CMD$ = "ver":GOSUB 5000:GOSUB 10000
+30 PRINT "INTERPRETER: ";INTERP$
+40 IF LEN(VERSION$) > 0 THEN PRINT "VERSION: ";VERSION$
+100 REM Determine memory
+110 REM CMD$ = "chkdsk":GOSUB 5000:GOSUB 11000
+120 PRINT "MEMORY: ";MEMFREE$;"/";MEMTOTAL$
+
+130 GOSUB 12000
+140 PRINT "CPUID: ";CPUID%
+1000 END
+
+5000 REM Run and pipe command
+5010 REM TMPFILE$ contains the file for capture
+5020 REM CMD$ contains the command to run
+5030 SHELL CMD$ + " > " + TMPFILE$
+5040 RETURN
+
+10000 REM 'ver' output parser
+10010 REM TMPFILE$ contains the file to open
+10011 REM output: INTERP$ is the interpeter
+10012 REM VERSION$ is the version
+10020 OPEN TMPFILE$ FOR INPUT AS #2
+10025 REM ON ERROR GOTO 10040
+10030 INPUT#2, VERLINE$
+10035 IF LEN(G$) = 0 THEN GOTO 10030 ELSE GOTO 10050
+10040 RESUME 10060
+10060 CLOSE#2
+10070 REM VERLINE$ now contains the first non-blank version
+10080 REM output. Technically it is just the command
+10090 REM interpreter version.
+10100 IDX = INSTR(VERLINE$, "ersion")
+10110 IF IDX = 0 THEN INTERP$ = VERLINE$:VERSION$="":RETURN
+10120 IDX = IDX - 1
+10130 INTERP$ = LEFT$(VERLINE$, IDX - 1)
+10140 IDX = IDX + 7
+10150 VERSION$ = RIGHT$(VERLINE$, LEN(VERLINE$) - IDX)
+10160 FOR IDX = 1 TO LEN(VERSION$)
+10170 IF MID$(VERSION$, IDX, 1) = " " THEN VERSION$ = LEFT$(VERSION$,IDX-1)
+10180 NEXT IDX
+10190 RETURN
+11000 REM 'chkdsk' output parser
+11010 REM TMPFILE$ contains the file to open
+11011 REM output: MEMTOTAL$ is the total memory in bytes
+11012 REM MEMFREE$ is the available memory in bytes
+11020 MEMTOTAL$ = "":MEMFREE$ = ""
+11025 ON ERROR GOTO 11100
+11030 OPEN TMPFILE$ FOR INPUT AS #2
+11040 INPUT#2, MEMLINE$
+11050 IDX = INSTR(MEMLINE$, "bytes total memory")
+11060 IF IDX > 0 THEN MEMTOTAL$ = LEFT$(MEMLINE$, IDX-1):GOTO 11090
+11070 IDX = INSTR(MEMLINE$, "bytes free")
+11080 IF IDX > 0 THEN MEMFREE$ = LEFT$(MEMLINE$, IDX-1)
+11090 IF LEN(MEMTOTAL$) = 0 OR LEN(MEMFREE$) = 0 THEN GOTO 11040 ELSE GOTO 11110
+11100 RESUME 11110
+11110 CLOSE#2
+11120 TOTRIM$ = MEMTOTAL$:GOSUB 30000:MEMTOTAL$ = TOTRIM$
+11130 TOTRIM$ = MEMFREE$:GOSUB 30000:MEMFREE$ = TOTRIM$
+11140 RETURN
+
+12000 REM CPU Identity
+12001 DIM Q%(400)
+12005 DEF SEG=VARSEG(Q%(0))
+12006 OS%=VARPTR(Q%(0))
+12010 FOR I = 1 TO 76
+12020 READ JC:POKE I+OS%, JC
+12025 print i, peek(i+OS%)
+12030 NEXT I
+12040 CPUQ = 1 + OS%
+12041 print "Calling!"
+12045 CALL CPUQ(CPUID%)
+12047 DEF SEG
+
+12048 REM CPUID% = PEEK(3)
+
+12050 DATA &H55 : REM push bp
+12051 DATA &H89, &HE5 : REM mov bp, sp
+12052 REM ; push zero onto the stack and pop it into flags.
+12053 REM ; some bits won't change
+12054 DATA &H31, &HC0 : REM xor ax,ax
+12055 DATA &H50 : REM push ax
+12056 DATA &H9D : REM popf
+12057 DATA &H9C : REM pushf
+12058 DATA &H58 : REM pop ax
+12059 DATA &H25, &H00, &HF0 : REM and ax, 0xf000 ;0f000h
+12060 DATA &H3D, &H00, &HF0 : REM cmp ax, 0xf000 ;0f000h
+12061 DATA &H74, &H13 : REM je lessthantwoeightsix
+12062 REM ; marked as 286 (2)
+12063 DATA &HB2, &H02 : REM mov dl, 2
+12064 DATA &HB8, &H00, &H70 : REM mov ax, 0x7000 ;7000h
+12065 DATA &H50 : REM push ax
+12066 DATA &H9D : REM popf
+12067 DATA &H9C : REM pushf
+12068 DATA &H58 : REM pop ax
+12069 DATA &H25, &H00, &H70 : REM and ax, 0x7000 ;7000h
+12070 DATA &H74, &H22 : REM jz alldone
+12071 REM ; mark as 386 (3)
+12072 DATA &HFE, &HC2 : REM inc dl
+12073 DATA &HE9, &H1D, &H00 : REM jmp alldone
+12074 REM lessthantwoeightsix:
+12075 DATA &HB2, &H01 : REM mov dl, 1
+12076 DATA &HB0, &HFF : REM mov al, 0xff ;0ffh
+12077 DATA &HB1, &H21 : REM mov cl, 0x21 ;21h
+12078 DATA &HD2, &HE8 : REM shr al, cl
+12079 REM ; if the shift leaves zero, it's a 8088 class cpu, else 8018
+12080 DATA &H75, &H13 : REM jnz alldone
+12081 REM ; Lets see if we have a V2
+12082 DATA &HB2, &H56 : REM mov dl, 0x56 ;056h
+12083 DATA &HFB : REM sti
+12084 DATA &H56 : REM push si
+12085 DATA &HBE, &H00, &H00 : REM mov si, 0
+12086 DATA &HB9, &HFF, &HFF : REM mov cx, 0xffff ;0ffffh
+12087 REM ;rep lods [BYTE PTR es:si]
+12088 DATA &HF2, &HAC : REM rep lodsb
+12089 DATA &H5E : REM pop si
+12090 DATA &H09, &HC9 : REM or cx, cx
+12091 DATA &H74, &H02 : REM jz alldone
+12092 REM ; mark as a 808
+12093 DATA &HB2, &H00 : REM mov dl, 0
+12094 REM alldone:
+12095 REM ; store in ax
+12096 DATA &H30, &HF6 : REM xor dh, dh
+12097 DATA &H8B, &H7E, &H06 : REM mov di, [bp]+6
+12098 DATA &H89, &H15 : REM mov [di], dx
+12099 DATA &H5D : REM pop bp
+12100 DATA &HCA, &H02, &H00 : REM ); { retf 2}
+12101 REM Total Bytes in Data: 76
+
+
+
+
+12200 RETURN
+
+
+13000 REM CPU Identity via dim
+13010 dim A%(37)
+13030 FOR I = 0 TO 14-1
+13040 READ JC:PRINT JC:POKE (VARPTR(A%(1))+I), JC
+13045 PRINT I
+13050 NEXT I
+13060 CPUQ = VARPTR(A%(1))
+
+13080 RETURN
+
+
+
+
+30000 REM String Trim Function
+30010 REM input/output: TOTRIM$
+30020 FOR IDX = 1 TO LEN(TOTRIM$):IF MID$(TOTRIM$, IDX, 1) <> " " THEN GOTO 30030:NEXT IDX
+30030 FOR RDX = LEN(TOTRIM$) TO IDX STEP -1:IF MID$(TOTRIM$, RDX, 1) <> " " THEN GOTO 30050:NEXT RDX
+30040 TOTRIM$ = MID$(TOTRIM$, IDX, RDX - IDX)
+30050 RETURN
+
|