Code: Select all
0GOTOFNg(0)
1DEFFNg(?-1)PRINT"Hello World!":=0
Code: Select all
0GOTOFNg(0)
1DEFFNg(?-1)PRINT"Hello World!":=0
The Hello World is only there because otherwise the program does nothing, which instantly makes people suspicioussorvad wrote:You've got me to byte
Yes, on the face of it just prints Hello World repeatadly, but why the other stuff ?
...It's in the function definition, so it's a formal parameter, and they're automatically made LOCAL...?-1,
OK this is going to return the contents of location 65535,
?-1 was chosen to add mystery, and because in OS 1.2 it contains a fortunate value for our purposes.Mmmmm.... if Beeb BASIC treats this as an integer and not a byte. Location &FFFF is the low order byte of the 6502 hard reset boot vector if memory serves me right. But how does passing 0 fit into it all.
Code: Select all
0PROCg(0)
1DEFPROCg(?-1)ENDPROC
Code: Select all
B259..76 Restores X, 19..B. Pushes 2A..C (address and data type) on 6502 stack
B30D..18 Choose ! or ?
B32C..51 Fetch byte from address in &2A,2B. Clear Y
AEEA..F6 Store 8/16-bit value in 2A..D (IWA), data type=&40 (integer)
B31B..1C Push data type on 6502 stack
BD90..99 Test data type, decrement stack pointer for integer
BE2E..40 Store stack pointer, test for No room
BD9C..B1 Store contents of IWA on stack
B320..26 Test data type, load X=&37
AF56..68 Load dword at 0,X into IWA, data type=&40
B329 Jump
BD94..99 Decrement stack pointer for integer
BE2E..40 Store stack pointer, test for No Room
BD9C..B1 Store contents of IWA on stack
B279.. Scan next DEF PROC argument...
Code: Select all
>LIST
10 aa%=&12:cc%=&34
20 DIM bb% 4:!bb%=&56789ABC
30 B%=bb%
40 PROCgg(1,2)
50 PRINT ~aa%,~bb%,~cc%,~B%,~?B%
60 END
70 DEF PROCgg(aa%,?B%)
80 PRINT "Test"
90 ENDPROC
>RUN
Test
12 17AE 34 17AE 2
>
Line 70 Result
DEF PROCgg(aa%,?B%) RUNs, !B% overwritten
DEF PROCgg(A%,?B%) RUNs, !B% overwritten
DEF PROCgg(A%,?bb%) DEF PROCgg(A%,<corrupted>)
DEF PROCgg(aa%,?bb%) DEF PROCgg(aa%,<corrupted>)
DEF PROCgg(?bb%,cc%) DEF PROCgg(<corrupted>,cc%)
DEF PROCgg(?B%,cc%) PROCgg call corrupted
DEF PROCgg(?B%) PROCgg call corrupted
Code: Select all
>LIST
10 DIM bb% 4
20 !bb%=&56789ABC
30 B%=bb%
40 PROCgg
50 PRINT ~!bb%
60 END
70 DEF PROCgg
80 LOCAL ?B%
90 PRINT "Test"
100 ?bb%=1
110 ENDPROC
>RUN
Test
56789A01
>
Line 80 Result
LOCAL ?B% RUNs, ?B% overwritten
LOCAL A%,?B% " " "
LOCAL aa%,?B% " " "
LOCAL ?B%,C% " " "
LOCAL ?B%,cc% " " "
LOCAL A%,?bb% LOCAL A%,<corrupted>
LOCAL aa%,?bb% LOCAL aa%,<corrupted>
LOCAL ?bb% LOCAL <corrupted>
LOCAL ?bb%,C% LOCAL <corrupted>,C%
LOCAL ?bb%,cc% LOCAL <corrupted>,cc%
Code: Select all
10A%=ASC("1")
20PROCa:PROCb(0)
30GOTO20
40DEFPROCa:ENDPROC
50DEFPROCb(?&404):ENDPROC
60DEFPROCa1:REPEATPRINT"Lame duck":UNTIL0:ENDPROC
Code: Select all
10 FOR I% = 2147483646 TO 2147483647
20 PRINT "Listen very carefully, I shall say this only twice"
30 NEXT
I don't consider integers rolling round a bug, but a useful feature. It means you can do things like !word=!word+something without worrying that it's going to bomb out just because !word happened to previously contain &7FFFFFFF and something happened to be 2.regregex wrote:BASIC's got lots of bugs with the minimum value actually -- least of all integers, indeed.
Code: Select all
$ bbcbasic
PDP11 BBC BASIC IV Version 0.32
(C) Copyright J.G.Harston 1989,2005-2020
>_