Memory questions

Question 1:

PRINT PEEK 23732+256*PEEK 23733 returns 65535 for a 48K Spectrum and 32767 for a 16K Spectrum.
PRINT PEEK 16388+256*PEEK 16389 returns 32768 on a 16K ZX81 and 17408 on a 1K ZX81.
But was there ever an equivalent for the ZX80, to test if it was unexpanded, or had a 3K (or more) RAM pack attached?
The offline copy of the ZX80 manual I've got stashed on my hard drive gives a completely different system variable at 16388-16389, and there are far fewer of them than there are on the ZX81 (to my complete non-surprise).

Question 2:

Was there ever anyone so mad as to try to write a program in BASIC so huge that it required the use of the 128K RAM disc and being split into pieces to make it work? (i.e. with a central loader or option menu that will LOAD! "part 1", LOAD! "part 2" etc. or LOAD "m:part 1" etc. on the +2A...)
And no, extra loading screens don't count, and neither does that bouncing ball program in the 128K+/+2 manual.

Comments

  • About question 2:

    Keep on mind that you can "merge" BASIC programs, but you can not "unmerge" them. So having some kind of overlays on BASIC is forbidden. At most, you can make a BASIC program that uses some kind of binary data that can be stored on RAM disc (or try to load arrays with data from RAM disc).
    I was there, too
    An' you know what they said?
    Well, some of it was true!
  • I suppose I was picturing more of a "cheat" method, inspired by what I've just been typing in from INPUT (to amuse myself). There's a database program there with an 8-option main menu; what I was thinking was, a much larger version of this database where several chunks all have to be loaded and saved to the RAM disc individually to get it to work, i.e.

    LOAD "menu" (from tape)
    SAVE ! "menu" (to RAM disc)
    LOAD "part1"
    SAVE ! "part1"
    LOAD "part2"
    SAVE ! "part2" (etc etc etc etc etc for all the parts).

    Each part of the program then calls what's stored in the RAM disc, so "menu" has options to LOAD ! "part1", LOAD ! "part2", LOAD ! "part3" and so on, and each part has a "return to menu" option with LOAD ! "menu". Putting all the parts together would exceed 48K so this would be the long, laborious but working way to do it.

    If such a program never existed, but anyone wants to see it as a challenge to do so, I nominate the programmer for whatever WOS's equivalent of a Cacoward is. This will be the 128K Spectrum's answer to NUTS.WAD...
  • Heh heh, regarding Question 2, I have considered using that approach for a large adventure game, CLEARing an area of memory for storing game variables (flags, items held, item states etc.)
    Something like the Trader Trilogy ( http://www.worldofspectrum.org/infoseekid.cgi?id=0005363 ) might be a good place to get some practise... maybe add some 128K sounds as well....
  • 1:
    There was no equivalent RAMTOP BASIC system variable on the ZX80. However, since the BASIC ROM sets the stack pointer to the top of available memory at startup, the most common way to determine (approximate) RAM size is to check the value of SP at the start of the program, eg:
    LD HL,$0000
    ADD HL,SP
    LD A,H
    CP $3F
    JR NC,rampack16k
    CP $0B
    JR NC,rampack3k
    CP $07
    JR NC,rampack2k
    ...
    
    Zup wrote: »
    About question 2:
    Keep on mind that you can "merge" BASIC programs, but you can not "unmerge" them. So having some kind of overlays on BASIC is forbidden.

    Although you can overwrite existing BASIC lines from a merged program. So you could, for example have a common BASIC menu program using lines 10 to 1000; then load in lots of different sub-programs in the 1001 to 9999 lines; each time overwriting the previous sub-program.
    If such a program never existed, but anyone wants to see it as a challenge to do so, I nominate the programmer for whatever WOS's equivalent of a Cacoward is. This will be the 128K Spectrum's answer to NUTS.WAD...

    Sounds like a perfect candidate for the CSSCGC, looking forward to receiving your entry :)

    Comp.Sys.Sinclair Crap Games Competition 2017
    Everyone has a crap game inside them, let yours out!
  • Q2: a running BASIC program can load another BASIC program, and in the process completely replace said running program...
    So if the loaded program has been SAVEd to auto-run...

    Mark
    Sinclair FAQ Wiki
    Repair Guides. Spanish Hardware site.
    WoS - can't download? Info here...
    former Meulie Spectrum Archive but no longer available :-(
    Spectranet: the TNFS directory thread

    ! Standby alert !
    “There are four lights!”
    Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb!
    Looking forward to summer in Somerset later in the year :)
  • GReW wrote: »
    Zup wrote: »
    About question 2:
    Keep on mind that you can "merge" BASIC programs, but you can not "unmerge" them. So having some kind of overlays on BASIC is forbidden.

    Although you can overwrite existing BASIC lines from a merged program. So you could, for example have a common BASIC menu program using lines 10 to 1000; then load in lots of different sub-programs in the 1001 to 9999 lines; each time overwriting the previous sub-program.

    Yes just make sure every overlay has the same set of line numbers, even if they are do-nothing REMs to delete all common lines.

    TS2068 basic has the DELETE keyword that allows a range of lines to be deleted which would fit this problem well. This means it's possible to write a short routine on the spectrum (perhaps copied from the TS2068 rom) to do the same. In fact, I'm sure at least one of the many basic toolkits would offer such a routine.
  • GReW wrote: »
    1:
    There was no equivalent RAMTOP BASIC system variable on the ZX80. However, since the BASIC ROM sets the stack pointer to the top of available memory at startup, the most common way to determine (approximate) RAM size is to check the value of SP at the start of the program, eg:
    LD HL,$0000
    ADD HL,SP
    LD A,H
    CP $3F
    JR NC,rampack16k
    CP $0B
    JR NC,rampack3k
    CP $07
    JR NC,rampack2k
    ...
    
    I knew there was a good reason why I was typing in those INPUT programs - I have zero knowledge of machine code, or at least I did until a week ago. I'm now about 0.1% of the way to total understanding. So I've dug out the ZX80 hex loader program I saw in Sinclair Programs (Jan 1983) and should be able to enter this if I can translate the code into hex correctly, which is always a concern...

    Now a further question:
    I know (and have known since I was a nipper when I saw it in said Sinclair Programs listings) that ZX81 machine code is stored in a REM statement at line 1 with start address 16514 - looking at the hex loader program I assume it's the same for the ZX80. If the statement looked something like this:
    1 REM H*$7X{**}{A}4?{OR }{R}{CLEAR }GB/ (etc...)
    
    ...then could I just type in that REM statement with a bit of trickery with the K cursor (i.e. I need to type in CLEAR first then cursor-left for the REM, and so on if there are more keywords), or do I have to go through the hex loader?

    Anything in non-ZX80-approved brackets above is a token or a block character from SHIFT + Q-T or A-G (i.e. the ones from ZX81 graphics mode).

    GReW wrote: »
    Sounds like a perfect candidate for the CSSCGC, looking forward to receiving your entry :)
    I have considered entering this year, if I can get some good ideas to match the 128K PLAY music I've had written for a while. Because the game has to be crap for the competition, any gameplay will of course be of secondary importance to said music.

    I last entered in 2004 with the late, great Jim Langmead running the show. He was suitably unimpressed by my attempts to showcase some music, 2x2 UDGs and a font I'd ripped from Mario games and package them as Super Mario Fruit Machine. Mission accomplished. Expect more of the same!

    Or I might try a text adventure, if I'm really determined to land myself in a massive mess.
  • edited March 2017

    Now a further question:
    I know (and have known since I was a nipper when I saw it in said Sinclair Programs listings) that ZX81 machine code is stored in a REM statement at line 1 with start address 16514 - looking at the hex loader program I assume it's the same for the ZX80. If the statement looked something like this:
    1 REM H*$7X{**}{A}4?{OR }{R}{CLEAR }GB/ (etc...)
    
    ...then could I just type in that REM statement with a bit of trickery with the K cursor (i.e. I need to type in CLEAR first then cursor-left for the REM, and so on if there are more keywords), or do I have to go through the hex loader?

    That code snippet I posted is only of use in as part of a larger assembly program, without the appropriate labels to jump to - it won't work. If you just want to check the amount of memory from BASIC all you need is:
    LD HL,$0000  ; 12 00 00
    ADD HL,SP ;39
    RET ;C9
    
    Then check the return value using IF statements.

    You can store Machine Code in REM statements on the ZX80, but it isn't as easy as on the ZX81; since there are huge chunks of the character set you can't type from the keyboard. To create the five byte routine above you'd need to enter this:
    10 REM -{space}{space}T0
    POKE 16431,201
    
    and call it with
    LET M=USR 16427
    
    Remembering that BASIC variables are signed 16-bit integers, so addresses more than 32767 will be displayed as negative numbers.



    Post edited by GReW on
    Comp.Sys.Sinclair Crap Games Competition 2017
    Everyone has a crap game inside them, let yours out!
  • Top banana. Barely an hour after I'd written my reply (i.e. too late to edit it) I thought "...non-printable characters!", but I was thinking of the ZX81 having the problem rather than the ZX80 - even so, your point stands.

    I'll try the routine (with NO$ZX81 set to ZX80 Reactor Control System mode) and see what happens. I'm not sure I can test the 3K version, though - I'll see if Paul Farrow's ZX80-on-Spectrum emulator gives the same figures (it should do!), I know that's got a 3K option. How many RAM packs for the ZX80 were there, anyway?

    It's at times like this I should dig out the "Machine Code for the Complete Beginner" book I found while digging through the old relics I bought off a friend a while back. There's Hewson's "Complete Machine Code Tutor" as well - I should go through that. This comment has been brought to you by typing in the INPUT assembler, noticing a dreadful typo (a GOTO statement with no number), tearing out what little hair I have, realising it presents no problems*, gluing all my hair back on, and finding it works. But every machine code line has to be stored as REM statements and it's as clunky to use as INPUT's word processor (that stores every line of the document in a DATA statement).

    Anyway, I'm going to have a butcher's in the WOS archive for a proper assembler/disassembler (if there's a good one, feel free to recommend it).

    * The program stops with 2 Variable not found (I've filled in the missing number with xxxx), but as it's the end of the assembly, I think it was supposed to jump to a dummy line 9999 and may as well just say STOP. 2 Variable not found, 0 OK, 9 STOP statement, what's the difference?
  • I'll try the routine (with NO$ZX81 set to ZX80 Reactor Control System mode) and see what happens. I'm not sure I can test the 3K version, though - I'll see if Paul Farrow's ZX80-on-Spectrum emulator gives the same figures (it should do!),
    As the first line of the program you should get the following values for SP with different RAM packs; if you're running more BASIC lines first or have any other custom machine code, then allow a few extra words stack space:
    0k    -31713
    2k    -30689
    4k    -28641
    8k    -24545
    16k+  -16353
    
    Anyway, I'm going to have a butcher's in the WOS archive for a proper assembler/disassembler (if there's a good one, feel free to recommend it).
    To be honest, there's really no reason to run an assembler on the target machine any more; except for nostalgia purposes. I use Pasmo, a Z80 cross-assembler for Windows/Linux with an .o file wrapper to generate tape files.



    Comp.Sys.Sinclair Crap Games Competition 2017
    Everyone has a crap game inside them, let yours out!
  • edited March 2017
    GReW wrote: »
    As the first line of the program you should get the following values for SP with different RAM packs; if you're running more BASIC lines first or have any other custom machine code, then allow a few extra words stack space:
    0k    -31713
    2k    -30689
    4k    -28641
    8k    -24545
    16k+  -16353
    
    I was thinking "wait, what, 0K?" but presumably that's the bare 1K machine, "2K" has a 2K RAM pack for a total of 3K... and I'd assume 16K+ refers to anything with a ZX81-esque 18K RAM pack (which I suspect you're going to tell me was actually a 15K RAM pack that merely brought the total up to 16K).
    GReW wrote: »
    To be honest, there's really no reason to run an assembler on the target machine any more; except for nostalgia purposes. I use Pasmo, a Z80 cross-assembler for Windows/Linux with an .o file wrapper to generate tape files.
    I had a look anyway, found a lot of MIA files, and a couple of programs that are designed for people who are already fluent in machine code and spit out error messages that I don't understand. And one from McGraw-Hill (who wrote a few of my university textbooks) that quite helpfully fails to run at all with Q Parameter error...

    Essentially what I was looking for was something where I could type in a machine code listing just the way I would do with a BASIC program, have an indication of the number of bytes (so when it's finished I could cram it at the highest address possible and have the last byte at 65535), SAVE "filename" CODE, and load it back in later. Equally with a disassembler all I ask is to LOAD "" CODE, and the program spits out a listing of ld, jr, push and pop statements. Is that so much to ask of the Spectrum software available?

    Anyway, I'll have a look at Pasmo - if it's not too complex!

    But first, I'll give the ZX80 memory routines a go.
    Post edited by The Mighty Dopethrone on
  • I had a look anyway, found a lot of MIA files, and a couple of programs that are designed for people who are already fluent in machine code and spit out error messages that I don't understand. And one from McGraw-Hill (who wrote a few of my university textbooks) that quite helpfully fails to run at all with Q Parameter error...

    Essentially what I was looking for was something where I could type in a machine code listing just the way I would do with a BASIC program, have an indication of the number of bytes (so when it's finished I could cram it at the highest address possible and have the last byte at 65535), SAVE "filename" CODE, and load it back in later. Equally with a disassembler all I ask is to LOAD "" CODE, and the program spits out a listing of ld, jr, push and pop statements. Is that so much to ask of the Spectrum software available?
    Didn't realise you'd suddenly switched from talking about ZX80 machine code to machine code on the Spectrum, the advice I gave was specific to the ZX80 - so don't try to use an .o wrapper to generate a Spectrum tape file, because it won't work; Pasmo can generate Spectrum .tap and .tzx files directly without needing custom header and tail files.

    You can run an assembler on the Spectrum if you want to, but you're severely limiting what you can do both in terms of code size and debugging. The assembler, source code, debugger and disassembler all occupy memory, which limits both the features available and the size and location of your assembled code. Even under emulation, having to reload your assembler, then your source code, then reassemble every time the program crashes gets very old, very fast.

    There's nothing wrong with the McGraw-Hill ZX Spectrum Assembler; the "Q Parameter error" you're getting, means you've made a syntax error in your source code.

    If you're just starting out learning machine code, I'd suggest you start with a Spectrum emulator with a built in Z80 Assembler, such as ZXSpin, which can assemble directly to the emulated Spectrum's memory. It also has an excellent debugger and disassembler built in.

    You've probably already realised this - but if you're determined to have all your machine code at the top of memory - you'll overwrite the stack, so you'd need to relocate it elsewhere.

    Comp.Sys.Sinclair Crap Games Competition 2017
    Everyone has a crap game inside them, let yours out!
  • edited March 2017
    GReW wrote: »
    As the first line of the program you should get the following values for SP with different RAM packs; if you're running more BASIC lines first or have any other custom machine code, then allow a few extra words stack space:
    0k    -31713
    2k    -30689
    4k    -28641
    8k    -24545
    16k+  -16353
    
    I was thinking "wait, what, 0K?" but presumably that's the bare 1K machine, "2K" has a 2K RAM pack for a total of 3K... and I'd assume 16K+ refers to anything with a ZX81-esque 18K RAM pack (which I suspect you're going to tell me was actually a 15K RAM pack that merely brought the total up to 16K).
    Total available RAM depends on the design of the RAM expansion. The 16k byte expansions disable the internal RAM chip(s) in the computer.
    Small RAM expansions can also do this. But the 2k byte expansion instead adds it's 2k bytes to the internal 1k byte, making a total of 3k bytes.

    I don't have the details of the other RAM expansions, so can't help with those.

    Mark

    Post edited by 1024MAK on
    Sinclair FAQ Wiki
    Repair Guides. Spanish Hardware site.
    WoS - can't download? Info here...
    former Meulie Spectrum Archive but no longer available :-(
    Spectranet: the TNFS directory thread

    ! Standby alert !
    “There are four lights!”
    Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb!
    Looking forward to summer in Somerset later in the year :)
  • GReW wrote: »
    You can run an assembler on the Spectrum if you want to, but you're severely limiting what you can do both in terms of code size and debugging. The assembler, source code, debugger and disassembler all occupy memory, which limits both the features available and the size and location of your assembled code. Even under emulation, having to reload your assembler, then your source code, then reassemble every time the program crashes gets very old, very fast.
    I can imagine. I heard that Codemasters developers (I think it was them, anyway) wrote their code for Spectrum games on an Amstrad CPC so they could use the disc drive - whether it was a CPC664 or (more likely) a CPC6128 I can see that being handy. They'd then have to port the Spectrum version back to the Amstrad...
    GReW wrote: »
    There's nothing wrong with the McGraw-Hill ZX Spectrum Assembler; the "Q Parameter error" you're getting, means you've made a syntax error in your source code.
    I was just testing it... download, load, run, "use this RANDOMIZE USR statement", the programs NEWs, I use the statement, Q Parameter error. I had no source code, I thought that's how it would run so I could write some!
    GReW wrote: »
    If you're just starting out learning machine code...
    Which I am. Can you tell?
    GReW wrote: »
    I'd suggest you start with a Spectrum emulator with a built in Z80 Assembler, such as ZXSpin, which can assemble directly to the emulated Spectrum's memory. It also has an excellent debugger and disassembler built in.
    When I went looking for an example program to test the INPUT assembler, I found the "machine code in 30 minutes" program on Bytes: Chuntey which looked promising - the article mentioned Spin's assembler, but I thought under the circumstances it was cheating! Still, I'll give this a shot now.

    Srangely, I always found Spin took ages to load - no idea why (and it seems to be OK now - maybe it didn't like Windows XP!). It's the emulator I used to use for recording RZXs on in t'old days (any of mine from 2004 such as Rick Dangerous I/II will have been made in Spin) but I'd never known of this feature before (as I had no cause to notice it in the menus).
    GReW wrote: »
    You've probably already realised this...
    Which I hadn't...
    GReW wrote: »
    but if you're determined to have all your machine code at the top of memory - you'll overwrite the stack, so you'd need to relocate it elsewhere.
    Not that I was particularly determined, but I thought "if this code is only a kilobyte long at best, why load it at 33000 instead of 64000 or so?"
    1024MAK wrote: »
    Total available RAM depends on the design of the RAM expansion. The 16k byte expansions disable the internal RAM chip(s) in the computer.
    Small RAM expansions can also do this. But the 2k byte expansion instead adds it's 2k bytes to the internal 1k byte, making a total of 3k bytes.
    I don't have the details of the other RAM expansions, so can't help with those.
    Would they have been third-party-only RAM packs, like Memotech's 32K/64K RAM for the ZX81?
  • edited March 2017
    So I typed in the program that bigjon wrote and Arjun did the tutorial for that I mentioned earlier (https://www.worldofspectrum.org/forums/discussion/27207/redirect/p1), and: it assembled first time!
    PRINT USR 3300
    

    I just spent half an hour wondering why I had no control over the blue square. And then it hit me, like a blue square slamming into a black square... seeing as the tutorial explains that the same principle is used as where I've seen ten addresses of the IN function floating at 191 when no key is pressed, have I got Spin set to an Issue 2 keyboard?

    Sure enough, I have.

    Switch it to Issue 3 and it's working. I could probably work out the way to make this program work with an Issue 2 keyboard (it's actually quite obvious from the text), but I'd need a manual for an Issue 2 Spectrum to find out the IN addresses to read, and of the three manuals I have, one is for the +2, one is for the +2A, and one is for the +3. No Issue 2 keyboards there!
    Post edited by The Mighty Dopethrone on
  • edited March 2017
    Switch it to Issue 3 and it's working. I could probably work out the way to make this program work with an Issue 2 keyboard (it's actually quite obvious from the text), but I'd need a manual for an Issue 2 Spectrum to find out the IN addresses to read, and of the three manuals I have, one is for the +2, one is for the +2A, and one is for the +3. No Issue 2 keyboards there!

    The port addresses to read the keyboard don't change with Issue numbers, only the contents of bits 5 to 7 in the return value. Usually a quick AND 31 is all you need to allow for all issues of keyboard.

    If you need them, the Spectrum manuals are available here: worldofspectrum.org/faq/resources/documents.htm

    Don't be caught out by the misprint in some editions of the +3 Manual regarding keyboard addresses.

    Or you could always RTFFAQ :-)

    Post edited by GReW on
    Comp.Sys.Sinclair Crap Games Competition 2017
    Everyone has a crap game inside them, let yours out!
  • edited March 2017
    GReW wrote: »
    The port addresses to read the keyboard don't change with Issue numbers, only the contents of bits 5 to 7 in the return value. Usually a quick AND 31 is all you need to allow for all issues of keyboard.
    That will be a bit wise AND (as in Z80 machine code) not a ZX Spectrum BASIC "AND" (which just does a logical operation based on the whole number where any value other than zero is treated as being logical "1", the result returned being either 0 or 1).

    Mark
    Post edited by 1024MAK on
    Sinclair FAQ Wiki
    Repair Guides. Spanish Hardware site.
    WoS - can't download? Info here...
    former Meulie Spectrum Archive but no longer available :-(
    Spectranet: the TNFS directory thread

    ! Standby alert !
    “There are four lights!”
    Step up to red alert. Sir, are you absolutely sure? It does mean changing the bulb!
    Looking forward to summer in Somerset later in the year :)
Sign In or Register to comment.