--- title: "Changing RAMTOP Without “NEW”" type: "article" slug: "changing-ramtop-without-new" url: "http://localhost/article/changing-ramtop-without-new/" markdown_url: "http://localhost/article/changing-ramtop-without-new.md" published_at: "2024-01-28T19:45:39+00:00" modified_at: "2026-06-21T23:25:58+00:00" featured_image: url: "http://localhost/wp-content/uploads/2022/04/20230809-041332.jpg" excerpt: "Editor's note: Although this pearl of programming poetry is not a direct Pro/File enhancement, it is never the less, a utility with many useful applications for people who like to cut and hack into Pro/File or any other program. Now for Richard's wisdom: Those of us who use 64K RAM on our ZX81/TS1000 must poke…" category: - name: "Pro/File Updates" slug: "pro-file-updates" taxonomy: "category" url: "http://localhost/category/periodicals/pro-file-updates/" post_tag: - name: "Full Text" slug: "fulltext" taxonomy: "post_tag" url: "http://localhost/tag/fulltext/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" - name: "Type-in program" slug: "type-in-program" taxonomy: "post_tag" url: "http://localhost/tag/type-in-program/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" indiv: - name: "Richard Erwin" slug: "richard-erwin" taxonomy: "indiv" url: "http://localhost/indiv/richard-erwin/" publication_r: id: 39136 title: "Pro/File Updates" type: "periodical" url: "http://localhost/periodical/pro-file-updates/" authors: "Richard Erwin" authors_r: - name: "Richard Erwin" slug: "richard-erwin" taxonomy: "indiv" url: "http://localhost/indiv/richard-erwin/" volume: "2" issue: "1" issues_articles: - id: 52733 title: "Pro/file Updates v2 n1" type: "issue" url: "http://localhost/issue/pro-file-updates-v2-n1/" pages: "7" pubdate: "January 1985" product_reviews: - id: 14729 title: "ZX Pro/File" type: "product" url: "http://localhost/product/zx-pro-file-2/" - id: 14670 title: "Z-XLR8" type: "product" url: "http://localhost/product/z-xlr8/" archive_link: false --- # Changing RAMTOP Without “NEW” Editor’s note: Although this pearl of programming poetry is not a direct [Pro/File](http://localhost/product/zx-pro-file-2/) enhancement, it is never the less, a utility with many useful applications for people who like to cut and hack into Pro/File or any other program. Now for Richard’s wisdom: Those of us who use 64K RAM on our ZX81/TS1000 must poke RAMTOP and execute NEW before loading large programs. This can also be done by a short machine code routine added to the high-speed loader programs like [ZXLR-8](http://localhost/product/z-xlr8/) described in previous UPDATES. This routine can be placed in a 35 character REMarks statement following any existing REMs in the loader (e.g. 2 REM for Z-XLR&8). The following list is poked into the 35 locations beginning with the first REMark character–for ZXLR-8 that is location 18833. ``` 18833 42 18834 4 18835 64 18836 167 18837 237 18838 114 18839 229 18840 193 18841 237 18842 91 18843 4 18844 64 18845 42 18846 50 18847 64 18848 34 18849 4 18850 64 18851 237 18852 66 18853 249 18854 235 18855 237 18856 66 18857 237 18858 176 18859 27 18860 27 18861 27 18862 27 18863 237 18864 83 18865 2 18866 64 18867 201 ``` The following BASIC routine can be used to POKE the REM: ``` 7000 FOR I=0 T 34 7010 INPUT J 7020 POKE (18833+I),J 7030 NEXT I 7040 STOP ``` The routine reads the new RAMTOP value from the random number seed, which must be preset using RAND 65535. It computes the current length of the machine stack, copies the stack to the new end of memory, sets the new value into RAMTOP, sets ERR_SP, and points the stack pointer (SP register) to the new stack. The Z80 instructions are: ``` ; MOVE MACHINE STACK ; NEW RAMTOP IN RND SEED ; COPY STACK TO NEW TOP ; SET STACK POINTER TO ; NEW STACK ; SET ERR-SP TO NEW END ; OF STACK 2A0440 LD HL,(4004) ;OLD RAMTOP A7 AND A ;CLEAR CARRY ED72 SBC HL,SP ;STACK SIZE E5 PUSH HL ;MOVE TO COUNTR C1 POP BC ED5B0440 LD DE,(4004) ;OLD RAMTOP 2A3240 LD HL,(4032) ;NEW RAMTOP 220440 LD (4004),HL ;SET RAMTOP ED42 SBC HL,BC ;NEW SP F9 LD SP,HL ;SET NEW SP EB EX DE,HL ;SWAP PTRS ED42 SBC HL,BC ;OLD SP EDB0 LDIR ;COPY BOTTOM-UP 1B DEC DE ;NEW RAMTOP-1 1B DEC DE ;ADJUST TO ERRSP 1B DEC DE 18 DEC DE ED530240 LD (4002),DE ;SET ERRSP C9 RET ``` To include this stack mover in ZXLR-8, delete statements 9080 and 9082, and add the following to both expand the usable memory and automatically start the loader: ``` 9100 REM MOVE MACHINE STACK 64K 9110 RAND 65535 9120 RAND USR 18833 9200 REM MOVE Z-XLR8 9210 RAND USR 18141 9220 REM EXECULTE ZXLR8 9230 RAND USR L ``` This routine can also be used (alone or with a loader) where the BASIC memory must be reduced to protect an area at the top of a 16K RAM. Just precede the RAND USR statement by RAND and the new RAMTOP value you want to have.